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