1 | /* $Id: DisplayImpl.cpp 59596 2016-02-05 14:35:20Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2014 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 = 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 | // wrapped IEventListener method
|
---|
2807 | HRESULT Display::handleEvent(const ComPtr<IEvent> &aEvent)
|
---|
2808 | {
|
---|
2809 | VBoxEventType_T aType = VBoxEventType_Invalid;
|
---|
2810 |
|
---|
2811 | aEvent->COMGETTER(Type)(&aType);
|
---|
2812 | switch (aType)
|
---|
2813 | {
|
---|
2814 | case VBoxEventType_OnStateChanged:
|
---|
2815 | {
|
---|
2816 | ComPtr<IStateChangedEvent> scev = aEvent;
|
---|
2817 | Assert(scev);
|
---|
2818 | MachineState_T machineState;
|
---|
2819 | scev->COMGETTER(State)(&machineState);
|
---|
2820 | if ( machineState == MachineState_Running
|
---|
2821 | || machineState == MachineState_Teleporting
|
---|
2822 | || machineState == MachineState_LiveSnapshotting
|
---|
2823 | || machineState == MachineState_DeletingSnapshotOnline
|
---|
2824 | )
|
---|
2825 | {
|
---|
2826 | LogRelFlowFunc(("Machine is running.\n"));
|
---|
2827 |
|
---|
2828 | #ifdef VBOX_WITH_CROGL
|
---|
2829 | i_crOglWindowsShow(true);
|
---|
2830 | #endif
|
---|
2831 | }
|
---|
2832 | else
|
---|
2833 | {
|
---|
2834 | #ifdef VBOX_WITH_CROGL
|
---|
2835 | if (machineState == MachineState_Paused)
|
---|
2836 | i_crOglWindowsShow(false);
|
---|
2837 | #endif
|
---|
2838 | }
|
---|
2839 | break;
|
---|
2840 | }
|
---|
2841 | default:
|
---|
2842 | AssertFailed();
|
---|
2843 | }
|
---|
2844 |
|
---|
2845 | return S_OK;
|
---|
2846 | }
|
---|
2847 |
|
---|
2848 |
|
---|
2849 | // private methods
|
---|
2850 | /////////////////////////////////////////////////////////////////////////////
|
---|
2851 |
|
---|
2852 | #if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
|
---|
2853 | int Display::i_crViewportNotify(ULONG aScreenId, ULONG x, ULONG y, ULONG width, ULONG height)
|
---|
2854 | {
|
---|
2855 | VMMDev *pVMMDev = mParent->i_getVMMDev();
|
---|
2856 | if (!pVMMDev)
|
---|
2857 | return VERR_INVALID_STATE;
|
---|
2858 |
|
---|
2859 | size_t cbData = RT_UOFFSETOF(VBOXCRCMDCTL_HGCM, aParms[5]);
|
---|
2860 | VBOXCRCMDCTL_HGCM *pData = (VBOXCRCMDCTL_HGCM *)alloca(cbData);
|
---|
2861 |
|
---|
2862 | pData->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
|
---|
2863 | pData->Hdr.u32Function = SHCRGL_HOST_FN_VIEWPORT_CHANGED;
|
---|
2864 |
|
---|
2865 | pData->aParms[0].type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
2866 | pData->aParms[0].u.uint32 = aScreenId;
|
---|
2867 |
|
---|
2868 | pData->aParms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
2869 | pData->aParms[1].u.uint32 = x;
|
---|
2870 |
|
---|
2871 | pData->aParms[2].type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
2872 | pData->aParms[2].u.uint32 = y;
|
---|
2873 |
|
---|
2874 | pData->aParms[3].type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
2875 | pData->aParms[3].u.uint32 = width;
|
---|
2876 |
|
---|
2877 | pData->aParms[4].type = VBOX_HGCM_SVC_PARM_32BIT;
|
---|
2878 | pData->aParms[4].u.uint32 = height;
|
---|
2879 |
|
---|
2880 | return i_crCtlSubmitSyncIfHasDataForScreen(aScreenId, &pData->Hdr, (uint32_t)cbData);
|
---|
2881 | }
|
---|
2882 | #endif
|
---|
2883 |
|
---|
2884 | #ifdef VBOX_WITH_CRHGSMI
|
---|
2885 | void Display::i_setupCrHgsmiData(void)
|
---|
2886 | {
|
---|
2887 | VMMDev *pVMMDev = mParent->i_getVMMDev();
|
---|
2888 | Assert(pVMMDev);
|
---|
2889 | int rc = RTCritSectRwEnterExcl(&mCrOglLock);
|
---|
2890 | AssertRC(rc);
|
---|
2891 |
|
---|
2892 | if (pVMMDev)
|
---|
2893 | rc = pVMMDev->hgcmHostSvcHandleCreate("VBoxSharedCrOpenGL", &mhCrOglSvc);
|
---|
2894 | else
|
---|
2895 | rc = VERR_GENERAL_FAILURE;
|
---|
2896 |
|
---|
2897 | if (RT_SUCCESS(rc))
|
---|
2898 | {
|
---|
2899 | Assert(mhCrOglSvc);
|
---|
2900 | /* setup command completion callback */
|
---|
2901 | VBOXVDMACMD_CHROMIUM_CTL_CRHGSMI_SETUP_MAINCB Completion;
|
---|
2902 | Completion.Hdr.enmType = VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP_MAINCB;
|
---|
2903 | Completion.Hdr.cbCmd = sizeof(Completion);
|
---|
2904 | Completion.hCompletion = mpDrv->pVBVACallbacks;
|
---|
2905 | Completion.pfnCompletion = mpDrv->pVBVACallbacks->pfnCrHgsmiCommandCompleteAsync;
|
---|
2906 |
|
---|
2907 | VBOXHGCMSVCPARM parm;
|
---|
2908 | parm.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
2909 | parm.u.pointer.addr = &Completion;
|
---|
2910 | parm.u.pointer.size = 0;
|
---|
2911 |
|
---|
2912 | rc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_CRHGSMI_CTL, 1, &parm);
|
---|
2913 | if (RT_SUCCESS(rc))
|
---|
2914 | mCrOglCallbacks = Completion.MainInterface;
|
---|
2915 | else
|
---|
2916 | AssertMsgFailed(("VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP_COMPLETION failed (rc=%Rrc)\n", rc));
|
---|
2917 | }
|
---|
2918 |
|
---|
2919 | if (RT_FAILURE(rc))
|
---|
2920 | mhCrOglSvc = NULL;
|
---|
2921 |
|
---|
2922 | RTCritSectRwLeaveExcl(&mCrOglLock);
|
---|
2923 | }
|
---|
2924 |
|
---|
2925 | void Display::i_destructCrHgsmiData(void)
|
---|
2926 | {
|
---|
2927 | int rc = RTCritSectRwEnterExcl(&mCrOglLock);
|
---|
2928 | AssertRC(rc);
|
---|
2929 | mhCrOglSvc = NULL;
|
---|
2930 | RTCritSectRwLeaveExcl(&mCrOglLock);
|
---|
2931 | }
|
---|
2932 | #endif /* VBOX_WITH_CRHGSMI */
|
---|
2933 |
|
---|
2934 | /**
|
---|
2935 | * Handle display resize event issued by the VGA device for the primary screen.
|
---|
2936 | *
|
---|
2937 | * @see PDMIDISPLAYCONNECTOR::pfnResize
|
---|
2938 | */
|
---|
2939 | DECLCALLBACK(int) Display::i_displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface,
|
---|
2940 | uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy)
|
---|
2941 | {
|
---|
2942 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
2943 | Display *pThis = pDrv->pDisplay;
|
---|
2944 |
|
---|
2945 | LogRelFlowFunc(("bpp %d, pvVRAM %p, cbLine %d, cx %d, cy %d\n",
|
---|
2946 | bpp, pvVRAM, cbLine, cx, cy));
|
---|
2947 |
|
---|
2948 | bool f = ASMAtomicCmpXchgBool(&pThis->fVGAResizing, true, false);
|
---|
2949 | if (!f)
|
---|
2950 | {
|
---|
2951 | /* This is a result of recursive call when the source bitmap is being updated
|
---|
2952 | * during a VGA resize. Tell the VGA device to ignore the call.
|
---|
2953 | *
|
---|
2954 | * @todo It is a workaround, actually pfnUpdateDisplayAll must
|
---|
2955 | * fail on resize.
|
---|
2956 | */
|
---|
2957 | LogRel(("displayResizeCallback: already processing\n"));
|
---|
2958 | return VINF_VGA_RESIZE_IN_PROGRESS;
|
---|
2959 | }
|
---|
2960 |
|
---|
2961 | int rc = pThis->i_handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, bpp, pvVRAM, cbLine, cx, cy, VBVA_SCREEN_F_ACTIVE);
|
---|
2962 |
|
---|
2963 | /* Restore the flag. */
|
---|
2964 | f = ASMAtomicCmpXchgBool(&pThis->fVGAResizing, false, true);
|
---|
2965 | AssertRelease(f);
|
---|
2966 |
|
---|
2967 | return rc;
|
---|
2968 | }
|
---|
2969 |
|
---|
2970 | /**
|
---|
2971 | * Handle display update.
|
---|
2972 | *
|
---|
2973 | * @see PDMIDISPLAYCONNECTOR::pfnUpdateRect
|
---|
2974 | */
|
---|
2975 | DECLCALLBACK(void) Display::i_displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
|
---|
2976 | uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
|
---|
2977 | {
|
---|
2978 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
2979 |
|
---|
2980 | #ifdef DEBUG_sunlover
|
---|
2981 | LogFlowFunc(("fVideoAccelEnabled = %d, %d,%d %dx%d\n",
|
---|
2982 | pDrv->pDisplay->mVideoAccelLegacy.fVideoAccelEnabled, x, y, cx, cy));
|
---|
2983 | #endif /* DEBUG_sunlover */
|
---|
2984 |
|
---|
2985 | /* This call does update regardless of VBVA status.
|
---|
2986 | * But in VBVA mode this is called only as result of
|
---|
2987 | * pfnUpdateDisplayAll in the VGA device.
|
---|
2988 | */
|
---|
2989 |
|
---|
2990 | pDrv->pDisplay->i_handleDisplayUpdate(VBOX_VIDEO_PRIMARY_SCREEN, x, y, cx, cy);
|
---|
2991 | }
|
---|
2992 |
|
---|
2993 | /**
|
---|
2994 | * Periodic display refresh callback.
|
---|
2995 | *
|
---|
2996 | * @see PDMIDISPLAYCONNECTOR::pfnRefresh
|
---|
2997 | * @thread EMT
|
---|
2998 | */
|
---|
2999 | /*static*/ DECLCALLBACK(void) Display::i_displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface)
|
---|
3000 | {
|
---|
3001 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3002 |
|
---|
3003 | #ifdef DEBUG_sunlover_2
|
---|
3004 | LogFlowFunc(("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
|
---|
3005 | pDrv->pDisplay->mfVideoAccelEnabled));
|
---|
3006 | #endif /* DEBUG_sunlover_2 */
|
---|
3007 |
|
---|
3008 | Display *pDisplay = pDrv->pDisplay;
|
---|
3009 | unsigned uScreenId;
|
---|
3010 |
|
---|
3011 | int rc = pDisplay->i_videoAccelRefreshProcess(pDrv->pUpPort);
|
---|
3012 | if (rc != VINF_TRY_AGAIN) /* Means 'do nothing' here. */
|
---|
3013 | {
|
---|
3014 | if (rc == VWRN_INVALID_STATE)
|
---|
3015 | {
|
---|
3016 | /* No VBVA do a display update. */
|
---|
3017 | DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN];
|
---|
3018 | pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
|
---|
3019 | }
|
---|
3020 |
|
---|
3021 | /* Inform the VRDP server that the current display update sequence is
|
---|
3022 | * completed. At this moment the framebuffer memory contains a definite
|
---|
3023 | * image, that is synchronized with the orders already sent to VRDP client.
|
---|
3024 | * The server can now process redraw requests from clients or initial
|
---|
3025 | * fullscreen updates for new clients.
|
---|
3026 | */
|
---|
3027 | for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
|
---|
3028 | {
|
---|
3029 | DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
|
---|
3030 |
|
---|
3031 | Assert(pDisplay->mParent && pDisplay->mParent->i_consoleVRDPServer());
|
---|
3032 | pDisplay->mParent->i_consoleVRDPServer()->SendUpdate(uScreenId, NULL, 0);
|
---|
3033 | }
|
---|
3034 | }
|
---|
3035 |
|
---|
3036 | #ifdef VBOX_WITH_VPX
|
---|
3037 | if (VideoRecIsEnabled(pDisplay->mpVideoRecCtx))
|
---|
3038 | {
|
---|
3039 | do {
|
---|
3040 | # if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
|
---|
3041 | if (pDisplay->mfIsCr3DEnabled)
|
---|
3042 | {
|
---|
3043 | if (ASMAtomicCmpXchgU32(&pDisplay->mfCrOglVideoRecState, CRVREC_STATE_SUBMITTED, CRVREC_STATE_IDLE))
|
---|
3044 | {
|
---|
3045 | if ( pDisplay->mCrOglCallbacks.pfnHasData
|
---|
3046 | && pDisplay->mCrOglCallbacks.pfnHasData())
|
---|
3047 | {
|
---|
3048 | /* submit */
|
---|
3049 | VBOXCRCMDCTL_HGCM *pData = &pDisplay->mCrOglScreenshotCtl;
|
---|
3050 |
|
---|
3051 | pData->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
|
---|
3052 | pData->Hdr.u32Function = SHCRGL_HOST_FN_TAKE_SCREENSHOT;
|
---|
3053 |
|
---|
3054 | pData->aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3055 | pData->aParms[0].u.pointer.addr = &pDisplay->mCrOglScreenshotData;
|
---|
3056 | pData->aParms[0].u.pointer.size = sizeof(pDisplay->mCrOglScreenshotData);
|
---|
3057 | rc = pDisplay->i_crCtlSubmit(&pData->Hdr, sizeof(*pData), Display::i_displayVRecCompletion, pDisplay);
|
---|
3058 | if (RT_SUCCESS(rc))
|
---|
3059 | break;
|
---|
3060 | AssertMsgFailed(("crCtlSubmit failed (rc=%Rrc)\n", rc));
|
---|
3061 | }
|
---|
3062 |
|
---|
3063 | /* no 3D data available, or error has occured,
|
---|
3064 | * go the straight way */
|
---|
3065 | ASMAtomicWriteU32(&pDisplay->mfCrOglVideoRecState, CRVREC_STATE_IDLE);
|
---|
3066 | }
|
---|
3067 | else
|
---|
3068 | {
|
---|
3069 | /* record request is still in progress, don't do anything */
|
---|
3070 | break;
|
---|
3071 | }
|
---|
3072 | }
|
---|
3073 | # endif /* VBOX_WITH_HGCM && VBOX_WITH_CROGL */
|
---|
3074 |
|
---|
3075 | uint64_t u64Now = RTTimeProgramMilliTS();
|
---|
3076 | for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
|
---|
3077 | {
|
---|
3078 | if (!pDisplay->maVideoRecEnabled[uScreenId])
|
---|
3079 | continue;
|
---|
3080 |
|
---|
3081 | if (VideoRecIsFull(pDisplay->mpVideoRecCtx, uScreenId, u64Now))
|
---|
3082 | {
|
---|
3083 | pDisplay->i_VideoCaptureStop();
|
---|
3084 | pDisplay->mParent->i_machine()->COMSETTER(VideoCaptureEnabled)(false);
|
---|
3085 | break;
|
---|
3086 | }
|
---|
3087 |
|
---|
3088 | DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
|
---|
3089 |
|
---|
3090 | if ( !pFBInfo->pFramebuffer.isNull()
|
---|
3091 | && !pFBInfo->fDisabled)
|
---|
3092 | {
|
---|
3093 | rc = VERR_NOT_SUPPORTED;
|
---|
3094 | if ( pFBInfo->fVBVAEnabled
|
---|
3095 | && pFBInfo->pu8FramebufferVRAM)
|
---|
3096 | {
|
---|
3097 | rc = VideoRecCopyToIntBuf(pDisplay->mpVideoRecCtx, uScreenId, 0, 0,
|
---|
3098 | BitmapFormat_BGR,
|
---|
3099 | pFBInfo->u16BitsPerPixel,
|
---|
3100 | pFBInfo->u32LineSize, pFBInfo->w, pFBInfo->h,
|
---|
3101 | pFBInfo->pu8FramebufferVRAM, u64Now);
|
---|
3102 | }
|
---|
3103 | else if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN && pDrv->IConnector.pbData)
|
---|
3104 | {
|
---|
3105 | rc = VideoRecCopyToIntBuf(pDisplay->mpVideoRecCtx, uScreenId, 0, 0,
|
---|
3106 | BitmapFormat_BGR,
|
---|
3107 | pDrv->IConnector.cBits,
|
---|
3108 | pDrv->IConnector.cbScanline, pDrv->IConnector.cx,
|
---|
3109 | pDrv->IConnector.cy, pDrv->IConnector.pbData, u64Now);
|
---|
3110 | }
|
---|
3111 | if (rc == VINF_TRY_AGAIN)
|
---|
3112 | break;
|
---|
3113 | }
|
---|
3114 | }
|
---|
3115 | } while (0);
|
---|
3116 | }
|
---|
3117 | #endif /* VBOX_WITH_VPX */
|
---|
3118 |
|
---|
3119 | #ifdef DEBUG_sunlover_2
|
---|
3120 | LogFlowFunc(("leave\n"));
|
---|
3121 | #endif /* DEBUG_sunlover_2 */
|
---|
3122 | }
|
---|
3123 |
|
---|
3124 | /**
|
---|
3125 | * Reset notification
|
---|
3126 | *
|
---|
3127 | * @see PDMIDISPLAYCONNECTOR::pfnReset
|
---|
3128 | */
|
---|
3129 | DECLCALLBACK(void) Display::i_displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface)
|
---|
3130 | {
|
---|
3131 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3132 |
|
---|
3133 | LogRelFlowFunc(("\n"));
|
---|
3134 |
|
---|
3135 | /* Disable VBVA mode. */
|
---|
3136 | pDrv->pDisplay->VideoAccelEnableVGA(false, NULL);
|
---|
3137 | }
|
---|
3138 |
|
---|
3139 | /**
|
---|
3140 | * LFBModeChange notification
|
---|
3141 | *
|
---|
3142 | * @see PDMIDISPLAYCONNECTOR::pfnLFBModeChange
|
---|
3143 | */
|
---|
3144 | DECLCALLBACK(void) Display::i_displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled)
|
---|
3145 | {
|
---|
3146 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3147 |
|
---|
3148 | LogRelFlowFunc(("fEnabled=%d\n", fEnabled));
|
---|
3149 |
|
---|
3150 | NOREF(fEnabled);
|
---|
3151 |
|
---|
3152 | /* Disable VBVA mode in any case. The guest driver reenables VBVA mode if necessary. */
|
---|
3153 | pDrv->pDisplay->VideoAccelEnableVGA(false, NULL);
|
---|
3154 | }
|
---|
3155 |
|
---|
3156 | /**
|
---|
3157 | * Adapter information change notification.
|
---|
3158 | *
|
---|
3159 | * @see PDMIDISPLAYCONNECTOR::pfnProcessAdapterData
|
---|
3160 | */
|
---|
3161 | DECLCALLBACK(void) Display::i_displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM,
|
---|
3162 | uint32_t u32VRAMSize)
|
---|
3163 | {
|
---|
3164 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3165 | pDrv->pDisplay->processAdapterData(pvVRAM, u32VRAMSize);
|
---|
3166 | }
|
---|
3167 |
|
---|
3168 | /**
|
---|
3169 | * Display information change notification.
|
---|
3170 | *
|
---|
3171 | * @see PDMIDISPLAYCONNECTOR::pfnProcessDisplayData
|
---|
3172 | */
|
---|
3173 | DECLCALLBACK(void) Display::i_displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface,
|
---|
3174 | void *pvVRAM, unsigned uScreenId)
|
---|
3175 | {
|
---|
3176 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3177 | pDrv->pDisplay->processDisplayData(pvVRAM, uScreenId);
|
---|
3178 | }
|
---|
3179 |
|
---|
3180 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
3181 |
|
---|
3182 | #ifndef S_FALSE
|
---|
3183 | # define S_FALSE ((HRESULT)1L)
|
---|
3184 | #endif
|
---|
3185 |
|
---|
3186 | int Display::i_handleVHWACommandProcess(PVBOXVHWACMD pCommand)
|
---|
3187 | {
|
---|
3188 | unsigned id = (unsigned)pCommand->iDisplay;
|
---|
3189 | int rc = VINF_SUCCESS;
|
---|
3190 | if (id >= mcMonitors)
|
---|
3191 | return VERR_INVALID_PARAMETER;
|
---|
3192 |
|
---|
3193 | ComPtr<IFramebuffer> pFramebuffer;
|
---|
3194 | AutoReadLock arlock(this COMMA_LOCKVAL_SRC_POS);
|
---|
3195 | pFramebuffer = maFramebuffers[id].pFramebuffer;
|
---|
3196 | bool fVHWASupported = RT_BOOL(maFramebuffers[id].u32Caps & FramebufferCapabilities_VHWA);
|
---|
3197 | arlock.release();
|
---|
3198 |
|
---|
3199 | if (pFramebuffer == NULL || !fVHWASupported)
|
---|
3200 | return VERR_NOT_IMPLEMENTED; /* Implementation is not available. */
|
---|
3201 |
|
---|
3202 | HRESULT hr = pFramebuffer->ProcessVHWACommand((BYTE*)pCommand);
|
---|
3203 | if (hr == S_FALSE)
|
---|
3204 | return VINF_SUCCESS;
|
---|
3205 | else if (SUCCEEDED(hr))
|
---|
3206 | return VINF_CALLBACK_RETURN;
|
---|
3207 | else if (hr == E_ACCESSDENIED)
|
---|
3208 | return VERR_INVALID_STATE; /* notify we can not handle request atm */
|
---|
3209 | else if (hr == E_NOTIMPL)
|
---|
3210 | return VERR_NOT_IMPLEMENTED;
|
---|
3211 | return VERR_GENERAL_FAILURE;
|
---|
3212 | }
|
---|
3213 |
|
---|
3214 | DECLCALLBACK(int) Display::i_displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
|
---|
3215 | {
|
---|
3216 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3217 |
|
---|
3218 | return pDrv->pDisplay->i_handleVHWACommandProcess(pCommand);
|
---|
3219 | }
|
---|
3220 | #endif
|
---|
3221 |
|
---|
3222 | #ifdef VBOX_WITH_CRHGSMI
|
---|
3223 | void Display::i_handleCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam)
|
---|
3224 | {
|
---|
3225 | mpDrv->pVBVACallbacks->pfnCrHgsmiCommandCompleteAsync(mpDrv->pVBVACallbacks,
|
---|
3226 | (PVBOXVDMACMD_CHROMIUM_CMD)pParam->u.pointer.addr, result);
|
---|
3227 | }
|
---|
3228 |
|
---|
3229 | void Display::i_handleCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam)
|
---|
3230 | {
|
---|
3231 | PVBOXVDMACMD_CHROMIUM_CTL pCtl = (PVBOXVDMACMD_CHROMIUM_CTL)pParam->u.pointer.addr;
|
---|
3232 | mpDrv->pVBVACallbacks->pfnCrHgsmiControlCompleteAsync(mpDrv->pVBVACallbacks, pCtl, result);
|
---|
3233 | }
|
---|
3234 |
|
---|
3235 | void Display::i_handleCrHgsmiCommandProcess(PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd)
|
---|
3236 | {
|
---|
3237 | int rc = VERR_NOT_SUPPORTED;
|
---|
3238 | VBOXHGCMSVCPARM parm;
|
---|
3239 | parm.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3240 | parm.u.pointer.addr = pCmd;
|
---|
3241 | parm.u.pointer.size = cbCmd;
|
---|
3242 |
|
---|
3243 | if (mhCrOglSvc)
|
---|
3244 | {
|
---|
3245 | VMMDev *pVMMDev = mParent->i_getVMMDev();
|
---|
3246 | if (pVMMDev)
|
---|
3247 | {
|
---|
3248 | /* no completion callback is specified with this call,
|
---|
3249 | * the CrOgl code will complete the CrHgsmi command once it processes it */
|
---|
3250 | rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CRHGSMI_CMD, &parm, NULL, NULL);
|
---|
3251 | AssertRC(rc);
|
---|
3252 | if (RT_SUCCESS(rc))
|
---|
3253 | return;
|
---|
3254 | }
|
---|
3255 | else
|
---|
3256 | rc = VERR_INVALID_STATE;
|
---|
3257 | }
|
---|
3258 |
|
---|
3259 | /* we are here because something went wrong with command processing, complete it */
|
---|
3260 | i_handleCrHgsmiCommandCompletion(rc, SHCRGL_HOST_FN_CRHGSMI_CMD, &parm);
|
---|
3261 | }
|
---|
3262 |
|
---|
3263 | void Display::i_handleCrHgsmiControlProcess(PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl)
|
---|
3264 | {
|
---|
3265 | int rc = VERR_NOT_SUPPORTED;
|
---|
3266 | VBOXHGCMSVCPARM parm;
|
---|
3267 | parm.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3268 | parm.u.pointer.addr = pCtl;
|
---|
3269 | parm.u.pointer.size = cbCtl;
|
---|
3270 |
|
---|
3271 | if (mhCrOglSvc)
|
---|
3272 | {
|
---|
3273 | VMMDev *pVMMDev = mParent->i_getVMMDev();
|
---|
3274 | if (pVMMDev)
|
---|
3275 | {
|
---|
3276 | bool fCheckPendingViewport = (pCtl->enmType == VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP);
|
---|
3277 | rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CRHGSMI_CTL, &parm,
|
---|
3278 | Display::i_displayCrHgsmiControlCompletion, this);
|
---|
3279 | AssertRC(rc);
|
---|
3280 | if (RT_SUCCESS(rc))
|
---|
3281 | {
|
---|
3282 | if (fCheckPendingViewport)
|
---|
3283 | {
|
---|
3284 | ULONG ul;
|
---|
3285 | for (ul = 0; ul < mcMonitors; ul++)
|
---|
3286 | {
|
---|
3287 | DISPLAYFBINFO *pFb = &maFramebuffers[ul];
|
---|
3288 | if (!pFb->pendingViewportInfo.fPending)
|
---|
3289 | continue;
|
---|
3290 |
|
---|
3291 | rc = i_crViewportNotify(ul, pFb->pendingViewportInfo.x, pFb->pendingViewportInfo.y,
|
---|
3292 | pFb->pendingViewportInfo.width, pFb->pendingViewportInfo.height);
|
---|
3293 | if (RT_SUCCESS(rc))
|
---|
3294 | pFb->pendingViewportInfo.fPending = false;
|
---|
3295 | else
|
---|
3296 | {
|
---|
3297 | AssertMsgFailed(("crViewportNotify failed (rc=%Rrc)\n", rc));
|
---|
3298 | rc = VINF_SUCCESS;
|
---|
3299 | }
|
---|
3300 | }
|
---|
3301 | }
|
---|
3302 | return;
|
---|
3303 | }
|
---|
3304 | }
|
---|
3305 | else
|
---|
3306 | rc = VERR_INVALID_STATE;
|
---|
3307 | }
|
---|
3308 |
|
---|
3309 | /* we are here because something went wrong with command processing, complete it */
|
---|
3310 | i_handleCrHgsmiControlCompletion(rc, SHCRGL_HOST_FN_CRHGSMI_CTL, &parm);
|
---|
3311 | }
|
---|
3312 |
|
---|
3313 | DECLCALLBACK(void) Display::i_displayCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd,
|
---|
3314 | uint32_t cbCmd)
|
---|
3315 | {
|
---|
3316 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3317 |
|
---|
3318 | pDrv->pDisplay->i_handleCrHgsmiCommandProcess(pCmd, cbCmd);
|
---|
3319 | }
|
---|
3320 |
|
---|
3321 | DECLCALLBACK(void) Display::i_displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCmd,
|
---|
3322 | uint32_t cbCmd)
|
---|
3323 | {
|
---|
3324 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3325 |
|
---|
3326 | pDrv->pDisplay->i_handleCrHgsmiControlProcess(pCmd, cbCmd);
|
---|
3327 | }
|
---|
3328 |
|
---|
3329 | DECLCALLBACK(void) Display::i_displayCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam,
|
---|
3330 | void *pvContext)
|
---|
3331 | {
|
---|
3332 | AssertMsgFailed(("not expected!\n"));
|
---|
3333 | Display *pDisplay = (Display *)pvContext;
|
---|
3334 | pDisplay->i_handleCrHgsmiCommandCompletion(result, u32Function, pParam);
|
---|
3335 | }
|
---|
3336 |
|
---|
3337 | DECLCALLBACK(void) Display::i_displayCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam,
|
---|
3338 | void *pvContext)
|
---|
3339 | {
|
---|
3340 | Display *pDisplay = (Display *)pvContext;
|
---|
3341 | pDisplay->i_handleCrHgsmiControlCompletion(result, u32Function, pParam);
|
---|
3342 |
|
---|
3343 | }
|
---|
3344 | #endif
|
---|
3345 |
|
---|
3346 | #if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
|
---|
3347 | DECLCALLBACK(void) Display::i_displayCrHgcmCtlSubmitCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam,
|
---|
3348 | void *pvContext)
|
---|
3349 | {
|
---|
3350 | VBOXCRCMDCTL *pCmd = (VBOXCRCMDCTL*)pParam->u.pointer.addr;
|
---|
3351 | if (pCmd->u.pfnInternal)
|
---|
3352 | ((PFNCRCTLCOMPLETION)pCmd->u.pfnInternal)(pCmd, pParam->u.pointer.size, result, pvContext);
|
---|
3353 | }
|
---|
3354 |
|
---|
3355 | int Display::i_handleCrHgcmCtlSubmit(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd,
|
---|
3356 | PFNCRCTLCOMPLETION pfnCompletion,
|
---|
3357 | void *pvCompletion)
|
---|
3358 | {
|
---|
3359 | VMMDev *pVMMDev = mParent ? mParent->i_getVMMDev() : NULL;
|
---|
3360 | if (!pVMMDev)
|
---|
3361 | {
|
---|
3362 | AssertMsgFailed(("no vmmdev\n"));
|
---|
3363 | return VERR_INVALID_STATE;
|
---|
3364 | }
|
---|
3365 |
|
---|
3366 | Assert(mhCrOglSvc);
|
---|
3367 | VBOXHGCMSVCPARM parm;
|
---|
3368 | parm.type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3369 | parm.u.pointer.addr = pCmd;
|
---|
3370 | parm.u.pointer.size = cbCmd;
|
---|
3371 |
|
---|
3372 | pCmd->u.pfnInternal = (void(*)())pfnCompletion;
|
---|
3373 | int rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CTL, &parm, i_displayCrHgcmCtlSubmitCompletion,
|
---|
3374 | pvCompletion);
|
---|
3375 | if (!RT_SUCCESS(rc))
|
---|
3376 | AssertMsgFailed(("hgcmHostFastCallAsync failed (rc=%Rrc)\n", rc));
|
---|
3377 |
|
---|
3378 | return rc;
|
---|
3379 | }
|
---|
3380 |
|
---|
3381 | DECLCALLBACK(int) Display::i_displayCrHgcmCtlSubmit(PPDMIDISPLAYCONNECTOR pInterface,
|
---|
3382 | struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd,
|
---|
3383 | PFNCRCTLCOMPLETION pfnCompletion,
|
---|
3384 | void *pvCompletion)
|
---|
3385 | {
|
---|
3386 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3387 | Display *pThis = pDrv->pDisplay;
|
---|
3388 | return pThis->i_handleCrHgcmCtlSubmit(pCmd, cbCmd, pfnCompletion, pvCompletion);
|
---|
3389 | }
|
---|
3390 |
|
---|
3391 | int Display::i_crCtlSubmit(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd, PFNCRCTLCOMPLETION pfnCompletion, void *pvCompletion)
|
---|
3392 | {
|
---|
3393 | int rc = RTCritSectRwEnterShared(&mCrOglLock);
|
---|
3394 | if (RT_SUCCESS(rc))
|
---|
3395 | {
|
---|
3396 | if (mhCrOglSvc)
|
---|
3397 | rc = mpDrv->pVBVACallbacks->pfnCrCtlSubmit(mpDrv->pVBVACallbacks, pCmd, cbCmd, pfnCompletion, pvCompletion);
|
---|
3398 | else
|
---|
3399 | rc = VERR_NOT_SUPPORTED;
|
---|
3400 |
|
---|
3401 | RTCritSectRwLeaveShared(&mCrOglLock);
|
---|
3402 | }
|
---|
3403 | return rc;
|
---|
3404 | }
|
---|
3405 |
|
---|
3406 | int Display::i_crCtlSubmitSync(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd)
|
---|
3407 | {
|
---|
3408 | int rc = RTCritSectRwEnterShared(&mCrOglLock);
|
---|
3409 | if (RT_SUCCESS(rc))
|
---|
3410 | {
|
---|
3411 | if (mhCrOglSvc)
|
---|
3412 | rc = mpDrv->pVBVACallbacks->pfnCrCtlSubmitSync(mpDrv->pVBVACallbacks, pCmd, cbCmd);
|
---|
3413 | else
|
---|
3414 | rc = VERR_NOT_SUPPORTED;
|
---|
3415 |
|
---|
3416 | RTCritSectRwLeaveShared(&mCrOglLock);
|
---|
3417 | }
|
---|
3418 | return rc;
|
---|
3419 | }
|
---|
3420 |
|
---|
3421 | int Display::i_crCtlSubmitAsyncCmdCopy(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd)
|
---|
3422 | {
|
---|
3423 | VBOXCRCMDCTL* pCmdCopy = (VBOXCRCMDCTL*)RTMemAlloc(cbCmd);
|
---|
3424 | if (!pCmdCopy)
|
---|
3425 | {
|
---|
3426 | LogRel(("RTMemAlloc failed\n"));
|
---|
3427 | return VERR_NO_MEMORY;
|
---|
3428 | }
|
---|
3429 |
|
---|
3430 | memcpy(pCmdCopy, pCmd, cbCmd);
|
---|
3431 |
|
---|
3432 | int rc = i_crCtlSubmit(pCmdCopy, cbCmd, i_displayCrCmdFree, pCmdCopy);
|
---|
3433 | if (RT_FAILURE(rc))
|
---|
3434 | {
|
---|
3435 | LogRel(("crCtlSubmit failed (rc=%Rrc)\n", rc));
|
---|
3436 | RTMemFree(pCmdCopy);
|
---|
3437 | return rc;
|
---|
3438 | }
|
---|
3439 |
|
---|
3440 | return VINF_SUCCESS;
|
---|
3441 | }
|
---|
3442 |
|
---|
3443 | int Display::i_crCtlSubmitSyncIfHasDataForScreen(uint32_t u32ScreenID, struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd)
|
---|
3444 | {
|
---|
3445 | int rc = RTCritSectRwEnterShared(&mCrOglLock);
|
---|
3446 | AssertRCReturn(rc, rc);
|
---|
3447 |
|
---|
3448 | if ( mCrOglCallbacks.pfnHasDataForScreen
|
---|
3449 | && mCrOglCallbacks.pfnHasDataForScreen(u32ScreenID))
|
---|
3450 | rc = i_crCtlSubmitSync(pCmd, cbCmd);
|
---|
3451 | else
|
---|
3452 | rc = i_crCtlSubmitAsyncCmdCopy(pCmd, cbCmd);
|
---|
3453 |
|
---|
3454 | RTCritSectRwLeaveShared(&mCrOglLock);
|
---|
3455 |
|
---|
3456 | return rc;
|
---|
3457 | }
|
---|
3458 |
|
---|
3459 | bool Display::i_handleCrVRecScreenshotBegin(uint32_t uScreen, uint64_t u64TimeStamp)
|
---|
3460 | {
|
---|
3461 | # if VBOX_WITH_VPX
|
---|
3462 | return VideoRecIsReady(mpVideoRecCtx, uScreen, u64TimeStamp);
|
---|
3463 | # else
|
---|
3464 | return false;
|
---|
3465 | # endif
|
---|
3466 | }
|
---|
3467 |
|
---|
3468 | void Display::i_handleCrVRecScreenshotEnd(uint32_t uScreen, uint64_t u64TimeStamp)
|
---|
3469 | {
|
---|
3470 | }
|
---|
3471 |
|
---|
3472 | void Display::i_handleCrVRecScreenshotPerform(uint32_t uScreen,
|
---|
3473 | uint32_t x, uint32_t y, uint32_t uPixelFormat,
|
---|
3474 | uint32_t uBitsPerPixel, uint32_t uBytesPerLine,
|
---|
3475 | uint32_t uGuestWidth, uint32_t uGuestHeight,
|
---|
3476 | uint8_t *pu8BufferAddress, uint64_t u64TimeStamp)
|
---|
3477 | {
|
---|
3478 | Assert(mfCrOglVideoRecState == CRVREC_STATE_SUBMITTED);
|
---|
3479 | # if VBOX_WITH_VPX
|
---|
3480 | int rc = VideoRecCopyToIntBuf(mpVideoRecCtx, uScreen, x, y,
|
---|
3481 | uPixelFormat,
|
---|
3482 | uBitsPerPixel, uBytesPerLine,
|
---|
3483 | uGuestWidth, uGuestHeight,
|
---|
3484 | pu8BufferAddress, u64TimeStamp);
|
---|
3485 | Assert(rc == VINF_SUCCESS /* || rc == VERR_TRY_AGAIN || rc == VINF_TRY_AGAIN*/);
|
---|
3486 | # endif
|
---|
3487 | }
|
---|
3488 |
|
---|
3489 | void Display::i_handleVRecCompletion()
|
---|
3490 | {
|
---|
3491 | Assert(mfCrOglVideoRecState == CRVREC_STATE_SUBMITTED);
|
---|
3492 | ASMAtomicWriteU32(&mfCrOglVideoRecState, CRVREC_STATE_IDLE);
|
---|
3493 | }
|
---|
3494 |
|
---|
3495 | #endif /* VBOX_WITH_HGCM && VBOX_WITH_CROGL */
|
---|
3496 |
|
---|
3497 | HRESULT Display::notifyScaleFactorChange(ULONG aScreenId, ULONG aScaleFactorWMultiplied, ULONG aScaleFactorHMultiplied)
|
---|
3498 | {
|
---|
3499 | #if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
|
---|
3500 | HRESULT hr = E_UNEXPECTED;
|
---|
3501 |
|
---|
3502 | if (aScreenId >= mcMonitors)
|
---|
3503 | return E_INVALIDARG;
|
---|
3504 |
|
---|
3505 | /* 3D acceleration enabled in VM config. */
|
---|
3506 | if (mfIsCr3DEnabled)
|
---|
3507 | {
|
---|
3508 | /* VBoxSharedCrOpenGL HGCM host service is running. */
|
---|
3509 | if (mhCrOglSvc)
|
---|
3510 | {
|
---|
3511 | VMMDev *pVMMDev = mParent->i_getVMMDev();
|
---|
3512 | if (pVMMDev)
|
---|
3513 | {
|
---|
3514 | VBOXCRCMDCTL_HGCM *pCtl;
|
---|
3515 | pCtl = (VBOXCRCMDCTL_HGCM *)RTMemAlloc(sizeof(CRVBOXHGCMSETSCALEFACTOR) + sizeof(VBOXCRCMDCTL_HGCM));
|
---|
3516 | if (pCtl)
|
---|
3517 | {
|
---|
3518 | CRVBOXHGCMSETSCALEFACTOR *pData = (CRVBOXHGCMSETSCALEFACTOR *)(pCtl + 1);
|
---|
3519 | int rc;
|
---|
3520 |
|
---|
3521 | pData->u32Screen = aScreenId;
|
---|
3522 | pData->u32ScaleFactorWMultiplied = aScaleFactorWMultiplied;
|
---|
3523 | pData->u32ScaleFactorHMultiplied = aScaleFactorHMultiplied;
|
---|
3524 |
|
---|
3525 | pCtl->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
|
---|
3526 | pCtl->Hdr.u32Function = SHCRGL_HOST_FN_SET_SCALE_FACTOR;
|
---|
3527 | pCtl->aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3528 | pCtl->aParms[0].u.pointer.addr = pData;
|
---|
3529 | pCtl->aParms[0].u.pointer.size = sizeof(*pData);
|
---|
3530 |
|
---|
3531 | rc = i_crCtlSubmitSync(&pCtl->Hdr, sizeof(*pCtl));
|
---|
3532 | if (RT_FAILURE(rc))
|
---|
3533 | AssertMsgFailed(("crCtlSubmitSync failed (rc=%Rrc)\n", rc));
|
---|
3534 | else
|
---|
3535 | hr = S_OK;
|
---|
3536 |
|
---|
3537 | RTMemFree(pCtl);
|
---|
3538 | }
|
---|
3539 | else
|
---|
3540 | {
|
---|
3541 | LogRel(("Running out of memory on attempt to set OpenGL content scale factor. Ignored.\n"));
|
---|
3542 | hr = E_OUTOFMEMORY;
|
---|
3543 | }
|
---|
3544 | }
|
---|
3545 | else
|
---|
3546 | LogRel(("Internal error occurred on attempt to set OpenGL content scale factor. Ignored.\n"));
|
---|
3547 | }
|
---|
3548 | else
|
---|
3549 | LogRel(("Attempt to specify OpenGL content scale factor while corresponding HGCM host service not yet runing. Ignored.\n"));
|
---|
3550 | }
|
---|
3551 | else
|
---|
3552 | # if 0 /** @todo Thank you so very much from anyone using VMSVGA3d! */
|
---|
3553 | AssertMsgFailed(("Attempt to specify OpenGL content scale factor while 3D acceleration is disabled in VM config. Ignored.\n"));
|
---|
3554 | # else
|
---|
3555 | {
|
---|
3556 | hr = S_OK;
|
---|
3557 | /* Need an interface like this here (and the #ifdefs needs adjusting):
|
---|
3558 | PPDMIDISPLAYPORT pUpPort = mpDrv ? mpDrv->pUpPort : NULL;
|
---|
3559 | if (pUpPort && pUpPort->pfnSetScaleFactor)
|
---|
3560 | pUpPort->pfnSetScaleFactor(pUpPort, aScreeId, aScaleFactorWMultiplied, aScaleFactorHMultiplied); */
|
---|
3561 | }
|
---|
3562 | # endif
|
---|
3563 |
|
---|
3564 | return hr;
|
---|
3565 | #else
|
---|
3566 | AssertMsgFailed(("Attempt to specify OpenGL content scale factor while corresponding functionality is disabled."));
|
---|
3567 | return E_UNEXPECTED;
|
---|
3568 | #endif /* VBOX_WITH_HGCM && VBOX_WITH_CROGL */
|
---|
3569 | }
|
---|
3570 |
|
---|
3571 | HRESULT Display::notifyHiDPIOutputPolicyChange(BOOL fUnscaledHiDPI)
|
---|
3572 | {
|
---|
3573 | #if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
|
---|
3574 | HRESULT hr = E_UNEXPECTED;
|
---|
3575 |
|
---|
3576 | /* 3D acceleration enabled in VM config. */
|
---|
3577 | if (mfIsCr3DEnabled)
|
---|
3578 | {
|
---|
3579 | /* VBoxSharedCrOpenGL HGCM host service is running. */
|
---|
3580 | if (mhCrOglSvc)
|
---|
3581 | {
|
---|
3582 | VMMDev *pVMMDev = mParent->i_getVMMDev();
|
---|
3583 | if (pVMMDev)
|
---|
3584 | {
|
---|
3585 | VBOXCRCMDCTL_HGCM *pCtl;
|
---|
3586 | pCtl = (VBOXCRCMDCTL_HGCM *)RTMemAlloc(sizeof(CRVBOXHGCMSETUNSCALEDHIDPIOUTPUT) + sizeof(VBOXCRCMDCTL_HGCM));
|
---|
3587 | if (pCtl)
|
---|
3588 | {
|
---|
3589 | CRVBOXHGCMSETUNSCALEDHIDPIOUTPUT *pData = (CRVBOXHGCMSETUNSCALEDHIDPIOUTPUT *)(pCtl + 1);
|
---|
3590 | int rc;
|
---|
3591 |
|
---|
3592 | pData->fUnscaledHiDPI = RT_BOOL(fUnscaledHiDPI);
|
---|
3593 |
|
---|
3594 | pCtl->Hdr.enmType = VBOXCRCMDCTL_TYPE_HGCM;
|
---|
3595 | pCtl->Hdr.u32Function = SHCRGL_HOST_FN_SET_UNSCALED_HIDPI;
|
---|
3596 | pCtl->aParms[0].type = VBOX_HGCM_SVC_PARM_PTR;
|
---|
3597 | pCtl->aParms[0].u.pointer.addr = pData;
|
---|
3598 | pCtl->aParms[0].u.pointer.size = sizeof(*pData);
|
---|
3599 |
|
---|
3600 | rc = i_crCtlSubmitSync(&pCtl->Hdr, sizeof(*pCtl));
|
---|
3601 | if (RT_FAILURE(rc))
|
---|
3602 | AssertMsgFailed(("crCtlSubmitSync failed (rc=%Rrc)\n", rc));
|
---|
3603 | else
|
---|
3604 | hr = S_OK;
|
---|
3605 |
|
---|
3606 | RTMemFree(pCtl);
|
---|
3607 | }
|
---|
3608 | else
|
---|
3609 | {
|
---|
3610 | LogRel(("Running out of memory on attempt to notify OpenGL about HiDPI output scaling policy change. Ignored.\n"));
|
---|
3611 | hr = E_OUTOFMEMORY;
|
---|
3612 | }
|
---|
3613 | }
|
---|
3614 | else
|
---|
3615 | LogRel(("Internal error occurred on attempt to notify OpenGL about HiDPI output scaling policy change. Ignored.\n"));
|
---|
3616 | }
|
---|
3617 | else
|
---|
3618 | LogRel(("Attempt to notify OpenGL about HiDPI output scaling policy change while corresponding HGCM host service not yet runing. Ignored.\n"));
|
---|
3619 | }
|
---|
3620 | else
|
---|
3621 | {
|
---|
3622 | hr = S_OK;
|
---|
3623 | /* Need an interface like this here (and the #ifdefs needs adjusting):
|
---|
3624 | PPDMIDISPLAYPORT pUpPort = mpDrv ? mpDrv->pUpPort : NULL;
|
---|
3625 | if (pUpPort && pUpPort->pfnSetScaleFactor)
|
---|
3626 | pUpPort->pfnSetScaleFactor(pUpPort, aScreeId, aScaleFactorWMultiplied, aScaleFactorHMultiplied); */
|
---|
3627 | }
|
---|
3628 |
|
---|
3629 | return hr;
|
---|
3630 | #else
|
---|
3631 | AssertMsgFailed(("Attempt to notify OpenGL about HiDPI output scaling policy change while corresponding functionality is disabled."));
|
---|
3632 | return E_UNEXPECTED;
|
---|
3633 | #endif /* VBOX_WITH_HGCM && VBOX_WITH_CROGL */
|
---|
3634 | }
|
---|
3635 |
|
---|
3636 | #if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
|
---|
3637 | DECLCALLBACK(void) Display::i_displayCrVRecScreenshotPerform(void *pvCtx, uint32_t uScreen,
|
---|
3638 | uint32_t x, uint32_t y,
|
---|
3639 | uint32_t uBitsPerPixel, uint32_t uBytesPerLine,
|
---|
3640 | uint32_t uGuestWidth, uint32_t uGuestHeight,
|
---|
3641 | uint8_t *pu8BufferAddress, uint64_t u64TimeStamp)
|
---|
3642 | {
|
---|
3643 | Display *pDisplay = (Display *)pvCtx;
|
---|
3644 | pDisplay->i_handleCrVRecScreenshotPerform(uScreen,
|
---|
3645 | x, y, BitmapFormat_BGR, uBitsPerPixel,
|
---|
3646 | uBytesPerLine, uGuestWidth, uGuestHeight,
|
---|
3647 | pu8BufferAddress, u64TimeStamp);
|
---|
3648 | }
|
---|
3649 |
|
---|
3650 | DECLCALLBACK(bool) Display::i_displayCrVRecScreenshotBegin(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp)
|
---|
3651 | {
|
---|
3652 | Display *pDisplay = (Display *)pvCtx;
|
---|
3653 | return pDisplay->i_handleCrVRecScreenshotBegin(uScreen, u64TimeStamp);
|
---|
3654 | }
|
---|
3655 |
|
---|
3656 | DECLCALLBACK(void) Display::i_displayCrVRecScreenshotEnd(void *pvCtx, uint32_t uScreen, uint64_t u64TimeStamp)
|
---|
3657 | {
|
---|
3658 | Display *pDisplay = (Display *)pvCtx;
|
---|
3659 | pDisplay->i_handleCrVRecScreenshotEnd(uScreen, u64TimeStamp);
|
---|
3660 | }
|
---|
3661 |
|
---|
3662 | DECLCALLBACK(void) Display::i_displayVRecCompletion(struct VBOXCRCMDCTL* pCmd, uint32_t cbCmd, int rc, void *pvCompletion)
|
---|
3663 | {
|
---|
3664 | Display *pDisplay = (Display *)pvCompletion;
|
---|
3665 | pDisplay->i_handleVRecCompletion();
|
---|
3666 | }
|
---|
3667 |
|
---|
3668 | #endif
|
---|
3669 |
|
---|
3670 |
|
---|
3671 | #ifdef VBOX_WITH_HGSMI
|
---|
3672 | DECLCALLBACK(int) Display::i_displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags,
|
---|
3673 | bool fRenderThreadMode)
|
---|
3674 | {
|
---|
3675 | LogRelFlowFunc(("uScreenId %d\n", uScreenId));
|
---|
3676 |
|
---|
3677 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3678 | Display *pThis = pDrv->pDisplay;
|
---|
3679 |
|
---|
3680 | if (pThis->maFramebuffers[uScreenId].fVBVAEnabled && pThis->maFramebuffers[uScreenId].fRenderThreadMode != fRenderThreadMode)
|
---|
3681 | {
|
---|
3682 | LogRel(("Enabling different vbva mode\n"));
|
---|
3683 | #ifdef DEBUG_misha
|
---|
3684 | AssertMsgFailed(("enabling different vbva mode\n"));
|
---|
3685 | #endif
|
---|
3686 | return VERR_INVALID_STATE;
|
---|
3687 | }
|
---|
3688 |
|
---|
3689 | pThis->maFramebuffers[uScreenId].fVBVAEnabled = true;
|
---|
3690 | pThis->maFramebuffers[uScreenId].pVBVAHostFlags = pHostFlags;
|
---|
3691 | pThis->maFramebuffers[uScreenId].fRenderThreadMode = fRenderThreadMode;
|
---|
3692 | pThis->maFramebuffers[uScreenId].fVBVAForceResize = true;
|
---|
3693 |
|
---|
3694 | vbvaSetMemoryFlagsHGSMI(uScreenId, pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, &pThis->maFramebuffers[uScreenId]);
|
---|
3695 |
|
---|
3696 | return VINF_SUCCESS;
|
---|
3697 | }
|
---|
3698 |
|
---|
3699 | DECLCALLBACK(void) Display::i_displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
|
---|
3700 | {
|
---|
3701 | LogRelFlowFunc(("uScreenId %d\n", uScreenId));
|
---|
3702 |
|
---|
3703 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3704 | Display *pThis = pDrv->pDisplay;
|
---|
3705 |
|
---|
3706 | DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
|
---|
3707 |
|
---|
3708 | bool fRenderThreadMode = pFBInfo->fRenderThreadMode;
|
---|
3709 |
|
---|
3710 | if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
|
---|
3711 | {
|
---|
3712 | /* Make sure that the primary screen is visible now.
|
---|
3713 | * The guest can't use VBVA anymore, so only only the VGA device output works.
|
---|
3714 | */
|
---|
3715 | if (pFBInfo->fDisabled)
|
---|
3716 | {
|
---|
3717 | pFBInfo->fDisabled = false;
|
---|
3718 | fireGuestMonitorChangedEvent(pThis->mParent->i_getEventSource(),
|
---|
3719 | GuestMonitorChangedEventType_Enabled,
|
---|
3720 | uScreenId,
|
---|
3721 | pFBInfo->xOrigin, pFBInfo->yOrigin,
|
---|
3722 | pFBInfo->w, pFBInfo->h);
|
---|
3723 | }
|
---|
3724 | }
|
---|
3725 |
|
---|
3726 | pFBInfo->fVBVAEnabled = false;
|
---|
3727 | pFBInfo->fVBVAForceResize = false;
|
---|
3728 | pFBInfo->fRenderThreadMode = false;
|
---|
3729 |
|
---|
3730 | vbvaSetMemoryFlagsHGSMI(uScreenId, 0, false, pFBInfo);
|
---|
3731 |
|
---|
3732 | pFBInfo->pVBVAHostFlags = NULL;
|
---|
3733 |
|
---|
3734 | if (!fRenderThreadMode && uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
|
---|
3735 | {
|
---|
3736 | /* Force full screen update, because VGA device must take control, do resize, etc. */
|
---|
3737 | pThis->mpDrv->pUpPort->pfnUpdateDisplayAll(pThis->mpDrv->pUpPort, /* fFailOnResize = */ false);
|
---|
3738 | }
|
---|
3739 | }
|
---|
3740 |
|
---|
3741 | DECLCALLBACK(void) Display::i_displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
|
---|
3742 | {
|
---|
3743 | LogFlowFunc(("uScreenId %d\n", uScreenId));
|
---|
3744 |
|
---|
3745 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3746 | Display *pThis = pDrv->pDisplay;
|
---|
3747 | DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
|
---|
3748 |
|
---|
3749 | if (ASMAtomicReadU32(&pThis->mu32UpdateVBVAFlags) > 0)
|
---|
3750 | {
|
---|
3751 | vbvaSetMemoryFlagsAllHGSMI(pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, pThis->maFramebuffers,
|
---|
3752 | pThis->mcMonitors);
|
---|
3753 | ASMAtomicDecU32(&pThis->mu32UpdateVBVAFlags);
|
---|
3754 | }
|
---|
3755 | }
|
---|
3756 |
|
---|
3757 | DECLCALLBACK(void) Display::i_displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId,
|
---|
3758 | const PVBVACMDHDR pCmd, size_t cbCmd)
|
---|
3759 | {
|
---|
3760 | LogFlowFunc(("uScreenId %d pCmd %p cbCmd %d, @%d,%d %dx%d\n", uScreenId, pCmd, cbCmd, pCmd->x, pCmd->y, pCmd->w, pCmd->h));
|
---|
3761 |
|
---|
3762 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3763 | Display *pThis = pDrv->pDisplay;
|
---|
3764 | DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
|
---|
3765 |
|
---|
3766 | if (pFBInfo->fDefaultFormat)
|
---|
3767 | {
|
---|
3768 | /* Make sure that framebuffer contains the same image as the guest VRAM. */
|
---|
3769 | if ( uScreenId == VBOX_VIDEO_PRIMARY_SCREEN
|
---|
3770 | && !pFBInfo->fDisabled)
|
---|
3771 | {
|
---|
3772 | pDrv->pUpPort->pfnUpdateDisplayRect(pDrv->pUpPort, pCmd->x, pCmd->y, pCmd->w, pCmd->h);
|
---|
3773 | }
|
---|
3774 | else if ( !pFBInfo->pSourceBitmap.isNull()
|
---|
3775 | && !pFBInfo->fDisabled)
|
---|
3776 | {
|
---|
3777 | /* Render VRAM content to the framebuffer. */
|
---|
3778 | BYTE *pAddress = NULL;
|
---|
3779 | ULONG ulWidth = 0;
|
---|
3780 | ULONG ulHeight = 0;
|
---|
3781 | ULONG ulBitsPerPixel = 0;
|
---|
3782 | ULONG ulBytesPerLine = 0;
|
---|
3783 | BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
|
---|
3784 |
|
---|
3785 | HRESULT hrc = pFBInfo->pSourceBitmap->QueryBitmapInfo(&pAddress,
|
---|
3786 | &ulWidth,
|
---|
3787 | &ulHeight,
|
---|
3788 | &ulBitsPerPixel,
|
---|
3789 | &ulBytesPerLine,
|
---|
3790 | &bitmapFormat);
|
---|
3791 | if (SUCCEEDED(hrc))
|
---|
3792 | {
|
---|
3793 | uint32_t width = pCmd->w;
|
---|
3794 | uint32_t height = pCmd->h;
|
---|
3795 |
|
---|
3796 | const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
|
---|
3797 | int32_t xSrc = pCmd->x - pFBInfo->xOrigin;
|
---|
3798 | int32_t ySrc = pCmd->y - pFBInfo->yOrigin;
|
---|
3799 | uint32_t u32SrcWidth = pFBInfo->w;
|
---|
3800 | uint32_t u32SrcHeight = pFBInfo->h;
|
---|
3801 | uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
|
---|
3802 | uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
|
---|
3803 |
|
---|
3804 | uint8_t *pu8Dst = pAddress;
|
---|
3805 | int32_t xDst = xSrc;
|
---|
3806 | int32_t yDst = ySrc;
|
---|
3807 | uint32_t u32DstWidth = u32SrcWidth;
|
---|
3808 | uint32_t u32DstHeight = u32SrcHeight;
|
---|
3809 | uint32_t u32DstLineSize = u32DstWidth * 4;
|
---|
3810 | uint32_t u32DstBitsPerPixel = 32;
|
---|
3811 |
|
---|
3812 | pDrv->pUpPort->pfnCopyRect(pDrv->pUpPort,
|
---|
3813 | width, height,
|
---|
3814 | pu8Src,
|
---|
3815 | xSrc, ySrc,
|
---|
3816 | u32SrcWidth, u32SrcHeight,
|
---|
3817 | u32SrcLineSize, u32SrcBitsPerPixel,
|
---|
3818 | pu8Dst,
|
---|
3819 | xDst, yDst,
|
---|
3820 | u32DstWidth, u32DstHeight,
|
---|
3821 | u32DstLineSize, u32DstBitsPerPixel);
|
---|
3822 | }
|
---|
3823 | }
|
---|
3824 | }
|
---|
3825 |
|
---|
3826 | VBVACMDHDR hdrSaved = *pCmd;
|
---|
3827 |
|
---|
3828 | VBVACMDHDR *pHdrUnconst = (VBVACMDHDR *)pCmd;
|
---|
3829 |
|
---|
3830 | pHdrUnconst->x -= (int16_t)pFBInfo->xOrigin;
|
---|
3831 | pHdrUnconst->y -= (int16_t)pFBInfo->yOrigin;
|
---|
3832 |
|
---|
3833 | /* @todo new SendUpdate entry which can get a separate cmd header or coords. */
|
---|
3834 | pThis->mParent->i_consoleVRDPServer()->SendUpdate(uScreenId, pCmd, (uint32_t)cbCmd);
|
---|
3835 |
|
---|
3836 | *pHdrUnconst = hdrSaved;
|
---|
3837 | }
|
---|
3838 |
|
---|
3839 | DECLCALLBACK(void) Display::i_displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y,
|
---|
3840 | uint32_t cx, uint32_t cy)
|
---|
3841 | {
|
---|
3842 | LogFlowFunc(("uScreenId %d %d,%d %dx%d\n", uScreenId, x, y, cx, cy));
|
---|
3843 |
|
---|
3844 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3845 | Display *pThis = pDrv->pDisplay;
|
---|
3846 | DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
|
---|
3847 |
|
---|
3848 | /* @todo handleFramebufferUpdate (uScreenId,
|
---|
3849 | * x - pThis->maFramebuffers[uScreenId].xOrigin,
|
---|
3850 | * y - pThis->maFramebuffers[uScreenId].yOrigin,
|
---|
3851 | * cx, cy);
|
---|
3852 | */
|
---|
3853 | pThis->i_handleDisplayUpdate(uScreenId, x - pFBInfo->xOrigin, y - pFBInfo->yOrigin, cx, cy);
|
---|
3854 | }
|
---|
3855 |
|
---|
3856 | #ifdef DEBUG_sunlover
|
---|
3857 | static void logVBVAResize(const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, const DISPLAYFBINFO *pFBInfo)
|
---|
3858 | {
|
---|
3859 | LogRel(("displayVBVAResize: [%d] %s\n"
|
---|
3860 | " pView->u32ViewIndex %d\n"
|
---|
3861 | " pView->u32ViewOffset 0x%08X\n"
|
---|
3862 | " pView->u32ViewSize 0x%08X\n"
|
---|
3863 | " pView->u32MaxScreenSize 0x%08X\n"
|
---|
3864 | " pScreen->i32OriginX %d\n"
|
---|
3865 | " pScreen->i32OriginY %d\n"
|
---|
3866 | " pScreen->u32StartOffset 0x%08X\n"
|
---|
3867 | " pScreen->u32LineSize 0x%08X\n"
|
---|
3868 | " pScreen->u32Width %d\n"
|
---|
3869 | " pScreen->u32Height %d\n"
|
---|
3870 | " pScreen->u16BitsPerPixel %d\n"
|
---|
3871 | " pScreen->u16Flags 0x%04X\n"
|
---|
3872 | " pFBInfo->u32Offset 0x%08X\n"
|
---|
3873 | " pFBInfo->u32MaxFramebufferSize 0x%08X\n"
|
---|
3874 | " pFBInfo->u32InformationSize 0x%08X\n"
|
---|
3875 | " pFBInfo->fDisabled %d\n"
|
---|
3876 | " xOrigin, yOrigin, w, h: %d,%d %dx%d\n"
|
---|
3877 | " pFBInfo->u16BitsPerPixel %d\n"
|
---|
3878 | " pFBInfo->pu8FramebufferVRAM %p\n"
|
---|
3879 | " pFBInfo->u32LineSize 0x%08X\n"
|
---|
3880 | " pFBInfo->flags 0x%04X\n"
|
---|
3881 | " pFBInfo->pHostEvents %p\n"
|
---|
3882 | " pFBInfo->fDefaultFormat %d\n"
|
---|
3883 | " pFBInfo->fVBVAEnabled %d\n"
|
---|
3884 | " pFBInfo->fVBVAForceResize %d\n"
|
---|
3885 | " pFBInfo->pVBVAHostFlags %p\n"
|
---|
3886 | "",
|
---|
3887 | pScreen->u32ViewIndex,
|
---|
3888 | (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)? "DISABLED": "ENABLED",
|
---|
3889 | pView->u32ViewIndex,
|
---|
3890 | pView->u32ViewOffset,
|
---|
3891 | pView->u32ViewSize,
|
---|
3892 | pView->u32MaxScreenSize,
|
---|
3893 | pScreen->i32OriginX,
|
---|
3894 | pScreen->i32OriginY,
|
---|
3895 | pScreen->u32StartOffset,
|
---|
3896 | pScreen->u32LineSize,
|
---|
3897 | pScreen->u32Width,
|
---|
3898 | pScreen->u32Height,
|
---|
3899 | pScreen->u16BitsPerPixel,
|
---|
3900 | pScreen->u16Flags,
|
---|
3901 | pFBInfo->u32Offset,
|
---|
3902 | pFBInfo->u32MaxFramebufferSize,
|
---|
3903 | pFBInfo->u32InformationSize,
|
---|
3904 | pFBInfo->fDisabled,
|
---|
3905 | pFBInfo->xOrigin,
|
---|
3906 | pFBInfo->yOrigin,
|
---|
3907 | pFBInfo->w,
|
---|
3908 | pFBInfo->h,
|
---|
3909 | pFBInfo->u16BitsPerPixel,
|
---|
3910 | pFBInfo->pu8FramebufferVRAM,
|
---|
3911 | pFBInfo->u32LineSize,
|
---|
3912 | pFBInfo->flags,
|
---|
3913 | pFBInfo->pHostEvents,
|
---|
3914 | pFBInfo->fDefaultFormat,
|
---|
3915 | pFBInfo->fVBVAEnabled,
|
---|
3916 | pFBInfo->fVBVAForceResize,
|
---|
3917 | pFBInfo->pVBVAHostFlags
|
---|
3918 | ));
|
---|
3919 | }
|
---|
3920 | #endif /* DEBUG_sunlover */
|
---|
3921 |
|
---|
3922 | DECLCALLBACK(int) Display::i_displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView,
|
---|
3923 | const PVBVAINFOSCREEN pScreen, void *pvVRAM)
|
---|
3924 | {
|
---|
3925 | LogRelFlowFunc(("pScreen %p, pvVRAM %p\n", pScreen, pvVRAM));
|
---|
3926 |
|
---|
3927 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
3928 | Display *pThis = pDrv->pDisplay;
|
---|
3929 |
|
---|
3930 | DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[pScreen->u32ViewIndex];
|
---|
3931 |
|
---|
3932 | if (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)
|
---|
3933 | {
|
---|
3934 | pThis->i_notifyCroglResize(pView, pScreen, pvVRAM);
|
---|
3935 |
|
---|
3936 | pFBInfo->fDisabled = true;
|
---|
3937 | pFBInfo->flags = pScreen->u16Flags;
|
---|
3938 |
|
---|
3939 | /* Ask the framebuffer to resize using a default format. The framebuffer will be black.
|
---|
3940 | * So if the frontend does not support GuestMonitorChangedEventType_Disabled event,
|
---|
3941 | * the VM window will be black. */
|
---|
3942 | uint32_t u32Width = pFBInfo->w ? pFBInfo->w : 640;
|
---|
3943 | uint32_t u32Height = pFBInfo->h ? pFBInfo->h : 480;
|
---|
3944 | pThis->i_handleDisplayResize(pScreen->u32ViewIndex, 0, (uint8_t *)NULL, 0,
|
---|
3945 | u32Width, u32Height, pScreen->u16Flags);
|
---|
3946 |
|
---|
3947 | fireGuestMonitorChangedEvent(pThis->mParent->i_getEventSource(),
|
---|
3948 | GuestMonitorChangedEventType_Disabled,
|
---|
3949 | pScreen->u32ViewIndex,
|
---|
3950 | 0, 0, 0, 0);
|
---|
3951 | return VINF_SUCCESS;
|
---|
3952 | }
|
---|
3953 |
|
---|
3954 | /* If display was disabled or there is no framebuffer, a resize will be required,
|
---|
3955 | * because the framebuffer was/will be changed.
|
---|
3956 | */
|
---|
3957 | bool fResize = pFBInfo->fDisabled || pFBInfo->pFramebuffer.isNull();
|
---|
3958 |
|
---|
3959 | if (pFBInfo->fVBVAForceResize)
|
---|
3960 | {
|
---|
3961 | /* VBVA was just enabled. Do the resize. */
|
---|
3962 | fResize = true;
|
---|
3963 | pFBInfo->fVBVAForceResize = false;
|
---|
3964 | }
|
---|
3965 |
|
---|
3966 | /* If the screen if blanked, then do a resize request to make sure that the framebuffer
|
---|
3967 | * switches to the default format.
|
---|
3968 | */
|
---|
3969 | fResize = fResize || RT_BOOL((pScreen->u16Flags ^ pFBInfo->flags) & VBVA_SCREEN_F_BLANK);
|
---|
3970 |
|
---|
3971 | /* Check if this is a real resize or a notification about the screen origin.
|
---|
3972 | * The guest uses this VBVAResize call for both.
|
---|
3973 | */
|
---|
3974 | fResize = fResize
|
---|
3975 | || pFBInfo->u16BitsPerPixel != pScreen->u16BitsPerPixel
|
---|
3976 | || pFBInfo->pu8FramebufferVRAM != (uint8_t *)pvVRAM + pScreen->u32StartOffset
|
---|
3977 | || pFBInfo->u32LineSize != pScreen->u32LineSize
|
---|
3978 | || pFBInfo->w != pScreen->u32Width
|
---|
3979 | || pFBInfo->h != pScreen->u32Height;
|
---|
3980 |
|
---|
3981 | bool fNewOrigin = pFBInfo->xOrigin != pScreen->i32OriginX
|
---|
3982 | || pFBInfo->yOrigin != pScreen->i32OriginY;
|
---|
3983 |
|
---|
3984 | if (fNewOrigin || fResize)
|
---|
3985 | pThis->i_notifyCroglResize(pView, pScreen, pvVRAM);
|
---|
3986 |
|
---|
3987 | if (pFBInfo->fDisabled)
|
---|
3988 | {
|
---|
3989 | pFBInfo->fDisabled = false;
|
---|
3990 | fireGuestMonitorChangedEvent(pThis->mParent->i_getEventSource(),
|
---|
3991 | GuestMonitorChangedEventType_Enabled,
|
---|
3992 | pScreen->u32ViewIndex,
|
---|
3993 | pScreen->i32OriginX, pScreen->i32OriginY,
|
---|
3994 | pScreen->u32Width, pScreen->u32Height);
|
---|
3995 | /* Continue to update pFBInfo. */
|
---|
3996 | }
|
---|
3997 |
|
---|
3998 | pFBInfo->u32Offset = pView->u32ViewOffset; /* Not used in HGSMI. */
|
---|
3999 | pFBInfo->u32MaxFramebufferSize = pView->u32MaxScreenSize; /* Not used in HGSMI. */
|
---|
4000 | pFBInfo->u32InformationSize = 0; /* Not used in HGSMI. */
|
---|
4001 |
|
---|
4002 | pFBInfo->xOrigin = pScreen->i32OriginX;
|
---|
4003 | pFBInfo->yOrigin = pScreen->i32OriginY;
|
---|
4004 |
|
---|
4005 | pFBInfo->w = pScreen->u32Width;
|
---|
4006 | pFBInfo->h = pScreen->u32Height;
|
---|
4007 |
|
---|
4008 | pFBInfo->u16BitsPerPixel = pScreen->u16BitsPerPixel;
|
---|
4009 | pFBInfo->pu8FramebufferVRAM = (uint8_t *)pvVRAM + pScreen->u32StartOffset;
|
---|
4010 | pFBInfo->u32LineSize = pScreen->u32LineSize;
|
---|
4011 |
|
---|
4012 | pFBInfo->flags = pScreen->u16Flags;
|
---|
4013 |
|
---|
4014 | pThis->xInputMappingOrigin = 0;
|
---|
4015 | pThis->yInputMappingOrigin = 0;
|
---|
4016 | pThis->cxInputMapping = 0;
|
---|
4017 | pThis->cyInputMapping = 0;
|
---|
4018 |
|
---|
4019 | if (fNewOrigin)
|
---|
4020 | {
|
---|
4021 | fireGuestMonitorChangedEvent(pThis->mParent->i_getEventSource(),
|
---|
4022 | GuestMonitorChangedEventType_NewOrigin,
|
---|
4023 | pScreen->u32ViewIndex,
|
---|
4024 | pScreen->i32OriginX, pScreen->i32OriginY,
|
---|
4025 | 0, 0);
|
---|
4026 | }
|
---|
4027 |
|
---|
4028 | if (!fResize)
|
---|
4029 | {
|
---|
4030 | /* No parameters of the framebuffer have actually changed. */
|
---|
4031 | if (fNewOrigin)
|
---|
4032 | {
|
---|
4033 | /* VRDP server still need this notification. */
|
---|
4034 | LogRelFlowFunc(("Calling VRDP\n"));
|
---|
4035 | pThis->mParent->i_consoleVRDPServer()->SendResize();
|
---|
4036 | }
|
---|
4037 | return VINF_SUCCESS;
|
---|
4038 | }
|
---|
4039 |
|
---|
4040 | /* Do a regular resize. */
|
---|
4041 | return pThis->i_handleDisplayResize(pScreen->u32ViewIndex, pScreen->u16BitsPerPixel,
|
---|
4042 | (uint8_t *)pvVRAM + pScreen->u32StartOffset,
|
---|
4043 | pScreen->u32LineSize, pScreen->u32Width, pScreen->u32Height, pScreen->u16Flags);
|
---|
4044 | }
|
---|
4045 |
|
---|
4046 | DECLCALLBACK(int) Display::i_displayVBVAMousePointerShape(PPDMIDISPLAYCONNECTOR pInterface, bool fVisible, bool fAlpha,
|
---|
4047 | uint32_t xHot, uint32_t yHot,
|
---|
4048 | uint32_t cx, uint32_t cy,
|
---|
4049 | const void *pvShape)
|
---|
4050 | {
|
---|
4051 | LogFlowFunc(("\n"));
|
---|
4052 |
|
---|
4053 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
4054 | Display *pThis = pDrv->pDisplay;
|
---|
4055 |
|
---|
4056 | uint32_t cbShape = 0;
|
---|
4057 | if (pvShape)
|
---|
4058 | {
|
---|
4059 | cbShape = (cx + 7) / 8 * cy; /* size of the AND mask */
|
---|
4060 | cbShape = ((cbShape + 3) & ~3) + cx * 4 * cy; /* + gap + size of the XOR mask */
|
---|
4061 | }
|
---|
4062 |
|
---|
4063 | /* Tell the console about it */
|
---|
4064 | pDrv->pDisplay->mParent->i_onMousePointerShapeChange(fVisible, fAlpha,
|
---|
4065 | xHot, yHot, cx, cy, (uint8_t *)pvShape, cbShape);
|
---|
4066 |
|
---|
4067 | return VINF_SUCCESS;
|
---|
4068 | }
|
---|
4069 |
|
---|
4070 | DECLCALLBACK(void) Display::i_displayVBVAGuestCapabilityUpdate(PPDMIDISPLAYCONNECTOR pInterface, uint32_t fCapabilities)
|
---|
4071 | {
|
---|
4072 | LogFlowFunc(("\n"));
|
---|
4073 |
|
---|
4074 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
4075 | Display *pThis = pDrv->pDisplay;
|
---|
4076 |
|
---|
4077 | pThis->i_handleUpdateGuestVBVACapabilities(fCapabilities);
|
---|
4078 | }
|
---|
4079 |
|
---|
4080 | DECLCALLBACK(void) Display::i_displayVBVAInputMappingUpdate(PPDMIDISPLAYCONNECTOR pInterface, int32_t xOrigin, int32_t yOrigin,
|
---|
4081 | uint32_t cx, uint32_t cy)
|
---|
4082 | {
|
---|
4083 | LogFlowFunc(("\n"));
|
---|
4084 |
|
---|
4085 | PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
|
---|
4086 | Display *pThis = pDrv->pDisplay;
|
---|
4087 |
|
---|
4088 | pThis->i_handleUpdateVBVAInputMapping(xOrigin, yOrigin, cx, cy);
|
---|
4089 | }
|
---|
4090 |
|
---|
4091 | #endif /* VBOX_WITH_HGSMI */
|
---|
4092 |
|
---|
4093 | /**
|
---|
4094 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
4095 | */
|
---|
4096 | DECLCALLBACK(void *) Display::i_drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
4097 | {
|
---|
4098 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
4099 | PDRVMAINDISPLAY pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
|
---|
4100 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
4101 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIDISPLAYCONNECTOR, &pDrv->IConnector);
|
---|
4102 | return NULL;
|
---|
4103 | }
|
---|
4104 |
|
---|
4105 |
|
---|
4106 | /**
|
---|
4107 | * Destruct a display driver instance.
|
---|
4108 | *
|
---|
4109 | * @returns VBox status code.
|
---|
4110 | * @param pDrvIns The driver instance data.
|
---|
4111 | */
|
---|
4112 | DECLCALLBACK(void) Display::i_drvDestruct(PPDMDRVINS pDrvIns)
|
---|
4113 | {
|
---|
4114 | PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
|
---|
4115 | PDRVMAINDISPLAY pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
|
---|
4116 | LogRelFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
|
---|
4117 |
|
---|
4118 | pThis->pUpPort->pfnSetRenderVRAM(pThis->pUpPort, false);
|
---|
4119 |
|
---|
4120 | pThis->IConnector.pbData = NULL;
|
---|
4121 | pThis->IConnector.cbScanline = 0;
|
---|
4122 | pThis->IConnector.cBits = 32;
|
---|
4123 | pThis->IConnector.cx = 0;
|
---|
4124 | pThis->IConnector.cy = 0;
|
---|
4125 |
|
---|
4126 | if (pThis->pDisplay)
|
---|
4127 | {
|
---|
4128 | AutoWriteLock displayLock(pThis->pDisplay COMMA_LOCKVAL_SRC_POS);
|
---|
4129 | #ifdef VBOX_WITH_VPX
|
---|
4130 | pThis->pDisplay->i_VideoCaptureStop();
|
---|
4131 | #endif
|
---|
4132 | #ifdef VBOX_WITH_CRHGSMI
|
---|
4133 | pThis->pDisplay->i_destructCrHgsmiData();
|
---|
4134 | #endif
|
---|
4135 | pThis->pDisplay->mpDrv = NULL;
|
---|
4136 | pThis->pDisplay->mpVMMDev = NULL;
|
---|
4137 | }
|
---|
4138 | }
|
---|
4139 |
|
---|
4140 |
|
---|
4141 | /**
|
---|
4142 | * Construct a display driver instance.
|
---|
4143 | *
|
---|
4144 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
4145 | */
|
---|
4146 | DECLCALLBACK(int) Display::i_drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
4147 | {
|
---|
4148 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
4149 | PDRVMAINDISPLAY pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
|
---|
4150 | LogRelFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
|
---|
4151 |
|
---|
4152 | /*
|
---|
4153 | * Validate configuration.
|
---|
4154 | */
|
---|
4155 | if (!CFGMR3AreValuesValid(pCfg, "Object\0"))
|
---|
4156 | return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
|
---|
4157 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
4158 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
4159 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
4160 |
|
---|
4161 | /*
|
---|
4162 | * Init Interfaces.
|
---|
4163 | */
|
---|
4164 | pDrvIns->IBase.pfnQueryInterface = Display::i_drvQueryInterface;
|
---|
4165 |
|
---|
4166 | pThis->IConnector.pfnResize = Display::i_displayResizeCallback;
|
---|
4167 | pThis->IConnector.pfnUpdateRect = Display::i_displayUpdateCallback;
|
---|
4168 | pThis->IConnector.pfnRefresh = Display::i_displayRefreshCallback;
|
---|
4169 | pThis->IConnector.pfnReset = Display::i_displayResetCallback;
|
---|
4170 | pThis->IConnector.pfnLFBModeChange = Display::i_displayLFBModeChangeCallback;
|
---|
4171 | pThis->IConnector.pfnProcessAdapterData = Display::i_displayProcessAdapterDataCallback;
|
---|
4172 | pThis->IConnector.pfnProcessDisplayData = Display::i_displayProcessDisplayDataCallback;
|
---|
4173 | #ifdef VBOX_WITH_VIDEOHWACCEL
|
---|
4174 | pThis->IConnector.pfnVHWACommandProcess = Display::i_displayVHWACommandProcess;
|
---|
4175 | #endif
|
---|
4176 | #ifdef VBOX_WITH_CRHGSMI
|
---|
4177 | pThis->IConnector.pfnCrHgsmiCommandProcess = Display::i_displayCrHgsmiCommandProcess;
|
---|
4178 | pThis->IConnector.pfnCrHgsmiControlProcess = Display::i_displayCrHgsmiControlProcess;
|
---|
4179 | #endif
|
---|
4180 | #if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
|
---|
4181 | pThis->IConnector.pfnCrHgcmCtlSubmit = Display::i_displayCrHgcmCtlSubmit;
|
---|
4182 | #endif
|
---|
4183 | #ifdef VBOX_WITH_HGSMI
|
---|
4184 | pThis->IConnector.pfnVBVAEnable = Display::i_displayVBVAEnable;
|
---|
4185 | pThis->IConnector.pfnVBVADisable = Display::i_displayVBVADisable;
|
---|
4186 | pThis->IConnector.pfnVBVAUpdateBegin = Display::i_displayVBVAUpdateBegin;
|
---|
4187 | pThis->IConnector.pfnVBVAUpdateProcess = Display::i_displayVBVAUpdateProcess;
|
---|
4188 | pThis->IConnector.pfnVBVAUpdateEnd = Display::i_displayVBVAUpdateEnd;
|
---|
4189 | pThis->IConnector.pfnVBVAResize = Display::i_displayVBVAResize;
|
---|
4190 | pThis->IConnector.pfnVBVAMousePointerShape = Display::i_displayVBVAMousePointerShape;
|
---|
4191 | pThis->IConnector.pfnVBVAGuestCapabilityUpdate = Display::i_displayVBVAGuestCapabilityUpdate;
|
---|
4192 | pThis->IConnector.pfnVBVAInputMappingUpdate = Display::i_displayVBVAInputMappingUpdate;
|
---|
4193 | #endif
|
---|
4194 |
|
---|
4195 | /*
|
---|
4196 | * Get the IDisplayPort interface of the above driver/device.
|
---|
4197 | */
|
---|
4198 | pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYPORT);
|
---|
4199 | if (!pThis->pUpPort)
|
---|
4200 | {
|
---|
4201 | AssertMsgFailed(("Configuration error: No display port interface above!\n"));
|
---|
4202 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
4203 | }
|
---|
4204 | #if defined(VBOX_WITH_VIDEOHWACCEL) || defined(VBOX_WITH_CRHGSMI)
|
---|
4205 | pThis->pVBVACallbacks = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYVBVACALLBACKS);
|
---|
4206 | if (!pThis->pVBVACallbacks)
|
---|
4207 | {
|
---|
4208 | AssertMsgFailed(("Configuration error: No VBVA callback interface above!\n"));
|
---|
4209 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
4210 | }
|
---|
4211 | #endif
|
---|
4212 | /*
|
---|
4213 | * Get the Display object pointer and update the mpDrv member.
|
---|
4214 | */
|
---|
4215 | void *pv;
|
---|
4216 | int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
|
---|
4217 | if (RT_FAILURE(rc))
|
---|
4218 | {
|
---|
4219 | AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
|
---|
4220 | return rc;
|
---|
4221 | }
|
---|
4222 | Display *pDisplay = (Display *)pv; /** @todo Check this cast! */
|
---|
4223 | pThis->pDisplay = pDisplay;
|
---|
4224 | pThis->pDisplay->mpDrv = pThis;
|
---|
4225 |
|
---|
4226 | /* Disable VRAM to a buffer copy initially. */
|
---|
4227 | pThis->pUpPort->pfnSetRenderVRAM(pThis->pUpPort, false);
|
---|
4228 | pThis->IConnector.cBits = 32; /* DevVGA does nothing otherwise. */
|
---|
4229 |
|
---|
4230 | /*
|
---|
4231 | * Start periodic screen refreshes
|
---|
4232 | */
|
---|
4233 | pThis->pUpPort->pfnSetRefreshRate(pThis->pUpPort, 20);
|
---|
4234 |
|
---|
4235 | #ifdef VBOX_WITH_CRHGSMI
|
---|
4236 | pDisplay->i_setupCrHgsmiData();
|
---|
4237 | #endif
|
---|
4238 |
|
---|
4239 | #ifdef VBOX_WITH_VPX
|
---|
4240 | ComPtr<IMachine> pMachine = pDisplay->mParent->i_machine();
|
---|
4241 | BOOL fEnabled = false;
|
---|
4242 | HRESULT hrc = pMachine->COMGETTER(VideoCaptureEnabled)(&fEnabled);
|
---|
4243 | AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
|
---|
4244 | if (fEnabled)
|
---|
4245 | {
|
---|
4246 | rc = pDisplay->i_VideoCaptureStart();
|
---|
4247 | fireVideoCaptureChangedEvent(pDisplay->mParent->i_getEventSource());
|
---|
4248 | }
|
---|
4249 | #endif
|
---|
4250 |
|
---|
4251 | return rc;
|
---|
4252 | }
|
---|
4253 |
|
---|
4254 |
|
---|
4255 | /**
|
---|
4256 | * Display driver registration record.
|
---|
4257 | */
|
---|
4258 | const PDMDRVREG Display::DrvReg =
|
---|
4259 | {
|
---|
4260 | /* u32Version */
|
---|
4261 | PDM_DRVREG_VERSION,
|
---|
4262 | /* szName */
|
---|
4263 | "MainDisplay",
|
---|
4264 | /* szRCMod */
|
---|
4265 | "",
|
---|
4266 | /* szR0Mod */
|
---|
4267 | "",
|
---|
4268 | /* pszDescription */
|
---|
4269 | "Main display driver (Main as in the API).",
|
---|
4270 | /* fFlags */
|
---|
4271 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
4272 | /* fClass. */
|
---|
4273 | PDM_DRVREG_CLASS_DISPLAY,
|
---|
4274 | /* cMaxInstances */
|
---|
4275 | ~0U,
|
---|
4276 | /* cbInstance */
|
---|
4277 | sizeof(DRVMAINDISPLAY),
|
---|
4278 | /* pfnConstruct */
|
---|
4279 | Display::i_drvConstruct,
|
---|
4280 | /* pfnDestruct */
|
---|
4281 | Display::i_drvDestruct,
|
---|
4282 | /* pfnRelocate */
|
---|
4283 | NULL,
|
---|
4284 | /* pfnIOCtl */
|
---|
4285 | NULL,
|
---|
4286 | /* pfnPowerOn */
|
---|
4287 | NULL,
|
---|
4288 | /* pfnReset */
|
---|
4289 | NULL,
|
---|
4290 | /* pfnSuspend */
|
---|
4291 | NULL,
|
---|
4292 | /* pfnResume */
|
---|
4293 | NULL,
|
---|
4294 | /* pfnAttach */
|
---|
4295 | NULL,
|
---|
4296 | /* pfnDetach */
|
---|
4297 | NULL,
|
---|
4298 | /* pfnPowerOff */
|
---|
4299 | NULL,
|
---|
4300 | /* pfnSoftReset */
|
---|
4301 | NULL,
|
---|
4302 | /* u32EndVersion */
|
---|
4303 | PDM_DRVREG_VERSION
|
---|
4304 | };
|
---|
4305 |
|
---|
4306 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|