VirtualBox

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

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

Main::Display: use screen id in VBVA mode.

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