VirtualBox

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

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

Main: bugref:8783: fixes for the new resizing code.

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

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