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