VirtualBox

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

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

DisplayImpl: repaint display after a resize (fixed a race)

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

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