VirtualBox

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

Last change on this file since 63363 was 63244, checked in by vboxsync, 8 years ago

Main: warnings

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 152.8 KB
Line 
1/* $Id: DisplayImpl.cpp 63244 2016-08-10 10:36:09Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "DisplayImpl.h"
19#include "DisplayUtils.h"
20#include "ConsoleImpl.h"
21#include "ConsoleVRDPServer.h"
22#include "GuestImpl.h"
23#include "VMMDev.h"
24
25#include "AutoCaller.h"
26#include "Logging.h"
27
28/* generated header */
29#include "VBoxEvents.h"
30
31#include <iprt/semaphore.h>
32#include <iprt/thread.h>
33#include <iprt/asm.h>
34#include <iprt/time.h>
35#include <iprt/cpp/utils.h>
36#include <iprt/alloca.h>
37
38#include <VBox/vmm/pdmdrv.h>
39#if defined(DEBUG) || defined(VBOX_STRICT) /* for VM_ASSERT_EMT(). */
40# include <VBox/vmm/vm.h>
41#endif
42
43#ifdef VBOX_WITH_VIDEOHWACCEL
44# include <VBox/VBoxVideo.h>
45#endif
46
47#if defined(VBOX_WITH_CROGL) || defined(VBOX_WITH_CRHGSMI)
48# include <VBox/HostServices/VBoxCrOpenGLSvc.h>
49#endif
50
51#include <VBox/com/array.h>
52
53#ifdef VBOX_WITH_VPX
54# include <iprt/path.h>
55# include "VideoRec.h"
56#endif
57
58#ifdef VBOX_WITH_CROGL
59typedef enum
60{
61 CRVREC_STATE_IDLE,
62 CRVREC_STATE_SUBMITTED
63} CRVREC_STATE;
64#endif
65
66/**
67 * Display driver instance data.
68 *
69 * @implements PDMIDISPLAYCONNECTOR
70 */
71typedef struct DRVMAINDISPLAY
72{
73 /** Pointer to the display object. */
74 Display *pDisplay;
75 /** Pointer to the driver instance structure. */
76 PPDMDRVINS pDrvIns;
77 /** Pointer to the keyboard port interface of the driver/device above us. */
78 PPDMIDISPLAYPORT pUpPort;
79 /** Our display connector interface. */
80 PDMIDISPLAYCONNECTOR IConnector;
81#if defined(VBOX_WITH_VIDEOHWACCEL) || defined(VBOX_WITH_CRHGSMI)
82 /** VBVA callbacks */
83 PPDMIDISPLAYVBVACALLBACKS pVBVACallbacks;
84#endif
85} DRVMAINDISPLAY, *PDRVMAINDISPLAY;
86
87/** Converts PDMIDISPLAYCONNECTOR pointer to a DRVMAINDISPLAY pointer. */
88#define PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface) RT_FROM_MEMBER(pInterface, DRVMAINDISPLAY, IConnector)
89
90// constructor / destructor
91/////////////////////////////////////////////////////////////////////////////
92
93Display::Display()
94 : mParent(NULL), mfIsCr3DEnabled(false)
95{
96}
97
98Display::~Display()
99{
100}
101
102
103HRESULT Display::FinalConstruct()
104{
105 int rc = videoAccelConstruct(&mVideoAccelLegacy);
106 AssertRC(rc);
107
108 mfVideoAccelVRDP = false;
109 mfu32SupportedOrders = 0;
110 mcVideoAccelVRDPRefs = 0;
111
112 mfSeamlessEnabled = false;
113 mpRectVisibleRegion = NULL;
114 mcRectVisibleRegion = 0;
115
116#ifdef VBOX_WITH_CROGL
117 mfCrOglDataHidden = false;
118#endif
119
120 mpDrv = NULL;
121 mpVMMDev = NULL;
122 mfVMMDevInited = false;
123
124 rc = RTCritSectInit(&mVideoAccelLock);
125 AssertRC(rc);
126
127#ifdef VBOX_WITH_HGSMI
128 mu32UpdateVBVAFlags = 0;
129 mfVMMDevSupportsGraphics = false;
130 mfGuestVBVACapabilities = 0;
131 mfHostCursorCapabilities = 0;
132#endif
133#ifdef VBOX_WITH_VPX
134 rc = RTCritSectInit(&mVideoCaptureLock);
135 AssertRC(rc);
136
137 mpVideoRecCtx = NULL;
138 for (unsigned i = 0; i < RT_ELEMENTS(maVideoRecEnabled); i++)
139 maVideoRecEnabled[i] = true;
140#endif
141
142#ifdef VBOX_WITH_CRHGSMI
143 mhCrOglSvc = NULL;
144 rc = RTCritSectRwInit(&mCrOglLock);
145 AssertRC(rc);
146#endif
147#ifdef VBOX_WITH_CROGL
148 RT_ZERO(mCrOglCallbacks);
149 RT_ZERO(mCrOglScreenshotData);
150 mfCrOglVideoRecState = CRVREC_STATE_IDLE;
151 mCrOglScreenshotData.u32Screen = CRSCREEN_ALL;
152 mCrOglScreenshotData.pvContext = this;
153 mCrOglScreenshotData.pfnScreenshotBegin = i_displayCrVRecScreenshotBegin;
154 mCrOglScreenshotData.pfnScreenshotPerform = i_displayCrVRecScreenshotPerform;
155 mCrOglScreenshotData.pfnScreenshotEnd = i_displayCrVRecScreenshotEnd;
156#endif
157
158 return BaseFinalConstruct();
159}
160
161void Display::FinalRelease()
162{
163 uninit();
164
165#ifdef VBOX_WITH_VPX
166 if (RTCritSectIsInitialized(&mVideoCaptureLock))
167 {
168 RTCritSectDelete(&mVideoCaptureLock);
169 RT_ZERO(mVideoCaptureLock);
170 }
171#endif
172
173 videoAccelDestroy(&mVideoAccelLegacy);
174 i_saveVisibleRegion(0, NULL);
175
176 if (RTCritSectIsInitialized(&mVideoAccelLock))
177 {
178 RTCritSectDelete(&mVideoAccelLock);
179 RT_ZERO(mVideoAccelLock);
180 }
181
182#ifdef VBOX_WITH_CRHGSMI
183 if (RTCritSectRwIsInitialized(&mCrOglLock))
184 {
185 RTCritSectRwDelete(&mCrOglLock);
186 RT_ZERO(mCrOglLock);
187 }
188#endif
189 BaseFinalRelease();
190}
191
192// public initializer/uninitializer for internal purposes only
193/////////////////////////////////////////////////////////////////////////////
194
195#define kMaxSizeThumbnail 64
196
197/**
198 * Save thumbnail and screenshot of the guest screen.
199 */
200static int displayMakeThumbnail(uint8_t *pbData, uint32_t cx, uint32_t cy,
201 uint8_t **ppu8Thumbnail, uint32_t *pcbThumbnail, uint32_t *pcxThumbnail, uint32_t *pcyThumbnail)
202{
203 int rc = VINF_SUCCESS;
204
205 uint8_t *pu8Thumbnail = NULL;
206 uint32_t cbThumbnail = 0;
207 uint32_t cxThumbnail = 0;
208 uint32_t cyThumbnail = 0;
209
210 if (cx > cy)
211 {
212 cxThumbnail = kMaxSizeThumbnail;
213 cyThumbnail = (kMaxSizeThumbnail * cy) / cx;
214 }
215 else
216 {
217 cyThumbnail = kMaxSizeThumbnail;
218 cxThumbnail = (kMaxSizeThumbnail * cx) / cy;
219 }
220
221 LogRelFlowFunc(("%dx%d -> %dx%d\n", cx, cy, cxThumbnail, cyThumbnail));
222
223 cbThumbnail = cxThumbnail * 4 * cyThumbnail;
224 pu8Thumbnail = (uint8_t *)RTMemAlloc(cbThumbnail);
225
226 if (pu8Thumbnail)
227 {
228 uint8_t *dst = pu8Thumbnail;
229 uint8_t *src = pbData;
230 int dstW = cxThumbnail;
231 int dstH = cyThumbnail;
232 int srcW = cx;
233 int srcH = cy;
234 int iDeltaLine = cx * 4;
235
236 BitmapScale32(dst,
237 dstW, dstH,
238 src,
239 iDeltaLine,
240 srcW, srcH);
241
242 *ppu8Thumbnail = pu8Thumbnail;
243 *pcbThumbnail = cbThumbnail;
244 *pcxThumbnail = cxThumbnail;
245 *pcyThumbnail = cyThumbnail;
246 }
247 else
248 {
249 rc = VERR_NO_MEMORY;
250 }
251
252 return rc;
253}
254
255#ifdef VBOX_WITH_CROGL
256typedef struct
257{
258 CRVBOXHGCMTAKESCREENSHOT Base;
259
260 /* 32bpp small RGB image. */
261 uint8_t *pu8Thumbnail;
262 uint32_t cbThumbnail;
263 uint32_t cxThumbnail;
264 uint32_t cyThumbnail;
265
266 /* PNG screenshot. */
267 uint8_t *pu8PNG;
268 uint32_t cbPNG;
269 uint32_t cxPNG;
270 uint32_t cyPNG;
271} VBOX_DISPLAY_SAVESCREENSHOT_DATA;
272
273static DECLCALLBACK(void) displaySaveScreenshotReport(void *pvCtx, uint32_t uScreen,
274 uint32_t x, uint32_t y, uint32_t uBitsPerPixel,
275 uint32_t uBytesPerLine, uint32_t uGuestWidth, uint32_t uGuestHeight,
276 uint8_t *pu8BufferAddress, uint64_t u64Timestamp)
277{
278 RT_NOREF(uScreen, x, y, uBitsPerPixel,uBytesPerLine, u64Timestamp);
279 VBOX_DISPLAY_SAVESCREENSHOT_DATA *pData = (VBOX_DISPLAY_SAVESCREENSHOT_DATA*)pvCtx;
280 displayMakeThumbnail(pu8BufferAddress, uGuestWidth, uGuestHeight, &pData->pu8Thumbnail,
281 &pData->cbThumbnail, &pData->cxThumbnail, &pData->cyThumbnail);
282 int rc = DisplayMakePNG(pu8BufferAddress, uGuestWidth, uGuestHeight, &pData->pu8PNG,
283 &pData->cbPNG, &pData->cxPNG, &pData->cyPNG, 1);
284 if (RT_FAILURE(rc))
285 {
286 AssertMsgFailed(("DisplayMakePNG failed (rc=%Rrc)\n", rc));
287 if (pData->pu8PNG)
288 {
289 RTMemFree(pData->pu8PNG);
290 pData->pu8PNG = NULL;
291 }
292 pData->cbPNG = 0;
293 pData->cxPNG = 0;
294 pData->cyPNG = 0;
295 }
296}
297#endif
298
299DECLCALLBACK(void) Display::i_displaySSMSaveScreenshot(PSSMHANDLE pSSM, void *pvUser)
300{
301 Display *that = static_cast<Display*>(pvUser);
302
303 /* 32bpp small RGB image. */
304 uint8_t *pu8Thumbnail = NULL;
305 uint32_t cbThumbnail = 0;
306 uint32_t cxThumbnail = 0;
307 uint32_t cyThumbnail = 0;
308
309 /* PNG screenshot. */
310 uint8_t *pu8PNG = NULL;
311 uint32_t cbPNG = 0;
312 uint32_t cxPNG = 0;
313 uint32_t cyPNG = 0;
314
315 Console::SafeVMPtr ptrVM(that->mParent);
316 if (ptrVM.isOk())
317 {
318#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
319 BOOL f3DSnapshot = FALSE;
320 if ( that->mfIsCr3DEnabled
321 && that->mCrOglCallbacks.pfnHasData
322 && that->mCrOglCallbacks.pfnHasData())
323 {
324 VMMDev *pVMMDev = that->mParent->i_getVMMDev();
325 if (pVMMDev)
326 {
327 VBOX_DISPLAY_SAVESCREENSHOT_DATA *pScreenshot;
328 pScreenshot = (VBOX_DISPLAY_SAVESCREENSHOT_DATA*)RTMemAllocZ(sizeof(*pScreenshot));
329 if (pScreenshot)
330 {
331 /* screen id or CRSCREEN_ALL to specify all enabled */
332 pScreenshot->Base.u32Screen = 0;
333 pScreenshot->Base.u32Width = 0;
334 pScreenshot->Base.u32Height = 0;
335 pScreenshot->Base.u32Pitch = 0;
336 pScreenshot->Base.pvBuffer = NULL;
337 pScreenshot->Base.pvContext = pScreenshot;
338 pScreenshot->Base.pfnScreenshotBegin = NULL;
339 pScreenshot->Base.pfnScreenshotPerform = displaySaveScreenshotReport;
340 pScreenshot->Base.pfnScreenshotEnd = NULL;
341
342 VBOXCRCMDCTL_HGCM data;
343 data.Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
344 data.Hdr.u32Function = SHCRGL_HOST_FN_TAKE_SCREENSHOT;
345
346 data.aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
347 data.aParms[0].u.pointer.addr = &pScreenshot->Base;
348 data.aParms[0].u.pointer.size = sizeof(pScreenshot->Base);
349
350 int rc = that->i_crCtlSubmitSync(&data.Hdr, sizeof(data));
351 if (RT_SUCCESS(rc))
352 {
353 if (pScreenshot->pu8PNG)
354 {
355 pu8Thumbnail = pScreenshot->pu8Thumbnail;
356 cbThumbnail = pScreenshot->cbThumbnail;
357 cxThumbnail = pScreenshot->cxThumbnail;
358 cyThumbnail = pScreenshot->cyThumbnail;
359
360 /* PNG screenshot. */
361 pu8PNG = pScreenshot->pu8PNG;
362 cbPNG = pScreenshot->cbPNG;
363 cxPNG = pScreenshot->cxPNG;
364 cyPNG = pScreenshot->cyPNG;
365 f3DSnapshot = TRUE;
366 }
367 else
368 AssertMsgFailed(("no png\n"));
369 }
370 else
371 AssertMsgFailed(("SHCRGL_HOST_FN_TAKE_SCREENSHOT failed (rc=%Rrc)\n", rc));
372
373
374 RTMemFree(pScreenshot);
375 }
376 }
377 }
378
379 if (!f3DSnapshot)
380#endif
381 {
382 /* Query RGB bitmap. */
383 /* SSM code is executed on EMT(0), therefore no need to use VMR3ReqCallWait. */
384 uint8_t *pbData = NULL;
385 size_t cbData = 0;
386 uint32_t cx = 0;
387 uint32_t cy = 0;
388 bool fFreeMem = false;
389 int rc = Display::i_displayTakeScreenshotEMT(that, VBOX_VIDEO_PRIMARY_SCREEN, &pbData, &cbData, &cx, &cy, &fFreeMem);
390
391 /*
392 * It is possible that success is returned but everything is 0 or NULL.
393 * (no display attached if a VM is running with VBoxHeadless on OSE for example)
394 */
395 if (RT_SUCCESS(rc) && pbData)
396 {
397 Assert(cx && cy);
398
399 /* Prepare a small thumbnail and a PNG screenshot. */
400 displayMakeThumbnail(pbData, cx, cy, &pu8Thumbnail, &cbThumbnail, &cxThumbnail, &cyThumbnail);
401 rc = DisplayMakePNG(pbData, cx, cy, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 1);
402 if (RT_FAILURE(rc))
403 {
404 if (pu8PNG)
405 {
406 RTMemFree(pu8PNG);
407 pu8PNG = NULL;
408 }
409 cbPNG = 0;
410 cxPNG = 0;
411 cyPNG = 0;
412 }
413
414 if (fFreeMem)
415 RTMemFree(pbData);
416 else
417 that->mpDrv->pUpPort->pfnFreeScreenshot(that->mpDrv->pUpPort, pbData);
418 }
419 }
420 }
421 else
422 {
423 LogFunc(("Failed to get VM pointer 0x%x\n", ptrVM.rc()));
424 }
425
426 /* Regardless of rc, save what is available:
427 * Data format:
428 * uint32_t cBlocks;
429 * [blocks]
430 *
431 * Each block is:
432 * uint32_t cbBlock; if 0 - no 'block data'.
433 * uint32_t typeOfBlock; 0 - 32bpp RGB bitmap, 1 - PNG, ignored if 'cbBlock' is 0.
434 * [block data]
435 *
436 * Block data for bitmap and PNG:
437 * uint32_t cx;
438 * uint32_t cy;
439 * [image data]
440 */
441 SSMR3PutU32(pSSM, 2); /* Write thumbnail and PNG screenshot. */
442
443 /* First block. */
444 SSMR3PutU32(pSSM, (uint32_t)(cbThumbnail + 2 * sizeof(uint32_t)));
445 SSMR3PutU32(pSSM, 0); /* Block type: thumbnail. */
446
447 if (cbThumbnail)
448 {
449 SSMR3PutU32(pSSM, cxThumbnail);
450 SSMR3PutU32(pSSM, cyThumbnail);
451 SSMR3PutMem(pSSM, pu8Thumbnail, cbThumbnail);
452 }
453
454 /* Second block. */
455 SSMR3PutU32(pSSM, (uint32_t)(cbPNG + 2 * sizeof(uint32_t)));
456 SSMR3PutU32(pSSM, 1); /* Block type: png. */
457
458 if (cbPNG)
459 {
460 SSMR3PutU32(pSSM, cxPNG);
461 SSMR3PutU32(pSSM, cyPNG);
462 SSMR3PutMem(pSSM, pu8PNG, cbPNG);
463 }
464
465 RTMemFree(pu8PNG);
466 RTMemFree(pu8Thumbnail);
467}
468
469DECLCALLBACK(int)
470Display::i_displaySSMLoadScreenshot(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass)
471{
472 RT_NOREF(pvUser);
473 if (uVersion != sSSMDisplayScreenshotVer)
474 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
475 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
476
477 /* Skip data. */
478 uint32_t cBlocks;
479 int rc = SSMR3GetU32(pSSM, &cBlocks);
480 AssertRCReturn(rc, rc);
481
482 for (uint32_t i = 0; i < cBlocks; i++)
483 {
484 uint32_t cbBlock;
485 rc = SSMR3GetU32(pSSM, &cbBlock);
486 AssertRCBreak(rc);
487
488 uint32_t typeOfBlock;
489 rc = SSMR3GetU32(pSSM, &typeOfBlock);
490 AssertRCBreak(rc);
491
492 LogRelFlowFunc(("[%d] type %d, size %d bytes\n", i, typeOfBlock, cbBlock));
493
494 /* Note: displaySSMSaveScreenshot writes size of a block = 8 and
495 * do not write any data if the image size was 0.
496 * @todo Fix and increase saved state version.
497 */
498 if (cbBlock > 2 * sizeof(uint32_t))
499 {
500 rc = SSMR3Skip(pSSM, cbBlock);
501 AssertRCBreak(rc);
502 }
503 }
504
505 return rc;
506}
507
508/**
509 * Save/Load some important guest state
510 */
511DECLCALLBACK(void)
512Display::i_displaySSMSave(PSSMHANDLE pSSM, void *pvUser)
513{
514 Display *that = static_cast<Display*>(pvUser);
515
516 SSMR3PutU32(pSSM, that->mcMonitors);
517 for (unsigned i = 0; i < that->mcMonitors; i++)
518 {
519 SSMR3PutU32(pSSM, that->maFramebuffers[i].u32Offset);
520 SSMR3PutU32(pSSM, that->maFramebuffers[i].u32MaxFramebufferSize);
521 SSMR3PutU32(pSSM, that->maFramebuffers[i].u32InformationSize);
522 SSMR3PutU32(pSSM, that->maFramebuffers[i].w);
523 SSMR3PutU32(pSSM, that->maFramebuffers[i].h);
524 SSMR3PutS32(pSSM, that->maFramebuffers[i].xOrigin);
525 SSMR3PutS32(pSSM, that->maFramebuffers[i].yOrigin);
526 SSMR3PutU32(pSSM, that->maFramebuffers[i].flags);
527 }
528 SSMR3PutS32(pSSM, that->xInputMappingOrigin);
529 SSMR3PutS32(pSSM, that->yInputMappingOrigin);
530 SSMR3PutU32(pSSM, that->cxInputMapping);
531 SSMR3PutU32(pSSM, that->cyInputMapping);
532 SSMR3PutU32(pSSM, that->mfGuestVBVACapabilities);
533 SSMR3PutU32(pSSM, that->mfHostCursorCapabilities);
534}
535
536DECLCALLBACK(int)
537Display::i_displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass)
538{
539 Display *that = static_cast<Display*>(pvUser);
540
541 if ( uVersion != sSSMDisplayVer
542 && uVersion != sSSMDisplayVer2
543 && uVersion != sSSMDisplayVer3
544 && uVersion != sSSMDisplayVer4
545 && uVersion != sSSMDisplayVer5)
546 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
547 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
548
549 uint32_t cMonitors;
550 int rc = SSMR3GetU32(pSSM, &cMonitors);
551 AssertRCReturn(rc, rc);
552 if (cMonitors != that->mcMonitors)
553 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Number of monitors changed (%d->%d)!"), cMonitors, that->mcMonitors);
554
555 for (uint32_t i = 0; i < cMonitors; i++)
556 {
557 SSMR3GetU32(pSSM, &that->maFramebuffers[i].u32Offset);
558 SSMR3GetU32(pSSM, &that->maFramebuffers[i].u32MaxFramebufferSize);
559 SSMR3GetU32(pSSM, &that->maFramebuffers[i].u32InformationSize);
560 if ( uVersion == sSSMDisplayVer2
561 || uVersion == sSSMDisplayVer3
562 || uVersion == sSSMDisplayVer4
563 || uVersion == sSSMDisplayVer5)
564 {
565 uint32_t w;
566 uint32_t h;
567 SSMR3GetU32(pSSM, &w);
568 SSMR3GetU32(pSSM, &h);
569 that->maFramebuffers[i].w = w;
570 that->maFramebuffers[i].h = h;
571 }
572 if ( uVersion == sSSMDisplayVer3
573 || uVersion == sSSMDisplayVer4
574 || uVersion == sSSMDisplayVer5)
575 {
576 int32_t xOrigin;
577 int32_t yOrigin;
578 uint32_t flags;
579 SSMR3GetS32(pSSM, &xOrigin);
580 SSMR3GetS32(pSSM, &yOrigin);
581 SSMR3GetU32(pSSM, &flags);
582 that->maFramebuffers[i].xOrigin = xOrigin;
583 that->maFramebuffers[i].yOrigin = yOrigin;
584 that->maFramebuffers[i].flags = (uint16_t)flags;
585 that->maFramebuffers[i].fDisabled = (that->maFramebuffers[i].flags & VBVA_SCREEN_F_DISABLED) != 0;
586 }
587 }
588 if ( uVersion == sSSMDisplayVer4
589 || uVersion == sSSMDisplayVer5)
590 {
591 SSMR3GetS32(pSSM, &that->xInputMappingOrigin);
592 SSMR3GetS32(pSSM, &that->yInputMappingOrigin);
593 SSMR3GetU32(pSSM, &that->cxInputMapping);
594 SSMR3GetU32(pSSM, &that->cyInputMapping);
595 }
596 if (uVersion == sSSMDisplayVer5)
597 {
598 SSMR3GetU32(pSSM, &that->mfGuestVBVACapabilities);
599 SSMR3GetU32(pSSM, &that->mfHostCursorCapabilities);
600 }
601
602 return VINF_SUCCESS;
603}
604
605/**
606 * Initializes the display object.
607 *
608 * @returns COM result indicator
609 * @param parent handle of our parent object
610 * @param qemuConsoleData address of common console data structure
611 */
612HRESULT Display::init(Console *aParent)
613{
614 ComAssertRet(aParent, E_INVALIDARG);
615 /* Enclose the state transition NotReady->InInit->Ready */
616 AutoInitSpan autoInitSpan(this);
617 AssertReturn(autoInitSpan.isOk(), E_FAIL);
618
619 unconst(mParent) = aParent;
620
621 mfSourceBitmapEnabled = true;
622 fVGAResizing = false;
623
624 ULONG ul;
625 mParent->i_machine()->COMGETTER(MonitorCount)(&ul);
626 mcMonitors = ul;
627 xInputMappingOrigin = 0;
628 yInputMappingOrigin = 0;
629 cxInputMapping = 0;
630 cyInputMapping = 0;
631
632 for (ul = 0; ul < mcMonitors; ul++)
633 {
634 maFramebuffers[ul].u32Offset = 0;
635 maFramebuffers[ul].u32MaxFramebufferSize = 0;
636 maFramebuffers[ul].u32InformationSize = 0;
637
638 maFramebuffers[ul].pFramebuffer = NULL;
639 /* All secondary monitors are disabled at startup. */
640 maFramebuffers[ul].fDisabled = ul > 0;
641
642 maFramebuffers[ul].u32Caps = 0;
643
644 maFramebuffers[ul].updateImage.pu8Address = NULL;
645 maFramebuffers[ul].updateImage.cbLine = 0;
646
647 maFramebuffers[ul].xOrigin = 0;
648 maFramebuffers[ul].yOrigin = 0;
649
650 maFramebuffers[ul].w = 0;
651 maFramebuffers[ul].h = 0;
652
653 maFramebuffers[ul].flags = maFramebuffers[ul].fDisabled? VBVA_SCREEN_F_DISABLED: 0;
654
655 maFramebuffers[ul].u16BitsPerPixel = 0;
656 maFramebuffers[ul].pu8FramebufferVRAM = NULL;
657 maFramebuffers[ul].u32LineSize = 0;
658
659 maFramebuffers[ul].pHostEvents = NULL;
660
661 maFramebuffers[ul].fDefaultFormat = false;
662
663#ifdef VBOX_WITH_HGSMI
664 maFramebuffers[ul].fVBVAEnabled = false;
665 maFramebuffers[ul].fVBVAForceResize = false;
666 maFramebuffers[ul].fRenderThreadMode = false;
667 maFramebuffers[ul].pVBVAHostFlags = NULL;
668#endif /* VBOX_WITH_HGSMI */
669#ifdef VBOX_WITH_CROGL
670 RT_ZERO(maFramebuffers[ul].pendingViewportInfo);
671#endif
672 }
673
674 {
675 // register listener for state change events
676 ComPtr<IEventSource> es;
677 mParent->COMGETTER(EventSource)(es.asOutParam());
678 com::SafeArray<VBoxEventType_T> eventTypes;
679 eventTypes.push_back(VBoxEventType_OnStateChanged);
680 es->RegisterListener(this, ComSafeArrayAsInParam(eventTypes), true);
681 }
682
683 /* Cache the 3D settings. */
684 BOOL fIs3DEnabled = FALSE;
685 mParent->i_machine()->COMGETTER(Accelerate3DEnabled)(&fIs3DEnabled);
686 GraphicsControllerType_T enmGpuType = (GraphicsControllerType_T)GraphicsControllerType_VBoxVGA;
687 mParent->i_machine()->COMGETTER(GraphicsControllerType)(&enmGpuType);
688 mfIsCr3DEnabled = fIs3DEnabled && enmGpuType == GraphicsControllerType_VBoxVGA;
689
690 /* Confirm a successful initialization */
691 autoInitSpan.setSucceeded();
692
693 return S_OK;
694}
695
696/**
697 * Uninitializes the instance and sets the ready flag to FALSE.
698 * Called either from FinalRelease() or by the parent when it gets destroyed.
699 */
700void Display::uninit()
701{
702 LogRelFlowFunc(("this=%p\n", this));
703
704 /* Enclose the state transition Ready->InUninit->NotReady */
705 AutoUninitSpan autoUninitSpan(this);
706 if (autoUninitSpan.uninitDone())
707 return;
708
709 unsigned uScreenId;
710 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
711 {
712 maFramebuffers[uScreenId].pSourceBitmap.setNull();
713 maFramebuffers[uScreenId].updateImage.pSourceBitmap.setNull();
714 maFramebuffers[uScreenId].updateImage.pu8Address = NULL;
715 maFramebuffers[uScreenId].updateImage.cbLine = 0;
716 maFramebuffers[uScreenId].pFramebuffer.setNull();
717#ifdef VBOX_WITH_VPX
718 maFramebuffers[uScreenId].videoCapture.pSourceBitmap.setNull();
719#endif
720 }
721
722 if (mParent)
723 {
724 ComPtr<IEventSource> es;
725 mParent->COMGETTER(EventSource)(es.asOutParam());
726 es->UnregisterListener(this);
727 }
728
729 unconst(mParent) = NULL;
730
731 if (mpDrv)
732 mpDrv->pDisplay = NULL;
733
734 mpDrv = NULL;
735 mpVMMDev = NULL;
736 mfVMMDevInited = true;
737}
738
739/**
740 * Register the SSM methods. Called by the power up thread to be able to
741 * pass pVM
742 */
743int Display::i_registerSSM(PUVM pUVM)
744{
745 /* Version 2 adds width and height of the framebuffer; version 3 adds
746 * the framebuffer offset in the virtual desktop and the framebuffer flags;
747 * version 4 adds guest to host input event mapping and version 5 adds
748 * guest VBVA and host cursor capabilities.
749 */
750 int rc = SSMR3RegisterExternal(pUVM, "DisplayData", 0, sSSMDisplayVer5,
751 mcMonitors * sizeof(uint32_t) * 8 + sizeof(uint32_t),
752 NULL, NULL, NULL,
753 NULL, i_displaySSMSave, NULL,
754 NULL, i_displaySSMLoad, NULL, this);
755 AssertRCReturn(rc, rc);
756
757 /*
758 * Register loaders for old saved states where iInstance was
759 * 3 * sizeof(uint32_t *) due to a code mistake.
760 */
761 rc = SSMR3RegisterExternal(pUVM, "DisplayData", 12 /*uInstance*/, sSSMDisplayVer, 0 /*cbGuess*/,
762 NULL, NULL, NULL,
763 NULL, NULL, NULL,
764 NULL, i_displaySSMLoad, NULL, this);
765 AssertRCReturn(rc, rc);
766
767 rc = SSMR3RegisterExternal(pUVM, "DisplayData", 24 /*uInstance*/, sSSMDisplayVer, 0 /*cbGuess*/,
768 NULL, NULL, NULL,
769 NULL, NULL, NULL,
770 NULL, i_displaySSMLoad, NULL, this);
771 AssertRCReturn(rc, rc);
772
773 /* uInstance is an arbitrary value greater than 1024. Such a value will ensure a quick seek in saved state file. */
774 rc = SSMR3RegisterExternal(pUVM, "DisplayScreenshot", 1100 /*uInstance*/, sSSMDisplayScreenshotVer, 0 /*cbGuess*/,
775 NULL, NULL, NULL,
776 NULL, i_displaySSMSaveScreenshot, NULL,
777 NULL, i_displaySSMLoadScreenshot, NULL, this);
778
779 AssertRCReturn(rc, rc);
780
781 return VINF_SUCCESS;
782}
783
784DECLCALLBACK(void) Display::i_displayCrCmdFree(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd, int rc, void *pvCompletion)
785{
786 RT_NOREF(pCmd, cbCmd, rc);
787 Assert(pvCompletion);
788 RTMemFree(pvCompletion);
789}
790
791#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
792int Display::i_crOglWindowsShow(bool fShow)
793{
794 if (!mfCrOglDataHidden == !!fShow)
795 return VINF_SUCCESS;
796
797 if (!mhCrOglSvc)
798 {
799 /* No 3D or the VMSVGA3d kind. */
800 Assert(!mfIsCr3DEnabled);
801 return VERR_INVALID_STATE;
802 }
803
804 VMMDev *pVMMDev = mParent->i_getVMMDev();
805 if (!pVMMDev)
806 {
807 AssertMsgFailed(("no vmmdev\n"));
808 return VERR_INVALID_STATE;
809 }
810
811 VBOXCRCMDCTL_HGCM *pData = (VBOXCRCMDCTL_HGCM*)RTMemAlloc(sizeof(VBOXCRCMDCTL_HGCM));
812 if (!pData)
813 {
814 AssertMsgFailed(("RTMemAlloc failed\n"));
815 return VERR_NO_MEMORY;
816 }
817
818 pData->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
819 pData->Hdr.u32Function = SHCRGL_HOST_FN_WINDOWS_SHOW;
820
821 pData->aParms[0].type = VBOX_HGCM_SVC_PARM_32BIT;
822 pData->aParms[0].u.uint32 = (uint32_t)fShow;
823
824 int rc = i_crCtlSubmit(&pData->Hdr, sizeof(*pData), i_displayCrCmdFree, pData);
825 if (RT_SUCCESS(rc))
826 mfCrOglDataHidden = !fShow;
827 else
828 {
829 AssertMsgFailed(("crCtlSubmit failed (rc=%Rrc)\n", rc));
830 RTMemFree(pData);
831 }
832
833 return rc;
834}
835#endif
836
837
838// public methods only for internal purposes
839/////////////////////////////////////////////////////////////////////////////
840
841int Display::i_notifyCroglResize(const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM)
842{
843 RT_NOREF(pView);
844#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
845 if (maFramebuffers[pScreen->u32ViewIndex].fRenderThreadMode)
846 return VINF_SUCCESS; /* nop it */
847
848 if (mfIsCr3DEnabled)
849 {
850 int rc = VERR_INVALID_STATE;
851 if (mhCrOglSvc)
852 {
853 VMMDev *pVMMDev = mParent->i_getVMMDev();
854 if (pVMMDev)
855 {
856 VBOXCRCMDCTL_HGCM *pCtl;
857 pCtl = (VBOXCRCMDCTL_HGCM*)RTMemAlloc(sizeof(CRVBOXHGCMDEVRESIZE) + sizeof(VBOXCRCMDCTL_HGCM));
858 if (pCtl)
859 {
860 CRVBOXHGCMDEVRESIZE *pData = (CRVBOXHGCMDEVRESIZE*)(pCtl+1);
861 pData->Screen = *pScreen;
862 pData->pvVRAM = pvVRAM;
863
864 pCtl->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
865 pCtl->Hdr.u32Function = SHCRGL_HOST_FN_DEV_RESIZE;
866 pCtl->aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
867 pCtl->aParms[0].u.pointer.addr = pData;
868 pCtl->aParms[0].u.pointer.size = sizeof(*pData);
869
870 rc = i_crCtlSubmit(&pCtl->Hdr, sizeof(*pCtl), i_displayCrCmdFree, pCtl);
871 if (RT_FAILURE(rc))
872 {
873 AssertMsgFailed(("crCtlSubmit failed (rc=%Rrc)\n", rc));
874 RTMemFree(pCtl);
875 }
876 }
877 else
878 rc = VERR_NO_MEMORY;
879 }
880 }
881
882 return rc;
883 }
884#endif /* #if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL) */
885 return VINF_SUCCESS;
886}
887
888/**
889 * Handles display resize event.
890 *
891 * @param w New display width
892 * @param h New display height
893 *
894 * @thread EMT
895 */
896int Display::i_handleDisplayResize(unsigned uScreenId, uint32_t bpp, void *pvVRAM,
897 uint32_t cbLine, uint32_t w, uint32_t h, uint16_t flags)
898{
899 LogRel(("Display::handleDisplayResize: uScreenId=%d pvVRAM=%p w=%d h=%d bpp=%d cbLine=0x%X flags=0x%X\n", uScreenId,
900 pvVRAM, w, h, bpp, cbLine, flags));
901
902 if (uScreenId >= mcMonitors)
903 return VINF_SUCCESS;
904
905 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
906
907 /* Reset the update mode. */
908 pFBInfo->updateImage.pSourceBitmap.setNull();
909 pFBInfo->updateImage.pu8Address = NULL;
910 pFBInfo->updateImage.cbLine = 0;
911
912 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
913 {
914 pFBInfo->w = w;
915 pFBInfo->h = h;
916
917 pFBInfo->u16BitsPerPixel = (uint16_t)bpp;
918 pFBInfo->pu8FramebufferVRAM = (uint8_t *)pvVRAM;
919 pFBInfo->u32LineSize = cbLine;
920 pFBInfo->flags = flags;
921 }
922
923 /* Guest screen image will be invalid during resize, make sure that it is not updated. */
924 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
925 {
926 if (mpDrv)
927 {
928 mpDrv->pUpPort->pfnSetRenderVRAM(mpDrv->pUpPort, false);
929
930 mpDrv->IConnector.pbData = NULL;
931 mpDrv->IConnector.cbScanline = 0;
932 mpDrv->IConnector.cBits = 32; /* DevVGA does not work with cBits == 0. */
933 mpDrv->IConnector.cx = 0;
934 mpDrv->IConnector.cy = 0;
935 }
936 }
937
938 maFramebuffers[uScreenId].pSourceBitmap.setNull();
939
940 if (!maFramebuffers[uScreenId].pFramebuffer.isNull())
941 {
942 HRESULT hr = maFramebuffers[uScreenId].pFramebuffer->NotifyChange(uScreenId, 0, 0, w, h); /* @todo origin */
943 LogFunc(("NotifyChange hr %08X\n", hr));
944 NOREF(hr);
945 }
946
947 bool fUpdateImage = RT_BOOL(pFBInfo->u32Caps & FramebufferCapabilities_UpdateImage);
948 if (fUpdateImage && !pFBInfo->pFramebuffer.isNull())
949 {
950 ComPtr<IDisplaySourceBitmap> pSourceBitmap;
951 HRESULT hr = QuerySourceBitmap(uScreenId, pSourceBitmap.asOutParam());
952 if (SUCCEEDED(hr))
953 {
954 BYTE *pAddress = NULL;
955 ULONG ulWidth = 0;
956 ULONG ulHeight = 0;
957 ULONG ulBitsPerPixel = 0;
958 ULONG ulBytesPerLine = 0;
959 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
960
961 hr = pSourceBitmap->QueryBitmapInfo(&pAddress,
962 &ulWidth,
963 &ulHeight,
964 &ulBitsPerPixel,
965 &ulBytesPerLine,
966 &bitmapFormat);
967 if (SUCCEEDED(hr))
968 {
969 pFBInfo->updateImage.pSourceBitmap = pSourceBitmap;
970 pFBInfo->updateImage.pu8Address = pAddress;
971 pFBInfo->updateImage.cbLine = ulBytesPerLine;
972 }
973 }
974 }
975
976 /* Inform the VRDP server about the change of display parameters. */
977 LogRelFlowFunc(("Calling VRDP\n"));
978 mParent->i_consoleVRDPServer()->SendResize();
979
980 /* And re-send the seamless rectangles if necessary. */
981 if (mfSeamlessEnabled)
982 i_handleSetVisibleRegion(mcRectVisibleRegion, mpRectVisibleRegion);
983
984#ifdef VBOX_WITH_VPX
985 videoCaptureScreenChanged(uScreenId);
986#endif
987
988 LogRelFlowFunc(("[%d]: default format %d\n", uScreenId, pFBInfo->fDefaultFormat));
989
990 return VINF_SUCCESS;
991}
992
993static void i_checkCoordBounds(int *px, int *py, int *pw, int *ph, int cx, int cy)
994{
995 /* Correct negative x and y coordinates. */
996 if (*px < 0)
997 {
998 *px += *pw; /* Compute xRight which is also the new width. */
999
1000 *pw = (*px < 0)? 0: *px;
1001
1002 *px = 0;
1003 }
1004
1005 if (*py < 0)
1006 {
1007 *py += *ph; /* Compute xBottom, which is also the new height. */
1008
1009 *ph = (*py < 0)? 0: *py;
1010
1011 *py = 0;
1012 }
1013
1014 /* Also check if coords are greater than the display resolution. */
1015 if (*px + *pw > cx)
1016 {
1017 *pw = cx > *px? cx - *px: 0;
1018 }
1019
1020 if (*py + *ph > cy)
1021 {
1022 *ph = cy > *py? cy - *py: 0;
1023 }
1024}
1025
1026void Display::i_handleDisplayUpdate(unsigned uScreenId, int x, int y, int w, int h)
1027{
1028 /*
1029 * Always runs under either VBVA lock or, for HGSMI, DevVGA lock.
1030 * Safe to use VBVA vars and take the framebuffer lock.
1031 */
1032
1033#ifdef DEBUG_sunlover
1034 LogFlowFunc(("[%d] %d,%d %dx%d\n",
1035 uScreenId, x, y, w, h));
1036#endif /* DEBUG_sunlover */
1037
1038 /* No updates for a disabled guest screen. */
1039 if (maFramebuffers[uScreenId].fDisabled)
1040 return;
1041
1042 /* No updates for a blank guest screen. */
1043 /** @note Disabled for now, as the GUI does not update the picture when we
1044 * first blank. */
1045 /* if (maFramebuffers[uScreenId].flags & VBVA_SCREEN_F_BLANK)
1046 return; */
1047
1048 i_checkCoordBounds(&x, &y, &w, &h, maFramebuffers[uScreenId].w,
1049 maFramebuffers[uScreenId].h);
1050
1051 IFramebuffer *pFramebuffer = maFramebuffers[uScreenId].pFramebuffer;
1052 if (pFramebuffer != NULL)
1053 {
1054 if (w != 0 && h != 0)
1055 {
1056 bool fUpdateImage = RT_BOOL(maFramebuffers[uScreenId].u32Caps & FramebufferCapabilities_UpdateImage);
1057 if (RT_LIKELY(!fUpdateImage))
1058 {
1059 pFramebuffer->NotifyUpdate(x, y, w, h);
1060 }
1061 else
1062 {
1063 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1064
1065 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1066
1067 if (!pFBInfo->updateImage.pSourceBitmap.isNull())
1068 {
1069 Assert(pFBInfo->updateImage.pu8Address);
1070
1071 size_t cbData = w * h * 4;
1072 com::SafeArray<BYTE> image(cbData);
1073
1074 uint8_t *pu8Dst = image.raw();
1075 const uint8_t *pu8Src = pFBInfo->updateImage.pu8Address + pFBInfo->updateImage.cbLine * y + x * 4;
1076
1077 int i;
1078 for (i = y; i < y + h; ++i)
1079 {
1080 memcpy(pu8Dst, pu8Src, w * 4);
1081 pu8Dst += w * 4;
1082 pu8Src += pFBInfo->updateImage.cbLine;
1083 }
1084
1085 pFramebuffer->NotifyUpdateImage(x, y, w, h, ComSafeArrayAsInParam(image));
1086 }
1087 }
1088 }
1089 }
1090
1091#ifndef VBOX_WITH_HGSMI
1092 if (!mVideoAccelLegacy.fVideoAccelEnabled)
1093 {
1094#else
1095 if (!mVideoAccelLegacy.fVideoAccelEnabled && !maFramebuffers[uScreenId].fVBVAEnabled)
1096 {
1097#endif /* VBOX_WITH_HGSMI */
1098 /* When VBVA is enabled, the VRDP server is informed
1099 * either in VideoAccelFlush or displayVBVAUpdateProcess.
1100 * Inform the server here only if VBVA is disabled.
1101 */
1102 mParent->i_consoleVRDPServer()->SendUpdateBitmap(uScreenId, x, y, w, h);
1103 }
1104}
1105
1106void Display::i_updateGuestGraphicsFacility(void)
1107{
1108 Guest* pGuest = mParent->i_getGuest();
1109 AssertPtrReturnVoid(pGuest);
1110 /* The following is from GuestImpl.cpp. */
1111 /** @todo A nit: The timestamp is wrong on saved state restore. Would be better
1112 * to move the graphics and seamless capability -> facility translation to
1113 * VMMDev so this could be saved. */
1114 RTTIMESPEC TimeSpecTS;
1115 RTTimeNow(&TimeSpecTS);
1116
1117 if ( mfVMMDevSupportsGraphics
1118 || (mfGuestVBVACapabilities & VBVACAPS_VIDEO_MODE_HINTS) != 0)
1119 pGuest->i_setAdditionsStatus(VBoxGuestFacilityType_Graphics,
1120 VBoxGuestFacilityStatus_Active,
1121 0 /*fFlags*/, &TimeSpecTS);
1122 else
1123 pGuest->i_setAdditionsStatus(VBoxGuestFacilityType_Graphics,
1124 VBoxGuestFacilityStatus_Inactive,
1125 0 /*fFlags*/, &TimeSpecTS);
1126}
1127
1128void Display::i_handleUpdateVMMDevSupportsGraphics(bool fSupportsGraphics)
1129{
1130 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1131 if (mfVMMDevSupportsGraphics == fSupportsGraphics)
1132 return;
1133 mfVMMDevSupportsGraphics = fSupportsGraphics;
1134 i_updateGuestGraphicsFacility();
1135 /* The VMMDev interface notifies the console. */
1136}
1137
1138void Display::i_handleUpdateGuestVBVACapabilities(uint32_t fNewCapabilities)
1139{
1140 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1141 bool fNotify = (fNewCapabilities & VBVACAPS_VIDEO_MODE_HINTS) != (mfGuestVBVACapabilities & VBVACAPS_VIDEO_MODE_HINTS);
1142
1143 mfGuestVBVACapabilities = fNewCapabilities;
1144 if (!fNotify)
1145 return;
1146 i_updateGuestGraphicsFacility();
1147 /* Tell the console about it */
1148 mParent->i_onAdditionsStateChange();
1149}
1150
1151void Display::i_handleUpdateVBVAInputMapping(int32_t xOrigin, int32_t yOrigin, uint32_t cx, uint32_t cy)
1152{
1153 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1154
1155 xInputMappingOrigin = xOrigin;
1156 yInputMappingOrigin = yOrigin;
1157 cxInputMapping = cx;
1158 cyInputMapping = cy;
1159
1160 /* Re-send the seamless rectangles if necessary. */
1161 if (mfSeamlessEnabled)
1162 i_handleSetVisibleRegion(mcRectVisibleRegion, mpRectVisibleRegion);
1163}
1164
1165/**
1166 * Returns the upper left and lower right corners of the virtual framebuffer.
1167 * The lower right is "exclusive" (i.e. first pixel beyond the framebuffer),
1168 * and the origin is (0, 0), not (1, 1) like the GUI returns.
1169 */
1170void Display::i_getFramebufferDimensions(int32_t *px1, int32_t *py1,
1171 int32_t *px2, int32_t *py2)
1172{
1173 int32_t x1 = 0, y1 = 0, x2 = 0, y2 = 0;
1174 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1175
1176 AssertPtrReturnVoid(px1);
1177 AssertPtrReturnVoid(py1);
1178 AssertPtrReturnVoid(px2);
1179 AssertPtrReturnVoid(py2);
1180 LogRelFlowFunc(("\n"));
1181
1182 if (!mpDrv)
1183 return;
1184 /* If VBVA is not in use then this flag will not be set and this
1185 * will still work as it should. */
1186 if (!maFramebuffers[0].fDisabled)
1187 {
1188 x1 = (int32_t)maFramebuffers[0].xOrigin;
1189 y1 = (int32_t)maFramebuffers[0].yOrigin;
1190 x2 = (int32_t)maFramebuffers[0].w + (int32_t)maFramebuffers[0].xOrigin;
1191 y2 = (int32_t)maFramebuffers[0].h + (int32_t)maFramebuffers[0].yOrigin;
1192 }
1193 if (cxInputMapping && cyInputMapping)
1194 {
1195 x1 = xInputMappingOrigin;
1196 y1 = yInputMappingOrigin;
1197 x2 = xInputMappingOrigin + cxInputMapping;
1198 y2 = yInputMappingOrigin + cyInputMapping;
1199 }
1200 else
1201 for (unsigned i = 1; i < mcMonitors; ++i)
1202 {
1203 if (!maFramebuffers[i].fDisabled)
1204 {
1205 x1 = RT_MIN(x1, maFramebuffers[i].xOrigin);
1206 y1 = RT_MIN(y1, maFramebuffers[i].yOrigin);
1207 x2 = RT_MAX(x2, maFramebuffers[i].xOrigin + (int32_t)maFramebuffers[i].w);
1208 y2 = RT_MAX(y2, maFramebuffers[i].yOrigin + (int32_t)maFramebuffers[i].h);
1209 }
1210 }
1211 *px1 = x1;
1212 *py1 = y1;
1213 *px2 = x2;
1214 *py2 = y2;
1215}
1216
1217HRESULT Display::i_reportHostCursorCapabilities(uint32_t fCapabilitiesAdded, uint32_t fCapabilitiesRemoved)
1218{
1219 /* Do we need this to access mParent? I presume that the safe VM pointer
1220 * ensures that mpDrv will remain valid. */
1221 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1222 uint32_t fHostCursorCapabilities = (mfHostCursorCapabilities | fCapabilitiesAdded)
1223 & ~fCapabilitiesRemoved;
1224
1225 Console::SafeVMPtr ptrVM(mParent);
1226 if (!ptrVM.isOk())
1227 return ptrVM.rc();
1228 if (mfHostCursorCapabilities == fHostCursorCapabilities)
1229 return S_OK;
1230 CHECK_CONSOLE_DRV(mpDrv);
1231 alock.release(); /* Release before calling up for lock order reasons. */
1232 mpDrv->pUpPort->pfnReportHostCursorCapabilities(mpDrv->pUpPort, fCapabilitiesAdded, fCapabilitiesRemoved);
1233 mfHostCursorCapabilities = fHostCursorCapabilities;
1234 return S_OK;
1235}
1236
1237HRESULT Display::i_reportHostCursorPosition(int32_t x, int32_t y)
1238{
1239 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1240 uint32_t xAdj = (uint32_t)RT_MAX(x - xInputMappingOrigin, 0);
1241 uint32_t yAdj = (uint32_t)RT_MAX(y - yInputMappingOrigin, 0);
1242 xAdj = RT_MIN(xAdj, cxInputMapping);
1243 yAdj = RT_MIN(yAdj, cyInputMapping);
1244
1245 Console::SafeVMPtr ptrVM(mParent);
1246 if (!ptrVM.isOk())
1247 return ptrVM.rc();
1248 CHECK_CONSOLE_DRV(mpDrv);
1249 alock.release(); /* Release before calling up for lock order reasons. */
1250 mpDrv->pUpPort->pfnReportHostCursorPosition(mpDrv->pUpPort, xAdj, yAdj);
1251 return S_OK;
1252}
1253
1254static bool displayIntersectRect(RTRECT *prectResult,
1255 const RTRECT *prect1,
1256 const RTRECT *prect2)
1257{
1258 /* Initialize result to an empty record. */
1259 memset(prectResult, 0, sizeof(RTRECT));
1260
1261 int xLeftResult = RT_MAX(prect1->xLeft, prect2->xLeft);
1262 int xRightResult = RT_MIN(prect1->xRight, prect2->xRight);
1263
1264 if (xLeftResult < xRightResult)
1265 {
1266 /* There is intersection by X. */
1267
1268 int yTopResult = RT_MAX(prect1->yTop, prect2->yTop);
1269 int yBottomResult = RT_MIN(prect1->yBottom, prect2->yBottom);
1270
1271 if (yTopResult < yBottomResult)
1272 {
1273 /* There is intersection by Y. */
1274
1275 prectResult->xLeft = xLeftResult;
1276 prectResult->yTop = yTopResult;
1277 prectResult->xRight = xRightResult;
1278 prectResult->yBottom = yBottomResult;
1279
1280 return true;
1281 }
1282 }
1283
1284 return false;
1285}
1286
1287int Display::i_saveVisibleRegion(uint32_t cRect, PRTRECT pRect)
1288{
1289 RTRECT *pRectVisibleRegion = NULL;
1290
1291 if (pRect == mpRectVisibleRegion)
1292 return VINF_SUCCESS;
1293 if (cRect != 0)
1294 {
1295 pRectVisibleRegion = (RTRECT *)RTMemAlloc(cRect * sizeof(RTRECT));
1296 if (!pRectVisibleRegion)
1297 {
1298 return VERR_NO_MEMORY;
1299 }
1300 memcpy(pRectVisibleRegion, pRect, cRect * sizeof(RTRECT));
1301 }
1302 if (mpRectVisibleRegion)
1303 RTMemFree(mpRectVisibleRegion);
1304 mcRectVisibleRegion = cRect;
1305 mpRectVisibleRegion = pRectVisibleRegion;
1306 return VINF_SUCCESS;
1307}
1308
1309int Display::i_handleSetVisibleRegion(uint32_t cRect, PRTRECT pRect)
1310{
1311 RTRECT *pVisibleRegion = (RTRECT *)RTMemTmpAlloc( RT_MAX(cRect, 1)
1312 * sizeof(RTRECT));
1313 LogRel2(("%s: cRect=%u\n", __PRETTY_FUNCTION__, cRect));
1314 if (!pVisibleRegion)
1315 {
1316 return VERR_NO_TMP_MEMORY;
1317 }
1318 int rc = i_saveVisibleRegion(cRect, pRect);
1319 if (RT_FAILURE(rc))
1320 {
1321 RTMemTmpFree(pVisibleRegion);
1322 return rc;
1323 }
1324
1325 unsigned uScreenId;
1326 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
1327 {
1328 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1329
1330 if ( !pFBInfo->pFramebuffer.isNull()
1331 && RT_BOOL(pFBInfo->u32Caps & FramebufferCapabilities_VisibleRegion))
1332 {
1333 /* Prepare a new array of rectangles which intersect with the framebuffer.
1334 */
1335 RTRECT rectFramebuffer;
1336 rectFramebuffer.xLeft = pFBInfo->xOrigin - xInputMappingOrigin;
1337 rectFramebuffer.yTop = pFBInfo->yOrigin - yInputMappingOrigin;
1338 rectFramebuffer.xRight = rectFramebuffer.xLeft + pFBInfo->w;
1339 rectFramebuffer.yBottom = rectFramebuffer.yTop + pFBInfo->h;
1340
1341 uint32_t cRectVisibleRegion = 0;
1342
1343 uint32_t i;
1344 for (i = 0; i < cRect; i++)
1345 {
1346 if (displayIntersectRect(&pVisibleRegion[cRectVisibleRegion], &pRect[i], &rectFramebuffer))
1347 {
1348 pVisibleRegion[cRectVisibleRegion].xLeft -= rectFramebuffer.xLeft;
1349 pVisibleRegion[cRectVisibleRegion].yTop -= rectFramebuffer.yTop;
1350 pVisibleRegion[cRectVisibleRegion].xRight -= rectFramebuffer.xLeft;
1351 pVisibleRegion[cRectVisibleRegion].yBottom -= rectFramebuffer.yTop;
1352
1353 cRectVisibleRegion++;
1354 }
1355 }
1356 pFBInfo->pFramebuffer->SetVisibleRegion((BYTE *)pVisibleRegion, cRectVisibleRegion);
1357 }
1358 }
1359
1360#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
1361 VMMDev *vmmDev = mParent->i_getVMMDev();
1362 if (mfIsCr3DEnabled && vmmDev)
1363 {
1364 if (mhCrOglSvc)
1365 {
1366 VBOXCRCMDCTL_HGCM *pCtl;
1367 pCtl = (VBOXCRCMDCTL_HGCM*)RTMemAlloc(RT_MAX(cRect, 1) * sizeof(RTRECT) + sizeof(VBOXCRCMDCTL_HGCM));
1368 if (pCtl)
1369 {
1370 RTRECT *pRectsCopy = (RTRECT*)(pCtl+1);
1371 memcpy(pRectsCopy, pRect, cRect * sizeof(RTRECT));
1372
1373 pCtl->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
1374 pCtl->Hdr.u32Function = SHCRGL_HOST_FN_SET_VISIBLE_REGION;
1375
1376 pCtl->aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
1377 pCtl->aParms[0].u.pointer.addr = pRectsCopy;
1378 pCtl->aParms[0].u.pointer.size = (uint32_t)(cRect * sizeof(RTRECT));
1379
1380 rc = i_crCtlSubmit(&pCtl->Hdr, sizeof(*pCtl), i_displayCrCmdFree, pCtl);
1381 if (!RT_SUCCESS(rc))
1382 {
1383 AssertMsgFailed(("crCtlSubmit failed (rc=%Rrc)\n", rc));
1384 RTMemFree(pCtl);
1385 }
1386 }
1387 else
1388 AssertMsgFailed(("failed to allocate rects memory\n"));
1389 }
1390 else
1391 AssertMsgFailed(("mhCrOglSvc is NULL\n"));
1392 }
1393#endif
1394
1395 RTMemTmpFree(pVisibleRegion);
1396
1397 return VINF_SUCCESS;
1398}
1399
1400int Display::i_handleQueryVisibleRegion(uint32_t *pcRects, PRTRECT paRects)
1401{
1402 /// @todo Currently not used by the guest and is not implemented in
1403 /// framebuffers. Remove?
1404 RT_NOREF(pcRects, paRects);
1405 return VERR_NOT_SUPPORTED;
1406}
1407
1408#ifdef VBOX_WITH_HGSMI
1409static void vbvaSetMemoryFlagsHGSMI(unsigned uScreenId,
1410 uint32_t fu32SupportedOrders,
1411 bool fVideoAccelVRDP,
1412 DISPLAYFBINFO *pFBInfo)
1413{
1414 LogRelFlowFunc(("HGSMI[%d]: %p\n", uScreenId, pFBInfo->pVBVAHostFlags));
1415
1416 if (pFBInfo->pVBVAHostFlags)
1417 {
1418 uint32_t fu32HostEvents = VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
1419
1420 if (pFBInfo->fVBVAEnabled)
1421 {
1422 fu32HostEvents |= VBVA_F_MODE_ENABLED;
1423
1424 if (fVideoAccelVRDP)
1425 {
1426 fu32HostEvents |= VBVA_F_MODE_VRDP;
1427 }
1428 }
1429
1430 ASMAtomicWriteU32(&pFBInfo->pVBVAHostFlags->u32HostEvents, fu32HostEvents);
1431 ASMAtomicWriteU32(&pFBInfo->pVBVAHostFlags->u32SupportedOrders, fu32SupportedOrders);
1432
1433 LogRelFlowFunc((" fu32HostEvents = 0x%08X, fu32SupportedOrders = 0x%08X\n", fu32HostEvents, fu32SupportedOrders));
1434 }
1435}
1436
1437static void vbvaSetMemoryFlagsAllHGSMI(uint32_t fu32SupportedOrders,
1438 bool fVideoAccelVRDP,
1439 DISPLAYFBINFO *paFBInfos,
1440 unsigned cFBInfos)
1441{
1442 unsigned uScreenId;
1443
1444 for (uScreenId = 0; uScreenId < cFBInfos; uScreenId++)
1445 {
1446 vbvaSetMemoryFlagsHGSMI(uScreenId, fu32SupportedOrders, fVideoAccelVRDP, &paFBInfos[uScreenId]);
1447 }
1448}
1449#endif /* VBOX_WITH_HGSMI */
1450
1451int Display::VideoAccelEnableVMMDev(bool fEnable, VBVAMEMORY *pVbvaMemory)
1452{
1453 LogFlowFunc(("%d %p\n", fEnable, pVbvaMemory));
1454 int rc = videoAccelEnterVMMDev(&mVideoAccelLegacy);
1455 if (RT_SUCCESS(rc))
1456 {
1457 rc = i_VideoAccelEnable(fEnable, pVbvaMemory, mpDrv->pUpPort);
1458 videoAccelLeaveVMMDev(&mVideoAccelLegacy);
1459 }
1460 LogFlowFunc(("leave %Rrc\n", rc));
1461 return rc;
1462}
1463
1464int Display::VideoAccelEnableVGA(bool fEnable, VBVAMEMORY *pVbvaMemory)
1465{
1466 LogFlowFunc(("%d %p\n", fEnable, pVbvaMemory));
1467 int rc = videoAccelEnterVGA(&mVideoAccelLegacy);
1468 if (RT_SUCCESS(rc))
1469 {
1470 rc = i_VideoAccelEnable(fEnable, pVbvaMemory, mpDrv->pUpPort);
1471 videoAccelLeaveVGA(&mVideoAccelLegacy);
1472 }
1473 LogFlowFunc(("leave %Rrc\n", rc));
1474 return rc;
1475}
1476
1477void Display::VideoAccelFlushVMMDev(void)
1478{
1479 LogFlowFunc(("enter\n"));
1480 int rc = videoAccelEnterVMMDev(&mVideoAccelLegacy);
1481 if (RT_SUCCESS(rc))
1482 {
1483 i_VideoAccelFlush(mpDrv->pUpPort);
1484 videoAccelLeaveVMMDev(&mVideoAccelLegacy);
1485 }
1486 LogFlowFunc(("leave\n"));
1487}
1488
1489/* Called always by one VRDP server thread. Can be thread-unsafe.
1490 */
1491void Display::i_VideoAccelVRDP(bool fEnable)
1492{
1493 LogRelFlowFunc(("fEnable = %d\n", fEnable));
1494
1495 VIDEOACCEL *pVideoAccel = &mVideoAccelLegacy;
1496
1497 int c = fEnable?
1498 ASMAtomicIncS32(&mcVideoAccelVRDPRefs):
1499 ASMAtomicDecS32(&mcVideoAccelVRDPRefs);
1500
1501 Assert (c >= 0);
1502
1503 /* This can run concurrently with Display videoaccel state change. */
1504 RTCritSectEnter(&mVideoAccelLock);
1505
1506 if (c == 0)
1507 {
1508 /* The last client has disconnected, and the accel can be
1509 * disabled.
1510 */
1511 Assert(fEnable == false);
1512
1513 mfVideoAccelVRDP = false;
1514 mfu32SupportedOrders = 0;
1515
1516 i_vbvaSetMemoryFlags(pVideoAccel->pVbvaMemory, pVideoAccel->fVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders,
1517 maFramebuffers, mcMonitors);
1518#ifdef VBOX_WITH_HGSMI
1519 /* Here is VRDP-IN thread. Process the request in vbvaUpdateBegin under DevVGA lock on an EMT. */
1520 ASMAtomicIncU32(&mu32UpdateVBVAFlags);
1521#endif /* VBOX_WITH_HGSMI */
1522
1523 LogRel(("VBVA: VRDP acceleration has been disabled.\n"));
1524 }
1525 else if ( c == 1
1526 && !mfVideoAccelVRDP)
1527 {
1528 /* The first client has connected. Enable the accel.
1529 */
1530 Assert(fEnable == true);
1531
1532 mfVideoAccelVRDP = true;
1533 /* Supporting all orders. */
1534 mfu32SupportedOrders = UINT32_MAX;
1535
1536 i_vbvaSetMemoryFlags(pVideoAccel->pVbvaMemory, pVideoAccel->fVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders,
1537 maFramebuffers, mcMonitors);
1538#ifdef VBOX_WITH_HGSMI
1539 /* Here is VRDP-IN thread. Process the request in vbvaUpdateBegin under DevVGA lock on an EMT. */
1540 ASMAtomicIncU32(&mu32UpdateVBVAFlags);
1541#endif /* VBOX_WITH_HGSMI */
1542
1543 LogRel(("VBVA: VRDP acceleration has been requested.\n"));
1544 }
1545 else
1546 {
1547 /* A client is connected or disconnected but there is no change in the
1548 * accel state. It remains enabled.
1549 */
1550 Assert(mfVideoAccelVRDP == true);
1551 }
1552
1553 RTCritSectLeave(&mVideoAccelLock);
1554}
1555
1556void Display::i_notifyPowerDown(void)
1557{
1558 LogRelFlowFunc(("\n"));
1559
1560 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1561
1562 /* Source bitmaps are not available anymore. */
1563 mfSourceBitmapEnabled = false;
1564
1565 alock.release();
1566
1567 /* Resize all displays to tell framebuffers to forget current source bitmap. */
1568 unsigned uScreenId = mcMonitors;
1569 while (uScreenId > 0)
1570 {
1571 --uScreenId;
1572
1573 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1574 if (!pFBInfo->fDisabled)
1575 {
1576 i_handleDisplayResize(uScreenId, 32,
1577 pFBInfo->pu8FramebufferVRAM,
1578 pFBInfo->u32LineSize,
1579 pFBInfo->w,
1580 pFBInfo->h,
1581 pFBInfo->flags);
1582 }
1583 }
1584}
1585
1586// Wrapped IDisplay methods
1587/////////////////////////////////////////////////////////////////////////////
1588HRESULT Display::getScreenResolution(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel,
1589 LONG *aXOrigin, LONG *aYOrigin, GuestMonitorStatus_T *aGuestMonitorStatus)
1590{
1591 LogRelFlowFunc(("aScreenId=%RU32\n", aScreenId));
1592
1593 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1594
1595 if (aScreenId >= mcMonitors)
1596 return E_INVALIDARG;
1597
1598 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
1599
1600 GuestMonitorStatus_T guestMonitorStatus = GuestMonitorStatus_Enabled;
1601 if (pFBInfo->flags & VBVA_SCREEN_F_DISABLED)
1602 guestMonitorStatus = GuestMonitorStatus_Disabled;
1603
1604 if (aWidth)
1605 *aWidth = pFBInfo->w;
1606 if (aHeight)
1607 *aHeight = pFBInfo->h;
1608 if (aBitsPerPixel)
1609 *aBitsPerPixel = pFBInfo->u16BitsPerPixel;
1610 if (aXOrigin)
1611 *aXOrigin = pFBInfo->xOrigin;
1612 if (aYOrigin)
1613 *aYOrigin = pFBInfo->yOrigin;
1614 if (aGuestMonitorStatus)
1615 *aGuestMonitorStatus = guestMonitorStatus;
1616
1617 return S_OK;
1618}
1619
1620
1621HRESULT Display::attachFramebuffer(ULONG aScreenId, const ComPtr<IFramebuffer> &aFramebuffer, com::Guid &aId)
1622{
1623 LogRelFlowFunc(("aScreenId = %d\n", aScreenId));
1624
1625 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1626
1627 if (aScreenId >= mcMonitors)
1628 return setError(E_INVALIDARG, tr("AttachFramebuffer: Invalid screen %d (total %d)"),
1629 aScreenId, mcMonitors);
1630
1631 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
1632 if (!pFBInfo->pFramebuffer.isNull())
1633 return setError(E_FAIL, tr("AttachFramebuffer: Framebuffer already attached to %d"),
1634 aScreenId);
1635
1636 pFBInfo->pFramebuffer = aFramebuffer;
1637 pFBInfo->framebufferId.create();
1638 aId = pFBInfo->framebufferId;
1639
1640 SafeArray<FramebufferCapabilities_T> caps;
1641 pFBInfo->pFramebuffer->COMGETTER(Capabilities)(ComSafeArrayAsOutParam(caps));
1642 pFBInfo->u32Caps = 0;
1643 size_t i;
1644 for (i = 0; i < caps.size(); ++i)
1645 pFBInfo->u32Caps |= caps[i];
1646
1647 alock.release();
1648
1649 /* The driver might not have been constructed yet */
1650 if (mpDrv)
1651 {
1652 /* Setup the new framebuffer. */
1653 i_handleDisplayResize(aScreenId, pFBInfo->u16BitsPerPixel,
1654 pFBInfo->pu8FramebufferVRAM,
1655 pFBInfo->u32LineSize,
1656 pFBInfo->w,
1657 pFBInfo->h,
1658 pFBInfo->flags);
1659 }
1660
1661 Console::SafeVMPtrQuiet ptrVM(mParent);
1662 if (ptrVM.isOk())
1663 {
1664#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
1665 if (mfIsCr3DEnabled)
1666 {
1667 VBOXCRCMDCTL_HGCM data;
1668 RT_ZERO(data);
1669 data.Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
1670 data.Hdr.u32Function = SHCRGL_HOST_FN_SCREEN_CHANGED;
1671
1672 data.aParms[0].type = VBOX_HGCM_SVC_PARM_32BIT;
1673 data.aParms[0].u.uint32 = aScreenId;
1674
1675 int vrc = i_crCtlSubmitSync(&data.Hdr, sizeof(data));
1676 AssertRC(vrc);
1677 }
1678#endif /* defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL) */
1679
1680 VMR3ReqCallNoWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_InvalidateAndUpdateEMT,
1681 3, this, aScreenId, false);
1682 }
1683
1684 LogRelFlowFunc(("Attached to %d %RTuuid\n", aScreenId, aId.raw()));
1685 return S_OK;
1686}
1687
1688HRESULT Display::detachFramebuffer(ULONG aScreenId, const com::Guid &aId)
1689{
1690 LogRelFlowFunc(("aScreenId = %d %RTuuid\n", aScreenId, aId.raw()));
1691
1692 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1693
1694 if (aScreenId >= mcMonitors)
1695 return setError(E_INVALIDARG, tr("DetachFramebuffer: Invalid screen %d (total %d)"),
1696 aScreenId, mcMonitors);
1697
1698 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
1699
1700 if (pFBInfo->framebufferId != aId)
1701 {
1702 LogRelFlowFunc(("Invalid framebuffer aScreenId = %d, attached %p\n", aScreenId, pFBInfo->framebufferId.raw()));
1703 return setError(E_FAIL, tr("DetachFramebuffer: Invalid framebuffer object"));
1704 }
1705
1706 pFBInfo->pFramebuffer.setNull();
1707 pFBInfo->framebufferId.clear();
1708
1709 alock.release();
1710
1711#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
1712 Console::SafeVMPtrQuiet ptrVM(mParent);
1713 if (ptrVM.isOk())
1714 {
1715 if (mfIsCr3DEnabled)
1716 {
1717 VBOXCRCMDCTL_HGCM data;
1718 RT_ZERO(data);
1719 data.Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
1720 data.Hdr.u32Function = SHCRGL_HOST_FN_SCREEN_CHANGED;
1721
1722 data.aParms[0].type = VBOX_HGCM_SVC_PARM_32BIT;
1723 data.aParms[0].u.uint32 = aScreenId;
1724
1725 int vrc = i_crCtlSubmitSync(&data.Hdr, sizeof(data));
1726 AssertRC(vrc);
1727 }
1728 }
1729#endif /* defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL) */
1730
1731 return S_OK;
1732}
1733
1734HRESULT Display::queryFramebuffer(ULONG aScreenId, ComPtr<IFramebuffer> &aFramebuffer)
1735{
1736 LogRelFlowFunc(("aScreenId = %d\n", aScreenId));
1737
1738 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1739
1740 if (aScreenId >= mcMonitors)
1741 return setError(E_INVALIDARG, tr("QueryFramebuffer: Invalid screen %d (total %d)"),
1742 aScreenId, mcMonitors);
1743
1744 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
1745
1746 pFBInfo->pFramebuffer.queryInterfaceTo(aFramebuffer.asOutParam());
1747
1748 return S_OK;
1749}
1750
1751HRESULT Display::setVideoModeHint(ULONG aDisplay, BOOL aEnabled,
1752 BOOL aChangeOrigin, LONG aOriginX, LONG aOriginY,
1753 ULONG aWidth, ULONG aHeight, ULONG aBitsPerPixel)
1754{
1755 if (aWidth == 0 || aHeight == 0 || aBitsPerPixel == 0)
1756 {
1757 /* Some of parameters must not change. Query current mode. */
1758 ULONG ulWidth = 0;
1759 ULONG ulHeight = 0;
1760 ULONG ulBitsPerPixel = 0;
1761 HRESULT hr = getScreenResolution(aDisplay, &ulWidth, &ulHeight, &ulBitsPerPixel, NULL, NULL, NULL);
1762 if (FAILED(hr))
1763 return hr;
1764
1765 /* Assign current values to not changing parameters. */
1766 if (aWidth == 0)
1767 aWidth = ulWidth;
1768 if (aHeight == 0)
1769 aHeight = ulHeight;
1770 if (aBitsPerPixel == 0)
1771 aBitsPerPixel = ulBitsPerPixel;
1772 }
1773
1774 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1775
1776 if (aDisplay >= mcMonitors)
1777 return E_INVALIDARG;
1778
1779 CHECK_CONSOLE_DRV(mpDrv);
1780
1781 /*
1782 * It is up to the guest to decide whether the hint is
1783 * valid. Therefore don't do any VRAM sanity checks here.
1784 */
1785
1786 /* Have to release the lock because the pfnRequestDisplayChange
1787 * will call EMT. */
1788 alock.release();
1789
1790 /* We always send the hint to the graphics card in case the guest enables
1791 * support later. For now we notify exactly when support is enabled. */
1792 mpDrv->pUpPort->pfnSendModeHint(mpDrv->pUpPort, aWidth, aHeight,
1793 aBitsPerPixel, aDisplay,
1794 aChangeOrigin ? aOriginX : ~0,
1795 aChangeOrigin ? aOriginY : ~0,
1796 RT_BOOL(aEnabled),
1797 mfGuestVBVACapabilities
1798 & VBVACAPS_VIDEO_MODE_HINTS);
1799 if ( mfGuestVBVACapabilities & VBVACAPS_VIDEO_MODE_HINTS
1800 && !(mfGuestVBVACapabilities & VBVACAPS_IRQ))
1801 {
1802 mParent->i_sendACPIMonitorHotPlugEvent();
1803 }
1804
1805 /* We currently never suppress the VMMDev hint if the guest has requested
1806 * it. Specifically the video graphics driver may not be responsible for
1807 * screen positioning in the guest virtual desktop, and the component
1808 * responsible may want to get the hint from VMMDev. */
1809 VMMDev *pVMMDev = mParent->i_getVMMDev();
1810 if (pVMMDev)
1811 {
1812 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
1813 if (pVMMDevPort)
1814 pVMMDevPort->pfnRequestDisplayChange(pVMMDevPort, aWidth, aHeight, aBitsPerPixel,
1815 aDisplay, aOriginX, aOriginY,
1816 RT_BOOL(aEnabled), RT_BOOL(aChangeOrigin));
1817 }
1818 return S_OK;
1819}
1820
1821HRESULT Display::setSeamlessMode(BOOL enabled)
1822{
1823 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1824
1825 /* Have to release the lock because the pfnRequestSeamlessChange will call EMT. */
1826 alock.release();
1827
1828 VMMDev *pVMMDev = mParent->i_getVMMDev();
1829 if (pVMMDev)
1830 {
1831 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
1832 if (pVMMDevPort)
1833 pVMMDevPort->pfnRequestSeamlessChange(pVMMDevPort, !!enabled);
1834 }
1835 mfSeamlessEnabled = RT_BOOL(enabled);
1836
1837#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
1838 if (!enabled)
1839 {
1840 VMMDev *vmmDev = mParent->i_getVMMDev();
1841 if (mfIsCr3DEnabled && vmmDev)
1842 {
1843 VBOXCRCMDCTL_HGCM *pData = (VBOXCRCMDCTL_HGCM*)RTMemAlloc(sizeof(VBOXCRCMDCTL_HGCM));
1844 if (!pData)
1845 {
1846 AssertMsgFailed(("RTMemAlloc failed\n"));
1847 return VERR_NO_MEMORY;
1848 }
1849
1850 pData->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
1851 pData->Hdr.u32Function = SHCRGL_HOST_FN_SET_VISIBLE_REGION;
1852
1853 pData->aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
1854 pData->aParms[0].u.pointer.addr = NULL;
1855 pData->aParms[0].u.pointer.size = 0; /* <- means null rects, NULL pRects address and 0 rects means "disable" */
1856
1857 int rc = i_crCtlSubmit(&pData->Hdr, sizeof(*pData), i_displayCrCmdFree, pData);
1858 if (!RT_SUCCESS(rc))
1859 {
1860 AssertMsgFailed(("crCtlSubmit failed (rc=%Rrc)\n", rc));
1861 RTMemFree(pData);
1862 }
1863 }
1864 }
1865#endif
1866 return S_OK;
1867}
1868
1869#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
1870BOOL Display::i_displayCheckTakeScreenshotCrOgl(Display *pDisplay, ULONG aScreenId, uint8_t *pbData,
1871 uint32_t u32Width, uint32_t u32Height)
1872{
1873 if ( pDisplay->mfIsCr3DEnabled
1874 && pDisplay->mCrOglCallbacks.pfnHasData
1875 && pDisplay->mCrOglCallbacks.pfnHasData())
1876 {
1877 VMMDev *pVMMDev = pDisplay->mParent->i_getVMMDev();
1878 if (pVMMDev)
1879 {
1880 CRVBOXHGCMTAKESCREENSHOT *pScreenshot = (CRVBOXHGCMTAKESCREENSHOT *)RTMemAlloc(sizeof(*pScreenshot));
1881 if (pScreenshot)
1882 {
1883 /* screen id or CRSCREEN_ALL to specify all enabled */
1884 pScreenshot->u32Screen = aScreenId;
1885 pScreenshot->u32Width = u32Width;
1886 pScreenshot->u32Height = u32Height;
1887 pScreenshot->u32Pitch = u32Width * 4;
1888 pScreenshot->pvBuffer = pbData;
1889 pScreenshot->pvContext = NULL;
1890 pScreenshot->pfnScreenshotBegin = NULL;
1891 pScreenshot->pfnScreenshotPerform = NULL;
1892 pScreenshot->pfnScreenshotEnd = NULL;
1893
1894 VBOXCRCMDCTL_HGCM data;
1895 data.Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
1896 data.Hdr.u32Function = SHCRGL_HOST_FN_TAKE_SCREENSHOT;
1897
1898 data.aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
1899 data.aParms[0].u.pointer.addr = pScreenshot;
1900 data.aParms[0].u.pointer.size = sizeof(*pScreenshot);
1901
1902 int rc = pDisplay->i_crCtlSubmitSync(&data.Hdr, sizeof(data));
1903
1904 RTMemFree(pScreenshot);
1905
1906 if (RT_SUCCESS(rc))
1907 return TRUE;
1908 AssertMsgFailed(("failed to get screenshot data from crOgl (rc=%Rrc)\n", rc));
1909 /* fall back to the non-3d mechanism */
1910 }
1911 }
1912 }
1913 return FALSE;
1914}
1915#endif
1916
1917/* static */
1918int Display::i_displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppbData, size_t *pcbData,
1919 uint32_t *pcx, uint32_t *pcy, bool *pfMemFree)
1920{
1921 int rc;
1922 if ( aScreenId == VBOX_VIDEO_PRIMARY_SCREEN
1923 && pDisplay->maFramebuffers[aScreenId].fVBVAEnabled == false) /* A non-VBVA mode. */
1924 {
1925 if (pDisplay->mpDrv)
1926 {
1927 rc = pDisplay->mpDrv->pUpPort->pfnTakeScreenshot(pDisplay->mpDrv->pUpPort, ppbData, pcbData, pcx, pcy);
1928 *pfMemFree = false;
1929 }
1930 else
1931 {
1932 /* No image. */
1933 *ppbData = NULL;
1934 *pcbData = 0;
1935 *pcx = 0;
1936 *pcy = 0;
1937 *pfMemFree = true;
1938 rc = VINF_SUCCESS;
1939 }
1940 }
1941 else if (aScreenId < pDisplay->mcMonitors)
1942 {
1943 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[aScreenId];
1944
1945 uint32_t width = pFBInfo->w;
1946 uint32_t height = pFBInfo->h;
1947
1948 /* Allocate 32 bit per pixel bitmap. */
1949 size_t cbRequired = width * 4 * height;
1950
1951 if (cbRequired)
1952 {
1953 uint8_t *pbDst = (uint8_t *)RTMemAlloc(cbRequired);
1954 if (pbDst != NULL)
1955 {
1956 if (pFBInfo->flags & VBVA_SCREEN_F_ACTIVE)
1957 {
1958 /* Copy guest VRAM to the allocated 32bpp buffer. */
1959 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
1960 int32_t xSrc = 0;
1961 int32_t ySrc = 0;
1962 uint32_t u32SrcWidth = width;
1963 uint32_t u32SrcHeight = height;
1964 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
1965 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
1966
1967 int32_t xDst = 0;
1968 int32_t yDst = 0;
1969 uint32_t u32DstWidth = u32SrcWidth;
1970 uint32_t u32DstHeight = u32SrcHeight;
1971 uint32_t u32DstLineSize = u32DstWidth * 4;
1972 uint32_t u32DstBitsPerPixel = 32;
1973
1974 rc = pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
1975 width, height,
1976 pu8Src,
1977 xSrc, ySrc,
1978 u32SrcWidth, u32SrcHeight,
1979 u32SrcLineSize, u32SrcBitsPerPixel,
1980 pbDst,
1981 xDst, yDst,
1982 u32DstWidth, u32DstHeight,
1983 u32DstLineSize, u32DstBitsPerPixel);
1984 }
1985 else
1986 {
1987 memset(pbDst, 0, cbRequired);
1988 rc = VINF_SUCCESS;
1989 }
1990 if (RT_SUCCESS(rc))
1991 {
1992 *ppbData = pbDst;
1993 *pcbData = cbRequired;
1994 *pcx = width;
1995 *pcy = height;
1996 *pfMemFree = true;
1997 }
1998 else
1999 {
2000 RTMemFree(pbDst);
2001
2002 /* CopyRect can fail if VBVA was paused in VGA device, retry using the generic method. */
2003 if ( rc == VERR_INVALID_STATE
2004 && aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2005 {
2006 rc = pDisplay->mpDrv->pUpPort->pfnTakeScreenshot(pDisplay->mpDrv->pUpPort, ppbData, pcbData, pcx, pcy);
2007 *pfMemFree = false;
2008 }
2009 }
2010 }
2011 else
2012 rc = VERR_NO_MEMORY;
2013 }
2014 else
2015 {
2016 /* No image. */
2017 *ppbData = NULL;
2018 *pcbData = 0;
2019 *pcx = 0;
2020 *pcy = 0;
2021 *pfMemFree = true;
2022 rc = VINF_SUCCESS;
2023 }
2024 }
2025 else
2026 rc = VERR_INVALID_PARAMETER;
2027 return rc;
2028}
2029
2030static int i_displayTakeScreenshot(PUVM pUVM, Display *pDisplay, struct DRVMAINDISPLAY *pDrv, ULONG aScreenId,
2031 BYTE *address, ULONG width, ULONG height)
2032{
2033#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
2034 /*
2035 * CrOgl screenshot hook/hack.
2036 */
2037 if (Display::i_displayCheckTakeScreenshotCrOgl(pDisplay, aScreenId, (uint8_t *)address, width, height))
2038 return VINF_SUCCESS;
2039#endif
2040
2041 uint8_t *pbData = NULL;
2042 size_t cbData = 0;
2043 uint32_t cx = 0;
2044 uint32_t cy = 0;
2045 bool fFreeMem = false;
2046 int vrc = VINF_SUCCESS;
2047
2048 int cRetries = 5;
2049 while (cRetries-- > 0)
2050 {
2051 /* Note! Not sure if the priority call is such a good idea here, but
2052 it would be nice to have an accurate screenshot for the bug
2053 report if the VM deadlocks. */
2054 vrc = VMR3ReqPriorityCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)Display::i_displayTakeScreenshotEMT, 7,
2055 pDisplay, aScreenId, &pbData, &cbData, &cx, &cy, &fFreeMem);
2056 if (vrc != VERR_TRY_AGAIN)
2057 {
2058 break;
2059 }
2060
2061 RTThreadSleep(10);
2062 }
2063
2064 if (RT_SUCCESS(vrc) && pbData)
2065 {
2066 if (cx == width && cy == height)
2067 {
2068 /* No scaling required. */
2069 memcpy(address, pbData, cbData);
2070 }
2071 else
2072 {
2073 /* Scale. */
2074 LogRelFlowFunc(("SCALE: %dx%d -> %dx%d\n", cx, cy, width, height));
2075
2076 uint8_t *dst = address;
2077 uint8_t *src = pbData;
2078 int dstW = width;
2079 int dstH = height;
2080 int srcW = cx;
2081 int srcH = cy;
2082 int iDeltaLine = cx * 4;
2083
2084 BitmapScale32(dst,
2085 dstW, dstH,
2086 src,
2087 iDeltaLine,
2088 srcW, srcH);
2089 }
2090
2091 if (fFreeMem)
2092 RTMemFree(pbData);
2093 else
2094 {
2095 /* This can be called from any thread. */
2096 pDrv->pUpPort->pfnFreeScreenshot(pDrv->pUpPort, pbData);
2097 }
2098 }
2099
2100 return vrc;
2101}
2102
2103HRESULT Display::takeScreenShotWorker(ULONG aScreenId,
2104 BYTE *aAddress,
2105 ULONG aWidth,
2106 ULONG aHeight,
2107 BitmapFormat_T aBitmapFormat,
2108 ULONG *pcbOut)
2109{
2110 HRESULT rc = S_OK;
2111
2112 /* Do not allow too small and too large screenshots. This also filters out negative
2113 * values passed as either 'aWidth' or 'aHeight'.
2114 */
2115 CheckComArgExpr(aWidth, aWidth != 0 && aWidth <= 32767);
2116 CheckComArgExpr(aHeight, aHeight != 0 && aHeight <= 32767);
2117
2118 if ( aBitmapFormat != BitmapFormat_BGR0
2119 && aBitmapFormat != BitmapFormat_BGRA
2120 && aBitmapFormat != BitmapFormat_RGBA
2121 && aBitmapFormat != BitmapFormat_PNG)
2122 {
2123 return setError(E_NOTIMPL,
2124 tr("Unsupported screenshot format 0x%08X"), aBitmapFormat);
2125 }
2126
2127 Console::SafeVMPtr ptrVM(mParent);
2128 if (!ptrVM.isOk())
2129 return ptrVM.rc();
2130
2131 int vrc = i_displayTakeScreenshot(ptrVM.rawUVM(), this, mpDrv, aScreenId, aAddress, aWidth, aHeight);
2132
2133 if (RT_SUCCESS(vrc))
2134 {
2135 const size_t cbData = aWidth * 4 * aHeight;
2136
2137 /* Most of uncompressed formats. */
2138 *pcbOut = (ULONG)cbData;
2139
2140 if (aBitmapFormat == BitmapFormat_BGR0)
2141 {
2142 /* Do nothing. */
2143 }
2144 else if (aBitmapFormat == BitmapFormat_BGRA)
2145 {
2146 uint32_t *pu32 = (uint32_t *)aAddress;
2147 size_t cPixels = aWidth * aHeight;
2148 while (cPixels--)
2149 {
2150 *pu32++ |= UINT32_C(0xFF000000);
2151 }
2152 }
2153 else if (aBitmapFormat == BitmapFormat_RGBA)
2154 {
2155 uint8_t *pu8 = aAddress;
2156 size_t cPixels = aWidth * aHeight;
2157 while (cPixels--)
2158 {
2159 uint8_t u8 = pu8[0];
2160 pu8[0] = pu8[2];
2161 pu8[2] = u8;
2162 pu8[3] = 0xFF;
2163
2164 pu8 += 4;
2165 }
2166 }
2167 else if (aBitmapFormat == BitmapFormat_PNG)
2168 {
2169 uint8_t *pu8PNG = NULL;
2170 uint32_t cbPNG = 0;
2171 uint32_t cxPNG = 0;
2172 uint32_t cyPNG = 0;
2173
2174 vrc = DisplayMakePNG(aAddress, aWidth, aHeight, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 0);
2175 if (RT_SUCCESS(vrc))
2176 {
2177 if (cbPNG <= cbData)
2178 {
2179 memcpy(aAddress, pu8PNG, cbPNG);
2180 *pcbOut = cbPNG;
2181 }
2182 else
2183 {
2184 rc = setError(E_FAIL,
2185 tr("PNG is larger than 32bpp bitmap"));
2186 }
2187 }
2188 else
2189 {
2190 rc = setError(VBOX_E_IPRT_ERROR,
2191 tr("Could not convert screenshot to PNG (%Rrc)"), vrc);
2192 }
2193 RTMemFree(pu8PNG);
2194 }
2195 }
2196 else if (vrc == VERR_TRY_AGAIN)
2197 rc = setError(E_UNEXPECTED,
2198 tr("Screenshot is not available at this time"));
2199 else if (RT_FAILURE(vrc))
2200 rc = setError(VBOX_E_IPRT_ERROR,
2201 tr("Could not take a screenshot (%Rrc)"), vrc);
2202
2203 return rc;
2204}
2205
2206HRESULT Display::takeScreenShot(ULONG aScreenId,
2207 BYTE *aAddress,
2208 ULONG aWidth,
2209 ULONG aHeight,
2210 BitmapFormat_T aBitmapFormat)
2211{
2212 HRESULT rc = S_OK;
2213
2214 LogRelFlowFunc(("[%d] address=%p, width=%d, height=%d, format 0x%08X\n",
2215 aScreenId, aAddress, aWidth, aHeight, aBitmapFormat));
2216
2217 ULONG cbOut = 0;
2218 rc = takeScreenShotWorker(aScreenId, aAddress, aWidth, aHeight, aBitmapFormat, &cbOut);
2219 NOREF(cbOut);
2220
2221 LogRelFlowFunc(("%Rhrc\n", rc));
2222 return rc;
2223}
2224
2225HRESULT Display::takeScreenShotToArray(ULONG aScreenId,
2226 ULONG aWidth,
2227 ULONG aHeight,
2228 BitmapFormat_T aBitmapFormat,
2229 std::vector<BYTE> &aScreenData)
2230{
2231 HRESULT rc = S_OK;
2232
2233 LogRelFlowFunc(("[%d] width=%d, height=%d, format 0x%08X\n",
2234 aScreenId, aWidth, aHeight, aBitmapFormat));
2235
2236 /* Do not allow too small and too large screenshots. This also filters out negative
2237 * values passed as either 'aWidth' or 'aHeight'.
2238 */
2239 CheckComArgExpr(aWidth, aWidth != 0 && aWidth <= 32767);
2240 CheckComArgExpr(aHeight, aHeight != 0 && aHeight <= 32767);
2241
2242 const size_t cbData = aWidth * 4 * aHeight;
2243 aScreenData.resize(cbData);
2244
2245 ULONG cbOut = 0;
2246 rc = takeScreenShotWorker(aScreenId, &aScreenData.front(), aWidth, aHeight, aBitmapFormat, &cbOut);
2247 if (FAILED(rc))
2248 cbOut = 0;
2249
2250 aScreenData.resize(cbOut);
2251
2252 LogRelFlowFunc(("%Rhrc\n", rc));
2253 return rc;
2254}
2255
2256
2257int Display::i_VideoCaptureEnableScreens(ComSafeArrayIn(BOOL, aScreens))
2258{
2259#ifdef VBOX_WITH_VPX
2260 com::SafeArray<BOOL> Screens(ComSafeArrayInArg(aScreens));
2261 for (unsigned i = 0; i < Screens.size(); i++)
2262 {
2263 bool fChanged = maVideoRecEnabled[i] != RT_BOOL(Screens[i]);
2264
2265 maVideoRecEnabled[i] = RT_BOOL(Screens[i]);
2266
2267 if (fChanged && i < mcMonitors)
2268 videoCaptureScreenChanged(i);
2269
2270 }
2271 return VINF_SUCCESS;
2272#else
2273 return VERR_NOT_IMPLEMENTED;
2274#endif
2275}
2276
2277/**
2278 * Start video capturing. Does nothing if capturing is already active.
2279 */
2280int Display::i_VideoCaptureStart()
2281{
2282#ifdef VBOX_WITH_VPX
2283 if (VideoRecIsEnabled(mpVideoRecCtx))
2284 return VINF_SUCCESS;
2285
2286 int rc = VideoRecContextCreate(&mpVideoRecCtx, mcMonitors);
2287 if (RT_FAILURE(rc))
2288 {
2289 LogFlow(("Failed to create video recording context (%Rrc)!\n", rc));
2290 return rc;
2291 }
2292 ComPtr<IMachine> pMachine = mParent->i_machine();
2293 com::SafeArray<BOOL> screens;
2294 HRESULT hrc = pMachine->COMGETTER(VideoCaptureScreens)(ComSafeArrayAsOutParam(screens));
2295 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
2296 for (unsigned i = 0; i < RT_ELEMENTS(maVideoRecEnabled); i++)
2297 maVideoRecEnabled[i] = i < screens.size() && screens[i];
2298 ULONG ulWidth;
2299 hrc = pMachine->COMGETTER(VideoCaptureWidth)(&ulWidth);
2300 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
2301 ULONG ulHeight;
2302 hrc = pMachine->COMGETTER(VideoCaptureHeight)(&ulHeight);
2303 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
2304 ULONG ulRate;
2305 hrc = pMachine->COMGETTER(VideoCaptureRate)(&ulRate);
2306 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
2307 ULONG ulFPS;
2308 hrc = pMachine->COMGETTER(VideoCaptureFPS)(&ulFPS);
2309 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
2310 BSTR strFile;
2311 hrc = pMachine->COMGETTER(VideoCaptureFile)(&strFile);
2312 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
2313 ULONG ulMaxTime;
2314 hrc = pMachine->COMGETTER(VideoCaptureMaxTime)(&ulMaxTime);
2315 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
2316 ULONG ulMaxSize;
2317 hrc = pMachine->COMGETTER(VideoCaptureMaxFileSize)(&ulMaxSize);
2318 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
2319 BSTR strOptions;
2320 hrc = pMachine->COMGETTER(VideoCaptureOptions)(&strOptions);
2321 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
2322
2323 RTTIMESPEC ts;
2324 RTTimeNow(&ts);
2325 RTTIME time;
2326 RTTimeExplode(&time, &ts);
2327 for (unsigned uScreen = 0; uScreen < mcMonitors; uScreen++)
2328 {
2329 char *pszAbsPath = RTPathAbsDup(com::Utf8Str(strFile).c_str());
2330 char *pszSuff = RTPathSuffix(pszAbsPath);
2331 if (pszSuff)
2332 pszSuff = RTStrDup(pszSuff);
2333 RTPathStripSuffix(pszAbsPath);
2334 if (!pszAbsPath)
2335 rc = VERR_INVALID_PARAMETER;
2336 if (!pszSuff)
2337 pszSuff = RTStrDup(".webm");
2338 char *pszName = NULL;
2339 if (RT_SUCCESS(rc))
2340 {
2341 if (mcMonitors > 1)
2342 rc = RTStrAPrintf(&pszName, "%s-%u%s", pszAbsPath, uScreen+1, pszSuff);
2343 else
2344 rc = RTStrAPrintf(&pszName, "%s%s", pszAbsPath, pszSuff);
2345 }
2346 if (RT_SUCCESS(rc))
2347 {
2348 rc = VideoRecStrmInit(mpVideoRecCtx, uScreen,
2349 pszName, ulWidth, ulHeight,
2350 ulRate, ulFPS, ulMaxTime,
2351 ulMaxSize, com::Utf8Str(strOptions).c_str());
2352 if (rc == VERR_ALREADY_EXISTS)
2353 {
2354 RTStrFree(pszName);
2355 pszName = NULL;
2356
2357 if (mcMonitors > 1)
2358 rc = RTStrAPrintf(&pszName, "%s-%04d-%02u-%02uT%02u-%02u-%02u-%09uZ-%u%s",
2359 pszAbsPath, time.i32Year, time.u8Month, time.u8MonthDay,
2360 time.u8Hour, time.u8Minute, time.u8Second, time.u32Nanosecond,
2361 uScreen+1, pszSuff);
2362 else
2363 rc = RTStrAPrintf(&pszName, "%s-%04d-%02u-%02uT%02u-%02u-%02u-%09uZ%s",
2364 pszAbsPath, time.i32Year, time.u8Month, time.u8MonthDay,
2365 time.u8Hour, time.u8Minute, time.u8Second, time.u32Nanosecond,
2366 pszSuff);
2367 if (RT_SUCCESS(rc))
2368 rc = VideoRecStrmInit(mpVideoRecCtx, uScreen,
2369 pszName, ulWidth, ulHeight, ulRate,
2370 ulFPS, ulMaxTime,
2371 ulMaxSize, com::Utf8Str(strOptions).c_str());
2372 }
2373 }
2374
2375 if (RT_SUCCESS(rc))
2376 {
2377 LogRel(("Display::VideoCaptureStart: WebM/VP8 video recording screen #%u with %ux%u @ %u kbps, %u fps to '%s' "
2378 "enabled\n", uScreen, ulWidth, ulHeight, ulRate, ulFPS, pszName));
2379
2380 videoCaptureScreenChanged(uScreen);
2381 }
2382 else
2383 LogRel(("Display::VideoCaptureStart: Failed to initialize video recording context #%u (%Rrc)!\n", uScreen, rc));
2384 RTStrFree(pszName);
2385 RTStrFree(pszSuff);
2386 RTStrFree(pszAbsPath);
2387 }
2388 return rc;
2389#else
2390 return VERR_NOT_IMPLEMENTED;
2391#endif
2392}
2393
2394/**
2395 * Stop video capturing. Does nothing if video capturing is not active.
2396 */
2397void Display::i_VideoCaptureStop()
2398{
2399#ifdef VBOX_WITH_VPX
2400 if (VideoRecIsEnabled(mpVideoRecCtx))
2401 LogRel(("Display::VideoCaptureStop: WebM/VP8 video recording stopped\n"));
2402 VideoRecContextClose(mpVideoRecCtx);
2403 mpVideoRecCtx = NULL;
2404
2405 unsigned uScreenId;
2406 for (uScreenId = 0; uScreenId < mcMonitors; ++uScreenId)
2407 videoCaptureScreenChanged(uScreenId);
2408#endif
2409}
2410
2411#ifdef VBOX_WITH_VPX
2412void Display::videoCaptureScreenChanged(unsigned uScreenId)
2413{
2414 ComPtr<IDisplaySourceBitmap> pSourceBitmap;
2415
2416 if (VideoRecIsEnabled(mpVideoRecCtx) && maVideoRecEnabled[uScreenId])
2417 {
2418 /* Get a new source bitmap which will be used by video capture code. */
2419 QuerySourceBitmap(uScreenId, pSourceBitmap.asOutParam());
2420 }
2421
2422 int rc = RTCritSectEnter(&mVideoCaptureLock);
2423 if (RT_SUCCESS(rc))
2424 {
2425 maFramebuffers[uScreenId].videoCapture.pSourceBitmap = pSourceBitmap;
2426 RTCritSectLeave(&mVideoCaptureLock);
2427 }
2428}
2429#endif
2430
2431int Display::i_drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address,
2432 ULONG x, ULONG y, ULONG width, ULONG height)
2433{
2434 int rc = VINF_SUCCESS;
2435
2436 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[aScreenId];
2437
2438 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2439 {
2440 rc = pDisplay->mpDrv->pUpPort->pfnDisplayBlt(pDisplay->mpDrv->pUpPort, address, x, y, width, height);
2441 }
2442 else if (aScreenId < pDisplay->mcMonitors)
2443 {
2444 /* Copy the bitmap to the guest VRAM. */
2445 const uint8_t *pu8Src = address;
2446 int32_t xSrc = 0;
2447 int32_t ySrc = 0;
2448 uint32_t u32SrcWidth = width;
2449 uint32_t u32SrcHeight = height;
2450 uint32_t u32SrcLineSize = width * 4;
2451 uint32_t u32SrcBitsPerPixel = 32;
2452
2453 uint8_t *pu8Dst = pFBInfo->pu8FramebufferVRAM;
2454 int32_t xDst = x;
2455 int32_t yDst = y;
2456 uint32_t u32DstWidth = pFBInfo->w;
2457 uint32_t u32DstHeight = pFBInfo->h;
2458 uint32_t u32DstLineSize = pFBInfo->u32LineSize;
2459 uint32_t u32DstBitsPerPixel = pFBInfo->u16BitsPerPixel;
2460
2461 rc = pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2462 width, height,
2463 pu8Src,
2464 xSrc, ySrc,
2465 u32SrcWidth, u32SrcHeight,
2466 u32SrcLineSize, u32SrcBitsPerPixel,
2467 pu8Dst,
2468 xDst, yDst,
2469 u32DstWidth, u32DstHeight,
2470 u32DstLineSize, u32DstBitsPerPixel);
2471 if (RT_SUCCESS(rc))
2472 {
2473 if (!pFBInfo->pSourceBitmap.isNull())
2474 {
2475 /* Update the changed screen area. When source bitmap uses VRAM directly, just notify
2476 * frontend to update. And for default format, render the guest VRAM to the source bitmap.
2477 */
2478 if ( pFBInfo->fDefaultFormat
2479 && !pFBInfo->fDisabled)
2480 {
2481 BYTE *pAddress = NULL;
2482 ULONG ulWidth = 0;
2483 ULONG ulHeight = 0;
2484 ULONG ulBitsPerPixel = 0;
2485 ULONG ulBytesPerLine = 0;
2486 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
2487
2488 HRESULT hrc = pFBInfo->pSourceBitmap->QueryBitmapInfo(&pAddress,
2489 &ulWidth,
2490 &ulHeight,
2491 &ulBitsPerPixel,
2492 &ulBytesPerLine,
2493 &bitmapFormat);
2494 if (SUCCEEDED(hrc))
2495 {
2496 pu8Src = pFBInfo->pu8FramebufferVRAM;
2497 xSrc = x;
2498 ySrc = y;
2499 u32SrcWidth = pFBInfo->w;
2500 u32SrcHeight = pFBInfo->h;
2501 u32SrcLineSize = pFBInfo->u32LineSize;
2502 u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2503
2504 /* Default format is 32 bpp. */
2505 pu8Dst = pAddress;
2506 xDst = xSrc;
2507 yDst = ySrc;
2508 u32DstWidth = u32SrcWidth;
2509 u32DstHeight = u32SrcHeight;
2510 u32DstLineSize = u32DstWidth * 4;
2511 u32DstBitsPerPixel = 32;
2512
2513 pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2514 width, height,
2515 pu8Src,
2516 xSrc, ySrc,
2517 u32SrcWidth, u32SrcHeight,
2518 u32SrcLineSize, u32SrcBitsPerPixel,
2519 pu8Dst,
2520 xDst, yDst,
2521 u32DstWidth, u32DstHeight,
2522 u32DstLineSize, u32DstBitsPerPixel);
2523 }
2524 }
2525 }
2526
2527 pDisplay->i_handleDisplayUpdate(aScreenId, x, y, width, height);
2528 }
2529 }
2530 else
2531 {
2532 rc = VERR_INVALID_PARAMETER;
2533 }
2534
2535 if (RT_SUCCESS(rc))
2536 pDisplay->mParent->i_consoleVRDPServer()->SendUpdateBitmap(aScreenId, x, y, width, height);
2537
2538 return rc;
2539}
2540
2541HRESULT Display::drawToScreen(ULONG aScreenId, BYTE *aAddress, ULONG aX, ULONG aY, ULONG aWidth, ULONG aHeight)
2542{
2543 /// @todo (r=dmik) this function may take too long to complete if the VM
2544 // is doing something like saving state right now. Which, in case if it
2545 // is called on the GUI thread, will make it unresponsive. We should
2546 // check the machine state here (by enclosing the check and VMRequCall
2547 // within the Console lock to make it atomic).
2548
2549 LogRelFlowFunc(("aAddress=%p, x=%d, y=%d, width=%d, height=%d\n",
2550 (void *)aAddress, aX, aY, aWidth, aHeight));
2551
2552 CheckComArgExpr(aWidth, aWidth != 0);
2553 CheckComArgExpr(aHeight, aHeight != 0);
2554
2555 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2556
2557 CHECK_CONSOLE_DRV(mpDrv);
2558
2559 Console::SafeVMPtr ptrVM(mParent);
2560 if (!ptrVM.isOk())
2561 return ptrVM.rc();
2562
2563 /* Release lock because the call scheduled on EMT may also try to take it. */
2564 alock.release();
2565
2566 /*
2567 * Again we're lazy and make the graphics device do all the
2568 * dirty conversion work.
2569 */
2570 int rcVBox = VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_drawToScreenEMT, 7,
2571 this, aScreenId, aAddress, aX, aY, aWidth, aHeight);
2572
2573 /*
2574 * If the function returns not supported, we'll have to do all the
2575 * work ourselves using the framebuffer.
2576 */
2577 HRESULT rc = S_OK;
2578 if (rcVBox == VERR_NOT_SUPPORTED || rcVBox == VERR_NOT_IMPLEMENTED)
2579 {
2580 /** @todo implement generic fallback for screen blitting. */
2581 rc = E_NOTIMPL;
2582 }
2583 else if (RT_FAILURE(rcVBox))
2584 rc = setError(VBOX_E_IPRT_ERROR,
2585 tr("Could not draw to the screen (%Rrc)"), rcVBox);
2586//@todo
2587// else
2588// {
2589// /* All ok. Redraw the screen. */
2590// handleDisplayUpdate(x, y, width, height);
2591// }
2592
2593 LogRelFlowFunc(("rc=%Rhrc\n", rc));
2594 return rc;
2595}
2596
2597int Display::i_InvalidateAndUpdateEMT(Display *pDisplay, unsigned uId, bool fUpdateAll)
2598{
2599 LogRelFlowFunc(("uId=%d, fUpdateAll %d\n", uId, fUpdateAll));
2600
2601 unsigned uScreenId;
2602 for (uScreenId = (fUpdateAll ? 0 : uId); uScreenId < pDisplay->mcMonitors; uScreenId++)
2603 {
2604 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
2605
2606 if ( !pFBInfo->fVBVAEnabled
2607 && uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2608 {
2609 pDisplay->mpDrv->pUpPort->pfnUpdateDisplayAll(pDisplay->mpDrv->pUpPort, /* fFailOnResize = */ true);
2610 }
2611 else
2612 {
2613 if (!pFBInfo->fDisabled)
2614 {
2615 /* Render complete VRAM screen to the framebuffer.
2616 * When framebuffer uses VRAM directly, just notify it to update.
2617 */
2618 if (pFBInfo->fDefaultFormat && !pFBInfo->pSourceBitmap.isNull())
2619 {
2620 BYTE *pAddress = NULL;
2621 ULONG ulWidth = 0;
2622 ULONG ulHeight = 0;
2623 ULONG ulBitsPerPixel = 0;
2624 ULONG ulBytesPerLine = 0;
2625 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
2626
2627 HRESULT hrc = pFBInfo->pSourceBitmap->QueryBitmapInfo(&pAddress,
2628 &ulWidth,
2629 &ulHeight,
2630 &ulBitsPerPixel,
2631 &ulBytesPerLine,
2632 &bitmapFormat);
2633 if (SUCCEEDED(hrc))
2634 {
2635 uint32_t width = pFBInfo->w;
2636 uint32_t height = pFBInfo->h;
2637
2638 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
2639 int32_t xSrc = 0;
2640 int32_t ySrc = 0;
2641 uint32_t u32SrcWidth = pFBInfo->w;
2642 uint32_t u32SrcHeight = pFBInfo->h;
2643 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
2644 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2645
2646 /* Default format is 32 bpp. */
2647 uint8_t *pu8Dst = pAddress;
2648 int32_t xDst = xSrc;
2649 int32_t yDst = ySrc;
2650 uint32_t u32DstWidth = u32SrcWidth;
2651 uint32_t u32DstHeight = u32SrcHeight;
2652 uint32_t u32DstLineSize = u32DstWidth * 4;
2653 uint32_t u32DstBitsPerPixel = 32;
2654
2655 /* if uWidth != pFBInfo->w and uHeight != pFBInfo->h
2656 * implies resize of Framebuffer is in progress and
2657 * copyrect should not be called.
2658 */
2659 if (ulWidth == pFBInfo->w && ulHeight == pFBInfo->h)
2660 {
2661 pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2662 width, height,
2663 pu8Src,
2664 xSrc, ySrc,
2665 u32SrcWidth, u32SrcHeight,
2666 u32SrcLineSize, u32SrcBitsPerPixel,
2667 pu8Dst,
2668 xDst, yDst,
2669 u32DstWidth, u32DstHeight,
2670 u32DstLineSize, u32DstBitsPerPixel);
2671 }
2672 }
2673 }
2674
2675 pDisplay->i_handleDisplayUpdate(uScreenId, 0, 0, pFBInfo->w, pFBInfo->h);
2676 }
2677 }
2678 if (!fUpdateAll)
2679 break;
2680 }
2681 LogRelFlowFunc(("done\n"));
2682 return VINF_SUCCESS;
2683}
2684
2685/**
2686 * Does a full invalidation of the VM display and instructs the VM
2687 * to update it immediately.
2688 *
2689 * @returns COM status code
2690 */
2691
2692HRESULT Display::invalidateAndUpdate()
2693{
2694 LogRelFlowFunc(("\n"));
2695
2696 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2697
2698 CHECK_CONSOLE_DRV(mpDrv);
2699
2700 Console::SafeVMPtr ptrVM(mParent);
2701 if (!ptrVM.isOk())
2702 return ptrVM.rc();
2703
2704 HRESULT rc = S_OK;
2705
2706 LogRelFlowFunc(("Sending DPYUPDATE request\n"));
2707
2708 /* Have to release the lock when calling EMT. */
2709 alock.release();
2710
2711 int rcVBox = VMR3ReqCallNoWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_InvalidateAndUpdateEMT,
2712 3, this, 0, true);
2713 alock.acquire();
2714
2715 if (RT_FAILURE(rcVBox))
2716 rc = setError(VBOX_E_IPRT_ERROR,
2717 tr("Could not invalidate and update the screen (%Rrc)"), rcVBox);
2718
2719 LogRelFlowFunc(("rc=%Rhrc\n", rc));
2720 return rc;
2721}
2722
2723HRESULT Display::invalidateAndUpdateScreen(ULONG aScreenId)
2724{
2725 LogRelFlowFunc(("\n"));
2726
2727 HRESULT rc = S_OK;
2728
2729 Console::SafeVMPtr ptrVM(mParent);
2730 if (!ptrVM.isOk())
2731 return ptrVM.rc();
2732
2733 int rcVBox = VMR3ReqCallNoWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_InvalidateAndUpdateEMT,
2734 3, this, aScreenId, false);
2735 if (RT_FAILURE(rcVBox))
2736 rc = setError(VBOX_E_IPRT_ERROR,
2737 tr("Could not invalidate and update the screen %d (%Rrc)"), aScreenId, rcVBox);
2738
2739 LogRelFlowFunc(("rc=%Rhrc\n", rc));
2740 return rc;
2741}
2742
2743HRESULT Display::completeVHWACommand(BYTE *aCommand)
2744{
2745#ifdef VBOX_WITH_VIDEOHWACCEL
2746 mpDrv->pVBVACallbacks->pfnVHWACommandCompleteAsync(mpDrv->pVBVACallbacks, (PVBOXVHWACMD)aCommand);
2747 return S_OK;
2748#else
2749 return E_NOTIMPL;
2750#endif
2751}
2752
2753HRESULT Display::viewportChanged(ULONG aScreenId, ULONG aX, ULONG aY, ULONG aWidth, ULONG aHeight)
2754{
2755 AssertMsgReturn(aScreenId < mcMonitors, ("aScreendId=%d mcMonitors=%d\n", aScreenId, mcMonitors), E_INVALIDARG);
2756
2757#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
2758 if (mfIsCr3DEnabled)
2759 {
2760 int rc = i_crViewportNotify(aScreenId, aX, aY, aWidth, aHeight);
2761 if (RT_FAILURE(rc))
2762 {
2763 DISPLAYFBINFO *pFb = &maFramebuffers[aScreenId];
2764 pFb->pendingViewportInfo.fPending = true;
2765 pFb->pendingViewportInfo.x = aX;
2766 pFb->pendingViewportInfo.y = aY;
2767 pFb->pendingViewportInfo.width = aWidth;
2768 pFb->pendingViewportInfo.height = aHeight;
2769 }
2770 }
2771#endif /* VBOX_WITH_CROGL && VBOX_WITH_HGCM */
2772
2773 /* The driver might not have been constructed yet */
2774 if (mpDrv && mpDrv->pUpPort->pfnSetViewport)
2775 mpDrv->pUpPort->pfnSetViewport(mpDrv->pUpPort, aScreenId, aX, aY, aWidth, aHeight);
2776
2777 return S_OK;
2778}
2779
2780HRESULT Display::querySourceBitmap(ULONG aScreenId,
2781 ComPtr<IDisplaySourceBitmap> &aDisplaySourceBitmap)
2782{
2783 LogRelFlowFunc(("aScreenId = %d\n", aScreenId));
2784
2785 Console::SafeVMPtr ptrVM(mParent);
2786 if (!ptrVM.isOk())
2787 return ptrVM.rc();
2788
2789 bool fSetRenderVRAM = false;
2790 bool fInvalidate = false;
2791
2792 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2793
2794 if (aScreenId >= mcMonitors)
2795 return setError(E_INVALIDARG, tr("QuerySourceBitmap: Invalid screen %d (total %d)"),
2796 aScreenId, mcMonitors);
2797
2798 if (!mfSourceBitmapEnabled)
2799 {
2800 aDisplaySourceBitmap = NULL;
2801 return E_FAIL;
2802 }
2803
2804 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
2805
2806 /* No source bitmap for a blank guest screen. */
2807 if (pFBInfo->flags & VBVA_SCREEN_F_BLANK)
2808 {
2809 aDisplaySourceBitmap = NULL;
2810 return E_FAIL;
2811 }
2812
2813 HRESULT hr = S_OK;
2814
2815 if (pFBInfo->pSourceBitmap.isNull())
2816 {
2817 /* Create a new object. */
2818 ComObjPtr<DisplaySourceBitmap> obj;
2819 hr = obj.createObject();
2820 if (SUCCEEDED(hr))
2821 hr = obj->init(this, aScreenId, pFBInfo);
2822
2823 if (SUCCEEDED(hr))
2824 {
2825 bool fDefaultFormat = !obj->i_usesVRAM();
2826
2827 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2828 {
2829 /* Start buffer updates. */
2830 BYTE *pAddress = NULL;
2831 ULONG ulWidth = 0;
2832 ULONG ulHeight = 0;
2833 ULONG ulBitsPerPixel = 0;
2834 ULONG ulBytesPerLine = 0;
2835 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
2836
2837 obj->QueryBitmapInfo(&pAddress,
2838 &ulWidth,
2839 &ulHeight,
2840 &ulBitsPerPixel,
2841 &ulBytesPerLine,
2842 &bitmapFormat);
2843
2844 mpDrv->IConnector.pbData = pAddress;
2845 mpDrv->IConnector.cbScanline = ulBytesPerLine;
2846 mpDrv->IConnector.cBits = ulBitsPerPixel;
2847 mpDrv->IConnector.cx = ulWidth;
2848 mpDrv->IConnector.cy = ulHeight;
2849
2850 fSetRenderVRAM = fDefaultFormat;
2851 }
2852
2853 /* Make sure that the bitmap contains the latest image. */
2854 fInvalidate = fDefaultFormat;
2855
2856 pFBInfo->pSourceBitmap = obj;
2857 pFBInfo->fDefaultFormat = fDefaultFormat;
2858 }
2859 }
2860
2861 if (SUCCEEDED(hr))
2862 {
2863 pFBInfo->pSourceBitmap.queryInterfaceTo(aDisplaySourceBitmap.asOutParam());
2864 }
2865
2866 /* Leave the IDisplay lock because the VGA device must not be called under it. */
2867 alock.release();
2868
2869 if (SUCCEEDED(hr))
2870 {
2871 if (fSetRenderVRAM)
2872 {
2873 mpDrv->pUpPort->pfnSetRenderVRAM(mpDrv->pUpPort, true);
2874 }
2875
2876 if (fInvalidate)
2877 VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_InvalidateAndUpdateEMT,
2878 3, this, aScreenId, false);
2879 }
2880
2881 LogRelFlowFunc(("%Rhrc\n", hr));
2882 return hr;
2883}
2884
2885HRESULT Display::getGuestScreenLayout(std::vector<ComPtr<IGuestScreenInfo> > &aGuestScreenLayout)
2886{
2887 NOREF(aGuestScreenLayout);
2888 return E_NOTIMPL;
2889}
2890
2891HRESULT Display::setScreenLayout(ScreenLayoutMode_T aScreenLayoutMode,
2892 const std::vector<ComPtr<IGuestScreenInfo> > &aGuestScreenInfo)
2893{
2894 NOREF(aScreenLayoutMode);
2895 NOREF(aGuestScreenInfo);
2896 return E_NOTIMPL;
2897}
2898
2899// wrapped IEventListener method
2900HRESULT Display::handleEvent(const ComPtr<IEvent> &aEvent)
2901{
2902 VBoxEventType_T aType = VBoxEventType_Invalid;
2903
2904 aEvent->COMGETTER(Type)(&aType);
2905 switch (aType)
2906 {
2907 case VBoxEventType_OnStateChanged:
2908 {
2909 ComPtr<IStateChangedEvent> scev = aEvent;
2910 Assert(scev);
2911 MachineState_T machineState;
2912 scev->COMGETTER(State)(&machineState);
2913 if ( machineState == MachineState_Running
2914 || machineState == MachineState_Teleporting
2915 || machineState == MachineState_LiveSnapshotting
2916 || machineState == MachineState_DeletingSnapshotOnline
2917 )
2918 {
2919 LogRelFlowFunc(("Machine is running.\n"));
2920
2921#ifdef VBOX_WITH_CROGL
2922 i_crOglWindowsShow(true);
2923#endif
2924 }
2925 else
2926 {
2927#ifdef VBOX_WITH_CROGL
2928 if (machineState == MachineState_Paused)
2929 i_crOglWindowsShow(false);
2930#endif
2931 }
2932 break;
2933 }
2934 default:
2935 AssertFailed();
2936 }
2937
2938 return S_OK;
2939}
2940
2941
2942// private methods
2943/////////////////////////////////////////////////////////////////////////////
2944
2945#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
2946int Display::i_crViewportNotify(ULONG aScreenId, ULONG x, ULONG y, ULONG width, ULONG height)
2947{
2948 VMMDev *pVMMDev = mParent->i_getVMMDev();
2949 if (!pVMMDev)
2950 return VERR_INVALID_STATE;
2951
2952 size_t cbData = RT_UOFFSETOF(VBOXCRCMDCTL_HGCM, aParms[5]);
2953 VBOXCRCMDCTL_HGCM *pData = (VBOXCRCMDCTL_HGCM *)alloca(cbData);
2954
2955 pData->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
2956 pData->Hdr.u32Function = SHCRGL_HOST_FN_VIEWPORT_CHANGED;
2957
2958 pData->aParms[0].type = VBOX_HGCM_SVC_PARM_32BIT;
2959 pData->aParms[0].u.uint32 = aScreenId;
2960
2961 pData->aParms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
2962 pData->aParms[1].u.uint32 = x;
2963
2964 pData->aParms[2].type = VBOX_HGCM_SVC_PARM_32BIT;
2965 pData->aParms[2].u.uint32 = y;
2966
2967 pData->aParms[3].type = VBOX_HGCM_SVC_PARM_32BIT;
2968 pData->aParms[3].u.uint32 = width;
2969
2970 pData->aParms[4].type = VBOX_HGCM_SVC_PARM_32BIT;
2971 pData->aParms[4].u.uint32 = height;
2972
2973 return i_crCtlSubmitSyncIfHasDataForScreen(aScreenId, &pData->Hdr, (uint32_t)cbData);
2974}
2975#endif
2976
2977#ifdef VBOX_WITH_CRHGSMI
2978void Display::i_setupCrHgsmiData(void)
2979{
2980 VMMDev *pVMMDev = mParent->i_getVMMDev();
2981 Assert(pVMMDev);
2982 int rc = RTCritSectRwEnterExcl(&mCrOglLock);
2983 AssertRC(rc);
2984
2985 if (pVMMDev)
2986 rc = pVMMDev->hgcmHostSvcHandleCreate("VBoxSharedCrOpenGL", &mhCrOglSvc);
2987 else
2988 rc = VERR_GENERAL_FAILURE;
2989
2990 if (RT_SUCCESS(rc))
2991 {
2992 Assert(mhCrOglSvc);
2993 /* setup command completion callback */
2994 VBOXVDMACMD_CHROMIUM_CTL_CRHGSMI_SETUP_MAINCB Completion;
2995 Completion.Hdr.enmType = VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP_MAINCB;
2996 Completion.Hdr.cbCmd = sizeof(Completion);
2997 Completion.hCompletion = mpDrv->pVBVACallbacks;
2998 Completion.pfnCompletion = mpDrv->pVBVACallbacks->pfnCrHgsmiCommandCompleteAsync;
2999
3000 VBOXHGCMSVCPARM parm;
3001 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3002 parm.u.pointer.addr = &Completion;
3003 parm.u.pointer.size = 0;
3004
3005 rc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_CRHGSMI_CTL, 1, &parm);
3006 if (RT_SUCCESS(rc))
3007 mCrOglCallbacks = Completion.MainInterface;
3008 else
3009 AssertMsgFailed(("VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP_COMPLETION failed (rc=%Rrc)\n", rc));
3010 }
3011
3012 if (RT_FAILURE(rc))
3013 mhCrOglSvc = NULL;
3014
3015 RTCritSectRwLeaveExcl(&mCrOglLock);
3016}
3017
3018void Display::i_destructCrHgsmiData(void)
3019{
3020 int rc = RTCritSectRwEnterExcl(&mCrOglLock);
3021 AssertRC(rc);
3022 mhCrOglSvc = NULL;
3023 RTCritSectRwLeaveExcl(&mCrOglLock);
3024}
3025#endif /* VBOX_WITH_CRHGSMI */
3026
3027/**
3028 * Handle display resize event issued by the VGA device for the primary screen.
3029 *
3030 * @see PDMIDISPLAYCONNECTOR::pfnResize
3031 */
3032DECLCALLBACK(int) Display::i_displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface,
3033 uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy)
3034{
3035 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3036 Display *pThis = pDrv->pDisplay;
3037
3038 LogRelFlowFunc(("bpp %d, pvVRAM %p, cbLine %d, cx %d, cy %d\n",
3039 bpp, pvVRAM, cbLine, cx, cy));
3040
3041 bool f = ASMAtomicCmpXchgBool(&pThis->fVGAResizing, true, false);
3042 if (!f)
3043 {
3044 /* This is a result of recursive call when the source bitmap is being updated
3045 * during a VGA resize. Tell the VGA device to ignore the call.
3046 *
3047 * @todo It is a workaround, actually pfnUpdateDisplayAll must
3048 * fail on resize.
3049 */
3050 LogRel(("displayResizeCallback: already processing\n"));
3051 return VINF_VGA_RESIZE_IN_PROGRESS;
3052 }
3053
3054 int rc = pThis->i_handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, bpp, pvVRAM, cbLine, cx, cy, VBVA_SCREEN_F_ACTIVE);
3055
3056 /* Restore the flag. */
3057 f = ASMAtomicCmpXchgBool(&pThis->fVGAResizing, false, true);
3058 AssertRelease(f);
3059
3060 return rc;
3061}
3062
3063/**
3064 * Handle display update.
3065 *
3066 * @see PDMIDISPLAYCONNECTOR::pfnUpdateRect
3067 */
3068DECLCALLBACK(void) Display::i_displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
3069 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
3070{
3071 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3072
3073#ifdef DEBUG_sunlover
3074 LogFlowFunc(("fVideoAccelEnabled = %d, %d,%d %dx%d\n",
3075 pDrv->pDisplay->mVideoAccelLegacy.fVideoAccelEnabled, x, y, cx, cy));
3076#endif /* DEBUG_sunlover */
3077
3078 /* This call does update regardless of VBVA status.
3079 * But in VBVA mode this is called only as result of
3080 * pfnUpdateDisplayAll in the VGA device.
3081 */
3082
3083 pDrv->pDisplay->i_handleDisplayUpdate(VBOX_VIDEO_PRIMARY_SCREEN, x, y, cx, cy);
3084}
3085
3086/**
3087 * Periodic display refresh callback.
3088 *
3089 * @see PDMIDISPLAYCONNECTOR::pfnRefresh
3090 * @thread EMT
3091 */
3092/*static*/ DECLCALLBACK(void) Display::i_displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface)
3093{
3094 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3095
3096#ifdef DEBUG_sunlover_2
3097 LogFlowFunc(("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
3098 pDrv->pDisplay->mfVideoAccelEnabled));
3099#endif /* DEBUG_sunlover_2 */
3100
3101 Display *pDisplay = pDrv->pDisplay;
3102 unsigned uScreenId;
3103
3104 int rc = pDisplay->i_videoAccelRefreshProcess(pDrv->pUpPort);
3105 if (rc != VINF_TRY_AGAIN) /* Means 'do nothing' here. */
3106 {
3107 if (rc == VWRN_INVALID_STATE)
3108 {
3109 /* No VBVA do a display update. */
3110 pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
3111 }
3112
3113 /* Inform the VRDP server that the current display update sequence is
3114 * completed. At this moment the framebuffer memory contains a definite
3115 * image, that is synchronized with the orders already sent to VRDP client.
3116 * The server can now process redraw requests from clients or initial
3117 * fullscreen updates for new clients.
3118 */
3119 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3120 {
3121 Assert(pDisplay->mParent && pDisplay->mParent->i_consoleVRDPServer());
3122 pDisplay->mParent->i_consoleVRDPServer()->SendUpdate(uScreenId, NULL, 0);
3123 }
3124 }
3125
3126#ifdef VBOX_WITH_VPX
3127 if (VideoRecIsEnabled(pDisplay->mpVideoRecCtx))
3128 {
3129 do {
3130# if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
3131 if (pDisplay->mfIsCr3DEnabled)
3132 {
3133 if (ASMAtomicCmpXchgU32(&pDisplay->mfCrOglVideoRecState, CRVREC_STATE_SUBMITTED, CRVREC_STATE_IDLE))
3134 {
3135 if ( pDisplay->mCrOglCallbacks.pfnHasData
3136 && pDisplay->mCrOglCallbacks.pfnHasData())
3137 {
3138 /* submit */
3139 VBOXCRCMDCTL_HGCM *pData = &pDisplay->mCrOglScreenshotCtl;
3140
3141 pData->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
3142 pData->Hdr.u32Function = SHCRGL_HOST_FN_TAKE_SCREENSHOT;
3143
3144 pData->aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
3145 pData->aParms[0].u.pointer.addr = &pDisplay->mCrOglScreenshotData;
3146 pData->aParms[0].u.pointer.size = sizeof(pDisplay->mCrOglScreenshotData);
3147 rc = pDisplay->i_crCtlSubmit(&pData->Hdr, sizeof(*pData), Display::i_displayVRecCompletion, pDisplay);
3148 if (RT_SUCCESS(rc))
3149 break;
3150 AssertMsgFailed(("crCtlSubmit failed (rc=%Rrc)\n", rc));
3151 }
3152
3153 /* no 3D data available, or error has occured,
3154 * go the straight way */
3155 ASMAtomicWriteU32(&pDisplay->mfCrOglVideoRecState, CRVREC_STATE_IDLE);
3156 }
3157 else
3158 {
3159 /* record request is still in progress, don't do anything */
3160 break;
3161 }
3162 }
3163# endif /* VBOX_WITH_HGCM && VBOX_WITH_CROGL */
3164
3165 uint64_t u64Now = RTTimeProgramMilliTS();
3166 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3167 {
3168 if (!pDisplay->maVideoRecEnabled[uScreenId])
3169 continue;
3170
3171 if (VideoRecIsFull(pDisplay->mpVideoRecCtx, uScreenId, u64Now))
3172 {
3173 pDisplay->i_VideoCaptureStop();
3174 pDisplay->mParent->i_machine()->COMSETTER(VideoCaptureEnabled)(false);
3175 break;
3176 }
3177
3178 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3179 if (!pFBInfo->fDisabled)
3180 {
3181 ComPtr<IDisplaySourceBitmap> pSourceBitmap;
3182 int rc2 = RTCritSectEnter(&pDisplay->mVideoCaptureLock);
3183 if (RT_SUCCESS(rc2))
3184 {
3185 pSourceBitmap = pFBInfo->videoCapture.pSourceBitmap;
3186 RTCritSectLeave(&pDisplay->mVideoCaptureLock);
3187 }
3188
3189 if (!pSourceBitmap.isNull())
3190 {
3191 BYTE *pbAddress = NULL;
3192 ULONG ulWidth = 0;
3193 ULONG ulHeight = 0;
3194 ULONG ulBitsPerPixel = 0;
3195 ULONG ulBytesPerLine = 0;
3196 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
3197 HRESULT hr = pSourceBitmap->QueryBitmapInfo(&pbAddress,
3198 &ulWidth,
3199 &ulHeight,
3200 &ulBitsPerPixel,
3201 &ulBytesPerLine,
3202 &bitmapFormat);
3203 if (SUCCEEDED(hr) && pbAddress)
3204 rc = VideoRecCopyToIntBuf(pDisplay->mpVideoRecCtx, uScreenId, 0, 0,
3205 BitmapFormat_BGR,
3206 ulBitsPerPixel, ulBytesPerLine, ulWidth, ulHeight,
3207 pbAddress, u64Now);
3208 else
3209 rc = VERR_NOT_SUPPORTED;
3210
3211 pSourceBitmap.setNull();
3212 }
3213 else
3214 rc = VERR_NOT_SUPPORTED;
3215
3216 if (rc == VINF_TRY_AGAIN)
3217 break;
3218 }
3219 }
3220 } while (0);
3221 }
3222#endif /* VBOX_WITH_VPX */
3223
3224#ifdef DEBUG_sunlover_2
3225 LogFlowFunc(("leave\n"));
3226#endif /* DEBUG_sunlover_2 */
3227}
3228
3229/**
3230 * Reset notification
3231 *
3232 * @see PDMIDISPLAYCONNECTOR::pfnReset
3233 */
3234DECLCALLBACK(void) Display::i_displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface)
3235{
3236 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3237
3238 LogRelFlowFunc(("\n"));
3239
3240 /* Disable VBVA mode. */
3241 pDrv->pDisplay->VideoAccelEnableVGA(false, NULL);
3242}
3243
3244/**
3245 * LFBModeChange notification
3246 *
3247 * @see PDMIDISPLAYCONNECTOR::pfnLFBModeChange
3248 */
3249DECLCALLBACK(void) Display::i_displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled)
3250{
3251 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3252
3253 LogRelFlowFunc(("fEnabled=%d\n", fEnabled));
3254
3255 NOREF(fEnabled);
3256
3257 /* Disable VBVA mode in any case. The guest driver reenables VBVA mode if necessary. */
3258 pDrv->pDisplay->VideoAccelEnableVGA(false, NULL);
3259}
3260
3261/**
3262 * Adapter information change notification.
3263 *
3264 * @see PDMIDISPLAYCONNECTOR::pfnProcessAdapterData
3265 */
3266DECLCALLBACK(void) Display::i_displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM,
3267 uint32_t u32VRAMSize)
3268{
3269 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3270 pDrv->pDisplay->processAdapterData(pvVRAM, u32VRAMSize);
3271}
3272
3273/**
3274 * Display information change notification.
3275 *
3276 * @see PDMIDISPLAYCONNECTOR::pfnProcessDisplayData
3277 */
3278DECLCALLBACK(void) Display::i_displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface,
3279 void *pvVRAM, unsigned uScreenId)
3280{
3281 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3282 pDrv->pDisplay->processDisplayData(pvVRAM, uScreenId);
3283}
3284
3285#ifdef VBOX_WITH_VIDEOHWACCEL
3286
3287#ifndef S_FALSE
3288# define S_FALSE ((HRESULT)1L)
3289#endif
3290
3291int Display::i_handleVHWACommandProcess(PVBOXVHWACMD pCommand)
3292{
3293 unsigned id = (unsigned)pCommand->iDisplay;
3294 if (id >= mcMonitors)
3295 return VERR_INVALID_PARAMETER;
3296
3297 ComPtr<IFramebuffer> pFramebuffer;
3298 AutoReadLock arlock(this COMMA_LOCKVAL_SRC_POS);
3299 pFramebuffer = maFramebuffers[id].pFramebuffer;
3300 bool fVHWASupported = RT_BOOL(maFramebuffers[id].u32Caps & FramebufferCapabilities_VHWA);
3301 arlock.release();
3302
3303 if (pFramebuffer == NULL || !fVHWASupported)
3304 return VERR_NOT_IMPLEMENTED; /* Implementation is not available. */
3305
3306 HRESULT hr = pFramebuffer->ProcessVHWACommand((BYTE*)pCommand);
3307 if (hr == S_FALSE)
3308 return VINF_SUCCESS;
3309 if (SUCCEEDED(hr))
3310 return VINF_CALLBACK_RETURN;
3311 if (hr == E_ACCESSDENIED)
3312 return VERR_INVALID_STATE; /* notify we can not handle request atm */
3313 if (hr == E_NOTIMPL)
3314 return VERR_NOT_IMPLEMENTED;
3315 return VERR_GENERAL_FAILURE;
3316}
3317
3318DECLCALLBACK(int) Display::i_displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
3319{
3320 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3321
3322 return pDrv->pDisplay->i_handleVHWACommandProcess(pCommand);
3323}
3324#endif
3325
3326#ifdef VBOX_WITH_CRHGSMI
3327void Display::i_handleCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam)
3328{
3329 RT_NOREF(u32Function);
3330 mpDrv->pVBVACallbacks->pfnCrHgsmiCommandCompleteAsync(mpDrv->pVBVACallbacks,
3331 (PVBOXVDMACMD_CHROMIUM_CMD)pParam->u.pointer.addr, result);
3332}
3333
3334void Display::i_handleCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam)
3335{
3336 RT_NOREF(u32Function);
3337 PVBOXVDMACMD_CHROMIUM_CTL pCtl = (PVBOXVDMACMD_CHROMIUM_CTL)pParam->u.pointer.addr;
3338 mpDrv->pVBVACallbacks->pfnCrHgsmiControlCompleteAsync(mpDrv->pVBVACallbacks, pCtl, result);
3339}
3340
3341void Display::i_handleCrHgsmiCommandProcess(PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd)
3342{
3343 int rc = VERR_NOT_SUPPORTED;
3344 VBOXHGCMSVCPARM parm;
3345 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3346 parm.u.pointer.addr = pCmd;
3347 parm.u.pointer.size = cbCmd;
3348
3349 if (mhCrOglSvc)
3350 {
3351 VMMDev *pVMMDev = mParent->i_getVMMDev();
3352 if (pVMMDev)
3353 {
3354 /* no completion callback is specified with this call,
3355 * the CrOgl code will complete the CrHgsmi command once it processes it */
3356 rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CRHGSMI_CMD, &parm, NULL, NULL);
3357 AssertRC(rc);
3358 if (RT_SUCCESS(rc))
3359 return;
3360 }
3361 else
3362 rc = VERR_INVALID_STATE;
3363 }
3364
3365 /* we are here because something went wrong with command processing, complete it */
3366 i_handleCrHgsmiCommandCompletion(rc, SHCRGL_HOST_FN_CRHGSMI_CMD, &parm);
3367}
3368
3369void Display::i_handleCrHgsmiControlProcess(PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl)
3370{
3371 int rc = VERR_NOT_SUPPORTED;
3372 VBOXHGCMSVCPARM parm;
3373 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3374 parm.u.pointer.addr = pCtl;
3375 parm.u.pointer.size = cbCtl;
3376
3377 if (mhCrOglSvc)
3378 {
3379 VMMDev *pVMMDev = mParent->i_getVMMDev();
3380 if (pVMMDev)
3381 {
3382 bool fCheckPendingViewport = (pCtl->enmType == VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP);
3383 rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CRHGSMI_CTL, &parm,
3384 Display::i_displayCrHgsmiControlCompletion, this);
3385 AssertRC(rc);
3386 if (RT_SUCCESS(rc))
3387 {
3388 if (fCheckPendingViewport)
3389 {
3390 ULONG ul;
3391 for (ul = 0; ul < mcMonitors; ul++)
3392 {
3393 DISPLAYFBINFO *pFb = &maFramebuffers[ul];
3394 if (!pFb->pendingViewportInfo.fPending)
3395 continue;
3396
3397 rc = i_crViewportNotify(ul, pFb->pendingViewportInfo.x, pFb->pendingViewportInfo.y,
3398 pFb->pendingViewportInfo.width, pFb->pendingViewportInfo.height);
3399 if (RT_SUCCESS(rc))
3400 pFb->pendingViewportInfo.fPending = false;
3401 else
3402 {
3403 AssertMsgFailed(("crViewportNotify failed (rc=%Rrc)\n", rc));
3404 rc = VINF_SUCCESS;
3405 }
3406 }
3407 }
3408 return;
3409 }
3410 }
3411 else
3412 rc = VERR_INVALID_STATE;
3413 }
3414
3415 /* we are here because something went wrong with command processing, complete it */
3416 i_handleCrHgsmiControlCompletion(rc, SHCRGL_HOST_FN_CRHGSMI_CTL, &parm);
3417}
3418
3419DECLCALLBACK(void) Display::i_displayCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd,
3420 uint32_t cbCmd)
3421{
3422 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3423
3424 pDrv->pDisplay->i_handleCrHgsmiCommandProcess(pCmd, cbCmd);
3425}
3426
3427DECLCALLBACK(void) Display::i_displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCmd,
3428 uint32_t cbCmd)
3429{
3430 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3431
3432 pDrv->pDisplay->i_handleCrHgsmiControlProcess(pCmd, cbCmd);
3433}
3434
3435DECLCALLBACK(void) Display::i_displayCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam,
3436 void *pvContext)
3437{
3438 AssertMsgFailed(("not expected!\n"));
3439 Display *pDisplay = (Display *)pvContext;
3440 pDisplay->i_handleCrHgsmiCommandCompletion(result, u32Function, pParam);
3441}
3442
3443DECLCALLBACK(void) Display::i_displayCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam,
3444 void *pvContext)
3445{
3446 Display *pDisplay = (Display *)pvContext;
3447 pDisplay->i_handleCrHgsmiControlCompletion(result, u32Function, pParam);
3448
3449}
3450#endif
3451
3452#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
3453DECLCALLBACK(void) Display::i_displayCrHgcmCtlSubmitCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam,
3454 void *pvContext)
3455{
3456 RT_NOREF(u32Function);
3457 VBOXCRCMDCTL *pCmd = (VBOXCRCMDCTL*)pParam->u.pointer.addr;
3458 if (pCmd->u.pfnInternal)
3459 ((PFNCRCTLCOMPLETION)pCmd->u.pfnInternal)(pCmd, pParam->u.pointer.size, result, pvContext);
3460}
3461
3462int Display::i_handleCrHgcmCtlSubmit(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd,
3463 PFNCRCTLCOMPLETION pfnCompletion,
3464 void *pvCompletion)
3465{
3466 VMMDev *pVMMDev = mParent ? mParent->i_getVMMDev() : NULL;
3467 if (!pVMMDev)
3468 {
3469 AssertMsgFailed(("no vmmdev\n"));
3470 return VERR_INVALID_STATE;
3471 }
3472
3473 Assert(mhCrOglSvc);
3474 VBOXHGCMSVCPARM parm;
3475 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3476 parm.u.pointer.addr = pCmd;
3477 parm.u.pointer.size = cbCmd;
3478
3479 pCmd->u.pfnInternal = (void(*)())pfnCompletion;
3480 int rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CTL, &parm, i_displayCrHgcmCtlSubmitCompletion,
3481 pvCompletion);
3482 if (!RT_SUCCESS(rc))
3483 AssertMsgFailed(("hgcmHostFastCallAsync failed (rc=%Rrc)\n", rc));
3484
3485 return rc;
3486}
3487
3488DECLCALLBACK(int) Display::i_displayCrHgcmCtlSubmit(PPDMIDISPLAYCONNECTOR pInterface,
3489 struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd,
3490 PFNCRCTLCOMPLETION pfnCompletion,
3491 void *pvCompletion)
3492{
3493 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3494 Display *pThis = pDrv->pDisplay;
3495 return pThis->i_handleCrHgcmCtlSubmit(pCmd, cbCmd, pfnCompletion, pvCompletion);
3496}
3497
3498int Display::i_crCtlSubmit(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd, PFNCRCTLCOMPLETION pfnCompletion, void *pvCompletion)
3499{
3500 int rc = RTCritSectRwEnterShared(&mCrOglLock);
3501 if (RT_SUCCESS(rc))
3502 {
3503 if (mhCrOglSvc)
3504 rc = mpDrv->pVBVACallbacks->pfnCrCtlSubmit(mpDrv->pVBVACallbacks, pCmd, cbCmd, pfnCompletion, pvCompletion);
3505 else
3506 rc = VERR_NOT_SUPPORTED;
3507
3508 RTCritSectRwLeaveShared(&mCrOglLock);
3509 }
3510 return rc;
3511}
3512
3513int Display::i_crCtlSubmitSync(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd)
3514{
3515 int rc = RTCritSectRwEnterShared(&mCrOglLock);
3516 if (RT_SUCCESS(rc))
3517 {
3518 if (mhCrOglSvc)
3519 rc = mpDrv->pVBVACallbacks->pfnCrCtlSubmitSync(mpDrv->pVBVACallbacks, pCmd, cbCmd);
3520 else
3521 rc = VERR_NOT_SUPPORTED;
3522
3523 RTCritSectRwLeaveShared(&mCrOglLock);
3524 }
3525 return rc;
3526}
3527
3528int Display::i_crCtlSubmitAsyncCmdCopy(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd)
3529{
3530 VBOXCRCMDCTL* pCmdCopy = (VBOXCRCMDCTL*)RTMemAlloc(cbCmd);
3531 if (!pCmdCopy)
3532 {
3533 LogRel(("RTMemAlloc failed\n"));
3534 return VERR_NO_MEMORY;
3535 }
3536
3537 memcpy(pCmdCopy, pCmd, cbCmd);
3538
3539 int rc = i_crCtlSubmit(pCmdCopy, cbCmd, i_displayCrCmdFree, pCmdCopy);
3540 if (RT_FAILURE(rc))
3541 {
3542 LogRel(("crCtlSubmit failed (rc=%Rrc)\n", rc));
3543 RTMemFree(pCmdCopy);
3544 return rc;
3545 }
3546
3547 return VINF_SUCCESS;
3548}
3549
3550int Display::i_crCtlSubmitSyncIfHasDataForScreen(uint32_t u32ScreenID, struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd)
3551{
3552 int rc = RTCritSectRwEnterShared(&mCrOglLock);
3553 AssertRCReturn(rc, rc);
3554
3555 if ( mCrOglCallbacks.pfnHasDataForScreen
3556 && mCrOglCallbacks.pfnHasDataForScreen(u32ScreenID))
3557 rc = i_crCtlSubmitSync(pCmd, cbCmd);
3558 else
3559 rc = i_crCtlSubmitAsyncCmdCopy(pCmd, cbCmd);
3560
3561 RTCritSectRwLeaveShared(&mCrOglLock);
3562
3563 return rc;
3564}
3565
3566bool Display::i_handleCrVRecScreenshotBegin(uint32_t uScreen, uint64_t u64Timestamp)
3567{
3568 /** @todo r=bird: u64Timestamp - using the 'u64' prefix add nothing.
3569 * However, using one of the prefixes indicating the timestamp unit
3570 * would be very valuable! */
3571# if VBOX_WITH_VPX
3572 return VideoRecIsReady(mpVideoRecCtx, uScreen, u64Timestamp);
3573# else
3574 RT_NOREF(uScreen, u64Timestamp);
3575 return false;
3576# endif
3577}
3578
3579void Display::i_handleCrVRecScreenshotEnd(uint32_t uScreen, uint64_t u64Timestamp)
3580{
3581 RT_NOREF(uScreen, u64Timestamp);
3582}
3583
3584void Display::i_handleCrVRecScreenshotPerform(uint32_t uScreen,
3585 uint32_t x, uint32_t y, uint32_t uPixelFormat,
3586 uint32_t uBitsPerPixel, uint32_t uBytesPerLine,
3587 uint32_t uGuestWidth, uint32_t uGuestHeight,
3588 uint8_t *pu8BufferAddress, uint64_t u64Timestamp)
3589{
3590 Assert(mfCrOglVideoRecState == CRVREC_STATE_SUBMITTED);
3591# if VBOX_WITH_VPX
3592 int rc = VideoRecCopyToIntBuf(mpVideoRecCtx, uScreen, x, y,
3593 uPixelFormat,
3594 uBitsPerPixel, uBytesPerLine,
3595 uGuestWidth, uGuestHeight,
3596 pu8BufferAddress, u64Timestamp);
3597 NOREF(rc);
3598 Assert(rc == VINF_SUCCESS /* || rc == VERR_TRY_AGAIN || rc == VINF_TRY_AGAIN*/);
3599# endif
3600}
3601
3602void Display::i_handleVRecCompletion()
3603{
3604 Assert(mfCrOglVideoRecState == CRVREC_STATE_SUBMITTED);
3605 ASMAtomicWriteU32(&mfCrOglVideoRecState, CRVREC_STATE_IDLE);
3606}
3607
3608#endif /* VBOX_WITH_HGCM && VBOX_WITH_CROGL */
3609
3610HRESULT Display::notifyScaleFactorChange(ULONG aScreenId, ULONG aScaleFactorWMultiplied, ULONG aScaleFactorHMultiplied)
3611{
3612#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
3613 HRESULT hr = E_UNEXPECTED;
3614
3615 if (aScreenId >= mcMonitors)
3616 return E_INVALIDARG;
3617
3618 /* 3D acceleration enabled in VM config. */
3619 if (mfIsCr3DEnabled)
3620 {
3621 /* VBoxSharedCrOpenGL HGCM host service is running. */
3622 if (mhCrOglSvc)
3623 {
3624 VMMDev *pVMMDev = mParent->i_getVMMDev();
3625 if (pVMMDev)
3626 {
3627 VBOXCRCMDCTL_HGCM *pCtl;
3628 pCtl = (VBOXCRCMDCTL_HGCM *)RTMemAlloc(sizeof(CRVBOXHGCMSETSCALEFACTOR) + sizeof(VBOXCRCMDCTL_HGCM));
3629 if (pCtl)
3630 {
3631 CRVBOXHGCMSETSCALEFACTOR *pData = (CRVBOXHGCMSETSCALEFACTOR *)(pCtl + 1);
3632 int rc;
3633
3634 pData->u32Screen = aScreenId;
3635 pData->u32ScaleFactorWMultiplied = aScaleFactorWMultiplied;
3636 pData->u32ScaleFactorHMultiplied = aScaleFactorHMultiplied;
3637
3638 pCtl->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
3639 pCtl->Hdr.u32Function = SHCRGL_HOST_FN_SET_SCALE_FACTOR;
3640 pCtl->aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
3641 pCtl->aParms[0].u.pointer.addr = pData;
3642 pCtl->aParms[0].u.pointer.size = sizeof(*pData);
3643
3644 rc = i_crCtlSubmitSync(&pCtl->Hdr, sizeof(*pCtl));
3645 if (RT_FAILURE(rc))
3646 AssertMsgFailed(("crCtlSubmitSync failed (rc=%Rrc)\n", rc));
3647 else
3648 hr = S_OK;
3649
3650 RTMemFree(pCtl);
3651 }
3652 else
3653 {
3654 LogRel(("Running out of memory on attempt to set OpenGL content scale factor. Ignored.\n"));
3655 hr = E_OUTOFMEMORY;
3656 }
3657 }
3658 else
3659 LogRel(("Internal error occurred on attempt to set OpenGL content scale factor. Ignored.\n"));
3660 }
3661 else
3662 LogRel(("Attempt to specify OpenGL content scale factor while corresponding HGCM host service not yet runing. Ignored.\n"));
3663 }
3664 else
3665# if 0 /** @todo Thank you so very much from anyone using VMSVGA3d! */
3666 AssertMsgFailed(("Attempt to specify OpenGL content scale factor while 3D acceleration is disabled in VM config. Ignored.\n"));
3667# else
3668 {
3669 hr = S_OK;
3670 /* Need an interface like this here (and the #ifdefs needs adjusting):
3671 PPDMIDISPLAYPORT pUpPort = mpDrv ? mpDrv->pUpPort : NULL;
3672 if (pUpPort && pUpPort->pfnSetScaleFactor)
3673 pUpPort->pfnSetScaleFactor(pUpPort, aScreeId, aScaleFactorWMultiplied, aScaleFactorHMultiplied); */
3674 }
3675# endif
3676
3677 return hr;
3678#else
3679 AssertMsgFailed(("Attempt to specify OpenGL content scale factor while corresponding functionality is disabled."));
3680 return E_UNEXPECTED;
3681#endif /* VBOX_WITH_HGCM && VBOX_WITH_CROGL */
3682}
3683
3684HRESULT Display::notifyHiDPIOutputPolicyChange(BOOL fUnscaledHiDPI)
3685{
3686#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
3687 HRESULT hr = E_UNEXPECTED;
3688
3689 /* 3D acceleration enabled in VM config. */
3690 if (mfIsCr3DEnabled)
3691 {
3692 /* VBoxSharedCrOpenGL HGCM host service is running. */
3693 if (mhCrOglSvc)
3694 {
3695 VMMDev *pVMMDev = mParent->i_getVMMDev();
3696 if (pVMMDev)
3697 {
3698 VBOXCRCMDCTL_HGCM *pCtl;
3699 pCtl = (VBOXCRCMDCTL_HGCM *)RTMemAlloc(sizeof(CRVBOXHGCMSETUNSCALEDHIDPIOUTPUT) + sizeof(VBOXCRCMDCTL_HGCM));
3700 if (pCtl)
3701 {
3702 CRVBOXHGCMSETUNSCALEDHIDPIOUTPUT *pData = (CRVBOXHGCMSETUNSCALEDHIDPIOUTPUT *)(pCtl + 1);
3703 int rc;
3704
3705 pData->fUnscaledHiDPI = RT_BOOL(fUnscaledHiDPI);
3706
3707 pCtl->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
3708 pCtl->Hdr.u32Function = SHCRGL_HOST_FN_SET_UNSCALED_HIDPI;
3709 pCtl->aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
3710 pCtl->aParms[0].u.pointer.addr = pData;
3711 pCtl->aParms[0].u.pointer.size = sizeof(*pData);
3712
3713 rc = i_crCtlSubmitSync(&pCtl->Hdr, sizeof(*pCtl));
3714 if (RT_FAILURE(rc))
3715 AssertMsgFailed(("crCtlSubmitSync failed (rc=%Rrc)\n", rc));
3716 else
3717 hr = S_OK;
3718
3719 RTMemFree(pCtl);
3720 }
3721 else
3722 {
3723 LogRel(("Running out of memory on attempt to notify OpenGL about HiDPI output scaling policy change. Ignored.\n"));
3724 hr = E_OUTOFMEMORY;
3725 }
3726 }
3727 else
3728 LogRel(("Internal error occurred on attempt to notify OpenGL about HiDPI output scaling policy change. Ignored.\n"));
3729 }
3730 else
3731 LogRel(("Attempt to notify OpenGL about HiDPI output scaling policy change while corresponding HGCM host service not yet runing. Ignored.\n"));
3732 }
3733 else
3734 {
3735 hr = S_OK;
3736 /* Need an interface like this here (and the #ifdefs needs adjusting):
3737 PPDMIDISPLAYPORT pUpPort = mpDrv ? mpDrv->pUpPort : NULL;
3738 if (pUpPort && pUpPort->pfnSetScaleFactor)
3739 pUpPort->pfnSetScaleFactor(pUpPort, aScreeId, aScaleFactorWMultiplied, aScaleFactorHMultiplied); */
3740 }
3741
3742 return hr;
3743#else
3744 AssertMsgFailed(("Attempt to notify OpenGL about HiDPI output scaling policy change while corresponding functionality is disabled."));
3745 return E_UNEXPECTED;
3746#endif /* VBOX_WITH_HGCM && VBOX_WITH_CROGL */
3747}
3748
3749#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
3750DECLCALLBACK(void) Display::i_displayCrVRecScreenshotPerform(void *pvCtx, uint32_t uScreen,
3751 uint32_t x, uint32_t y,
3752 uint32_t uBitsPerPixel, uint32_t uBytesPerLine,
3753 uint32_t uGuestWidth, uint32_t uGuestHeight,
3754 uint8_t *pu8BufferAddress, uint64_t u64Timestamp)
3755{
3756 Display *pDisplay = (Display *)pvCtx;
3757 pDisplay->i_handleCrVRecScreenshotPerform(uScreen,
3758 x, y, BitmapFormat_BGR, uBitsPerPixel,
3759 uBytesPerLine, uGuestWidth, uGuestHeight,
3760 pu8BufferAddress, u64Timestamp);
3761}
3762
3763DECLCALLBACK(bool) Display::i_displayCrVRecScreenshotBegin(void *pvCtx, uint32_t uScreen, uint64_t u64Timestamp)
3764{
3765 Display *pDisplay = (Display *)pvCtx;
3766 return pDisplay->i_handleCrVRecScreenshotBegin(uScreen, u64Timestamp);
3767}
3768
3769DECLCALLBACK(void) Display::i_displayCrVRecScreenshotEnd(void *pvCtx, uint32_t uScreen, uint64_t u64Timestamp)
3770{
3771 Display *pDisplay = (Display *)pvCtx;
3772 pDisplay->i_handleCrVRecScreenshotEnd(uScreen, u64Timestamp);
3773}
3774
3775DECLCALLBACK(void) Display::i_displayVRecCompletion(struct VBOXCRCMDCTL *pCmd, uint32_t cbCmd, int rc, void *pvCompletion)
3776{
3777 RT_NOREF(pCmd, cbCmd, rc);
3778 Display *pDisplay = (Display *)pvCompletion;
3779 pDisplay->i_handleVRecCompletion();
3780}
3781
3782#endif
3783
3784
3785#ifdef VBOX_WITH_HGSMI
3786DECLCALLBACK(int) Display::i_displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags,
3787 bool fRenderThreadMode)
3788{
3789 LogRelFlowFunc(("uScreenId %d\n", uScreenId));
3790
3791 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3792 Display *pThis = pDrv->pDisplay;
3793
3794 if (pThis->maFramebuffers[uScreenId].fVBVAEnabled && pThis->maFramebuffers[uScreenId].fRenderThreadMode != fRenderThreadMode)
3795 {
3796 LogRel(("Enabling different vbva mode\n"));
3797#ifdef DEBUG_misha
3798 AssertMsgFailed(("enabling different vbva mode\n"));
3799#endif
3800 return VERR_INVALID_STATE;
3801 }
3802
3803 pThis->maFramebuffers[uScreenId].fVBVAEnabled = true;
3804 pThis->maFramebuffers[uScreenId].pVBVAHostFlags = pHostFlags;
3805 pThis->maFramebuffers[uScreenId].fRenderThreadMode = fRenderThreadMode;
3806 pThis->maFramebuffers[uScreenId].fVBVAForceResize = true;
3807
3808 vbvaSetMemoryFlagsHGSMI(uScreenId, pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, &pThis->maFramebuffers[uScreenId]);
3809
3810 return VINF_SUCCESS;
3811}
3812
3813DECLCALLBACK(void) Display::i_displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3814{
3815 LogRelFlowFunc(("uScreenId %d\n", uScreenId));
3816
3817 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3818 Display *pThis = pDrv->pDisplay;
3819
3820 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3821
3822 bool fRenderThreadMode = pFBInfo->fRenderThreadMode;
3823
3824 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3825 {
3826 /* Make sure that the primary screen is visible now.
3827 * The guest can't use VBVA anymore, so only only the VGA device output works.
3828 */
3829 if (pFBInfo->fDisabled)
3830 {
3831 pFBInfo->fDisabled = false;
3832 fireGuestMonitorChangedEvent(pThis->mParent->i_getEventSource(),
3833 GuestMonitorChangedEventType_Enabled,
3834 uScreenId,
3835 pFBInfo->xOrigin, pFBInfo->yOrigin,
3836 pFBInfo->w, pFBInfo->h);
3837 }
3838 }
3839
3840 pFBInfo->fVBVAEnabled = false;
3841 pFBInfo->fVBVAForceResize = false;
3842 pFBInfo->fRenderThreadMode = false;
3843
3844 vbvaSetMemoryFlagsHGSMI(uScreenId, 0, false, pFBInfo);
3845
3846 pFBInfo->pVBVAHostFlags = NULL;
3847
3848 if (!fRenderThreadMode && uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3849 {
3850 /* Force full screen update, because VGA device must take control, do resize, etc. */
3851 pThis->mpDrv->pUpPort->pfnUpdateDisplayAll(pThis->mpDrv->pUpPort, /* fFailOnResize = */ false);
3852 }
3853}
3854
3855DECLCALLBACK(void) Display::i_displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3856{
3857 RT_NOREF(uScreenId);
3858 LogFlowFunc(("uScreenId %d\n", uScreenId));
3859
3860 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3861 Display *pThis = pDrv->pDisplay;
3862
3863 if (ASMAtomicReadU32(&pThis->mu32UpdateVBVAFlags) > 0)
3864 {
3865 vbvaSetMemoryFlagsAllHGSMI(pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, pThis->maFramebuffers,
3866 pThis->mcMonitors);
3867 ASMAtomicDecU32(&pThis->mu32UpdateVBVAFlags);
3868 }
3869}
3870
3871DECLCALLBACK(void) Display::i_displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId,
3872 const PVBVACMDHDR pCmd, size_t cbCmd)
3873{
3874 LogFlowFunc(("uScreenId %d pCmd %p cbCmd %d, @%d,%d %dx%d\n", uScreenId, pCmd, cbCmd, pCmd->x, pCmd->y, pCmd->w, pCmd->h));
3875
3876 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3877 Display *pThis = pDrv->pDisplay;
3878 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3879
3880 if (pFBInfo->fDefaultFormat)
3881 {
3882 /* Make sure that framebuffer contains the same image as the guest VRAM. */
3883 if ( uScreenId == VBOX_VIDEO_PRIMARY_SCREEN
3884 && !pFBInfo->fDisabled)
3885 {
3886 pDrv->pUpPort->pfnUpdateDisplayRect(pDrv->pUpPort, pCmd->x, pCmd->y, pCmd->w, pCmd->h);
3887 }
3888 else if ( !pFBInfo->pSourceBitmap.isNull()
3889 && !pFBInfo->fDisabled)
3890 {
3891 /* Render VRAM content to the framebuffer. */
3892 BYTE *pAddress = NULL;
3893 ULONG ulWidth = 0;
3894 ULONG ulHeight = 0;
3895 ULONG ulBitsPerPixel = 0;
3896 ULONG ulBytesPerLine = 0;
3897 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
3898
3899 HRESULT hrc = pFBInfo->pSourceBitmap->QueryBitmapInfo(&pAddress,
3900 &ulWidth,
3901 &ulHeight,
3902 &ulBitsPerPixel,
3903 &ulBytesPerLine,
3904 &bitmapFormat);
3905 if (SUCCEEDED(hrc))
3906 {
3907 uint32_t width = pCmd->w;
3908 uint32_t height = pCmd->h;
3909
3910 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
3911 int32_t xSrc = pCmd->x - pFBInfo->xOrigin;
3912 int32_t ySrc = pCmd->y - pFBInfo->yOrigin;
3913 uint32_t u32SrcWidth = pFBInfo->w;
3914 uint32_t u32SrcHeight = pFBInfo->h;
3915 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
3916 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
3917
3918 uint8_t *pu8Dst = pAddress;
3919 int32_t xDst = xSrc;
3920 int32_t yDst = ySrc;
3921 uint32_t u32DstWidth = u32SrcWidth;
3922 uint32_t u32DstHeight = u32SrcHeight;
3923 uint32_t u32DstLineSize = u32DstWidth * 4;
3924 uint32_t u32DstBitsPerPixel = 32;
3925
3926 pDrv->pUpPort->pfnCopyRect(pDrv->pUpPort,
3927 width, height,
3928 pu8Src,
3929 xSrc, ySrc,
3930 u32SrcWidth, u32SrcHeight,
3931 u32SrcLineSize, u32SrcBitsPerPixel,
3932 pu8Dst,
3933 xDst, yDst,
3934 u32DstWidth, u32DstHeight,
3935 u32DstLineSize, u32DstBitsPerPixel);
3936 }
3937 }
3938 }
3939
3940 VBVACMDHDR hdrSaved = *pCmd;
3941
3942 VBVACMDHDR *pHdrUnconst = (VBVACMDHDR *)pCmd;
3943
3944 pHdrUnconst->x -= (int16_t)pFBInfo->xOrigin;
3945 pHdrUnconst->y -= (int16_t)pFBInfo->yOrigin;
3946
3947 /* @todo new SendUpdate entry which can get a separate cmd header or coords. */
3948 pThis->mParent->i_consoleVRDPServer()->SendUpdate(uScreenId, pCmd, (uint32_t)cbCmd);
3949
3950 *pHdrUnconst = hdrSaved;
3951}
3952
3953DECLCALLBACK(void) Display::i_displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y,
3954 uint32_t cx, uint32_t cy)
3955{
3956 LogFlowFunc(("uScreenId %d %d,%d %dx%d\n", uScreenId, x, y, cx, cy));
3957
3958 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3959 Display *pThis = pDrv->pDisplay;
3960 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3961
3962 /* @todo handleFramebufferUpdate (uScreenId,
3963 * x - pThis->maFramebuffers[uScreenId].xOrigin,
3964 * y - pThis->maFramebuffers[uScreenId].yOrigin,
3965 * cx, cy);
3966 */
3967 pThis->i_handleDisplayUpdate(uScreenId, x - pFBInfo->xOrigin, y - pFBInfo->yOrigin, cx, cy);
3968}
3969
3970#ifdef DEBUG_sunlover
3971static void logVBVAResize(const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, const DISPLAYFBINFO *pFBInfo)
3972{
3973 LogRel(("displayVBVAResize: [%d] %s\n"
3974 " pView->u32ViewIndex %d\n"
3975 " pView->u32ViewOffset 0x%08X\n"
3976 " pView->u32ViewSize 0x%08X\n"
3977 " pView->u32MaxScreenSize 0x%08X\n"
3978 " pScreen->i32OriginX %d\n"
3979 " pScreen->i32OriginY %d\n"
3980 " pScreen->u32StartOffset 0x%08X\n"
3981 " pScreen->u32LineSize 0x%08X\n"
3982 " pScreen->u32Width %d\n"
3983 " pScreen->u32Height %d\n"
3984 " pScreen->u16BitsPerPixel %d\n"
3985 " pScreen->u16Flags 0x%04X\n"
3986 " pFBInfo->u32Offset 0x%08X\n"
3987 " pFBInfo->u32MaxFramebufferSize 0x%08X\n"
3988 " pFBInfo->u32InformationSize 0x%08X\n"
3989 " pFBInfo->fDisabled %d\n"
3990 " xOrigin, yOrigin, w, h: %d,%d %dx%d\n"
3991 " pFBInfo->u16BitsPerPixel %d\n"
3992 " pFBInfo->pu8FramebufferVRAM %p\n"
3993 " pFBInfo->u32LineSize 0x%08X\n"
3994 " pFBInfo->flags 0x%04X\n"
3995 " pFBInfo->pHostEvents %p\n"
3996 " pFBInfo->fDefaultFormat %d\n"
3997 " pFBInfo->fVBVAEnabled %d\n"
3998 " pFBInfo->fVBVAForceResize %d\n"
3999 " pFBInfo->pVBVAHostFlags %p\n"
4000 "",
4001 pScreen->u32ViewIndex,
4002 (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)? "DISABLED": "ENABLED",
4003 pView->u32ViewIndex,
4004 pView->u32ViewOffset,
4005 pView->u32ViewSize,
4006 pView->u32MaxScreenSize,
4007 pScreen->i32OriginX,
4008 pScreen->i32OriginY,
4009 pScreen->u32StartOffset,
4010 pScreen->u32LineSize,
4011 pScreen->u32Width,
4012 pScreen->u32Height,
4013 pScreen->u16BitsPerPixel,
4014 pScreen->u16Flags,
4015 pFBInfo->u32Offset,
4016 pFBInfo->u32MaxFramebufferSize,
4017 pFBInfo->u32InformationSize,
4018 pFBInfo->fDisabled,
4019 pFBInfo->xOrigin,
4020 pFBInfo->yOrigin,
4021 pFBInfo->w,
4022 pFBInfo->h,
4023 pFBInfo->u16BitsPerPixel,
4024 pFBInfo->pu8FramebufferVRAM,
4025 pFBInfo->u32LineSize,
4026 pFBInfo->flags,
4027 pFBInfo->pHostEvents,
4028 pFBInfo->fDefaultFormat,
4029 pFBInfo->fVBVAEnabled,
4030 pFBInfo->fVBVAForceResize,
4031 pFBInfo->pVBVAHostFlags
4032 ));
4033}
4034#endif /* DEBUG_sunlover */
4035
4036DECLCALLBACK(int) Display::i_displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView,
4037 const PVBVAINFOSCREEN pScreen, void *pvVRAM, bool fResetInputMapping)
4038{
4039 LogRelFlowFunc(("pScreen %p, pvVRAM %p\n", pScreen, pvVRAM));
4040
4041 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
4042 Display *pThis = pDrv->pDisplay;
4043
4044 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[pScreen->u32ViewIndex];
4045
4046 if (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)
4047 {
4048 pThis->i_notifyCroglResize(pView, pScreen, pvVRAM);
4049
4050 pFBInfo->fDisabled = true;
4051 pFBInfo->flags = pScreen->u16Flags;
4052
4053 /* Ask the framebuffer to resize using a default format. The framebuffer will be black.
4054 * So if the frontend does not support GuestMonitorChangedEventType_Disabled event,
4055 * the VM window will be black. */
4056 uint32_t u32Width = pFBInfo->w ? pFBInfo->w : 640;
4057 uint32_t u32Height = pFBInfo->h ? pFBInfo->h : 480;
4058 pThis->i_handleDisplayResize(pScreen->u32ViewIndex, 0, (uint8_t *)NULL, 0,
4059 u32Width, u32Height, pScreen->u16Flags);
4060
4061 fireGuestMonitorChangedEvent(pThis->mParent->i_getEventSource(),
4062 GuestMonitorChangedEventType_Disabled,
4063 pScreen->u32ViewIndex,
4064 0, 0, 0, 0);
4065 return VINF_SUCCESS;
4066 }
4067
4068 /* If display was disabled or there is no framebuffer, a resize will be required,
4069 * because the framebuffer was/will be changed.
4070 */
4071 bool fResize = pFBInfo->fDisabled || pFBInfo->pFramebuffer.isNull();
4072
4073 if (pFBInfo->fVBVAForceResize)
4074 {
4075 /* VBVA was just enabled. Do the resize. */
4076 fResize = true;
4077 pFBInfo->fVBVAForceResize = false;
4078 }
4079
4080 /* If the screen if blanked, then do a resize request to make sure that the framebuffer
4081 * switches to the default format.
4082 */
4083 fResize = fResize || RT_BOOL((pScreen->u16Flags ^ pFBInfo->flags) & VBVA_SCREEN_F_BLANK);
4084
4085 /* Check if this is a real resize or a notification about the screen origin.
4086 * The guest uses this VBVAResize call for both.
4087 */
4088 fResize = fResize
4089 || pFBInfo->u16BitsPerPixel != pScreen->u16BitsPerPixel
4090 || pFBInfo->pu8FramebufferVRAM != (uint8_t *)pvVRAM + pScreen->u32StartOffset
4091 || pFBInfo->u32LineSize != pScreen->u32LineSize
4092 || pFBInfo->w != pScreen->u32Width
4093 || pFBInfo->h != pScreen->u32Height;
4094
4095 bool fNewOrigin = pFBInfo->xOrigin != pScreen->i32OriginX
4096 || pFBInfo->yOrigin != pScreen->i32OriginY;
4097
4098 if (fNewOrigin || fResize)
4099 pThis->i_notifyCroglResize(pView, pScreen, pvVRAM);
4100
4101 if (pFBInfo->fDisabled)
4102 {
4103 pFBInfo->fDisabled = false;
4104 fireGuestMonitorChangedEvent(pThis->mParent->i_getEventSource(),
4105 GuestMonitorChangedEventType_Enabled,
4106 pScreen->u32ViewIndex,
4107 pScreen->i32OriginX, pScreen->i32OriginY,
4108 pScreen->u32Width, pScreen->u32Height);
4109 /* Continue to update pFBInfo. */
4110 }
4111
4112 pFBInfo->u32Offset = pView->u32ViewOffset; /* Not used in HGSMI. */
4113 pFBInfo->u32MaxFramebufferSize = pView->u32MaxScreenSize; /* Not used in HGSMI. */
4114 pFBInfo->u32InformationSize = 0; /* Not used in HGSMI. */
4115
4116 pFBInfo->xOrigin = pScreen->i32OriginX;
4117 pFBInfo->yOrigin = pScreen->i32OriginY;
4118
4119 pFBInfo->w = pScreen->u32Width;
4120 pFBInfo->h = pScreen->u32Height;
4121
4122 pFBInfo->u16BitsPerPixel = pScreen->u16BitsPerPixel;
4123 pFBInfo->pu8FramebufferVRAM = (uint8_t *)pvVRAM + pScreen->u32StartOffset;
4124 pFBInfo->u32LineSize = pScreen->u32LineSize;
4125
4126 pFBInfo->flags = pScreen->u16Flags;
4127
4128 if (fResetInputMapping)
4129 {
4130 pThis->xInputMappingOrigin = 0;
4131 pThis->yInputMappingOrigin = 0;
4132 pThis->cxInputMapping = 0;
4133 pThis->cyInputMapping = 0;
4134 }
4135
4136 if (fNewOrigin)
4137 {
4138 fireGuestMonitorChangedEvent(pThis->mParent->i_getEventSource(),
4139 GuestMonitorChangedEventType_NewOrigin,
4140 pScreen->u32ViewIndex,
4141 pScreen->i32OriginX, pScreen->i32OriginY,
4142 0, 0);
4143 }
4144
4145 if (!fResize)
4146 {
4147 /* No parameters of the framebuffer have actually changed. */
4148 if (fNewOrigin)
4149 {
4150 /* VRDP server still need this notification. */
4151 LogRelFlowFunc(("Calling VRDP\n"));
4152 pThis->mParent->i_consoleVRDPServer()->SendResize();
4153 }
4154 return VINF_SUCCESS;
4155 }
4156
4157 /* Do a regular resize. */
4158 return pThis->i_handleDisplayResize(pScreen->u32ViewIndex, pScreen->u16BitsPerPixel,
4159 (uint8_t *)pvVRAM + pScreen->u32StartOffset,
4160 pScreen->u32LineSize, pScreen->u32Width, pScreen->u32Height, pScreen->u16Flags);
4161}
4162
4163DECLCALLBACK(int) Display::i_displayVBVAMousePointerShape(PPDMIDISPLAYCONNECTOR pInterface, bool fVisible, bool fAlpha,
4164 uint32_t xHot, uint32_t yHot,
4165 uint32_t cx, uint32_t cy,
4166 const void *pvShape)
4167{
4168 LogFlowFunc(("\n"));
4169
4170 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
4171
4172 uint32_t cbShape = 0;
4173 if (pvShape)
4174 {
4175 cbShape = (cx + 7) / 8 * cy; /* size of the AND mask */
4176 cbShape = ((cbShape + 3) & ~3) + cx * 4 * cy; /* + gap + size of the XOR mask */
4177 }
4178
4179 /* Tell the console about it */
4180 pDrv->pDisplay->mParent->i_onMousePointerShapeChange(fVisible, fAlpha,
4181 xHot, yHot, cx, cy, (uint8_t *)pvShape, cbShape);
4182
4183 return VINF_SUCCESS;
4184}
4185
4186DECLCALLBACK(void) Display::i_displayVBVAGuestCapabilityUpdate(PPDMIDISPLAYCONNECTOR pInterface, uint32_t fCapabilities)
4187{
4188 LogFlowFunc(("\n"));
4189
4190 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
4191 Display *pThis = pDrv->pDisplay;
4192
4193 pThis->i_handleUpdateGuestVBVACapabilities(fCapabilities);
4194}
4195
4196DECLCALLBACK(void) Display::i_displayVBVAInputMappingUpdate(PPDMIDISPLAYCONNECTOR pInterface, int32_t xOrigin, int32_t yOrigin,
4197 uint32_t cx, uint32_t cy)
4198{
4199 LogFlowFunc(("\n"));
4200
4201 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
4202 Display *pThis = pDrv->pDisplay;
4203
4204 pThis->i_handleUpdateVBVAInputMapping(xOrigin, yOrigin, cx, cy);
4205}
4206
4207#endif /* VBOX_WITH_HGSMI */
4208
4209/**
4210 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
4211 */
4212DECLCALLBACK(void *) Display::i_drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
4213{
4214 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
4215 PDRVMAINDISPLAY pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
4216 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
4217 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIDISPLAYCONNECTOR, &pDrv->IConnector);
4218 return NULL;
4219}
4220
4221
4222/**
4223 * Destruct a display driver instance.
4224 *
4225 * @returns VBox status code.
4226 * @param pDrvIns The driver instance data.
4227 */
4228DECLCALLBACK(void) Display::i_drvDestruct(PPDMDRVINS pDrvIns)
4229{
4230 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
4231 PDRVMAINDISPLAY pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
4232 LogRelFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
4233
4234 pThis->pUpPort->pfnSetRenderVRAM(pThis->pUpPort, false);
4235
4236 pThis->IConnector.pbData = NULL;
4237 pThis->IConnector.cbScanline = 0;
4238 pThis->IConnector.cBits = 32;
4239 pThis->IConnector.cx = 0;
4240 pThis->IConnector.cy = 0;
4241
4242 if (pThis->pDisplay)
4243 {
4244 AutoWriteLock displayLock(pThis->pDisplay COMMA_LOCKVAL_SRC_POS);
4245#ifdef VBOX_WITH_VPX
4246 pThis->pDisplay->i_VideoCaptureStop();
4247#endif
4248#ifdef VBOX_WITH_CRHGSMI
4249 pThis->pDisplay->i_destructCrHgsmiData();
4250#endif
4251 pThis->pDisplay->mpDrv = NULL;
4252 pThis->pDisplay->mpVMMDev = NULL;
4253 }
4254}
4255
4256
4257/**
4258 * Construct a display driver instance.
4259 *
4260 * @copydoc FNPDMDRVCONSTRUCT
4261 */
4262DECLCALLBACK(int) Display::i_drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
4263{
4264 RT_NOREF(fFlags);
4265 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
4266 PDRVMAINDISPLAY pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
4267 LogRelFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
4268
4269 /*
4270 * Validate configuration.
4271 */
4272 if (!CFGMR3AreValuesValid(pCfg, "Object\0"))
4273 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
4274 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
4275 ("Configuration error: Not possible to attach anything to this driver!\n"),
4276 VERR_PDM_DRVINS_NO_ATTACH);
4277
4278 /*
4279 * Init Interfaces.
4280 */
4281 pDrvIns->IBase.pfnQueryInterface = Display::i_drvQueryInterface;
4282
4283 pThis->IConnector.pfnResize = Display::i_displayResizeCallback;
4284 pThis->IConnector.pfnUpdateRect = Display::i_displayUpdateCallback;
4285 pThis->IConnector.pfnRefresh = Display::i_displayRefreshCallback;
4286 pThis->IConnector.pfnReset = Display::i_displayResetCallback;
4287 pThis->IConnector.pfnLFBModeChange = Display::i_displayLFBModeChangeCallback;
4288 pThis->IConnector.pfnProcessAdapterData = Display::i_displayProcessAdapterDataCallback;
4289 pThis->IConnector.pfnProcessDisplayData = Display::i_displayProcessDisplayDataCallback;
4290#ifdef VBOX_WITH_VIDEOHWACCEL
4291 pThis->IConnector.pfnVHWACommandProcess = Display::i_displayVHWACommandProcess;
4292#endif
4293#ifdef VBOX_WITH_CRHGSMI
4294 pThis->IConnector.pfnCrHgsmiCommandProcess = Display::i_displayCrHgsmiCommandProcess;
4295 pThis->IConnector.pfnCrHgsmiControlProcess = Display::i_displayCrHgsmiControlProcess;
4296#endif
4297#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
4298 pThis->IConnector.pfnCrHgcmCtlSubmit = Display::i_displayCrHgcmCtlSubmit;
4299#endif
4300#ifdef VBOX_WITH_HGSMI
4301 pThis->IConnector.pfnVBVAEnable = Display::i_displayVBVAEnable;
4302 pThis->IConnector.pfnVBVADisable = Display::i_displayVBVADisable;
4303 pThis->IConnector.pfnVBVAUpdateBegin = Display::i_displayVBVAUpdateBegin;
4304 pThis->IConnector.pfnVBVAUpdateProcess = Display::i_displayVBVAUpdateProcess;
4305 pThis->IConnector.pfnVBVAUpdateEnd = Display::i_displayVBVAUpdateEnd;
4306 pThis->IConnector.pfnVBVAResize = Display::i_displayVBVAResize;
4307 pThis->IConnector.pfnVBVAMousePointerShape = Display::i_displayVBVAMousePointerShape;
4308 pThis->IConnector.pfnVBVAGuestCapabilityUpdate = Display::i_displayVBVAGuestCapabilityUpdate;
4309 pThis->IConnector.pfnVBVAInputMappingUpdate = Display::i_displayVBVAInputMappingUpdate;
4310#endif
4311
4312 /*
4313 * Get the IDisplayPort interface of the above driver/device.
4314 */
4315 pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYPORT);
4316 if (!pThis->pUpPort)
4317 {
4318 AssertMsgFailed(("Configuration error: No display port interface above!\n"));
4319 return VERR_PDM_MISSING_INTERFACE_ABOVE;
4320 }
4321#if defined(VBOX_WITH_VIDEOHWACCEL) || defined(VBOX_WITH_CRHGSMI)
4322 pThis->pVBVACallbacks = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYVBVACALLBACKS);
4323 if (!pThis->pVBVACallbacks)
4324 {
4325 AssertMsgFailed(("Configuration error: No VBVA callback interface above!\n"));
4326 return VERR_PDM_MISSING_INTERFACE_ABOVE;
4327 }
4328#endif
4329 /*
4330 * Get the Display object pointer and update the mpDrv member.
4331 */
4332 void *pv;
4333 int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
4334 if (RT_FAILURE(rc))
4335 {
4336 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
4337 return rc;
4338 }
4339 Display *pDisplay = (Display *)pv; /** @todo Check this cast! */
4340 pThis->pDisplay = pDisplay;
4341 pThis->pDisplay->mpDrv = pThis;
4342
4343 /* Disable VRAM to a buffer copy initially. */
4344 pThis->pUpPort->pfnSetRenderVRAM(pThis->pUpPort, false);
4345 pThis->IConnector.cBits = 32; /* DevVGA does nothing otherwise. */
4346
4347 /*
4348 * Start periodic screen refreshes
4349 */
4350 pThis->pUpPort->pfnSetRefreshRate(pThis->pUpPort, 20);
4351
4352#ifdef VBOX_WITH_CRHGSMI
4353 pDisplay->i_setupCrHgsmiData();
4354#endif
4355
4356#ifdef VBOX_WITH_VPX
4357 ComPtr<IMachine> pMachine = pDisplay->mParent->i_machine();
4358 BOOL fEnabled = false;
4359 HRESULT hrc = pMachine->COMGETTER(VideoCaptureEnabled)(&fEnabled);
4360 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
4361 if (fEnabled)
4362 {
4363 rc = pDisplay->i_VideoCaptureStart();
4364 fireVideoCaptureChangedEvent(pDisplay->mParent->i_getEventSource());
4365 }
4366#endif
4367
4368 return rc;
4369}
4370
4371
4372/**
4373 * Display driver registration record.
4374 */
4375const PDMDRVREG Display::DrvReg =
4376{
4377 /* u32Version */
4378 PDM_DRVREG_VERSION,
4379 /* szName */
4380 "MainDisplay",
4381 /* szRCMod */
4382 "",
4383 /* szR0Mod */
4384 "",
4385 /* pszDescription */
4386 "Main display driver (Main as in the API).",
4387 /* fFlags */
4388 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
4389 /* fClass. */
4390 PDM_DRVREG_CLASS_DISPLAY,
4391 /* cMaxInstances */
4392 ~0U,
4393 /* cbInstance */
4394 sizeof(DRVMAINDISPLAY),
4395 /* pfnConstruct */
4396 Display::i_drvConstruct,
4397 /* pfnDestruct */
4398 Display::i_drvDestruct,
4399 /* pfnRelocate */
4400 NULL,
4401 /* pfnIOCtl */
4402 NULL,
4403 /* pfnPowerOn */
4404 NULL,
4405 /* pfnReset */
4406 NULL,
4407 /* pfnSuspend */
4408 NULL,
4409 /* pfnResume */
4410 NULL,
4411 /* pfnAttach */
4412 NULL,
4413 /* pfnDetach */
4414 NULL,
4415 /* pfnPowerOff */
4416 NULL,
4417 /* pfnSoftReset */
4418 NULL,
4419 /* u32EndVersion */
4420 PDM_DRVREG_VERSION
4421};
4422
4423/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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