VirtualBox

source: vbox/trunk/src/VBox/Main/DisplayImpl.cpp@ 31892

Last change on this file since 31892 was 31718, checked in by vboxsync, 14 years ago

Main: PNG screenshoting API

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette