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