VirtualBox

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

Last change on this file since 27611 was 27607, checked in by vboxsync, 15 years ago

Main: remove templates for 'weak' com pointers which do nothing anyway

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

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