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