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