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