VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/DisplayImpl.cpp@ 50405

Last change on this file since 50405 was 50405, checked in by vboxsync, 11 years ago

crOpenGL: include 3D data in framebuffer saved state snapshot, saved state fix

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

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