VirtualBox

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

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

Main/VMMDev: optionally report multi-monitor mouse co-ordinates relative to the whole virtual framebuffer and not to the first screen

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 131.9 KB
Line 
1/* $Id: DisplayImpl.cpp 34754 2010-12-06 14:40:03Z 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
934void Display::getFramebufferDimensions(int32_t *px1, int32_t *py1,
935 int32_t *px2, int32_t *py2)
936{
937 AssertPtrReturnVoid(px1);
938 AssertPtrReturnVoid(py1);
939 AssertPtrReturnVoid(px2);
940 AssertPtrReturnVoid(py2);
941 int32_t x1 = 0, y1 = 0, x2 = 0, y2 = 0;
942 for (unsigned i = 0; i < mcMonitors; ++i)
943 {
944 x1 = RT_MIN(x1, maFramebuffers[i].xOrigin);
945 y1 = RT_MIN(y1, maFramebuffers[i].yOrigin);
946 x2 = RT_MAX(x2, maFramebuffers[i].xOrigin + (int32_t)maFramebuffers[i].w);
947 y2 = RT_MAX(y2, maFramebuffers[i].yOrigin + (int32_t)maFramebuffers[i].h);
948 }
949 *px1 = x1;
950 *py1 = y1;
951 *px2 = x2;
952 *py2 = y2;
953}
954
955#ifdef MMSEAMLESS
956static bool displayIntersectRect(RTRECT *prectResult,
957 const RTRECT *prect1,
958 const RTRECT *prect2)
959{
960 /* Initialize result to an empty record. */
961 memset (prectResult, 0, sizeof (RTRECT));
962
963 int xLeftResult = RT_MAX(prect1->xLeft, prect2->xLeft);
964 int xRightResult = RT_MIN(prect1->xRight, prect2->xRight);
965
966 if (xLeftResult < xRightResult)
967 {
968 /* There is intersection by X. */
969
970 int yTopResult = RT_MAX(prect1->yTop, prect2->yTop);
971 int yBottomResult = RT_MIN(prect1->yBottom, prect2->yBottom);
972
973 if (yTopResult < yBottomResult)
974 {
975 /* There is intersection by Y. */
976
977 prectResult->xLeft = xLeftResult;
978 prectResult->yTop = yTopResult;
979 prectResult->xRight = xRightResult;
980 prectResult->yBottom = yBottomResult;
981
982 return true;
983 }
984 }
985
986 return false;
987}
988
989int Display::handleSetVisibleRegion(uint32_t cRect, PRTRECT pRect)
990{
991 RTRECT *pVisibleRegion = (RTRECT *)RTMemTmpAlloc(cRect * sizeof (RTRECT));
992 if (!pVisibleRegion)
993 {
994 return VERR_NO_TMP_MEMORY;
995 }
996
997 unsigned uScreenId;
998 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
999 {
1000 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1001
1002 if (!pFBInfo->pFramebuffer.isNull())
1003 {
1004 /* Prepare a new array of rectangles which intersect with the framebuffer.
1005 */
1006 RTRECT rectFramebuffer;
1007 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
1008 {
1009 rectFramebuffer.xLeft = 0;
1010 rectFramebuffer.yTop = 0;
1011 if (mpDrv)
1012 {
1013 rectFramebuffer.xRight = mpDrv->IConnector.cx;
1014 rectFramebuffer.yBottom = mpDrv->IConnector.cy;
1015 }
1016 else
1017 {
1018 rectFramebuffer.xRight = 0;
1019 rectFramebuffer.yBottom = 0;
1020 }
1021 }
1022 else
1023 {
1024 rectFramebuffer.xLeft = pFBInfo->xOrigin;
1025 rectFramebuffer.yTop = pFBInfo->yOrigin;
1026 rectFramebuffer.xRight = pFBInfo->xOrigin + pFBInfo->w;
1027 rectFramebuffer.yBottom = pFBInfo->yOrigin + pFBInfo->h;
1028 }
1029
1030 uint32_t cRectVisibleRegion = 0;
1031
1032 uint32_t i;
1033 for (i = 0; i < cRect; i++)
1034 {
1035 if (displayIntersectRect(&pVisibleRegion[cRectVisibleRegion], &pRect[i], &rectFramebuffer))
1036 {
1037 pVisibleRegion[cRectVisibleRegion].xLeft -= pFBInfo->xOrigin;
1038 pVisibleRegion[cRectVisibleRegion].yTop -= pFBInfo->yOrigin;
1039 pVisibleRegion[cRectVisibleRegion].xRight -= pFBInfo->xOrigin;
1040 pVisibleRegion[cRectVisibleRegion].yBottom -= pFBInfo->yOrigin;
1041
1042 cRectVisibleRegion++;
1043 }
1044 }
1045
1046 if (cRectVisibleRegion > 0)
1047 {
1048 pFBInfo->pFramebuffer->SetVisibleRegion((BYTE *)pVisibleRegion, cRectVisibleRegion);
1049 }
1050 }
1051 }
1052
1053#if defined(RT_OS_DARWIN) && defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
1054 // @todo fix for multimonitor
1055 BOOL is3denabled = FALSE;
1056
1057 mParent->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
1058
1059 VMMDev *vmmDev = mParent->getVMMDev();
1060 if (is3denabled && vmmDev)
1061 {
1062 VBOXHGCMSVCPARM parms[2];
1063
1064 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
1065 parms[0].u.pointer.addr = pRect;
1066 parms[0].u.pointer.size = 0; /* We don't actually care. */
1067 parms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
1068 parms[1].u.uint32 = cRect;
1069
1070 vmmDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VISIBLE_REGION, 2, &parms[0]);
1071 }
1072#endif
1073
1074 RTMemTmpFree(pVisibleRegion);
1075
1076 return VINF_SUCCESS;
1077}
1078
1079int Display::handleQueryVisibleRegion(uint32_t *pcRect, PRTRECT pRect)
1080{
1081 // @todo Currently not used by the guest and is not implemented in framebuffers. Remove?
1082 return VERR_NOT_SUPPORTED;
1083}
1084#endif
1085
1086typedef struct _VBVADIRTYREGION
1087{
1088 /* Copies of object's pointers used by vbvaRgn functions. */
1089 DISPLAYFBINFO *paFramebuffers;
1090 unsigned cMonitors;
1091 Display *pDisplay;
1092 PPDMIDISPLAYPORT pPort;
1093
1094} VBVADIRTYREGION;
1095
1096static void vbvaRgnInit (VBVADIRTYREGION *prgn, DISPLAYFBINFO *paFramebuffers, unsigned cMonitors, Display *pd, PPDMIDISPLAYPORT pp)
1097{
1098 prgn->paFramebuffers = paFramebuffers;
1099 prgn->cMonitors = cMonitors;
1100 prgn->pDisplay = pd;
1101 prgn->pPort = pp;
1102
1103 unsigned uScreenId;
1104 for (uScreenId = 0; uScreenId < cMonitors; uScreenId++)
1105 {
1106 DISPLAYFBINFO *pFBInfo = &prgn->paFramebuffers[uScreenId];
1107
1108 memset (&pFBInfo->dirtyRect, 0, sizeof (pFBInfo->dirtyRect));
1109 }
1110}
1111
1112static void vbvaRgnDirtyRect (VBVADIRTYREGION *prgn, unsigned uScreenId, VBVACMDHDR *phdr)
1113{
1114 LogSunlover (("x = %d, y = %d, w = %d, h = %d\n",
1115 phdr->x, phdr->y, phdr->w, phdr->h));
1116
1117 /*
1118 * Here update rectangles are accumulated to form an update area.
1119 * @todo
1120 * Now the simplest method is used which builds one rectangle that
1121 * includes all update areas. A bit more advanced method can be
1122 * employed here. The method should be fast however.
1123 */
1124 if (phdr->w == 0 || phdr->h == 0)
1125 {
1126 /* Empty rectangle. */
1127 return;
1128 }
1129
1130 int32_t xRight = phdr->x + phdr->w;
1131 int32_t yBottom = phdr->y + phdr->h;
1132
1133 DISPLAYFBINFO *pFBInfo = &prgn->paFramebuffers[uScreenId];
1134
1135 if (pFBInfo->dirtyRect.xRight == 0)
1136 {
1137 /* This is the first rectangle to be added. */
1138 pFBInfo->dirtyRect.xLeft = phdr->x;
1139 pFBInfo->dirtyRect.yTop = phdr->y;
1140 pFBInfo->dirtyRect.xRight = xRight;
1141 pFBInfo->dirtyRect.yBottom = yBottom;
1142 }
1143 else
1144 {
1145 /* Adjust region coordinates. */
1146 if (pFBInfo->dirtyRect.xLeft > phdr->x)
1147 {
1148 pFBInfo->dirtyRect.xLeft = phdr->x;
1149 }
1150
1151 if (pFBInfo->dirtyRect.yTop > phdr->y)
1152 {
1153 pFBInfo->dirtyRect.yTop = phdr->y;
1154 }
1155
1156 if (pFBInfo->dirtyRect.xRight < xRight)
1157 {
1158 pFBInfo->dirtyRect.xRight = xRight;
1159 }
1160
1161 if (pFBInfo->dirtyRect.yBottom < yBottom)
1162 {
1163 pFBInfo->dirtyRect.yBottom = yBottom;
1164 }
1165 }
1166
1167 if (pFBInfo->fDefaultFormat)
1168 {
1169 //@todo pfnUpdateDisplayRect must take the vram offset parameter for the framebuffer
1170 prgn->pPort->pfnUpdateDisplayRect (prgn->pPort, phdr->x, phdr->y, phdr->w, phdr->h);
1171 prgn->pDisplay->handleDisplayUpdateLegacy (phdr->x + pFBInfo->xOrigin,
1172 phdr->y + pFBInfo->yOrigin, phdr->w, phdr->h);
1173 }
1174
1175 return;
1176}
1177
1178static void vbvaRgnUpdateFramebuffer (VBVADIRTYREGION *prgn, unsigned uScreenId)
1179{
1180 DISPLAYFBINFO *pFBInfo = &prgn->paFramebuffers[uScreenId];
1181
1182 uint32_t w = pFBInfo->dirtyRect.xRight - pFBInfo->dirtyRect.xLeft;
1183 uint32_t h = pFBInfo->dirtyRect.yBottom - pFBInfo->dirtyRect.yTop;
1184
1185 if (!pFBInfo->fDefaultFormat && pFBInfo->pFramebuffer && w != 0 && h != 0)
1186 {
1187 //@todo pfnUpdateDisplayRect must take the vram offset parameter for the framebuffer
1188 prgn->pPort->pfnUpdateDisplayRect (prgn->pPort, pFBInfo->dirtyRect.xLeft, pFBInfo->dirtyRect.yTop, w, h);
1189 prgn->pDisplay->handleDisplayUpdateLegacy (pFBInfo->dirtyRect.xLeft + pFBInfo->xOrigin,
1190 pFBInfo->dirtyRect.yTop + pFBInfo->yOrigin, w, h);
1191 }
1192}
1193
1194static void vbvaSetMemoryFlags (VBVAMEMORY *pVbvaMemory,
1195 bool fVideoAccelEnabled,
1196 bool fVideoAccelVRDP,
1197 uint32_t fu32SupportedOrders,
1198 DISPLAYFBINFO *paFBInfos,
1199 unsigned cFBInfos)
1200{
1201 if (pVbvaMemory)
1202 {
1203 /* This called only on changes in mode. So reset VRDP always. */
1204 uint32_t fu32Flags = VBVA_F_MODE_VRDP_RESET;
1205
1206 if (fVideoAccelEnabled)
1207 {
1208 fu32Flags |= VBVA_F_MODE_ENABLED;
1209
1210 if (fVideoAccelVRDP)
1211 {
1212 fu32Flags |= VBVA_F_MODE_VRDP | VBVA_F_MODE_VRDP_ORDER_MASK;
1213
1214 pVbvaMemory->fu32SupportedOrders = fu32SupportedOrders;
1215 }
1216 }
1217
1218 pVbvaMemory->fu32ModeFlags = fu32Flags;
1219 }
1220
1221 unsigned uScreenId;
1222 for (uScreenId = 0; uScreenId < cFBInfos; uScreenId++)
1223 {
1224 if (paFBInfos[uScreenId].pHostEvents)
1225 {
1226 paFBInfos[uScreenId].pHostEvents->fu32Events |= VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
1227 }
1228 }
1229}
1230
1231#ifdef VBOX_WITH_HGSMI
1232static void vbvaSetMemoryFlagsHGSMI (unsigned uScreenId,
1233 uint32_t fu32SupportedOrders,
1234 bool fVideoAccelVRDP,
1235 DISPLAYFBINFO *pFBInfo)
1236{
1237 LogFlowFunc(("HGSMI[%d]: %p\n", uScreenId, pFBInfo->pVBVAHostFlags));
1238
1239 if (pFBInfo->pVBVAHostFlags)
1240 {
1241 uint32_t fu32HostEvents = VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
1242
1243 if (pFBInfo->fVBVAEnabled)
1244 {
1245 fu32HostEvents |= VBVA_F_MODE_ENABLED;
1246
1247 if (fVideoAccelVRDP)
1248 {
1249 fu32HostEvents |= VBVA_F_MODE_VRDP;
1250 }
1251 }
1252
1253 ASMAtomicWriteU32(&pFBInfo->pVBVAHostFlags->u32HostEvents, fu32HostEvents);
1254 ASMAtomicWriteU32(&pFBInfo->pVBVAHostFlags->u32SupportedOrders, fu32SupportedOrders);
1255
1256 LogFlowFunc((" fu32HostEvents = 0x%08X, fu32SupportedOrders = 0x%08X\n", fu32HostEvents, fu32SupportedOrders));
1257 }
1258}
1259
1260static void vbvaSetMemoryFlagsAllHGSMI (uint32_t fu32SupportedOrders,
1261 bool fVideoAccelVRDP,
1262 DISPLAYFBINFO *paFBInfos,
1263 unsigned cFBInfos)
1264{
1265 unsigned uScreenId;
1266
1267 for (uScreenId = 0; uScreenId < cFBInfos; uScreenId++)
1268 {
1269 vbvaSetMemoryFlagsHGSMI(uScreenId, fu32SupportedOrders, fVideoAccelVRDP, &paFBInfos[uScreenId]);
1270 }
1271}
1272#endif /* VBOX_WITH_HGSMI */
1273
1274bool Display::VideoAccelAllowed (void)
1275{
1276 return true;
1277}
1278
1279#ifdef VBOX_WITH_OLD_VBVA_LOCK
1280int Display::vbvaLock(void)
1281{
1282 return RTCritSectEnter(&mVBVALock);
1283}
1284
1285void Display::vbvaUnlock(void)
1286{
1287 RTCritSectLeave(&mVBVALock);
1288}
1289#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1290
1291/**
1292 * @thread EMT
1293 */
1294#ifdef VBOX_WITH_OLD_VBVA_LOCK
1295int Display::VideoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory)
1296{
1297 int rc;
1298 vbvaLock();
1299 rc = videoAccelEnable (fEnable, pVbvaMemory);
1300 vbvaUnlock();
1301 return rc;
1302}
1303#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1304
1305#ifdef VBOX_WITH_OLD_VBVA_LOCK
1306int Display::videoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory)
1307#else
1308int Display::VideoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory)
1309#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1310{
1311 int rc = VINF_SUCCESS;
1312
1313 /* Called each time the guest wants to use acceleration,
1314 * or when the VGA device disables acceleration,
1315 * or when restoring the saved state with accel enabled.
1316 *
1317 * VGA device disables acceleration on each video mode change
1318 * and on reset.
1319 *
1320 * Guest enabled acceleration at will. And it has to enable
1321 * acceleration after a mode change.
1322 */
1323 LogFlowFunc (("mfVideoAccelEnabled = %d, fEnable = %d, pVbvaMemory = %p\n",
1324 mfVideoAccelEnabled, fEnable, pVbvaMemory));
1325
1326 /* Strictly check parameters. Callers must not pass anything in the case. */
1327 Assert((fEnable && pVbvaMemory) || (!fEnable && pVbvaMemory == NULL));
1328
1329 if (!VideoAccelAllowed ())
1330 return VERR_NOT_SUPPORTED;
1331
1332 /*
1333 * Verify that the VM is in running state. If it is not,
1334 * then this must be postponed until it goes to running.
1335 */
1336 if (!mfMachineRunning)
1337 {
1338 Assert (!mfVideoAccelEnabled);
1339
1340 LogFlowFunc (("Machine is not yet running.\n"));
1341
1342 if (fEnable)
1343 {
1344 mfPendingVideoAccelEnable = fEnable;
1345 mpPendingVbvaMemory = pVbvaMemory;
1346 }
1347
1348 return rc;
1349 }
1350
1351 /* Check that current status is not being changed */
1352 if (mfVideoAccelEnabled == fEnable)
1353 return rc;
1354
1355 if (mfVideoAccelEnabled)
1356 {
1357 /* Process any pending orders and empty the VBVA ring buffer. */
1358#ifdef VBOX_WITH_OLD_VBVA_LOCK
1359 videoAccelFlush ();
1360#else
1361 VideoAccelFlush ();
1362#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1363 }
1364
1365 if (!fEnable && mpVbvaMemory)
1366 mpVbvaMemory->fu32ModeFlags &= ~VBVA_F_MODE_ENABLED;
1367
1368 /* Safety precaution. There is no more VBVA until everything is setup! */
1369 mpVbvaMemory = NULL;
1370 mfVideoAccelEnabled = false;
1371
1372 /* Update entire display. */
1373 if (maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].u32ResizeStatus == ResizeStatus_Void)
1374 mpDrv->pUpPort->pfnUpdateDisplayAll(mpDrv->pUpPort);
1375
1376 /* Everything OK. VBVA status can be changed. */
1377
1378 /* Notify the VMMDev, which saves VBVA status in the saved state,
1379 * and needs to know current status.
1380 */
1381 VMMDev *pVMMDev = mParent->getVMMDev();
1382 if (pVMMDev)
1383 {
1384 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
1385 if (pVMMDevPort)
1386 pVMMDevPort->pfnVBVAChange(pVMMDevPort, fEnable);
1387 }
1388
1389 if (fEnable)
1390 {
1391 mpVbvaMemory = pVbvaMemory;
1392 mfVideoAccelEnabled = true;
1393
1394 /* Initialize the hardware memory. */
1395 vbvaSetMemoryFlags(mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
1396 mpVbvaMemory->off32Data = 0;
1397 mpVbvaMemory->off32Free = 0;
1398
1399 memset(mpVbvaMemory->aRecords, 0, sizeof (mpVbvaMemory->aRecords));
1400 mpVbvaMemory->indexRecordFirst = 0;
1401 mpVbvaMemory->indexRecordFree = 0;
1402
1403#ifdef VBOX_WITH_OLD_VBVA_LOCK
1404 mfu32PendingVideoAccelDisable = false;
1405#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1406
1407 LogRel(("VBVA: Enabled.\n"));
1408 }
1409 else
1410 {
1411 LogRel(("VBVA: Disabled.\n"));
1412 }
1413
1414 LogFlowFunc (("VideoAccelEnable: rc = %Rrc.\n", rc));
1415
1416 return rc;
1417}
1418
1419/* Called always by one VRDP server thread. Can be thread-unsafe.
1420 */
1421void Display::VideoAccelVRDP (bool fEnable)
1422{
1423 LogFlowFunc(("fEnable = %d\n", fEnable));
1424
1425#ifdef VBOX_WITH_OLD_VBVA_LOCK
1426 vbvaLock();
1427#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1428
1429 int c = fEnable?
1430 ASMAtomicIncS32 (&mcVideoAccelVRDPRefs):
1431 ASMAtomicDecS32 (&mcVideoAccelVRDPRefs);
1432
1433 Assert (c >= 0);
1434
1435 if (c == 0)
1436 {
1437 /* The last client has disconnected, and the accel can be
1438 * disabled.
1439 */
1440 Assert (fEnable == false);
1441
1442 mfVideoAccelVRDP = false;
1443 mfu32SupportedOrders = 0;
1444
1445 vbvaSetMemoryFlags (mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
1446#ifdef VBOX_WITH_HGSMI
1447 /* Here is VRDP-IN thread. Process the request in vbvaUpdateBegin under DevVGA lock on an EMT. */
1448 ASMAtomicIncU32(&mu32UpdateVBVAFlags);
1449#endif /* VBOX_WITH_HGSMI */
1450
1451 LogRel(("VBVA: VRDP acceleration has been disabled.\n"));
1452 }
1453 else if ( c == 1
1454 && !mfVideoAccelVRDP)
1455 {
1456 /* The first client has connected. Enable the accel.
1457 */
1458 Assert (fEnable == true);
1459
1460 mfVideoAccelVRDP = true;
1461 /* Supporting all orders. */
1462 mfu32SupportedOrders = ~0;
1463
1464 vbvaSetMemoryFlags (mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
1465#ifdef VBOX_WITH_HGSMI
1466 /* Here is VRDP-IN thread. Process the request in vbvaUpdateBegin under DevVGA lock on an EMT. */
1467 ASMAtomicIncU32(&mu32UpdateVBVAFlags);
1468#endif /* VBOX_WITH_HGSMI */
1469
1470 LogRel(("VBVA: VRDP acceleration has been requested.\n"));
1471 }
1472 else
1473 {
1474 /* A client is connected or disconnected but there is no change in the
1475 * accel state. It remains enabled.
1476 */
1477 Assert (mfVideoAccelVRDP == true);
1478 }
1479#ifdef VBOX_WITH_OLD_VBVA_LOCK
1480 vbvaUnlock();
1481#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1482}
1483
1484static bool vbvaVerifyRingBuffer (VBVAMEMORY *pVbvaMemory)
1485{
1486 return true;
1487}
1488
1489static void vbvaFetchBytes (VBVAMEMORY *pVbvaMemory, uint8_t *pu8Dst, uint32_t cbDst)
1490{
1491 if (cbDst >= VBVA_RING_BUFFER_SIZE)
1492 {
1493 AssertMsgFailed (("cbDst = 0x%08X, ring buffer size 0x%08X", cbDst, VBVA_RING_BUFFER_SIZE));
1494 return;
1495 }
1496
1497 uint32_t u32BytesTillBoundary = VBVA_RING_BUFFER_SIZE - pVbvaMemory->off32Data;
1498 uint8_t *src = &pVbvaMemory->au8RingBuffer[pVbvaMemory->off32Data];
1499 int32_t i32Diff = cbDst - u32BytesTillBoundary;
1500
1501 if (i32Diff <= 0)
1502 {
1503 /* Chunk will not cross buffer boundary. */
1504 memcpy (pu8Dst, src, cbDst);
1505 }
1506 else
1507 {
1508 /* Chunk crosses buffer boundary. */
1509 memcpy (pu8Dst, src, u32BytesTillBoundary);
1510 memcpy (pu8Dst + u32BytesTillBoundary, &pVbvaMemory->au8RingBuffer[0], i32Diff);
1511 }
1512
1513 /* Advance data offset. */
1514 pVbvaMemory->off32Data = (pVbvaMemory->off32Data + cbDst) % VBVA_RING_BUFFER_SIZE;
1515
1516 return;
1517}
1518
1519
1520static bool vbvaPartialRead (uint8_t **ppu8, uint32_t *pcb, uint32_t cbRecord, VBVAMEMORY *pVbvaMemory)
1521{
1522 uint8_t *pu8New;
1523
1524 LogFlow(("MAIN::DisplayImpl::vbvaPartialRead: p = %p, cb = %d, cbRecord 0x%08X\n",
1525 *ppu8, *pcb, cbRecord));
1526
1527 if (*ppu8)
1528 {
1529 Assert (*pcb);
1530 pu8New = (uint8_t *)RTMemRealloc (*ppu8, cbRecord);
1531 }
1532 else
1533 {
1534 Assert (!*pcb);
1535 pu8New = (uint8_t *)RTMemAlloc (cbRecord);
1536 }
1537
1538 if (!pu8New)
1539 {
1540 /* Memory allocation failed, fail the function. */
1541 Log(("MAIN::vbvaPartialRead: failed to (re)alocate memory for partial record!!! cbRecord 0x%08X\n",
1542 cbRecord));
1543
1544 if (*ppu8)
1545 {
1546 RTMemFree (*ppu8);
1547 }
1548
1549 *ppu8 = NULL;
1550 *pcb = 0;
1551
1552 return false;
1553 }
1554
1555 /* Fetch data from the ring buffer. */
1556 vbvaFetchBytes (pVbvaMemory, pu8New + *pcb, cbRecord - *pcb);
1557
1558 *ppu8 = pu8New;
1559 *pcb = cbRecord;
1560
1561 return true;
1562}
1563
1564/* For contiguous chunks just return the address in the buffer.
1565 * For crossing boundary - allocate a buffer from heap.
1566 */
1567bool Display::vbvaFetchCmd (VBVACMDHDR **ppHdr, uint32_t *pcbCmd)
1568{
1569 uint32_t indexRecordFirst = mpVbvaMemory->indexRecordFirst;
1570 uint32_t indexRecordFree = mpVbvaMemory->indexRecordFree;
1571
1572#ifdef DEBUG_sunlover
1573 LogFlowFunc (("first = %d, free = %d\n",
1574 indexRecordFirst, indexRecordFree));
1575#endif /* DEBUG_sunlover */
1576
1577 if (!vbvaVerifyRingBuffer (mpVbvaMemory))
1578 {
1579 return false;
1580 }
1581
1582 if (indexRecordFirst == indexRecordFree)
1583 {
1584 /* No records to process. Return without assigning output variables. */
1585 return true;
1586 }
1587
1588 VBVARECORD *pRecord = &mpVbvaMemory->aRecords[indexRecordFirst];
1589
1590#ifdef DEBUG_sunlover
1591 LogFlowFunc (("cbRecord = 0x%08X\n", pRecord->cbRecord));
1592#endif /* DEBUG_sunlover */
1593
1594 uint32_t cbRecord = pRecord->cbRecord & ~VBVA_F_RECORD_PARTIAL;
1595
1596 if (mcbVbvaPartial)
1597 {
1598 /* There is a partial read in process. Continue with it. */
1599
1600 Assert (mpu8VbvaPartial);
1601
1602 LogFlowFunc (("continue partial record mcbVbvaPartial = %d cbRecord 0x%08X, first = %d, free = %d\n",
1603 mcbVbvaPartial, pRecord->cbRecord, indexRecordFirst, indexRecordFree));
1604
1605 if (cbRecord > mcbVbvaPartial)
1606 {
1607 /* New data has been added to the record. */
1608 if (!vbvaPartialRead (&mpu8VbvaPartial, &mcbVbvaPartial, cbRecord, mpVbvaMemory))
1609 {
1610 return false;
1611 }
1612 }
1613
1614 if (!(pRecord->cbRecord & VBVA_F_RECORD_PARTIAL))
1615 {
1616 /* The record is completed by guest. Return it to the caller. */
1617 *ppHdr = (VBVACMDHDR *)mpu8VbvaPartial;
1618 *pcbCmd = mcbVbvaPartial;
1619
1620 mpu8VbvaPartial = NULL;
1621 mcbVbvaPartial = 0;
1622
1623 /* Advance the record index. */
1624 mpVbvaMemory->indexRecordFirst = (indexRecordFirst + 1) % VBVA_MAX_RECORDS;
1625
1626#ifdef DEBUG_sunlover
1627 LogFlowFunc (("partial done ok, data = %d, free = %d\n",
1628 mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1629#endif /* DEBUG_sunlover */
1630 }
1631
1632 return true;
1633 }
1634
1635 /* A new record need to be processed. */
1636 if (pRecord->cbRecord & VBVA_F_RECORD_PARTIAL)
1637 {
1638 /* Current record is being written by guest. '=' is important here. */
1639 if (cbRecord >= VBVA_RING_BUFFER_SIZE - VBVA_RING_BUFFER_THRESHOLD)
1640 {
1641 /* Partial read must be started. */
1642 if (!vbvaPartialRead (&mpu8VbvaPartial, &mcbVbvaPartial, cbRecord, mpVbvaMemory))
1643 {
1644 return false;
1645 }
1646
1647 LogFlowFunc (("started partial record mcbVbvaPartial = 0x%08X cbRecord 0x%08X, first = %d, free = %d\n",
1648 mcbVbvaPartial, pRecord->cbRecord, indexRecordFirst, indexRecordFree));
1649 }
1650
1651 return true;
1652 }
1653
1654 /* Current record is complete. If it is not empty, process it. */
1655 if (cbRecord)
1656 {
1657 /* The size of largest contiguous chunk in the ring biffer. */
1658 uint32_t u32BytesTillBoundary = VBVA_RING_BUFFER_SIZE - mpVbvaMemory->off32Data;
1659
1660 /* The ring buffer pointer. */
1661 uint8_t *au8RingBuffer = &mpVbvaMemory->au8RingBuffer[0];
1662
1663 /* The pointer to data in the ring buffer. */
1664 uint8_t *src = &au8RingBuffer[mpVbvaMemory->off32Data];
1665
1666 /* Fetch or point the data. */
1667 if (u32BytesTillBoundary >= cbRecord)
1668 {
1669 /* The command does not cross buffer boundary. Return address in the buffer. */
1670 *ppHdr = (VBVACMDHDR *)src;
1671
1672 /* Advance data offset. */
1673 mpVbvaMemory->off32Data = (mpVbvaMemory->off32Data + cbRecord) % VBVA_RING_BUFFER_SIZE;
1674 }
1675 else
1676 {
1677 /* The command crosses buffer boundary. Rare case, so not optimized. */
1678 uint8_t *dst = (uint8_t *)RTMemAlloc (cbRecord);
1679
1680 if (!dst)
1681 {
1682 LogFlowFunc (("could not allocate %d bytes from heap!!!\n", cbRecord));
1683 mpVbvaMemory->off32Data = (mpVbvaMemory->off32Data + cbRecord) % VBVA_RING_BUFFER_SIZE;
1684 return false;
1685 }
1686
1687 vbvaFetchBytes (mpVbvaMemory, dst, cbRecord);
1688
1689 *ppHdr = (VBVACMDHDR *)dst;
1690
1691#ifdef DEBUG_sunlover
1692 LogFlowFunc (("Allocated from heap %p\n", dst));
1693#endif /* DEBUG_sunlover */
1694 }
1695 }
1696
1697 *pcbCmd = cbRecord;
1698
1699 /* Advance the record index. */
1700 mpVbvaMemory->indexRecordFirst = (indexRecordFirst + 1) % VBVA_MAX_RECORDS;
1701
1702#ifdef DEBUG_sunlover
1703 LogFlowFunc (("done ok, data = %d, free = %d\n",
1704 mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1705#endif /* DEBUG_sunlover */
1706
1707 return true;
1708}
1709
1710void Display::vbvaReleaseCmd (VBVACMDHDR *pHdr, int32_t cbCmd)
1711{
1712 uint8_t *au8RingBuffer = mpVbvaMemory->au8RingBuffer;
1713
1714 if ( (uint8_t *)pHdr >= au8RingBuffer
1715 && (uint8_t *)pHdr < &au8RingBuffer[VBVA_RING_BUFFER_SIZE])
1716 {
1717 /* The pointer is inside ring buffer. Must be continuous chunk. */
1718 Assert (VBVA_RING_BUFFER_SIZE - ((uint8_t *)pHdr - au8RingBuffer) >= cbCmd);
1719
1720 /* Do nothing. */
1721
1722 Assert (!mpu8VbvaPartial && mcbVbvaPartial == 0);
1723 }
1724 else
1725 {
1726 /* The pointer is outside. It is then an allocated copy. */
1727
1728#ifdef DEBUG_sunlover
1729 LogFlowFunc (("Free heap %p\n", pHdr));
1730#endif /* DEBUG_sunlover */
1731
1732 if ((uint8_t *)pHdr == mpu8VbvaPartial)
1733 {
1734 mpu8VbvaPartial = NULL;
1735 mcbVbvaPartial = 0;
1736 }
1737 else
1738 {
1739 Assert (!mpu8VbvaPartial && mcbVbvaPartial == 0);
1740 }
1741
1742 RTMemFree (pHdr);
1743 }
1744
1745 return;
1746}
1747
1748
1749/**
1750 * Called regularly on the DisplayRefresh timer.
1751 * Also on behalf of guest, when the ring buffer is full.
1752 *
1753 * @thread EMT
1754 */
1755#ifdef VBOX_WITH_OLD_VBVA_LOCK
1756void Display::VideoAccelFlush (void)
1757{
1758 vbvaLock();
1759 videoAccelFlush();
1760 vbvaUnlock();
1761}
1762#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1763
1764#ifdef VBOX_WITH_OLD_VBVA_LOCK
1765/* Under VBVA lock. DevVGA is not taken. */
1766void Display::videoAccelFlush (void)
1767#else
1768void Display::VideoAccelFlush (void)
1769#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1770{
1771#ifdef DEBUG_sunlover_2
1772 LogFlowFunc (("mfVideoAccelEnabled = %d\n", mfVideoAccelEnabled));
1773#endif /* DEBUG_sunlover_2 */
1774
1775 if (!mfVideoAccelEnabled)
1776 {
1777 Log(("Display::VideoAccelFlush: called with disabled VBVA!!! Ignoring.\n"));
1778 return;
1779 }
1780
1781 /* Here VBVA is enabled and we have the accelerator memory pointer. */
1782 Assert(mpVbvaMemory);
1783
1784#ifdef DEBUG_sunlover_2
1785 LogFlowFunc (("indexRecordFirst = %d, indexRecordFree = %d, off32Data = %d, off32Free = %d\n",
1786 mpVbvaMemory->indexRecordFirst, mpVbvaMemory->indexRecordFree, mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1787#endif /* DEBUG_sunlover_2 */
1788
1789 /* Quick check for "nothing to update" case. */
1790 if (mpVbvaMemory->indexRecordFirst == mpVbvaMemory->indexRecordFree)
1791 {
1792 return;
1793 }
1794
1795 /* Process the ring buffer */
1796 unsigned uScreenId;
1797#ifndef VBOX_WITH_OLD_VBVA_LOCK
1798 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
1799 {
1800 if (!maFramebuffers[uScreenId].pFramebuffer.isNull())
1801 {
1802 maFramebuffers[uScreenId].pFramebuffer->Lock ();
1803 }
1804 }
1805#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1806
1807 /* Initialize dirty rectangles accumulator. */
1808 VBVADIRTYREGION rgn;
1809 vbvaRgnInit (&rgn, maFramebuffers, mcMonitors, this, mpDrv->pUpPort);
1810
1811 for (;;)
1812 {
1813 VBVACMDHDR *phdr = NULL;
1814 uint32_t cbCmd = ~0;
1815
1816 /* Fetch the command data. */
1817 if (!vbvaFetchCmd (&phdr, &cbCmd))
1818 {
1819 Log(("Display::VideoAccelFlush: unable to fetch command. off32Data = %d, off32Free = %d. Disabling VBVA!!!\n",
1820 mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1821
1822 /* Disable VBVA on those processing errors. */
1823#ifdef VBOX_WITH_OLD_VBVA_LOCK
1824 videoAccelEnable (false, NULL);
1825#else
1826 VideoAccelEnable (false, NULL);
1827#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1828
1829 break;
1830 }
1831
1832 if (cbCmd == uint32_t(~0))
1833 {
1834 /* No more commands yet in the queue. */
1835 break;
1836 }
1837
1838 if (cbCmd != 0)
1839 {
1840#ifdef DEBUG_sunlover
1841 LogFlowFunc (("hdr: cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
1842 cbCmd, phdr->x, phdr->y, phdr->w, phdr->h));
1843#endif /* DEBUG_sunlover */
1844
1845 VBVACMDHDR hdrSaved = *phdr;
1846
1847 int x = phdr->x;
1848 int y = phdr->y;
1849 int w = phdr->w;
1850 int h = phdr->h;
1851
1852 uScreenId = mapCoordsToScreen(maFramebuffers, mcMonitors, &x, &y, &w, &h);
1853
1854 phdr->x = (int16_t)x;
1855 phdr->y = (int16_t)y;
1856 phdr->w = (uint16_t)w;
1857 phdr->h = (uint16_t)h;
1858
1859 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1860
1861 if (pFBInfo->u32ResizeStatus == ResizeStatus_Void)
1862 {
1863 /* Handle the command.
1864 *
1865 * Guest is responsible for updating the guest video memory.
1866 * The Windows guest does all drawing using Eng*.
1867 *
1868 * For local output, only dirty rectangle information is used
1869 * to update changed areas.
1870 *
1871 * Dirty rectangles are accumulated to exclude overlapping updates and
1872 * group small updates to a larger one.
1873 */
1874
1875 /* Accumulate the update. */
1876 vbvaRgnDirtyRect (&rgn, uScreenId, phdr);
1877
1878 /* Forward the command to VRDP server. */
1879 mParent->consoleVRDPServer()->SendUpdate (uScreenId, phdr, cbCmd);
1880
1881 *phdr = hdrSaved;
1882 }
1883 }
1884
1885 vbvaReleaseCmd (phdr, cbCmd);
1886 }
1887
1888 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
1889 {
1890#ifndef VBOX_WITH_OLD_VBVA_LOCK
1891 if (!maFramebuffers[uScreenId].pFramebuffer.isNull())
1892 {
1893 maFramebuffers[uScreenId].pFramebuffer->Unlock ();
1894 }
1895#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
1896
1897 if (maFramebuffers[uScreenId].u32ResizeStatus == ResizeStatus_Void)
1898 {
1899 /* Draw the framebuffer. */
1900 vbvaRgnUpdateFramebuffer (&rgn, uScreenId);
1901 }
1902 }
1903}
1904
1905#ifdef VBOX_WITH_OLD_VBVA_LOCK
1906int Display::videoAccelRefreshProcess(void)
1907{
1908 int rc = VWRN_INVALID_STATE; /* Default is to do a display update in VGA device. */
1909
1910 vbvaLock();
1911
1912 if (ASMAtomicCmpXchgU32(&mfu32PendingVideoAccelDisable, false, true))
1913 {
1914 videoAccelEnable (false, NULL);
1915 }
1916 else if (mfPendingVideoAccelEnable)
1917 {
1918 /* Acceleration was enabled while machine was not yet running
1919 * due to restoring from saved state. Update entire display and
1920 * actually enable acceleration.
1921 */
1922 Assert(mpPendingVbvaMemory);
1923
1924 /* Acceleration can not be yet enabled.*/
1925 Assert(mpVbvaMemory == NULL);
1926 Assert(!mfVideoAccelEnabled);
1927
1928 if (mfMachineRunning)
1929 {
1930 videoAccelEnable (mfPendingVideoAccelEnable,
1931 mpPendingVbvaMemory);
1932
1933 /* Reset the pending state. */
1934 mfPendingVideoAccelEnable = false;
1935 mpPendingVbvaMemory = NULL;
1936 }
1937
1938 rc = VINF_TRY_AGAIN;
1939 }
1940 else
1941 {
1942 Assert(mpPendingVbvaMemory == NULL);
1943
1944 if (mfVideoAccelEnabled)
1945 {
1946 Assert(mpVbvaMemory);
1947 videoAccelFlush ();
1948
1949 rc = VINF_SUCCESS; /* VBVA processed, no need to a display update. */
1950 }
1951 }
1952
1953 vbvaUnlock();
1954
1955 return rc;
1956}
1957#endif /* VBOX_WITH_OLD_VBVA_LOCK */
1958
1959
1960// IDisplay methods
1961/////////////////////////////////////////////////////////////////////////////
1962STDMETHODIMP Display::GetScreenResolution (ULONG aScreenId,
1963 ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel)
1964{
1965 LogFlowFunc (("aScreenId = %d\n", aScreenId));
1966
1967 AutoCaller autoCaller(this);
1968 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1969
1970 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1971
1972 uint32_t u32Width = 0;
1973 uint32_t u32Height = 0;
1974 uint32_t u32BitsPerPixel = 0;
1975
1976 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
1977 {
1978 CHECK_CONSOLE_DRV (mpDrv);
1979
1980 u32Width = mpDrv->IConnector.cx;
1981 u32Height = mpDrv->IConnector.cy;
1982 int rc = mpDrv->pUpPort->pfnQueryColorDepth(mpDrv->pUpPort, &u32BitsPerPixel);
1983 AssertRC(rc);
1984 }
1985 else if (aScreenId < mcMonitors)
1986 {
1987 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
1988 u32Width = pFBInfo->w;
1989 u32Height = pFBInfo->h;
1990 u32BitsPerPixel = pFBInfo->u16BitsPerPixel;
1991 }
1992 else
1993 {
1994 return E_INVALIDARG;
1995 }
1996
1997 if (aWidth)
1998 *aWidth = u32Width;
1999 if (aHeight)
2000 *aHeight = u32Height;
2001 if (aBitsPerPixel)
2002 *aBitsPerPixel = u32BitsPerPixel;
2003
2004 return S_OK;
2005}
2006
2007STDMETHODIMP Display::SetFramebuffer (ULONG aScreenId,
2008 IFramebuffer *aFramebuffer)
2009{
2010 LogFlowFunc (("\n"));
2011
2012 if (aFramebuffer != NULL)
2013 CheckComArgOutPointerValid(aFramebuffer);
2014
2015 AutoCaller autoCaller(this);
2016 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2017
2018 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2019
2020 Console::SafeVMPtrQuiet pVM (mParent);
2021 if (pVM.isOk())
2022 {
2023 /* Must leave the lock here because the changeFramebuffer will
2024 * also obtain it. */
2025 alock.leave ();
2026
2027 /* send request to the EMT thread */
2028 int vrc = VMR3ReqCallWait (pVM, VMCPUID_ANY,
2029 (PFNRT) changeFramebuffer, 3, this, aFramebuffer, aScreenId);
2030
2031 alock.enter ();
2032
2033 ComAssertRCRet (vrc, E_FAIL);
2034
2035#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
2036 {
2037 BOOL is3denabled;
2038 mParent->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
2039
2040 if (is3denabled)
2041 {
2042 VBOXHGCMSVCPARM parm;
2043
2044 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2045 parm.u.uint32 = aScreenId;
2046
2047 VMMDev *pVMMDev = mParent->getVMMDev();
2048
2049 alock.leave ();
2050
2051 if (pVMMDev)
2052 vrc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SCREEN_CHANGED, SHCRGL_CPARMS_SCREEN_CHANGED, &parm);
2053 /*ComAssertRCRet (vrc, E_FAIL);*/
2054
2055 alock.enter ();
2056 }
2057 }
2058#endif /* VBOX_WITH_CROGL */
2059 }
2060 else
2061 {
2062 /* No VM is created (VM is powered off), do a direct call */
2063 int vrc = changeFramebuffer (this, aFramebuffer, aScreenId);
2064 ComAssertRCRet (vrc, E_FAIL);
2065 }
2066
2067 return S_OK;
2068}
2069
2070STDMETHODIMP Display::GetFramebuffer (ULONG aScreenId,
2071 IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin)
2072{
2073 LogFlowFunc (("aScreenId = %d\n", aScreenId));
2074
2075 CheckComArgOutPointerValid(aFramebuffer);
2076
2077 AutoCaller autoCaller(this);
2078 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2079
2080 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2081
2082 if (aScreenId != 0 && aScreenId >= mcMonitors)
2083 return E_INVALIDARG;
2084
2085 /* @todo this should be actually done on EMT. */
2086 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
2087
2088 *aFramebuffer = pFBInfo->pFramebuffer;
2089 if (*aFramebuffer)
2090 (*aFramebuffer)->AddRef ();
2091 if (aXOrigin)
2092 *aXOrigin = pFBInfo->xOrigin;
2093 if (aYOrigin)
2094 *aYOrigin = pFBInfo->yOrigin;
2095
2096 return S_OK;
2097}
2098
2099STDMETHODIMP Display::SetVideoModeHint(ULONG aWidth, ULONG aHeight,
2100 ULONG aBitsPerPixel, ULONG aDisplay)
2101{
2102 AutoCaller autoCaller(this);
2103 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2104
2105 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2106
2107 CHECK_CONSOLE_DRV (mpDrv);
2108
2109 /*
2110 * Do some rough checks for valid input
2111 */
2112 ULONG width = aWidth;
2113 if (!width)
2114 width = mpDrv->IConnector.cx;
2115 ULONG height = aHeight;
2116 if (!height)
2117 height = mpDrv->IConnector.cy;
2118 ULONG bpp = aBitsPerPixel;
2119 if (!bpp)
2120 {
2121 uint32_t cBits = 0;
2122 int rc = mpDrv->pUpPort->pfnQueryColorDepth(mpDrv->pUpPort, &cBits);
2123 AssertRC(rc);
2124 bpp = cBits;
2125 }
2126 ULONG cMonitors;
2127 mParent->machine()->COMGETTER(MonitorCount)(&cMonitors);
2128 if (cMonitors == 0 && aDisplay > 0)
2129 return E_INVALIDARG;
2130 if (aDisplay >= cMonitors)
2131 return E_INVALIDARG;
2132
2133// sunlover 20070614: It is up to the guest to decide whether the hint is valid.
2134// ULONG vramSize;
2135// mParent->machine()->COMGETTER(VRAMSize)(&vramSize);
2136// /* enough VRAM? */
2137// if ((width * height * (bpp / 8)) > (vramSize * 1024 * 1024))
2138// return setError(E_FAIL, tr("Not enough VRAM for the selected video mode"));
2139
2140 /* Have to leave the lock because the pfnRequestDisplayChange
2141 * will call EMT. */
2142 alock.leave ();
2143
2144 VMMDev *pVMMDev = mParent->getVMMDev();
2145 if (pVMMDev)
2146 {
2147 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
2148 if (pVMMDevPort)
2149 pVMMDevPort->pfnRequestDisplayChange(pVMMDevPort, aWidth, aHeight, aBitsPerPixel, aDisplay);
2150 }
2151 return S_OK;
2152}
2153
2154STDMETHODIMP Display::SetSeamlessMode (BOOL enabled)
2155{
2156 AutoCaller autoCaller(this);
2157 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2158
2159 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2160
2161 /* Have to leave the lock because the pfnRequestSeamlessChange will call EMT. */
2162 alock.leave ();
2163
2164 VMMDev *pVMMDev = mParent->getVMMDev();
2165 if (pVMMDev)
2166 {
2167 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
2168 if (pVMMDevPort)
2169 pVMMDevPort->pfnRequestSeamlessChange(pVMMDevPort, !!enabled);
2170 }
2171 return S_OK;
2172}
2173
2174#ifdef VBOX_WITH_OLD_VBVA_LOCK
2175int Display::displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppu8Data, size_t *pcbData, uint32_t *pu32Width, uint32_t *pu32Height)
2176{
2177 int rc;
2178 pDisplay->vbvaLock();
2179 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2180 {
2181 rc = pDisplay->mpDrv->pUpPort->pfnTakeScreenshot(pDisplay->mpDrv->pUpPort, ppu8Data, pcbData, pu32Width, pu32Height);
2182 }
2183 else if (aScreenId < pDisplay->mcMonitors)
2184 {
2185 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[aScreenId];
2186
2187 uint32_t width = pFBInfo->w;
2188 uint32_t height = pFBInfo->h;
2189
2190 /* Allocate 32 bit per pixel bitmap. */
2191 size_t cbRequired = width * 4 * height;
2192
2193 if (cbRequired)
2194 {
2195 uint8_t *pu8Data = (uint8_t *)RTMemAlloc(cbRequired);
2196
2197 if (pu8Data == NULL)
2198 {
2199 rc = VERR_NO_MEMORY;
2200 }
2201 else
2202 {
2203 /* Copy guest VRAM to the allocated 32bpp buffer. */
2204 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
2205 int32_t xSrc = 0;
2206 int32_t ySrc = 0;
2207 uint32_t u32SrcWidth = width;
2208 uint32_t u32SrcHeight = height;
2209 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
2210 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2211
2212 uint8_t *pu8Dst = pu8Data;
2213 int32_t xDst = 0;
2214 int32_t yDst = 0;
2215 uint32_t u32DstWidth = u32SrcWidth;
2216 uint32_t u32DstHeight = u32SrcHeight;
2217 uint32_t u32DstLineSize = u32DstWidth * 4;
2218 uint32_t u32DstBitsPerPixel = 32;
2219
2220 rc = pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2221 width, height,
2222 pu8Src,
2223 xSrc, ySrc,
2224 u32SrcWidth, u32SrcHeight,
2225 u32SrcLineSize, u32SrcBitsPerPixel,
2226 pu8Dst,
2227 xDst, yDst,
2228 u32DstWidth, u32DstHeight,
2229 u32DstLineSize, u32DstBitsPerPixel);
2230 if (RT_SUCCESS(rc))
2231 {
2232 *ppu8Data = pu8Data;
2233 *pcbData = cbRequired;
2234 *pu32Width = width;
2235 *pu32Height = height;
2236 }
2237 }
2238 }
2239 else
2240 {
2241 /* No image. */
2242 *ppu8Data = NULL;
2243 *pcbData = 0;
2244 *pu32Width = 0;
2245 *pu32Height = 0;
2246 rc = VINF_SUCCESS;
2247 }
2248 }
2249 else
2250 {
2251 rc = VERR_INVALID_PARAMETER;
2252 }
2253 pDisplay->vbvaUnlock();
2254 return rc;
2255}
2256#endif /* VBOX_WITH_OLD_VBVA_LOCK */
2257
2258#ifdef VBOX_WITH_OLD_VBVA_LOCK
2259static int displayTakeScreenshot(PVM pVM, Display *pDisplay, struct DRVMAINDISPLAY *pDrv, ULONG aScreenId, BYTE *address, ULONG width, ULONG height)
2260#else
2261static int displayTakeScreenshot(PVM pVM, struct DRVMAINDISPLAY *pDrv, BYTE *address, ULONG width, ULONG height)
2262#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2263{
2264 uint8_t *pu8Data = NULL;
2265 size_t cbData = 0;
2266 uint32_t cx = 0;
2267 uint32_t cy = 0;
2268 int vrc = VINF_SUCCESS;
2269
2270#ifdef VBOX_WITH_OLD_VBVA_LOCK
2271 int cRetries = 5;
2272
2273 while (cRetries-- > 0)
2274 {
2275 vrc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)Display::displayTakeScreenshotEMT, 6,
2276 pDisplay, aScreenId, &pu8Data, &cbData, &cx, &cy);
2277 if (vrc != VERR_TRY_AGAIN)
2278 {
2279 break;
2280 }
2281
2282 RTThreadSleep(10);
2283 }
2284#else
2285 /* @todo pfnTakeScreenshot is probably callable from any thread, because it uses the VGA device lock. */
2286 vrc = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)pDrv->pUpPort->pfnTakeScreenshot, 5,
2287 pDrv->pUpPort, &pu8Data, &cbData, &cx, &cy);
2288#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2289
2290 if (RT_SUCCESS(vrc) && pu8Data)
2291 {
2292 if (cx == width && cy == height)
2293 {
2294 /* No scaling required. */
2295 memcpy(address, pu8Data, cbData);
2296 }
2297 else
2298 {
2299 /* Scale. */
2300 LogFlowFunc(("SCALE: %dx%d -> %dx%d\n", cx, cy, width, height));
2301
2302 uint8_t *dst = address;
2303 uint8_t *src = pu8Data;
2304 int dstW = width;
2305 int dstH = height;
2306 int srcW = cx;
2307 int srcH = cy;
2308 int iDeltaLine = cx * 4;
2309
2310 BitmapScale32 (dst,
2311 dstW, dstH,
2312 src,
2313 iDeltaLine,
2314 srcW, srcH);
2315 }
2316
2317 /* This can be called from any thread. */
2318 pDrv->pUpPort->pfnFreeScreenshot (pDrv->pUpPort, pu8Data);
2319 }
2320
2321 return vrc;
2322}
2323
2324STDMETHODIMP Display::TakeScreenShot (ULONG aScreenId, BYTE *address, ULONG width, ULONG height)
2325{
2326 /// @todo (r=dmik) this function may take too long to complete if the VM
2327 // is doing something like saving state right now. Which, in case if it
2328 // is called on the GUI thread, will make it unresponsive. We should
2329 // check the machine state here (by enclosing the check and VMRequCall
2330 // within the Console lock to make it atomic).
2331
2332 LogFlowFuncEnter();
2333 LogFlowFunc (("address=%p, width=%d, height=%d\n",
2334 address, width, height));
2335
2336 CheckComArgNotNull(address);
2337 CheckComArgExpr(width, width != 0);
2338 CheckComArgExpr(height, height != 0);
2339
2340 AutoCaller autoCaller(this);
2341 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2342
2343 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2344
2345 CHECK_CONSOLE_DRV (mpDrv);
2346
2347 Console::SafeVMPtr pVM(mParent);
2348 if (FAILED(pVM.rc())) return pVM.rc();
2349
2350 HRESULT rc = S_OK;
2351
2352 LogFlowFunc (("Sending SCREENSHOT request\n"));
2353
2354 /* Leave lock because other thread (EMT) is called and it may initiate a resize
2355 * which also needs lock.
2356 *
2357 * This method does not need the lock anymore.
2358 */
2359 alock.leave();
2360
2361#ifdef VBOX_WITH_OLD_VBVA_LOCK
2362 int vrc = displayTakeScreenshot(pVM, this, mpDrv, aScreenId, address, width, height);
2363#else
2364 int vrc = displayTakeScreenshot(pVM, mpDrv, address, width, height);
2365#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2366
2367 if (vrc == VERR_NOT_IMPLEMENTED)
2368 rc = setError(E_NOTIMPL,
2369 tr("This feature is not implemented"));
2370 else if (vrc == VERR_TRY_AGAIN)
2371 rc = setError(E_UNEXPECTED,
2372 tr("This feature is not available at this time"));
2373 else if (RT_FAILURE(vrc))
2374 rc = setError(VBOX_E_IPRT_ERROR,
2375 tr("Could not take a screenshot (%Rrc)"), vrc);
2376
2377 LogFlowFunc (("rc=%08X\n", rc));
2378 LogFlowFuncLeave();
2379 return rc;
2380}
2381
2382STDMETHODIMP Display::TakeScreenShotToArray (ULONG aScreenId, ULONG width, ULONG height,
2383 ComSafeArrayOut(BYTE, aScreenData))
2384{
2385 LogFlowFuncEnter();
2386 LogFlowFunc (("width=%d, height=%d\n",
2387 width, height));
2388
2389 CheckComArgOutSafeArrayPointerValid(aScreenData);
2390 CheckComArgExpr(width, width != 0);
2391 CheckComArgExpr(height, height != 0);
2392
2393 AutoCaller autoCaller(this);
2394 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2395
2396 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2397
2398 CHECK_CONSOLE_DRV (mpDrv);
2399
2400 Console::SafeVMPtr pVM(mParent);
2401 if (FAILED(pVM.rc())) return pVM.rc();
2402
2403 HRESULT rc = S_OK;
2404
2405 LogFlowFunc (("Sending SCREENSHOT request\n"));
2406
2407 /* Leave lock because other thread (EMT) is called and it may initiate a resize
2408 * which also needs lock.
2409 *
2410 * This method does not need the lock anymore.
2411 */
2412 alock.leave();
2413
2414 size_t cbData = width * 4 * height;
2415 uint8_t *pu8Data = (uint8_t *)RTMemAlloc(cbData);
2416
2417 if (!pu8Data)
2418 return E_OUTOFMEMORY;
2419
2420#ifdef VBOX_WITH_OLD_VBVA_LOCK
2421 int vrc = displayTakeScreenshot(pVM, this, mpDrv, aScreenId, pu8Data, width, height);
2422#else
2423 int vrc = displayTakeScreenshot(pVM, mpDrv, pu8Data, width, height);
2424#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2425
2426 if (RT_SUCCESS(vrc))
2427 {
2428 /* Convert pixels to format expected by the API caller: [0] R, [1] G, [2] B, [3] A. */
2429 uint8_t *pu8 = pu8Data;
2430 unsigned cPixels = width * height;
2431 while (cPixels)
2432 {
2433 uint8_t u8 = pu8[0];
2434 pu8[0] = pu8[2];
2435 pu8[2] = u8;
2436 pu8[3] = 0xff;
2437 cPixels--;
2438 pu8 += 4;
2439 }
2440
2441 com::SafeArray<BYTE> screenData (cbData);
2442 screenData.initFrom(pu8Data, cbData);
2443 screenData.detachTo(ComSafeArrayOutArg(aScreenData));
2444 }
2445 else if (vrc == VERR_NOT_IMPLEMENTED)
2446 rc = setError(E_NOTIMPL,
2447 tr("This feature is not implemented"));
2448 else
2449 rc = setError(VBOX_E_IPRT_ERROR,
2450 tr("Could not take a screenshot (%Rrc)"), vrc);
2451
2452 RTMemFree(pu8Data);
2453
2454 LogFlowFunc (("rc=%08X\n", rc));
2455 LogFlowFuncLeave();
2456 return rc;
2457}
2458
2459STDMETHODIMP Display::TakeScreenShotPNGToArray (ULONG aScreenId, ULONG width, ULONG height,
2460 ComSafeArrayOut(BYTE, aScreenData))
2461{
2462 LogFlowFuncEnter();
2463 LogFlowFunc (("width=%d, height=%d\n",
2464 width, height));
2465
2466 CheckComArgOutSafeArrayPointerValid(aScreenData);
2467 CheckComArgExpr(width, width != 0);
2468 CheckComArgExpr(height, height != 0);
2469
2470 AutoCaller autoCaller(this);
2471 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2472
2473 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2474
2475 CHECK_CONSOLE_DRV (mpDrv);
2476
2477 Console::SafeVMPtr pVM(mParent);
2478 if (FAILED(pVM.rc())) return pVM.rc();
2479
2480 HRESULT rc = S_OK;
2481
2482 LogFlowFunc (("Sending SCREENSHOT request\n"));
2483
2484 /* Leave lock because other thread (EMT) is called and it may initiate a resize
2485 * which also needs lock.
2486 *
2487 * This method does not need the lock anymore.
2488 */
2489 alock.leave();
2490
2491 size_t cbData = width * 4 * height;
2492 uint8_t *pu8Data = (uint8_t *)RTMemAlloc(cbData);
2493
2494 if (!pu8Data)
2495 return E_OUTOFMEMORY;
2496
2497#ifdef VBOX_WITH_OLD_VBVA_LOCK
2498 int vrc = displayTakeScreenshot(pVM, this, mpDrv, aScreenId, pu8Data, width, height);
2499#else
2500 int vrc = displayTakeScreenshot(pVM, mpDrv, pu8Data, width, height);
2501#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2502
2503 if (RT_SUCCESS(vrc))
2504 {
2505 uint8_t *pu8PNG = NULL;
2506 uint32_t cbPNG = 0;
2507 uint32_t cxPNG = 0;
2508 uint32_t cyPNG = 0;
2509
2510 DisplayMakePNG(pu8Data, width, height, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 0);
2511
2512 com::SafeArray<BYTE> screenData (cbPNG);
2513 screenData.initFrom(pu8PNG, cbPNG);
2514 RTMemFree(pu8PNG);
2515
2516 screenData.detachTo(ComSafeArrayOutArg(aScreenData));
2517 }
2518 else if (vrc == VERR_NOT_IMPLEMENTED)
2519 rc = setError(E_NOTIMPL,
2520 tr("This feature is not implemented"));
2521 else
2522 rc = setError(VBOX_E_IPRT_ERROR,
2523 tr("Could not take a screenshot (%Rrc)"), vrc);
2524
2525 RTMemFree(pu8Data);
2526
2527 LogFlowFunc (("rc=%08X\n", rc));
2528 LogFlowFuncLeave();
2529 return rc;
2530}
2531
2532
2533#ifdef VBOX_WITH_OLD_VBVA_LOCK
2534int Display::drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height)
2535{
2536 int rc;
2537 pDisplay->vbvaLock();
2538 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2539 {
2540 rc = pDisplay->mpDrv->pUpPort->pfnDisplayBlt(pDisplay->mpDrv->pUpPort, address, x, y, width, height);
2541 }
2542 else if (aScreenId < pDisplay->mcMonitors)
2543 {
2544 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[aScreenId];
2545
2546 /* Copy the bitmap to the guest VRAM. */
2547 const uint8_t *pu8Src = address;
2548 int32_t xSrc = 0;
2549 int32_t ySrc = 0;
2550 uint32_t u32SrcWidth = width;
2551 uint32_t u32SrcHeight = height;
2552 uint32_t u32SrcLineSize = width * 4;
2553 uint32_t u32SrcBitsPerPixel = 32;
2554
2555 uint8_t *pu8Dst = pFBInfo->pu8FramebufferVRAM;
2556 int32_t xDst = x;
2557 int32_t yDst = y;
2558 uint32_t u32DstWidth = pFBInfo->w;
2559 uint32_t u32DstHeight = pFBInfo->h;
2560 uint32_t u32DstLineSize = pFBInfo->u32LineSize;
2561 uint32_t u32DstBitsPerPixel = pFBInfo->u16BitsPerPixel;
2562
2563 rc = pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2564 width, height,
2565 pu8Src,
2566 xSrc, ySrc,
2567 u32SrcWidth, u32SrcHeight,
2568 u32SrcLineSize, u32SrcBitsPerPixel,
2569 pu8Dst,
2570 xDst, yDst,
2571 u32DstWidth, u32DstHeight,
2572 u32DstLineSize, u32DstBitsPerPixel);
2573 if (RT_SUCCESS(rc))
2574 {
2575 if (!pFBInfo->pFramebuffer.isNull())
2576 {
2577 /* Update the changed screen area. When framebuffer uses VRAM directly, just notify
2578 * it to update. And for default format, render the guest VRAM to framebuffer.
2579 */
2580 if (pFBInfo->fDefaultFormat)
2581 {
2582 address = NULL;
2583 HRESULT hrc = pFBInfo->pFramebuffer->COMGETTER(Address) (&address);
2584 if (SUCCEEDED(hrc) && address != NULL)
2585 {
2586 pu8Src = pFBInfo->pu8FramebufferVRAM;
2587 xSrc = x;
2588 ySrc = y;
2589 u32SrcWidth = pFBInfo->w;
2590 u32SrcHeight = pFBInfo->h;
2591 u32SrcLineSize = pFBInfo->u32LineSize;
2592 u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2593
2594 /* Default format is 32 bpp. */
2595 pu8Dst = address;
2596 xDst = xSrc;
2597 yDst = ySrc;
2598 u32DstWidth = u32SrcWidth;
2599 u32DstHeight = u32SrcHeight;
2600 u32DstLineSize = u32DstWidth * 4;
2601 u32DstBitsPerPixel = 32;
2602
2603 pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2604 width, height,
2605 pu8Src,
2606 xSrc, ySrc,
2607 u32SrcWidth, u32SrcHeight,
2608 u32SrcLineSize, u32SrcBitsPerPixel,
2609 pu8Dst,
2610 xDst, yDst,
2611 u32DstWidth, u32DstHeight,
2612 u32DstLineSize, u32DstBitsPerPixel);
2613 }
2614 }
2615
2616 pDisplay->handleDisplayUpdate(aScreenId, x, y, width, height);
2617 }
2618 }
2619 }
2620 else
2621 {
2622 rc = VERR_INVALID_PARAMETER;
2623 }
2624 pDisplay->vbvaUnlock();
2625 return rc;
2626}
2627#endif /* VBOX_WITH_OLD_VBVA_LOCK */
2628
2629STDMETHODIMP Display::DrawToScreen (ULONG aScreenId, BYTE *address, ULONG x, ULONG y,
2630 ULONG width, ULONG height)
2631{
2632 /// @todo (r=dmik) this function may take too long to complete if the VM
2633 // is doing something like saving state right now. Which, in case if it
2634 // is called on the GUI thread, will make it unresponsive. We should
2635 // check the machine state here (by enclosing the check and VMRequCall
2636 // within the Console lock to make it atomic).
2637
2638 LogFlowFuncEnter();
2639 LogFlowFunc (("address=%p, x=%d, y=%d, width=%d, height=%d\n",
2640 (void *)address, x, y, width, height));
2641
2642 CheckComArgNotNull(address);
2643 CheckComArgExpr(width, width != 0);
2644 CheckComArgExpr(height, height != 0);
2645
2646 AutoCaller autoCaller(this);
2647 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2648
2649 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2650
2651 CHECK_CONSOLE_DRV (mpDrv);
2652
2653 Console::SafeVMPtr pVM(mParent);
2654 if (FAILED(pVM.rc())) return pVM.rc();
2655
2656 /*
2657 * Again we're lazy and make the graphics device do all the
2658 * dirty conversion work.
2659 */
2660#ifdef VBOX_WITH_OLD_VBVA_LOCK
2661 int rcVBox = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)Display::drawToScreenEMT, 7,
2662 this, aScreenId, address, x, y, width, height);
2663#else
2664 int rcVBox = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)mpDrv->pUpPort->pfnDisplayBlt, 6,
2665 mpDrv->pUpPort, address, x, y, width, height);
2666#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2667
2668 /*
2669 * If the function returns not supported, we'll have to do all the
2670 * work ourselves using the framebuffer.
2671 */
2672 HRESULT rc = S_OK;
2673 if (rcVBox == VERR_NOT_SUPPORTED || rcVBox == VERR_NOT_IMPLEMENTED)
2674 {
2675 /** @todo implement generic fallback for screen blitting. */
2676 rc = E_NOTIMPL;
2677 }
2678 else if (RT_FAILURE(rcVBox))
2679 rc = setError(VBOX_E_IPRT_ERROR,
2680 tr("Could not draw to the screen (%Rrc)"), rcVBox);
2681//@todo
2682// else
2683// {
2684// /* All ok. Redraw the screen. */
2685// handleDisplayUpdate (x, y, width, height);
2686// }
2687
2688 LogFlowFunc (("rc=%08X\n", rc));
2689 LogFlowFuncLeave();
2690 return rc;
2691}
2692
2693#ifdef VBOX_WITH_OLD_VBVA_LOCK
2694void Display::InvalidateAndUpdateEMT(Display *pDisplay)
2695{
2696 pDisplay->vbvaLock();
2697 unsigned uScreenId;
2698 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
2699 {
2700 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
2701
2702 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN && !pFBInfo->pFramebuffer.isNull())
2703 {
2704 pDisplay->mpDrv->pUpPort->pfnUpdateDisplayAll(pDisplay->mpDrv->pUpPort);
2705 }
2706 else
2707 {
2708 if (!pFBInfo->pFramebuffer.isNull())
2709 {
2710 /* Render complete VRAM screen to the framebuffer.
2711 * When framebuffer uses VRAM directly, just notify it to update.
2712 */
2713 if (pFBInfo->fDefaultFormat)
2714 {
2715 BYTE *address = NULL;
2716 HRESULT hrc = pFBInfo->pFramebuffer->COMGETTER(Address) (&address);
2717 if (SUCCEEDED(hrc) && address != NULL)
2718 {
2719 uint32_t width = pFBInfo->w;
2720 uint32_t height = pFBInfo->h;
2721
2722 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
2723 int32_t xSrc = 0;
2724 int32_t ySrc = 0;
2725 uint32_t u32SrcWidth = pFBInfo->w;
2726 uint32_t u32SrcHeight = pFBInfo->h;
2727 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
2728 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2729
2730 /* Default format is 32 bpp. */
2731 uint8_t *pu8Dst = address;
2732 int32_t xDst = xSrc;
2733 int32_t yDst = ySrc;
2734 uint32_t u32DstWidth = u32SrcWidth;
2735 uint32_t u32DstHeight = u32SrcHeight;
2736 uint32_t u32DstLineSize = u32DstWidth * 4;
2737 uint32_t u32DstBitsPerPixel = 32;
2738
2739 pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2740 width, height,
2741 pu8Src,
2742 xSrc, ySrc,
2743 u32SrcWidth, u32SrcHeight,
2744 u32SrcLineSize, u32SrcBitsPerPixel,
2745 pu8Dst,
2746 xDst, yDst,
2747 u32DstWidth, u32DstHeight,
2748 u32DstLineSize, u32DstBitsPerPixel);
2749 }
2750 }
2751
2752 pDisplay->handleDisplayUpdate (uScreenId, 0, 0, pFBInfo->w, pFBInfo->h);
2753 }
2754 }
2755 }
2756 pDisplay->vbvaUnlock();
2757}
2758#endif /* VBOX_WITH_OLD_VBVA_LOCK */
2759
2760/**
2761 * Does a full invalidation of the VM display and instructs the VM
2762 * to update it immediately.
2763 *
2764 * @returns COM status code
2765 */
2766STDMETHODIMP Display::InvalidateAndUpdate()
2767{
2768 LogFlowFuncEnter();
2769
2770 AutoCaller autoCaller(this);
2771 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2772
2773 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2774
2775 CHECK_CONSOLE_DRV (mpDrv);
2776
2777 Console::SafeVMPtr pVM(mParent);
2778 if (FAILED(pVM.rc())) return pVM.rc();
2779
2780 HRESULT rc = S_OK;
2781
2782 LogFlowFunc (("Sending DPYUPDATE request\n"));
2783
2784 /* Have to leave the lock when calling EMT. */
2785 alock.leave ();
2786
2787 /* pdm.h says that this has to be called from the EMT thread */
2788#ifdef VBOX_WITH_OLD_VBVA_LOCK
2789 int rcVBox = VMR3ReqCallVoidWait(pVM, VMCPUID_ANY, (PFNRT)Display::InvalidateAndUpdateEMT,
2790 1, this);
2791#else
2792 int rcVBox = VMR3ReqCallVoidWait(pVM, VMCPUID_ANY,
2793 (PFNRT)mpDrv->pUpPort->pfnUpdateDisplayAll, 1, mpDrv->pUpPort);
2794#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
2795 alock.enter ();
2796
2797 if (RT_FAILURE(rcVBox))
2798 rc = setError(VBOX_E_IPRT_ERROR,
2799 tr("Could not invalidate and update the screen (%Rrc)"), rcVBox);
2800
2801 LogFlowFunc (("rc=%08X\n", rc));
2802 LogFlowFuncLeave();
2803 return rc;
2804}
2805
2806/**
2807 * Notification that the framebuffer has completed the
2808 * asynchronous resize processing
2809 *
2810 * @returns COM status code
2811 */
2812STDMETHODIMP Display::ResizeCompleted(ULONG aScreenId)
2813{
2814 LogFlowFunc (("\n"));
2815
2816 /// @todo (dmik) can we AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); here?
2817 // This will require general code review and may add some details.
2818 // In particular, we may want to check whether EMT is really waiting for
2819 // this notification, etc. It might be also good to obey the caller to make
2820 // sure this method is not called from more than one thread at a time
2821 // (and therefore don't use Display lock at all here to save some
2822 // milliseconds).
2823 AutoCaller autoCaller(this);
2824 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2825
2826 /* this is only valid for external framebuffers */
2827 if (maFramebuffers[aScreenId].pFramebuffer == NULL)
2828 return setError(VBOX_E_NOT_SUPPORTED,
2829 tr("Resize completed notification is valid only for external framebuffers"));
2830
2831 /* Set the flag indicating that the resize has completed and display
2832 * data need to be updated. */
2833 bool f = ASMAtomicCmpXchgU32 (&maFramebuffers[aScreenId].u32ResizeStatus,
2834 ResizeStatus_UpdateDisplayData, ResizeStatus_InProgress);
2835 AssertRelease(f);NOREF(f);
2836
2837 return S_OK;
2838}
2839
2840STDMETHODIMP Display::CompleteVHWACommand(BYTE *pCommand)
2841{
2842#ifdef VBOX_WITH_VIDEOHWACCEL
2843 mpDrv->pVBVACallbacks->pfnVHWACommandCompleteAsynch(mpDrv->pVBVACallbacks, (PVBOXVHWACMD)pCommand);
2844 return S_OK;
2845#else
2846 return E_NOTIMPL;
2847#endif
2848}
2849
2850// private methods
2851/////////////////////////////////////////////////////////////////////////////
2852
2853/**
2854 * Helper to update the display information from the framebuffer.
2855 *
2856 * @thread EMT
2857 */
2858void Display::updateDisplayData(void)
2859{
2860 LogFlowFunc (("\n"));
2861
2862 /* the driver might not have been constructed yet */
2863 if (!mpDrv)
2864 return;
2865
2866#if DEBUG
2867 /*
2868 * Sanity check. Note that this method may be called on EMT after Console
2869 * has started the power down procedure (but before our #drvDestruct() is
2870 * called, in which case pVM will already be NULL but mpDrv will not). Since
2871 * we don't really need pVM to proceed, we avoid this check in the release
2872 * build to save some ms (necessary to construct SafeVMPtrQuiet) in this
2873 * time-critical method.
2874 */
2875 Console::SafeVMPtrQuiet pVM (mParent);
2876 if (pVM.isOk())
2877 VM_ASSERT_EMT (pVM.raw());
2878#endif
2879
2880 /* The method is only relevant to the primary framebuffer. */
2881 IFramebuffer *pFramebuffer = maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
2882
2883 if (pFramebuffer)
2884 {
2885 HRESULT rc;
2886 BYTE *address = 0;
2887 rc = pFramebuffer->COMGETTER(Address) (&address);
2888 AssertComRC (rc);
2889 ULONG bytesPerLine = 0;
2890 rc = pFramebuffer->COMGETTER(BytesPerLine) (&bytesPerLine);
2891 AssertComRC (rc);
2892 ULONG bitsPerPixel = 0;
2893 rc = pFramebuffer->COMGETTER(BitsPerPixel) (&bitsPerPixel);
2894 AssertComRC (rc);
2895 ULONG width = 0;
2896 rc = pFramebuffer->COMGETTER(Width) (&width);
2897 AssertComRC (rc);
2898 ULONG height = 0;
2899 rc = pFramebuffer->COMGETTER(Height) (&height);
2900 AssertComRC (rc);
2901
2902 mpDrv->IConnector.pu8Data = (uint8_t *) address;
2903 mpDrv->IConnector.cbScanline = bytesPerLine;
2904 mpDrv->IConnector.cBits = bitsPerPixel;
2905 mpDrv->IConnector.cx = width;
2906 mpDrv->IConnector.cy = height;
2907 }
2908 else
2909 {
2910 /* black hole */
2911 mpDrv->IConnector.pu8Data = NULL;
2912 mpDrv->IConnector.cbScanline = 0;
2913 mpDrv->IConnector.cBits = 0;
2914 mpDrv->IConnector.cx = 0;
2915 mpDrv->IConnector.cy = 0;
2916 }
2917 LogFlowFunc (("leave\n"));
2918}
2919
2920#ifdef VBOX_WITH_CRHGSMI
2921void Display::setupCrHgsmiData(void)
2922{
2923 VMMDev *pVMMDev = mParent->getVMMDev();
2924 Assert(pVMMDev);
2925 int rc = VERR_GENERAL_FAILURE;
2926 if (pVMMDev)
2927 rc = pVMMDev->hgcmHostSvcHandleCreate("VBoxSharedCrOpenGL", &mhCrOglSvc);
2928
2929 if (RT_SUCCESS(rc))
2930 {
2931 Assert(mhCrOglSvc);
2932 }
2933 else
2934 {
2935 mhCrOglSvc = NULL;
2936 }
2937}
2938
2939void Display::destructCrHgsmiData(void)
2940{
2941 mhCrOglSvc = NULL;
2942}
2943#endif
2944
2945/**
2946 * Changes the current frame buffer. Called on EMT to avoid both
2947 * race conditions and excessive locking.
2948 *
2949 * @note locks this object for writing
2950 * @thread EMT
2951 */
2952/* static */
2953DECLCALLBACK(int) Display::changeFramebuffer (Display *that, IFramebuffer *aFB,
2954 unsigned uScreenId)
2955{
2956 LogFlowFunc (("uScreenId = %d\n", uScreenId));
2957
2958 AssertReturn(that, VERR_INVALID_PARAMETER);
2959 AssertReturn(uScreenId < that->mcMonitors, VERR_INVALID_PARAMETER);
2960
2961 AutoCaller autoCaller(that);
2962 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2963
2964 AutoWriteLock alock(that COMMA_LOCKVAL_SRC_POS);
2965
2966 DISPLAYFBINFO *pDisplayFBInfo = &that->maFramebuffers[uScreenId];
2967 pDisplayFBInfo->pFramebuffer = aFB;
2968
2969 that->mParent->consoleVRDPServer()->SendResize ();
2970
2971 /* The driver might not have been constructed yet */
2972 if (that->mpDrv)
2973 {
2974 /* Setup the new framebuffer, the resize will lead to an updateDisplayData call. */
2975 DISPLAYFBINFO *pFBInfo = &that->maFramebuffers[uScreenId];
2976
2977 if (pFBInfo->fVBVAEnabled && pFBInfo->pu8FramebufferVRAM)
2978 {
2979 /* This display in VBVA mode. Resize it to the last guest resolution,
2980 * if it has been reported.
2981 */
2982 that->handleDisplayResize(uScreenId, pFBInfo->u16BitsPerPixel,
2983 pFBInfo->pu8FramebufferVRAM,
2984 pFBInfo->u32LineSize,
2985 pFBInfo->w,
2986 pFBInfo->h);
2987 }
2988 else if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2989 {
2990 /* VGA device mode, only for the primary screen. */
2991 that->handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, that->mLastBitsPerPixel,
2992 that->mLastAddress,
2993 that->mLastBytesPerLine,
2994 that->mLastWidth,
2995 that->mLastHeight);
2996 }
2997 }
2998
2999 LogFlowFunc (("leave\n"));
3000 return VINF_SUCCESS;
3001}
3002
3003/**
3004 * Handle display resize event issued by the VGA device for the primary screen.
3005 *
3006 * @see PDMIDISPLAYCONNECTOR::pfnResize
3007 */
3008DECLCALLBACK(int) Display::displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface,
3009 uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy)
3010{
3011 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3012
3013 LogFlowFunc (("bpp %d, pvVRAM %p, cbLine %d, cx %d, cy %d\n",
3014 bpp, pvVRAM, cbLine, cx, cy));
3015
3016 return pDrv->pDisplay->handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, bpp, pvVRAM, cbLine, cx, cy);
3017}
3018
3019/**
3020 * Handle display update.
3021 *
3022 * @see PDMIDISPLAYCONNECTOR::pfnUpdateRect
3023 */
3024DECLCALLBACK(void) Display::displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
3025 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
3026{
3027 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3028
3029#ifdef DEBUG_sunlover
3030 LogFlowFunc (("mfVideoAccelEnabled = %d, %d,%d %dx%d\n",
3031 pDrv->pDisplay->mfVideoAccelEnabled, x, y, cx, cy));
3032#endif /* DEBUG_sunlover */
3033
3034 /* This call does update regardless of VBVA status.
3035 * But in VBVA mode this is called only as result of
3036 * pfnUpdateDisplayAll in the VGA device.
3037 */
3038
3039 pDrv->pDisplay->handleDisplayUpdate(VBOX_VIDEO_PRIMARY_SCREEN, x, y, cx, cy);
3040}
3041
3042/**
3043 * Periodic display refresh callback.
3044 *
3045 * @see PDMIDISPLAYCONNECTOR::pfnRefresh
3046 */
3047DECLCALLBACK(void) Display::displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface)
3048{
3049 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3050
3051#ifdef DEBUG_sunlover
3052 STAM_PROFILE_START(&StatDisplayRefresh, a);
3053#endif /* DEBUG_sunlover */
3054
3055#ifdef DEBUG_sunlover_2
3056 LogFlowFunc (("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
3057 pDrv->pDisplay->mfVideoAccelEnabled));
3058#endif /* DEBUG_sunlover_2 */
3059
3060 Display *pDisplay = pDrv->pDisplay;
3061 bool fNoUpdate = false; /* Do not update the display if any of the framebuffers is being resized. */
3062 unsigned uScreenId;
3063
3064 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3065 {
3066 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3067
3068 /* Check the resize status. The status can be checked normally because
3069 * the status affects only the EMT.
3070 */
3071 uint32_t u32ResizeStatus = pFBInfo->u32ResizeStatus;
3072
3073 if (u32ResizeStatus == ResizeStatus_UpdateDisplayData)
3074 {
3075 LogFlowFunc (("ResizeStatus_UpdateDisplayData %d\n", uScreenId));
3076 fNoUpdate = true; /* Always set it here, because pfnUpdateDisplayAll can cause a new resize. */
3077 /* The framebuffer was resized and display data need to be updated. */
3078 pDisplay->handleResizeCompletedEMT ();
3079 if (pFBInfo->u32ResizeStatus != ResizeStatus_Void)
3080 {
3081 /* The resize status could be not Void here because a pending resize is issued. */
3082 continue;
3083 }
3084 /* Continue with normal processing because the status here is ResizeStatus_Void. */
3085 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3086 {
3087 /* Repaint the display because VM continued to run during the framebuffer resize. */
3088 if (!pFBInfo->pFramebuffer.isNull())
3089#ifdef VBOX_WITH_OLD_VBVA_LOCK
3090 {
3091 pDisplay->vbvaLock();
3092#endif /* VBOX_WITH_OLD_VBVA_LOCK */
3093 pDrv->pUpPort->pfnUpdateDisplayAll(pDrv->pUpPort);
3094#ifdef VBOX_WITH_OLD_VBVA_LOCK
3095 pDisplay->vbvaUnlock();
3096 }
3097#endif /* VBOX_WITH_OLD_VBVA_LOCK */
3098 }
3099 }
3100 else if (u32ResizeStatus == ResizeStatus_InProgress)
3101 {
3102 /* The framebuffer is being resized. Do not call the VGA device back. Immediately return. */
3103 LogFlowFunc (("ResizeStatus_InProcess\n"));
3104 fNoUpdate = true;
3105 continue;
3106 }
3107 }
3108
3109 if (!fNoUpdate)
3110 {
3111#ifdef VBOX_WITH_OLD_VBVA_LOCK
3112 int rc = pDisplay->videoAccelRefreshProcess();
3113
3114 if (rc != VINF_TRY_AGAIN) /* Means 'do nothing' here. */
3115 {
3116 if (rc == VWRN_INVALID_STATE)
3117 {
3118 /* No VBVA do a display update. */
3119 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN];
3120 if (!pFBInfo->pFramebuffer.isNull() && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
3121 {
3122 Assert(pDrv->IConnector.pu8Data);
3123 pDisplay->vbvaLock();
3124 pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
3125 pDisplay->vbvaUnlock();
3126 }
3127 }
3128
3129 /* Inform the VRDP server that the current display update sequence is
3130 * completed. At this moment the framebuffer memory contains a definite
3131 * image, that is synchronized with the orders already sent to VRDP client.
3132 * The server can now process redraw requests from clients or initial
3133 * fullscreen updates for new clients.
3134 */
3135 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3136 {
3137 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3138
3139 if (!pFBInfo->pFramebuffer.isNull() && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
3140 {
3141 Assert (pDisplay->mParent && pDisplay->mParent->consoleVRDPServer());
3142 pDisplay->mParent->consoleVRDPServer()->SendUpdate (uScreenId, NULL, 0);
3143 }
3144 }
3145 }
3146#else
3147 if (pDisplay->mfPendingVideoAccelEnable)
3148 {
3149 /* Acceleration was enabled while machine was not yet running
3150 * due to restoring from saved state. Update entire display and
3151 * actually enable acceleration.
3152 */
3153 Assert(pDisplay->mpPendingVbvaMemory);
3154
3155 /* Acceleration can not be yet enabled.*/
3156 Assert(pDisplay->mpVbvaMemory == NULL);
3157 Assert(!pDisplay->mfVideoAccelEnabled);
3158
3159 if (pDisplay->mfMachineRunning)
3160 {
3161 pDisplay->VideoAccelEnable (pDisplay->mfPendingVideoAccelEnable,
3162 pDisplay->mpPendingVbvaMemory);
3163
3164 /* Reset the pending state. */
3165 pDisplay->mfPendingVideoAccelEnable = false;
3166 pDisplay->mpPendingVbvaMemory = NULL;
3167 }
3168 }
3169 else
3170 {
3171 Assert(pDisplay->mpPendingVbvaMemory == NULL);
3172
3173 if (pDisplay->mfVideoAccelEnabled)
3174 {
3175 Assert(pDisplay->mpVbvaMemory);
3176 pDisplay->VideoAccelFlush ();
3177 }
3178 else
3179 {
3180 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN];
3181 if (!pFBInfo->pFramebuffer.isNull())
3182 {
3183 Assert(pDrv->IConnector.pu8Data);
3184 Assert(pFBInfo->u32ResizeStatus == ResizeStatus_Void);
3185 pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
3186 }
3187 }
3188
3189 /* Inform the VRDP server that the current display update sequence is
3190 * completed. At this moment the framebuffer memory contains a definite
3191 * image, that is synchronized with the orders already sent to VRDP client.
3192 * The server can now process redraw requests from clients or initial
3193 * fullscreen updates for new clients.
3194 */
3195 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3196 {
3197 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3198
3199 if (!pFBInfo->pFramebuffer.isNull() && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
3200 {
3201 Assert (pDisplay->mParent && pDisplay->mParent->consoleVRDPServer());
3202 pDisplay->mParent->consoleVRDPServer()->SendUpdate (uScreenId, NULL, 0);
3203 }
3204 }
3205 }
3206#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
3207 }
3208
3209#ifdef DEBUG_sunlover
3210 STAM_PROFILE_STOP(&StatDisplayRefresh, a);
3211#endif /* DEBUG_sunlover */
3212#ifdef DEBUG_sunlover_2
3213 LogFlowFunc (("leave\n"));
3214#endif /* DEBUG_sunlover_2 */
3215}
3216
3217/**
3218 * Reset notification
3219 *
3220 * @see PDMIDISPLAYCONNECTOR::pfnReset
3221 */
3222DECLCALLBACK(void) Display::displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface)
3223{
3224 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3225
3226 LogFlowFunc (("\n"));
3227
3228 /* Disable VBVA mode. */
3229 pDrv->pDisplay->VideoAccelEnable (false, NULL);
3230}
3231
3232/**
3233 * LFBModeChange notification
3234 *
3235 * @see PDMIDISPLAYCONNECTOR::pfnLFBModeChange
3236 */
3237DECLCALLBACK(void) Display::displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled)
3238{
3239 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3240
3241 LogFlowFunc (("fEnabled=%d\n", fEnabled));
3242
3243 NOREF(fEnabled);
3244
3245 /* Disable VBVA mode in any case. The guest driver reenables VBVA mode if necessary. */
3246#ifdef VBOX_WITH_OLD_VBVA_LOCK
3247 /* This is called under DevVGA lock. Postpone disabling VBVA, do it in the refresh timer. */
3248 ASMAtomicWriteU32(&pDrv->pDisplay->mfu32PendingVideoAccelDisable, true);
3249#else
3250 pDrv->pDisplay->VideoAccelEnable (false, NULL);
3251#endif /* !VBOX_WITH_OLD_VBVA_LOCK */
3252}
3253
3254/**
3255 * Adapter information change notification.
3256 *
3257 * @see PDMIDISPLAYCONNECTOR::pfnProcessAdapterData
3258 */
3259DECLCALLBACK(void) Display::displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize)
3260{
3261 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3262
3263 if (pvVRAM == NULL)
3264 {
3265 unsigned i;
3266 for (i = 0; i < pDrv->pDisplay->mcMonitors; i++)
3267 {
3268 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[i];
3269
3270 pFBInfo->u32Offset = 0;
3271 pFBInfo->u32MaxFramebufferSize = 0;
3272 pFBInfo->u32InformationSize = 0;
3273 }
3274 }
3275#ifndef VBOX_WITH_HGSMI
3276 else
3277 {
3278 uint8_t *pu8 = (uint8_t *)pvVRAM;
3279 pu8 += u32VRAMSize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE;
3280
3281 // @todo
3282 uint8_t *pu8End = pu8 + VBOX_VIDEO_ADAPTER_INFORMATION_SIZE;
3283
3284 VBOXVIDEOINFOHDR *pHdr;
3285
3286 for (;;)
3287 {
3288 pHdr = (VBOXVIDEOINFOHDR *)pu8;
3289 pu8 += sizeof (VBOXVIDEOINFOHDR);
3290
3291 if (pu8 >= pu8End)
3292 {
3293 LogRel(("VBoxVideo: Guest adapter information overflow!!!\n"));
3294 break;
3295 }
3296
3297 if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_DISPLAY)
3298 {
3299 if (pHdr->u16Length != sizeof (VBOXVIDEOINFODISPLAY))
3300 {
3301 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "DISPLAY", pHdr->u16Length));
3302 break;
3303 }
3304
3305 VBOXVIDEOINFODISPLAY *pDisplay = (VBOXVIDEOINFODISPLAY *)pu8;
3306
3307 if (pDisplay->u32Index >= pDrv->pDisplay->mcMonitors)
3308 {
3309 LogRel(("VBoxVideo: Guest adapter information invalid display index %d!!!\n", pDisplay->u32Index));
3310 break;
3311 }
3312
3313 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[pDisplay->u32Index];
3314
3315 pFBInfo->u32Offset = pDisplay->u32Offset;
3316 pFBInfo->u32MaxFramebufferSize = pDisplay->u32FramebufferSize;
3317 pFBInfo->u32InformationSize = pDisplay->u32InformationSize;
3318
3319 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));
3320 }
3321 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_QUERY_CONF32)
3322 {
3323 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOQUERYCONF32))
3324 {
3325 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "CONF32", pHdr->u16Length));
3326 break;
3327 }
3328
3329 VBOXVIDEOINFOQUERYCONF32 *pConf32 = (VBOXVIDEOINFOQUERYCONF32 *)pu8;
3330
3331 switch (pConf32->u32Index)
3332 {
3333 case VBOX_VIDEO_QCI32_MONITOR_COUNT:
3334 {
3335 pConf32->u32Value = pDrv->pDisplay->mcMonitors;
3336 } break;
3337
3338 case VBOX_VIDEO_QCI32_OFFSCREEN_HEAP_SIZE:
3339 {
3340 /* @todo make configurable. */
3341 pConf32->u32Value = _1M;
3342 } break;
3343
3344 default:
3345 LogRel(("VBoxVideo: CONF32 %d not supported!!! Skipping.\n", pConf32->u32Index));
3346 }
3347 }
3348 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_END)
3349 {
3350 if (pHdr->u16Length != 0)
3351 {
3352 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "END", pHdr->u16Length));
3353 break;
3354 }
3355
3356 break;
3357 }
3358 else if (pHdr->u8Type != VBOX_VIDEO_INFO_TYPE_NV_HEAP) /** @todo why is Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp pushing this to us? */
3359 {
3360 LogRel(("Guest adapter information contains unsupported type %d. The block has been skipped.\n", pHdr->u8Type));
3361 }
3362
3363 pu8 += pHdr->u16Length;
3364 }
3365 }
3366#endif /* !VBOX_WITH_HGSMI */
3367}
3368
3369/**
3370 * Display information change notification.
3371 *
3372 * @see PDMIDISPLAYCONNECTOR::pfnProcessDisplayData
3373 */
3374DECLCALLBACK(void) Display::displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId)
3375{
3376 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3377
3378 if (uScreenId >= pDrv->pDisplay->mcMonitors)
3379 {
3380 LogRel(("VBoxVideo: Guest display information invalid display index %d!!!\n", uScreenId));
3381 return;
3382 }
3383
3384 /* Get the display information structure. */
3385 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[uScreenId];
3386
3387 uint8_t *pu8 = (uint8_t *)pvVRAM;
3388 pu8 += pFBInfo->u32Offset + pFBInfo->u32MaxFramebufferSize;
3389
3390 // @todo
3391 uint8_t *pu8End = pu8 + pFBInfo->u32InformationSize;
3392
3393 VBOXVIDEOINFOHDR *pHdr;
3394
3395 for (;;)
3396 {
3397 pHdr = (VBOXVIDEOINFOHDR *)pu8;
3398 pu8 += sizeof (VBOXVIDEOINFOHDR);
3399
3400 if (pu8 >= pu8End)
3401 {
3402 LogRel(("VBoxVideo: Guest display information overflow!!!\n"));
3403 break;
3404 }
3405
3406 if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_SCREEN)
3407 {
3408 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOSCREEN))
3409 {
3410 LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "SCREEN", pHdr->u16Length));
3411 break;
3412 }
3413
3414 VBOXVIDEOINFOSCREEN *pScreen = (VBOXVIDEOINFOSCREEN *)pu8;
3415
3416 pFBInfo->xOrigin = pScreen->xOrigin;
3417 pFBInfo->yOrigin = pScreen->yOrigin;
3418
3419 pFBInfo->w = pScreen->u16Width;
3420 pFBInfo->h = pScreen->u16Height;
3421
3422 LogFlow(("VBOX_VIDEO_INFO_TYPE_SCREEN: (%p) %d: at %d,%d, linesize 0x%X, size %dx%d, bpp %d, flags 0x%02X\n",
3423 pHdr, uScreenId, pScreen->xOrigin, pScreen->yOrigin, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height, pScreen->bitsPerPixel, pScreen->u8Flags));
3424
3425 if (uScreenId != VBOX_VIDEO_PRIMARY_SCREEN)
3426 {
3427 /* Primary screen resize is initiated by the VGA device. */
3428 pDrv->pDisplay->handleDisplayResize(uScreenId, pScreen->bitsPerPixel, (uint8_t *)pvVRAM + pFBInfo->u32Offset, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height);
3429 }
3430 }
3431 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_END)
3432 {
3433 if (pHdr->u16Length != 0)
3434 {
3435 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "END", pHdr->u16Length));
3436 break;
3437 }
3438
3439 break;
3440 }
3441 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_HOST_EVENTS)
3442 {
3443 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOHOSTEVENTS))
3444 {
3445 LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "HOST_EVENTS", pHdr->u16Length));
3446 break;
3447 }
3448
3449 VBOXVIDEOINFOHOSTEVENTS *pHostEvents = (VBOXVIDEOINFOHOSTEVENTS *)pu8;
3450
3451 pFBInfo->pHostEvents = pHostEvents;
3452
3453 LogFlow(("VBOX_VIDEO_INFO_TYPE_HOSTEVENTS: (%p)\n",
3454 pHostEvents));
3455 }
3456 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_LINK)
3457 {
3458 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOLINK))
3459 {
3460 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "LINK", pHdr->u16Length));
3461 break;
3462 }
3463
3464 VBOXVIDEOINFOLINK *pLink = (VBOXVIDEOINFOLINK *)pu8;
3465 pu8 += pLink->i32Offset;
3466 }
3467 else
3468 {
3469 LogRel(("Guest display information contains unsupported type %d\n", pHdr->u8Type));
3470 }
3471
3472 pu8 += pHdr->u16Length;
3473 }
3474}
3475
3476#ifdef VBOX_WITH_VIDEOHWACCEL
3477
3478void Display::handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
3479{
3480 unsigned id = (unsigned)pCommand->iDisplay;
3481 int rc = VINF_SUCCESS;
3482 if (id < mcMonitors)
3483 {
3484 IFramebuffer *pFramebuffer = maFramebuffers[id].pFramebuffer;
3485#ifdef DEBUG_misha
3486 Assert (pFramebuffer);
3487#endif
3488
3489 if (pFramebuffer != NULL)
3490 {
3491 HRESULT hr = pFramebuffer->ProcessVHWACommand((BYTE*)pCommand);
3492 if (FAILED(hr))
3493 {
3494 rc = (hr == E_NOTIMPL) ? VERR_NOT_IMPLEMENTED : VERR_GENERAL_FAILURE;
3495 }
3496 }
3497 else
3498 {
3499 rc = VERR_NOT_IMPLEMENTED;
3500 }
3501 }
3502 else
3503 {
3504 rc = VERR_INVALID_PARAMETER;
3505 }
3506
3507 if (RT_FAILURE(rc))
3508 {
3509 /* tell the guest the command is complete */
3510 pCommand->Flags &= (~VBOXVHWACMD_FLAG_HG_ASYNCH);
3511 pCommand->rc = rc;
3512 }
3513}
3514
3515DECLCALLBACK(void) Display::displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
3516{
3517 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3518
3519 pDrv->pDisplay->handleVHWACommandProcess(pInterface, pCommand);
3520}
3521#endif
3522
3523#ifdef VBOX_WITH_CRHGSMI
3524void Display::handleCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam)
3525{
3526 mpDrv->pVBVACallbacks->pfnCrHgsmiCommandCompleteAsync(mpDrv->pVBVACallbacks, (PVBOXVDMACMD_CHROMIUM_CMD)pParam->u.pointer.addr, result);
3527}
3528
3529void Display::handleCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam)
3530{
3531 mpDrv->pVBVACallbacks->pfnCrHgsmiControlCompleteAsync(mpDrv->pVBVACallbacks, (PVBOXVDMACMD_CHROMIUM_CTL)pParam->u.pointer.addr, result);
3532}
3533
3534void Display::handleCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd)
3535{
3536 int rc = VERR_INVALID_FUNCTION;
3537 VBOXHGCMSVCPARM parm;
3538 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3539 parm.u.pointer.addr = pCmd;
3540 parm.u.pointer.size = 0;
3541
3542 if (mhCrOglSvc)
3543 {
3544 VMMDev *pVMMDev = mParent->getVMMDev();
3545 if (pVMMDev)
3546 {
3547 rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CRHGSMI_CMD, &parm, Display::displayCrHgsmiCommandCompletion, this);
3548 AssertRC(rc);
3549 if (RT_SUCCESS(rc))
3550 return;
3551 }
3552 else
3553 rc = VERR_INVALID_STATE;
3554 }
3555
3556 /* we are here because something went wrong with command processing, complete it */
3557 handleCrHgsmiCommandCompletion(rc, SHCRGL_HOST_FN_CRHGSMI_CMD, &parm);
3558}
3559
3560void Display::handleCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl)
3561{
3562 int rc = VERR_INVALID_FUNCTION;
3563 VBOXHGCMSVCPARM parm;
3564 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3565 parm.u.pointer.addr = pCtl;
3566 parm.u.pointer.size = 0;
3567
3568 if (mhCrOglSvc)
3569 {
3570 VMMDev *pVMMDev = mParent->getVMMDev();
3571 if (pVMMDev)
3572 {
3573 rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CRHGSMI_CTL, &parm, Display::displayCrHgsmiControlCompletion, this);
3574 AssertRC(rc);
3575 if (RT_SUCCESS(rc))
3576 return;
3577 }
3578 else
3579 rc = VERR_INVALID_STATE;
3580 }
3581
3582 /* we are here because something went wrong with command processing, complete it */
3583 handleCrHgsmiControlCompletion(rc, SHCRGL_HOST_FN_CRHGSMI_CTL, &parm);
3584}
3585
3586DECLCALLBACK(void) Display::displayCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd)
3587{
3588 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3589
3590 pDrv->pDisplay->handleCrHgsmiCommandProcess(pInterface, pCmd);
3591}
3592
3593DECLCALLBACK(void) Display::displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCmd)
3594{
3595 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3596
3597 pDrv->pDisplay->handleCrHgsmiControlProcess(pInterface, pCmd);
3598}
3599
3600DECLCALLBACK(void) Display::displayCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext)
3601{
3602 Display *pDisplay = (Display *)pvContext;
3603 pDisplay->handleCrHgsmiCommandCompletion(result, u32Function, pParam);
3604}
3605
3606DECLCALLBACK(void) Display::displayCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext)
3607{
3608 Display *pDisplay = (Display *)pvContext;
3609 pDisplay->handleCrHgsmiControlCompletion(result, u32Function, pParam);
3610}
3611#endif
3612
3613
3614#ifdef VBOX_WITH_HGSMI
3615DECLCALLBACK(int) Display::displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags)
3616{
3617 LogFlowFunc(("uScreenId %d\n", uScreenId));
3618
3619 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3620 Display *pThis = pDrv->pDisplay;
3621
3622 pThis->maFramebuffers[uScreenId].fVBVAEnabled = true;
3623 pThis->maFramebuffers[uScreenId].pVBVAHostFlags = pHostFlags;
3624
3625 vbvaSetMemoryFlagsHGSMI(uScreenId, pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, &pThis->maFramebuffers[uScreenId]);
3626
3627 return VINF_SUCCESS;
3628}
3629
3630DECLCALLBACK(void) Display::displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3631{
3632 LogFlowFunc(("uScreenId %d\n", uScreenId));
3633
3634 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3635 Display *pThis = pDrv->pDisplay;
3636
3637 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3638
3639 pFBInfo->fVBVAEnabled = false;
3640
3641 vbvaSetMemoryFlagsHGSMI(uScreenId, 0, false, pFBInfo);
3642
3643 pFBInfo->pVBVAHostFlags = NULL;
3644
3645 pFBInfo->u32Offset = 0; /* Not used in HGSMI. */
3646 pFBInfo->u32MaxFramebufferSize = 0; /* Not used in HGSMI. */
3647 pFBInfo->u32InformationSize = 0; /* Not used in HGSMI. */
3648
3649 pFBInfo->xOrigin = 0;
3650 pFBInfo->yOrigin = 0;
3651
3652 pFBInfo->w = 0;
3653 pFBInfo->h = 0;
3654
3655 pFBInfo->u16BitsPerPixel = 0;
3656 pFBInfo->pu8FramebufferVRAM = NULL;
3657 pFBInfo->u32LineSize = 0;
3658}
3659
3660DECLCALLBACK(void) Display::displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3661{
3662 LogFlowFunc(("uScreenId %d\n", uScreenId));
3663
3664 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3665 Display *pThis = pDrv->pDisplay;
3666 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3667
3668 if (ASMAtomicReadU32(&pThis->mu32UpdateVBVAFlags) > 0)
3669 {
3670 vbvaSetMemoryFlagsAllHGSMI(pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, pThis->maFramebuffers, pThis->mcMonitors);
3671 ASMAtomicDecU32(&pThis->mu32UpdateVBVAFlags);
3672 }
3673
3674 if (RT_LIKELY(pFBInfo->u32ResizeStatus == ResizeStatus_Void))
3675 {
3676 if (RT_UNLIKELY(pFBInfo->cVBVASkipUpdate != 0))
3677 {
3678 /* Some updates were skipped. Note: displayVBVAUpdate* callbacks are called
3679 * under display device lock, so thread safe.
3680 */
3681 pFBInfo->cVBVASkipUpdate = 0;
3682 pThis->handleDisplayUpdate(uScreenId, pFBInfo->vbvaSkippedRect.xLeft - pFBInfo->xOrigin,
3683 pFBInfo->vbvaSkippedRect.yTop - pFBInfo->yOrigin,
3684 pFBInfo->vbvaSkippedRect.xRight - pFBInfo->vbvaSkippedRect.xLeft,
3685 pFBInfo->vbvaSkippedRect.yBottom - pFBInfo->vbvaSkippedRect.yTop);
3686 }
3687 }
3688 else
3689 {
3690 /* The framebuffer is being resized. */
3691 pFBInfo->cVBVASkipUpdate++;
3692 }
3693}
3694
3695DECLCALLBACK(void) Display::displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd)
3696{
3697 LogFlowFunc(("uScreenId %d pCmd %p cbCmd %d, @%d,%d %dx%d\n", uScreenId, pCmd, cbCmd, pCmd->x, pCmd->y, pCmd->w, pCmd->h));
3698
3699 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3700 Display *pThis = pDrv->pDisplay;
3701 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3702
3703 if (RT_LIKELY(pFBInfo->cVBVASkipUpdate == 0))
3704 {
3705 if (pFBInfo->fDefaultFormat)
3706 {
3707 /* Make sure that framebuffer contains the same image as the guest VRAM. */
3708 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN && !pFBInfo->pFramebuffer.isNull())
3709 {
3710 pDrv->pUpPort->pfnUpdateDisplayRect (pDrv->pUpPort, pCmd->x, pCmd->y, pCmd->w, pCmd->h);
3711 }
3712 else if (!pFBInfo->pFramebuffer.isNull())
3713 {
3714 /* Render VRAM content to the framebuffer. */
3715 BYTE *address = NULL;
3716 HRESULT hrc = pFBInfo->pFramebuffer->COMGETTER(Address) (&address);
3717 if (SUCCEEDED(hrc) && address != NULL)
3718 {
3719 uint32_t width = pCmd->w;
3720 uint32_t height = pCmd->h;
3721
3722 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
3723 int32_t xSrc = pCmd->x - pFBInfo->xOrigin;
3724 int32_t ySrc = pCmd->y - pFBInfo->yOrigin;
3725 uint32_t u32SrcWidth = pFBInfo->w;
3726 uint32_t u32SrcHeight = pFBInfo->h;
3727 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
3728 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
3729
3730 uint8_t *pu8Dst = address;
3731 int32_t xDst = xSrc;
3732 int32_t yDst = ySrc;
3733 uint32_t u32DstWidth = u32SrcWidth;
3734 uint32_t u32DstHeight = u32SrcHeight;
3735 uint32_t u32DstLineSize = u32DstWidth * 4;
3736 uint32_t u32DstBitsPerPixel = 32;
3737
3738 pDrv->pUpPort->pfnCopyRect(pDrv->pUpPort,
3739 width, height,
3740 pu8Src,
3741 xSrc, ySrc,
3742 u32SrcWidth, u32SrcHeight,
3743 u32SrcLineSize, u32SrcBitsPerPixel,
3744 pu8Dst,
3745 xDst, yDst,
3746 u32DstWidth, u32DstHeight,
3747 u32DstLineSize, u32DstBitsPerPixel);
3748 }
3749 }
3750 }
3751
3752 VBVACMDHDR hdrSaved = *pCmd;
3753
3754 VBVACMDHDR *pHdrUnconst = (VBVACMDHDR *)pCmd;
3755
3756 pHdrUnconst->x -= (int16_t)pFBInfo->xOrigin;
3757 pHdrUnconst->y -= (int16_t)pFBInfo->yOrigin;
3758
3759 /* @todo new SendUpdate entry which can get a separate cmd header or coords. */
3760 pThis->mParent->consoleVRDPServer()->SendUpdate (uScreenId, pCmd, cbCmd);
3761
3762 *pHdrUnconst = hdrSaved;
3763 }
3764}
3765
3766DECLCALLBACK(void) Display::displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy)
3767{
3768 LogFlowFunc(("uScreenId %d %d,%d %dx%d\n", uScreenId, x, y, cx, cy));
3769
3770 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3771 Display *pThis = pDrv->pDisplay;
3772 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3773
3774 /* @todo handleFramebufferUpdate (uScreenId,
3775 * x - pThis->maFramebuffers[uScreenId].xOrigin,
3776 * y - pThis->maFramebuffers[uScreenId].yOrigin,
3777 * cx, cy);
3778 */
3779 if (RT_LIKELY(pFBInfo->cVBVASkipUpdate == 0))
3780 {
3781 pThis->handleDisplayUpdate(uScreenId, x - pFBInfo->xOrigin, y - pFBInfo->yOrigin, cx, cy);
3782 }
3783 else
3784 {
3785 /* Save the updated rectangle. */
3786 int32_t xRight = x + cx;
3787 int32_t yBottom = y + cy;
3788
3789 if (pFBInfo->cVBVASkipUpdate == 1)
3790 {
3791 pFBInfo->vbvaSkippedRect.xLeft = x;
3792 pFBInfo->vbvaSkippedRect.yTop = y;
3793 pFBInfo->vbvaSkippedRect.xRight = xRight;
3794 pFBInfo->vbvaSkippedRect.yBottom = yBottom;
3795 }
3796 else
3797 {
3798 if (pFBInfo->vbvaSkippedRect.xLeft > x)
3799 {
3800 pFBInfo->vbvaSkippedRect.xLeft = x;
3801 }
3802 if (pFBInfo->vbvaSkippedRect.yTop > y)
3803 {
3804 pFBInfo->vbvaSkippedRect.yTop = y;
3805 }
3806 if (pFBInfo->vbvaSkippedRect.xRight < xRight)
3807 {
3808 pFBInfo->vbvaSkippedRect.xRight = xRight;
3809 }
3810 if (pFBInfo->vbvaSkippedRect.yBottom < yBottom)
3811 {
3812 pFBInfo->vbvaSkippedRect.yBottom = yBottom;
3813 }
3814 }
3815 }
3816}
3817
3818DECLCALLBACK(int) Display::displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM)
3819{
3820 LogFlowFunc(("pScreen %p, pvVRAM %p\n", pScreen, pvVRAM));
3821
3822 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3823 Display *pThis = pDrv->pDisplay;
3824
3825 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[pScreen->u32ViewIndex];
3826
3827 /* Check if this is a real resize or a notification about the screen origin.
3828 * The guest uses this VBVAResize call for both.
3829 */
3830 bool fResize = pFBInfo->u16BitsPerPixel != pScreen->u16BitsPerPixel
3831 || pFBInfo->pu8FramebufferVRAM != (uint8_t *)pvVRAM + pScreen->u32StartOffset
3832 || pFBInfo->u32LineSize != pScreen->u32LineSize
3833 || pFBInfo->w != pScreen->u32Width
3834 || pFBInfo->h != pScreen->u32Height;
3835
3836 bool fNewOrigin = pFBInfo->xOrigin != pScreen->i32OriginX
3837 || pFBInfo->yOrigin != pScreen->i32OriginY;
3838
3839 pFBInfo->u32Offset = pView->u32ViewOffset; /* Not used in HGSMI. */
3840 pFBInfo->u32MaxFramebufferSize = pView->u32MaxScreenSize; /* Not used in HGSMI. */
3841 pFBInfo->u32InformationSize = 0; /* Not used in HGSMI. */
3842
3843 pFBInfo->xOrigin = pScreen->i32OriginX;
3844 pFBInfo->yOrigin = pScreen->i32OriginY;
3845
3846 pFBInfo->w = pScreen->u32Width;
3847 pFBInfo->h = pScreen->u32Height;
3848
3849 pFBInfo->u16BitsPerPixel = pScreen->u16BitsPerPixel;
3850 pFBInfo->pu8FramebufferVRAM = (uint8_t *)pvVRAM + pScreen->u32StartOffset;
3851 pFBInfo->u32LineSize = pScreen->u32LineSize;
3852
3853 if (fNewOrigin)
3854 {
3855 /* @todo May be framebuffer/display should be notified in this case. */
3856 }
3857
3858#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
3859 if (fNewOrigin && !fResize)
3860 {
3861 BOOL is3denabled;
3862 pThis->mParent->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
3863
3864 if (is3denabled)
3865 {
3866 VBOXHGCMSVCPARM parm;
3867
3868 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
3869 parm.u.uint32 = pScreen->u32ViewIndex;
3870
3871 VMMDev *pVMMDev = pThis->mParent->getVMMDev();
3872
3873 if (pVMMDev)
3874 pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SCREEN_CHANGED, SHCRGL_CPARMS_SCREEN_CHANGED, &parm);
3875 }
3876 }
3877#endif /* VBOX_WITH_CROGL */
3878
3879 if (!fResize)
3880 {
3881 /* No parameters of the framebuffer have actually changed. */
3882 if (fNewOrigin)
3883 {
3884 /* VRDP server still need this notification. */
3885 LogFlowFunc (("Calling VRDP\n"));
3886 pThis->mParent->consoleVRDPServer()->SendResize();
3887 }
3888 return VINF_SUCCESS;
3889 }
3890
3891 return pThis->handleDisplayResize(pScreen->u32ViewIndex, pScreen->u16BitsPerPixel,
3892 (uint8_t *)pvVRAM + pScreen->u32StartOffset,
3893 pScreen->u32LineSize, pScreen->u32Width, pScreen->u32Height);
3894}
3895
3896DECLCALLBACK(int) Display::displayVBVAMousePointerShape(PPDMIDISPLAYCONNECTOR pInterface, bool fVisible, bool fAlpha,
3897 uint32_t xHot, uint32_t yHot,
3898 uint32_t cx, uint32_t cy,
3899 const void *pvShape)
3900{
3901 LogFlowFunc(("\n"));
3902
3903 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3904 Display *pThis = pDrv->pDisplay;
3905
3906 size_t cbShapeSize = 0;
3907
3908 if (pvShape)
3909 {
3910 cbShapeSize = (cx + 7) / 8 * cy; /* size of the AND mask */
3911 cbShapeSize = ((cbShapeSize + 3) & ~3) + cx * 4 * cy; /* + gap + size of the XOR mask */
3912 }
3913 com::SafeArray<BYTE> shapeData(cbShapeSize);
3914
3915 if (pvShape)
3916 ::memcpy(shapeData.raw(), pvShape, cbShapeSize);
3917
3918 /* Tell the console about it */
3919 pDrv->pDisplay->mParent->onMousePointerShapeChange(fVisible, fAlpha,
3920 xHot, yHot, cx, cy, ComSafeArrayAsInParam(shapeData));
3921
3922 return VINF_SUCCESS;
3923}
3924#endif /* VBOX_WITH_HGSMI */
3925
3926/**
3927 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
3928 */
3929DECLCALLBACK(void *) Display::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
3930{
3931 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
3932 PDRVMAINDISPLAY pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3933 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
3934 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIDISPLAYCONNECTOR, &pDrv->IConnector);
3935 return NULL;
3936}
3937
3938
3939/**
3940 * Destruct a display driver instance.
3941 *
3942 * @returns VBox status.
3943 * @param pDrvIns The driver instance data.
3944 */
3945DECLCALLBACK(void) Display::drvDestruct(PPDMDRVINS pDrvIns)
3946{
3947 PDRVMAINDISPLAY pData = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3948 LogFlowFunc (("iInstance=%d\n", pDrvIns->iInstance));
3949 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
3950
3951 if (pData->pDisplay)
3952 {
3953 AutoWriteLock displayLock(pData->pDisplay COMMA_LOCKVAL_SRC_POS);
3954#ifdef VBOX_WITH_CRHGSMI
3955 pData->pDisplay->destructCrHgsmiData();
3956#endif
3957 pData->pDisplay->mpDrv = NULL;
3958 pData->pDisplay->mpVMMDev = NULL;
3959 pData->pDisplay->mLastAddress = NULL;
3960 pData->pDisplay->mLastBytesPerLine = 0;
3961 pData->pDisplay->mLastBitsPerPixel = 0,
3962 pData->pDisplay->mLastWidth = 0;
3963 pData->pDisplay->mLastHeight = 0;
3964 }
3965}
3966
3967
3968/**
3969 * Construct a display driver instance.
3970 *
3971 * @copydoc FNPDMDRVCONSTRUCT
3972 */
3973DECLCALLBACK(int) Display::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
3974{
3975 PDRVMAINDISPLAY pData = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3976 LogFlowFunc (("iInstance=%d\n", pDrvIns->iInstance));
3977 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
3978
3979 /*
3980 * Validate configuration.
3981 */
3982 if (!CFGMR3AreValuesValid(pCfg, "Object\0"))
3983 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
3984 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
3985 ("Configuration error: Not possible to attach anything to this driver!\n"),
3986 VERR_PDM_DRVINS_NO_ATTACH);
3987
3988 /*
3989 * Init Interfaces.
3990 */
3991 pDrvIns->IBase.pfnQueryInterface = Display::drvQueryInterface;
3992
3993 pData->IConnector.pfnResize = Display::displayResizeCallback;
3994 pData->IConnector.pfnUpdateRect = Display::displayUpdateCallback;
3995 pData->IConnector.pfnRefresh = Display::displayRefreshCallback;
3996 pData->IConnector.pfnReset = Display::displayResetCallback;
3997 pData->IConnector.pfnLFBModeChange = Display::displayLFBModeChangeCallback;
3998 pData->IConnector.pfnProcessAdapterData = Display::displayProcessAdapterDataCallback;
3999 pData->IConnector.pfnProcessDisplayData = Display::displayProcessDisplayDataCallback;
4000#ifdef VBOX_WITH_VIDEOHWACCEL
4001 pData->IConnector.pfnVHWACommandProcess = Display::displayVHWACommandProcess;
4002#endif
4003#ifdef VBOX_WITH_CRHGSMI
4004 pData->IConnector.pfnCrHgsmiCommandProcess = Display::displayCrHgsmiCommandProcess;
4005 pData->IConnector.pfnCrHgsmiControlProcess = Display::displayCrHgsmiControlProcess;
4006#endif
4007#ifdef VBOX_WITH_HGSMI
4008 pData->IConnector.pfnVBVAEnable = Display::displayVBVAEnable;
4009 pData->IConnector.pfnVBVADisable = Display::displayVBVADisable;
4010 pData->IConnector.pfnVBVAUpdateBegin = Display::displayVBVAUpdateBegin;
4011 pData->IConnector.pfnVBVAUpdateProcess = Display::displayVBVAUpdateProcess;
4012 pData->IConnector.pfnVBVAUpdateEnd = Display::displayVBVAUpdateEnd;
4013 pData->IConnector.pfnVBVAResize = Display::displayVBVAResize;
4014 pData->IConnector.pfnVBVAMousePointerShape = Display::displayVBVAMousePointerShape;
4015#endif
4016
4017
4018 /*
4019 * Get the IDisplayPort interface of the above driver/device.
4020 */
4021 pData->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYPORT);
4022 if (!pData->pUpPort)
4023 {
4024 AssertMsgFailed(("Configuration error: No display port interface above!\n"));
4025 return VERR_PDM_MISSING_INTERFACE_ABOVE;
4026 }
4027#if defined(VBOX_WITH_VIDEOHWACCEL) || defined(VBOX_WITH_CRHGSMI)
4028 pData->pVBVACallbacks = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYVBVACALLBACKS);
4029 if (!pData->pVBVACallbacks)
4030 {
4031 AssertMsgFailed(("Configuration error: No VBVA callback interface above!\n"));
4032 return VERR_PDM_MISSING_INTERFACE_ABOVE;
4033 }
4034#endif
4035 /*
4036 * Get the Display object pointer and update the mpDrv member.
4037 */
4038 void *pv;
4039 int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
4040 if (RT_FAILURE(rc))
4041 {
4042 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
4043 return rc;
4044 }
4045 pData->pDisplay = (Display *)pv; /** @todo Check this cast! */
4046 pData->pDisplay->mpDrv = pData;
4047
4048 /*
4049 * Update our display information according to the framebuffer
4050 */
4051 pData->pDisplay->updateDisplayData();
4052
4053 /*
4054 * Start periodic screen refreshes
4055 */
4056 pData->pUpPort->pfnSetRefreshRate(pData->pUpPort, 20);
4057
4058#ifdef VBOX_WITH_CRHGSMI
4059 pData->pDisplay->setupCrHgsmiData();
4060#endif
4061
4062 return VINF_SUCCESS;
4063}
4064
4065
4066/**
4067 * Display driver registration record.
4068 */
4069const PDMDRVREG Display::DrvReg =
4070{
4071 /* u32Version */
4072 PDM_DRVREG_VERSION,
4073 /* szName */
4074 "MainDisplay",
4075 /* szRCMod */
4076 "",
4077 /* szR0Mod */
4078 "",
4079 /* pszDescription */
4080 "Main display driver (Main as in the API).",
4081 /* fFlags */
4082 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
4083 /* fClass. */
4084 PDM_DRVREG_CLASS_DISPLAY,
4085 /* cMaxInstances */
4086 ~0,
4087 /* cbInstance */
4088 sizeof(DRVMAINDISPLAY),
4089 /* pfnConstruct */
4090 Display::drvConstruct,
4091 /* pfnDestruct */
4092 Display::drvDestruct,
4093 /* pfnRelocate */
4094 NULL,
4095 /* pfnIOCtl */
4096 NULL,
4097 /* pfnPowerOn */
4098 NULL,
4099 /* pfnReset */
4100 NULL,
4101 /* pfnSuspend */
4102 NULL,
4103 /* pfnResume */
4104 NULL,
4105 /* pfnAttach */
4106 NULL,
4107 /* pfnDetach */
4108 NULL,
4109 /* pfnPowerOff */
4110 NULL,
4111 /* pfnSoftReset */
4112 NULL,
4113 /* u32EndVersion */
4114 PDM_DRVREG_VERSION
4115};
4116/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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