VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/DisplayImpl.cpp@ 93920

Last change on this file since 93920 was 93444, checked in by vboxsync, 3 years ago

VMM,Main,HostServices: Use a function table for accessing the VBoxVMM.dll/so/dylib functionality, and load it dynamically when the Console object is initialized. Also converted a few drivers in Main to use device helpers to get config values and such. bugref:10074

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 133.4 KB
Line 
1/* $Id: DisplayImpl.cpp 93444 2022-01-26 18:01:15Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#define LOG_GROUP LOG_GROUP_MAIN_DISPLAY
19#include "LoggingNew.h"
20
21#include "DisplayImpl.h"
22#include "DisplayUtils.h"
23#include "ConsoleImpl.h"
24#include "ConsoleVRDPServer.h"
25#include "GuestImpl.h"
26#include "VMMDev.h"
27
28#include "AutoCaller.h"
29
30/* generated header */
31#include "VBoxEvents.h"
32
33#include <iprt/semaphore.h>
34#include <iprt/thread.h>
35#include <iprt/asm.h>
36#include <iprt/time.h>
37#include <iprt/cpp/utils.h>
38#include <iprt/alloca.h>
39
40#include <VBox/vmm/vmmr3vtable.h>
41#include <VBox/vmm/pdmdrv.h>
42
43#ifdef VBOX_WITH_VIDEOHWACCEL
44# include <VBoxVideo.h>
45#endif
46#include <VBoxVideo3D.h>
47
48#include <VBox/com/array.h>
49
50#ifdef VBOX_WITH_RECORDING
51# include <iprt/path.h>
52# include "Recording.h"
53
54# ifdef VBOX_WITH_LIBVPX
55# ifdef _MSC_VER
56# pragma warning(push)
57# pragma warning(disable: 4668) /* vpx_codec.h(64) : warning C4668: '__GNUC__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */
58# include <vpx/vpx_encoder.h>
59# pragma warning(pop)
60# else
61# include <vpx/vpx_encoder.h>
62# endif
63# endif
64
65# include <VBox/vmm/pdmapi.h>
66# include <VBox/vmm/pdmaudioifs.h>
67#endif
68
69/**
70 * Display driver instance data.
71 *
72 * @implements PDMIDISPLAYCONNECTOR
73 */
74typedef struct DRVMAINDISPLAY
75{
76 /** Pointer to the display object. */
77 Display *pDisplay;
78 /** Pointer to the driver instance structure. */
79 PPDMDRVINS pDrvIns;
80 /** Pointer to the display port interface of the driver/device above us. */
81 PPDMIDISPLAYPORT pUpPort;
82 /** Our display connector interface. */
83 PDMIDISPLAYCONNECTOR IConnector;
84#if defined(VBOX_WITH_VIDEOHWACCEL)
85 /** VBVA callbacks */
86 PPDMIDISPLAYVBVACALLBACKS pVBVACallbacks;
87#endif
88} DRVMAINDISPLAY, *PDRVMAINDISPLAY;
89
90/** Converts PDMIDISPLAYCONNECTOR pointer to a DRVMAINDISPLAY pointer. */
91#define PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface) RT_FROM_MEMBER(pInterface, DRVMAINDISPLAY, IConnector)
92
93// constructor / destructor
94/////////////////////////////////////////////////////////////////////////////
95
96Display::Display()
97 : mParent(NULL)
98{
99}
100
101Display::~Display()
102{
103}
104
105
106HRESULT Display::FinalConstruct()
107{
108 int rc = videoAccelConstruct(&mVideoAccelLegacy);
109 AssertRC(rc);
110
111 mfVideoAccelVRDP = false;
112 mfu32SupportedOrders = 0;
113 mcVRDPRefs = 0;
114
115 mfSeamlessEnabled = false;
116 mpRectVisibleRegion = NULL;
117 mcRectVisibleRegion = 0;
118
119 mpDrv = NULL;
120
121 rc = RTCritSectInit(&mVideoAccelLock);
122 AssertRC(rc);
123
124#ifdef VBOX_WITH_HGSMI
125 mu32UpdateVBVAFlags = 0;
126 mfVMMDevSupportsGraphics = false;
127 mfGuestVBVACapabilities = 0;
128 mfHostCursorCapabilities = 0;
129#endif
130
131#ifdef VBOX_WITH_RECORDING
132 rc = RTCritSectInit(&mVideoRecLock);
133 AssertRC(rc);
134
135 for (unsigned i = 0; i < RT_ELEMENTS(maRecordingEnabled); i++)
136 maRecordingEnabled[i] = true;
137#endif
138
139 return BaseFinalConstruct();
140}
141
142void Display::FinalRelease()
143{
144 uninit();
145
146#ifdef VBOX_WITH_RECORDING
147 if (RTCritSectIsInitialized(&mVideoRecLock))
148 {
149 RTCritSectDelete(&mVideoRecLock);
150 RT_ZERO(mVideoRecLock);
151 }
152#endif
153
154 videoAccelDestroy(&mVideoAccelLegacy);
155 i_saveVisibleRegion(0, NULL);
156
157 if (RTCritSectIsInitialized(&mVideoAccelLock))
158 {
159 RTCritSectDelete(&mVideoAccelLock);
160 RT_ZERO(mVideoAccelLock);
161 }
162
163 BaseFinalRelease();
164}
165
166// public initializer/uninitializer for internal purposes only
167/////////////////////////////////////////////////////////////////////////////
168
169#define kMaxSizeThumbnail 64
170
171/**
172 * Save thumbnail and screenshot of the guest screen.
173 */
174static int displayMakeThumbnail(uint8_t *pbData, uint32_t cx, uint32_t cy,
175 uint8_t **ppu8Thumbnail, uint32_t *pcbThumbnail, uint32_t *pcxThumbnail, uint32_t *pcyThumbnail)
176{
177 int rc = VINF_SUCCESS;
178
179 uint8_t *pu8Thumbnail = NULL;
180 uint32_t cbThumbnail = 0;
181 uint32_t cxThumbnail = 0;
182 uint32_t cyThumbnail = 0;
183
184 if (cx > cy)
185 {
186 cxThumbnail = kMaxSizeThumbnail;
187 cyThumbnail = (kMaxSizeThumbnail * cy) / cx;
188 }
189 else
190 {
191 cyThumbnail = kMaxSizeThumbnail;
192 cxThumbnail = (kMaxSizeThumbnail * cx) / cy;
193 }
194
195 LogRelFlowFunc(("%dx%d -> %dx%d\n", cx, cy, cxThumbnail, cyThumbnail));
196
197 cbThumbnail = cxThumbnail * 4 * cyThumbnail;
198 pu8Thumbnail = (uint8_t *)RTMemAlloc(cbThumbnail);
199
200 if (pu8Thumbnail)
201 {
202 uint8_t *dst = pu8Thumbnail;
203 uint8_t *src = pbData;
204 int dstW = cxThumbnail;
205 int dstH = cyThumbnail;
206 int srcW = cx;
207 int srcH = cy;
208 int iDeltaLine = cx * 4;
209
210 BitmapScale32(dst,
211 dstW, dstH,
212 src,
213 iDeltaLine,
214 srcW, srcH);
215
216 *ppu8Thumbnail = pu8Thumbnail;
217 *pcbThumbnail = cbThumbnail;
218 *pcxThumbnail = cxThumbnail;
219 *pcyThumbnail = cyThumbnail;
220 }
221 else
222 {
223 rc = VERR_NO_MEMORY;
224 }
225
226 return rc;
227}
228
229/**
230 * @callback_method_impl{FNSSMEXTSAVEEXEC}
231 */
232DECLCALLBACK(int) Display::i_displaySSMSaveScreenshot(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser)
233{
234 Display * const pThat = static_cast<Display *>(pvUser);
235 AssertPtrReturn(pThat, VERR_INVALID_POINTER);
236
237 /* 32bpp small RGB image. */
238 uint8_t *pu8Thumbnail = NULL;
239 uint32_t cbThumbnail = 0;
240 uint32_t cxThumbnail = 0;
241 uint32_t cyThumbnail = 0;
242
243 /* PNG screenshot. */
244 uint8_t *pu8PNG = NULL;
245 uint32_t cbPNG = 0;
246 uint32_t cxPNG = 0;
247 uint32_t cyPNG = 0;
248
249 Console::SafeVMPtr ptrVM(pThat->mParent);
250 if (ptrVM.isOk())
251 {
252 /* Query RGB bitmap. */
253 /* SSM code is executed on EMT(0), therefore no need to use VMR3ReqCallWait. */
254 uint8_t *pbData = NULL;
255 size_t cbData = 0;
256 uint32_t cx = 0;
257 uint32_t cy = 0;
258 bool fFreeMem = false;
259 int rc = Display::i_displayTakeScreenshotEMT(pThat, VBOX_VIDEO_PRIMARY_SCREEN, &pbData, &cbData, &cx, &cy, &fFreeMem);
260
261 /*
262 * It is possible that success is returned but everything is 0 or NULL.
263 * (no display attached if a VM is running with VBoxHeadless on OSE for example)
264 */
265 if (RT_SUCCESS(rc) && pbData)
266 {
267 Assert(cx && cy);
268
269 /* Prepare a small thumbnail and a PNG screenshot. */
270 displayMakeThumbnail(pbData, cx, cy, &pu8Thumbnail, &cbThumbnail, &cxThumbnail, &cyThumbnail);
271 rc = DisplayMakePNG(pbData, cx, cy, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 1);
272 if (RT_FAILURE(rc))
273 {
274 if (pu8PNG)
275 {
276 RTMemFree(pu8PNG);
277 pu8PNG = NULL;
278 }
279 cbPNG = 0;
280 cxPNG = 0;
281 cyPNG = 0;
282 }
283
284 if (fFreeMem)
285 RTMemFree(pbData);
286 else
287 pThat->mpDrv->pUpPort->pfnFreeScreenshot(pThat->mpDrv->pUpPort, pbData);
288 }
289 }
290 else
291 {
292 LogFunc(("Failed to get VM pointer 0x%x\n", ptrVM.rc()));
293 }
294
295 /* Regardless of rc, save what is available:
296 * Data format:
297 * uint32_t cBlocks;
298 * [blocks]
299 *
300 * Each block is:
301 * uint32_t cbBlock; if 0 - no 'block data'.
302 * uint32_t typeOfBlock; 0 - 32bpp RGB bitmap, 1 - PNG, ignored if 'cbBlock' is 0.
303 * [block data]
304 *
305 * Block data for bitmap and PNG:
306 * uint32_t cx;
307 * uint32_t cy;
308 * [image data]
309 */
310 pVMM->pfnSSMR3PutU32(pSSM, 2); /* Write thumbnail and PNG screenshot. */
311
312 /* First block. */
313 pVMM->pfnSSMR3PutU32(pSSM, (uint32_t)(cbThumbnail + 2 * sizeof(uint32_t)));
314 pVMM->pfnSSMR3PutU32(pSSM, 0); /* Block type: thumbnail. */
315
316 if (cbThumbnail)
317 {
318 pVMM->pfnSSMR3PutU32(pSSM, cxThumbnail);
319 pVMM->pfnSSMR3PutU32(pSSM, cyThumbnail);
320 pVMM->pfnSSMR3PutMem(pSSM, pu8Thumbnail, cbThumbnail);
321 }
322
323 /* Second block. */
324 pVMM->pfnSSMR3PutU32(pSSM, (uint32_t)(cbPNG + 2 * sizeof(uint32_t)));
325 pVMM->pfnSSMR3PutU32(pSSM, 1); /* Block type: png. */
326
327 if (cbPNG)
328 {
329 pVMM->pfnSSMR3PutU32(pSSM, cxPNG);
330 pVMM->pfnSSMR3PutU32(pSSM, cyPNG);
331 pVMM->pfnSSMR3PutMem(pSSM, pu8PNG, cbPNG);
332 }
333
334 RTMemFree(pu8PNG);
335 RTMemFree(pu8Thumbnail);
336
337 return VINF_SUCCESS;
338}
339
340/**
341 * @callback_method_impl{FNSSMEXTLOADEXEC}
342 */
343DECLCALLBACK(int)
344Display::i_displaySSMLoadScreenshot(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser, uint32_t uVersion, uint32_t uPass)
345{
346 Display * const pThat = static_cast<Display *>(pvUser);
347 AssertPtrReturn(pThat, VERR_INVALID_POINTER);
348 Assert(uPass == SSM_PASS_FINAL); RT_NOREF_PV(uPass);
349
350 if (uVersion != sSSMDisplayScreenshotVer)
351 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
352
353 /* Skip data. */
354 uint32_t cBlocks;
355 int vrc = pVMM->pfnSSMR3GetU32(pSSM, &cBlocks);
356 AssertRCReturn(vrc, vrc);
357
358 for (uint32_t i = 0; i < cBlocks; i++)
359 {
360 uint32_t cbBlock;
361 vrc = pVMM->pfnSSMR3GetU32(pSSM, &cbBlock);
362 AssertRCReturn(vrc, vrc);
363
364 uint32_t typeOfBlock;
365 vrc = pVMM->pfnSSMR3GetU32(pSSM, &typeOfBlock);
366 AssertRCReturn(vrc, vrc);
367
368 LogRelFlowFunc(("[%d] type %d, size %d bytes\n", i, typeOfBlock, cbBlock));
369
370 /* Note: displaySSMSaveScreenshot writes size of a block = 8 and
371 * do not write any data if the image size was 0.
372 */
373 /** @todo Fix and increase saved state version. */
374 if (cbBlock > 2 * sizeof(uint32_t))
375 {
376 vrc = pVMM->pfnSSMR3Skip(pSSM, cbBlock);
377 AssertRCReturn(vrc, vrc);
378 }
379 }
380
381 return vrc;
382}
383
384/**
385 * @callback_method_impl{FNSSMEXTSAVEEXEC, Save some important guest state}
386 */
387/*static*/ DECLCALLBACK(int)
388Display::i_displaySSMSave(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser)
389{
390 Display * const pThat = static_cast<Display *>(pvUser);
391 AssertPtrReturn(pThat, VERR_INVALID_POINTER);
392
393 pVMM->pfnSSMR3PutU32(pSSM, pThat->mcMonitors);
394 for (unsigned i = 0; i < pThat->mcMonitors; i++)
395 {
396 pVMM->pfnSSMR3PutU32(pSSM, pThat->maFramebuffers[i].u32Offset);
397 pVMM->pfnSSMR3PutU32(pSSM, pThat->maFramebuffers[i].u32MaxFramebufferSize);
398 pVMM->pfnSSMR3PutU32(pSSM, pThat->maFramebuffers[i].u32InformationSize);
399 pVMM->pfnSSMR3PutU32(pSSM, pThat->maFramebuffers[i].w);
400 pVMM->pfnSSMR3PutU32(pSSM, pThat->maFramebuffers[i].h);
401 pVMM->pfnSSMR3PutS32(pSSM, pThat->maFramebuffers[i].xOrigin);
402 pVMM->pfnSSMR3PutS32(pSSM, pThat->maFramebuffers[i].yOrigin);
403 pVMM->pfnSSMR3PutU32(pSSM, pThat->maFramebuffers[i].flags);
404 }
405 pVMM->pfnSSMR3PutS32(pSSM, pThat->xInputMappingOrigin);
406 pVMM->pfnSSMR3PutS32(pSSM, pThat->yInputMappingOrigin);
407 pVMM->pfnSSMR3PutU32(pSSM, pThat->cxInputMapping);
408 pVMM->pfnSSMR3PutU32(pSSM, pThat->cyInputMapping);
409 pVMM->pfnSSMR3PutU32(pSSM, pThat->mfGuestVBVACapabilities);
410 return pVMM->pfnSSMR3PutU32(pSSM, pThat->mfHostCursorCapabilities);
411}
412
413/**
414 * @callback_method_impl{FNSSMEXTLOADEXEC, Load some important guest state}
415 */
416/*static*/ DECLCALLBACK(int)
417Display::i_displaySSMLoad(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser, uint32_t uVersion, uint32_t uPass)
418{
419 Display * const pThat = static_cast<Display *>(pvUser);
420 AssertPtrReturn(pThat, VERR_INVALID_POINTER);
421
422 if ( uVersion != sSSMDisplayVer
423 && uVersion != sSSMDisplayVer2
424 && uVersion != sSSMDisplayVer3
425 && uVersion != sSSMDisplayVer4
426 && uVersion != sSSMDisplayVer5)
427 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
428 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
429
430 uint32_t cMonitors;
431 int rc = pVMM->pfnSSMR3GetU32(pSSM, &cMonitors);
432 AssertRCReturn(rc, rc);
433 if (cMonitors != pThat->mcMonitors)
434 return pVMM->pfnSSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Number of monitors changed (%d->%d)!"), cMonitors, pThat->mcMonitors);
435
436 for (uint32_t i = 0; i < cMonitors; i++)
437 {
438 pVMM->pfnSSMR3GetU32(pSSM, &pThat->maFramebuffers[i].u32Offset);
439 pVMM->pfnSSMR3GetU32(pSSM, &pThat->maFramebuffers[i].u32MaxFramebufferSize);
440 pVMM->pfnSSMR3GetU32(pSSM, &pThat->maFramebuffers[i].u32InformationSize);
441 if ( uVersion == sSSMDisplayVer2
442 || uVersion == sSSMDisplayVer3
443 || uVersion == sSSMDisplayVer4
444 || uVersion == sSSMDisplayVer5)
445 {
446 uint32_t w;
447 uint32_t h;
448 pVMM->pfnSSMR3GetU32(pSSM, &w);
449 rc = pVMM->pfnSSMR3GetU32(pSSM, &h);
450 AssertRCReturn(rc, rc);
451 pThat->maFramebuffers[i].w = w;
452 pThat->maFramebuffers[i].h = h;
453 }
454 if ( uVersion == sSSMDisplayVer3
455 || uVersion == sSSMDisplayVer4
456 || uVersion == sSSMDisplayVer5)
457 {
458 int32_t xOrigin;
459 int32_t yOrigin;
460 uint32_t flags;
461 pVMM->pfnSSMR3GetS32(pSSM, &xOrigin);
462 pVMM->pfnSSMR3GetS32(pSSM, &yOrigin);
463 rc = pVMM->pfnSSMR3GetU32(pSSM, &flags);
464 AssertRCReturn(rc, rc);
465 pThat->maFramebuffers[i].xOrigin = xOrigin;
466 pThat->maFramebuffers[i].yOrigin = yOrigin;
467 pThat->maFramebuffers[i].flags = (uint16_t)flags;
468 pThat->maFramebuffers[i].fDisabled = (pThat->maFramebuffers[i].flags & VBVA_SCREEN_F_DISABLED) != 0;
469 }
470 }
471 if ( uVersion == sSSMDisplayVer4
472 || uVersion == sSSMDisplayVer5)
473 {
474 pVMM->pfnSSMR3GetS32(pSSM, &pThat->xInputMappingOrigin);
475 pVMM->pfnSSMR3GetS32(pSSM, &pThat->yInputMappingOrigin);
476 pVMM->pfnSSMR3GetU32(pSSM, &pThat->cxInputMapping);
477 pVMM->pfnSSMR3GetU32(pSSM, &pThat->cyInputMapping);
478 }
479 if (uVersion == sSSMDisplayVer5)
480 {
481 pVMM->pfnSSMR3GetU32(pSSM, &pThat->mfGuestVBVACapabilities);
482 pVMM->pfnSSMR3GetU32(pSSM, &pThat->mfHostCursorCapabilities);
483 }
484
485 return VINF_SUCCESS;
486}
487
488/**
489 * Initializes the display object.
490 *
491 * @returns COM result indicator
492 * @param aParent handle of our parent object
493 */
494HRESULT Display::init(Console *aParent)
495{
496 ComAssertRet(aParent, E_INVALIDARG);
497 /* Enclose the state transition NotReady->InInit->Ready */
498 AutoInitSpan autoInitSpan(this);
499 AssertReturn(autoInitSpan.isOk(), E_FAIL);
500
501 unconst(mParent) = aParent;
502
503 mfSourceBitmapEnabled = true;
504 fVGAResizing = false;
505
506 ComPtr<IGraphicsAdapter> pGraphicsAdapter;
507 HRESULT hrc = mParent->i_machine()->COMGETTER(GraphicsAdapter)(pGraphicsAdapter.asOutParam());
508 AssertComRCReturnRC(hrc);
509 AssertReturn(!pGraphicsAdapter.isNull(), E_FAIL);
510
511 ULONG ul;
512 pGraphicsAdapter->COMGETTER(MonitorCount)(&ul);
513 mcMonitors = ul;
514 xInputMappingOrigin = 0;
515 yInputMappingOrigin = 0;
516 cxInputMapping = 0;
517 cyInputMapping = 0;
518
519 for (ul = 0; ul < mcMonitors; ul++)
520 {
521 maFramebuffers[ul].u32Offset = 0;
522 maFramebuffers[ul].u32MaxFramebufferSize = 0;
523 maFramebuffers[ul].u32InformationSize = 0;
524
525 maFramebuffers[ul].pFramebuffer = NULL;
526 /* All secondary monitors are disabled at startup. */
527 maFramebuffers[ul].fDisabled = ul > 0;
528
529 maFramebuffers[ul].u32Caps = 0;
530
531 maFramebuffers[ul].updateImage.pu8Address = NULL;
532 maFramebuffers[ul].updateImage.cbLine = 0;
533
534 maFramebuffers[ul].xOrigin = 0;
535 maFramebuffers[ul].yOrigin = 0;
536
537 maFramebuffers[ul].w = 0;
538 maFramebuffers[ul].h = 0;
539
540 maFramebuffers[ul].flags = maFramebuffers[ul].fDisabled? VBVA_SCREEN_F_DISABLED: 0;
541
542 maFramebuffers[ul].u16BitsPerPixel = 0;
543 maFramebuffers[ul].pu8FramebufferVRAM = NULL;
544 maFramebuffers[ul].u32LineSize = 0;
545
546 maFramebuffers[ul].pHostEvents = NULL;
547
548 maFramebuffers[ul].fDefaultFormat = false;
549
550#ifdef VBOX_WITH_HGSMI
551 maFramebuffers[ul].fVBVAEnabled = false;
552 maFramebuffers[ul].fVBVAForceResize = false;
553 maFramebuffers[ul].pVBVAHostFlags = NULL;
554#endif /* VBOX_WITH_HGSMI */
555 }
556
557 {
558 // register listener for state change events
559 ComPtr<IEventSource> es;
560 mParent->COMGETTER(EventSource)(es.asOutParam());
561 com::SafeArray<VBoxEventType_T> eventTypes;
562 eventTypes.push_back(VBoxEventType_OnStateChanged);
563 es->RegisterListener(this, ComSafeArrayAsInParam(eventTypes), true);
564 }
565
566 /* Confirm a successful initialization */
567 autoInitSpan.setSucceeded();
568
569 return S_OK;
570}
571
572/**
573 * Uninitializes the instance and sets the ready flag to FALSE.
574 * Called either from FinalRelease() or by the parent when it gets destroyed.
575 */
576void Display::uninit()
577{
578 LogRelFlowFunc(("this=%p\n", this));
579
580 /* Enclose the state transition Ready->InUninit->NotReady */
581 AutoUninitSpan autoUninitSpan(this);
582 if (autoUninitSpan.uninitDone())
583 return;
584
585 unsigned uScreenId;
586 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
587 {
588 maFramebuffers[uScreenId].pSourceBitmap.setNull();
589 maFramebuffers[uScreenId].updateImage.pSourceBitmap.setNull();
590 maFramebuffers[uScreenId].updateImage.pu8Address = NULL;
591 maFramebuffers[uScreenId].updateImage.cbLine = 0;
592 maFramebuffers[uScreenId].pFramebuffer.setNull();
593#ifdef VBOX_WITH_RECORDING
594 maFramebuffers[uScreenId].Recording.pSourceBitmap.setNull();
595#endif
596 }
597
598 if (mParent)
599 {
600 ComPtr<IEventSource> es;
601 mParent->COMGETTER(EventSource)(es.asOutParam());
602 es->UnregisterListener(this);
603 }
604
605 unconst(mParent) = NULL;
606
607 if (mpDrv)
608 mpDrv->pDisplay = NULL;
609
610 mpDrv = NULL;
611}
612
613/**
614 * Register the SSM methods. Called by the power up thread to be able to
615 * pass pVM
616 */
617int Display::i_registerSSM(PUVM pUVM)
618{
619 PCVMMR3VTABLE const pVMM = mParent->i_getVMMVTable();
620 AssertPtrReturn(pVMM, VERR_INTERNAL_ERROR_3);
621
622 /* Version 2 adds width and height of the framebuffer; version 3 adds
623 * the framebuffer offset in the virtual desktop and the framebuffer flags;
624 * version 4 adds guest to host input event mapping and version 5 adds
625 * guest VBVA and host cursor capabilities.
626 */
627 int rc = pVMM->pfnSSMR3RegisterExternal(pUVM, "DisplayData", 0, sSSMDisplayVer5,
628 mcMonitors * sizeof(uint32_t) * 8 + sizeof(uint32_t),
629 NULL, NULL, NULL,
630 NULL, i_displaySSMSave, NULL,
631 NULL, i_displaySSMLoad, NULL, this);
632 AssertRCReturn(rc, rc);
633
634 /*
635 * Register loaders for old saved states where iInstance was
636 * 3 * sizeof(uint32_t *) due to a code mistake.
637 */
638 rc = pVMM->pfnSSMR3RegisterExternal(pUVM, "DisplayData", 12 /*uInstance*/, sSSMDisplayVer, 0 /*cbGuess*/,
639 NULL, NULL, NULL,
640 NULL, NULL, NULL,
641 NULL, i_displaySSMLoad, NULL, this);
642 AssertRCReturn(rc, rc);
643
644 rc = pVMM->pfnSSMR3RegisterExternal(pUVM, "DisplayData", 24 /*uInstance*/, sSSMDisplayVer, 0 /*cbGuess*/,
645 NULL, NULL, NULL,
646 NULL, NULL, NULL,
647 NULL, i_displaySSMLoad, NULL, this);
648 AssertRCReturn(rc, rc);
649
650 /* uInstance is an arbitrary value greater than 1024. Such a value will ensure a quick seek in saved state file. */
651 rc = pVMM->pfnSSMR3RegisterExternal(pUVM, "DisplayScreenshot", 1100 /*uInstance*/, sSSMDisplayScreenshotVer, 0 /*cbGuess*/,
652 NULL, NULL, NULL,
653 NULL, i_displaySSMSaveScreenshot, NULL,
654 NULL, i_displaySSMLoadScreenshot, NULL, this);
655
656 AssertRCReturn(rc, rc);
657
658 return VINF_SUCCESS;
659}
660
661// public methods only for internal purposes
662/////////////////////////////////////////////////////////////////////////////
663
664/**
665 * Handles display resize event.
666 *
667 * @param uScreenId Screen ID
668 * @param bpp New bits per pixel.
669 * @param pvVRAM VRAM pointer.
670 * @param cbLine New bytes per line.
671 * @param w New display width.
672 * @param h New display height.
673 * @param flags Flags of the new video mode.
674 * @param xOrigin New display origin X.
675 * @param yOrigin New display origin Y.
676 * @param fVGAResize Whether the resize is originated from the VGA device (DevVGA).
677 */
678int Display::i_handleDisplayResize(unsigned uScreenId, uint32_t bpp, void *pvVRAM,
679 uint32_t cbLine, uint32_t w, uint32_t h, uint16_t flags,
680 int32_t xOrigin, int32_t yOrigin, bool fVGAResize)
681{
682 LogRel2(("Display::i_handleDisplayResize: uScreenId=%d pvVRAM=%p w=%d h=%d bpp=%d cbLine=0x%X flags=0x%X\n", uScreenId,
683 pvVRAM, w, h, bpp, cbLine, flags));
684
685 /* Caller must not hold the object lock. */
686 AssertReturn(!isWriteLockOnCurrentThread(), VERR_INVALID_STATE);
687
688 /* Note: the old code checked if the video mode was actually changed and
689 * did not invalidate the source bitmap if the mode did not change.
690 * The new code always invalidates the source bitmap, i.e. it will
691 * notify the frontend even if nothing actually changed.
692 *
693 * Implementing the filtering is possible but might lead to pfnSetRenderVRAM races
694 * between this method and QuerySourceBitmap. Such races can be avoided by implementing
695 * the @todo below.
696 */
697
698 /* Make sure that the VGA device does not access the source bitmap. */
699 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN && mpDrv)
700 {
701 /// @todo It is probably more convenient to implement
702 // mpDrv->pUpPort->pfnSetOutputBitmap(pvVRAM, cbScanline, cBits, cx, cy, bool fSet);
703 // and remove IConnector.pbData, cbScanline, cBits, cx, cy.
704 // fSet = false disables rendering and VGA can check
705 // if it is already rendering to a different bitmap, avoiding
706 // enable/disable rendering races.
707 mpDrv->pUpPort->pfnSetRenderVRAM(mpDrv->pUpPort, false);
708
709 mpDrv->IConnector.pbData = NULL;
710 mpDrv->IConnector.cbScanline = 0;
711 mpDrv->IConnector.cBits = 32; /* DevVGA does not work with cBits == 0. */
712 mpDrv->IConnector.cx = 0;
713 mpDrv->IConnector.cy = 0;
714 }
715
716 /* Update maFramebuffers[uScreenId] under lock. */
717 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
718
719 if (uScreenId >= mcMonitors)
720 {
721 LogRel(("Display::i_handleDisplayResize: mcMonitors=%u < uScreenId=%u (pvVRAM=%p w=%u h=%u bpp=%d cbLine=0x%X flags=0x%X)\n",
722 mcMonitors, uScreenId, pvVRAM, w, h, bpp, cbLine, flags));
723 return VINF_SUCCESS;
724 }
725
726 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
727
728 /* Whether the monitor position has changed.
729 * A resize initiated by the VGA device does not change the monitor position.
730 */
731 const bool fNewOrigin = !fVGAResize
732 && ( pFBInfo->xOrigin != xOrigin
733 || pFBInfo->yOrigin != yOrigin);
734
735 /* The event for disabled->enabled transition.
736 * VGA resizes also come when the guest uses VBVA mode. They do not affect pFBInfo->fDisabled.
737 * The primary screen is re-enabled when the guest leaves the VBVA mode in i_displayVBVADisable.
738 */
739 const bool fGuestMonitorChangedEvent = !fVGAResize
740 && (pFBInfo->fDisabled != RT_BOOL(flags & VBVA_SCREEN_F_DISABLED));
741
742 /* Reset the update mode. */
743 pFBInfo->updateImage.pSourceBitmap.setNull();
744 pFBInfo->updateImage.pu8Address = NULL;
745 pFBInfo->updateImage.cbLine = 0;
746
747 /* Release the current source bitmap. */
748 pFBInfo->pSourceBitmap.setNull();
749
750 /* VGA blanking is signaled as w=0, h=0, bpp=0 and cbLine=0, and it's
751 * best to keep the old resolution, as otherwise the window size would
752 * change before the new resolution is known. */
753 const bool fVGABlank = fVGAResize && uScreenId == VBOX_VIDEO_PRIMARY_SCREEN
754 && w == 0 && h == 0 && bpp == 0 && cbLine == 0;
755 if (fVGABlank)
756 {
757 w = pFBInfo->w;
758 h = pFBInfo->h;
759 }
760
761 /* Log changes. */
762 if ( pFBInfo->w != w
763 || pFBInfo->h != h
764 || pFBInfo->u32LineSize != cbLine
765 /*|| pFBInfo->pu8FramebufferVRAM != (uint8_t *)pvVRAM - too noisy */
766 || ( !fVGAResize
767 && ( pFBInfo->xOrigin != xOrigin
768 || pFBInfo->yOrigin != yOrigin
769 || pFBInfo->flags != flags)))
770 LogRel(("Display::i_handleDisplayResize: uScreenId=%d pvVRAM=%p w=%d h=%d bpp=%d cbLine=0x%X flags=0x%X origin=%d,%d\n",
771 uScreenId, pvVRAM, w, h, bpp, cbLine, flags, xOrigin, yOrigin));
772
773 /* Update the video mode information. */
774 pFBInfo->w = w;
775 pFBInfo->h = h;
776 pFBInfo->u16BitsPerPixel = (uint16_t)bpp;
777 pFBInfo->pu8FramebufferVRAM = (uint8_t *)pvVRAM;
778 pFBInfo->u32LineSize = cbLine;
779 if (!fVGAResize)
780 {
781 /* Fields which are not used in not VBVA modes and not affected by a VGA resize. */
782 pFBInfo->flags = flags;
783 pFBInfo->xOrigin = xOrigin;
784 pFBInfo->yOrigin = yOrigin;
785 pFBInfo->fDisabled = RT_BOOL(flags & VBVA_SCREEN_F_DISABLED);
786 pFBInfo->fVBVAForceResize = false;
787 }
788 else
789 {
790 pFBInfo->flags = VBVA_SCREEN_F_ACTIVE;
791 if (fVGABlank)
792 pFBInfo->flags |= VBVA_SCREEN_F_BLANK;
793 pFBInfo->fDisabled = false;
794 }
795
796 /* Prepare local vars for the notification code below. */
797 ComPtr<IFramebuffer> pFramebuffer = pFBInfo->pFramebuffer;
798 const bool fDisabled = pFBInfo->fDisabled;
799
800 alock.release();
801
802 if (!pFramebuffer.isNull())
803 {
804 HRESULT hr = pFramebuffer->NotifyChange(uScreenId, 0, 0, w, h); /** @todo origin */
805 LogFunc(("NotifyChange hr %08X\n", hr));
806 NOREF(hr);
807 }
808
809 if (fGuestMonitorChangedEvent)
810 {
811 if (fDisabled)
812 ::FireGuestMonitorChangedEvent(mParent->i_getEventSource(),
813 GuestMonitorChangedEventType_Disabled, uScreenId, 0, 0, 0, 0);
814 else
815 ::FireGuestMonitorChangedEvent(mParent->i_getEventSource(),
816 GuestMonitorChangedEventType_Enabled, uScreenId, xOrigin, yOrigin, w, h);
817 }
818
819 if (fNewOrigin)
820 ::FireGuestMonitorChangedEvent(mParent->i_getEventSource(),
821 GuestMonitorChangedEventType_NewOrigin, uScreenId, xOrigin, yOrigin, 0, 0);
822
823 /* Inform the VRDP server about the change of display parameters. */
824 LogRelFlowFunc(("Calling VRDP\n"));
825 mParent->i_consoleVRDPServer()->SendResize();
826
827 /* And re-send the seamless rectangles if necessary. */
828 if (mfSeamlessEnabled)
829 i_handleSetVisibleRegion(mcRectVisibleRegion, mpRectVisibleRegion);
830
831#ifdef VBOX_WITH_RECORDING
832 i_recordingScreenChanged(uScreenId);
833#endif
834
835 LogRelFlowFunc(("[%d]: default format %d\n", uScreenId, pFBInfo->fDefaultFormat));
836
837 return VINF_SUCCESS;
838}
839
840static void i_checkCoordBounds(int *px, int *py, int *pw, int *ph, int cx, int cy)
841{
842 /* Correct negative x and y coordinates. */
843 if (*px < 0)
844 {
845 *px += *pw; /* Compute xRight which is also the new width. */
846
847 *pw = (*px < 0)? 0: *px;
848
849 *px = 0;
850 }
851
852 if (*py < 0)
853 {
854 *py += *ph; /* Compute xBottom, which is also the new height. */
855
856 *ph = (*py < 0)? 0: *py;
857
858 *py = 0;
859 }
860
861 /* Also check if coords are greater than the display resolution. */
862 if (*px + *pw > cx)
863 {
864 *pw = cx > *px? cx - *px: 0;
865 }
866
867 if (*py + *ph > cy)
868 {
869 *ph = cy > *py? cy - *py: 0;
870 }
871}
872
873void Display::i_handleDisplayUpdate(unsigned uScreenId, int x, int y, int w, int h)
874{
875 /*
876 * Always runs under either VBVA lock or, for HGSMI, DevVGA lock.
877 * Safe to use VBVA vars and take the framebuffer lock.
878 */
879
880#ifdef DEBUG_sunlover
881 LogFlowFunc(("[%d] %d,%d %dx%d\n",
882 uScreenId, x, y, w, h));
883#endif /* DEBUG_sunlover */
884
885 /* No updates for a disabled guest screen. */
886 if (maFramebuffers[uScreenId].fDisabled)
887 return;
888
889 /* No updates for a blank guest screen. */
890 /** @note Disabled for now, as the GUI does not update the picture when we
891 * first blank. */
892 /* if (maFramebuffers[uScreenId].flags & VBVA_SCREEN_F_BLANK)
893 return; */
894
895 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
896 AutoReadLock alockr(this COMMA_LOCKVAL_SRC_POS);
897
898 ComPtr<IFramebuffer> pFramebuffer = pFBInfo->pFramebuffer;
899 ComPtr<IDisplaySourceBitmap> pSourceBitmap = pFBInfo->updateImage.pSourceBitmap;
900
901 alockr.release();
902
903 if (RT_LIKELY(!pFramebuffer.isNull()))
904 {
905 if (RT_LIKELY(!RT_BOOL(pFBInfo->u32Caps & FramebufferCapabilities_UpdateImage)))
906 {
907 i_checkCoordBounds(&x, &y, &w, &h, pFBInfo->w, pFBInfo->h);
908
909 if (w != 0 && h != 0)
910 {
911 pFramebuffer->NotifyUpdate(x, y, w, h);
912 }
913 }
914 else
915 {
916 if (RT_LIKELY(!pSourceBitmap.isNull()))
917 { /* likely */ }
918 else
919 {
920 /* Create a source bitmap if UpdateImage mode is used. */
921 HRESULT hr = QuerySourceBitmap(uScreenId, pSourceBitmap.asOutParam());
922 if (SUCCEEDED(hr))
923 {
924 BYTE *pAddress = NULL;
925 ULONG ulWidth = 0;
926 ULONG ulHeight = 0;
927 ULONG ulBitsPerPixel = 0;
928 ULONG ulBytesPerLine = 0;
929 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
930
931 hr = pSourceBitmap->QueryBitmapInfo(&pAddress,
932 &ulWidth,
933 &ulHeight,
934 &ulBitsPerPixel,
935 &ulBytesPerLine,
936 &bitmapFormat);
937 if (SUCCEEDED(hr))
938 {
939 AutoWriteLock alockw(this COMMA_LOCKVAL_SRC_POS);
940
941 if (pFBInfo->updateImage.pSourceBitmap.isNull())
942 {
943 pFBInfo->updateImage.pSourceBitmap = pSourceBitmap;
944 pFBInfo->updateImage.pu8Address = pAddress;
945 pFBInfo->updateImage.cbLine = ulBytesPerLine;
946 }
947
948 pSourceBitmap = pFBInfo->updateImage.pSourceBitmap;
949
950 alockw.release();
951 }
952 }
953 }
954
955 if (RT_LIKELY(!pSourceBitmap.isNull()))
956 {
957 BYTE *pbAddress = NULL;
958 ULONG ulWidth = 0;
959 ULONG ulHeight = 0;
960 ULONG ulBitsPerPixel = 0;
961 ULONG ulBytesPerLine = 0;
962 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
963
964 HRESULT hr = pSourceBitmap->QueryBitmapInfo(&pbAddress,
965 &ulWidth,
966 &ulHeight,
967 &ulBitsPerPixel,
968 &ulBytesPerLine,
969 &bitmapFormat);
970 if (SUCCEEDED(hr))
971 {
972 /* Make sure that the requested update is within the source bitmap dimensions. */
973 i_checkCoordBounds(&x, &y, &w, &h, ulWidth, ulHeight);
974
975 if (w != 0 && h != 0)
976 {
977 const size_t cbData = w * h * 4;
978 com::SafeArray<BYTE> image(cbData);
979
980 uint8_t *pu8Dst = image.raw();
981 const uint8_t *pu8Src = pbAddress + ulBytesPerLine * y + x * 4;
982
983 int i;
984 for (i = y; i < y + h; ++i)
985 {
986 memcpy(pu8Dst, pu8Src, w * 4);
987 pu8Dst += w * 4;
988 pu8Src += ulBytesPerLine;
989 }
990
991 pFramebuffer->NotifyUpdateImage(x, y, w, h, ComSafeArrayAsInParam(image));
992 }
993 }
994 }
995 }
996 }
997
998#ifndef VBOX_WITH_HGSMI
999 if (!mVideoAccelLegacy.fVideoAccelEnabled)
1000#else
1001 if (!mVideoAccelLegacy.fVideoAccelEnabled && !maFramebuffers[uScreenId].fVBVAEnabled)
1002#endif
1003 {
1004 /* When VBVA is enabled, the VRDP server is informed
1005 * either in VideoAccelFlush or displayVBVAUpdateProcess.
1006 * Inform the server here only if VBVA is disabled.
1007 */
1008 mParent->i_consoleVRDPServer()->SendUpdateBitmap(uScreenId, x, y, w, h);
1009 }
1010}
1011
1012void Display::i_updateGuestGraphicsFacility(void)
1013{
1014 Guest* pGuest = mParent->i_getGuest();
1015 AssertPtrReturnVoid(pGuest);
1016 /* The following is from GuestImpl.cpp. */
1017 /** @todo A nit: The timestamp is wrong on saved state restore. Would be better
1018 * to move the graphics and seamless capability -> facility translation to
1019 * VMMDev so this could be saved. */
1020 RTTIMESPEC TimeSpecTS;
1021 RTTimeNow(&TimeSpecTS);
1022
1023 if ( mfVMMDevSupportsGraphics
1024 || (mfGuestVBVACapabilities & VBVACAPS_VIDEO_MODE_HINTS) != 0)
1025 pGuest->i_setAdditionsStatus(VBoxGuestFacilityType_Graphics,
1026 VBoxGuestFacilityStatus_Active,
1027 0 /*fFlags*/, &TimeSpecTS);
1028 else
1029 pGuest->i_setAdditionsStatus(VBoxGuestFacilityType_Graphics,
1030 VBoxGuestFacilityStatus_Inactive,
1031 0 /*fFlags*/, &TimeSpecTS);
1032}
1033
1034void Display::i_handleUpdateVMMDevSupportsGraphics(bool fSupportsGraphics)
1035{
1036 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1037 if (mfVMMDevSupportsGraphics == fSupportsGraphics)
1038 return;
1039 mfVMMDevSupportsGraphics = fSupportsGraphics;
1040 i_updateGuestGraphicsFacility();
1041 /* The VMMDev interface notifies the console. */
1042}
1043
1044void Display::i_handleUpdateGuestVBVACapabilities(uint32_t fNewCapabilities)
1045{
1046 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1047 bool fNotify = (fNewCapabilities & VBVACAPS_VIDEO_MODE_HINTS) != (mfGuestVBVACapabilities & VBVACAPS_VIDEO_MODE_HINTS);
1048
1049 mfGuestVBVACapabilities = fNewCapabilities;
1050 if (!fNotify)
1051 return;
1052 i_updateGuestGraphicsFacility();
1053 /* Tell the console about it */
1054 mParent->i_onAdditionsStateChange();
1055}
1056
1057void Display::i_handleUpdateVBVAInputMapping(int32_t xOrigin, int32_t yOrigin, uint32_t cx, uint32_t cy)
1058{
1059 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1060
1061 xInputMappingOrigin = xOrigin;
1062 yInputMappingOrigin = yOrigin;
1063 cxInputMapping = cx;
1064 cyInputMapping = cy;
1065
1066 /* Re-send the seamless rectangles if necessary. */
1067 if (mfSeamlessEnabled)
1068 i_handleSetVisibleRegion(mcRectVisibleRegion, mpRectVisibleRegion);
1069}
1070
1071/**
1072 * Returns the upper left and lower right corners of the virtual framebuffer.
1073 * The lower right is "exclusive" (i.e. first pixel beyond the framebuffer),
1074 * and the origin is (0, 0), not (1, 1) like the GUI returns.
1075 */
1076void Display::i_getFramebufferDimensions(int32_t *px1, int32_t *py1,
1077 int32_t *px2, int32_t *py2)
1078{
1079 int32_t x1 = 0, y1 = 0, x2 = 0, y2 = 0;
1080 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1081
1082 AssertPtrReturnVoid(px1);
1083 AssertPtrReturnVoid(py1);
1084 AssertPtrReturnVoid(px2);
1085 AssertPtrReturnVoid(py2);
1086 LogRelFlowFunc(("\n"));
1087
1088 if (!mpDrv)
1089 return;
1090
1091 if (maFramebuffers[0].fVBVAEnabled && cxInputMapping && cyInputMapping)
1092 {
1093 /* Guest uses VBVA with explicit mouse mapping dimensions. */
1094 x1 = xInputMappingOrigin;
1095 y1 = yInputMappingOrigin;
1096 x2 = xInputMappingOrigin + cxInputMapping;
1097 y2 = yInputMappingOrigin + cyInputMapping;
1098 }
1099 else
1100 {
1101 /* If VBVA is not in use then this flag will not be set and this
1102 * will still work as it should. */
1103 if (!maFramebuffers[0].fDisabled)
1104 {
1105 x1 = (int32_t)maFramebuffers[0].xOrigin;
1106 y1 = (int32_t)maFramebuffers[0].yOrigin;
1107 x2 = (int32_t)maFramebuffers[0].w + (int32_t)maFramebuffers[0].xOrigin;
1108 y2 = (int32_t)maFramebuffers[0].h + (int32_t)maFramebuffers[0].yOrigin;
1109 }
1110
1111 for (unsigned i = 1; i < mcMonitors; ++i)
1112 {
1113 if (!maFramebuffers[i].fDisabled)
1114 {
1115 x1 = RT_MIN(x1, maFramebuffers[i].xOrigin);
1116 y1 = RT_MIN(y1, maFramebuffers[i].yOrigin);
1117 x2 = RT_MAX(x2, maFramebuffers[i].xOrigin + (int32_t)maFramebuffers[i].w);
1118 y2 = RT_MAX(y2, maFramebuffers[i].yOrigin + (int32_t)maFramebuffers[i].h);
1119 }
1120 }
1121 }
1122
1123 *px1 = x1;
1124 *py1 = y1;
1125 *px2 = x2;
1126 *py2 = y2;
1127}
1128
1129/** Updates the device's view of the host cursor handling capabilities.
1130 * Calls into mpDrv->pUpPort. */
1131void Display::i_UpdateDeviceCursorCapabilities(void)
1132{
1133 bool fRenderCursor = true;
1134 bool fMoveCursor = mcVRDPRefs == 0;
1135#ifdef VBOX_WITH_RECORDING
1136 RecordingContext *pCtx = mParent->i_recordingGetContext();
1137
1138 if ( pCtx
1139 && pCtx->IsStarted()
1140 && pCtx->IsFeatureEnabled(RecordingFeature_Video))
1141 fRenderCursor = fMoveCursor = false;
1142 else
1143#endif /* VBOX_WITH_RECORDING */
1144 {
1145 for (unsigned uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
1146 {
1147 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1148 if (!(pFBInfo->u32Caps & FramebufferCapabilities_RenderCursor))
1149 fRenderCursor = false;
1150 if (!(pFBInfo->u32Caps & FramebufferCapabilities_MoveCursor))
1151 fMoveCursor = false;
1152 }
1153 }
1154
1155 if (mpDrv)
1156 mpDrv->pUpPort->pfnReportHostCursorCapabilities(mpDrv->pUpPort, fRenderCursor, fMoveCursor);
1157}
1158
1159HRESULT Display::i_reportHostCursorCapabilities(uint32_t fCapabilitiesAdded, uint32_t fCapabilitiesRemoved)
1160{
1161 /* Do we need this to access mParent? I presume that the safe VM pointer
1162 * ensures that mpDrv will remain valid. */
1163 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1164 uint32_t fHostCursorCapabilities = (mfHostCursorCapabilities | fCapabilitiesAdded)
1165 & ~fCapabilitiesRemoved;
1166
1167 Console::SafeVMPtr ptrVM(mParent);
1168 if (!ptrVM.isOk())
1169 return ptrVM.rc();
1170 if (mfHostCursorCapabilities == fHostCursorCapabilities)
1171 return S_OK;
1172 CHECK_CONSOLE_DRV(mpDrv);
1173 alock.release(); /* Release before calling up for lock order reasons. */
1174 mfHostCursorCapabilities = fHostCursorCapabilities;
1175 i_UpdateDeviceCursorCapabilities();
1176 return S_OK;
1177}
1178
1179HRESULT Display::i_reportHostCursorPosition(int32_t x, int32_t y, bool fOutOfRange)
1180{
1181 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1182 uint32_t xAdj = (uint32_t)RT_MAX(x - xInputMappingOrigin, 0);
1183 uint32_t yAdj = (uint32_t)RT_MAX(y - yInputMappingOrigin, 0);
1184 xAdj = RT_MIN(xAdj, cxInputMapping);
1185 yAdj = RT_MIN(yAdj, cyInputMapping);
1186
1187 Console::SafeVMPtr ptrVM(mParent);
1188 if (!ptrVM.isOk())
1189 return ptrVM.rc();
1190 CHECK_CONSOLE_DRV(mpDrv);
1191 alock.release(); /* Release before calling up for lock order reasons. */
1192 if (fOutOfRange)
1193 mpDrv->pUpPort->pfnReportHostCursorPosition(mpDrv->pUpPort, 0, 0, true);
1194 else
1195 mpDrv->pUpPort->pfnReportHostCursorPosition(mpDrv->pUpPort, xAdj, yAdj, false);
1196 return S_OK;
1197}
1198
1199static bool displayIntersectRect(RTRECT *prectResult,
1200 const RTRECT *prect1,
1201 const RTRECT *prect2)
1202{
1203 /* Initialize result to an empty record. */
1204 memset(prectResult, 0, sizeof(RTRECT));
1205
1206 int xLeftResult = RT_MAX(prect1->xLeft, prect2->xLeft);
1207 int xRightResult = RT_MIN(prect1->xRight, prect2->xRight);
1208
1209 if (xLeftResult < xRightResult)
1210 {
1211 /* There is intersection by X. */
1212
1213 int yTopResult = RT_MAX(prect1->yTop, prect2->yTop);
1214 int yBottomResult = RT_MIN(prect1->yBottom, prect2->yBottom);
1215
1216 if (yTopResult < yBottomResult)
1217 {
1218 /* There is intersection by Y. */
1219
1220 prectResult->xLeft = xLeftResult;
1221 prectResult->yTop = yTopResult;
1222 prectResult->xRight = xRightResult;
1223 prectResult->yBottom = yBottomResult;
1224
1225 return true;
1226 }
1227 }
1228
1229 return false;
1230}
1231
1232int Display::i_saveVisibleRegion(uint32_t cRect, PRTRECT pRect)
1233{
1234 RTRECT *pRectVisibleRegion = NULL;
1235
1236 if (pRect == mpRectVisibleRegion)
1237 return VINF_SUCCESS;
1238 if (cRect != 0)
1239 {
1240 pRectVisibleRegion = (RTRECT *)RTMemAlloc(cRect * sizeof(RTRECT));
1241 if (!pRectVisibleRegion)
1242 {
1243 return VERR_NO_MEMORY;
1244 }
1245 memcpy(pRectVisibleRegion, pRect, cRect * sizeof(RTRECT));
1246 }
1247 if (mpRectVisibleRegion)
1248 RTMemFree(mpRectVisibleRegion);
1249 mcRectVisibleRegion = cRect;
1250 mpRectVisibleRegion = pRectVisibleRegion;
1251 return VINF_SUCCESS;
1252}
1253
1254int Display::i_handleSetVisibleRegion(uint32_t cRect, PRTRECT pRect)
1255{
1256 RTRECT *pVisibleRegion = (RTRECT *)RTMemTmpAlloc( RT_MAX(cRect, 1)
1257 * sizeof(RTRECT));
1258 LogRel2(("%s: cRect=%u\n", __PRETTY_FUNCTION__, cRect));
1259 if (!pVisibleRegion)
1260 {
1261 return VERR_NO_TMP_MEMORY;
1262 }
1263 int rc = i_saveVisibleRegion(cRect, pRect);
1264 if (RT_FAILURE(rc))
1265 {
1266 RTMemTmpFree(pVisibleRegion);
1267 return rc;
1268 }
1269
1270 unsigned uScreenId;
1271 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
1272 {
1273 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1274
1275 if ( !pFBInfo->pFramebuffer.isNull()
1276 && RT_BOOL(pFBInfo->u32Caps & FramebufferCapabilities_VisibleRegion))
1277 {
1278 /* Prepare a new array of rectangles which intersect with the framebuffer.
1279 */
1280 RTRECT rectFramebuffer;
1281 rectFramebuffer.xLeft = pFBInfo->xOrigin - xInputMappingOrigin;
1282 rectFramebuffer.yTop = pFBInfo->yOrigin - yInputMappingOrigin;
1283 rectFramebuffer.xRight = rectFramebuffer.xLeft + pFBInfo->w;
1284 rectFramebuffer.yBottom = rectFramebuffer.yTop + pFBInfo->h;
1285
1286 uint32_t cRectVisibleRegion = 0;
1287
1288 uint32_t i;
1289 for (i = 0; i < cRect; i++)
1290 {
1291 if (displayIntersectRect(&pVisibleRegion[cRectVisibleRegion], &pRect[i], &rectFramebuffer))
1292 {
1293 pVisibleRegion[cRectVisibleRegion].xLeft -= rectFramebuffer.xLeft;
1294 pVisibleRegion[cRectVisibleRegion].yTop -= rectFramebuffer.yTop;
1295 pVisibleRegion[cRectVisibleRegion].xRight -= rectFramebuffer.xLeft;
1296 pVisibleRegion[cRectVisibleRegion].yBottom -= rectFramebuffer.yTop;
1297
1298 cRectVisibleRegion++;
1299 }
1300 }
1301 pFBInfo->pFramebuffer->SetVisibleRegion((BYTE *)pVisibleRegion, cRectVisibleRegion);
1302 }
1303 }
1304
1305 RTMemTmpFree(pVisibleRegion);
1306
1307 return VINF_SUCCESS;
1308}
1309
1310int Display::i_handleUpdateMonitorPositions(uint32_t cPositions, PCRTPOINT paPositions)
1311{
1312 AssertMsgReturn(paPositions, ("Empty monitor position array\n"), E_INVALIDARG);
1313 for (unsigned i = 0; i < cPositions; ++i)
1314 LogRel2(("Display::i_handleUpdateMonitorPositions: uScreenId=%d xOrigin=%d yOrigin=%dX\n",
1315 i, paPositions[i].x, paPositions[i].y));
1316
1317 if (mpDrv && mpDrv->pUpPort->pfnReportMonitorPositions)
1318 mpDrv->pUpPort->pfnReportMonitorPositions(mpDrv->pUpPort, cPositions, paPositions);
1319 return VINF_SUCCESS;
1320}
1321
1322int Display::i_handleQueryVisibleRegion(uint32_t *pcRects, PRTRECT paRects)
1323{
1324 /// @todo Currently not used by the guest and is not implemented in
1325 /// framebuffers. Remove?
1326 RT_NOREF(pcRects, paRects);
1327 return VERR_NOT_SUPPORTED;
1328}
1329
1330#ifdef VBOX_WITH_HGSMI
1331static void vbvaSetMemoryFlagsHGSMI(unsigned uScreenId,
1332 uint32_t fu32SupportedOrders,
1333 bool fVideoAccelVRDP,
1334 DISPLAYFBINFO *pFBInfo)
1335{
1336 LogRelFlowFunc(("HGSMI[%d]: %p\n", uScreenId, pFBInfo->pVBVAHostFlags));
1337
1338 if (pFBInfo->pVBVAHostFlags)
1339 {
1340 uint32_t fu32HostEvents = VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
1341
1342 if (pFBInfo->fVBVAEnabled)
1343 {
1344 fu32HostEvents |= VBVA_F_MODE_ENABLED;
1345
1346 if (fVideoAccelVRDP)
1347 {
1348 fu32HostEvents |= VBVA_F_MODE_VRDP;
1349 }
1350 }
1351
1352 ASMAtomicWriteU32(&pFBInfo->pVBVAHostFlags->u32HostEvents, fu32HostEvents);
1353 ASMAtomicWriteU32(&pFBInfo->pVBVAHostFlags->u32SupportedOrders, fu32SupportedOrders);
1354
1355 LogRelFlowFunc((" fu32HostEvents = 0x%08X, fu32SupportedOrders = 0x%08X\n", fu32HostEvents, fu32SupportedOrders));
1356 }
1357}
1358
1359static void vbvaSetMemoryFlagsAllHGSMI(uint32_t fu32SupportedOrders,
1360 bool fVideoAccelVRDP,
1361 DISPLAYFBINFO *paFBInfos,
1362 unsigned cFBInfos)
1363{
1364 unsigned uScreenId;
1365
1366 for (uScreenId = 0; uScreenId < cFBInfos; uScreenId++)
1367 {
1368 vbvaSetMemoryFlagsHGSMI(uScreenId, fu32SupportedOrders, fVideoAccelVRDP, &paFBInfos[uScreenId]);
1369 }
1370}
1371#endif /* VBOX_WITH_HGSMI */
1372
1373int Display::VideoAccelEnableVMMDev(bool fEnable, VBVAMEMORY *pVbvaMemory)
1374{
1375 LogFlowFunc(("%d %p\n", fEnable, pVbvaMemory));
1376 int rc = videoAccelEnterVMMDev(&mVideoAccelLegacy);
1377 if (RT_SUCCESS(rc))
1378 {
1379 rc = i_VideoAccelEnable(fEnable, pVbvaMemory, mpDrv->pUpPort);
1380 videoAccelLeaveVMMDev(&mVideoAccelLegacy);
1381 }
1382 LogFlowFunc(("leave %Rrc\n", rc));
1383 return rc;
1384}
1385
1386int Display::VideoAccelEnableVGA(bool fEnable, VBVAMEMORY *pVbvaMemory)
1387{
1388 LogFlowFunc(("%d %p\n", fEnable, pVbvaMemory));
1389 int rc = videoAccelEnterVGA(&mVideoAccelLegacy);
1390 if (RT_SUCCESS(rc))
1391 {
1392 rc = i_VideoAccelEnable(fEnable, pVbvaMemory, mpDrv->pUpPort);
1393 videoAccelLeaveVGA(&mVideoAccelLegacy);
1394 }
1395 LogFlowFunc(("leave %Rrc\n", rc));
1396 return rc;
1397}
1398
1399void Display::VideoAccelFlushVMMDev(void)
1400{
1401 LogFlowFunc(("enter\n"));
1402 int rc = videoAccelEnterVMMDev(&mVideoAccelLegacy);
1403 if (RT_SUCCESS(rc))
1404 {
1405 i_VideoAccelFlush(mpDrv->pUpPort);
1406 videoAccelLeaveVMMDev(&mVideoAccelLegacy);
1407 }
1408 LogFlowFunc(("leave\n"));
1409}
1410
1411/* Called always by one VRDP server thread. Can be thread-unsafe.
1412 */
1413void Display::i_VRDPConnectionEvent(bool fConnect)
1414{
1415 LogRelFlowFunc(("fConnect = %d\n", fConnect));
1416
1417 int c = fConnect?
1418 ASMAtomicIncS32(&mcVRDPRefs):
1419 ASMAtomicDecS32(&mcVRDPRefs);
1420
1421 i_VideoAccelVRDP(fConnect, c);
1422 i_UpdateDeviceCursorCapabilities();
1423}
1424
1425
1426void Display::i_VideoAccelVRDP(bool fEnable, int c)
1427{
1428 VIDEOACCEL *pVideoAccel = &mVideoAccelLegacy;
1429
1430 Assert (c >= 0);
1431 RT_NOREF(fEnable);
1432
1433 /* This can run concurrently with Display videoaccel state change. */
1434 RTCritSectEnter(&mVideoAccelLock);
1435
1436 if (c == 0)
1437 {
1438 /* The last client has disconnected, and the accel can be
1439 * disabled.
1440 */
1441 Assert(fEnable == false);
1442
1443 mfVideoAccelVRDP = false;
1444 mfu32SupportedOrders = 0;
1445
1446 i_vbvaSetMemoryFlags(pVideoAccel->pVbvaMemory, pVideoAccel->fVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders,
1447 maFramebuffers, mcMonitors);
1448#ifdef VBOX_WITH_HGSMI
1449 /* Here is VRDP-IN thread. Process the request in vbvaUpdateBegin under DevVGA lock on an EMT. */
1450 ASMAtomicIncU32(&mu32UpdateVBVAFlags);
1451#endif /* VBOX_WITH_HGSMI */
1452
1453 LogRel(("VBVA: VRDP acceleration has been disabled.\n"));
1454 }
1455 else if ( c == 1
1456 && !mfVideoAccelVRDP)
1457 {
1458 /* The first client has connected. Enable the accel.
1459 */
1460 Assert(fEnable == true);
1461
1462 mfVideoAccelVRDP = true;
1463 /* Supporting all orders. */
1464 mfu32SupportedOrders = UINT32_MAX;
1465
1466 i_vbvaSetMemoryFlags(pVideoAccel->pVbvaMemory, pVideoAccel->fVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders,
1467 maFramebuffers, mcMonitors);
1468#ifdef VBOX_WITH_HGSMI
1469 /* Here is VRDP-IN thread. Process the request in vbvaUpdateBegin under DevVGA lock on an EMT. */
1470 ASMAtomicIncU32(&mu32UpdateVBVAFlags);
1471#endif /* VBOX_WITH_HGSMI */
1472
1473 LogRel(("VBVA: VRDP acceleration has been requested.\n"));
1474 }
1475 else
1476 {
1477 /* A client is connected or disconnected but there is no change in the
1478 * accel state. It remains enabled.
1479 */
1480 Assert(mfVideoAccelVRDP == true);
1481 }
1482
1483 RTCritSectLeave(&mVideoAccelLock);
1484}
1485
1486void Display::i_notifyPowerDown(void)
1487{
1488 LogRelFlowFunc(("\n"));
1489
1490 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1491
1492 /* Source bitmaps are not available anymore. */
1493 mfSourceBitmapEnabled = false;
1494
1495 alock.release();
1496
1497 /* Resize all displays to tell framebuffers to forget current source bitmap. */
1498 unsigned uScreenId = mcMonitors;
1499 while (uScreenId > 0)
1500 {
1501 --uScreenId;
1502
1503 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1504 if (!pFBInfo->fDisabled)
1505 {
1506 i_handleDisplayResize(uScreenId, 32,
1507 pFBInfo->pu8FramebufferVRAM,
1508 pFBInfo->u32LineSize,
1509 pFBInfo->w,
1510 pFBInfo->h,
1511 pFBInfo->flags,
1512 pFBInfo->xOrigin,
1513 pFBInfo->yOrigin,
1514 false);
1515 }
1516 }
1517}
1518
1519// Wrapped IDisplay methods
1520/////////////////////////////////////////////////////////////////////////////
1521HRESULT Display::getScreenResolution(ULONG aScreenId, ULONG *aWidth, ULONG *aHeight, ULONG *aBitsPerPixel,
1522 LONG *aXOrigin, LONG *aYOrigin, GuestMonitorStatus_T *aGuestMonitorStatus)
1523{
1524 LogRelFlowFunc(("aScreenId=%RU32\n", aScreenId));
1525
1526 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1527
1528 if (aScreenId >= mcMonitors)
1529 return E_INVALIDARG;
1530
1531 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
1532
1533 GuestMonitorStatus_T guestMonitorStatus = GuestMonitorStatus_Enabled;
1534
1535 if (pFBInfo->flags & VBVA_SCREEN_F_DISABLED)
1536 guestMonitorStatus = GuestMonitorStatus_Disabled;
1537 else if (pFBInfo->flags & (VBVA_SCREEN_F_BLANK | VBVA_SCREEN_F_BLANK2))
1538 guestMonitorStatus = GuestMonitorStatus_Blank;
1539
1540 if (aWidth)
1541 *aWidth = pFBInfo->w;
1542 if (aHeight)
1543 *aHeight = pFBInfo->h;
1544 if (aBitsPerPixel)
1545 *aBitsPerPixel = pFBInfo->u16BitsPerPixel;
1546 if (aXOrigin)
1547 *aXOrigin = pFBInfo->xOrigin;
1548 if (aYOrigin)
1549 *aYOrigin = pFBInfo->yOrigin;
1550 if (aGuestMonitorStatus)
1551 *aGuestMonitorStatus = guestMonitorStatus;
1552
1553 return S_OK;
1554}
1555
1556
1557HRESULT Display::attachFramebuffer(ULONG aScreenId, const ComPtr<IFramebuffer> &aFramebuffer, com::Guid &aId)
1558{
1559 LogRelFlowFunc(("aScreenId = %d\n", aScreenId));
1560
1561 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1562
1563 if (aScreenId >= mcMonitors)
1564 return setError(E_INVALIDARG, tr("AttachFramebuffer: Invalid screen %d (total %d)"),
1565 aScreenId, mcMonitors);
1566
1567 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
1568 if (!pFBInfo->pFramebuffer.isNull())
1569 return setError(E_FAIL, tr("AttachFramebuffer: Framebuffer already attached to %d"),
1570 aScreenId);
1571
1572 pFBInfo->pFramebuffer = aFramebuffer;
1573 pFBInfo->framebufferId.create();
1574 aId = pFBInfo->framebufferId;
1575
1576 SafeArray<FramebufferCapabilities_T> caps;
1577 pFBInfo->pFramebuffer->COMGETTER(Capabilities)(ComSafeArrayAsOutParam(caps));
1578 pFBInfo->u32Caps = 0;
1579 size_t i;
1580 for (i = 0; i < caps.size(); ++i)
1581 pFBInfo->u32Caps |= caps[i];
1582
1583 alock.release();
1584
1585 /* The driver might not have been constructed yet */
1586 if (mpDrv)
1587 {
1588 /* Inform the framebuffer about the actual screen size. */
1589 HRESULT hr = aFramebuffer->NotifyChange(aScreenId, 0, 0, pFBInfo->w, pFBInfo->h); /** @todo origin */
1590 LogFunc(("NotifyChange hr %08X\n", hr)); NOREF(hr);
1591
1592 /* Re-send the seamless rectangles if necessary. */
1593 if (mfSeamlessEnabled)
1594 i_handleSetVisibleRegion(mcRectVisibleRegion, mpRectVisibleRegion);
1595 }
1596
1597 Console::SafeVMPtrQuiet ptrVM(mParent);
1598 if (ptrVM.isOk())
1599 ptrVM.vtable()->pfnVMR3ReqCallNoWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_InvalidateAndUpdateEMT,
1600 3, this, aScreenId, false);
1601
1602 LogRelFlowFunc(("Attached to %d %RTuuid\n", aScreenId, aId.raw()));
1603 return S_OK;
1604}
1605
1606HRESULT Display::detachFramebuffer(ULONG aScreenId, const com::Guid &aId)
1607{
1608 LogRelFlowFunc(("aScreenId = %d %RTuuid\n", aScreenId, aId.raw()));
1609
1610 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1611
1612 if (aScreenId >= mcMonitors)
1613 return setError(E_INVALIDARG, tr("DetachFramebuffer: Invalid screen %d (total %d)"),
1614 aScreenId, mcMonitors);
1615
1616 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
1617
1618 if (pFBInfo->framebufferId != aId)
1619 {
1620 LogRelFlowFunc(("Invalid framebuffer aScreenId = %d, attached %p\n", aScreenId, pFBInfo->framebufferId.raw()));
1621 return setError(E_FAIL, tr("DetachFramebuffer: Invalid framebuffer object"));
1622 }
1623
1624 pFBInfo->pFramebuffer.setNull();
1625 pFBInfo->framebufferId.clear();
1626
1627 alock.release();
1628 return S_OK;
1629}
1630
1631HRESULT Display::queryFramebuffer(ULONG aScreenId, ComPtr<IFramebuffer> &aFramebuffer)
1632{
1633 LogRelFlowFunc(("aScreenId = %d\n", aScreenId));
1634
1635 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1636
1637 if (aScreenId >= mcMonitors)
1638 return setError(E_INVALIDARG, tr("QueryFramebuffer: Invalid screen %d (total %d)"),
1639 aScreenId, mcMonitors);
1640
1641 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
1642
1643 pFBInfo->pFramebuffer.queryInterfaceTo(aFramebuffer.asOutParam());
1644
1645 return S_OK;
1646}
1647
1648HRESULT Display::setVideoModeHint(ULONG aDisplay, BOOL aEnabled,
1649 BOOL aChangeOrigin, LONG aOriginX, LONG aOriginY,
1650 ULONG aWidth, ULONG aHeight, ULONG aBitsPerPixel,
1651 BOOL aNotify)
1652{
1653 if (aWidth == 0 || aHeight == 0 || aBitsPerPixel == 0)
1654 {
1655 /* Some of parameters must not change. Query current mode. */
1656 ULONG ulWidth = 0;
1657 ULONG ulHeight = 0;
1658 ULONG ulBitsPerPixel = 0;
1659 HRESULT hr = getScreenResolution(aDisplay, &ulWidth, &ulHeight, &ulBitsPerPixel, NULL, NULL, NULL);
1660 if (FAILED(hr))
1661 return hr;
1662
1663 /* Assign current values to not changing parameters. */
1664 if (aWidth == 0)
1665 aWidth = ulWidth;
1666 if (aHeight == 0)
1667 aHeight = ulHeight;
1668 if (aBitsPerPixel == 0)
1669 aBitsPerPixel = ulBitsPerPixel;
1670 }
1671
1672 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1673
1674 if (aDisplay >= mcMonitors)
1675 return E_INVALIDARG;
1676
1677 VMMDevDisplayDef d;
1678 d.idDisplay = aDisplay;
1679 d.xOrigin = aOriginX;
1680 d.yOrigin = aOriginY;
1681 d.cx = aWidth;
1682 d.cy = aHeight;
1683 d.cBitsPerPixel = aBitsPerPixel;
1684 d.fDisplayFlags = VMMDEV_DISPLAY_CX | VMMDEV_DISPLAY_CY | VMMDEV_DISPLAY_BPP;
1685 if (!aEnabled)
1686 d.fDisplayFlags |= VMMDEV_DISPLAY_DISABLED;
1687 if (aChangeOrigin)
1688 d.fDisplayFlags |= VMMDEV_DISPLAY_ORIGIN;
1689 if (aDisplay == 0)
1690 d.fDisplayFlags |= VMMDEV_DISPLAY_PRIMARY;
1691
1692 /* Remember the monitor information. */
1693 maFramebuffers[aDisplay].monitorDesc = d;
1694
1695 CHECK_CONSOLE_DRV(mpDrv);
1696
1697 /*
1698 * It is up to the guest to decide whether the hint is
1699 * valid. Therefore don't do any VRAM sanity checks here.
1700 */
1701
1702 /* Have to release the lock because the pfnRequestDisplayChange
1703 * will call EMT. */
1704 alock.release();
1705
1706 /* We always send the hint to the graphics card in case the guest enables
1707 * support later. For now we notify exactly when support is enabled. */
1708 mpDrv->pUpPort->pfnSendModeHint(mpDrv->pUpPort, aWidth, aHeight,
1709 aBitsPerPixel, aDisplay,
1710 aChangeOrigin ? aOriginX : ~0,
1711 aChangeOrigin ? aOriginY : ~0,
1712 RT_BOOL(aEnabled),
1713 (mfGuestVBVACapabilities & VBVACAPS_VIDEO_MODE_HINTS)
1714 && aNotify);
1715 if ( mfGuestVBVACapabilities & VBVACAPS_VIDEO_MODE_HINTS
1716 && !(mfGuestVBVACapabilities & VBVACAPS_IRQ)
1717 && aNotify)
1718 mParent->i_sendACPIMonitorHotPlugEvent();
1719
1720 /* We currently never suppress the VMMDev hint if the guest has requested
1721 * it. Specifically the video graphics driver may not be responsible for
1722 * screen positioning in the guest virtual desktop, and the component
1723 * responsible may want to get the hint from VMMDev. */
1724 VMMDev *pVMMDev = mParent->i_getVMMDev();
1725 if (pVMMDev)
1726 {
1727 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
1728 if (pVMMDevPort)
1729 pVMMDevPort->pfnRequestDisplayChange(pVMMDevPort, 1, &d, false, RT_BOOL(aNotify));
1730 }
1731 /* Notify listeners. */
1732 ::FireGuestMonitorInfoChangedEvent(mParent->i_getEventSource(), aDisplay);
1733 return S_OK;
1734}
1735
1736HRESULT Display::getVideoModeHint(ULONG cDisplay, BOOL *pfEnabled,
1737 BOOL *pfChangeOrigin, LONG *pxOrigin, LONG *pyOrigin,
1738 ULONG *pcx, ULONG *pcy, ULONG *pcBitsPerPixel)
1739{
1740 if (cDisplay >= mcMonitors)
1741 return E_INVALIDARG;
1742
1743 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1744 if (pfEnabled)
1745 *pfEnabled = !( maFramebuffers[cDisplay].monitorDesc.fDisplayFlags
1746 & VMMDEV_DISPLAY_DISABLED);
1747 if (pfChangeOrigin)
1748 *pfChangeOrigin = RT_BOOL( maFramebuffers[cDisplay].monitorDesc.fDisplayFlags
1749 & VMMDEV_DISPLAY_ORIGIN);
1750 if (pxOrigin)
1751 *pxOrigin = maFramebuffers[cDisplay].monitorDesc.xOrigin;
1752 if (pyOrigin)
1753 *pyOrigin = maFramebuffers[cDisplay].monitorDesc.yOrigin;
1754 if (pcx)
1755 *pcx = maFramebuffers[cDisplay].monitorDesc.cx;
1756 if (pcy)
1757 *pcy = maFramebuffers[cDisplay].monitorDesc.cy;
1758 if (pcBitsPerPixel)
1759 *pcBitsPerPixel = maFramebuffers[cDisplay].monitorDesc.cBitsPerPixel;
1760 return S_OK;
1761}
1762
1763HRESULT Display::setSeamlessMode(BOOL enabled)
1764{
1765 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1766
1767 /* Have to release the lock because the pfnRequestSeamlessChange will call EMT. */
1768 alock.release();
1769
1770 VMMDev *pVMMDev = mParent->i_getVMMDev();
1771 if (pVMMDev)
1772 {
1773 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
1774 if (pVMMDevPort)
1775 pVMMDevPort->pfnRequestSeamlessChange(pVMMDevPort, !!enabled);
1776 }
1777 mfSeamlessEnabled = RT_BOOL(enabled);
1778 return S_OK;
1779}
1780
1781/*static*/ DECLCALLBACK(int)
1782Display::i_displayTakeScreenshotEMT(Display *pDisplay, ULONG aScreenId, uint8_t **ppbData, size_t *pcbData,
1783 uint32_t *pcx, uint32_t *pcy, bool *pfMemFree)
1784{
1785 int rc;
1786 if ( aScreenId == VBOX_VIDEO_PRIMARY_SCREEN
1787 && pDisplay->maFramebuffers[aScreenId].fVBVAEnabled == false) /* A non-VBVA mode. */
1788 {
1789 if (pDisplay->mpDrv)
1790 {
1791 rc = pDisplay->mpDrv->pUpPort->pfnTakeScreenshot(pDisplay->mpDrv->pUpPort, ppbData, pcbData, pcx, pcy);
1792 *pfMemFree = false;
1793 }
1794 else
1795 {
1796 /* No image. */
1797 *ppbData = NULL;
1798 *pcbData = 0;
1799 *pcx = 0;
1800 *pcy = 0;
1801 *pfMemFree = true;
1802 rc = VINF_SUCCESS;
1803 }
1804 }
1805 else if (aScreenId < pDisplay->mcMonitors)
1806 {
1807 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[aScreenId];
1808
1809 uint32_t width = pFBInfo->w;
1810 uint32_t height = pFBInfo->h;
1811
1812 /* Allocate 32 bit per pixel bitmap. */
1813 size_t cbRequired = width * 4 * height;
1814
1815 if (cbRequired)
1816 {
1817 uint8_t *pbDst = (uint8_t *)RTMemAlloc(cbRequired);
1818 if (pbDst != NULL)
1819 {
1820 if (pFBInfo->flags & VBVA_SCREEN_F_ACTIVE)
1821 {
1822 /* Copy guest VRAM to the allocated 32bpp buffer. */
1823 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
1824 int32_t xSrc = 0;
1825 int32_t ySrc = 0;
1826 uint32_t u32SrcWidth = width;
1827 uint32_t u32SrcHeight = height;
1828 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
1829 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
1830
1831 int32_t xDst = 0;
1832 int32_t yDst = 0;
1833 uint32_t u32DstWidth = u32SrcWidth;
1834 uint32_t u32DstHeight = u32SrcHeight;
1835 uint32_t u32DstLineSize = u32DstWidth * 4;
1836 uint32_t u32DstBitsPerPixel = 32;
1837
1838 rc = pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
1839 width, height,
1840 pu8Src,
1841 xSrc, ySrc,
1842 u32SrcWidth, u32SrcHeight,
1843 u32SrcLineSize, u32SrcBitsPerPixel,
1844 pbDst,
1845 xDst, yDst,
1846 u32DstWidth, u32DstHeight,
1847 u32DstLineSize, u32DstBitsPerPixel);
1848 }
1849 else
1850 {
1851 memset(pbDst, 0, cbRequired);
1852 rc = VINF_SUCCESS;
1853 }
1854 if (RT_SUCCESS(rc))
1855 {
1856 *ppbData = pbDst;
1857 *pcbData = cbRequired;
1858 *pcx = width;
1859 *pcy = height;
1860 *pfMemFree = true;
1861 }
1862 else
1863 {
1864 RTMemFree(pbDst);
1865
1866 /* CopyRect can fail if VBVA was paused in VGA device, retry using the generic method. */
1867 if ( rc == VERR_INVALID_STATE
1868 && aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
1869 {
1870 rc = pDisplay->mpDrv->pUpPort->pfnTakeScreenshot(pDisplay->mpDrv->pUpPort, ppbData, pcbData, pcx, pcy);
1871 *pfMemFree = false;
1872 }
1873 }
1874 }
1875 else
1876 rc = VERR_NO_MEMORY;
1877 }
1878 else
1879 {
1880 /* No image. */
1881 *ppbData = NULL;
1882 *pcbData = 0;
1883 *pcx = 0;
1884 *pcy = 0;
1885 *pfMemFree = true;
1886 rc = VINF_SUCCESS;
1887 }
1888 }
1889 else
1890 rc = VERR_INVALID_PARAMETER;
1891 return rc;
1892}
1893
1894static int i_displayTakeScreenshot(PUVM pUVM, PCVMMR3VTABLE pVMM, Display *pDisplay, struct DRVMAINDISPLAY *pDrv,
1895 ULONG aScreenId, BYTE *address, ULONG width, ULONG height)
1896{
1897 uint8_t *pbData = NULL;
1898 size_t cbData = 0;
1899 uint32_t cx = 0;
1900 uint32_t cy = 0;
1901 bool fFreeMem = false;
1902 int vrc = VINF_SUCCESS;
1903
1904 int cRetries = 5;
1905 while (cRetries-- > 0)
1906 {
1907 /* Note! Not sure if the priority call is such a good idea here, but
1908 it would be nice to have an accurate screenshot for the bug
1909 report if the VM deadlocks. */
1910 vrc = pVMM->pfnVMR3ReqPriorityCallWaitU(pUVM, VMCPUID_ANY, (PFNRT)Display::i_displayTakeScreenshotEMT, 7,
1911 pDisplay, aScreenId, &pbData, &cbData, &cx, &cy, &fFreeMem);
1912 if (vrc != VERR_TRY_AGAIN)
1913 {
1914 break;
1915 }
1916
1917 RTThreadSleep(10);
1918 }
1919
1920 if (RT_SUCCESS(vrc) && pbData)
1921 {
1922 if (cx == width && cy == height)
1923 {
1924 /* No scaling required. */
1925 memcpy(address, pbData, cbData);
1926 }
1927 else
1928 {
1929 /* Scale. */
1930 LogRelFlowFunc(("SCALE: %dx%d -> %dx%d\n", cx, cy, width, height));
1931
1932 uint8_t *dst = address;
1933 uint8_t *src = pbData;
1934 int dstW = width;
1935 int dstH = height;
1936 int srcW = cx;
1937 int srcH = cy;
1938 int iDeltaLine = cx * 4;
1939
1940 BitmapScale32(dst,
1941 dstW, dstH,
1942 src,
1943 iDeltaLine,
1944 srcW, srcH);
1945 }
1946
1947 if (fFreeMem)
1948 RTMemFree(pbData);
1949 else
1950 {
1951 /* This can be called from any thread. */
1952 pDrv->pUpPort->pfnFreeScreenshot(pDrv->pUpPort, pbData);
1953 }
1954 }
1955
1956 return vrc;
1957}
1958
1959HRESULT Display::takeScreenShotWorker(ULONG aScreenId,
1960 BYTE *aAddress,
1961 ULONG aWidth,
1962 ULONG aHeight,
1963 BitmapFormat_T aBitmapFormat,
1964 ULONG *pcbOut)
1965{
1966 HRESULT rc = S_OK;
1967
1968 /* Do not allow too small and too large screenshots. This also filters out negative
1969 * values passed as either 'aWidth' or 'aHeight'.
1970 */
1971 CheckComArgExpr(aWidth, aWidth != 0 && aWidth <= 32767);
1972 CheckComArgExpr(aHeight, aHeight != 0 && aHeight <= 32767);
1973
1974 if ( aBitmapFormat != BitmapFormat_BGR0
1975 && aBitmapFormat != BitmapFormat_BGRA
1976 && aBitmapFormat != BitmapFormat_RGBA
1977 && aBitmapFormat != BitmapFormat_PNG)
1978 {
1979 return setError(E_NOTIMPL,
1980 tr("Unsupported screenshot format 0x%08X"), aBitmapFormat);
1981 }
1982
1983 Console::SafeVMPtr ptrVM(mParent);
1984 if (!ptrVM.isOk())
1985 return ptrVM.rc();
1986
1987 int vrc = i_displayTakeScreenshot(ptrVM.rawUVM(), ptrVM.vtable(), this, mpDrv, aScreenId, aAddress, aWidth, aHeight);
1988 if (RT_SUCCESS(vrc))
1989 {
1990 const size_t cbData = aWidth * 4 * aHeight;
1991
1992 /* Most of uncompressed formats. */
1993 *pcbOut = (ULONG)cbData;
1994
1995 if (aBitmapFormat == BitmapFormat_BGR0)
1996 {
1997 /* Do nothing. */
1998 }
1999 else if (aBitmapFormat == BitmapFormat_BGRA)
2000 {
2001 uint32_t *pu32 = (uint32_t *)aAddress;
2002 size_t cPixels = aWidth * aHeight;
2003 while (cPixels--)
2004 *pu32++ |= UINT32_C(0xFF000000);
2005 }
2006 else if (aBitmapFormat == BitmapFormat_RGBA)
2007 {
2008 uint8_t *pu8 = aAddress;
2009 size_t cPixels = aWidth * aHeight;
2010 while (cPixels--)
2011 {
2012 uint8_t u8 = pu8[0];
2013 pu8[0] = pu8[2];
2014 pu8[2] = u8;
2015 pu8[3] = 0xFF;
2016
2017 pu8 += 4;
2018 }
2019 }
2020 else if (aBitmapFormat == BitmapFormat_PNG)
2021 {
2022 uint8_t *pu8PNG = NULL;
2023 uint32_t cbPNG = 0;
2024 uint32_t cxPNG = 0;
2025 uint32_t cyPNG = 0;
2026
2027 vrc = DisplayMakePNG(aAddress, aWidth, aHeight, &pu8PNG, &cbPNG, &cxPNG, &cyPNG, 0);
2028 if (RT_SUCCESS(vrc))
2029 {
2030 if (cbPNG <= cbData)
2031 {
2032 memcpy(aAddress, pu8PNG, cbPNG);
2033 *pcbOut = cbPNG;
2034 }
2035 else
2036 rc = setError(E_FAIL, tr("PNG is larger than 32bpp bitmap"));
2037 }
2038 else
2039 rc = setErrorBoth(VBOX_E_VM_ERROR, vrc, tr("Could not convert screenshot to PNG (%Rrc)"), vrc);
2040 RTMemFree(pu8PNG);
2041 }
2042 }
2043 else if (vrc == VERR_TRY_AGAIN)
2044 rc = setErrorBoth(E_UNEXPECTED, vrc, tr("Screenshot is not available at this time"));
2045 else if (RT_FAILURE(vrc))
2046 rc = setErrorBoth(VBOX_E_VM_ERROR, vrc, tr("Could not take a screenshot (%Rrc)"), vrc);
2047
2048 return rc;
2049}
2050
2051HRESULT Display::takeScreenShot(ULONG aScreenId,
2052 BYTE *aAddress,
2053 ULONG aWidth,
2054 ULONG aHeight,
2055 BitmapFormat_T aBitmapFormat)
2056{
2057 HRESULT rc = S_OK;
2058
2059 LogRelFlowFunc(("[%d] address=%p, width=%d, height=%d, format 0x%08X\n",
2060 aScreenId, aAddress, aWidth, aHeight, aBitmapFormat));
2061
2062 ULONG cbOut = 0;
2063 rc = takeScreenShotWorker(aScreenId, aAddress, aWidth, aHeight, aBitmapFormat, &cbOut);
2064 NOREF(cbOut);
2065
2066 LogRelFlowFunc(("%Rhrc\n", rc));
2067 return rc;
2068}
2069
2070HRESULT Display::takeScreenShotToArray(ULONG aScreenId,
2071 ULONG aWidth,
2072 ULONG aHeight,
2073 BitmapFormat_T aBitmapFormat,
2074 std::vector<BYTE> &aScreenData)
2075{
2076 HRESULT rc = S_OK;
2077
2078 LogRelFlowFunc(("[%d] width=%d, height=%d, format 0x%08X\n",
2079 aScreenId, aWidth, aHeight, aBitmapFormat));
2080
2081 /* Do not allow too small and too large screenshots. This also filters out negative
2082 * values passed as either 'aWidth' or 'aHeight'.
2083 */
2084 CheckComArgExpr(aWidth, aWidth != 0 && aWidth <= 32767);
2085 CheckComArgExpr(aHeight, aHeight != 0 && aHeight <= 32767);
2086
2087 const size_t cbData = aWidth * 4 * aHeight;
2088 aScreenData.resize(cbData);
2089
2090 ULONG cbOut = 0;
2091 rc = takeScreenShotWorker(aScreenId, &aScreenData.front(), aWidth, aHeight, aBitmapFormat, &cbOut);
2092 if (FAILED(rc))
2093 cbOut = 0;
2094
2095 aScreenData.resize(cbOut);
2096
2097 LogRelFlowFunc(("%Rhrc\n", rc));
2098 return rc;
2099}
2100
2101#ifdef VBOX_WITH_RECORDING
2102/**
2103 * Invalidates the recording configuration.
2104 *
2105 * @returns IPRT status code.
2106 */
2107int Display::i_recordingInvalidate(void)
2108{
2109 RecordingContext *pCtx = mParent->i_recordingGetContext();
2110 if (!pCtx || !pCtx->IsStarted())
2111 return VINF_SUCCESS;
2112
2113 /*
2114 * Invalidate screens.
2115 */
2116 for (unsigned uScreen = 0; uScreen < mcMonitors; uScreen++)
2117 {
2118 RecordingStream *pRecordingStream = pCtx->GetStream(uScreen);
2119
2120 const bool fStreamEnabled = pRecordingStream->IsReady();
2121 bool fChanged = maRecordingEnabled[uScreen] != fStreamEnabled;
2122
2123 maRecordingEnabled[uScreen] = fStreamEnabled;
2124
2125 if (fChanged && uScreen < mcMonitors)
2126 i_recordingScreenChanged(uScreen);
2127 }
2128
2129 return VINF_SUCCESS;
2130}
2131
2132void Display::i_recordingScreenChanged(unsigned uScreenId)
2133{
2134 RecordingContext *pCtx = mParent->i_recordingGetContext();
2135
2136 i_UpdateDeviceCursorCapabilities();
2137 if ( RT_LIKELY(!maRecordingEnabled[uScreenId])
2138 || !pCtx || !pCtx->IsStarted())
2139 {
2140 /* Skip recording this screen. */
2141 return;
2142 }
2143
2144 /* Get a new source bitmap which will be used by video recording code. */
2145 ComPtr<IDisplaySourceBitmap> pSourceBitmap;
2146 QuerySourceBitmap(uScreenId, pSourceBitmap.asOutParam());
2147
2148 int rc2 = RTCritSectEnter(&mVideoRecLock);
2149 if (RT_SUCCESS(rc2))
2150 {
2151 maFramebuffers[uScreenId].Recording.pSourceBitmap = pSourceBitmap;
2152
2153 rc2 = RTCritSectLeave(&mVideoRecLock);
2154 AssertRC(rc2);
2155 }
2156}
2157#endif /* VBOX_WITH_RECORDING */
2158
2159/*static*/ DECLCALLBACK(int)
2160Display::i_drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address, ULONG x, ULONG y, ULONG width, ULONG height)
2161{
2162 int rc = VINF_SUCCESS;
2163
2164 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[aScreenId];
2165
2166 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2167 {
2168 rc = pDisplay->mpDrv->pUpPort->pfnDisplayBlt(pDisplay->mpDrv->pUpPort, address, x, y, width, height);
2169 }
2170 else if (aScreenId < pDisplay->mcMonitors)
2171 {
2172 /* Copy the bitmap to the guest VRAM. */
2173 const uint8_t *pu8Src = address;
2174 int32_t xSrc = 0;
2175 int32_t ySrc = 0;
2176 uint32_t u32SrcWidth = width;
2177 uint32_t u32SrcHeight = height;
2178 uint32_t u32SrcLineSize = width * 4;
2179 uint32_t u32SrcBitsPerPixel = 32;
2180
2181 uint8_t *pu8Dst = pFBInfo->pu8FramebufferVRAM;
2182 int32_t xDst = x;
2183 int32_t yDst = y;
2184 uint32_t u32DstWidth = pFBInfo->w;
2185 uint32_t u32DstHeight = pFBInfo->h;
2186 uint32_t u32DstLineSize = pFBInfo->u32LineSize;
2187 uint32_t u32DstBitsPerPixel = pFBInfo->u16BitsPerPixel;
2188
2189 rc = pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2190 width, height,
2191 pu8Src,
2192 xSrc, ySrc,
2193 u32SrcWidth, u32SrcHeight,
2194 u32SrcLineSize, u32SrcBitsPerPixel,
2195 pu8Dst,
2196 xDst, yDst,
2197 u32DstWidth, u32DstHeight,
2198 u32DstLineSize, u32DstBitsPerPixel);
2199 if (RT_SUCCESS(rc))
2200 {
2201 if (!pFBInfo->pSourceBitmap.isNull())
2202 {
2203 /* Update the changed screen area. When source bitmap uses VRAM directly, just notify
2204 * frontend to update. And for default format, render the guest VRAM to the source bitmap.
2205 */
2206 if ( pFBInfo->fDefaultFormat
2207 && !pFBInfo->fDisabled)
2208 {
2209 BYTE *pAddress = NULL;
2210 ULONG ulWidth = 0;
2211 ULONG ulHeight = 0;
2212 ULONG ulBitsPerPixel = 0;
2213 ULONG ulBytesPerLine = 0;
2214 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
2215
2216 HRESULT hrc = pFBInfo->pSourceBitmap->QueryBitmapInfo(&pAddress,
2217 &ulWidth,
2218 &ulHeight,
2219 &ulBitsPerPixel,
2220 &ulBytesPerLine,
2221 &bitmapFormat);
2222 if (SUCCEEDED(hrc))
2223 {
2224 pu8Src = pFBInfo->pu8FramebufferVRAM;
2225 xSrc = x;
2226 ySrc = y;
2227 u32SrcWidth = pFBInfo->w;
2228 u32SrcHeight = pFBInfo->h;
2229 u32SrcLineSize = pFBInfo->u32LineSize;
2230 u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2231
2232 /* Default format is 32 bpp. */
2233 pu8Dst = pAddress;
2234 xDst = xSrc;
2235 yDst = ySrc;
2236 u32DstWidth = u32SrcWidth;
2237 u32DstHeight = u32SrcHeight;
2238 u32DstLineSize = u32DstWidth * 4;
2239 u32DstBitsPerPixel = 32;
2240
2241 pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2242 width, height,
2243 pu8Src,
2244 xSrc, ySrc,
2245 u32SrcWidth, u32SrcHeight,
2246 u32SrcLineSize, u32SrcBitsPerPixel,
2247 pu8Dst,
2248 xDst, yDst,
2249 u32DstWidth, u32DstHeight,
2250 u32DstLineSize, u32DstBitsPerPixel);
2251 }
2252 }
2253 }
2254
2255 pDisplay->i_handleDisplayUpdate(aScreenId, x, y, width, height);
2256 }
2257 }
2258 else
2259 {
2260 rc = VERR_INVALID_PARAMETER;
2261 }
2262
2263 if (RT_SUCCESS(rc))
2264 pDisplay->mParent->i_consoleVRDPServer()->SendUpdateBitmap(aScreenId, x, y, width, height);
2265
2266 return rc;
2267}
2268
2269HRESULT Display::drawToScreen(ULONG aScreenId, BYTE *aAddress, ULONG aX, ULONG aY, ULONG aWidth, ULONG aHeight)
2270{
2271 /// @todo (r=dmik) this function may take too long to complete if the VM
2272 // is doing something like saving state right now. Which, in case if it
2273 // is called on the GUI thread, will make it unresponsive. We should
2274 // check the machine state here (by enclosing the check and VMRequCall
2275 // within the Console lock to make it atomic).
2276
2277 LogRelFlowFunc(("aAddress=%p, x=%d, y=%d, width=%d, height=%d\n",
2278 (void *)aAddress, aX, aY, aWidth, aHeight));
2279
2280 CheckComArgExpr(aWidth, aWidth != 0);
2281 CheckComArgExpr(aHeight, aHeight != 0);
2282
2283 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2284
2285 CHECK_CONSOLE_DRV(mpDrv);
2286
2287 Console::SafeVMPtr ptrVM(mParent);
2288 if (!ptrVM.isOk())
2289 return ptrVM.rc();
2290
2291 /* Release lock because the call scheduled on EMT may also try to take it. */
2292 alock.release();
2293
2294 /*
2295 * Again we're lazy and make the graphics device do all the
2296 * dirty conversion work.
2297 */
2298 int vrc = ptrVM.vtable()->pfnVMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_drawToScreenEMT, 7,
2299 this, aScreenId, aAddress, aX, aY, aWidth, aHeight);
2300
2301 /*
2302 * If the function returns not supported, we'll have to do all the
2303 * work ourselves using the framebuffer.
2304 */
2305 HRESULT rc = S_OK;
2306 if (vrc == VERR_NOT_SUPPORTED || vrc == VERR_NOT_IMPLEMENTED)
2307 {
2308 /** @todo implement generic fallback for screen blitting. */
2309 rc = E_NOTIMPL;
2310 }
2311 else if (RT_FAILURE(vrc))
2312 rc = setErrorBoth(VBOX_E_VM_ERROR, vrc, tr("Could not draw to the screen (%Rrc)"), vrc);
2313/// @todo
2314// else
2315// {
2316// /* All ok. Redraw the screen. */
2317// handleDisplayUpdate(x, y, width, height);
2318// }
2319
2320 LogRelFlowFunc(("rc=%Rhrc\n", rc));
2321 return rc;
2322}
2323
2324/** @todo r=bird: cannot quite see why this would be required to run on an
2325 * EMT any more. It's not an issue in the COM methods, but for the
2326 * VGA device interface it is an issue, see querySourceBitmap. */
2327/*static*/ DECLCALLBACK(int) Display::i_InvalidateAndUpdateEMT(Display *pDisplay, unsigned uId, bool fUpdateAll)
2328{
2329 LogRelFlowFunc(("uId=%d, fUpdateAll %d\n", uId, fUpdateAll));
2330
2331 unsigned uScreenId;
2332 for (uScreenId = (fUpdateAll ? 0 : uId); uScreenId < pDisplay->mcMonitors; uScreenId++)
2333 {
2334 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
2335
2336 if ( !pFBInfo->fVBVAEnabled
2337 && uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2338 pDisplay->mpDrv->pUpPort->pfnUpdateDisplayAll(pDisplay->mpDrv->pUpPort, /* fFailOnResize = */ true);
2339 else
2340 {
2341 if (!pFBInfo->fDisabled)
2342 {
2343 /* Render complete VRAM screen to the framebuffer.
2344 * When framebuffer uses VRAM directly, just notify it to update.
2345 */
2346 if (pFBInfo->fDefaultFormat && !pFBInfo->pSourceBitmap.isNull())
2347 {
2348 BYTE *pAddress = NULL;
2349 ULONG ulWidth = 0;
2350 ULONG ulHeight = 0;
2351 ULONG ulBitsPerPixel = 0;
2352 ULONG ulBytesPerLine = 0;
2353 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
2354
2355 HRESULT hrc = pFBInfo->pSourceBitmap->QueryBitmapInfo(&pAddress,
2356 &ulWidth,
2357 &ulHeight,
2358 &ulBitsPerPixel,
2359 &ulBytesPerLine,
2360 &bitmapFormat);
2361 if (SUCCEEDED(hrc))
2362 {
2363 uint32_t width = pFBInfo->w;
2364 uint32_t height = pFBInfo->h;
2365
2366 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
2367 int32_t xSrc = 0;
2368 int32_t ySrc = 0;
2369 uint32_t u32SrcWidth = pFBInfo->w;
2370 uint32_t u32SrcHeight = pFBInfo->h;
2371 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
2372 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2373
2374 /* Default format is 32 bpp. */
2375 uint8_t *pu8Dst = pAddress;
2376 int32_t xDst = xSrc;
2377 int32_t yDst = ySrc;
2378 uint32_t u32DstWidth = u32SrcWidth;
2379 uint32_t u32DstHeight = u32SrcHeight;
2380 uint32_t u32DstLineSize = u32DstWidth * 4;
2381 uint32_t u32DstBitsPerPixel = 32;
2382
2383 /* if uWidth != pFBInfo->w and uHeight != pFBInfo->h
2384 * implies resize of Framebuffer is in progress and
2385 * copyrect should not be called.
2386 */
2387 if (ulWidth == pFBInfo->w && ulHeight == pFBInfo->h)
2388 pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2389 width, height,
2390 pu8Src,
2391 xSrc, ySrc,
2392 u32SrcWidth, u32SrcHeight,
2393 u32SrcLineSize, u32SrcBitsPerPixel,
2394 pu8Dst,
2395 xDst, yDst,
2396 u32DstWidth, u32DstHeight,
2397 u32DstLineSize, u32DstBitsPerPixel);
2398 }
2399 }
2400
2401 pDisplay->i_handleDisplayUpdate(uScreenId, 0, 0, pFBInfo->w, pFBInfo->h);
2402 }
2403 }
2404 if (!fUpdateAll)
2405 break;
2406 }
2407 LogRelFlowFunc(("done\n"));
2408 return VINF_SUCCESS;
2409}
2410
2411/**
2412 * Does a full invalidation of the VM display and instructs the VM
2413 * to update it immediately.
2414 *
2415 * @returns COM status code
2416 */
2417
2418HRESULT Display::invalidateAndUpdate()
2419{
2420 LogRelFlowFunc(("\n"));
2421
2422 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2423
2424 CHECK_CONSOLE_DRV(mpDrv);
2425
2426 Console::SafeVMPtr ptrVM(mParent);
2427 HRESULT hrc = ptrVM.rc();
2428 if (SUCCEEDED(hrc))
2429 {
2430 LogRelFlowFunc(("Sending DPYUPDATE request\n"));
2431
2432 /* Have to release the lock when calling EMT. */
2433 alock.release();
2434
2435 int vrc = ptrVM.vtable()->pfnVMR3ReqCallNoWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_InvalidateAndUpdateEMT,
2436 3, this, 0, true);
2437 alock.acquire();
2438
2439 if (RT_FAILURE(vrc))
2440 hrc = setErrorBoth(VBOX_E_VM_ERROR, vrc, tr("Could not invalidate and update the screen (%Rrc)"), vrc);
2441 }
2442
2443 LogRelFlowFunc(("hrc=%Rhrc\n", hrc));
2444 return hrc;
2445}
2446
2447HRESULT Display::invalidateAndUpdateScreen(ULONG aScreenId)
2448{
2449 LogRelFlowFunc(("\n"));
2450
2451 Console::SafeVMPtr ptrVM(mParent);
2452 HRESULT hrc = ptrVM.rc();
2453 if (SUCCEEDED(hrc))
2454 {
2455 int vrc = ptrVM.vtable()->pfnVMR3ReqCallNoWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_InvalidateAndUpdateEMT,
2456 3, this, aScreenId, false);
2457 if (RT_FAILURE(vrc))
2458 hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc, tr("Could not invalidate and update the screen %d (%Rrc)"), aScreenId, vrc);
2459 }
2460
2461 LogRelFlowFunc(("hrc=%Rhrc\n", hrc));
2462 return hrc;
2463}
2464
2465HRESULT Display::completeVHWACommand(BYTE *aCommand)
2466{
2467#ifdef VBOX_WITH_VIDEOHWACCEL
2468 mpDrv->pVBVACallbacks->pfnVHWACommandCompleteAsync(mpDrv->pVBVACallbacks, (VBOXVHWACMD RT_UNTRUSTED_VOLATILE_GUEST *)aCommand);
2469 return S_OK;
2470#else
2471 RT_NOREF(aCommand);
2472 return E_NOTIMPL;
2473#endif
2474}
2475
2476HRESULT Display::viewportChanged(ULONG aScreenId, ULONG aX, ULONG aY, ULONG aWidth, ULONG aHeight)
2477{
2478 AssertMsgReturn(aScreenId < mcMonitors, ("aScreendId=%d mcMonitors=%d\n", aScreenId, mcMonitors), E_INVALIDARG);
2479
2480 /* The driver might not have been constructed yet */
2481 if (mpDrv && mpDrv->pUpPort->pfnSetViewport)
2482 mpDrv->pUpPort->pfnSetViewport(mpDrv->pUpPort, aScreenId, aX, aY, aWidth, aHeight);
2483
2484 return S_OK;
2485}
2486
2487HRESULT Display::querySourceBitmap(ULONG aScreenId,
2488 ComPtr<IDisplaySourceBitmap> &aDisplaySourceBitmap)
2489{
2490 LogRelFlowFunc(("aScreenId = %d\n", aScreenId));
2491
2492 Console::SafeVMPtr ptrVM(mParent);
2493 if (!ptrVM.isOk())
2494 return ptrVM.rc();
2495
2496 CHECK_CONSOLE_DRV(mpDrv);
2497
2498 bool fSetRenderVRAM = false;
2499 bool fInvalidate = false;
2500
2501 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2502
2503 if (aScreenId >= mcMonitors)
2504 return setError(E_INVALIDARG, tr("QuerySourceBitmap: Invalid screen %d (total %d)"), aScreenId, mcMonitors);
2505
2506 if (!mfSourceBitmapEnabled)
2507 {
2508 aDisplaySourceBitmap = NULL;
2509 return E_FAIL;
2510 }
2511
2512 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
2513
2514 /* No source bitmap for a blank guest screen. */
2515 if (pFBInfo->flags & VBVA_SCREEN_F_BLANK)
2516 {
2517 aDisplaySourceBitmap = NULL;
2518 return E_FAIL;
2519 }
2520
2521 HRESULT hr = S_OK;
2522
2523 if (pFBInfo->pSourceBitmap.isNull())
2524 {
2525 /* Create a new object. */
2526 ComObjPtr<DisplaySourceBitmap> obj;
2527 hr = obj.createObject();
2528 if (SUCCEEDED(hr))
2529 hr = obj->init(this, aScreenId, pFBInfo);
2530
2531 if (SUCCEEDED(hr))
2532 {
2533 pFBInfo->pSourceBitmap = obj;
2534 pFBInfo->fDefaultFormat = !obj->i_usesVRAM();
2535
2536 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2537 {
2538 /* Start buffer updates. */
2539 BYTE *pAddress = NULL;
2540 ULONG ulWidth = 0;
2541 ULONG ulHeight = 0;
2542 ULONG ulBitsPerPixel = 0;
2543 ULONG ulBytesPerLine = 0;
2544 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
2545
2546 pFBInfo->pSourceBitmap->QueryBitmapInfo(&pAddress,
2547 &ulWidth,
2548 &ulHeight,
2549 &ulBitsPerPixel,
2550 &ulBytesPerLine,
2551 &bitmapFormat);
2552
2553 mpDrv->IConnector.pbData = pAddress;
2554 mpDrv->IConnector.cbScanline = ulBytesPerLine;
2555 mpDrv->IConnector.cBits = ulBitsPerPixel;
2556 mpDrv->IConnector.cx = ulWidth;
2557 mpDrv->IConnector.cy = ulHeight;
2558
2559 fSetRenderVRAM = pFBInfo->fDefaultFormat;
2560 }
2561
2562 /* Make sure that the bitmap contains the latest image. */
2563 fInvalidate = pFBInfo->fDefaultFormat;
2564 }
2565 }
2566
2567 if (SUCCEEDED(hr))
2568 {
2569 pFBInfo->pSourceBitmap.queryInterfaceTo(aDisplaySourceBitmap.asOutParam());
2570 }
2571
2572 /* Leave the IDisplay lock because the VGA device must not be called under it. */
2573 alock.release();
2574
2575 if (SUCCEEDED(hr))
2576 {
2577 if (fSetRenderVRAM)
2578 mpDrv->pUpPort->pfnSetRenderVRAM(mpDrv->pUpPort, true);
2579
2580 if (fInvalidate)
2581#if 1 /* bird: Cannot see why this needs to run on an EMT. It deadlocks now with timer callback moving to non-EMT worker threads. */
2582 Display::i_InvalidateAndUpdateEMT(this, aScreenId, false /*fUpdateAll*/);
2583#else
2584 VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_InvalidateAndUpdateEMT,
2585 3, this, aScreenId, false);
2586#endif
2587 }
2588
2589 LogRelFlowFunc(("%Rhrc\n", hr));
2590 return hr;
2591}
2592
2593HRESULT Display::getGuestScreenLayout(std::vector<ComPtr<IGuestScreenInfo> > &aGuestScreenLayout)
2594{
2595 NOREF(aGuestScreenLayout);
2596 return E_NOTIMPL;
2597}
2598
2599HRESULT Display::setScreenLayout(ScreenLayoutMode_T aScreenLayoutMode,
2600 const std::vector<ComPtr<IGuestScreenInfo> > &aGuestScreenInfo)
2601{
2602 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2603
2604 if (aGuestScreenInfo.size() != mcMonitors)
2605 return E_INVALIDARG;
2606
2607 CHECK_CONSOLE_DRV(mpDrv);
2608
2609 /*
2610 * It is up to the guest to decide whether the hint is
2611 * valid. Therefore don't do any VRAM sanity checks here.
2612 */
2613
2614 /* Have to release the lock because the pfnRequestDisplayChange
2615 * will call EMT. */
2616 alock.release();
2617
2618 VMMDev *pVMMDev = mParent->i_getVMMDev();
2619 if (pVMMDev)
2620 {
2621 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
2622 if (pVMMDevPort)
2623 {
2624 uint32_t const cDisplays = (uint32_t)aGuestScreenInfo.size();
2625
2626 size_t const cbAlloc = cDisplays * sizeof(VMMDevDisplayDef);
2627 VMMDevDisplayDef *paDisplayDefs = (VMMDevDisplayDef *)RTMemAlloc(cbAlloc);
2628 if (paDisplayDefs)
2629 {
2630 for (uint32_t i = 0; i < cDisplays; ++i)
2631 {
2632 VMMDevDisplayDef *p = &paDisplayDefs[i];
2633 ComPtr<IGuestScreenInfo> pScreenInfo = aGuestScreenInfo[i];
2634
2635 ULONG screenId = 0;
2636 GuestMonitorStatus_T guestMonitorStatus = GuestMonitorStatus_Enabled;
2637 BOOL origin = FALSE;
2638 BOOL primary = FALSE;
2639 LONG originX = 0;
2640 LONG originY = 0;
2641 ULONG width = 0;
2642 ULONG height = 0;
2643 ULONG bitsPerPixel = 0;
2644
2645 pScreenInfo->COMGETTER(ScreenId) (&screenId);
2646 pScreenInfo->COMGETTER(GuestMonitorStatus)(&guestMonitorStatus);
2647 pScreenInfo->COMGETTER(Primary) (&primary);
2648 pScreenInfo->COMGETTER(Origin) (&origin);
2649 pScreenInfo->COMGETTER(OriginX) (&originX);
2650 pScreenInfo->COMGETTER(OriginY) (&originY);
2651 pScreenInfo->COMGETTER(Width) (&width);
2652 pScreenInfo->COMGETTER(Height) (&height);
2653 pScreenInfo->COMGETTER(BitsPerPixel)(&bitsPerPixel);
2654
2655 LogFlowFunc(("%d %d,%d %dx%d\n", screenId, originX, originY, width, height));
2656
2657 p->idDisplay = screenId;
2658 p->xOrigin = originX;
2659 p->yOrigin = originY;
2660 p->cx = width;
2661 p->cy = height;
2662 p->cBitsPerPixel = bitsPerPixel;
2663 p->fDisplayFlags = VMMDEV_DISPLAY_CX | VMMDEV_DISPLAY_CY | VMMDEV_DISPLAY_BPP;
2664 if (guestMonitorStatus == GuestMonitorStatus_Disabled)
2665 p->fDisplayFlags |= VMMDEV_DISPLAY_DISABLED;
2666 if (origin)
2667 p->fDisplayFlags |= VMMDEV_DISPLAY_ORIGIN;
2668 if (primary)
2669 p->fDisplayFlags |= VMMDEV_DISPLAY_PRIMARY;
2670 }
2671
2672 bool const fForce = aScreenLayoutMode == ScreenLayoutMode_Reset
2673 || aScreenLayoutMode == ScreenLayoutMode_Apply;
2674 bool const fNotify = aScreenLayoutMode != ScreenLayoutMode_Silent;
2675 pVMMDevPort->pfnRequestDisplayChange(pVMMDevPort, cDisplays, paDisplayDefs, fForce, fNotify);
2676
2677 RTMemFree(paDisplayDefs);
2678 }
2679 }
2680 }
2681 return S_OK;
2682}
2683
2684HRESULT Display::detachScreens(const std::vector<LONG> &aScreenIds)
2685{
2686 NOREF(aScreenIds);
2687 return E_NOTIMPL;
2688}
2689
2690HRESULT Display::createGuestScreenInfo(ULONG aDisplay,
2691 GuestMonitorStatus_T aStatus,
2692 BOOL aPrimary,
2693 BOOL aChangeOrigin,
2694 LONG aOriginX,
2695 LONG aOriginY,
2696 ULONG aWidth,
2697 ULONG aHeight,
2698 ULONG aBitsPerPixel,
2699 ComPtr<IGuestScreenInfo> &aGuestScreenInfo)
2700{
2701 /* Create a new object. */
2702 ComObjPtr<GuestScreenInfo> obj;
2703 HRESULT hr = obj.createObject();
2704 if (SUCCEEDED(hr))
2705 hr = obj->init(aDisplay, aStatus, aPrimary, aChangeOrigin, aOriginX, aOriginY,
2706 aWidth, aHeight, aBitsPerPixel);
2707 if (SUCCEEDED(hr))
2708 obj.queryInterfaceTo(aGuestScreenInfo.asOutParam());
2709
2710 return hr;
2711}
2712
2713
2714/*
2715 * GuestScreenInfo implementation.
2716 */
2717DEFINE_EMPTY_CTOR_DTOR(GuestScreenInfo)
2718
2719HRESULT GuestScreenInfo::FinalConstruct()
2720{
2721 return BaseFinalConstruct();
2722}
2723
2724void GuestScreenInfo::FinalRelease()
2725{
2726 uninit();
2727
2728 BaseFinalRelease();
2729}
2730
2731HRESULT GuestScreenInfo::init(ULONG aDisplay,
2732 GuestMonitorStatus_T aGuestMonitorStatus,
2733 BOOL aPrimary,
2734 BOOL aChangeOrigin,
2735 LONG aOriginX,
2736 LONG aOriginY,
2737 ULONG aWidth,
2738 ULONG aHeight,
2739 ULONG aBitsPerPixel)
2740{
2741 LogFlowThisFunc(("[%u]\n", aDisplay));
2742
2743 /* Enclose the state transition NotReady->InInit->Ready */
2744 AutoInitSpan autoInitSpan(this);
2745 AssertReturn(autoInitSpan.isOk(), E_FAIL);
2746
2747 mScreenId = aDisplay;
2748 mGuestMonitorStatus = aGuestMonitorStatus;
2749 mPrimary = aPrimary;
2750 mOrigin = aChangeOrigin;
2751 mOriginX = aOriginX;
2752 mOriginY = aOriginY;
2753 mWidth = aWidth;
2754 mHeight = aHeight;
2755 mBitsPerPixel = aBitsPerPixel;
2756
2757 /* Confirm a successful initialization */
2758 autoInitSpan.setSucceeded();
2759
2760 return S_OK;
2761}
2762
2763void GuestScreenInfo::uninit()
2764{
2765 /* Enclose the state transition Ready->InUninit->NotReady */
2766 AutoUninitSpan autoUninitSpan(this);
2767 if (autoUninitSpan.uninitDone())
2768 return;
2769
2770 LogFlowThisFunc(("[%u]\n", mScreenId));
2771}
2772
2773HRESULT GuestScreenInfo::getScreenId(ULONG *aScreenId)
2774{
2775 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2776 *aScreenId = mScreenId;
2777 return S_OK;
2778}
2779
2780HRESULT GuestScreenInfo::getGuestMonitorStatus(GuestMonitorStatus_T *aGuestMonitorStatus)
2781{
2782 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2783 *aGuestMonitorStatus = mGuestMonitorStatus;
2784 return S_OK;
2785}
2786
2787HRESULT GuestScreenInfo::getPrimary(BOOL *aPrimary)
2788{
2789 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2790 *aPrimary = mPrimary;
2791 return S_OK;
2792}
2793
2794HRESULT GuestScreenInfo::getOrigin(BOOL *aOrigin)
2795{
2796 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2797 *aOrigin = mOrigin;
2798 return S_OK;
2799}
2800
2801HRESULT GuestScreenInfo::getOriginX(LONG *aOriginX)
2802{
2803 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2804 *aOriginX = mOriginX;
2805 return S_OK;
2806}
2807
2808HRESULT GuestScreenInfo::getOriginY(LONG *aOriginY)
2809{
2810 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2811 *aOriginY = mOriginY;
2812 return S_OK;
2813}
2814
2815HRESULT GuestScreenInfo::getWidth(ULONG *aWidth)
2816{
2817 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2818 *aWidth = mWidth;
2819 return S_OK;
2820}
2821
2822HRESULT GuestScreenInfo::getHeight(ULONG *aHeight)
2823{
2824 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2825 *aHeight = mHeight;
2826 return S_OK;
2827}
2828
2829HRESULT GuestScreenInfo::getBitsPerPixel(ULONG *aBitsPerPixel)
2830{
2831 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2832 *aBitsPerPixel = mBitsPerPixel;
2833 return S_OK;
2834}
2835
2836HRESULT GuestScreenInfo::getExtendedInfo(com::Utf8Str &aExtendedInfo)
2837{
2838 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2839 aExtendedInfo = com::Utf8Str();
2840 return S_OK;
2841}
2842
2843// wrapped IEventListener method
2844HRESULT Display::handleEvent(const ComPtr<IEvent> &aEvent)
2845{
2846 VBoxEventType_T aType = VBoxEventType_Invalid;
2847
2848 aEvent->COMGETTER(Type)(&aType);
2849 switch (aType)
2850 {
2851 case VBoxEventType_OnStateChanged:
2852 {
2853 ComPtr<IStateChangedEvent> scev = aEvent;
2854 Assert(scev);
2855 MachineState_T machineState;
2856 scev->COMGETTER(State)(&machineState);
2857 if ( machineState == MachineState_Running
2858 || machineState == MachineState_Teleporting
2859 || machineState == MachineState_LiveSnapshotting
2860 || machineState == MachineState_DeletingSnapshotOnline
2861 )
2862 {
2863 LogRelFlowFunc(("Machine is running.\n"));
2864
2865 }
2866 break;
2867 }
2868 default:
2869 AssertFailed();
2870 }
2871
2872 return S_OK;
2873}
2874
2875
2876// private methods
2877/////////////////////////////////////////////////////////////////////////////
2878
2879/**
2880 * Handle display resize event issued by the VGA device for the primary screen.
2881 *
2882 * @see PDMIDISPLAYCONNECTOR::pfnResize
2883 */
2884DECLCALLBACK(int) Display::i_displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface,
2885 uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy)
2886{
2887 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2888 Display *pThis = pDrv->pDisplay;
2889
2890 LogRelFlowFunc(("bpp %d, pvVRAM %p, cbLine %d, cx %d, cy %d\n",
2891 bpp, pvVRAM, cbLine, cx, cy));
2892
2893 bool f = ASMAtomicCmpXchgBool(&pThis->fVGAResizing, true, false);
2894 if (!f)
2895 {
2896 /* This is a result of recursive call when the source bitmap is being updated
2897 * during a VGA resize. Tell the VGA device to ignore the call.
2898 *
2899 * @todo It is a workaround, actually pfnUpdateDisplayAll must
2900 * fail on resize.
2901 */
2902 LogRel(("displayResizeCallback: already processing\n"));
2903 return VINF_VGA_RESIZE_IN_PROGRESS;
2904 }
2905
2906 int rc = pThis->i_handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, bpp, pvVRAM, cbLine, cx, cy, 0, 0, 0, true);
2907
2908 /* Restore the flag. */
2909 f = ASMAtomicCmpXchgBool(&pThis->fVGAResizing, false, true);
2910 AssertRelease(f);
2911
2912 return rc;
2913}
2914
2915/**
2916 * Handle display update.
2917 *
2918 * @see PDMIDISPLAYCONNECTOR::pfnUpdateRect
2919 */
2920DECLCALLBACK(void) Display::i_displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
2921 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
2922{
2923 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2924
2925#ifdef DEBUG_sunlover
2926 LogFlowFunc(("fVideoAccelEnabled = %d, %d,%d %dx%d\n",
2927 pDrv->pDisplay->mVideoAccelLegacy.fVideoAccelEnabled, x, y, cx, cy));
2928#endif /* DEBUG_sunlover */
2929
2930 /* This call does update regardless of VBVA status.
2931 * But in VBVA mode this is called only as result of
2932 * pfnUpdateDisplayAll in the VGA device.
2933 */
2934
2935 pDrv->pDisplay->i_handleDisplayUpdate(VBOX_VIDEO_PRIMARY_SCREEN, x, y, cx, cy);
2936}
2937
2938/**
2939 * Periodic display refresh callback.
2940 *
2941 * @see PDMIDISPLAYCONNECTOR::pfnRefresh
2942 * @thread EMT
2943 */
2944/*static*/ DECLCALLBACK(void) Display::i_displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface)
2945{
2946 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2947
2948#ifdef DEBUG_sunlover_2
2949 LogFlowFunc(("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
2950 pDrv->pDisplay->mfVideoAccelEnabled));
2951#endif /* DEBUG_sunlover_2 */
2952
2953 Display *pDisplay = pDrv->pDisplay;
2954 unsigned uScreenId;
2955
2956 int rc = pDisplay->i_videoAccelRefreshProcess(pDrv->pUpPort);
2957 if (rc != VINF_TRY_AGAIN) /* Means 'do nothing' here. */
2958 {
2959 if (rc == VWRN_INVALID_STATE)
2960 {
2961 /* No VBVA do a display update. */
2962 pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
2963 }
2964
2965 /* Inform the VRDP server that the current display update sequence is
2966 * completed. At this moment the framebuffer memory contains a definite
2967 * image, that is synchronized with the orders already sent to VRDP client.
2968 * The server can now process redraw requests from clients or initial
2969 * fullscreen updates for new clients.
2970 */
2971 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
2972 {
2973 Assert(pDisplay->mParent && pDisplay->mParent->i_consoleVRDPServer());
2974 pDisplay->mParent->i_consoleVRDPServer()->SendUpdate(uScreenId, NULL, 0);
2975 }
2976 }
2977
2978#ifdef VBOX_WITH_RECORDING
2979 AssertPtr(pDisplay->mParent);
2980 RecordingContext *pCtx = pDisplay->mParent->i_recordingGetContext();
2981
2982 if ( pCtx
2983 && pCtx->IsStarted()
2984 && pCtx->IsFeatureEnabled(RecordingFeature_Video))
2985 {
2986 do
2987 {
2988 /* If the recording context has reached the configured recording
2989 * limit, disable recording. */
2990 if (pCtx->IsLimitReached())
2991 {
2992 pDisplay->mParent->i_onRecordingChange(FALSE /* Disable */);
2993 break;
2994 }
2995
2996 uint64_t tsNowMs = RTTimeProgramMilliTS();
2997 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
2998 {
2999 if (!pDisplay->maRecordingEnabled[uScreenId])
3000 continue;
3001
3002 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3003 if (!pFBInfo->fDisabled)
3004 {
3005 ComPtr<IDisplaySourceBitmap> pSourceBitmap;
3006 int rc2 = RTCritSectEnter(&pDisplay->mVideoRecLock);
3007 if (RT_SUCCESS(rc2))
3008 {
3009 pSourceBitmap = pFBInfo->Recording.pSourceBitmap;
3010 RTCritSectLeave(&pDisplay->mVideoRecLock);
3011 }
3012
3013 if (!pSourceBitmap.isNull())
3014 {
3015 BYTE *pbAddress = NULL;
3016 ULONG ulWidth = 0;
3017 ULONG ulHeight = 0;
3018 ULONG ulBitsPerPixel = 0;
3019 ULONG ulBytesPerLine = 0;
3020 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
3021 HRESULT hr = pSourceBitmap->QueryBitmapInfo(&pbAddress,
3022 &ulWidth,
3023 &ulHeight,
3024 &ulBitsPerPixel,
3025 &ulBytesPerLine,
3026 &bitmapFormat);
3027 if (SUCCEEDED(hr) && pbAddress)
3028 rc = pCtx->SendVideoFrame(uScreenId, 0, 0, BitmapFormat_BGR,
3029 ulBitsPerPixel, ulBytesPerLine, ulWidth, ulHeight,
3030 pbAddress, tsNowMs);
3031 else
3032 rc = VERR_NOT_SUPPORTED;
3033
3034 pSourceBitmap.setNull();
3035 }
3036 else
3037 rc = VERR_NOT_SUPPORTED;
3038
3039 if (rc == VINF_TRY_AGAIN)
3040 break;
3041 }
3042 }
3043 } while (0);
3044 }
3045#endif /* VBOX_WITH_RECORDING */
3046
3047#ifdef DEBUG_sunlover_2
3048 LogFlowFunc(("leave\n"));
3049#endif /* DEBUG_sunlover_2 */
3050}
3051
3052/**
3053 * Reset notification
3054 *
3055 * @see PDMIDISPLAYCONNECTOR::pfnReset
3056 */
3057DECLCALLBACK(void) Display::i_displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface)
3058{
3059 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3060
3061 LogRelFlowFunc(("\n"));
3062
3063 /* Disable VBVA mode. */
3064 pDrv->pDisplay->VideoAccelEnableVGA(false, NULL);
3065}
3066
3067/**
3068 * LFBModeChange notification
3069 *
3070 * @see PDMIDISPLAYCONNECTOR::pfnLFBModeChange
3071 */
3072DECLCALLBACK(void) Display::i_displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled)
3073{
3074 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3075
3076 LogRelFlowFunc(("fEnabled=%d\n", fEnabled));
3077
3078 NOREF(fEnabled);
3079
3080 /* Disable VBVA mode in any case. The guest driver reenables VBVA mode if necessary. */
3081 pDrv->pDisplay->VideoAccelEnableVGA(false, NULL);
3082}
3083
3084/**
3085 * Adapter information change notification.
3086 *
3087 * @see PDMIDISPLAYCONNECTOR::pfnProcessAdapterData
3088 */
3089DECLCALLBACK(void) Display::i_displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM,
3090 uint32_t u32VRAMSize)
3091{
3092 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3093 pDrv->pDisplay->processAdapterData(pvVRAM, u32VRAMSize);
3094}
3095
3096/**
3097 * Display information change notification.
3098 *
3099 * @see PDMIDISPLAYCONNECTOR::pfnProcessDisplayData
3100 */
3101DECLCALLBACK(void) Display::i_displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface,
3102 void *pvVRAM, unsigned uScreenId)
3103{
3104 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3105 pDrv->pDisplay->processDisplayData(pvVRAM, uScreenId);
3106}
3107
3108#ifdef VBOX_WITH_VIDEOHWACCEL
3109
3110int Display::i_handleVHWACommandProcess(int enmCmd, bool fGuestCmd, VBOXVHWACMD RT_UNTRUSTED_VOLATILE_GUEST *pCommand)
3111{
3112 /* bugref:9691 Disable the legacy VHWA interface.
3113 * Keep the host commands enabled because they are needed when an old saved state is loaded.
3114 */
3115 if (fGuestCmd)
3116 return VERR_NOT_IMPLEMENTED;
3117
3118 unsigned id = (unsigned)pCommand->iDisplay;
3119 if (id >= mcMonitors)
3120 return VERR_INVALID_PARAMETER;
3121
3122 ComPtr<IFramebuffer> pFramebuffer;
3123 AutoReadLock arlock(this COMMA_LOCKVAL_SRC_POS);
3124 pFramebuffer = maFramebuffers[id].pFramebuffer;
3125 bool fVHWASupported = RT_BOOL(maFramebuffers[id].u32Caps & FramebufferCapabilities_VHWA);
3126 arlock.release();
3127
3128 if (pFramebuffer == NULL || !fVHWASupported)
3129 return VERR_NOT_IMPLEMENTED; /* Implementation is not available. */
3130
3131 HRESULT hr = pFramebuffer->ProcessVHWACommand((BYTE *)pCommand, enmCmd, fGuestCmd);
3132 if (hr == S_FALSE)
3133 return VINF_SUCCESS;
3134 if (SUCCEEDED(hr))
3135 return VINF_CALLBACK_RETURN;
3136 if (hr == E_ACCESSDENIED)
3137 return VERR_INVALID_STATE; /* notify we can not handle request atm */
3138 if (hr == E_NOTIMPL)
3139 return VERR_NOT_IMPLEMENTED;
3140 return VERR_GENERAL_FAILURE;
3141}
3142
3143DECLCALLBACK(int) Display::i_displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, int enmCmd, bool fGuestCmd,
3144 VBOXVHWACMD RT_UNTRUSTED_VOLATILE_GUEST *pCommand)
3145{
3146 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3147
3148 return pDrv->pDisplay->i_handleVHWACommandProcess(enmCmd, fGuestCmd, pCommand);
3149}
3150
3151#endif /* VBOX_WITH_VIDEOHWACCEL */
3152
3153int Display::i_handle3DNotifyProcess(VBOX3DNOTIFY *p3DNotify)
3154{
3155 unsigned const id = (unsigned)p3DNotify->iDisplay;
3156 if (id >= mcMonitors)
3157 return VERR_INVALID_PARAMETER;
3158
3159 ComPtr<IFramebuffer> pFramebuffer;
3160 AutoReadLock arlock(this COMMA_LOCKVAL_SRC_POS);
3161 pFramebuffer = maFramebuffers[id].pFramebuffer;
3162 arlock.release();
3163
3164 int rc = VINF_SUCCESS;
3165
3166 if (!pFramebuffer.isNull())
3167 {
3168 if (p3DNotify->enmNotification == VBOX3D_NOTIFY_TYPE_HW_OVERLAY_GET_ID)
3169 {
3170 LONG64 winId = 0;
3171 HRESULT hr = pFramebuffer->COMGETTER(WinId)(&winId);
3172 if (SUCCEEDED(hr))
3173 {
3174 *(uint64_t *)&p3DNotify->au8Data[0] = winId;
3175 }
3176 else
3177 rc = VERR_NOT_SUPPORTED;
3178 }
3179 else
3180 {
3181 com::SafeArray<BYTE> data;
3182 data.initFrom((BYTE *)&p3DNotify->au8Data[0], p3DNotify->cbData);
3183
3184 HRESULT hr = pFramebuffer->Notify3DEvent((ULONG)p3DNotify->enmNotification, ComSafeArrayAsInParam(data));
3185 if (FAILED(hr))
3186 rc = VERR_NOT_SUPPORTED;
3187 }
3188 }
3189 else
3190 rc = VERR_NOT_IMPLEMENTED;
3191
3192 return rc;
3193}
3194
3195DECLCALLBACK(int) Display::i_display3DNotifyProcess(PPDMIDISPLAYCONNECTOR pInterface,
3196 VBOX3DNOTIFY *p3DNotify)
3197{
3198 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3199 return pDrv->pDisplay->i_handle3DNotifyProcess(p3DNotify);
3200}
3201
3202HRESULT Display::notifyScaleFactorChange(ULONG aScreenId, ULONG aScaleFactorWMultiplied, ULONG aScaleFactorHMultiplied)
3203{
3204 RT_NOREF(aScreenId, aScaleFactorWMultiplied, aScaleFactorHMultiplied);
3205# if 0 /** @todo Thank you so very much from anyone using VMSVGA3d! */
3206 AssertMsgFailed(("Attempt to specify OpenGL content scale factor while 3D acceleration is disabled in VM config. Ignored.\n"));
3207# else
3208 /* Need an interface like this here (and the #ifdefs needs adjusting):
3209 PPDMIDISPLAYPORT pUpPort = mpDrv ? mpDrv->pUpPort : NULL;
3210 if (pUpPort && pUpPort->pfnSetScaleFactor)
3211 pUpPort->pfnSetScaleFactor(pUpPort, aScreeId, aScaleFactorWMultiplied, aScaleFactorHMultiplied); */
3212# endif
3213 return S_OK;
3214}
3215
3216HRESULT Display::notifyHiDPIOutputPolicyChange(BOOL fUnscaledHiDPI)
3217{
3218 RT_NOREF(fUnscaledHiDPI);
3219
3220 /* Need an interface like this here (and the #ifdefs needs adjusting):
3221 PPDMIDISPLAYPORT pUpPort = mpDrv ? mpDrv->pUpPort : NULL;
3222 if (pUpPort && pUpPort->pfnSetScaleFactor)
3223 pUpPort->pfnSetScaleFactor(pUpPort, aScreeId, aScaleFactorWMultiplied, aScaleFactorHMultiplied); */
3224
3225 return S_OK;
3226}
3227
3228#ifdef VBOX_WITH_HGSMI
3229/**
3230 * @interface_method_impl{PDMIDISPLAYCONNECTOR,pfnVBVAEnable}
3231 */
3232DECLCALLBACK(int) Display::i_displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId,
3233 VBVAHOSTFLAGS RT_UNTRUSTED_VOLATILE_GUEST *pHostFlags)
3234{
3235 LogRelFlowFunc(("uScreenId %d\n", uScreenId));
3236
3237 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3238 Display *pThis = pDrv->pDisplay;
3239 AssertReturn(uScreenId < pThis->mcMonitors, VERR_INVALID_PARAMETER);
3240
3241 if (pThis->maFramebuffers[uScreenId].fVBVAEnabled)
3242 {
3243 LogRel(("Enabling different vbva mode\n"));
3244#ifdef DEBUG_misha
3245 AssertMsgFailed(("enabling different vbva mode\n"));
3246#endif
3247 return VERR_INVALID_STATE;
3248 }
3249
3250 pThis->maFramebuffers[uScreenId].fVBVAEnabled = true;
3251 pThis->maFramebuffers[uScreenId].pVBVAHostFlags = pHostFlags;
3252 pThis->maFramebuffers[uScreenId].fVBVAForceResize = true;
3253
3254 vbvaSetMemoryFlagsHGSMI(uScreenId, pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, &pThis->maFramebuffers[uScreenId]);
3255
3256 return VINF_SUCCESS;
3257}
3258
3259/**
3260 * @interface_method_impl{PDMIDISPLAYCONNECTOR,pfnVBVADisable}
3261 */
3262DECLCALLBACK(void) Display::i_displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3263{
3264 LogRelFlowFunc(("uScreenId %d\n", uScreenId));
3265
3266 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3267 Display *pThis = pDrv->pDisplay;
3268 AssertReturnVoid(uScreenId < pThis->mcMonitors);
3269
3270 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3271
3272 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3273 {
3274 /* Make sure that the primary screen is visible now.
3275 * The guest can't use VBVA anymore, so only only the VGA device output works.
3276 */
3277 pFBInfo->flags = 0;
3278 if (pFBInfo->fDisabled)
3279 {
3280 pFBInfo->fDisabled = false;
3281 ::FireGuestMonitorChangedEvent(pThis->mParent->i_getEventSource(), GuestMonitorChangedEventType_Enabled, uScreenId,
3282 pFBInfo->xOrigin, pFBInfo->yOrigin, pFBInfo->w, pFBInfo->h);
3283 }
3284 }
3285
3286 pFBInfo->fVBVAEnabled = false;
3287 pFBInfo->fVBVAForceResize = false;
3288
3289 vbvaSetMemoryFlagsHGSMI(uScreenId, 0, false, pFBInfo);
3290
3291 pFBInfo->pVBVAHostFlags = NULL;
3292
3293 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3294 {
3295 /* Force full screen update, because VGA device must take control, do resize, etc. */
3296 pThis->mpDrv->pUpPort->pfnUpdateDisplayAll(pThis->mpDrv->pUpPort, /* fFailOnResize = */ false);
3297 }
3298}
3299
3300DECLCALLBACK(void) Display::i_displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3301{
3302 RT_NOREF(uScreenId);
3303 LogFlowFunc(("uScreenId %d\n", uScreenId));
3304
3305 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3306 Display *pThis = pDrv->pDisplay;
3307
3308 if (ASMAtomicReadU32(&pThis->mu32UpdateVBVAFlags) > 0)
3309 {
3310 vbvaSetMemoryFlagsAllHGSMI(pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, pThis->maFramebuffers,
3311 pThis->mcMonitors);
3312 ASMAtomicDecU32(&pThis->mu32UpdateVBVAFlags);
3313 }
3314}
3315
3316/**
3317 * @interface_method_impl{PDMIDISPLAYCONNECTOR,pfnVBVAUpdateProcess}
3318 */
3319DECLCALLBACK(void) Display::i_displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId,
3320 struct VBVACMDHDR const RT_UNTRUSTED_VOLATILE_GUEST *pCmd, size_t cbCmd)
3321{
3322 LogFlowFunc(("uScreenId %d pCmd %p cbCmd %d, @%d,%d %dx%d\n", uScreenId, pCmd, cbCmd, pCmd->x, pCmd->y, pCmd->w, pCmd->h));
3323 VBVACMDHDR hdrSaved;
3324 RT_COPY_VOLATILE(hdrSaved, *pCmd);
3325 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
3326
3327 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3328 Display *pThis = pDrv->pDisplay;
3329 DISPLAYFBINFO *pFBInfo;
3330 AssertReturnVoid(uScreenId < pThis->mcMonitors);
3331
3332 pFBInfo = &pThis->maFramebuffers[uScreenId];
3333
3334 if (pFBInfo->fDefaultFormat)
3335 {
3336 /* Make sure that framebuffer contains the same image as the guest VRAM. */
3337 if ( uScreenId == VBOX_VIDEO_PRIMARY_SCREEN
3338 && !pFBInfo->fDisabled)
3339 {
3340 pDrv->pUpPort->pfnUpdateDisplayRect(pDrv->pUpPort, hdrSaved.x, hdrSaved.y, hdrSaved.w, hdrSaved.h);
3341 }
3342 else if ( !pFBInfo->pSourceBitmap.isNull()
3343 && !pFBInfo->fDisabled)
3344 {
3345 /* Render VRAM content to the framebuffer. */
3346 BYTE *pAddress = NULL;
3347 ULONG ulWidth = 0;
3348 ULONG ulHeight = 0;
3349 ULONG ulBitsPerPixel = 0;
3350 ULONG ulBytesPerLine = 0;
3351 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
3352
3353 HRESULT hrc = pFBInfo->pSourceBitmap->QueryBitmapInfo(&pAddress,
3354 &ulWidth,
3355 &ulHeight,
3356 &ulBitsPerPixel,
3357 &ulBytesPerLine,
3358 &bitmapFormat);
3359 if (SUCCEEDED(hrc))
3360 {
3361 uint32_t width = hdrSaved.w;
3362 uint32_t height = hdrSaved.h;
3363
3364 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
3365 int32_t xSrc = hdrSaved.x - pFBInfo->xOrigin;
3366 int32_t ySrc = hdrSaved.y - pFBInfo->yOrigin;
3367 uint32_t u32SrcWidth = pFBInfo->w;
3368 uint32_t u32SrcHeight = pFBInfo->h;
3369 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
3370 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
3371
3372 uint8_t *pu8Dst = pAddress;
3373 int32_t xDst = xSrc;
3374 int32_t yDst = ySrc;
3375 uint32_t u32DstWidth = u32SrcWidth;
3376 uint32_t u32DstHeight = u32SrcHeight;
3377 uint32_t u32DstLineSize = u32DstWidth * 4;
3378 uint32_t u32DstBitsPerPixel = 32;
3379
3380 pDrv->pUpPort->pfnCopyRect(pDrv->pUpPort,
3381 width, height,
3382 pu8Src,
3383 xSrc, ySrc,
3384 u32SrcWidth, u32SrcHeight,
3385 u32SrcLineSize, u32SrcBitsPerPixel,
3386 pu8Dst,
3387 xDst, yDst,
3388 u32DstWidth, u32DstHeight,
3389 u32DstLineSize, u32DstBitsPerPixel);
3390 }
3391 }
3392 }
3393
3394 /*
3395 * Here is your classic 'temporary' solution.
3396 */
3397 /** @todo New SendUpdate entry which can get a separate cmd header or coords. */
3398 VBVACMDHDR *pHdrUnconst = (VBVACMDHDR *)pCmd;
3399
3400 pHdrUnconst->x -= (int16_t)pFBInfo->xOrigin;
3401 pHdrUnconst->y -= (int16_t)pFBInfo->yOrigin;
3402
3403 pThis->mParent->i_consoleVRDPServer()->SendUpdate(uScreenId, pHdrUnconst, (uint32_t)cbCmd);
3404
3405 *pHdrUnconst = hdrSaved;
3406}
3407
3408DECLCALLBACK(void) Display::i_displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y,
3409 uint32_t cx, uint32_t cy)
3410{
3411 LogFlowFunc(("uScreenId %d %d,%d %dx%d\n", uScreenId, x, y, cx, cy));
3412
3413 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3414 Display *pThis = pDrv->pDisplay;
3415 DISPLAYFBINFO *pFBInfo;
3416 AssertReturnVoid(uScreenId < pThis->mcMonitors);
3417
3418 pFBInfo = &pThis->maFramebuffers[uScreenId];
3419
3420 /** @todo handleFramebufferUpdate (uScreenId,
3421 * x - pThis->maFramebuffers[uScreenId].xOrigin,
3422 * y - pThis->maFramebuffers[uScreenId].yOrigin,
3423 * cx, cy);
3424 */
3425 pThis->i_handleDisplayUpdate(uScreenId, x - pFBInfo->xOrigin, y - pFBInfo->yOrigin, cx, cy);
3426}
3427
3428#ifdef DEBUG_sunlover
3429static void logVBVAResize(PCVBVAINFOVIEW pView, PCVBVAINFOSCREEN pScreen, const DISPLAYFBINFO *pFBInfo)
3430{
3431 LogRel(("displayVBVAResize: [%d] %s\n"
3432 " pView->u32ViewIndex %d\n"
3433 " pView->u32ViewOffset 0x%08X\n"
3434 " pView->u32ViewSize 0x%08X\n"
3435 " pView->u32MaxScreenSize 0x%08X\n"
3436 " pScreen->i32OriginX %d\n"
3437 " pScreen->i32OriginY %d\n"
3438 " pScreen->u32StartOffset 0x%08X\n"
3439 " pScreen->u32LineSize 0x%08X\n"
3440 " pScreen->u32Width %d\n"
3441 " pScreen->u32Height %d\n"
3442 " pScreen->u16BitsPerPixel %d\n"
3443 " pScreen->u16Flags 0x%04X\n"
3444 " pFBInfo->u32Offset 0x%08X\n"
3445 " pFBInfo->u32MaxFramebufferSize 0x%08X\n"
3446 " pFBInfo->u32InformationSize 0x%08X\n"
3447 " pFBInfo->fDisabled %d\n"
3448 " xOrigin, yOrigin, w, h: %d,%d %dx%d\n"
3449 " pFBInfo->u16BitsPerPixel %d\n"
3450 " pFBInfo->pu8FramebufferVRAM %p\n"
3451 " pFBInfo->u32LineSize 0x%08X\n"
3452 " pFBInfo->flags 0x%04X\n"
3453 " pFBInfo->pHostEvents %p\n"
3454 " pFBInfo->fDefaultFormat %d\n"
3455 " pFBInfo->fVBVAEnabled %d\n"
3456 " pFBInfo->fVBVAForceResize %d\n"
3457 " pFBInfo->pVBVAHostFlags %p\n"
3458 "",
3459 pScreen->u32ViewIndex,
3460 (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)? "DISABLED": "ENABLED",
3461 pView->u32ViewIndex,
3462 pView->u32ViewOffset,
3463 pView->u32ViewSize,
3464 pView->u32MaxScreenSize,
3465 pScreen->i32OriginX,
3466 pScreen->i32OriginY,
3467 pScreen->u32StartOffset,
3468 pScreen->u32LineSize,
3469 pScreen->u32Width,
3470 pScreen->u32Height,
3471 pScreen->u16BitsPerPixel,
3472 pScreen->u16Flags,
3473 pFBInfo->u32Offset,
3474 pFBInfo->u32MaxFramebufferSize,
3475 pFBInfo->u32InformationSize,
3476 pFBInfo->fDisabled,
3477 pFBInfo->xOrigin,
3478 pFBInfo->yOrigin,
3479 pFBInfo->w,
3480 pFBInfo->h,
3481 pFBInfo->u16BitsPerPixel,
3482 pFBInfo->pu8FramebufferVRAM,
3483 pFBInfo->u32LineSize,
3484 pFBInfo->flags,
3485 pFBInfo->pHostEvents,
3486 pFBInfo->fDefaultFormat,
3487 pFBInfo->fVBVAEnabled,
3488 pFBInfo->fVBVAForceResize,
3489 pFBInfo->pVBVAHostFlags
3490 ));
3491}
3492#endif /* DEBUG_sunlover */
3493
3494DECLCALLBACK(int) Display::i_displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, PCVBVAINFOVIEW pView,
3495 PCVBVAINFOSCREEN pScreen, void *pvVRAM, bool fResetInputMapping)
3496{
3497 LogRelFlowFunc(("pScreen %p, pvVRAM %p\n", pScreen, pvVRAM));
3498
3499 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3500 Display *pThis = pDrv->pDisplay;
3501
3502 return pThis->processVBVAResize(pView, pScreen, pvVRAM, fResetInputMapping);
3503}
3504
3505int Display::processVBVAResize(PCVBVAINFOVIEW pView, PCVBVAINFOSCREEN pScreen, void *pvVRAM, bool fResetInputMapping)
3506{
3507 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
3508
3509 RT_NOREF(pView);
3510
3511 DISPLAYFBINFO *pFBInfo = &maFramebuffers[pScreen->u32ViewIndex];
3512
3513#ifdef DEBUG_sunlover
3514 logVBVAResize(pView, pScreen, pFBInfo);
3515#endif
3516
3517 if (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)
3518 {
3519 /* Ask the framebuffer to resize using a default format. The framebuffer will be black.
3520 * So if the frontend does not support GuestMonitorChangedEventType_Disabled event,
3521 * the VM window will be black. */
3522 uint32_t u32Width = pFBInfo->w ? pFBInfo->w : 640;
3523 uint32_t u32Height = pFBInfo->h ? pFBInfo->h : 480;
3524 int32_t xOrigin = pFBInfo->xOrigin;
3525 int32_t yOrigin = pFBInfo->yOrigin;
3526
3527 alock.release();
3528
3529 i_handleDisplayResize(pScreen->u32ViewIndex, 0, (uint8_t *)NULL, 0,
3530 u32Width, u32Height, pScreen->u16Flags, xOrigin, yOrigin, false);
3531
3532 return VINF_SUCCESS;
3533 }
3534
3535 VBVAINFOSCREEN screenInfo;
3536 RT_ZERO(screenInfo);
3537
3538 if (pScreen->u16Flags & VBVA_SCREEN_F_BLANK2)
3539 {
3540 /* Init a local VBVAINFOSCREEN structure, which will be used instead of
3541 * the original pScreen. Set VBVA_SCREEN_F_BLANK, which will force
3542 * the code below to choose the "blanking" branches.
3543 */
3544 screenInfo.u32ViewIndex = pScreen->u32ViewIndex;
3545 screenInfo.i32OriginX = pFBInfo->xOrigin;
3546 screenInfo.i32OriginY = pFBInfo->yOrigin;
3547 screenInfo.u32StartOffset = 0; /* Irrelevant */
3548 screenInfo.u32LineSize = pFBInfo->u32LineSize;
3549 screenInfo.u32Width = pFBInfo->w;
3550 screenInfo.u32Height = pFBInfo->h;
3551 screenInfo.u16BitsPerPixel = pFBInfo->u16BitsPerPixel;
3552 screenInfo.u16Flags = pScreen->u16Flags | VBVA_SCREEN_F_BLANK;
3553
3554 pScreen = &screenInfo;
3555 }
3556
3557 if (fResetInputMapping)
3558 {
3559 /// @todo Rename to m* and verify whether some kind of lock is required.
3560 xInputMappingOrigin = 0;
3561 yInputMappingOrigin = 0;
3562 cxInputMapping = 0;
3563 cyInputMapping = 0;
3564 }
3565
3566 alock.release();
3567
3568 return i_handleDisplayResize(pScreen->u32ViewIndex, pScreen->u16BitsPerPixel,
3569 (uint8_t *)pvVRAM + pScreen->u32StartOffset,
3570 pScreen->u32LineSize, pScreen->u32Width, pScreen->u32Height, pScreen->u16Flags,
3571 pScreen->i32OriginX, pScreen->i32OriginY, false);
3572}
3573
3574DECLCALLBACK(int) Display::i_displayVBVAMousePointerShape(PPDMIDISPLAYCONNECTOR pInterface, bool fVisible, bool fAlpha,
3575 uint32_t xHot, uint32_t yHot,
3576 uint32_t cx, uint32_t cy,
3577 const void *pvShape)
3578{
3579 LogFlowFunc(("\n"));
3580 LogRel2(("%s: fVisible=%RTbool\n", __PRETTY_FUNCTION__, fVisible));
3581
3582 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3583
3584 uint32_t cbShape = 0;
3585 if (pvShape)
3586 {
3587 cbShape = (cx + 7) / 8 * cy; /* size of the AND mask */
3588 cbShape = ((cbShape + 3) & ~3) + cx * 4 * cy; /* + gap + size of the XOR mask */
3589 }
3590
3591 /* Tell the console about it */
3592 pDrv->pDisplay->mParent->i_onMousePointerShapeChange(fVisible, fAlpha,
3593 xHot, yHot, cx, cy, (uint8_t *)pvShape, cbShape);
3594
3595 return VINF_SUCCESS;
3596}
3597
3598DECLCALLBACK(void) Display::i_displayVBVAGuestCapabilityUpdate(PPDMIDISPLAYCONNECTOR pInterface, uint32_t fCapabilities)
3599{
3600 LogFlowFunc(("\n"));
3601
3602 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3603 Display *pThis = pDrv->pDisplay;
3604
3605 pThis->i_handleUpdateGuestVBVACapabilities(fCapabilities);
3606}
3607
3608DECLCALLBACK(void) Display::i_displayVBVAInputMappingUpdate(PPDMIDISPLAYCONNECTOR pInterface, int32_t xOrigin, int32_t yOrigin,
3609 uint32_t cx, uint32_t cy)
3610{
3611 LogFlowFunc(("\n"));
3612
3613 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3614 Display *pThis = pDrv->pDisplay;
3615
3616 pThis->i_handleUpdateVBVAInputMapping(xOrigin, yOrigin, cx, cy);
3617}
3618
3619DECLCALLBACK(void) Display::i_displayVBVAReportCursorPosition(PPDMIDISPLAYCONNECTOR pInterface, uint32_t fFlags, uint32_t aScreenId, uint32_t x, uint32_t y)
3620{
3621 LogFlowFunc(("\n"));
3622 LogRel2(("%s: fFlags=%RU32, aScreenId=%RU32, x=%RU32, y=%RU32\n",
3623 __PRETTY_FUNCTION__, fFlags, aScreenId, x, y));
3624
3625 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3626 Display *pThis = pDrv->pDisplay;
3627
3628 if (fFlags & VBVA_CURSOR_SCREEN_RELATIVE)
3629 {
3630 AssertReturnVoid(aScreenId < pThis->mcMonitors);
3631
3632 x += pThis->maFramebuffers[aScreenId].xOrigin;
3633 y += pThis->maFramebuffers[aScreenId].yOrigin;
3634 }
3635 ::FireCursorPositionChangedEvent(pThis->mParent->i_getEventSource(), RT_BOOL(fFlags & VBVA_CURSOR_VALID_DATA), x, y);
3636}
3637
3638#endif /* VBOX_WITH_HGSMI */
3639
3640/**
3641 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
3642 */
3643DECLCALLBACK(void *) Display::i_drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
3644{
3645 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
3646 PDRVMAINDISPLAY pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3647 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
3648 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIDISPLAYCONNECTOR, &pDrv->IConnector);
3649 return NULL;
3650}
3651
3652
3653/**
3654 * @interface_method_impl{PDMDRVREG,pfnPowerOff,
3655 * Tries to ensure no client calls gets to HGCM or the VGA device from here on.}
3656 */
3657DECLCALLBACK(void) Display::i_drvPowerOff(PPDMDRVINS pDrvIns)
3658{
3659 PDRVMAINDISPLAY pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3660 LogRelFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
3661
3662 /*
3663 * Do much of the work that i_drvDestruct does.
3664 */
3665 if (pThis->pUpPort)
3666 pThis->pUpPort->pfnSetRenderVRAM(pThis->pUpPort, false);
3667
3668 pThis->IConnector.pbData = NULL;
3669 pThis->IConnector.cbScanline = 0;
3670 pThis->IConnector.cBits = 32;
3671 pThis->IConnector.cx = 0;
3672 pThis->IConnector.cy = 0;
3673
3674 if (pThis->pDisplay)
3675 {
3676 AutoWriteLock displayLock(pThis->pDisplay COMMA_LOCKVAL_SRC_POS);
3677#ifdef VBOX_WITH_RECORDING
3678 pThis->pDisplay->mParent->i_recordingStop();
3679#endif
3680#if defined(VBOX_WITH_VIDEOHWACCEL)
3681 pThis->pVBVACallbacks = NULL;
3682#endif
3683 }
3684}
3685
3686
3687/**
3688 * Destruct a display driver instance.
3689 *
3690 * @returns VBox status code.
3691 * @param pDrvIns The driver instance data.
3692 */
3693DECLCALLBACK(void) Display::i_drvDestruct(PPDMDRVINS pDrvIns)
3694{
3695 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
3696 PDRVMAINDISPLAY pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3697 LogRelFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
3698
3699 /*
3700 * We repeat much of what i_drvPowerOff does in case it wasn't called.
3701 * In addition we sever the connection between us and the display.
3702 */
3703 if (pThis->pUpPort)
3704 pThis->pUpPort->pfnSetRenderVRAM(pThis->pUpPort, false);
3705
3706 pThis->IConnector.pbData = NULL;
3707 pThis->IConnector.cbScanline = 0;
3708 pThis->IConnector.cBits = 32;
3709 pThis->IConnector.cx = 0;
3710 pThis->IConnector.cy = 0;
3711
3712 if (pThis->pDisplay)
3713 {
3714 AutoWriteLock displayLock(pThis->pDisplay COMMA_LOCKVAL_SRC_POS);
3715#ifdef VBOX_WITH_RECORDING
3716 pThis->pDisplay->mParent->i_recordingStop();
3717#endif
3718#if defined(VBOX_WITH_VIDEOHWACCEL)
3719 pThis->pVBVACallbacks = NULL;
3720#endif
3721
3722 pThis->pDisplay->mpDrv = NULL;
3723 pThis->pDisplay = NULL;
3724 }
3725#if defined(VBOX_WITH_VIDEOHWACCEL)
3726 pThis->pVBVACallbacks = NULL;
3727#endif
3728}
3729
3730
3731/**
3732 * Construct a display driver instance.
3733 *
3734 * @copydoc FNPDMDRVCONSTRUCT
3735 */
3736DECLCALLBACK(int) Display::i_drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
3737{
3738 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
3739 RT_NOREF(fFlags, pCfg);
3740 PDRVMAINDISPLAY pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3741 LogRelFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
3742
3743 /*
3744 * Validate configuration.
3745 */
3746 PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "", "");
3747 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
3748 ("Configuration error: Not possible to attach anything to this driver!\n"),
3749 VERR_PDM_DRVINS_NO_ATTACH);
3750
3751 /*
3752 * Init Interfaces.
3753 */
3754 pDrvIns->IBase.pfnQueryInterface = Display::i_drvQueryInterface;
3755
3756 pThis->IConnector.pfnResize = Display::i_displayResizeCallback;
3757 pThis->IConnector.pfnUpdateRect = Display::i_displayUpdateCallback;
3758 pThis->IConnector.pfnRefresh = Display::i_displayRefreshCallback;
3759 pThis->IConnector.pfnReset = Display::i_displayResetCallback;
3760 pThis->IConnector.pfnLFBModeChange = Display::i_displayLFBModeChangeCallback;
3761 pThis->IConnector.pfnProcessAdapterData = Display::i_displayProcessAdapterDataCallback;
3762 pThis->IConnector.pfnProcessDisplayData = Display::i_displayProcessDisplayDataCallback;
3763#ifdef VBOX_WITH_VIDEOHWACCEL
3764 pThis->IConnector.pfnVHWACommandProcess = Display::i_displayVHWACommandProcess;
3765#endif
3766#ifdef VBOX_WITH_HGSMI
3767 pThis->IConnector.pfnVBVAEnable = Display::i_displayVBVAEnable;
3768 pThis->IConnector.pfnVBVADisable = Display::i_displayVBVADisable;
3769 pThis->IConnector.pfnVBVAUpdateBegin = Display::i_displayVBVAUpdateBegin;
3770 pThis->IConnector.pfnVBVAUpdateProcess = Display::i_displayVBVAUpdateProcess;
3771 pThis->IConnector.pfnVBVAUpdateEnd = Display::i_displayVBVAUpdateEnd;
3772 pThis->IConnector.pfnVBVAResize = Display::i_displayVBVAResize;
3773 pThis->IConnector.pfnVBVAMousePointerShape = Display::i_displayVBVAMousePointerShape;
3774 pThis->IConnector.pfnVBVAGuestCapabilityUpdate = Display::i_displayVBVAGuestCapabilityUpdate;
3775 pThis->IConnector.pfnVBVAInputMappingUpdate = Display::i_displayVBVAInputMappingUpdate;
3776 pThis->IConnector.pfnVBVAReportCursorPosition = Display::i_displayVBVAReportCursorPosition;
3777#endif
3778 pThis->IConnector.pfn3DNotifyProcess = Display::i_display3DNotifyProcess;
3779
3780 /*
3781 * Get the IDisplayPort interface of the above driver/device.
3782 */
3783 pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYPORT);
3784 if (!pThis->pUpPort)
3785 {
3786 AssertMsgFailed(("Configuration error: No display port interface above!\n"));
3787 return VERR_PDM_MISSING_INTERFACE_ABOVE;
3788 }
3789#if defined(VBOX_WITH_VIDEOHWACCEL)
3790 pThis->pVBVACallbacks = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYVBVACALLBACKS);
3791 if (!pThis->pVBVACallbacks)
3792 {
3793 AssertMsgFailed(("Configuration error: No VBVA callback interface above!\n"));
3794 return VERR_PDM_MISSING_INTERFACE_ABOVE;
3795 }
3796#endif
3797 /*
3798 * Get the Display object pointer and update the mpDrv member.
3799 */
3800 com::Guid uuid(COM_IIDOF(IDisplay));
3801 IDisplay *pIDisplay = (IDisplay *)PDMDrvHlpQueryGenericUserObject(pDrvIns, uuid.raw());
3802 if (!pIDisplay)
3803 {
3804 AssertMsgFailed(("Configuration error: No/bad Keyboard object!\n"));
3805 return VERR_NOT_FOUND;
3806 }
3807 pThis->pDisplay = static_cast<Display *>(pIDisplay);
3808 pThis->pDisplay->mpDrv = pThis;
3809
3810 /* Disable VRAM to a buffer copy initially. */
3811 pThis->pUpPort->pfnSetRenderVRAM(pThis->pUpPort, false);
3812 pThis->IConnector.cBits = 32; /* DevVGA does nothing otherwise. */
3813
3814 /*
3815 * Start periodic screen refreshes
3816 */
3817 pThis->pUpPort->pfnSetRefreshRate(pThis->pUpPort, 20);
3818
3819 return VINF_SUCCESS;
3820}
3821
3822
3823/**
3824 * Display driver registration record.
3825 */
3826const PDMDRVREG Display::DrvReg =
3827{
3828 /* u32Version */
3829 PDM_DRVREG_VERSION,
3830 /* szName */
3831 "MainDisplay",
3832 /* szRCMod */
3833 "",
3834 /* szR0Mod */
3835 "",
3836 /* pszDescription */
3837 "Main display driver (Main as in the API).",
3838 /* fFlags */
3839 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
3840 /* fClass. */
3841 PDM_DRVREG_CLASS_DISPLAY,
3842 /* cMaxInstances */
3843 ~0U,
3844 /* cbInstance */
3845 sizeof(DRVMAINDISPLAY),
3846 /* pfnConstruct */
3847 Display::i_drvConstruct,
3848 /* pfnDestruct */
3849 Display::i_drvDestruct,
3850 /* pfnRelocate */
3851 NULL,
3852 /* pfnIOCtl */
3853 NULL,
3854 /* pfnPowerOn */
3855 NULL,
3856 /* pfnReset */
3857 NULL,
3858 /* pfnSuspend */
3859 NULL,
3860 /* pfnResume */
3861 NULL,
3862 /* pfnAttach */
3863 NULL,
3864 /* pfnDetach */
3865 NULL,
3866 /* pfnPowerOff */
3867 Display::i_drvPowerOff,
3868 /* pfnSoftReset */
3869 NULL,
3870 /* u32EndVersion */
3871 PDM_DRVREG_VERSION
3872};
3873
3874/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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