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