VirtualBox

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

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

DisplayImpl: repaint display after a resize (better fix for a race)

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

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