VirtualBox

source: vbox/trunk/src/VBox/Main/DisplayImpl.cpp@ 35157

Last change on this file since 35157 was 35157, checked in by vboxsync, 14 years ago

Main: OnGuestMonitorDisabled event.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 133.0 KB
Line 
1/* $Id: DisplayImpl.cpp 35157 2010-12-15 17:13:27Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "DisplayImpl.h"
19#include "DisplayUtils.h"
20#include "ConsoleImpl.h"
21#include "ConsoleVRDPServer.h"
22#include "VMMDev.h"
23
24#include "AutoCaller.h"
25#include "Logging.h"
26
27/* generated header */
28#include "VBoxEvents.h"
29
30#include <iprt/semaphore.h>
31#include <iprt/thread.h>
32#include <iprt/asm.h>
33#include <iprt/cpp/utils.h>
34
35#include <VBox/pdmdrv.h>
36#ifdef DEBUG /* for VM_ASSERT_EMT(). */
37# include <VBox/vm.h>
38#endif
39
40#ifdef VBOX_WITH_VIDEOHWACCEL
41# include <VBox/VBoxVideo.h>
42#endif
43
44#ifdef VBOX_WITH_CROGL
45# include <VBox/HostServices/VBoxCrOpenGLSvc.h>
46#endif
47
48#include <VBox/com/array.h>
49
50/**
51 * Display driver instance data.
52 *
53 * @implements PDMIDISPLAYCONNECTOR
54 */
55typedef struct DRVMAINDISPLAY
56{
57 /** Pointer to the display object. */
58 Display *pDisplay;
59 /** Pointer to the driver instance structure. */
60 PPDMDRVINS pDrvIns;
61 /** Pointer to the keyboard port interface of the driver/device above us. */
62 PPDMIDISPLAYPORT pUpPort;
63 /** Our display connector interface. */
64 PDMIDISPLAYCONNECTOR IConnector;
65#if defined(VBOX_WITH_VIDEOHWACCEL) || defined(VBOX_WITH_CRHGSMI)
66 /** VBVA callbacks */
67 PPDMIDISPLAYVBVACALLBACKS pVBVACallbacks;
68#endif
69} DRVMAINDISPLAY, *PDRVMAINDISPLAY;
70
71/** Converts PDMIDISPLAYCONNECTOR pointer to a DRVMAINDISPLAY pointer. */
72#define PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface) RT_FROM_MEMBER(pInterface, DRVMAINDISPLAY, IConnector)
73
74#ifdef DEBUG_sunlover
75static STAMPROFILE StatDisplayRefresh;
76static int stam = 0;
77#endif /* DEBUG_sunlover */
78
79// constructor / destructor
80/////////////////////////////////////////////////////////////////////////////
81
82Display::Display()
83 : mParent(NULL)
84{
85}
86
87Display::~Display()
88{
89}
90
91
92HRESULT Display::FinalConstruct()
93{
94 mpVbvaMemory = NULL;
95 mfVideoAccelEnabled = false;
96 mfVideoAccelVRDP = false;
97 mfu32SupportedOrders = 0;
98 mcVideoAccelVRDPRefs = 0;
99
100 mpPendingVbvaMemory = NULL;
101 mfPendingVideoAccelEnable = false;
102
103 mfMachineRunning = false;
104
105 mpu8VbvaPartial = NULL;
106 mcbVbvaPartial = 0;
107
108 mpDrv = NULL;
109 mpVMMDev = NULL;
110 mfVMMDevInited = false;
111
112 mLastAddress = NULL;
113 mLastBytesPerLine = 0;
114 mLastBitsPerPixel = 0,
115 mLastWidth = 0;
116 mLastHeight = 0;
117
118#ifdef VBOX_WITH_OLD_VBVA_LOCK
119 int rc = RTCritSectInit(&mVBVALock);
120 AssertRC(rc);
121 mfu32PendingVideoAccelDisable = false;
122#endif /* VBOX_WITH_OLD_VBVA_LOCK */
123
124#ifdef VBOX_WITH_HGSMI
125 mu32UpdateVBVAFlags = 0;
126#endif
127
128 return S_OK;
129}
130
131void Display::FinalRelease()
132{
133 uninit();
134
135#ifdef VBOX_WITH_OLD_VBVA_LOCK
136 if (RTCritSectIsInitialized (&mVBVALock))
137 {
138 RTCritSectDelete (&mVBVALock);
139 memset (&mVBVALock, 0, sizeof (mVBVALock));
140 }
141#endif /* VBOX_WITH_OLD_VBVA_LOCK */
142}
143
144// public initializer/uninitializer for internal purposes only
145/////////////////////////////////////////////////////////////////////////////
146
147#define kMaxSizeThumbnail 64
148
149/**
150 * Save thumbnail and screenshot of the guest screen.
151 */
152static int displayMakeThumbnail(uint8_t *pu8Data, uint32_t cx, uint32_t cy,
153 uint8_t **ppu8Thumbnail, uint32_t *pcbThumbnail, uint32_t *pcxThumbnail, uint32_t *pcyThumbnail)
154{
155 int rc = VINF_SUCCESS;
156
157 uint8_t *pu8Thumbnail = NULL;
158 uint32_t cbThumbnail = 0;
159 uint32_t cxThumbnail = 0;
160 uint32_t cyThumbnail = 0;
161
162 if (cx > cy)
163 {
164 cxThumbnail = kMaxSizeThumbnail;
165 cyThumbnail = (kMaxSizeThumbnail * cy) / cx;
166 }
167 else
168 {
169 cyThumbnail = kMaxSizeThumbnail;
170 cxThumbnail = (kMaxSizeThumbnail * cx) / cy;
171 }
172
173 LogFlowFunc(("%dx%d -> %dx%d\n", cx, cy, cxThumbnail, cyThumbnail));
174
175 cbThumbnail = cxThumbnail * 4 * cyThumbnail;
176 pu8Thumbnail = (uint8_t *)RTMemAlloc(cbThumbnail);
177
178 if (pu8Thumbnail)
179 {
180 uint8_t *dst = pu8Thumbnail;
181 uint8_t *src = pu8Data;
182 int dstW = cxThumbnail;
183 int dstH = cyThumbnail;
184 int srcW = cx;
185 int srcH = cy;
186 int iDeltaLine = cx * 4;
187
188 BitmapScale32 (dst,
189 dstW, dstH,
190 src,
191 iDeltaLine,
192 srcW, srcH);
193
194 *ppu8Thumbnail = pu8Thumbnail;
195 *pcbThumbnail = cbThumbnail;
196 *pcxThumbnail = cxThumbnail;
197 *pcyThumbnail = cyThumbnail;
198 }
199 else
200 {
201 rc = VERR_NO_MEMORY;
202 }
203
204 return rc;
205}
206
207DECLCALLBACK(void)
208Display::displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser)
209{
210 Display *that = static_cast<Display*>(pvUser);
211
212 /* 32bpp small RGB image. */
213 uint8_t *pu8Thumbnail = NULL;
214 uint32_t cbThumbnail = 0;
215 uint32_t cxThumbnail = 0;
216 uint32_t cyThumbnail = 0;
217
218 /* PNG screenshot. */
219 uint8_t *pu8PNG = NULL;
220 uint32_t cbPNG = 0;
221 uint32_t cxPNG = 0;
222 uint32_t cyPNG = 0;
223
224 Console::SafeVMPtr pVM (that->mParent);
225 if (SUCCEEDED(pVM.rc()))
226 {
227 /* Query RGB bitmap. */
228 uint8_t *pu8Data = NULL;
229 size_t cbData = 0;
230 uint32_t cx = 0;
231 uint32_t cy = 0;
232
233 /* SSM code is executed on EMT(0), therefore no need to use VMR3ReqCallWait. */
234#ifdef VBOX_WITH_OLD_VBVA_LOCK
235 int rc = Display::displayTakeScreenshotEMT(that, VBOX_VIDEO_PRIMARY_SCREEN, &pu8Data, &cbData, &cx, &cy);
236#else
237 int rc = that->mpDrv->pUpPort->pfnTakeScreenshot (that->mpDrv->pUpPort, &pu8Data, &cbData, &cx, &cy);
238#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
239
240 /*
241 * It is possible that success is returned but everything is 0 or NULL.
242 * (no display attached if a VM is running with VBoxHeadless on OSE for example)
243 */
244 if (RT_SUCCESS(rc) && pu8Data)
245 {
246 Assert(cx && cy);
247
248 /* Prepare a small thumbnail and a PNG screenshot. */
249 displayMakeThumbnail(pu8Data, cx, cy, &pu8Thumbnail, &cbThumbnail, &cxThumbnail, &cyThumbnail);
250 DisplayMakePNG(pu8Data, cx, cy, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 1);
251
252 /* This can be called from any thread. */
253 that->mpDrv->pUpPort->pfnFreeScreenshot (that->mpDrv->pUpPort, pu8Data);
254 }
255 }
256 else
257 {
258 LogFunc(("Failed to get VM pointer 0x%x\n", pVM.rc()));
259 }
260
261 /* Regardless of rc, save what is available:
262 * Data format:
263 * uint32_t cBlocks;
264 * [blocks]
265 *
266 * Each block is:
267 * uint32_t cbBlock; if 0 - no 'block data'.
268 * uint32_t typeOfBlock; 0 - 32bpp RGB bitmap, 1 - PNG, ignored if 'cbBlock' is 0.
269 * [block data]
270 *
271 * Block data for bitmap and PNG:
272 * uint32_t cx;
273 * uint32_t cy;
274 * [image data]
275 */
276 SSMR3PutU32(pSSM, 2); /* Write thumbnail and PNG screenshot. */
277
278 /* First block. */
279 SSMR3PutU32(pSSM, cbThumbnail + 2 * sizeof (uint32_t));
280 SSMR3PutU32(pSSM, 0); /* Block type: thumbnail. */
281
282 if (cbThumbnail)
283 {
284 SSMR3PutU32(pSSM, cxThumbnail);
285 SSMR3PutU32(pSSM, cyThumbnail);
286 SSMR3PutMem(pSSM, pu8Thumbnail, cbThumbnail);
287 }
288
289 /* Second block. */
290 SSMR3PutU32(pSSM, cbPNG + 2 * sizeof (uint32_t));
291 SSMR3PutU32(pSSM, 1); /* Block type: png. */
292
293 if (cbPNG)
294 {
295 SSMR3PutU32(pSSM, cxPNG);
296 SSMR3PutU32(pSSM, cyPNG);
297 SSMR3PutMem(pSSM, pu8PNG, cbPNG);
298 }
299
300 RTMemFree(pu8PNG);
301 RTMemFree(pu8Thumbnail);
302}
303
304DECLCALLBACK(int)
305Display::displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass)
306{
307 Display *that = static_cast<Display*>(pvUser);
308
309 if (uVersion != sSSMDisplayScreenshotVer)
310 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
311 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
312
313 /* Skip data. */
314 uint32_t cBlocks;
315 int rc = SSMR3GetU32(pSSM, &cBlocks);
316 AssertRCReturn(rc, rc);
317
318 for (uint32_t i = 0; i < cBlocks; i++)
319 {
320 uint32_t cbBlock;
321 rc = SSMR3GetU32(pSSM, &cbBlock);
322 AssertRCBreak(rc);
323
324 uint32_t typeOfBlock;
325 rc = SSMR3GetU32(pSSM, &typeOfBlock);
326 AssertRCBreak(rc);
327
328 LogFlowFunc(("[%d] type %d, size %d bytes\n", i, typeOfBlock, cbBlock));
329
330 /* Note: displaySSMSaveScreenshot writes size of a block = 8 and
331 * do not write any data if the image size was 0.
332 * @todo Fix and increase saved state version.
333 */
334 if (cbBlock > 2 * sizeof (uint32_t))
335 {
336 rc = SSMR3Skip(pSSM, cbBlock);
337 AssertRCBreak(rc);
338 }
339 }
340
341 return rc;
342}
343
344/**
345 * Save/Load some important guest state
346 */
347DECLCALLBACK(void)
348Display::displaySSMSave(PSSMHANDLE pSSM, void *pvUser)
349{
350 Display *that = static_cast<Display*>(pvUser);
351
352 SSMR3PutU32(pSSM, that->mcMonitors);
353 for (unsigned i = 0; i < that->mcMonitors; i++)
354 {
355 SSMR3PutU32(pSSM, that->maFramebuffers[i].u32Offset);
356 SSMR3PutU32(pSSM, that->maFramebuffers[i].u32MaxFramebufferSize);
357 SSMR3PutU32(pSSM, that->maFramebuffers[i].u32InformationSize);
358 SSMR3PutU32(pSSM, that->maFramebuffers[i].w);
359 SSMR3PutU32(pSSM, that->maFramebuffers[i].h);
360 }
361}
362
363DECLCALLBACK(int)
364Display::displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass)
365{
366 Display *that = static_cast<Display*>(pvUser);
367
368 if (!( uVersion == sSSMDisplayVer
369 || uVersion == sSSMDisplayVer2))
370 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
371 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
372
373 uint32_t cMonitors;
374 int rc = SSMR3GetU32(pSSM, &cMonitors);
375 if (cMonitors != that->mcMonitors)
376 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Number of monitors changed (%d->%d)!"), cMonitors, that->mcMonitors);
377
378 for (uint32_t i = 0; i < cMonitors; i++)
379 {
380 SSMR3GetU32(pSSM, &that->maFramebuffers[i].u32Offset);
381 SSMR3GetU32(pSSM, &that->maFramebuffers[i].u32MaxFramebufferSize);
382 SSMR3GetU32(pSSM, &that->maFramebuffers[i].u32InformationSize);
383 if (uVersion == sSSMDisplayVer2)
384 {
385 uint32_t w;
386 uint32_t h;
387 SSMR3GetU32(pSSM, &w);
388 SSMR3GetU32(pSSM, &h);
389 that->maFramebuffers[i].w = w;
390 that->maFramebuffers[i].h = h;
391 }
392 }
393
394 return VINF_SUCCESS;
395}
396
397/**
398 * Initializes the display object.
399 *
400 * @returns COM result indicator
401 * @param parent handle of our parent object
402 * @param qemuConsoleData address of common console data structure
403 */
404HRESULT Display::init (Console *aParent)
405{
406 LogFlowThisFunc(("aParent=%p\n", aParent));
407
408 ComAssertRet(aParent, E_INVALIDARG);
409
410 /* Enclose the state transition NotReady->InInit->Ready */
411 AutoInitSpan autoInitSpan(this);
412 AssertReturn(autoInitSpan.isOk(), E_FAIL);
413
414 unconst(mParent) = aParent;
415
416 // by default, we have an internal framebuffer which is
417 // NULL, i.e. a black hole for no display output
418 mFramebufferOpened = false;
419
420 ULONG ul;
421 mParent->machine()->COMGETTER(MonitorCount)(&ul);
422 mcMonitors = ul;
423
424 for (ul = 0; ul < mcMonitors; ul++)
425 {
426 maFramebuffers[ul].u32Offset = 0;
427 maFramebuffers[ul].u32MaxFramebufferSize = 0;
428 maFramebuffers[ul].u32InformationSize = 0;
429
430 maFramebuffers[ul].pFramebuffer = NULL;
431
432 maFramebuffers[ul].xOrigin = 0;
433 maFramebuffers[ul].yOrigin = 0;
434
435 maFramebuffers[ul].w = 0;
436 maFramebuffers[ul].h = 0;
437
438 maFramebuffers[ul].u16BitsPerPixel = 0;
439 maFramebuffers[ul].pu8FramebufferVRAM = NULL;
440 maFramebuffers[ul].u32LineSize = 0;
441
442 maFramebuffers[ul].pHostEvents = NULL;
443
444 maFramebuffers[ul].u32ResizeStatus = ResizeStatus_Void;
445
446 maFramebuffers[ul].fDefaultFormat = false;
447
448 memset (&maFramebuffers[ul].dirtyRect, 0 , sizeof (maFramebuffers[ul].dirtyRect));
449 memset (&maFramebuffers[ul].pendingResize, 0 , sizeof (maFramebuffers[ul].pendingResize));
450#ifdef VBOX_WITH_HGSMI
451 maFramebuffers[ul].fVBVAEnabled = false;
452 maFramebuffers[ul].cVBVASkipUpdate = 0;
453 memset (&maFramebuffers[ul].vbvaSkippedRect, 0, sizeof (maFramebuffers[ul].vbvaSkippedRect));
454 maFramebuffers[ul].pVBVAHostFlags = NULL;
455#endif /* VBOX_WITH_HGSMI */
456 }
457
458 {
459 // register listener for state change events
460 ComPtr<IEventSource> es;
461 mParent->COMGETTER(EventSource)(es.asOutParam());
462 com::SafeArray <VBoxEventType_T> eventTypes;
463 eventTypes.push_back(VBoxEventType_OnStateChanged);
464 es->RegisterListener(this, ComSafeArrayAsInParam(eventTypes), true);
465 }
466
467 /* Confirm a successful initialization */
468 autoInitSpan.setSucceeded();
469
470 return S_OK;
471}
472
473/**
474 * Uninitializes the instance and sets the ready flag to FALSE.
475 * Called either from FinalRelease() or by the parent when it gets destroyed.
476 */
477void Display::uninit()
478{
479 LogFlowThisFunc(("\n"));
480
481 /* Enclose the state transition Ready->InUninit->NotReady */
482 AutoUninitSpan autoUninitSpan(this);
483 if (autoUninitSpan.uninitDone())
484 return;
485
486 ULONG ul;
487 for (ul = 0; ul < mcMonitors; ul++)
488 maFramebuffers[ul].pFramebuffer = NULL;
489
490 if (mParent)
491 {
492 ComPtr<IEventSource> es;
493 mParent->COMGETTER(EventSource)(es.asOutParam());
494 es->UnregisterListener(this);
495 }
496
497 unconst(mParent) = NULL;
498
499 if (mpDrv)
500 mpDrv->pDisplay = NULL;
501
502 mpDrv = NULL;
503 mpVMMDev = NULL;
504 mfVMMDevInited = true;
505}
506
507/**
508 * Register the SSM methods. Called by the power up thread to be able to
509 * pass pVM
510 */
511int Display::registerSSM(PVM pVM)
512{
513 /* Newest version adds width and height of the framebuffer */
514 int rc = SSMR3RegisterExternal(pVM, "DisplayData", 0, sSSMDisplayVer2,
515 mcMonitors * sizeof(uint32_t) * 5 + sizeof(uint32_t),
516 NULL, NULL, NULL,
517 NULL, displaySSMSave, NULL,
518 NULL, displaySSMLoad, NULL, this);
519 AssertRCReturn(rc, rc);
520
521 /*
522 * Register loaders for old saved states where iInstance was 3 * sizeof(uint32_t *).
523 */
524 rc = SSMR3RegisterExternal(pVM, "DisplayData", 12 /*uInstance*/, sSSMDisplayVer, 0 /*cbGuess*/,
525 NULL, NULL, NULL,
526 NULL, NULL, NULL,
527 NULL, displaySSMLoad, NULL, this);
528 AssertRCReturn(rc, rc);
529
530 rc = SSMR3RegisterExternal(pVM, "DisplayData", 24 /*uInstance*/, sSSMDisplayVer, 0 /*cbGuess*/,
531 NULL, NULL, NULL,
532 NULL, NULL, NULL,
533 NULL, displaySSMLoad, NULL, this);
534 AssertRCReturn(rc, rc);
535
536 /* uInstance is an arbitrary value greater than 1024. Such a value will ensure a quick seek in saved state file. */
537 rc = SSMR3RegisterExternal(pVM, "DisplayScreenshot", 1100 /*uInstance*/, sSSMDisplayScreenshotVer, 0 /*cbGuess*/,
538 NULL, NULL, NULL,
539 NULL, displaySSMSaveScreenshot, NULL,
540 NULL, displaySSMLoadScreenshot, NULL, this);
541
542 AssertRCReturn(rc, rc);
543
544 return VINF_SUCCESS;
545}
546
547// IEventListener method
548STDMETHODIMP Display::HandleEvent(IEvent * aEvent)
549{
550 VBoxEventType_T aType = VBoxEventType_Invalid;
551
552 aEvent->COMGETTER(Type)(&aType);
553 switch (aType)
554 {
555 case VBoxEventType_OnStateChanged:
556 {
557 ComPtr<IStateChangedEvent> scev = aEvent;
558 Assert(scev);
559 MachineState_T machineState;
560 scev->COMGETTER(State)(&machineState);
561 if ( machineState == MachineState_Running
562 || machineState == MachineState_Teleporting
563 || machineState == MachineState_LiveSnapshotting
564 )
565 {
566 LogFlowFunc(("Machine is running.\n"));
567
568 mfMachineRunning = true;
569 }
570 else
571 mfMachineRunning = false;
572 break;
573 }
574 default:
575 AssertFailed();
576 }
577
578 return S_OK;
579}
580
581// public methods only for internal purposes
582/////////////////////////////////////////////////////////////////////////////
583
584/**
585 * @thread EMT
586 */
587static int callFramebufferResize (IFramebuffer *pFramebuffer, unsigned uScreenId,
588 ULONG pixelFormat, void *pvVRAM,
589 uint32_t bpp, uint32_t cbLine,
590 int w, int h)
591{
592 Assert (pFramebuffer);
593
594 /* Call the framebuffer to try and set required pixelFormat. */
595 BOOL finished = TRUE;
596
597 pFramebuffer->RequestResize (uScreenId, pixelFormat, (BYTE *) pvVRAM,
598 bpp, cbLine, w, h, &finished);
599
600 if (!finished)
601 {
602 LogFlowFunc (("External framebuffer wants us to wait!\n"));
603 return VINF_VGA_RESIZE_IN_PROGRESS;
604 }
605
606 return VINF_SUCCESS;
607}
608
609/**
610 * Handles display resize event.
611 * Disables access to VGA device;
612 * calls the framebuffer RequestResize method;
613 * if framebuffer resizes synchronously,
614 * updates the display connector data and enables access to the VGA device.
615 *
616 * @param w New display width
617 * @param h New display height
618 *
619 * @thread EMT
620 */
621int Display::handleDisplayResize (unsigned uScreenId, uint32_t bpp, void *pvVRAM,
622 uint32_t cbLine, int w, int h, uint16_t flags)
623{
624 LogRel (("Display::handleDisplayResize(): uScreenId = %d, pvVRAM=%p "
625 "w=%d h=%d bpp=%d cbLine=0x%X, flags=0x%X\n",
626 uScreenId, pvVRAM, w, h, bpp, cbLine, flags));
627
628 /* If there is no framebuffer, this call is not interesting. */
629 if ( uScreenId >= mcMonitors
630 || maFramebuffers[uScreenId].pFramebuffer.isNull())
631 {
632 return VINF_SUCCESS;
633 }
634
635 mLastAddress = pvVRAM;
636 mLastBytesPerLine = cbLine;
637 mLastBitsPerPixel = bpp,
638 mLastWidth = w;
639 mLastHeight = h;
640 mLastFlags = flags;
641
642 ULONG pixelFormat;
643
644 switch (bpp)
645 {
646 case 32:
647 case 24:
648 case 16:
649 pixelFormat = FramebufferPixelFormat_FOURCC_RGB;
650 break;
651 default:
652 pixelFormat = FramebufferPixelFormat_Opaque;
653 bpp = cbLine = 0;
654 break;
655 }
656
657 /* Atomically set the resize status before calling the framebuffer. The new InProgress status will
658 * disable access to the VGA device by the EMT thread.
659 */
660 bool f = ASMAtomicCmpXchgU32 (&maFramebuffers[uScreenId].u32ResizeStatus,
661 ResizeStatus_InProgress, ResizeStatus_Void);
662 if (!f)
663 {
664 /* This could be a result of the screenshot taking call Display::TakeScreenShot:
665 * if the framebuffer is processing the resize request and GUI calls the TakeScreenShot
666 * and the guest has reprogrammed the virtual VGA devices again so a new resize is required.
667 *
668 * Save the resize information and return the pending status code.
669 *
670 * Note: the resize information is only accessed on EMT so no serialization is required.
671 */
672 LogRel (("Display::handleDisplayResize(): Warning: resize postponed.\n"));
673
674 maFramebuffers[uScreenId].pendingResize.fPending = true;
675 maFramebuffers[uScreenId].pendingResize.pixelFormat = pixelFormat;
676 maFramebuffers[uScreenId].pendingResize.pvVRAM = pvVRAM;
677 maFramebuffers[uScreenId].pendingResize.bpp = bpp;
678 maFramebuffers[uScreenId].pendingResize.cbLine = cbLine;
679 maFramebuffers[uScreenId].pendingResize.w = w;
680 maFramebuffers[uScreenId].pendingResize.h = h;
681 maFramebuffers[uScreenId].pendingResize.flags = flags;
682
683 return VINF_VGA_RESIZE_IN_PROGRESS;
684 }
685
686 int rc = callFramebufferResize (maFramebuffers[uScreenId].pFramebuffer, uScreenId,
687 pixelFormat, pvVRAM, bpp, cbLine, w, h);
688 if (rc == VINF_VGA_RESIZE_IN_PROGRESS)
689 {
690 /* Immediately return to the caller. ResizeCompleted will be called back by the
691 * GUI thread. The ResizeCompleted callback will change the resize status from
692 * InProgress to UpdateDisplayData. The latter status will be checked by the
693 * display timer callback on EMT and all required adjustments will be done there.
694 */
695 return rc;
696 }
697
698 /* Set the status so the 'handleResizeCompleted' would work. */
699 f = ASMAtomicCmpXchgU32 (&maFramebuffers[uScreenId].u32ResizeStatus,
700 ResizeStatus_UpdateDisplayData, ResizeStatus_InProgress);
701 AssertRelease(f);NOREF(f);
702
703 AssertRelease(!maFramebuffers[uScreenId].pendingResize.fPending);
704
705 /* The method also unlocks the framebuffer. */
706 handleResizeCompletedEMT();
707
708 return VINF_SUCCESS;
709}
710
711/**
712 * Framebuffer has been resized.
713 * Read the new display data and unlock the framebuffer.
714 *
715 * @thread EMT
716 */
717void Display::handleResizeCompletedEMT (void)
718{
719 LogFlowFunc(("\n"));
720
721 unsigned uScreenId;
722 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
723 {
724 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
725
726 /* Try to into non resizing state. */
727 bool f = ASMAtomicCmpXchgU32 (&pFBInfo->u32ResizeStatus, ResizeStatus_Void, ResizeStatus_UpdateDisplayData);
728
729 if (f == false)
730 {
731 /* This is not the display that has completed resizing. */
732 continue;
733 }
734
735 /* Check whether a resize is pending for this framebuffer. */
736 if (pFBInfo->pendingResize.fPending)
737 {
738 /* Reset the condition, call the display resize with saved data and continue.
739 *
740 * Note: handleDisplayResize can call handleResizeCompletedEMT back,
741 * but infinite recursion is not possible, because when the handleResizeCompletedEMT
742 * is called, the pFBInfo->pendingResize.fPending is equal to false.
743 */
744 pFBInfo->pendingResize.fPending = false;
745 handleDisplayResize (uScreenId, pFBInfo->pendingResize.bpp, pFBInfo->pendingResize.pvVRAM,
746 pFBInfo->pendingResize.cbLine, pFBInfo->pendingResize.w, pFBInfo->pendingResize.h, pFBInfo->pendingResize.flags);
747 continue;
748 }
749
750 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN && !pFBInfo->pFramebuffer.isNull())
751 {
752 /* Primary framebuffer has completed the resize. Update the connector data for VGA device. */
753 updateDisplayData();
754
755 /* Check the framebuffer pixel format to setup the rendering in VGA device. */
756 BOOL usesGuestVRAM = FALSE;
757 pFBInfo->pFramebuffer->COMGETTER(UsesGuestVRAM) (&usesGuestVRAM);
758
759 pFBInfo->fDefaultFormat = (usesGuestVRAM == FALSE);
760
761 mpDrv->pUpPort->pfnSetRenderVRAM (mpDrv->pUpPort, pFBInfo->fDefaultFormat);
762 }
763 else if (!pFBInfo->pFramebuffer.isNull())
764 {
765 BOOL usesGuestVRAM = FALSE;
766 pFBInfo->pFramebuffer->COMGETTER(UsesGuestVRAM) (&usesGuestVRAM);
767
768 pFBInfo->fDefaultFormat = (usesGuestVRAM == FALSE);
769 }
770 LogFlow(("[%d]: default format %d\n", uScreenId, pFBInfo->fDefaultFormat));
771
772#ifdef DEBUG_sunlover
773 if (!stam)
774 {
775 /* protect mpVM */
776 Console::SafeVMPtr pVM (mParent);
777 AssertComRC (pVM.rc());
778
779 STAM_REG(pVM, &StatDisplayRefresh, STAMTYPE_PROFILE, "/PROF/Display/Refresh", STAMUNIT_TICKS_PER_CALL, "Time spent in EMT for display updates.");
780 stam = 1;
781 }
782#endif /* DEBUG_sunlover */
783
784 /* Inform VRDP server about the change of display parameters. */
785 LogFlowFunc (("Calling VRDP\n"));
786 mParent->consoleVRDPServer()->SendResize();
787
788#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
789 {
790 BOOL is3denabled;
791 mParent->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
792
793 if (is3denabled)
794 {
795 VBOXHGCMSVCPARM parm;
796
797 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
798 parm.u.uint32 = uScreenId;
799
800 VMMDev *pVMMDev = mParent->getVMMDev();
801 if (pVMMDev)
802 pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SCREEN_CHANGED, SHCRGL_CPARMS_SCREEN_CHANGED, &parm);
803 }
804 }
805#endif /* VBOX_WITH_CROGL */
806 }
807}
808
809static void checkCoordBounds (int *px, int *py, int *pw, int *ph, int cx, int cy)
810{
811 /* Correct negative x and y coordinates. */
812 if (*px < 0)
813 {
814 *px += *pw; /* Compute xRight which is also the new width. */
815
816 *pw = (*px < 0)? 0: *px;
817
818 *px = 0;
819 }
820
821 if (*py < 0)
822 {
823 *py += *ph; /* Compute xBottom, which is also the new height. */
824
825 *ph = (*py < 0)? 0: *py;
826
827 *py = 0;
828 }
829
830 /* Also check if coords are greater than the display resolution. */
831 if (*px + *pw > cx)
832 {
833 *pw = cx > *px? cx - *px: 0;
834 }
835
836 if (*py + *ph > cy)
837 {
838 *ph = cy > *py? cy - *py: 0;
839 }
840}
841
842unsigned mapCoordsToScreen(DISPLAYFBINFO *pInfos, unsigned cInfos, int *px, int *py, int *pw, int *ph)
843{
844 DISPLAYFBINFO *pInfo = pInfos;
845 unsigned uScreenId;
846 LogSunlover (("mapCoordsToScreen: %d,%d %dx%d\n", *px, *py, *pw, *ph));
847 for (uScreenId = 0; uScreenId < cInfos; uScreenId++, pInfo++)
848 {
849 LogSunlover ((" [%d] %d,%d %dx%d\n", uScreenId, pInfo->xOrigin, pInfo->yOrigin, pInfo->w, pInfo->h));
850 if ( (pInfo->xOrigin <= *px && *px < pInfo->xOrigin + (int)pInfo->w)
851 && (pInfo->yOrigin <= *py && *py < pInfo->yOrigin + (int)pInfo->h))
852 {
853 /* The rectangle belongs to the screen. Correct coordinates. */
854 *px -= pInfo->xOrigin;
855 *py -= pInfo->yOrigin;
856 LogSunlover ((" -> %d,%d", *px, *py));
857 break;
858 }
859 }
860 if (uScreenId == cInfos)
861 {
862 /* Map to primary screen. */
863 uScreenId = 0;
864 }
865 LogSunlover ((" scr %d\n", uScreenId));
866 return uScreenId;
867}
868
869
870/**
871 * Handles display update event.
872 *
873 * @param x Update area x coordinate
874 * @param y Update area y coordinate
875 * @param w Update area width
876 * @param h Update area height
877 *
878 * @thread EMT
879 */
880void Display::handleDisplayUpdateLegacy (int x, int y, int w, int h)
881{
882 unsigned uScreenId = mapCoordsToScreen(maFramebuffers, mcMonitors, &x, &y, &w, &h);
883
884#ifdef DEBUG_sunlover
885 LogFlowFunc (("%d,%d %dx%d (checked)\n", x, y, w, h));
886#endif /* DEBUG_sunlover */
887
888 handleDisplayUpdate (uScreenId, x, y, w, h);
889}
890
891void Display::handleDisplayUpdate (unsigned uScreenId, int x, int y, int w, int h)
892{
893#ifdef VBOX_WITH_OLD_VBVA_LOCK
894 /*
895 * Always runs under either VBVA lock or, for HGSMI, DevVGA lock.
896 * Safe to use VBVA vars and take the framebuffer lock.
897 */
898#endif /* VBOX_WITH_OLD_VBVA_LOCK */
899
900#ifdef DEBUG_sunlover
901 LogFlowFunc (("[%d] %d,%d %dx%d (%d,%d)\n",
902 uScreenId, x, y, w, h, mpDrv->IConnector.cx, mpDrv->IConnector.cy));
903#endif /* DEBUG_sunlover */
904
905 IFramebuffer *pFramebuffer = maFramebuffers[uScreenId].pFramebuffer;
906
907 // if there is no framebuffer, this call is not interesting
908 if (pFramebuffer == NULL)
909 return;
910
911 pFramebuffer->Lock();
912
913 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
914 checkCoordBounds (&x, &y, &w, &h, mpDrv->IConnector.cx, mpDrv->IConnector.cy);
915 else
916 checkCoordBounds (&x, &y, &w, &h, maFramebuffers[uScreenId].w,
917 maFramebuffers[uScreenId].h);
918
919 if (w != 0 && h != 0)
920 pFramebuffer->NotifyUpdate(x, y, w, h);
921
922 pFramebuffer->Unlock();
923
924#ifndef VBOX_WITH_HGSMI
925 if (!mfVideoAccelEnabled)
926 {
927#else
928 if (!mfVideoAccelEnabled && !maFramebuffers[uScreenId].fVBVAEnabled)
929 {
930#endif /* VBOX_WITH_HGSMI */
931 /* When VBVA is enabled, the VRDP server is informed in the VideoAccelFlush.
932 * Inform the server here only if VBVA is disabled.
933 */
934 if (maFramebuffers[uScreenId].u32ResizeStatus == ResizeStatus_Void)
935 mParent->consoleVRDPServer()->SendUpdateBitmap(uScreenId, x, y, w, h);
936 }
937}
938
939void Display::getFramebufferDimensions(int32_t *px1, int32_t *py1,
940 int32_t *px2, int32_t *py2)
941{
942 int32_t x1 = 0, y1 = 0, x2 = 0, y2 = 0;
943 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
944
945 AssertPtrReturnVoid(px1);
946 AssertPtrReturnVoid(py1);
947 AssertPtrReturnVoid(px2);
948 AssertPtrReturnVoid(py2);
949 LogFlowFunc(("\n"));
950
951 if (!mpDrv)
952 return;
953 /* If VBVA is not in use then maFramebuffers will be zeroed out and this
954 * will still work as it should. */
955 if (!(maFramebuffers[0].flags & VBVA_SCREEN_F_DISABLED))
956 {
957 x2 = mpDrv->IConnector.cx + (int32_t)maFramebuffers[0].xOrigin;
958 y2 = mpDrv->IConnector.cy + (int32_t)maFramebuffers[0].yOrigin;
959 }
960 for (unsigned i = 1; i < mcMonitors; ++i)
961 {
962 if (!(maFramebuffers[i].flags & VBVA_SCREEN_F_DISABLED))
963 {
964 x1 = RT_MIN(x1, maFramebuffers[i].xOrigin);
965 y1 = RT_MIN(y1, maFramebuffers[i].yOrigin);
966 x2 = RT_MAX(x2, maFramebuffers[i].xOrigin
967 + (int32_t)maFramebuffers[i].w);
968 y2 = RT_MAX(y2, maFramebuffers[i].yOrigin
969 + (int32_t)maFramebuffers[i].h);
970 }
971 }
972 *px1 = x1;
973 *py1 = y1;
974 *px2 = x2;
975 *py2 = y2;
976}
977
978#ifdef MMSEAMLESS
979static bool displayIntersectRect(RTRECT *prectResult,
980 const RTRECT *prect1,
981 const RTRECT *prect2)
982{
983 /* Initialize result to an empty record. */
984 memset (prectResult, 0, sizeof (RTRECT));
985
986 int xLeftResult = RT_MAX(prect1->xLeft, prect2->xLeft);
987 int xRightResult = RT_MIN(prect1->xRight, prect2->xRight);
988
989 if (xLeftResult < xRightResult)
990 {
991 /* There is intersection by X. */
992
993 int yTopResult = RT_MAX(prect1->yTop, prect2->yTop);
994 int yBottomResult = RT_MIN(prect1->yBottom, prect2->yBottom);
995
996 if (yTopResult < yBottomResult)
997 {
998 /* There is intersection by Y. */
999
1000 prectResult->xLeft = xLeftResult;
1001 prectResult->yTop = yTopResult;
1002 prectResult->xRight = xRightResult;
1003 prectResult->yBottom = yBottomResult;
1004
1005 return true;
1006 }
1007 }
1008
1009 return false;
1010}
1011
1012int Display::handleSetVisibleRegion(uint32_t cRect, PRTRECT pRect)
1013{
1014 RTRECT *pVisibleRegion = (RTRECT *)RTMemTmpAlloc(cRect * sizeof (RTRECT));
1015 if (!pVisibleRegion)
1016 {
1017 return VERR_NO_TMP_MEMORY;
1018 }
1019
1020 unsigned uScreenId;
1021 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
1022 {
1023 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1024
1025 if (!pFBInfo->pFramebuffer.isNull())
1026 {
1027 /* Prepare a new array of rectangles which intersect with the framebuffer.
1028 */
1029 RTRECT rectFramebuffer;
1030 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
1031 {
1032 rectFramebuffer.xLeft = 0;
1033 rectFramebuffer.yTop = 0;
1034 if (mpDrv)
1035 {
1036 rectFramebuffer.xRight = mpDrv->IConnector.cx;
1037 rectFramebuffer.yBottom = mpDrv->IConnector.cy;
1038 }
1039 else
1040 {
1041 rectFramebuffer.xRight = 0;
1042 rectFramebuffer.yBottom = 0;
1043 }
1044 }
1045 else
1046 {
1047 rectFramebuffer.xLeft = pFBInfo->xOrigin;
1048 rectFramebuffer.yTop = pFBInfo->yOrigin;
1049 rectFramebuffer.xRight = pFBInfo->xOrigin + pFBInfo->w;
1050 rectFramebuffer.yBottom = pFBInfo->yOrigin + pFBInfo->h;
1051 }
1052
1053 uint32_t cRectVisibleRegion = 0;
1054
1055 uint32_t i;
1056 for (i = 0; i < cRect; i++)
1057 {
1058 if (displayIntersectRect(&pVisibleRegion[cRectVisibleRegion], &pRect[i], &rectFramebuffer))
1059 {
1060 pVisibleRegion[cRectVisibleRegion].xLeft -= pFBInfo->xOrigin;
1061 pVisibleRegion[cRectVisibleRegion].yTop -= pFBInfo->yOrigin;
1062 pVisibleRegion[cRectVisibleRegion].xRight -= pFBInfo->xOrigin;
1063 pVisibleRegion[cRectVisibleRegion].yBottom -= pFBInfo->yOrigin;
1064
1065 cRectVisibleRegion++;
1066 }
1067 }
1068
1069 if (cRectVisibleRegion > 0)
1070 {
1071 pFBInfo->pFramebuffer->SetVisibleRegion((BYTE *)pVisibleRegion, cRectVisibleRegion);
1072 }
1073 }
1074 }
1075
1076#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
1077 // @todo fix for multimonitor
1078 BOOL is3denabled = FALSE;
1079
1080 mParent->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
1081
1082 VMMDev *vmmDev = mParent->getVMMDev();
1083 if (is3denabled && vmmDev)
1084 {
1085 VBOXHGCMSVCPARM parms[2];
1086
1087 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
1088 parms[0].u.pointer.addr = pRect;
1089 parms[0].u.pointer.size = 0; /* We don't actually care. */
1090 parms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
1091 parms[1].u.uint32 = cRect;
1092
1093 vmmDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VISIBLE_REGION, 2, &parms[0]);
1094 }
1095#endif
1096
1097 RTMemTmpFree(pVisibleRegion);
1098
1099 return VINF_SUCCESS;
1100}
1101
1102int Display::handleQueryVisibleRegion(uint32_t *pcRect, PRTRECT pRect)
1103{
1104 // @todo Currently not used by the guest and is not implemented in framebuffers. Remove?
1105 return VERR_NOT_SUPPORTED;
1106}
1107#endif
1108
1109typedef struct _VBVADIRTYREGION
1110{
1111 /* Copies of object's pointers used by vbvaRgn functions. */
1112 DISPLAYFBINFO *paFramebuffers;
1113 unsigned cMonitors;
1114 Display *pDisplay;
1115 PPDMIDISPLAYPORT pPort;
1116
1117} VBVADIRTYREGION;
1118
1119static void vbvaRgnInit (VBVADIRTYREGION *prgn, DISPLAYFBINFO *paFramebuffers, unsigned cMonitors, Display *pd, PPDMIDISPLAYPORT pp)
1120{
1121 prgn->paFramebuffers = paFramebuffers;
1122 prgn->cMonitors = cMonitors;
1123 prgn->pDisplay = pd;
1124 prgn->pPort = pp;
1125
1126 unsigned uScreenId;
1127 for (uScreenId = 0; uScreenId < cMonitors; uScreenId++)
1128 {
1129 DISPLAYFBINFO *pFBInfo = &prgn->paFramebuffers[uScreenId];
1130
1131 memset (&pFBInfo->dirtyRect, 0, sizeof (pFBInfo->dirtyRect));
1132 }
1133}
1134
1135static void vbvaRgnDirtyRect (VBVADIRTYREGION *prgn, unsigned uScreenId, VBVACMDHDR *phdr)
1136{
1137 LogSunlover (("x = %d, y = %d, w = %d, h = %d\n",
1138 phdr->x, phdr->y, phdr->w, phdr->h));
1139
1140 /*
1141 * Here update rectangles are accumulated to form an update area.
1142 * @todo
1143 * Now the simplest method is used which builds one rectangle that
1144 * includes all update areas. A bit more advanced method can be
1145 * employed here. The method should be fast however.
1146 */
1147 if (phdr->w == 0 || phdr->h == 0)
1148 {
1149 /* Empty rectangle. */
1150 return;
1151 }
1152
1153 int32_t xRight = phdr->x + phdr->w;
1154 int32_t yBottom = phdr->y + phdr->h;
1155
1156 DISPLAYFBINFO *pFBInfo = &prgn->paFramebuffers[uScreenId];
1157
1158 if (pFBInfo->dirtyRect.xRight == 0)
1159 {
1160 /* This is the first rectangle to be added. */
1161 pFBInfo->dirtyRect.xLeft = phdr->x;
1162 pFBInfo->dirtyRect.yTop = phdr->y;
1163 pFBInfo->dirtyRect.xRight = xRight;
1164 pFBInfo->dirtyRect.yBottom = yBottom;
1165 }
1166 else
1167 {
1168 /* Adjust region coordinates. */
1169 if (pFBInfo->dirtyRect.xLeft > phdr->x)
1170 {
1171 pFBInfo->dirtyRect.xLeft = phdr->x;
1172 }
1173
1174 if (pFBInfo->dirtyRect.yTop > phdr->y)
1175 {
1176 pFBInfo->dirtyRect.yTop = phdr->y;
1177 }
1178
1179 if (pFBInfo->dirtyRect.xRight < xRight)
1180 {
1181 pFBInfo->dirtyRect.xRight = xRight;
1182 }
1183
1184 if (pFBInfo->dirtyRect.yBottom < yBottom)
1185 {
1186 pFBInfo->dirtyRect.yBottom = yBottom;
1187 }
1188 }
1189
1190 if (pFBInfo->fDefaultFormat)
1191 {
1192 //@todo pfnUpdateDisplayRect must take the vram offset parameter for the framebuffer
1193 prgn->pPort->pfnUpdateDisplayRect (prgn->pPort, phdr->x, phdr->y, phdr->w, phdr->h);
1194 prgn->pDisplay->handleDisplayUpdateLegacy (phdr->x + pFBInfo->xOrigin,
1195 phdr->y + pFBInfo->yOrigin, phdr->w, phdr->h);
1196 }
1197
1198 return;
1199}
1200
1201static void vbvaRgnUpdateFramebuffer (VBVADIRTYREGION *prgn, unsigned uScreenId)
1202{
1203 DISPLAYFBINFO *pFBInfo = &prgn->paFramebuffers[uScreenId];
1204
1205 uint32_t w = pFBInfo->dirtyRect.xRight - pFBInfo->dirtyRect.xLeft;
1206 uint32_t h = pFBInfo->dirtyRect.yBottom - pFBInfo->dirtyRect.yTop;
1207
1208 if (!pFBInfo->fDefaultFormat && pFBInfo->pFramebuffer && w != 0 && h != 0)
1209 {
1210 //@todo pfnUpdateDisplayRect must take the vram offset parameter for the framebuffer
1211 prgn->pPort->pfnUpdateDisplayRect (prgn->pPort, pFBInfo->dirtyRect.xLeft, pFBInfo->dirtyRect.yTop, w, h);
1212 prgn->pDisplay->handleDisplayUpdateLegacy (pFBInfo->dirtyRect.xLeft + pFBInfo->xOrigin,
1213 pFBInfo->dirtyRect.yTop + pFBInfo->yOrigin, w, h);
1214 }
1215}
1216
1217static void vbvaSetMemoryFlags (VBVAMEMORY *pVbvaMemory,
1218 bool fVideoAccelEnabled,
1219 bool fVideoAccelVRDP,
1220 uint32_t fu32SupportedOrders,
1221 DISPLAYFBINFO *paFBInfos,
1222 unsigned cFBInfos)
1223{
1224 if (pVbvaMemory)
1225 {
1226 /* This called only on changes in mode. So reset VRDP always. */
1227 uint32_t fu32Flags = VBVA_F_MODE_VRDP_RESET;
1228
1229 if (fVideoAccelEnabled)
1230 {
1231 fu32Flags |= VBVA_F_MODE_ENABLED;
1232
1233 if (fVideoAccelVRDP)
1234 {
1235 fu32Flags |= VBVA_F_MODE_VRDP | VBVA_F_MODE_VRDP_ORDER_MASK;
1236
1237 pVbvaMemory->fu32SupportedOrders = fu32SupportedOrders;
1238 }
1239 }
1240
1241 pVbvaMemory->fu32ModeFlags = fu32Flags;
1242 }
1243
1244 unsigned uScreenId;
1245 for (uScreenId = 0; uScreenId < cFBInfos; uScreenId++)
1246 {
1247 if (paFBInfos[uScreenId].pHostEvents)
1248 {
1249 paFBInfos[uScreenId].pHostEvents->fu32Events |= VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
1250 }
1251 }
1252}
1253
1254#ifdef VBOX_WITH_HGSMI
1255static void vbvaSetMemoryFlagsHGSMI (unsigned uScreenId,
1256 uint32_t fu32SupportedOrders,
1257 bool fVideoAccelVRDP,
1258 DISPLAYFBINFO *pFBInfo)
1259{
1260 LogFlowFunc(("HGSMI[%d]: %p\n", uScreenId, pFBInfo->pVBVAHostFlags));
1261
1262 if (pFBInfo->pVBVAHostFlags)
1263 {
1264 uint32_t fu32HostEvents = VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
1265
1266 if (pFBInfo->fVBVAEnabled)
1267 {
1268 fu32HostEvents |= VBVA_F_MODE_ENABLED;
1269
1270 if (fVideoAccelVRDP)
1271 {
1272 fu32HostEvents |= VBVA_F_MODE_VRDP;
1273 }
1274 }
1275
1276 ASMAtomicWriteU32(&pFBInfo->pVBVAHostFlags->u32HostEvents, fu32HostEvents);
1277 ASMAtomicWriteU32(&pFBInfo->pVBVAHostFlags->u32SupportedOrders, fu32SupportedOrders);
1278
1279 LogFlowFunc((" fu32HostEvents = 0x%08X, fu32SupportedOrders = 0x%08X\n", fu32HostEvents, fu32SupportedOrders));
1280 }
1281}
1282
1283static void vbvaSetMemoryFlagsAllHGSMI (uint32_t fu32SupportedOrders,
1284 bool fVideoAccelVRDP,
1285 DISPLAYFBINFO *paFBInfos,
1286 unsigned cFBInfos)
1287{
1288 unsigned uScreenId;
1289
1290 for (uScreenId = 0; uScreenId < cFBInfos; uScreenId++)
1291 {
1292 vbvaSetMemoryFlagsHGSMI(uScreenId, fu32SupportedOrders, fVideoAccelVRDP, &paFBInfos[uScreenId]);
1293 }
1294}
1295#endif /* VBOX_WITH_HGSMI */
1296
1297bool Display::VideoAccelAllowed (void)
1298{
1299 return true;
1300}
1301
1302#ifdef VBOX_WITH_OLD_VBVA_LOCK
1303int Display::vbvaLock(void)
1304{
1305 return RTCritSectEnter(&mVBVALock);
1306}
1307
1308void Display::vbvaUnlock(void)
1309{
1310 RTCritSectLeave(&mVBVALock);
1311}
1312#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1313
1314/**
1315 * @thread EMT
1316 */
1317#ifdef VBOX_WITH_OLD_VBVA_LOCK
1318int Display::VideoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory)
1319{
1320 int rc;
1321 vbvaLock();
1322 rc = videoAccelEnable (fEnable, pVbvaMemory);
1323 vbvaUnlock();
1324 return rc;
1325}
1326#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1327
1328#ifdef VBOX_WITH_OLD_VBVA_LOCK
1329int Display::videoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory)
1330#else
1331int Display::VideoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory)
1332#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1333{
1334 int rc = VINF_SUCCESS;
1335
1336 /* Called each time the guest wants to use acceleration,
1337 * or when the VGA device disables acceleration,
1338 * or when restoring the saved state with accel enabled.
1339 *
1340 * VGA device disables acceleration on each video mode change
1341 * and on reset.
1342 *
1343 * Guest enabled acceleration at will. And it has to enable
1344 * acceleration after a mode change.
1345 */
1346 LogFlowFunc (("mfVideoAccelEnabled = %d, fEnable = %d, pVbvaMemory = %p\n",
1347 mfVideoAccelEnabled, fEnable, pVbvaMemory));
1348
1349 /* Strictly check parameters. Callers must not pass anything in the case. */
1350 Assert((fEnable && pVbvaMemory) || (!fEnable && pVbvaMemory == NULL));
1351
1352 if (!VideoAccelAllowed ())
1353 return VERR_NOT_SUPPORTED;
1354
1355 /*
1356 * Verify that the VM is in running state. If it is not,
1357 * then this must be postponed until it goes to running.
1358 */
1359 if (!mfMachineRunning)
1360 {
1361 Assert (!mfVideoAccelEnabled);
1362
1363 LogFlowFunc (("Machine is not yet running.\n"));
1364
1365 if (fEnable)
1366 {
1367 mfPendingVideoAccelEnable = fEnable;
1368 mpPendingVbvaMemory = pVbvaMemory;
1369 }
1370
1371 return rc;
1372 }
1373
1374 /* Check that current status is not being changed */
1375 if (mfVideoAccelEnabled == fEnable)
1376 return rc;
1377
1378 if (mfVideoAccelEnabled)
1379 {
1380 /* Process any pending orders and empty the VBVA ring buffer. */
1381#ifdef VBOX_WITH_OLD_VBVA_LOCK
1382 videoAccelFlush ();
1383#else
1384 VideoAccelFlush ();
1385#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1386 }
1387
1388 if (!fEnable && mpVbvaMemory)
1389 mpVbvaMemory->fu32ModeFlags &= ~VBVA_F_MODE_ENABLED;
1390
1391 /* Safety precaution. There is no more VBVA until everything is setup! */
1392 mpVbvaMemory = NULL;
1393 mfVideoAccelEnabled = false;
1394
1395 /* Update entire display. */
1396 if (maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].u32ResizeStatus == ResizeStatus_Void)
1397 mpDrv->pUpPort->pfnUpdateDisplayAll(mpDrv->pUpPort);
1398
1399 /* Everything OK. VBVA status can be changed. */
1400
1401 /* Notify the VMMDev, which saves VBVA status in the saved state,
1402 * and needs to know current status.
1403 */
1404 VMMDev *pVMMDev = mParent->getVMMDev();
1405 if (pVMMDev)
1406 {
1407 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
1408 if (pVMMDevPort)
1409 pVMMDevPort->pfnVBVAChange(pVMMDevPort, fEnable);
1410 }
1411
1412 if (fEnable)
1413 {
1414 mpVbvaMemory = pVbvaMemory;
1415 mfVideoAccelEnabled = true;
1416
1417 /* Initialize the hardware memory. */
1418 vbvaSetMemoryFlags(mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
1419 mpVbvaMemory->off32Data = 0;
1420 mpVbvaMemory->off32Free = 0;
1421
1422 memset(mpVbvaMemory->aRecords, 0, sizeof (mpVbvaMemory->aRecords));
1423 mpVbvaMemory->indexRecordFirst = 0;
1424 mpVbvaMemory->indexRecordFree = 0;
1425
1426#ifdef VBOX_WITH_OLD_VBVA_LOCK
1427 mfu32PendingVideoAccelDisable = false;
1428#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1429
1430 LogRel(("VBVA: Enabled.\n"));
1431 }
1432 else
1433 {
1434 LogRel(("VBVA: Disabled.\n"));
1435 }
1436
1437 LogFlowFunc (("VideoAccelEnable: rc = %Rrc.\n", rc));
1438
1439 return rc;
1440}
1441
1442/* Called always by one VRDP server thread. Can be thread-unsafe.
1443 */
1444void Display::VideoAccelVRDP (bool fEnable)
1445{
1446 LogFlowFunc(("fEnable = %d\n", fEnable));
1447
1448#ifdef VBOX_WITH_OLD_VBVA_LOCK
1449 vbvaLock();
1450#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1451
1452 int c = fEnable?
1453 ASMAtomicIncS32 (&mcVideoAccelVRDPRefs):
1454 ASMAtomicDecS32 (&mcVideoAccelVRDPRefs);
1455
1456 Assert (c >= 0);
1457
1458 if (c == 0)
1459 {
1460 /* The last client has disconnected, and the accel can be
1461 * disabled.
1462 */
1463 Assert (fEnable == false);
1464
1465 mfVideoAccelVRDP = false;
1466 mfu32SupportedOrders = 0;
1467
1468 vbvaSetMemoryFlags (mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
1469#ifdef VBOX_WITH_HGSMI
1470 /* Here is VRDP-IN thread. Process the request in vbvaUpdateBegin under DevVGA lock on an EMT. */
1471 ASMAtomicIncU32(&mu32UpdateVBVAFlags);
1472#endif /* VBOX_WITH_HGSMI */
1473
1474 LogRel(("VBVA: VRDP acceleration has been disabled.\n"));
1475 }
1476 else if ( c == 1
1477 && !mfVideoAccelVRDP)
1478 {
1479 /* The first client has connected. Enable the accel.
1480 */
1481 Assert (fEnable == true);
1482
1483 mfVideoAccelVRDP = true;
1484 /* Supporting all orders. */
1485 mfu32SupportedOrders = ~0;
1486
1487 vbvaSetMemoryFlags (mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
1488#ifdef VBOX_WITH_HGSMI
1489 /* Here is VRDP-IN thread. Process the request in vbvaUpdateBegin under DevVGA lock on an EMT. */
1490 ASMAtomicIncU32(&mu32UpdateVBVAFlags);
1491#endif /* VBOX_WITH_HGSMI */
1492
1493 LogRel(("VBVA: VRDP acceleration has been requested.\n"));
1494 }
1495 else
1496 {
1497 /* A client is connected or disconnected but there is no change in the
1498 * accel state. It remains enabled.
1499 */
1500 Assert (mfVideoAccelVRDP == true);
1501 }
1502#ifdef VBOX_WITH_OLD_VBVA_LOCK
1503 vbvaUnlock();
1504#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1505}
1506
1507static bool vbvaVerifyRingBuffer (VBVAMEMORY *pVbvaMemory)
1508{
1509 return true;
1510}
1511
1512static void vbvaFetchBytes (VBVAMEMORY *pVbvaMemory, uint8_t *pu8Dst, uint32_t cbDst)
1513{
1514 if (cbDst >= VBVA_RING_BUFFER_SIZE)
1515 {
1516 AssertMsgFailed (("cbDst = 0x%08X, ring buffer size 0x%08X", cbDst, VBVA_RING_BUFFER_SIZE));
1517 return;
1518 }
1519
1520 uint32_t u32BytesTillBoundary = VBVA_RING_BUFFER_SIZE - pVbvaMemory->off32Data;
1521 uint8_t *src = &pVbvaMemory->au8RingBuffer[pVbvaMemory->off32Data];
1522 int32_t i32Diff = cbDst - u32BytesTillBoundary;
1523
1524 if (i32Diff <= 0)
1525 {
1526 /* Chunk will not cross buffer boundary. */
1527 memcpy (pu8Dst, src, cbDst);
1528 }
1529 else
1530 {
1531 /* Chunk crosses buffer boundary. */
1532 memcpy (pu8Dst, src, u32BytesTillBoundary);
1533 memcpy (pu8Dst + u32BytesTillBoundary, &pVbvaMemory->au8RingBuffer[0], i32Diff);
1534 }
1535
1536 /* Advance data offset. */
1537 pVbvaMemory->off32Data = (pVbvaMemory->off32Data + cbDst) % VBVA_RING_BUFFER_SIZE;
1538
1539 return;
1540}
1541
1542
1543static bool vbvaPartialRead (uint8_t **ppu8, uint32_t *pcb, uint32_t cbRecord, VBVAMEMORY *pVbvaMemory)
1544{
1545 uint8_t *pu8New;
1546
1547 LogFlow(("MAIN::DisplayImpl::vbvaPartialRead: p = %p, cb = %d, cbRecord 0x%08X\n",
1548 *ppu8, *pcb, cbRecord));
1549
1550 if (*ppu8)
1551 {
1552 Assert (*pcb);
1553 pu8New = (uint8_t *)RTMemRealloc (*ppu8, cbRecord);
1554 }
1555 else
1556 {
1557 Assert (!*pcb);
1558 pu8New = (uint8_t *)RTMemAlloc (cbRecord);
1559 }
1560
1561 if (!pu8New)
1562 {
1563 /* Memory allocation failed, fail the function. */
1564 Log(("MAIN::vbvaPartialRead: failed to (re)alocate memory for partial record!!! cbRecord 0x%08X\n",
1565 cbRecord));
1566
1567 if (*ppu8)
1568 {
1569 RTMemFree (*ppu8);
1570 }
1571
1572 *ppu8 = NULL;
1573 *pcb = 0;
1574
1575 return false;
1576 }
1577
1578 /* Fetch data from the ring buffer. */
1579 vbvaFetchBytes (pVbvaMemory, pu8New + *pcb, cbRecord - *pcb);
1580
1581 *ppu8 = pu8New;
1582 *pcb = cbRecord;
1583
1584 return true;
1585}
1586
1587/* For contiguous chunks just return the address in the buffer.
1588 * For crossing boundary - allocate a buffer from heap.
1589 */
1590bool Display::vbvaFetchCmd (VBVACMDHDR **ppHdr, uint32_t *pcbCmd)
1591{
1592 uint32_t indexRecordFirst = mpVbvaMemory->indexRecordFirst;
1593 uint32_t indexRecordFree = mpVbvaMemory->indexRecordFree;
1594
1595#ifdef DEBUG_sunlover
1596 LogFlowFunc (("first = %d, free = %d\n",
1597 indexRecordFirst, indexRecordFree));
1598#endif /* DEBUG_sunlover */
1599
1600 if (!vbvaVerifyRingBuffer (mpVbvaMemory))
1601 {
1602 return false;
1603 }
1604
1605 if (indexRecordFirst == indexRecordFree)
1606 {
1607 /* No records to process. Return without assigning output variables. */
1608 return true;
1609 }
1610
1611 VBVARECORD *pRecord = &mpVbvaMemory->aRecords[indexRecordFirst];
1612
1613#ifdef DEBUG_sunlover
1614 LogFlowFunc (("cbRecord = 0x%08X\n", pRecord->cbRecord));
1615#endif /* DEBUG_sunlover */
1616
1617 uint32_t cbRecord = pRecord->cbRecord & ~VBVA_F_RECORD_PARTIAL;
1618
1619 if (mcbVbvaPartial)
1620 {
1621 /* There is a partial read in process. Continue with it. */
1622
1623 Assert (mpu8VbvaPartial);
1624
1625 LogFlowFunc (("continue partial record mcbVbvaPartial = %d cbRecord 0x%08X, first = %d, free = %d\n",
1626 mcbVbvaPartial, pRecord->cbRecord, indexRecordFirst, indexRecordFree));
1627
1628 if (cbRecord > mcbVbvaPartial)
1629 {
1630 /* New data has been added to the record. */
1631 if (!vbvaPartialRead (&mpu8VbvaPartial, &mcbVbvaPartial, cbRecord, mpVbvaMemory))
1632 {
1633 return false;
1634 }
1635 }
1636
1637 if (!(pRecord->cbRecord & VBVA_F_RECORD_PARTIAL))
1638 {
1639 /* The record is completed by guest. Return it to the caller. */
1640 *ppHdr = (VBVACMDHDR *)mpu8VbvaPartial;
1641 *pcbCmd = mcbVbvaPartial;
1642
1643 mpu8VbvaPartial = NULL;
1644 mcbVbvaPartial = 0;
1645
1646 /* Advance the record index. */
1647 mpVbvaMemory->indexRecordFirst = (indexRecordFirst + 1) % VBVA_MAX_RECORDS;
1648
1649#ifdef DEBUG_sunlover
1650 LogFlowFunc (("partial done ok, data = %d, free = %d\n",
1651 mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1652#endif /* DEBUG_sunlover */
1653 }
1654
1655 return true;
1656 }
1657
1658 /* A new record need to be processed. */
1659 if (pRecord->cbRecord & VBVA_F_RECORD_PARTIAL)
1660 {
1661 /* Current record is being written by guest. '=' is important here. */
1662 if (cbRecord >= VBVA_RING_BUFFER_SIZE - VBVA_RING_BUFFER_THRESHOLD)
1663 {
1664 /* Partial read must be started. */
1665 if (!vbvaPartialRead (&mpu8VbvaPartial, &mcbVbvaPartial, cbRecord, mpVbvaMemory))
1666 {
1667 return false;
1668 }
1669
1670 LogFlowFunc (("started partial record mcbVbvaPartial = 0x%08X cbRecord 0x%08X, first = %d, free = %d\n",
1671 mcbVbvaPartial, pRecord->cbRecord, indexRecordFirst, indexRecordFree));
1672 }
1673
1674 return true;
1675 }
1676
1677 /* Current record is complete. If it is not empty, process it. */
1678 if (cbRecord)
1679 {
1680 /* The size of largest contiguous chunk in the ring biffer. */
1681 uint32_t u32BytesTillBoundary = VBVA_RING_BUFFER_SIZE - mpVbvaMemory->off32Data;
1682
1683 /* The ring buffer pointer. */
1684 uint8_t *au8RingBuffer = &mpVbvaMemory->au8RingBuffer[0];
1685
1686 /* The pointer to data in the ring buffer. */
1687 uint8_t *src = &au8RingBuffer[mpVbvaMemory->off32Data];
1688
1689 /* Fetch or point the data. */
1690 if (u32BytesTillBoundary >= cbRecord)
1691 {
1692 /* The command does not cross buffer boundary. Return address in the buffer. */
1693 *ppHdr = (VBVACMDHDR *)src;
1694
1695 /* Advance data offset. */
1696 mpVbvaMemory->off32Data = (mpVbvaMemory->off32Data + cbRecord) % VBVA_RING_BUFFER_SIZE;
1697 }
1698 else
1699 {
1700 /* The command crosses buffer boundary. Rare case, so not optimized. */
1701 uint8_t *dst = (uint8_t *)RTMemAlloc (cbRecord);
1702
1703 if (!dst)
1704 {
1705 LogFlowFunc (("could not allocate %d bytes from heap!!!\n", cbRecord));
1706 mpVbvaMemory->off32Data = (mpVbvaMemory->off32Data + cbRecord) % VBVA_RING_BUFFER_SIZE;
1707 return false;
1708 }
1709
1710 vbvaFetchBytes (mpVbvaMemory, dst, cbRecord);
1711
1712 *ppHdr = (VBVACMDHDR *)dst;
1713
1714#ifdef DEBUG_sunlover
1715 LogFlowFunc (("Allocated from heap %p\n", dst));
1716#endif /* DEBUG_sunlover */
1717 }
1718 }
1719
1720 *pcbCmd = cbRecord;
1721
1722 /* Advance the record index. */
1723 mpVbvaMemory->indexRecordFirst = (indexRecordFirst + 1) % VBVA_MAX_RECORDS;
1724
1725#ifdef DEBUG_sunlover
1726 LogFlowFunc (("done ok, data = %d, free = %d\n",
1727 mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1728#endif /* DEBUG_sunlover */
1729
1730 return true;
1731}
1732
1733void Display::vbvaReleaseCmd (VBVACMDHDR *pHdr, int32_t cbCmd)
1734{
1735 uint8_t *au8RingBuffer = mpVbvaMemory->au8RingBuffer;
1736
1737 if ( (uint8_t *)pHdr >= au8RingBuffer
1738 && (uint8_t *)pHdr < &au8RingBuffer[VBVA_RING_BUFFER_SIZE])
1739 {
1740 /* The pointer is inside ring buffer. Must be continuous chunk. */
1741 Assert (VBVA_RING_BUFFER_SIZE - ((uint8_t *)pHdr - au8RingBuffer) >= cbCmd);
1742
1743 /* Do nothing. */
1744
1745 Assert (!mpu8VbvaPartial && mcbVbvaPartial == 0);
1746 }
1747 else
1748 {
1749 /* The pointer is outside. It is then an allocated copy. */
1750
1751#ifdef DEBUG_sunlover
1752 LogFlowFunc (("Free heap %p\n", pHdr));
1753#endif /* DEBUG_sunlover */
1754
1755 if ((uint8_t *)pHdr == mpu8VbvaPartial)
1756 {
1757 mpu8VbvaPartial = NULL;
1758 mcbVbvaPartial = 0;
1759 }
1760 else
1761 {
1762 Assert (!mpu8VbvaPartial && mcbVbvaPartial == 0);
1763 }
1764
1765 RTMemFree (pHdr);
1766 }
1767
1768 return;
1769}
1770
1771
1772/**
1773 * Called regularly on the DisplayRefresh timer.
1774 * Also on behalf of guest, when the ring buffer is full.
1775 *
1776 * @thread EMT
1777 */
1778#ifdef VBOX_WITH_OLD_VBVA_LOCK
1779void Display::VideoAccelFlush (void)
1780{
1781 vbvaLock();
1782 videoAccelFlush();
1783 vbvaUnlock();
1784}
1785#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1786
1787#ifdef VBOX_WITH_OLD_VBVA_LOCK
1788/* Under VBVA lock. DevVGA is not taken. */
1789void Display::videoAccelFlush (void)
1790#else
1791void Display::VideoAccelFlush (void)
1792#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1793{
1794#ifdef DEBUG_sunlover_2
1795 LogFlowFunc (("mfVideoAccelEnabled = %d\n", mfVideoAccelEnabled));
1796#endif /* DEBUG_sunlover_2 */
1797
1798 if (!mfVideoAccelEnabled)
1799 {
1800 Log(("Display::VideoAccelFlush: called with disabled VBVA!!! Ignoring.\n"));
1801 return;
1802 }
1803
1804 /* Here VBVA is enabled and we have the accelerator memory pointer. */
1805 Assert(mpVbvaMemory);
1806
1807#ifdef DEBUG_sunlover_2
1808 LogFlowFunc (("indexRecordFirst = %d, indexRecordFree = %d, off32Data = %d, off32Free = %d\n",
1809 mpVbvaMemory->indexRecordFirst, mpVbvaMemory->indexRecordFree, mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1810#endif /* DEBUG_sunlover_2 */
1811
1812 /* Quick check for "nothing to update" case. */
1813 if (mpVbvaMemory->indexRecordFirst == mpVbvaMemory->indexRecordFree)
1814 {
1815 return;
1816 }
1817
1818 /* Process the ring buffer */
1819 unsigned uScreenId;
1820#ifndef VBOX_WITH_OLD_VBVA_LOCK
1821 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
1822 {
1823 if (!maFramebuffers[uScreenId].pFramebuffer.isNull())
1824 {
1825 maFramebuffers[uScreenId].pFramebuffer->Lock ();
1826 }
1827 }
1828#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1829
1830 /* Initialize dirty rectangles accumulator. */
1831 VBVADIRTYREGION rgn;
1832 vbvaRgnInit (&rgn, maFramebuffers, mcMonitors, this, mpDrv->pUpPort);
1833
1834 for (;;)
1835 {
1836 VBVACMDHDR *phdr = NULL;
1837 uint32_t cbCmd = ~0;
1838
1839 /* Fetch the command data. */
1840 if (!vbvaFetchCmd (&phdr, &cbCmd))
1841 {
1842 Log(("Display::VideoAccelFlush: unable to fetch command. off32Data = %d, off32Free = %d. Disabling VBVA!!!\n",
1843 mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1844
1845 /* Disable VBVA on those processing errors. */
1846#ifdef VBOX_WITH_OLD_VBVA_LOCK
1847 videoAccelEnable (false, NULL);
1848#else
1849 VideoAccelEnable (false, NULL);
1850#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1851
1852 break;
1853 }
1854
1855 if (cbCmd == uint32_t(~0))
1856 {
1857 /* No more commands yet in the queue. */
1858 break;
1859 }
1860
1861 if (cbCmd != 0)
1862 {
1863#ifdef DEBUG_sunlover
1864 LogFlowFunc (("hdr: cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
1865 cbCmd, phdr->x, phdr->y, phdr->w, phdr->h));
1866#endif /* DEBUG_sunlover */
1867
1868 VBVACMDHDR hdrSaved = *phdr;
1869
1870 int x = phdr->x;
1871 int y = phdr->y;
1872 int w = phdr->w;
1873 int h = phdr->h;
1874
1875 uScreenId = mapCoordsToScreen(maFramebuffers, mcMonitors, &x, &y, &w, &h);
1876
1877 phdr->x = (int16_t)x;
1878 phdr->y = (int16_t)y;
1879 phdr->w = (uint16_t)w;
1880 phdr->h = (uint16_t)h;
1881
1882 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1883
1884 if (pFBInfo->u32ResizeStatus == ResizeStatus_Void)
1885 {
1886 /* Handle the command.
1887 *
1888 * Guest is responsible for updating the guest video memory.
1889 * The Windows guest does all drawing using Eng*.
1890 *
1891 * For local output, only dirty rectangle information is used
1892 * to update changed areas.
1893 *
1894 * Dirty rectangles are accumulated to exclude overlapping updates and
1895 * group small updates to a larger one.
1896 */
1897
1898 /* Accumulate the update. */
1899 vbvaRgnDirtyRect (&rgn, uScreenId, phdr);
1900
1901 /* Forward the command to VRDP server. */
1902 mParent->consoleVRDPServer()->SendUpdate (uScreenId, phdr, cbCmd);
1903
1904 *phdr = hdrSaved;
1905 }
1906 }
1907
1908 vbvaReleaseCmd (phdr, cbCmd);
1909 }
1910
1911 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
1912 {
1913#ifndef VBOX_WITH_OLD_VBVA_LOCK
1914 if (!maFramebuffers[uScreenId].pFramebuffer.isNull())
1915 {
1916 maFramebuffers[uScreenId].pFramebuffer->Unlock ();
1917 }
1918#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1919
1920 if (maFramebuffers[uScreenId].u32ResizeStatus == ResizeStatus_Void)
1921 {
1922 /* Draw the framebuffer. */
1923 vbvaRgnUpdateFramebuffer (&rgn, uScreenId);
1924 }
1925 }
1926}
1927
1928#ifdef VBOX_WITH_OLD_VBVA_LOCK
1929int Display::videoAccelRefreshProcess(void)
1930{
1931 int rc = VWRN_INVALID_STATE; /* Default is to do a display update in VGA device. */
1932
1933 vbvaLock();
1934
1935 if (ASMAtomicCmpXchgU32(&mfu32PendingVideoAccelDisable, false, true))
1936 {
1937 videoAccelEnable (false, NULL);
1938 }
1939 else if (mfPendingVideoAccelEnable)
1940 {
1941 /* Acceleration was enabled while machine was not yet running
1942 * due to restoring from saved state. Update entire display and
1943 * actually enable acceleration.
1944 */
1945 Assert(mpPendingVbvaMemory);
1946
1947 /* Acceleration can not be yet enabled.*/
1948 Assert(mpVbvaMemory == NULL);
1949 Assert(!mfVideoAccelEnabled);
1950
1951 if (mfMachineRunning)
1952 {
1953 videoAccelEnable (mfPendingVideoAccelEnable,
1954 mpPendingVbvaMemory);
1955
1956 /* Reset the pending state. */
1957 mfPendingVideoAccelEnable = false;
1958 mpPendingVbvaMemory = NULL;
1959 }
1960
1961 rc = VINF_TRY_AGAIN;
1962 }
1963 else
1964 {
1965 Assert(mpPendingVbvaMemory == NULL);
1966
1967 if (mfVideoAccelEnabled)
1968 {
1969 Assert(mpVbvaMemory);
1970 videoAccelFlush ();
1971
1972 rc = VINF_SUCCESS; /* VBVA processed, no need to a display update. */
1973 }
1974 }
1975
1976 vbvaUnlock();
1977
1978 return rc;
1979}
1980#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1981
1982
1983// IDisplay methods
1984/////////////////////////////////////////////////////////////////////////////
1985STDMETHODIMP Display::GetScreenResolution (ULONG aScreenId,
1986 ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel)
1987{
1988 LogFlowFunc (("aScreenId = %d\n", aScreenId));
1989
1990 AutoCaller autoCaller(this);
1991 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1992
1993 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1994
1995 uint32_t u32Width = 0;
1996 uint32_t u32Height = 0;
1997 uint32_t u32BitsPerPixel = 0;
1998
1999 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2000 {
2001 CHECK_CONSOLE_DRV (mpDrv);
2002
2003 u32Width = mpDrv->IConnector.cx;
2004 u32Height = mpDrv->IConnector.cy;
2005 int rc = mpDrv->pUpPort->pfnQueryColorDepth(mpDrv->pUpPort, &u32BitsPerPixel);
2006 AssertRC(rc);
2007 }
2008 else if (aScreenId < mcMonitors)
2009 {
2010 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
2011 u32Width = pFBInfo->w;
2012 u32Height = pFBInfo->h;
2013 u32BitsPerPixel = pFBInfo->u16BitsPerPixel;
2014 }
2015 else
2016 {
2017 return E_INVALIDARG;
2018 }
2019
2020 if (aWidth)
2021 *aWidth = u32Width;
2022 if (aHeight)
2023 *aHeight = u32Height;
2024 if (aBitsPerPixel)
2025 *aBitsPerPixel = u32BitsPerPixel;
2026
2027 return S_OK;
2028}
2029
2030STDMETHODIMP Display::SetFramebuffer (ULONG aScreenId,
2031 IFramebuffer *aFramebuffer)
2032{
2033 LogFlowFunc (("\n"));
2034
2035 if (aFramebuffer != NULL)
2036 CheckComArgOutPointerValid(aFramebuffer);
2037
2038 AutoCaller autoCaller(this);
2039 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2040
2041 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2042
2043 Console::SafeVMPtrQuiet pVM (mParent);
2044 if (pVM.isOk())
2045 {
2046 /* Must leave the lock here because the changeFramebuffer will
2047 * also obtain it. */
2048 alock.leave ();
2049
2050 /* send request to the EMT thread */
2051 int vrc = VMR3ReqCallWait (pVM, VMCPUID_ANY,
2052 (PFNRT) changeFramebuffer, 3, this, aFramebuffer, aScreenId);
2053
2054 alock.enter ();
2055
2056 ComAssertRCRet (vrc, E_FAIL);
2057
2058#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
2059 {
2060 BOOL is3denabled;
2061 mParent->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
2062
2063 if (is3denabled)
2064 {
2065 VBOXHGCMSVCPARM parm;
2066
2067 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2068 parm.u.uint32 = aScreenId;
2069
2070 VMMDev *pVMMDev = mParent->getVMMDev();
2071
2072 alock.leave ();
2073
2074 if (pVMMDev)
2075 vrc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SCREEN_CHANGED, SHCRGL_CPARMS_SCREEN_CHANGED, &parm);
2076 /*ComAssertRCRet (vrc, E_FAIL);*/
2077
2078 alock.enter ();
2079 }
2080 }
2081#endif /* VBOX_WITH_CROGL */
2082 }
2083 else
2084 {
2085 /* No VM is created (VM is powered off), do a direct call */
2086 int vrc = changeFramebuffer (this, aFramebuffer, aScreenId);
2087 ComAssertRCRet (vrc, E_FAIL);
2088 }
2089
2090 return S_OK;
2091}
2092
2093STDMETHODIMP Display::GetFramebuffer (ULONG aScreenId,
2094 IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin)
2095{
2096 LogFlowFunc (("aScreenId = %d\n", aScreenId));
2097
2098 CheckComArgOutPointerValid(aFramebuffer);
2099
2100 AutoCaller autoCaller(this);
2101 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2102
2103 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2104
2105 if (aScreenId != 0 && aScreenId >= mcMonitors)
2106 return E_INVALIDARG;
2107
2108 /* @todo this should be actually done on EMT. */
2109 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
2110
2111 *aFramebuffer = pFBInfo->pFramebuffer;
2112 if (*aFramebuffer)
2113 (*aFramebuffer)->AddRef ();
2114 if (aXOrigin)
2115 *aXOrigin = pFBInfo->xOrigin;
2116 if (aYOrigin)
2117 *aYOrigin = pFBInfo->yOrigin;
2118
2119 return S_OK;
2120}
2121
2122STDMETHODIMP Display::SetVideoModeHint(ULONG aWidth, ULONG aHeight,
2123 ULONG aBitsPerPixel, ULONG aDisplay)
2124{
2125 AutoCaller autoCaller(this);
2126 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2127
2128 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2129
2130 CHECK_CONSOLE_DRV (mpDrv);
2131
2132 /*
2133 * Do some rough checks for valid input
2134 */
2135 ULONG width = aWidth;
2136 if (!width)
2137 width = mpDrv->IConnector.cx;
2138 ULONG height = aHeight;
2139 if (!height)
2140 height = mpDrv->IConnector.cy;
2141 ULONG bpp = aBitsPerPixel;
2142 if (!bpp)
2143 {
2144 uint32_t cBits = 0;
2145 int rc = mpDrv->pUpPort->pfnQueryColorDepth(mpDrv->pUpPort, &cBits);
2146 AssertRC(rc);
2147 bpp = cBits;
2148 }
2149 ULONG cMonitors;
2150 mParent->machine()->COMGETTER(MonitorCount)(&cMonitors);
2151 if (cMonitors == 0 && aDisplay > 0)
2152 return E_INVALIDARG;
2153 if (aDisplay >= cMonitors)
2154 return E_INVALIDARG;
2155
2156// sunlover 20070614: It is up to the guest to decide whether the hint is valid.
2157// ULONG vramSize;
2158// mParent->machine()->COMGETTER(VRAMSize)(&vramSize);
2159// /* enough VRAM? */
2160// if ((width * height * (bpp / 8)) > (vramSize * 1024 * 1024))
2161// return setError(E_FAIL, tr("Not enough VRAM for the selected video mode"));
2162
2163 /* Have to leave the lock because the pfnRequestDisplayChange
2164 * will call EMT. */
2165 alock.leave ();
2166
2167 VMMDev *pVMMDev = mParent->getVMMDev();
2168 if (pVMMDev)
2169 {
2170 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
2171 if (pVMMDevPort)
2172 pVMMDevPort->pfnRequestDisplayChange(pVMMDevPort, aWidth, aHeight, aBitsPerPixel, aDisplay);
2173 }
2174 return S_OK;
2175}
2176
2177STDMETHODIMP Display::SetSeamlessMode (BOOL enabled)
2178{
2179 AutoCaller autoCaller(this);
2180 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2181
2182 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2183
2184 /* Have to leave the lock because the pfnRequestSeamlessChange will call EMT. */
2185 alock.leave ();
2186
2187 VMMDev *pVMMDev = mParent->getVMMDev();
2188 if (pVMMDev)
2189 {
2190 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
2191 if (pVMMDevPort)
2192 pVMMDevPort->pfnRequestSeamlessChange(pVMMDevPort, !!enabled);
2193 }
2194 return S_OK;
2195}
2196
2197#ifdef VBOX_WITH_OLD_VBVA_LOCK
2198int Display::displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height)
2199{
2200 int rc;
2201 pDisplay->vbvaLock();
2202 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2203 {
2204 rc = pDisplay->mpDrv->pUpPort->pfnTakeScreenshot(pDisplay->mpDrv->pUpPort, ppu8Data, pcbData, pu32Width, pu32Height);
2205 }
2206 else if (aScreenId < pDisplay->mcMonitors)
2207 {
2208 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[aScreenId];
2209
2210 uint32_t width = pFBInfo->w;
2211 uint32_t height = pFBInfo->h;
2212
2213 /* Allocate 32 bit per pixel bitmap. */
2214 size_t cbRequired = width * 4 * height;
2215
2216 if (cbRequired)
2217 {
2218 uint8_t *pu8Data = (uint8_t *)RTMemAlloc(cbRequired);
2219
2220 if (pu8Data == NULL)
2221 {
2222 rc = VERR_NO_MEMORY;
2223 }
2224 else
2225 {
2226 /* Copy guest VRAM to the allocated 32bpp buffer. */
2227 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
2228 int32_t xSrc = 0;
2229 int32_t ySrc = 0;
2230 uint32_t u32SrcWidth = width;
2231 uint32_t u32SrcHeight = height;
2232 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
2233 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2234
2235 uint8_t *pu8Dst = pu8Data;
2236 int32_t xDst = 0;
2237 int32_t yDst = 0;
2238 uint32_t u32DstWidth = u32SrcWidth;
2239 uint32_t u32DstHeight = u32SrcHeight;
2240 uint32_t u32DstLineSize = u32DstWidth * 4;
2241 uint32_t u32DstBitsPerPixel = 32;
2242
2243 rc = pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2244 width, height,
2245 pu8Src,
2246 xSrc, ySrc,
2247 u32SrcWidth, u32SrcHeight,
2248 u32SrcLineSize, u32SrcBitsPerPixel,
2249 pu8Dst,
2250 xDst, yDst,
2251 u32DstWidth, u32DstHeight,
2252 u32DstLineSize, u32DstBitsPerPixel);
2253 if (RT_SUCCESS(rc))
2254 {
2255 *ppu8Data = pu8Data;
2256 *pcbData = cbRequired;
2257 *pu32Width = width;
2258 *pu32Height = height;
2259 }
2260 }
2261 }
2262 else
2263 {
2264 /* No image. */
2265 *ppu8Data = NULL;
2266 *pcbData = 0;
2267 *pu32Width = 0;
2268 *pu32Height = 0;
2269 rc = VINF_SUCCESS;
2270 }
2271 }
2272 else
2273 {
2274 rc = VERR_INVALID_PARAMETER;
2275 }
2276 pDisplay->vbvaUnlock();
2277 return rc;
2278}
2279#endif /* VBOX_WITH_OLD_VBVA_LOCK */
2280
2281#ifdef VBOX_WITH_OLD_VBVA_LOCK
2282static int displayTakeScreenshot(PVM pVM, Display *pDisplay, struct DRVMAINDISPLAY *pDrv, ULONG aScreenId, BYTE *address, ULONG width, ULONG height)
2283#else
2284static int displayTakeScreenshot(PVM pVM, struct DRVMAINDISPLAY *pDrv, BYTE *address, ULONG width, ULONG height)
2285#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2286{
2287 uint8_t *pu8Data = NULL;
2288 size_t cbData = 0;
2289 uint32_t cx = 0;
2290 uint32_t cy = 0;
2291 int vrc = VINF_SUCCESS;
2292
2293#ifdef VBOX_WITH_OLD_VBVA_LOCK
2294 int cRetries = 5;
2295
2296 while (cRetries-- > 0)
2297 {
2298 vrc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)Display::displayTakeScreenshotEMT, 6,
2299 pDisplay, aScreenId, &pu8Data, &cbData, &cx, &cy);
2300 if (vrc != VERR_TRY_AGAIN)
2301 {
2302 break;
2303 }
2304
2305 RTThreadSleep(10);
2306 }
2307#else
2308 /* @todo pfnTakeScreenshot is probably callable from any thread, because it uses the VGA device lock. */
2309 vrc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)pDrv->pUpPort->pfnTakeScreenshot, 5,
2310 pDrv->pUpPort, &pu8Data, &cbData, &cx, &cy);
2311#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2312
2313 if (RT_SUCCESS(vrc) && pu8Data)
2314 {
2315 if (cx == width && cy == height)
2316 {
2317 /* No scaling required. */
2318 memcpy(address, pu8Data, cbData);
2319 }
2320 else
2321 {
2322 /* Scale. */
2323 LogFlowFunc(("SCALE: %dx%d -> %dx%d\n", cx, cy, width, height));
2324
2325 uint8_t *dst = address;
2326 uint8_t *src = pu8Data;
2327 int dstW = width;
2328 int dstH = height;
2329 int srcW = cx;
2330 int srcH = cy;
2331 int iDeltaLine = cx * 4;
2332
2333 BitmapScale32 (dst,
2334 dstW, dstH,
2335 src,
2336 iDeltaLine,
2337 srcW, srcH);
2338 }
2339
2340 /* This can be called from any thread. */
2341 pDrv->pUpPort->pfnFreeScreenshot (pDrv->pUpPort, pu8Data);
2342 }
2343
2344 return vrc;
2345}
2346
2347STDMETHODIMP Display::TakeScreenShot (ULONG aScreenId, BYTE *address, ULONG width, ULONG height)
2348{
2349 /// @todo (r=dmik) this function may take too long to complete if the VM
2350 // is doing something like saving state right now. Which, in case if it
2351 // is called on the GUI thread, will make it unresponsive. We should
2352 // check the machine state here (by enclosing the check and VMRequCall
2353 // within the Console lock to make it atomic).
2354
2355 LogFlowFuncEnter();
2356 LogFlowFunc (("address=%p, width=%d, height=%d\n",
2357 address, width, height));
2358
2359 CheckComArgNotNull(address);
2360 CheckComArgExpr(width, width != 0);
2361 CheckComArgExpr(height, height != 0);
2362
2363 AutoCaller autoCaller(this);
2364 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2365
2366 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2367
2368 CHECK_CONSOLE_DRV (mpDrv);
2369
2370 Console::SafeVMPtr pVM(mParent);
2371 if (FAILED(pVM.rc())) return pVM.rc();
2372
2373 HRESULT rc = S_OK;
2374
2375 LogFlowFunc (("Sending SCREENSHOT request\n"));
2376
2377 /* Leave lock because other thread (EMT) is called and it may initiate a resize
2378 * which also needs lock.
2379 *
2380 * This method does not need the lock anymore.
2381 */
2382 alock.leave();
2383
2384#ifdef VBOX_WITH_OLD_VBVA_LOCK
2385 int vrc = displayTakeScreenshot(pVM, this, mpDrv, aScreenId, address, width, height);
2386#else
2387 int vrc = displayTakeScreenshot(pVM, mpDrv, address, width, height);
2388#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2389
2390 if (vrc == VERR_NOT_IMPLEMENTED)
2391 rc = setError(E_NOTIMPL,
2392 tr("This feature is not implemented"));
2393 else if (vrc == VERR_TRY_AGAIN)
2394 rc = setError(E_UNEXPECTED,
2395 tr("This feature is not available at this time"));
2396 else if (RT_FAILURE(vrc))
2397 rc = setError(VBOX_E_IPRT_ERROR,
2398 tr("Could not take a screenshot (%Rrc)"), vrc);
2399
2400 LogFlowFunc (("rc=%08X\n", rc));
2401 LogFlowFuncLeave();
2402 return rc;
2403}
2404
2405STDMETHODIMP Display::TakeScreenShotToArray (ULONG aScreenId, ULONG width, ULONG height,
2406 ComSafeArrayOut(BYTE, aScreenData))
2407{
2408 LogFlowFuncEnter();
2409 LogFlowFunc (("width=%d, height=%d\n",
2410 width, height));
2411
2412 CheckComArgOutSafeArrayPointerValid(aScreenData);
2413 CheckComArgExpr(width, width != 0);
2414 CheckComArgExpr(height, height != 0);
2415
2416 AutoCaller autoCaller(this);
2417 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2418
2419 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2420
2421 CHECK_CONSOLE_DRV (mpDrv);
2422
2423 Console::SafeVMPtr pVM(mParent);
2424 if (FAILED(pVM.rc())) return pVM.rc();
2425
2426 HRESULT rc = S_OK;
2427
2428 LogFlowFunc (("Sending SCREENSHOT request\n"));
2429
2430 /* Leave lock because other thread (EMT) is called and it may initiate a resize
2431 * which also needs lock.
2432 *
2433 * This method does not need the lock anymore.
2434 */
2435 alock.leave();
2436
2437 size_t cbData = width * 4 * height;
2438 uint8_t *pu8Data = (uint8_t *)RTMemAlloc(cbData);
2439
2440 if (!pu8Data)
2441 return E_OUTOFMEMORY;
2442
2443#ifdef VBOX_WITH_OLD_VBVA_LOCK
2444 int vrc = displayTakeScreenshot(pVM, this, mpDrv, aScreenId, pu8Data, width, height);
2445#else
2446 int vrc = displayTakeScreenshot(pVM, mpDrv, pu8Data, width, height);
2447#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2448
2449 if (RT_SUCCESS(vrc))
2450 {
2451 /* Convert pixels to format expected by the API caller: [0] R, [1] G, [2] B, [3] A. */
2452 uint8_t *pu8 = pu8Data;
2453 unsigned cPixels = width * height;
2454 while (cPixels)
2455 {
2456 uint8_t u8 = pu8[0];
2457 pu8[0] = pu8[2];
2458 pu8[2] = u8;
2459 pu8[3] = 0xff;
2460 cPixels--;
2461 pu8 += 4;
2462 }
2463
2464 com::SafeArray<BYTE> screenData (cbData);
2465 screenData.initFrom(pu8Data, cbData);
2466 screenData.detachTo(ComSafeArrayOutArg(aScreenData));
2467 }
2468 else if (vrc == VERR_NOT_IMPLEMENTED)
2469 rc = setError(E_NOTIMPL,
2470 tr("This feature is not implemented"));
2471 else
2472 rc = setError(VBOX_E_IPRT_ERROR,
2473 tr("Could not take a screenshot (%Rrc)"), vrc);
2474
2475 RTMemFree(pu8Data);
2476
2477 LogFlowFunc (("rc=%08X\n", rc));
2478 LogFlowFuncLeave();
2479 return rc;
2480}
2481
2482STDMETHODIMP Display::TakeScreenShotPNGToArray (ULONG aScreenId, ULONG width, ULONG height,
2483 ComSafeArrayOut(BYTE, aScreenData))
2484{
2485 LogFlowFuncEnter();
2486 LogFlowFunc (("width=%d, height=%d\n",
2487 width, height));
2488
2489 CheckComArgOutSafeArrayPointerValid(aScreenData);
2490 CheckComArgExpr(width, width != 0);
2491 CheckComArgExpr(height, height != 0);
2492
2493 AutoCaller autoCaller(this);
2494 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2495
2496 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2497
2498 CHECK_CONSOLE_DRV (mpDrv);
2499
2500 Console::SafeVMPtr pVM(mParent);
2501 if (FAILED(pVM.rc())) return pVM.rc();
2502
2503 HRESULT rc = S_OK;
2504
2505 LogFlowFunc (("Sending SCREENSHOT request\n"));
2506
2507 /* Leave lock because other thread (EMT) is called and it may initiate a resize
2508 * which also needs lock.
2509 *
2510 * This method does not need the lock anymore.
2511 */
2512 alock.leave();
2513
2514 size_t cbData = width * 4 * height;
2515 uint8_t *pu8Data = (uint8_t *)RTMemAlloc(cbData);
2516
2517 if (!pu8Data)
2518 return E_OUTOFMEMORY;
2519
2520#ifdef VBOX_WITH_OLD_VBVA_LOCK
2521 int vrc = displayTakeScreenshot(pVM, this, mpDrv, aScreenId, pu8Data, width, height);
2522#else
2523 int vrc = displayTakeScreenshot(pVM, mpDrv, pu8Data, width, height);
2524#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2525
2526 if (RT_SUCCESS(vrc))
2527 {
2528 uint8_t *pu8PNG = NULL;
2529 uint32_t cbPNG = 0;
2530 uint32_t cxPNG = 0;
2531 uint32_t cyPNG = 0;
2532
2533 DisplayMakePNG(pu8Data, width, height, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 0);
2534
2535 com::SafeArray<BYTE> screenData (cbPNG);
2536 screenData.initFrom(pu8PNG, cbPNG);
2537 RTMemFree(pu8PNG);
2538
2539 screenData.detachTo(ComSafeArrayOutArg(aScreenData));
2540 }
2541 else if (vrc == VERR_NOT_IMPLEMENTED)
2542 rc = setError(E_NOTIMPL,
2543 tr("This feature is not implemented"));
2544 else
2545 rc = setError(VBOX_E_IPRT_ERROR,
2546 tr("Could not take a screenshot (%Rrc)"), vrc);
2547
2548 RTMemFree(pu8Data);
2549
2550 LogFlowFunc (("rc=%08X\n", rc));
2551 LogFlowFuncLeave();
2552 return rc;
2553}
2554
2555
2556#ifdef VBOX_WITH_OLD_VBVA_LOCK
2557int Display::drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height)
2558{
2559 int rc;
2560 pDisplay->vbvaLock();
2561 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2562 {
2563 rc = pDisplay->mpDrv->pUpPort->pfnDisplayBlt(pDisplay->mpDrv->pUpPort, address, x, y, width, height);
2564 }
2565 else if (aScreenId < pDisplay->mcMonitors)
2566 {
2567 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[aScreenId];
2568
2569 /* Copy the bitmap to the guest VRAM. */
2570 const uint8_t *pu8Src = address;
2571 int32_t xSrc = 0;
2572 int32_t ySrc = 0;
2573 uint32_t u32SrcWidth = width;
2574 uint32_t u32SrcHeight = height;
2575 uint32_t u32SrcLineSize = width * 4;
2576 uint32_t u32SrcBitsPerPixel = 32;
2577
2578 uint8_t *pu8Dst = pFBInfo->pu8FramebufferVRAM;
2579 int32_t xDst = x;
2580 int32_t yDst = y;
2581 uint32_t u32DstWidth = pFBInfo->w;
2582 uint32_t u32DstHeight = pFBInfo->h;
2583 uint32_t u32DstLineSize = pFBInfo->u32LineSize;
2584 uint32_t u32DstBitsPerPixel = pFBInfo->u16BitsPerPixel;
2585
2586 rc = pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2587 width, height,
2588 pu8Src,
2589 xSrc, ySrc,
2590 u32SrcWidth, u32SrcHeight,
2591 u32SrcLineSize, u32SrcBitsPerPixel,
2592 pu8Dst,
2593 xDst, yDst,
2594 u32DstWidth, u32DstHeight,
2595 u32DstLineSize, u32DstBitsPerPixel);
2596 if (RT_SUCCESS(rc))
2597 {
2598 if (!pFBInfo->pFramebuffer.isNull())
2599 {
2600 /* Update the changed screen area. When framebuffer uses VRAM directly, just notify
2601 * it to update. And for default format, render the guest VRAM to framebuffer.
2602 */
2603 if (pFBInfo->fDefaultFormat)
2604 {
2605 address = NULL;
2606 HRESULT hrc = pFBInfo->pFramebuffer->COMGETTER(Address) (&address);
2607 if (SUCCEEDED(hrc) && address != NULL)
2608 {
2609 pu8Src = pFBInfo->pu8FramebufferVRAM;
2610 xSrc = x;
2611 ySrc = y;
2612 u32SrcWidth = pFBInfo->w;
2613 u32SrcHeight = pFBInfo->h;
2614 u32SrcLineSize = pFBInfo->u32LineSize;
2615 u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2616
2617 /* Default format is 32 bpp. */
2618 pu8Dst = address;
2619 xDst = xSrc;
2620 yDst = ySrc;
2621 u32DstWidth = u32SrcWidth;
2622 u32DstHeight = u32SrcHeight;
2623 u32DstLineSize = u32DstWidth * 4;
2624 u32DstBitsPerPixel = 32;
2625
2626 pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2627 width, height,
2628 pu8Src,
2629 xSrc, ySrc,
2630 u32SrcWidth, u32SrcHeight,
2631 u32SrcLineSize, u32SrcBitsPerPixel,
2632 pu8Dst,
2633 xDst, yDst,
2634 u32DstWidth, u32DstHeight,
2635 u32DstLineSize, u32DstBitsPerPixel);
2636 }
2637 }
2638
2639 pDisplay->handleDisplayUpdate(aScreenId, x, y, width, height);
2640 }
2641 }
2642 }
2643 else
2644 {
2645 rc = VERR_INVALID_PARAMETER;
2646 }
2647 pDisplay->vbvaUnlock();
2648 return rc;
2649}
2650#endif /* VBOX_WITH_OLD_VBVA_LOCK */
2651
2652STDMETHODIMP Display::DrawToScreen (ULONG aScreenId, BYTE *address, ULONG x, ULONG y,
2653 ULONG width, ULONG height)
2654{
2655 /// @todo (r=dmik) this function may take too long to complete if the VM
2656 // is doing something like saving state right now. Which, in case if it
2657 // is called on the GUI thread, will make it unresponsive. We should
2658 // check the machine state here (by enclosing the check and VMRequCall
2659 // within the Console lock to make it atomic).
2660
2661 LogFlowFuncEnter();
2662 LogFlowFunc (("address=%p, x=%d, y=%d, width=%d, height=%d\n",
2663 (void *)address, x, y, width, height));
2664
2665 CheckComArgNotNull(address);
2666 CheckComArgExpr(width, width != 0);
2667 CheckComArgExpr(height, height != 0);
2668
2669 AutoCaller autoCaller(this);
2670 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2671
2672 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2673
2674 CHECK_CONSOLE_DRV (mpDrv);
2675
2676 Console::SafeVMPtr pVM(mParent);
2677 if (FAILED(pVM.rc())) return pVM.rc();
2678
2679 /*
2680 * Again we're lazy and make the graphics device do all the
2681 * dirty conversion work.
2682 */
2683#ifdef VBOX_WITH_OLD_VBVA_LOCK
2684 int rcVBox = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)Display::drawToScreenEMT, 7,
2685 this, aScreenId, address, x, y, width, height);
2686#else
2687 int rcVBox = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)mpDrv->pUpPort->pfnDisplayBlt, 6,
2688 mpDrv->pUpPort, address, x, y, width, height);
2689#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2690
2691 /*
2692 * If the function returns not supported, we'll have to do all the
2693 * work ourselves using the framebuffer.
2694 */
2695 HRESULT rc = S_OK;
2696 if (rcVBox == VERR_NOT_SUPPORTED || rcVBox == VERR_NOT_IMPLEMENTED)
2697 {
2698 /** @todo implement generic fallback for screen blitting. */
2699 rc = E_NOTIMPL;
2700 }
2701 else if (RT_FAILURE(rcVBox))
2702 rc = setError(VBOX_E_IPRT_ERROR,
2703 tr("Could not draw to the screen (%Rrc)"), rcVBox);
2704//@todo
2705// else
2706// {
2707// /* All ok. Redraw the screen. */
2708// handleDisplayUpdate (x, y, width, height);
2709// }
2710
2711 LogFlowFunc (("rc=%08X\n", rc));
2712 LogFlowFuncLeave();
2713 return rc;
2714}
2715
2716#ifdef VBOX_WITH_OLD_VBVA_LOCK
2717void Display::InvalidateAndUpdateEMT(Display *pDisplay)
2718{
2719 pDisplay->vbvaLock();
2720 unsigned uScreenId;
2721 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
2722 {
2723 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
2724
2725 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN && !pFBInfo->pFramebuffer.isNull())
2726 {
2727 pDisplay->mpDrv->pUpPort->pfnUpdateDisplayAll(pDisplay->mpDrv->pUpPort);
2728 }
2729 else
2730 {
2731 if (!pFBInfo->pFramebuffer.isNull())
2732 {
2733 /* Render complete VRAM screen to the framebuffer.
2734 * When framebuffer uses VRAM directly, just notify it to update.
2735 */
2736 if (pFBInfo->fDefaultFormat)
2737 {
2738 BYTE *address = NULL;
2739 HRESULT hrc = pFBInfo->pFramebuffer->COMGETTER(Address) (&address);
2740 if (SUCCEEDED(hrc) && address != NULL)
2741 {
2742 uint32_t width = pFBInfo->w;
2743 uint32_t height = pFBInfo->h;
2744
2745 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
2746 int32_t xSrc = 0;
2747 int32_t ySrc = 0;
2748 uint32_t u32SrcWidth = pFBInfo->w;
2749 uint32_t u32SrcHeight = pFBInfo->h;
2750 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
2751 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2752
2753 /* Default format is 32 bpp. */
2754 uint8_t *pu8Dst = address;
2755 int32_t xDst = xSrc;
2756 int32_t yDst = ySrc;
2757 uint32_t u32DstWidth = u32SrcWidth;
2758 uint32_t u32DstHeight = u32SrcHeight;
2759 uint32_t u32DstLineSize = u32DstWidth * 4;
2760 uint32_t u32DstBitsPerPixel = 32;
2761
2762 pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2763 width, height,
2764 pu8Src,
2765 xSrc, ySrc,
2766 u32SrcWidth, u32SrcHeight,
2767 u32SrcLineSize, u32SrcBitsPerPixel,
2768 pu8Dst,
2769 xDst, yDst,
2770 u32DstWidth, u32DstHeight,
2771 u32DstLineSize, u32DstBitsPerPixel);
2772 }
2773 }
2774
2775 pDisplay->handleDisplayUpdate (uScreenId, 0, 0, pFBInfo->w, pFBInfo->h);
2776 }
2777 }
2778 }
2779 pDisplay->vbvaUnlock();
2780}
2781#endif /* VBOX_WITH_OLD_VBVA_LOCK */
2782
2783/**
2784 * Does a full invalidation of the VM display and instructs the VM
2785 * to update it immediately.
2786 *
2787 * @returns COM status code
2788 */
2789STDMETHODIMP Display::InvalidateAndUpdate()
2790{
2791 LogFlowFuncEnter();
2792
2793 AutoCaller autoCaller(this);
2794 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2795
2796 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2797
2798 CHECK_CONSOLE_DRV (mpDrv);
2799
2800 Console::SafeVMPtr pVM(mParent);
2801 if (FAILED(pVM.rc())) return pVM.rc();
2802
2803 HRESULT rc = S_OK;
2804
2805 LogFlowFunc (("Sending DPYUPDATE request\n"));
2806
2807 /* Have to leave the lock when calling EMT. */
2808 alock.leave ();
2809
2810 /* pdm.h says that this has to be called from the EMT thread */
2811#ifdef VBOX_WITH_OLD_VBVA_LOCK
2812 int rcVBox = VMR3ReqCallVoidWait(pVM, VMCPUID_ANY, (PFNRT)Display::InvalidateAndUpdateEMT,
2813 1, this);
2814#else
2815 int rcVBox = VMR3ReqCallVoidWait(pVM, VMCPUID_ANY,
2816 (PFNRT)mpDrv->pUpPort->pfnUpdateDisplayAll, 1, mpDrv->pUpPort);
2817#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2818 alock.enter ();
2819
2820 if (RT_FAILURE(rcVBox))
2821 rc = setError(VBOX_E_IPRT_ERROR,
2822 tr("Could not invalidate and update the screen (%Rrc)"), rcVBox);
2823
2824 LogFlowFunc (("rc=%08X\n", rc));
2825 LogFlowFuncLeave();
2826 return rc;
2827}
2828
2829/**
2830 * Notification that the framebuffer has completed the
2831 * asynchronous resize processing
2832 *
2833 * @returns COM status code
2834 */
2835STDMETHODIMP Display::ResizeCompleted(ULONG aScreenId)
2836{
2837 LogFlowFunc (("\n"));
2838
2839 /// @todo (dmik) can we AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); here?
2840 // This will require general code review and may add some details.
2841 // In particular, we may want to check whether EMT is really waiting for
2842 // this notification, etc. It might be also good to obey the caller to make
2843 // sure this method is not called from more than one thread at a time
2844 // (and therefore don't use Display lock at all here to save some
2845 // milliseconds).
2846 AutoCaller autoCaller(this);
2847 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2848
2849 /* this is only valid for external framebuffers */
2850 if (maFramebuffers[aScreenId].pFramebuffer == NULL)
2851 return setError(VBOX_E_NOT_SUPPORTED,
2852 tr("Resize completed notification is valid only for external framebuffers"));
2853
2854 /* Set the flag indicating that the resize has completed and display
2855 * data need to be updated. */
2856 bool f = ASMAtomicCmpXchgU32 (&maFramebuffers[aScreenId].u32ResizeStatus,
2857 ResizeStatus_UpdateDisplayData, ResizeStatus_InProgress);
2858 AssertRelease(f);NOREF(f);
2859
2860 return S_OK;
2861}
2862
2863STDMETHODIMP Display::CompleteVHWACommand(BYTE *pCommand)
2864{
2865#ifdef VBOX_WITH_VIDEOHWACCEL
2866 mpDrv->pVBVACallbacks->pfnVHWACommandCompleteAsynch(mpDrv->pVBVACallbacks, (PVBOXVHWACMD)pCommand);
2867 return S_OK;
2868#else
2869 return E_NOTIMPL;
2870#endif
2871}
2872
2873// private methods
2874/////////////////////////////////////////////////////////////////////////////
2875
2876/**
2877 * Helper to update the display information from the framebuffer.
2878 *
2879 * @thread EMT
2880 */
2881void Display::updateDisplayData(void)
2882{
2883 LogFlowFunc (("\n"));
2884
2885 /* the driver might not have been constructed yet */
2886 if (!mpDrv)
2887 return;
2888
2889#if DEBUG
2890 /*
2891 * Sanity check. Note that this method may be called on EMT after Console
2892 * has started the power down procedure (but before our #drvDestruct() is
2893 * called, in which case pVM will already be NULL but mpDrv will not). Since
2894 * we don't really need pVM to proceed, we avoid this check in the release
2895 * build to save some ms (necessary to construct SafeVMPtrQuiet) in this
2896 * time-critical method.
2897 */
2898 Console::SafeVMPtrQuiet pVM (mParent);
2899 if (pVM.isOk())
2900 VM_ASSERT_EMT (pVM.raw());
2901#endif
2902
2903 /* The method is only relevant to the primary framebuffer. */
2904 IFramebuffer *pFramebuffer = maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
2905
2906 if (pFramebuffer)
2907 {
2908 HRESULT rc;
2909 BYTE *address = 0;
2910 rc = pFramebuffer->COMGETTER(Address) (&address);
2911 AssertComRC (rc);
2912 ULONG bytesPerLine = 0;
2913 rc = pFramebuffer->COMGETTER(BytesPerLine) (&bytesPerLine);
2914 AssertComRC (rc);
2915 ULONG bitsPerPixel = 0;
2916 rc = pFramebuffer->COMGETTER(BitsPerPixel) (&bitsPerPixel);
2917 AssertComRC (rc);
2918 ULONG width = 0;
2919 rc = pFramebuffer->COMGETTER(Width) (&width);
2920 AssertComRC (rc);
2921 ULONG height = 0;
2922 rc = pFramebuffer->COMGETTER(Height) (&height);
2923 AssertComRC (rc);
2924
2925 mpDrv->IConnector.pu8Data = (uint8_t *) address;
2926 mpDrv->IConnector.cbScanline = bytesPerLine;
2927 mpDrv->IConnector.cBits = bitsPerPixel;
2928 mpDrv->IConnector.cx = width;
2929 mpDrv->IConnector.cy = height;
2930 }
2931 else
2932 {
2933 /* black hole */
2934 mpDrv->IConnector.pu8Data = NULL;
2935 mpDrv->IConnector.cbScanline = 0;
2936 mpDrv->IConnector.cBits = 0;
2937 mpDrv->IConnector.cx = 0;
2938 mpDrv->IConnector.cy = 0;
2939 }
2940 LogFlowFunc (("leave\n"));
2941}
2942
2943#ifdef VBOX_WITH_CRHGSMI
2944void Display::setupCrHgsmiData(void)
2945{
2946 VMMDev *pVMMDev = mParent->getVMMDev();
2947 Assert(pVMMDev);
2948 int rc = VERR_GENERAL_FAILURE;
2949 if (pVMMDev)
2950 rc = pVMMDev->hgcmHostSvcHandleCreate("VBoxSharedCrOpenGL", &mhCrOglSvc);
2951
2952 if (RT_SUCCESS(rc))
2953 {
2954 Assert(mhCrOglSvc);
2955 }
2956 else
2957 {
2958 mhCrOglSvc = NULL;
2959 }
2960}
2961
2962void Display::destructCrHgsmiData(void)
2963{
2964 mhCrOglSvc = NULL;
2965}
2966#endif
2967
2968/**
2969 * Changes the current frame buffer. Called on EMT to avoid both
2970 * race conditions and excessive locking.
2971 *
2972 * @note locks this object for writing
2973 * @thread EMT
2974 */
2975/* static */
2976DECLCALLBACK(int) Display::changeFramebuffer (Display *that, IFramebuffer *aFB,
2977 unsigned uScreenId)
2978{
2979 LogFlowFunc (("uScreenId = %d\n", uScreenId));
2980
2981 AssertReturn(that, VERR_INVALID_PARAMETER);
2982 AssertReturn(uScreenId < that->mcMonitors, VERR_INVALID_PARAMETER);
2983
2984 AutoCaller autoCaller(that);
2985 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2986
2987 AutoWriteLock alock(that COMMA_LOCKVAL_SRC_POS);
2988
2989 DISPLAYFBINFO *pDisplayFBInfo = &that->maFramebuffers[uScreenId];
2990 pDisplayFBInfo->pFramebuffer = aFB;
2991
2992 that->mParent->consoleVRDPServer()->SendResize ();
2993
2994 /* The driver might not have been constructed yet */
2995 if (that->mpDrv)
2996 {
2997 /* Setup the new framebuffer, the resize will lead to an updateDisplayData call. */
2998 DISPLAYFBINFO *pFBInfo = &that->maFramebuffers[uScreenId];
2999
3000 if (pFBInfo->fVBVAEnabled && pFBInfo->pu8FramebufferVRAM)
3001 {
3002 /* This display in VBVA mode. Resize it to the last guest resolution,
3003 * if it has been reported.
3004 */
3005 that->handleDisplayResize(uScreenId, pFBInfo->u16BitsPerPixel,
3006 pFBInfo->pu8FramebufferVRAM,
3007 pFBInfo->u32LineSize,
3008 pFBInfo->w,
3009 pFBInfo->h,
3010 pFBInfo->flags);
3011 }
3012 else if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3013 {
3014 /* VGA device mode, only for the primary screen. */
3015 that->handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, that->mLastBitsPerPixel,
3016 that->mLastAddress,
3017 that->mLastBytesPerLine,
3018 that->mLastWidth,
3019 that->mLastHeight,
3020 that->mLastFlags);
3021 }
3022 }
3023
3024 LogFlowFunc (("leave\n"));
3025 return VINF_SUCCESS;
3026}
3027
3028/**
3029 * Handle display resize event issued by the VGA device for the primary screen.
3030 *
3031 * @see PDMIDISPLAYCONNECTOR::pfnResize
3032 */
3033DECLCALLBACK(int) Display::displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface,
3034 uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy)
3035{
3036 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3037
3038 LogFlowFunc (("bpp %d, pvVRAM %p, cbLine %d, cx %d, cy %d\n",
3039 bpp, pvVRAM, cbLine, cx, cy));
3040
3041 return pDrv->pDisplay->handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, bpp, pvVRAM, cbLine, cx, cy, VBVA_SCREEN_F_ACTIVE);
3042}
3043
3044/**
3045 * Handle display update.
3046 *
3047 * @see PDMIDISPLAYCONNECTOR::pfnUpdateRect
3048 */
3049DECLCALLBACK(void) Display::displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
3050 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
3051{
3052 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3053
3054#ifdef DEBUG_sunlover
3055 LogFlowFunc (("mfVideoAccelEnabled = %d, %d,%d %dx%d\n",
3056 pDrv->pDisplay->mfVideoAccelEnabled, x, y, cx, cy));
3057#endif /* DEBUG_sunlover */
3058
3059 /* This call does update regardless of VBVA status.
3060 * But in VBVA mode this is called only as result of
3061 * pfnUpdateDisplayAll in the VGA device.
3062 */
3063
3064 pDrv->pDisplay->handleDisplayUpdate(VBOX_VIDEO_PRIMARY_SCREEN, x, y, cx, cy);
3065}
3066
3067/**
3068 * Periodic display refresh callback.
3069 *
3070 * @see PDMIDISPLAYCONNECTOR::pfnRefresh
3071 */
3072DECLCALLBACK(void) Display::displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface)
3073{
3074 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3075
3076#ifdef DEBUG_sunlover
3077 STAM_PROFILE_START(&StatDisplayRefresh, a);
3078#endif /* DEBUG_sunlover */
3079
3080#ifdef DEBUG_sunlover_2
3081 LogFlowFunc (("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
3082 pDrv->pDisplay->mfVideoAccelEnabled));
3083#endif /* DEBUG_sunlover_2 */
3084
3085 Display *pDisplay = pDrv->pDisplay;
3086 bool fNoUpdate = false; /* Do not update the display if any of the framebuffers is being resized. */
3087 unsigned uScreenId;
3088
3089 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3090 {
3091 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3092
3093 /* Check the resize status. The status can be checked normally because
3094 * the status affects only the EMT.
3095 */
3096 uint32_t u32ResizeStatus = pFBInfo->u32ResizeStatus;
3097
3098 if (u32ResizeStatus == ResizeStatus_UpdateDisplayData)
3099 {
3100 LogFlowFunc (("ResizeStatus_UpdateDisplayData %d\n", uScreenId));
3101 fNoUpdate = true; /* Always set it here, because pfnUpdateDisplayAll can cause a new resize. */
3102 /* The framebuffer was resized and display data need to be updated. */
3103 pDisplay->handleResizeCompletedEMT ();
3104 if (pFBInfo->u32ResizeStatus != ResizeStatus_Void)
3105 {
3106 /* The resize status could be not Void here because a pending resize is issued. */
3107 continue;
3108 }
3109 /* Continue with normal processing because the status here is ResizeStatus_Void. */
3110 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3111 {
3112 /* Repaint the display because VM continued to run during the framebuffer resize. */
3113 if (!pFBInfo->pFramebuffer.isNull())
3114#ifdef VBOX_WITH_OLD_VBVA_LOCK
3115 {
3116 pDisplay->vbvaLock();
3117#endif /* VBOX_WITH_OLD_VBVA_LOCK */
3118 pDrv->pUpPort->pfnUpdateDisplayAll(pDrv->pUpPort);
3119#ifdef VBOX_WITH_OLD_VBVA_LOCK
3120 pDisplay->vbvaUnlock();
3121 }
3122#endif /* VBOX_WITH_OLD_VBVA_LOCK */
3123 }
3124 }
3125 else if (u32ResizeStatus == ResizeStatus_InProgress)
3126 {
3127 /* The framebuffer is being resized. Do not call the VGA device back. Immediately return. */
3128 LogFlowFunc (("ResizeStatus_InProcess\n"));
3129 fNoUpdate = true;
3130 continue;
3131 }
3132 }
3133
3134 if (!fNoUpdate)
3135 {
3136#ifdef VBOX_WITH_OLD_VBVA_LOCK
3137 int rc = pDisplay->videoAccelRefreshProcess();
3138
3139 if (rc != VINF_TRY_AGAIN) /* Means 'do nothing' here. */
3140 {
3141 if (rc == VWRN_INVALID_STATE)
3142 {
3143 /* No VBVA do a display update. */
3144 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN];
3145 if (!pFBInfo->pFramebuffer.isNull() && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
3146 {
3147 Assert(pDrv->IConnector.pu8Data);
3148 pDisplay->vbvaLock();
3149 pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
3150 pDisplay->vbvaUnlock();
3151 }
3152 }
3153
3154 /* Inform the VRDP server that the current display update sequence is
3155 * completed. At this moment the framebuffer memory contains a definite
3156 * image, that is synchronized with the orders already sent to VRDP client.
3157 * The server can now process redraw requests from clients or initial
3158 * fullscreen updates for new clients.
3159 */
3160 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3161 {
3162 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3163
3164 if (!pFBInfo->pFramebuffer.isNull() && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
3165 {
3166 Assert (pDisplay->mParent && pDisplay->mParent->consoleVRDPServer());
3167 pDisplay->mParent->consoleVRDPServer()->SendUpdate (uScreenId, NULL, 0);
3168 }
3169 }
3170 }
3171#else
3172 if (pDisplay->mfPendingVideoAccelEnable)
3173 {
3174 /* Acceleration was enabled while machine was not yet running
3175 * due to restoring from saved state. Update entire display and
3176 * actually enable acceleration.
3177 */
3178 Assert(pDisplay->mpPendingVbvaMemory);
3179
3180 /* Acceleration can not be yet enabled.*/
3181 Assert(pDisplay->mpVbvaMemory == NULL);
3182 Assert(!pDisplay->mfVideoAccelEnabled);
3183
3184 if (pDisplay->mfMachineRunning)
3185 {
3186 pDisplay->VideoAccelEnable (pDisplay->mfPendingVideoAccelEnable,
3187 pDisplay->mpPendingVbvaMemory);
3188
3189 /* Reset the pending state. */
3190 pDisplay->mfPendingVideoAccelEnable = false;
3191 pDisplay->mpPendingVbvaMemory = NULL;
3192 }
3193 }
3194 else
3195 {
3196 Assert(pDisplay->mpPendingVbvaMemory == NULL);
3197
3198 if (pDisplay->mfVideoAccelEnabled)
3199 {
3200 Assert(pDisplay->mpVbvaMemory);
3201 pDisplay->VideoAccelFlush ();
3202 }
3203 else
3204 {
3205 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN];
3206 if (!pFBInfo->pFramebuffer.isNull())
3207 {
3208 Assert(pDrv->IConnector.pu8Data);
3209 Assert(pFBInfo->u32ResizeStatus == ResizeStatus_Void);
3210 pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
3211 }
3212 }
3213
3214 /* Inform the VRDP server that the current display update sequence is
3215 * completed. At this moment the framebuffer memory contains a definite
3216 * image, that is synchronized with the orders already sent to VRDP client.
3217 * The server can now process redraw requests from clients or initial
3218 * fullscreen updates for new clients.
3219 */
3220 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3221 {
3222 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3223
3224 if (!pFBInfo->pFramebuffer.isNull() && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
3225 {
3226 Assert (pDisplay->mParent && pDisplay->mParent->consoleVRDPServer());
3227 pDisplay->mParent->consoleVRDPServer()->SendUpdate (uScreenId, NULL, 0);
3228 }
3229 }
3230 }
3231#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
3232 }
3233
3234#ifdef DEBUG_sunlover
3235 STAM_PROFILE_STOP(&StatDisplayRefresh, a);
3236#endif /* DEBUG_sunlover */
3237#ifdef DEBUG_sunlover_2
3238 LogFlowFunc (("leave\n"));
3239#endif /* DEBUG_sunlover_2 */
3240}
3241
3242/**
3243 * Reset notification
3244 *
3245 * @see PDMIDISPLAYCONNECTOR::pfnReset
3246 */
3247DECLCALLBACK(void) Display::displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface)
3248{
3249 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3250
3251 LogFlowFunc (("\n"));
3252
3253 /* Disable VBVA mode. */
3254 pDrv->pDisplay->VideoAccelEnable (false, NULL);
3255}
3256
3257/**
3258 * LFBModeChange notification
3259 *
3260 * @see PDMIDISPLAYCONNECTOR::pfnLFBModeChange
3261 */
3262DECLCALLBACK(void) Display::displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled)
3263{
3264 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3265
3266 LogFlowFunc (("fEnabled=%d\n", fEnabled));
3267
3268 NOREF(fEnabled);
3269
3270 /* Disable VBVA mode in any case. The guest driver reenables VBVA mode if necessary. */
3271#ifdef VBOX_WITH_OLD_VBVA_LOCK
3272 /* This is called under DevVGA lock. Postpone disabling VBVA, do it in the refresh timer. */
3273 ASMAtomicWriteU32(&pDrv->pDisplay->mfu32PendingVideoAccelDisable, true);
3274#else
3275 pDrv->pDisplay->VideoAccelEnable (false, NULL);
3276#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
3277}
3278
3279/**
3280 * Adapter information change notification.
3281 *
3282 * @see PDMIDISPLAYCONNECTOR::pfnProcessAdapterData
3283 */
3284DECLCALLBACK(void) Display::displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize)
3285{
3286 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3287
3288 if (pvVRAM == NULL)
3289 {
3290 unsigned i;
3291 for (i = 0; i < pDrv->pDisplay->mcMonitors; i++)
3292 {
3293 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[i];
3294
3295 pFBInfo->u32Offset = 0;
3296 pFBInfo->u32MaxFramebufferSize = 0;
3297 pFBInfo->u32InformationSize = 0;
3298 }
3299 }
3300#ifndef VBOX_WITH_HGSMI
3301 else
3302 {
3303 uint8_t *pu8 = (uint8_t *)pvVRAM;
3304 pu8 += u32VRAMSize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE;
3305
3306 // @todo
3307 uint8_t *pu8End = pu8 + VBOX_VIDEO_ADAPTER_INFORMATION_SIZE;
3308
3309 VBOXVIDEOINFOHDR *pHdr;
3310
3311 for (;;)
3312 {
3313 pHdr = (VBOXVIDEOINFOHDR *)pu8;
3314 pu8 += sizeof (VBOXVIDEOINFOHDR);
3315
3316 if (pu8 >= pu8End)
3317 {
3318 LogRel(("VBoxVideo: Guest adapter information overflow!!!\n"));
3319 break;
3320 }
3321
3322 if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_DISPLAY)
3323 {
3324 if (pHdr->u16Length != sizeof (VBOXVIDEOINFODISPLAY))
3325 {
3326 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "DISPLAY", pHdr->u16Length));
3327 break;
3328 }
3329
3330 VBOXVIDEOINFODISPLAY *pDisplay = (VBOXVIDEOINFODISPLAY *)pu8;
3331
3332 if (pDisplay->u32Index >= pDrv->pDisplay->mcMonitors)
3333 {
3334 LogRel(("VBoxVideo: Guest adapter information invalid display index %d!!!\n", pDisplay->u32Index));
3335 break;
3336 }
3337
3338 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[pDisplay->u32Index];
3339
3340 pFBInfo->u32Offset = pDisplay->u32Offset;
3341 pFBInfo->u32MaxFramebufferSize = pDisplay->u32FramebufferSize;
3342 pFBInfo->u32InformationSize = pDisplay->u32InformationSize;
3343
3344 LogFlow(("VBOX_VIDEO_INFO_TYPE_DISPLAY: %d: at 0x%08X, size 0x%08X, info 0x%08X\n", pDisplay->u32Index, pDisplay->u32Offset, pDisplay->u32FramebufferSize, pDisplay->u32InformationSize));
3345 }
3346 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_QUERY_CONF32)
3347 {
3348 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOQUERYCONF32))
3349 {
3350 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "CONF32", pHdr->u16Length));
3351 break;
3352 }
3353
3354 VBOXVIDEOINFOQUERYCONF32 *pConf32 = (VBOXVIDEOINFOQUERYCONF32 *)pu8;
3355
3356 switch (pConf32->u32Index)
3357 {
3358 case VBOX_VIDEO_QCI32_MONITOR_COUNT:
3359 {
3360 pConf32->u32Value = pDrv->pDisplay->mcMonitors;
3361 } break;
3362
3363 case VBOX_VIDEO_QCI32_OFFSCREEN_HEAP_SIZE:
3364 {
3365 /* @todo make configurable. */
3366 pConf32->u32Value = _1M;
3367 } break;
3368
3369 default:
3370 LogRel(("VBoxVideo: CONF32 %d not supported!!! Skipping.\n", pConf32->u32Index));
3371 }
3372 }
3373 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_END)
3374 {
3375 if (pHdr->u16Length != 0)
3376 {
3377 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "END", pHdr->u16Length));
3378 break;
3379 }
3380
3381 break;
3382 }
3383 else if (pHdr->u8Type != VBOX_VIDEO_INFO_TYPE_NV_HEAP) /** @todo why is Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp pushing this to us? */
3384 {
3385 LogRel(("Guest adapter information contains unsupported type %d. The block has been skipped.\n", pHdr->u8Type));
3386 }
3387
3388 pu8 += pHdr->u16Length;
3389 }
3390 }
3391#endif /* !VBOX_WITH_HGSMI */
3392}
3393
3394/**
3395 * Display information change notification.
3396 *
3397 * @see PDMIDISPLAYCONNECTOR::pfnProcessDisplayData
3398 */
3399DECLCALLBACK(void) Display::displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId)
3400{
3401 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3402
3403 if (uScreenId >= pDrv->pDisplay->mcMonitors)
3404 {
3405 LogRel(("VBoxVideo: Guest display information invalid display index %d!!!\n", uScreenId));
3406 return;
3407 }
3408
3409 /* Get the display information structure. */
3410 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[uScreenId];
3411
3412 uint8_t *pu8 = (uint8_t *)pvVRAM;
3413 pu8 += pFBInfo->u32Offset + pFBInfo->u32MaxFramebufferSize;
3414
3415 // @todo
3416 uint8_t *pu8End = pu8 + pFBInfo->u32InformationSize;
3417
3418 VBOXVIDEOINFOHDR *pHdr;
3419
3420 for (;;)
3421 {
3422 pHdr = (VBOXVIDEOINFOHDR *)pu8;
3423 pu8 += sizeof (VBOXVIDEOINFOHDR);
3424
3425 if (pu8 >= pu8End)
3426 {
3427 LogRel(("VBoxVideo: Guest display information overflow!!!\n"));
3428 break;
3429 }
3430
3431 if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_SCREEN)
3432 {
3433 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOSCREEN))
3434 {
3435 LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "SCREEN", pHdr->u16Length));
3436 break;
3437 }
3438
3439 VBOXVIDEOINFOSCREEN *pScreen = (VBOXVIDEOINFOSCREEN *)pu8;
3440
3441 pFBInfo->xOrigin = pScreen->xOrigin;
3442 pFBInfo->yOrigin = pScreen->yOrigin;
3443
3444 pFBInfo->w = pScreen->u16Width;
3445 pFBInfo->h = pScreen->u16Height;
3446
3447 LogFlow(("VBOX_VIDEO_INFO_TYPE_SCREEN: (%p) %d: at %d,%d, linesize 0x%X, size %dx%d, bpp %d, flags 0x%02X\n",
3448 pHdr, uScreenId, pScreen->xOrigin, pScreen->yOrigin, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height, pScreen->bitsPerPixel, pScreen->u8Flags));
3449
3450 if (uScreenId != VBOX_VIDEO_PRIMARY_SCREEN)
3451 {
3452 /* Primary screen resize is initiated by the VGA device. */
3453 pDrv->pDisplay->handleDisplayResize(uScreenId, pScreen->bitsPerPixel, (uint8_t *)pvVRAM + pFBInfo->u32Offset, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height, VBVA_SCREEN_F_ACTIVE);
3454 }
3455 }
3456 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_END)
3457 {
3458 if (pHdr->u16Length != 0)
3459 {
3460 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "END", pHdr->u16Length));
3461 break;
3462 }
3463
3464 break;
3465 }
3466 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_HOST_EVENTS)
3467 {
3468 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOHOSTEVENTS))
3469 {
3470 LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "HOST_EVENTS", pHdr->u16Length));
3471 break;
3472 }
3473
3474 VBOXVIDEOINFOHOSTEVENTS *pHostEvents = (VBOXVIDEOINFOHOSTEVENTS *)pu8;
3475
3476 pFBInfo->pHostEvents = pHostEvents;
3477
3478 LogFlow(("VBOX_VIDEO_INFO_TYPE_HOSTEVENTS: (%p)\n",
3479 pHostEvents));
3480 }
3481 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_LINK)
3482 {
3483 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOLINK))
3484 {
3485 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "LINK", pHdr->u16Length));
3486 break;
3487 }
3488
3489 VBOXVIDEOINFOLINK *pLink = (VBOXVIDEOINFOLINK *)pu8;
3490 pu8 += pLink->i32Offset;
3491 }
3492 else
3493 {
3494 LogRel(("Guest display information contains unsupported type %d\n", pHdr->u8Type));
3495 }
3496
3497 pu8 += pHdr->u16Length;
3498 }
3499}
3500
3501#ifdef VBOX_WITH_VIDEOHWACCEL
3502
3503void Display::handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
3504{
3505 unsigned id = (unsigned)pCommand->iDisplay;
3506 int rc = VINF_SUCCESS;
3507 if (id < mcMonitors)
3508 {
3509 IFramebuffer *pFramebuffer = maFramebuffers[id].pFramebuffer;
3510#ifdef DEBUG_misha
3511 Assert (pFramebuffer);
3512#endif
3513
3514 if (pFramebuffer != NULL)
3515 {
3516 HRESULT hr = pFramebuffer->ProcessVHWACommand((BYTE*)pCommand);
3517 if (FAILED(hr))
3518 {
3519 rc = (hr == E_NOTIMPL) ? VERR_NOT_IMPLEMENTED : VERR_GENERAL_FAILURE;
3520 }
3521 }
3522 else
3523 {
3524 rc = VERR_NOT_IMPLEMENTED;
3525 }
3526 }
3527 else
3528 {
3529 rc = VERR_INVALID_PARAMETER;
3530 }
3531
3532 if (RT_FAILURE(rc))
3533 {
3534 /* tell the guest the command is complete */
3535 pCommand->Flags &= (~VBOXVHWACMD_FLAG_HG_ASYNCH);
3536 pCommand->rc = rc;
3537 }
3538}
3539
3540DECLCALLBACK(void) Display::displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
3541{
3542 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3543
3544 pDrv->pDisplay->handleVHWACommandProcess(pInterface, pCommand);
3545}
3546#endif
3547
3548#ifdef VBOX_WITH_CRHGSMI
3549void Display::handleCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam)
3550{
3551 mpDrv->pVBVACallbacks->pfnCrHgsmiCommandCompleteAsync(mpDrv->pVBVACallbacks, (PVBOXVDMACMD_CHROMIUM_CMD)pParam->u.pointer.addr, result);
3552}
3553
3554void Display::handleCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam)
3555{
3556 mpDrv->pVBVACallbacks->pfnCrHgsmiControlCompleteAsync(mpDrv->pVBVACallbacks, (PVBOXVDMACMD_CHROMIUM_CTL)pParam->u.pointer.addr, result);
3557}
3558
3559void Display::handleCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd)
3560{
3561 int rc = VERR_INVALID_FUNCTION;
3562 VBOXHGCMSVCPARM parm;
3563 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3564 parm.u.pointer.addr = pCmd;
3565 parm.u.pointer.size = 0;
3566
3567 if (mhCrOglSvc)
3568 {
3569 VMMDev *pVMMDev = mParent->getVMMDev();
3570 if (pVMMDev)
3571 {
3572 rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CRHGSMI_CMD, &parm, Display::displayCrHgsmiCommandCompletion, this);
3573 AssertRC(rc);
3574 if (RT_SUCCESS(rc))
3575 return;
3576 }
3577 else
3578 rc = VERR_INVALID_STATE;
3579 }
3580
3581 /* we are here because something went wrong with command processing, complete it */
3582 handleCrHgsmiCommandCompletion(rc, SHCRGL_HOST_FN_CRHGSMI_CMD, &parm);
3583}
3584
3585void Display::handleCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl)
3586{
3587 int rc = VERR_INVALID_FUNCTION;
3588 VBOXHGCMSVCPARM parm;
3589 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3590 parm.u.pointer.addr = pCtl;
3591 parm.u.pointer.size = 0;
3592
3593 if (mhCrOglSvc)
3594 {
3595 VMMDev *pVMMDev = mParent->getVMMDev();
3596 if (pVMMDev)
3597 {
3598 rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CRHGSMI_CTL, &parm, Display::displayCrHgsmiControlCompletion, this);
3599 AssertRC(rc);
3600 if (RT_SUCCESS(rc))
3601 return;
3602 }
3603 else
3604 rc = VERR_INVALID_STATE;
3605 }
3606
3607 /* we are here because something went wrong with command processing, complete it */
3608 handleCrHgsmiControlCompletion(rc, SHCRGL_HOST_FN_CRHGSMI_CTL, &parm);
3609}
3610
3611DECLCALLBACK(void) Display::displayCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd)
3612{
3613 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3614
3615 pDrv->pDisplay->handleCrHgsmiCommandProcess(pInterface, pCmd);
3616}
3617
3618DECLCALLBACK(void) Display::displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCmd)
3619{
3620 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3621
3622 pDrv->pDisplay->handleCrHgsmiControlProcess(pInterface, pCmd);
3623}
3624
3625DECLCALLBACK(void) Display::displayCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext)
3626{
3627 Display *pDisplay = (Display *)pvContext;
3628 pDisplay->handleCrHgsmiCommandCompletion(result, u32Function, pParam);
3629}
3630
3631DECLCALLBACK(void) Display::displayCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext)
3632{
3633 Display *pDisplay = (Display *)pvContext;
3634 pDisplay->handleCrHgsmiControlCompletion(result, u32Function, pParam);
3635}
3636#endif
3637
3638
3639#ifdef VBOX_WITH_HGSMI
3640DECLCALLBACK(int) Display::displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags)
3641{
3642 LogFlowFunc(("uScreenId %d\n", uScreenId));
3643
3644 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3645 Display *pThis = pDrv->pDisplay;
3646
3647 pThis->maFramebuffers[uScreenId].fVBVAEnabled = true;
3648 pThis->maFramebuffers[uScreenId].pVBVAHostFlags = pHostFlags;
3649
3650 vbvaSetMemoryFlagsHGSMI(uScreenId, pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, &pThis->maFramebuffers[uScreenId]);
3651
3652 return VINF_SUCCESS;
3653}
3654
3655DECLCALLBACK(void) Display::displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3656{
3657 LogFlowFunc(("uScreenId %d\n", uScreenId));
3658
3659 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3660 Display *pThis = pDrv->pDisplay;
3661
3662 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3663
3664 pFBInfo->fVBVAEnabled = false;
3665
3666 vbvaSetMemoryFlagsHGSMI(uScreenId, 0, false, pFBInfo);
3667
3668 pFBInfo->pVBVAHostFlags = NULL;
3669
3670 pFBInfo->u32Offset = 0; /* Not used in HGSMI. */
3671 pFBInfo->u32MaxFramebufferSize = 0; /* Not used in HGSMI. */
3672 pFBInfo->u32InformationSize = 0; /* Not used in HGSMI. */
3673
3674 pFBInfo->xOrigin = 0;
3675 pFBInfo->yOrigin = 0;
3676
3677 pFBInfo->w = 0;
3678 pFBInfo->h = 0;
3679
3680 pFBInfo->u16BitsPerPixel = 0;
3681 pFBInfo->pu8FramebufferVRAM = NULL;
3682 pFBInfo->u32LineSize = 0;
3683}
3684
3685DECLCALLBACK(void) Display::displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3686{
3687 LogFlowFunc(("uScreenId %d\n", uScreenId));
3688
3689 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3690 Display *pThis = pDrv->pDisplay;
3691 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3692
3693 if (ASMAtomicReadU32(&pThis->mu32UpdateVBVAFlags) > 0)
3694 {
3695 vbvaSetMemoryFlagsAllHGSMI(pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, pThis->maFramebuffers, pThis->mcMonitors);
3696 ASMAtomicDecU32(&pThis->mu32UpdateVBVAFlags);
3697 }
3698
3699 if (RT_LIKELY(pFBInfo->u32ResizeStatus == ResizeStatus_Void))
3700 {
3701 if (RT_UNLIKELY(pFBInfo->cVBVASkipUpdate != 0))
3702 {
3703 /* Some updates were skipped. Note: displayVBVAUpdate* callbacks are called
3704 * under display device lock, so thread safe.
3705 */
3706 pFBInfo->cVBVASkipUpdate = 0;
3707 pThis->handleDisplayUpdate(uScreenId, pFBInfo->vbvaSkippedRect.xLeft - pFBInfo->xOrigin,
3708 pFBInfo->vbvaSkippedRect.yTop - pFBInfo->yOrigin,
3709 pFBInfo->vbvaSkippedRect.xRight - pFBInfo->vbvaSkippedRect.xLeft,
3710 pFBInfo->vbvaSkippedRect.yBottom - pFBInfo->vbvaSkippedRect.yTop);
3711 }
3712 }
3713 else
3714 {
3715 /* The framebuffer is being resized. */
3716 pFBInfo->cVBVASkipUpdate++;
3717 }
3718}
3719
3720DECLCALLBACK(void) Display::displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd)
3721{
3722 LogFlowFunc(("uScreenId %d pCmd %p cbCmd %d, @%d,%d %dx%d\n", uScreenId, pCmd, cbCmd, pCmd->x, pCmd->y, pCmd->w, pCmd->h));
3723
3724 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3725 Display *pThis = pDrv->pDisplay;
3726 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3727
3728 if (RT_LIKELY(pFBInfo->cVBVASkipUpdate == 0))
3729 {
3730 if (pFBInfo->fDefaultFormat)
3731 {
3732 /* Make sure that framebuffer contains the same image as the guest VRAM. */
3733 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN && !pFBInfo->pFramebuffer.isNull())
3734 {
3735 pDrv->pUpPort->pfnUpdateDisplayRect (pDrv->pUpPort, pCmd->x, pCmd->y, pCmd->w, pCmd->h);
3736 }
3737 else if (!pFBInfo->pFramebuffer.isNull())
3738 {
3739 /* Render VRAM content to the framebuffer. */
3740 BYTE *address = NULL;
3741 HRESULT hrc = pFBInfo->pFramebuffer->COMGETTER(Address) (&address);
3742 if (SUCCEEDED(hrc) && address != NULL)
3743 {
3744 uint32_t width = pCmd->w;
3745 uint32_t height = pCmd->h;
3746
3747 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
3748 int32_t xSrc = pCmd->x - pFBInfo->xOrigin;
3749 int32_t ySrc = pCmd->y - pFBInfo->yOrigin;
3750 uint32_t u32SrcWidth = pFBInfo->w;
3751 uint32_t u32SrcHeight = pFBInfo->h;
3752 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
3753 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
3754
3755 uint8_t *pu8Dst = address;
3756 int32_t xDst = xSrc;
3757 int32_t yDst = ySrc;
3758 uint32_t u32DstWidth = u32SrcWidth;
3759 uint32_t u32DstHeight = u32SrcHeight;
3760 uint32_t u32DstLineSize = u32DstWidth * 4;
3761 uint32_t u32DstBitsPerPixel = 32;
3762
3763 pDrv->pUpPort->pfnCopyRect(pDrv->pUpPort,
3764 width, height,
3765 pu8Src,
3766 xSrc, ySrc,
3767 u32SrcWidth, u32SrcHeight,
3768 u32SrcLineSize, u32SrcBitsPerPixel,
3769 pu8Dst,
3770 xDst, yDst,
3771 u32DstWidth, u32DstHeight,
3772 u32DstLineSize, u32DstBitsPerPixel);
3773 }
3774 }
3775 }
3776
3777 VBVACMDHDR hdrSaved = *pCmd;
3778
3779 VBVACMDHDR *pHdrUnconst = (VBVACMDHDR *)pCmd;
3780
3781 pHdrUnconst->x -= (int16_t)pFBInfo->xOrigin;
3782 pHdrUnconst->y -= (int16_t)pFBInfo->yOrigin;
3783
3784 /* @todo new SendUpdate entry which can get a separate cmd header or coords. */
3785 pThis->mParent->consoleVRDPServer()->SendUpdate (uScreenId, pCmd, cbCmd);
3786
3787 *pHdrUnconst = hdrSaved;
3788 }
3789}
3790
3791DECLCALLBACK(void) Display::displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy)
3792{
3793 LogFlowFunc(("uScreenId %d %d,%d %dx%d\n", uScreenId, x, y, cx, cy));
3794
3795 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3796 Display *pThis = pDrv->pDisplay;
3797 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3798
3799 /* @todo handleFramebufferUpdate (uScreenId,
3800 * x - pThis->maFramebuffers[uScreenId].xOrigin,
3801 * y - pThis->maFramebuffers[uScreenId].yOrigin,
3802 * cx, cy);
3803 */
3804 if (RT_LIKELY(pFBInfo->cVBVASkipUpdate == 0))
3805 {
3806 pThis->handleDisplayUpdate(uScreenId, x - pFBInfo->xOrigin, y - pFBInfo->yOrigin, cx, cy);
3807 }
3808 else
3809 {
3810 /* Save the updated rectangle. */
3811 int32_t xRight = x + cx;
3812 int32_t yBottom = y + cy;
3813
3814 if (pFBInfo->cVBVASkipUpdate == 1)
3815 {
3816 pFBInfo->vbvaSkippedRect.xLeft = x;
3817 pFBInfo->vbvaSkippedRect.yTop = y;
3818 pFBInfo->vbvaSkippedRect.xRight = xRight;
3819 pFBInfo->vbvaSkippedRect.yBottom = yBottom;
3820 }
3821 else
3822 {
3823 if (pFBInfo->vbvaSkippedRect.xLeft > x)
3824 {
3825 pFBInfo->vbvaSkippedRect.xLeft = x;
3826 }
3827 if (pFBInfo->vbvaSkippedRect.yTop > y)
3828 {
3829 pFBInfo->vbvaSkippedRect.yTop = y;
3830 }
3831 if (pFBInfo->vbvaSkippedRect.xRight < xRight)
3832 {
3833 pFBInfo->vbvaSkippedRect.xRight = xRight;
3834 }
3835 if (pFBInfo->vbvaSkippedRect.yBottom < yBottom)
3836 {
3837 pFBInfo->vbvaSkippedRect.yBottom = yBottom;
3838 }
3839 }
3840 }
3841}
3842
3843DECLCALLBACK(int) Display::displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM)
3844{
3845 LogFlowFunc(("pScreen %p, pvVRAM %p\n", pScreen, pvVRAM));
3846
3847 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3848 Display *pThis = pDrv->pDisplay;
3849
3850 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[pScreen->u32ViewIndex];
3851
3852 if (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)
3853 {
3854 fireGuestMonitorDisabledEvent(pThis->mParent->getEventSource(), pScreen->u32ViewIndex);
3855 return VINF_SUCCESS;
3856 }
3857
3858 /* Check if this is a real resize or a notification about the screen origin.
3859 * The guest uses this VBVAResize call for both.
3860 */
3861 bool fResize = pFBInfo->u16BitsPerPixel != pScreen->u16BitsPerPixel
3862 || pFBInfo->pu8FramebufferVRAM != (uint8_t *)pvVRAM + pScreen->u32StartOffset
3863 || pFBInfo->u32LineSize != pScreen->u32LineSize
3864 || pFBInfo->w != pScreen->u32Width
3865 || pFBInfo->h != pScreen->u32Height;
3866
3867 bool fNewOrigin = pFBInfo->xOrigin != pScreen->i32OriginX
3868 || pFBInfo->yOrigin != pScreen->i32OriginY;
3869
3870 pFBInfo->u32Offset = pView->u32ViewOffset; /* Not used in HGSMI. */
3871 pFBInfo->u32MaxFramebufferSize = pView->u32MaxScreenSize; /* Not used in HGSMI. */
3872 pFBInfo->u32InformationSize = 0; /* Not used in HGSMI. */
3873
3874 pFBInfo->xOrigin = pScreen->i32OriginX;
3875 pFBInfo->yOrigin = pScreen->i32OriginY;
3876
3877 pFBInfo->w = pScreen->u32Width;
3878 pFBInfo->h = pScreen->u32Height;
3879
3880 pFBInfo->u16BitsPerPixel = pScreen->u16BitsPerPixel;
3881 pFBInfo->pu8FramebufferVRAM = (uint8_t *)pvVRAM + pScreen->u32StartOffset;
3882 pFBInfo->u32LineSize = pScreen->u32LineSize;
3883
3884 pFBInfo->flags = pScreen->u16Flags;
3885
3886 if (fNewOrigin)
3887 {
3888 /* @todo May be framebuffer/display should be notified in this case. */
3889 }
3890
3891#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
3892 if (fNewOrigin && !fResize)
3893 {
3894 BOOL is3denabled;
3895 pThis->mParent->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
3896
3897 if (is3denabled)
3898 {
3899 VBOXHGCMSVCPARM parm;
3900
3901 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
3902 parm.u.uint32 = pScreen->u32ViewIndex;
3903
3904 VMMDev *pVMMDev = pThis->mParent->getVMMDev();
3905
3906 if (pVMMDev)
3907 pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SCREEN_CHANGED, SHCRGL_CPARMS_SCREEN_CHANGED, &parm);
3908 }
3909 }
3910#endif /* VBOX_WITH_CROGL */
3911
3912 if (!fResize)
3913 {
3914 /* No parameters of the framebuffer have actually changed. */
3915 if (fNewOrigin)
3916 {
3917 /* VRDP server still need this notification. */
3918 LogFlowFunc (("Calling VRDP\n"));
3919 pThis->mParent->consoleVRDPServer()->SendResize();
3920 }
3921 return VINF_SUCCESS;
3922 }
3923
3924 return pThis->handleDisplayResize(pScreen->u32ViewIndex, pScreen->u16BitsPerPixel,
3925 (uint8_t *)pvVRAM + pScreen->u32StartOffset,
3926 pScreen->u32LineSize, pScreen->u32Width, pScreen->u32Height, pScreen->u16Flags);
3927}
3928
3929DECLCALLBACK(int) Display::displayVBVAMousePointerShape(PPDMIDISPLAYCONNECTOR pInterface, bool fVisible, bool fAlpha,
3930 uint32_t xHot, uint32_t yHot,
3931 uint32_t cx, uint32_t cy,
3932 const void *pvShape)
3933{
3934 LogFlowFunc(("\n"));
3935
3936 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3937 Display *pThis = pDrv->pDisplay;
3938
3939 size_t cbShapeSize = 0;
3940
3941 if (pvShape)
3942 {
3943 cbShapeSize = (cx + 7) / 8 * cy; /* size of the AND mask */
3944 cbShapeSize = ((cbShapeSize + 3) & ~3) + cx * 4 * cy; /* + gap + size of the XOR mask */
3945 }
3946 com::SafeArray<BYTE> shapeData(cbShapeSize);
3947
3948 if (pvShape)
3949 ::memcpy(shapeData.raw(), pvShape, cbShapeSize);
3950
3951 /* Tell the console about it */
3952 pDrv->pDisplay->mParent->onMousePointerShapeChange(fVisible, fAlpha,
3953 xHot, yHot, cx, cy, ComSafeArrayAsInParam(shapeData));
3954
3955 return VINF_SUCCESS;
3956}
3957#endif /* VBOX_WITH_HGSMI */
3958
3959/**
3960 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
3961 */
3962DECLCALLBACK(void *) Display::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
3963{
3964 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
3965 PDRVMAINDISPLAY pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3966 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
3967 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIDISPLAYCONNECTOR, &pDrv->IConnector);
3968 return NULL;
3969}
3970
3971
3972/**
3973 * Destruct a display driver instance.
3974 *
3975 * @returns VBox status.
3976 * @param pDrvIns The driver instance data.
3977 */
3978DECLCALLBACK(void) Display::drvDestruct(PPDMDRVINS pDrvIns)
3979{
3980 PDRVMAINDISPLAY pData = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3981 LogFlowFunc (("iInstance=%d\n", pDrvIns->iInstance));
3982 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
3983
3984 if (pData->pDisplay)
3985 {
3986 AutoWriteLock displayLock(pData->pDisplay COMMA_LOCKVAL_SRC_POS);
3987#ifdef VBOX_WITH_CRHGSMI
3988 pData->pDisplay->destructCrHgsmiData();
3989#endif
3990 pData->pDisplay->mpDrv = NULL;
3991 pData->pDisplay->mpVMMDev = NULL;
3992 pData->pDisplay->mLastAddress = NULL;
3993 pData->pDisplay->mLastBytesPerLine = 0;
3994 pData->pDisplay->mLastBitsPerPixel = 0,
3995 pData->pDisplay->mLastWidth = 0;
3996 pData->pDisplay->mLastHeight = 0;
3997 }
3998}
3999
4000
4001/**
4002 * Construct a display driver instance.
4003 *
4004 * @copydoc FNPDMDRVCONSTRUCT
4005 */
4006DECLCALLBACK(int) Display::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
4007{
4008 PDRVMAINDISPLAY pData = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
4009 LogFlowFunc (("iInstance=%d\n", pDrvIns->iInstance));
4010 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
4011
4012 /*
4013 * Validate configuration.
4014 */
4015 if (!CFGMR3AreValuesValid(pCfg, "Object\0"))
4016 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
4017 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
4018 ("Configuration error: Not possible to attach anything to this driver!\n"),
4019 VERR_PDM_DRVINS_NO_ATTACH);
4020
4021 /*
4022 * Init Interfaces.
4023 */
4024 pDrvIns->IBase.pfnQueryInterface = Display::drvQueryInterface;
4025
4026 pData->IConnector.pfnResize = Display::displayResizeCallback;
4027 pData->IConnector.pfnUpdateRect = Display::displayUpdateCallback;
4028 pData->IConnector.pfnRefresh = Display::displayRefreshCallback;
4029 pData->IConnector.pfnReset = Display::displayResetCallback;
4030 pData->IConnector.pfnLFBModeChange = Display::displayLFBModeChangeCallback;
4031 pData->IConnector.pfnProcessAdapterData = Display::displayProcessAdapterDataCallback;
4032 pData->IConnector.pfnProcessDisplayData = Display::displayProcessDisplayDataCallback;
4033#ifdef VBOX_WITH_VIDEOHWACCEL
4034 pData->IConnector.pfnVHWACommandProcess = Display::displayVHWACommandProcess;
4035#endif
4036#ifdef VBOX_WITH_CRHGSMI
4037 pData->IConnector.pfnCrHgsmiCommandProcess = Display::displayCrHgsmiCommandProcess;
4038 pData->IConnector.pfnCrHgsmiControlProcess = Display::displayCrHgsmiControlProcess;
4039#endif
4040#ifdef VBOX_WITH_HGSMI
4041 pData->IConnector.pfnVBVAEnable = Display::displayVBVAEnable;
4042 pData->IConnector.pfnVBVADisable = Display::displayVBVADisable;
4043 pData->IConnector.pfnVBVAUpdateBegin = Display::displayVBVAUpdateBegin;
4044 pData->IConnector.pfnVBVAUpdateProcess = Display::displayVBVAUpdateProcess;
4045 pData->IConnector.pfnVBVAUpdateEnd = Display::displayVBVAUpdateEnd;
4046 pData->IConnector.pfnVBVAResize = Display::displayVBVAResize;
4047 pData->IConnector.pfnVBVAMousePointerShape = Display::displayVBVAMousePointerShape;
4048#endif
4049
4050
4051 /*
4052 * Get the IDisplayPort interface of the above driver/device.
4053 */
4054 pData->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYPORT);
4055 if (!pData->pUpPort)
4056 {
4057 AssertMsgFailed(("Configuration error: No display port interface above!\n"));
4058 return VERR_PDM_MISSING_INTERFACE_ABOVE;
4059 }
4060#if defined(VBOX_WITH_VIDEOHWACCEL) || defined(VBOX_WITH_CRHGSMI)
4061 pData->pVBVACallbacks = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYVBVACALLBACKS);
4062 if (!pData->pVBVACallbacks)
4063 {
4064 AssertMsgFailed(("Configuration error: No VBVA callback interface above!\n"));
4065 return VERR_PDM_MISSING_INTERFACE_ABOVE;
4066 }
4067#endif
4068 /*
4069 * Get the Display object pointer and update the mpDrv member.
4070 */
4071 void *pv;
4072 int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
4073 if (RT_FAILURE(rc))
4074 {
4075 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
4076 return rc;
4077 }
4078 pData->pDisplay = (Display *)pv; /** @todo Check this cast! */
4079 pData->pDisplay->mpDrv = pData;
4080
4081 /*
4082 * Update our display information according to the framebuffer
4083 */
4084 pData->pDisplay->updateDisplayData();
4085
4086 /*
4087 * Start periodic screen refreshes
4088 */
4089 pData->pUpPort->pfnSetRefreshRate(pData->pUpPort, 20);
4090
4091#ifdef VBOX_WITH_CRHGSMI
4092 pData->pDisplay->setupCrHgsmiData();
4093#endif
4094
4095 return VINF_SUCCESS;
4096}
4097
4098
4099/**
4100 * Display driver registration record.
4101 */
4102const PDMDRVREG Display::DrvReg =
4103{
4104 /* u32Version */
4105 PDM_DRVREG_VERSION,
4106 /* szName */
4107 "MainDisplay",
4108 /* szRCMod */
4109 "",
4110 /* szR0Mod */
4111 "",
4112 /* pszDescription */
4113 "Main display driver (Main as in the API).",
4114 /* fFlags */
4115 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
4116 /* fClass. */
4117 PDM_DRVREG_CLASS_DISPLAY,
4118 /* cMaxInstances */
4119 ~0,
4120 /* cbInstance */
4121 sizeof(DRVMAINDISPLAY),
4122 /* pfnConstruct */
4123 Display::drvConstruct,
4124 /* pfnDestruct */
4125 Display::drvDestruct,
4126 /* pfnRelocate */
4127 NULL,
4128 /* pfnIOCtl */
4129 NULL,
4130 /* pfnPowerOn */
4131 NULL,
4132 /* pfnReset */
4133 NULL,
4134 /* pfnSuspend */
4135 NULL,
4136 /* pfnResume */
4137 NULL,
4138 /* pfnAttach */
4139 NULL,
4140 /* pfnDetach */
4141 NULL,
4142 /* pfnPowerOff */
4143 NULL,
4144 /* pfnSoftReset */
4145 NULL,
4146 /* u32EndVersion */
4147 PDM_DRVREG_VERSION
4148};
4149/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette