VirtualBox

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

Last change on this file was 99912, checked in by vboxsync, 12 months ago

Main/DisplayImpl: Don't fail if the graphics adapter doesn't provide a VBVA interace (like the dumb RAM based framebuffer), bugref:10431

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

© 2023 Oracle
ContactPrivacy policyTerms of Use