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