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