VirtualBox

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

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