VirtualBox

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

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

Main: reverted r114346.

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

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