VirtualBox

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

Last change on this file since 98273 was 98262, checked in by vboxsync, 23 months ago

Main: rc() -> hrc()/vrc(). bugref:10223

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 133.6 KB
Line 
1/* $Id: DisplayImpl.cpp 98262 2023-01-24 01:42:14Z 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 rc, 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 mpDrv->pVBVACallbacks->pfnVHWACommandCompleteAsync(mpDrv->pVBVACallbacks, (VBOXVHWACMD RT_UNTRUSTED_VOLATILE_GUEST *)aCommand);
2464 return S_OK;
2465#else
2466 RT_NOREF(aCommand);
2467 return E_NOTIMPL;
2468#endif
2469}
2470
2471HRESULT Display::viewportChanged(ULONG aScreenId, ULONG aX, ULONG aY, ULONG aWidth, ULONG aHeight)
2472{
2473 AssertMsgReturn(aScreenId < mcMonitors, ("aScreendId=%d mcMonitors=%d\n", aScreenId, mcMonitors), E_INVALIDARG);
2474
2475 /* The driver might not have been constructed yet */
2476 if (mpDrv && mpDrv->pUpPort->pfnSetViewport)
2477 mpDrv->pUpPort->pfnSetViewport(mpDrv->pUpPort, aScreenId, aX, aY, aWidth, aHeight);
2478
2479 return S_OK;
2480}
2481
2482HRESULT Display::querySourceBitmap(ULONG aScreenId,
2483 ComPtr<IDisplaySourceBitmap> &aDisplaySourceBitmap)
2484{
2485 LogRelFlowFunc(("aScreenId = %d\n", aScreenId));
2486
2487 Console::SafeVMPtr ptrVM(mParent);
2488 if (!ptrVM.isOk())
2489 return ptrVM.hrc();
2490
2491 CHECK_CONSOLE_DRV(mpDrv);
2492
2493 bool fSetRenderVRAM = false;
2494 bool fInvalidate = false;
2495
2496 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2497
2498 if (aScreenId >= mcMonitors)
2499 return setError(E_INVALIDARG, tr("QuerySourceBitmap: Invalid screen %d (total %d)"), aScreenId, mcMonitors);
2500
2501 if (!mfSourceBitmapEnabled)
2502 {
2503 aDisplaySourceBitmap = NULL;
2504 return E_FAIL;
2505 }
2506
2507 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
2508
2509 /* No source bitmap for a blank guest screen. */
2510 if (pFBInfo->flags & VBVA_SCREEN_F_BLANK)
2511 {
2512 aDisplaySourceBitmap = NULL;
2513 return E_FAIL;
2514 }
2515
2516 HRESULT hr = S_OK;
2517
2518 if (pFBInfo->pSourceBitmap.isNull())
2519 {
2520 /* Create a new object. */
2521 ComObjPtr<DisplaySourceBitmap> obj;
2522 hr = obj.createObject();
2523 if (SUCCEEDED(hr))
2524 hr = obj->init(this, aScreenId, pFBInfo);
2525
2526 if (SUCCEEDED(hr))
2527 {
2528 pFBInfo->pSourceBitmap = obj;
2529 pFBInfo->fDefaultFormat = !obj->i_usesVRAM();
2530
2531 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2532 {
2533 /* Start buffer updates. */
2534 BYTE *pAddress = NULL;
2535 ULONG ulWidth = 0;
2536 ULONG ulHeight = 0;
2537 ULONG ulBitsPerPixel = 0;
2538 ULONG ulBytesPerLine = 0;
2539 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
2540
2541 pFBInfo->pSourceBitmap->QueryBitmapInfo(&pAddress,
2542 &ulWidth,
2543 &ulHeight,
2544 &ulBitsPerPixel,
2545 &ulBytesPerLine,
2546 &bitmapFormat);
2547
2548 mpDrv->IConnector.pbData = pAddress;
2549 mpDrv->IConnector.cbScanline = ulBytesPerLine;
2550 mpDrv->IConnector.cBits = ulBitsPerPixel;
2551 mpDrv->IConnector.cx = ulWidth;
2552 mpDrv->IConnector.cy = ulHeight;
2553
2554 fSetRenderVRAM = pFBInfo->fDefaultFormat;
2555 }
2556
2557 /* Make sure that the bitmap contains the latest image. */
2558 fInvalidate = pFBInfo->fDefaultFormat;
2559 }
2560 }
2561
2562 if (SUCCEEDED(hr))
2563 {
2564 pFBInfo->pSourceBitmap.queryInterfaceTo(aDisplaySourceBitmap.asOutParam());
2565 }
2566
2567 /* Leave the IDisplay lock because the VGA device must not be called under it. */
2568 alock.release();
2569
2570 if (SUCCEEDED(hr))
2571 {
2572 if (fSetRenderVRAM)
2573 mpDrv->pUpPort->pfnSetRenderVRAM(mpDrv->pUpPort, true);
2574
2575 if (fInvalidate)
2576#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. */
2577 Display::i_InvalidateAndUpdateEMT(this, aScreenId, false /*fUpdateAll*/);
2578#else
2579 VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::i_InvalidateAndUpdateEMT,
2580 3, this, aScreenId, false);
2581#endif
2582 }
2583
2584 LogRelFlowFunc(("%Rhrc\n", hr));
2585 return hr;
2586}
2587
2588HRESULT Display::getGuestScreenLayout(std::vector<ComPtr<IGuestScreenInfo> > &aGuestScreenLayout)
2589{
2590 NOREF(aGuestScreenLayout);
2591 return E_NOTIMPL;
2592}
2593
2594HRESULT Display::setScreenLayout(ScreenLayoutMode_T aScreenLayoutMode,
2595 const std::vector<ComPtr<IGuestScreenInfo> > &aGuestScreenInfo)
2596{
2597 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2598
2599 if (aGuestScreenInfo.size() != mcMonitors)
2600 return E_INVALIDARG;
2601
2602 CHECK_CONSOLE_DRV(mpDrv);
2603
2604 /*
2605 * It is up to the guest to decide whether the hint is
2606 * valid. Therefore don't do any VRAM sanity checks here.
2607 */
2608
2609 /* Have to release the lock because the pfnRequestDisplayChange
2610 * will call EMT. */
2611 alock.release();
2612
2613 VMMDev *pVMMDev = mParent->i_getVMMDev();
2614 if (pVMMDev)
2615 {
2616 PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
2617 if (pVMMDevPort)
2618 {
2619 uint32_t const cDisplays = (uint32_t)aGuestScreenInfo.size();
2620
2621 size_t const cbAlloc = cDisplays * sizeof(VMMDevDisplayDef);
2622 VMMDevDisplayDef *paDisplayDefs = (VMMDevDisplayDef *)RTMemAlloc(cbAlloc);
2623 if (paDisplayDefs)
2624 {
2625 for (uint32_t i = 0; i < cDisplays; ++i)
2626 {
2627 VMMDevDisplayDef *p = &paDisplayDefs[i];
2628 ComPtr<IGuestScreenInfo> pScreenInfo = aGuestScreenInfo[i];
2629
2630 ULONG screenId = 0;
2631 GuestMonitorStatus_T guestMonitorStatus = GuestMonitorStatus_Enabled;
2632 BOOL origin = FALSE;
2633 BOOL primary = FALSE;
2634 LONG originX = 0;
2635 LONG originY = 0;
2636 ULONG width = 0;
2637 ULONG height = 0;
2638 ULONG bitsPerPixel = 0;
2639
2640 pScreenInfo->COMGETTER(ScreenId) (&screenId);
2641 pScreenInfo->COMGETTER(GuestMonitorStatus)(&guestMonitorStatus);
2642 pScreenInfo->COMGETTER(Primary) (&primary);
2643 pScreenInfo->COMGETTER(Origin) (&origin);
2644 pScreenInfo->COMGETTER(OriginX) (&originX);
2645 pScreenInfo->COMGETTER(OriginY) (&originY);
2646 pScreenInfo->COMGETTER(Width) (&width);
2647 pScreenInfo->COMGETTER(Height) (&height);
2648 pScreenInfo->COMGETTER(BitsPerPixel)(&bitsPerPixel);
2649
2650 LogFlowFunc(("%d %d,%d %dx%d\n", screenId, originX, originY, width, height));
2651
2652 p->idDisplay = screenId;
2653 p->xOrigin = originX;
2654 p->yOrigin = originY;
2655 p->cx = width;
2656 p->cy = height;
2657 p->cBitsPerPixel = bitsPerPixel;
2658 p->fDisplayFlags = VMMDEV_DISPLAY_CX | VMMDEV_DISPLAY_CY | VMMDEV_DISPLAY_BPP;
2659 if (guestMonitorStatus == GuestMonitorStatus_Disabled)
2660 p->fDisplayFlags |= VMMDEV_DISPLAY_DISABLED;
2661 if (origin)
2662 p->fDisplayFlags |= VMMDEV_DISPLAY_ORIGIN;
2663 if (primary)
2664 p->fDisplayFlags |= VMMDEV_DISPLAY_PRIMARY;
2665 }
2666
2667 bool const fForce = aScreenLayoutMode == ScreenLayoutMode_Reset
2668 || aScreenLayoutMode == ScreenLayoutMode_Apply;
2669 bool const fNotify = aScreenLayoutMode != ScreenLayoutMode_Silent;
2670 pVMMDevPort->pfnRequestDisplayChange(pVMMDevPort, cDisplays, paDisplayDefs, fForce, fNotify);
2671
2672 RTMemFree(paDisplayDefs);
2673 }
2674 }
2675 }
2676 return S_OK;
2677}
2678
2679HRESULT Display::detachScreens(const std::vector<LONG> &aScreenIds)
2680{
2681 NOREF(aScreenIds);
2682 return E_NOTIMPL;
2683}
2684
2685HRESULT Display::createGuestScreenInfo(ULONG aDisplay,
2686 GuestMonitorStatus_T aStatus,
2687 BOOL aPrimary,
2688 BOOL aChangeOrigin,
2689 LONG aOriginX,
2690 LONG aOriginY,
2691 ULONG aWidth,
2692 ULONG aHeight,
2693 ULONG aBitsPerPixel,
2694 ComPtr<IGuestScreenInfo> &aGuestScreenInfo)
2695{
2696 /* Create a new object. */
2697 ComObjPtr<GuestScreenInfo> obj;
2698 HRESULT hr = obj.createObject();
2699 if (SUCCEEDED(hr))
2700 hr = obj->init(aDisplay, aStatus, aPrimary, aChangeOrigin, aOriginX, aOriginY,
2701 aWidth, aHeight, aBitsPerPixel);
2702 if (SUCCEEDED(hr))
2703 obj.queryInterfaceTo(aGuestScreenInfo.asOutParam());
2704
2705 return hr;
2706}
2707
2708
2709/*
2710 * GuestScreenInfo implementation.
2711 */
2712DEFINE_EMPTY_CTOR_DTOR(GuestScreenInfo)
2713
2714HRESULT GuestScreenInfo::FinalConstruct()
2715{
2716 return BaseFinalConstruct();
2717}
2718
2719void GuestScreenInfo::FinalRelease()
2720{
2721 uninit();
2722
2723 BaseFinalRelease();
2724}
2725
2726HRESULT GuestScreenInfo::init(ULONG aDisplay,
2727 GuestMonitorStatus_T aGuestMonitorStatus,
2728 BOOL aPrimary,
2729 BOOL aChangeOrigin,
2730 LONG aOriginX,
2731 LONG aOriginY,
2732 ULONG aWidth,
2733 ULONG aHeight,
2734 ULONG aBitsPerPixel)
2735{
2736 LogFlowThisFunc(("[%u]\n", aDisplay));
2737
2738 /* Enclose the state transition NotReady->InInit->Ready */
2739 AutoInitSpan autoInitSpan(this);
2740 AssertReturn(autoInitSpan.isOk(), E_FAIL);
2741
2742 mScreenId = aDisplay;
2743 mGuestMonitorStatus = aGuestMonitorStatus;
2744 mPrimary = aPrimary;
2745 mOrigin = aChangeOrigin;
2746 mOriginX = aOriginX;
2747 mOriginY = aOriginY;
2748 mWidth = aWidth;
2749 mHeight = aHeight;
2750 mBitsPerPixel = aBitsPerPixel;
2751
2752 /* Confirm a successful initialization */
2753 autoInitSpan.setSucceeded();
2754
2755 return S_OK;
2756}
2757
2758void GuestScreenInfo::uninit()
2759{
2760 /* Enclose the state transition Ready->InUninit->NotReady */
2761 AutoUninitSpan autoUninitSpan(this);
2762 if (autoUninitSpan.uninitDone())
2763 return;
2764
2765 LogFlowThisFunc(("[%u]\n", mScreenId));
2766}
2767
2768HRESULT GuestScreenInfo::getScreenId(ULONG *aScreenId)
2769{
2770 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2771 *aScreenId = mScreenId;
2772 return S_OK;
2773}
2774
2775HRESULT GuestScreenInfo::getGuestMonitorStatus(GuestMonitorStatus_T *aGuestMonitorStatus)
2776{
2777 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2778 *aGuestMonitorStatus = mGuestMonitorStatus;
2779 return S_OK;
2780}
2781
2782HRESULT GuestScreenInfo::getPrimary(BOOL *aPrimary)
2783{
2784 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2785 *aPrimary = mPrimary;
2786 return S_OK;
2787}
2788
2789HRESULT GuestScreenInfo::getOrigin(BOOL *aOrigin)
2790{
2791 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2792 *aOrigin = mOrigin;
2793 return S_OK;
2794}
2795
2796HRESULT GuestScreenInfo::getOriginX(LONG *aOriginX)
2797{
2798 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2799 *aOriginX = mOriginX;
2800 return S_OK;
2801}
2802
2803HRESULT GuestScreenInfo::getOriginY(LONG *aOriginY)
2804{
2805 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2806 *aOriginY = mOriginY;
2807 return S_OK;
2808}
2809
2810HRESULT GuestScreenInfo::getWidth(ULONG *aWidth)
2811{
2812 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2813 *aWidth = mWidth;
2814 return S_OK;
2815}
2816
2817HRESULT GuestScreenInfo::getHeight(ULONG *aHeight)
2818{
2819 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2820 *aHeight = mHeight;
2821 return S_OK;
2822}
2823
2824HRESULT GuestScreenInfo::getBitsPerPixel(ULONG *aBitsPerPixel)
2825{
2826 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2827 *aBitsPerPixel = mBitsPerPixel;
2828 return S_OK;
2829}
2830
2831HRESULT GuestScreenInfo::getExtendedInfo(com::Utf8Str &aExtendedInfo)
2832{
2833 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
2834 aExtendedInfo = com::Utf8Str();
2835 return S_OK;
2836}
2837
2838// wrapped IEventListener method
2839HRESULT Display::handleEvent(const ComPtr<IEvent> &aEvent)
2840{
2841 VBoxEventType_T aType = VBoxEventType_Invalid;
2842
2843 aEvent->COMGETTER(Type)(&aType);
2844 switch (aType)
2845 {
2846 case VBoxEventType_OnStateChanged:
2847 {
2848 ComPtr<IStateChangedEvent> scev = aEvent;
2849 Assert(scev);
2850 MachineState_T machineState;
2851 scev->COMGETTER(State)(&machineState);
2852 if ( machineState == MachineState_Running
2853 || machineState == MachineState_Teleporting
2854 || machineState == MachineState_LiveSnapshotting
2855 || machineState == MachineState_DeletingSnapshotOnline
2856 )
2857 {
2858 LogRelFlowFunc(("Machine is running.\n"));
2859
2860 }
2861 break;
2862 }
2863 default:
2864 AssertFailed();
2865 }
2866
2867 return S_OK;
2868}
2869
2870
2871// private methods
2872/////////////////////////////////////////////////////////////////////////////
2873
2874/**
2875 * Handle display resize event issued by the VGA device for the primary screen.
2876 *
2877 * @see PDMIDISPLAYCONNECTOR::pfnResize
2878 */
2879DECLCALLBACK(int) Display::i_displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface,
2880 uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy)
2881{
2882 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2883 Display *pThis = pDrv->pDisplay;
2884
2885 LogRelFlowFunc(("bpp %d, pvVRAM %p, cbLine %d, cx %d, cy %d\n",
2886 bpp, pvVRAM, cbLine, cx, cy));
2887
2888 bool f = ASMAtomicCmpXchgBool(&pThis->fVGAResizing, true, false);
2889 if (!f)
2890 {
2891 /* This is a result of recursive call when the source bitmap is being updated
2892 * during a VGA resize. Tell the VGA device to ignore the call.
2893 *
2894 * @todo It is a workaround, actually pfnUpdateDisplayAll must
2895 * fail on resize.
2896 */
2897 LogRel(("displayResizeCallback: already processing\n"));
2898 return VINF_VGA_RESIZE_IN_PROGRESS;
2899 }
2900
2901 int vrc = pThis->i_handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, bpp, pvVRAM, cbLine, cx, cy, 0, 0, 0, true);
2902
2903 /* Restore the flag. */
2904 f = ASMAtomicCmpXchgBool(&pThis->fVGAResizing, false, true);
2905 AssertRelease(f);
2906
2907 return vrc;
2908}
2909
2910/**
2911 * Handle display update.
2912 *
2913 * @see PDMIDISPLAYCONNECTOR::pfnUpdateRect
2914 */
2915DECLCALLBACK(void) Display::i_displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
2916 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
2917{
2918 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2919
2920#ifdef DEBUG_sunlover
2921 LogFlowFunc(("fVideoAccelEnabled = %d, %d,%d %dx%d\n",
2922 pDrv->pDisplay->mVideoAccelLegacy.fVideoAccelEnabled, x, y, cx, cy));
2923#endif /* DEBUG_sunlover */
2924
2925 /* This call does update regardless of VBVA status.
2926 * But in VBVA mode this is called only as result of
2927 * pfnUpdateDisplayAll in the VGA device.
2928 */
2929
2930 pDrv->pDisplay->i_handleDisplayUpdate(VBOX_VIDEO_PRIMARY_SCREEN, x, y, cx, cy);
2931}
2932
2933/**
2934 * Periodic display refresh callback.
2935 *
2936 * @see PDMIDISPLAYCONNECTOR::pfnRefresh
2937 * @thread EMT
2938 */
2939/*static*/ DECLCALLBACK(void) Display::i_displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface)
2940{
2941 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2942
2943#ifdef DEBUG_sunlover_2
2944 LogFlowFunc(("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
2945 pDrv->pDisplay->mfVideoAccelEnabled));
2946#endif /* DEBUG_sunlover_2 */
2947
2948 Display *pDisplay = pDrv->pDisplay;
2949 unsigned uScreenId;
2950
2951 int vrc = pDisplay->i_videoAccelRefreshProcess(pDrv->pUpPort);
2952 if (vrc != VINF_TRY_AGAIN) /* Means 'do nothing' here. */
2953 {
2954 if (vrc == VWRN_INVALID_STATE)
2955 {
2956 /* No VBVA do a display update. */
2957 pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
2958 }
2959
2960 /* Inform the VRDP server that the current display update sequence is
2961 * completed. At this moment the framebuffer memory contains a definite
2962 * image, that is synchronized with the orders already sent to VRDP client.
2963 * The server can now process redraw requests from clients or initial
2964 * fullscreen updates for new clients.
2965 */
2966 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
2967 {
2968 Assert(pDisplay->mParent && pDisplay->mParent->i_consoleVRDPServer());
2969 pDisplay->mParent->i_consoleVRDPServer()->SendUpdate(uScreenId, NULL, 0);
2970 }
2971 }
2972
2973#ifdef VBOX_WITH_RECORDING
2974 AssertPtr(pDisplay->mParent);
2975 RecordingContext *pCtx = pDisplay->mParent->i_recordingGetContext();
2976
2977 if ( pCtx
2978 && pCtx->IsStarted()
2979 && pCtx->IsFeatureEnabled(RecordingFeature_Video))
2980 {
2981 do
2982 {
2983 /* If the recording context has reached the configured recording
2984 * limit, disable recording. */
2985 if (pCtx->IsLimitReached())
2986 {
2987 pDisplay->mParent->i_onRecordingChange(FALSE /* Disable */);
2988 break;
2989 }
2990
2991 uint64_t tsNowMs = RTTimeProgramMilliTS();
2992 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
2993 {
2994 if (!pDisplay->maRecordingEnabled[uScreenId])
2995 continue;
2996
2997 if (!pCtx->NeedsUpdate(uScreenId, tsNowMs))
2998 continue;
2999
3000 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3001 if (!pFBInfo->fDisabled)
3002 {
3003 ComPtr<IDisplaySourceBitmap> pSourceBitmap;
3004 int vrc2 = RTCritSectEnter(&pDisplay->mVideoRecLock);
3005 if (RT_SUCCESS(vrc2))
3006 {
3007 pSourceBitmap = pFBInfo->Recording.pSourceBitmap;
3008 RTCritSectLeave(&pDisplay->mVideoRecLock);
3009 }
3010
3011 if (!pSourceBitmap.isNull())
3012 {
3013 BYTE *pbAddress = NULL;
3014 ULONG ulWidth = 0;
3015 ULONG ulHeight = 0;
3016 ULONG ulBitsPerPixel = 0;
3017 ULONG ulBytesPerLine = 0;
3018 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
3019 HRESULT hrc = pSourceBitmap->QueryBitmapInfo(&pbAddress,
3020 &ulWidth,
3021 &ulHeight,
3022 &ulBitsPerPixel,
3023 &ulBytesPerLine,
3024 &bitmapFormat);
3025 if (SUCCEEDED(hrc) && pbAddress)
3026 vrc = pCtx->SendVideoFrame(uScreenId, 0, 0, BitmapFormat_BGR,
3027 ulBitsPerPixel, ulBytesPerLine, ulWidth, ulHeight,
3028 pbAddress, tsNowMs);
3029 else
3030 vrc = VERR_NOT_SUPPORTED;
3031
3032 pSourceBitmap.setNull();
3033 }
3034 else
3035 vrc = VERR_NOT_SUPPORTED;
3036
3037 if (vrc == VINF_TRY_AGAIN)
3038 break;
3039 }
3040 }
3041 } while (0);
3042 }
3043#endif /* VBOX_WITH_RECORDING */
3044
3045#ifdef DEBUG_sunlover_2
3046 LogFlowFunc(("leave\n"));
3047#endif /* DEBUG_sunlover_2 */
3048}
3049
3050/**
3051 * Reset notification
3052 *
3053 * @see PDMIDISPLAYCONNECTOR::pfnReset
3054 */
3055DECLCALLBACK(void) Display::i_displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface)
3056{
3057 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3058
3059 LogRelFlowFunc(("\n"));
3060
3061 /* Disable VBVA mode. */
3062 pDrv->pDisplay->VideoAccelEnableVGA(false, NULL);
3063}
3064
3065/**
3066 * LFBModeChange notification
3067 *
3068 * @see PDMIDISPLAYCONNECTOR::pfnLFBModeChange
3069 */
3070DECLCALLBACK(void) Display::i_displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled)
3071{
3072 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3073
3074 LogRelFlowFunc(("fEnabled=%d\n", fEnabled));
3075
3076 NOREF(fEnabled);
3077
3078 /* Disable VBVA mode in any case. The guest driver reenables VBVA mode if necessary. */
3079 pDrv->pDisplay->VideoAccelEnableVGA(false, NULL);
3080}
3081
3082/**
3083 * Adapter information change notification.
3084 *
3085 * @see PDMIDISPLAYCONNECTOR::pfnProcessAdapterData
3086 */
3087DECLCALLBACK(void) Display::i_displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM,
3088 uint32_t u32VRAMSize)
3089{
3090 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3091 pDrv->pDisplay->processAdapterData(pvVRAM, u32VRAMSize);
3092}
3093
3094/**
3095 * Display information change notification.
3096 *
3097 * @see PDMIDISPLAYCONNECTOR::pfnProcessDisplayData
3098 */
3099DECLCALLBACK(void) Display::i_displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface,
3100 void *pvVRAM, unsigned uScreenId)
3101{
3102 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3103 pDrv->pDisplay->processDisplayData(pvVRAM, uScreenId);
3104}
3105
3106#ifdef VBOX_WITH_VIDEOHWACCEL
3107
3108int Display::i_handleVHWACommandProcess(int enmCmd, bool fGuestCmd, VBOXVHWACMD RT_UNTRUSTED_VOLATILE_GUEST *pCommand)
3109{
3110 /* bugref:9691 Disable the legacy VHWA interface.
3111 * Keep the host commands enabled because they are needed when an old saved state is loaded.
3112 */
3113 if (fGuestCmd)
3114 return VERR_NOT_IMPLEMENTED;
3115
3116 unsigned id = (unsigned)pCommand->iDisplay;
3117 if (id >= mcMonitors)
3118 return VERR_INVALID_PARAMETER;
3119
3120 ComPtr<IFramebuffer> pFramebuffer;
3121 AutoReadLock arlock(this COMMA_LOCKVAL_SRC_POS);
3122 pFramebuffer = maFramebuffers[id].pFramebuffer;
3123 bool fVHWASupported = RT_BOOL(maFramebuffers[id].u32Caps & FramebufferCapabilities_VHWA);
3124 arlock.release();
3125
3126 if (pFramebuffer == NULL || !fVHWASupported)
3127 return VERR_NOT_IMPLEMENTED; /* Implementation is not available. */
3128
3129 HRESULT hr = pFramebuffer->ProcessVHWACommand((BYTE *)pCommand, enmCmd, fGuestCmd);
3130 if (hr == S_FALSE)
3131 return VINF_SUCCESS;
3132 if (SUCCEEDED(hr))
3133 return VINF_CALLBACK_RETURN;
3134 if (hr == E_ACCESSDENIED)
3135 return VERR_INVALID_STATE; /* notify we can not handle request atm */
3136 if (hr == E_NOTIMPL)
3137 return VERR_NOT_IMPLEMENTED;
3138 return VERR_GENERAL_FAILURE;
3139}
3140
3141DECLCALLBACK(int) Display::i_displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, int enmCmd, bool fGuestCmd,
3142 VBOXVHWACMD RT_UNTRUSTED_VOLATILE_GUEST *pCommand)
3143{
3144 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3145
3146 return pDrv->pDisplay->i_handleVHWACommandProcess(enmCmd, fGuestCmd, pCommand);
3147}
3148
3149#endif /* VBOX_WITH_VIDEOHWACCEL */
3150
3151int Display::i_handle3DNotifyProcess(VBOX3DNOTIFY *p3DNotify)
3152{
3153 unsigned const id = (unsigned)p3DNotify->iDisplay;
3154 if (id >= mcMonitors)
3155 return VERR_INVALID_PARAMETER;
3156
3157 ComPtr<IFramebuffer> pFramebuffer;
3158 AutoReadLock arlock(this COMMA_LOCKVAL_SRC_POS);
3159 pFramebuffer = maFramebuffers[id].pFramebuffer;
3160 arlock.release();
3161
3162 int vrc = VINF_SUCCESS;
3163
3164 if (!pFramebuffer.isNull())
3165 {
3166 if (p3DNotify->enmNotification == VBOX3D_NOTIFY_TYPE_HW_OVERLAY_GET_ID)
3167 {
3168 LONG64 winId = 0;
3169 HRESULT hrc = pFramebuffer->COMGETTER(WinId)(&winId);
3170 if (SUCCEEDED(hrc))
3171 {
3172 *(uint64_t *)&p3DNotify->au8Data[0] = winId;
3173 }
3174 else
3175 vrc = VERR_NOT_SUPPORTED;
3176 }
3177 else
3178 {
3179 com::SafeArray<BYTE> data;
3180 data.initFrom((BYTE *)&p3DNotify->au8Data[0], p3DNotify->cbData);
3181
3182 HRESULT hrc = pFramebuffer->Notify3DEvent((ULONG)p3DNotify->enmNotification, ComSafeArrayAsInParam(data));
3183 if (FAILED(hrc))
3184 vrc = VERR_NOT_SUPPORTED;
3185 }
3186 }
3187 else
3188 vrc = VERR_NOT_IMPLEMENTED;
3189
3190 return vrc;
3191}
3192
3193DECLCALLBACK(int) Display::i_display3DNotifyProcess(PPDMIDISPLAYCONNECTOR pInterface,
3194 VBOX3DNOTIFY *p3DNotify)
3195{
3196 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3197 return pDrv->pDisplay->i_handle3DNotifyProcess(p3DNotify);
3198}
3199
3200HRESULT Display::notifyScaleFactorChange(ULONG aScreenId, ULONG aScaleFactorWMultiplied, ULONG aScaleFactorHMultiplied)
3201{
3202 RT_NOREF(aScreenId, aScaleFactorWMultiplied, aScaleFactorHMultiplied);
3203# if 0 /** @todo Thank you so very much from anyone using VMSVGA3d! */
3204 AssertMsgFailed(("Attempt to specify OpenGL content scale factor while 3D acceleration is disabled in VM config. Ignored.\n"));
3205# else
3206 /* Need an interface like this here (and the #ifdefs needs adjusting):
3207 PPDMIDISPLAYPORT pUpPort = mpDrv ? mpDrv->pUpPort : NULL;
3208 if (pUpPort && pUpPort->pfnSetScaleFactor)
3209 pUpPort->pfnSetScaleFactor(pUpPort, aScreeId, aScaleFactorWMultiplied, aScaleFactorHMultiplied); */
3210# endif
3211 return S_OK;
3212}
3213
3214HRESULT Display::notifyHiDPIOutputPolicyChange(BOOL fUnscaledHiDPI)
3215{
3216 RT_NOREF(fUnscaledHiDPI);
3217
3218 /* Need an interface like this here (and the #ifdefs needs adjusting):
3219 PPDMIDISPLAYPORT pUpPort = mpDrv ? mpDrv->pUpPort : NULL;
3220 if (pUpPort && pUpPort->pfnSetScaleFactor)
3221 pUpPort->pfnSetScaleFactor(pUpPort, aScreeId, aScaleFactorWMultiplied, aScaleFactorHMultiplied); */
3222
3223 return S_OK;
3224}
3225
3226#ifdef VBOX_WITH_HGSMI
3227/**
3228 * @interface_method_impl{PDMIDISPLAYCONNECTOR,pfnVBVAEnable}
3229 */
3230DECLCALLBACK(int) Display::i_displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId,
3231 VBVAHOSTFLAGS RT_UNTRUSTED_VOLATILE_GUEST *pHostFlags)
3232{
3233 LogRelFlowFunc(("uScreenId %d\n", uScreenId));
3234
3235 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3236 Display *pThis = pDrv->pDisplay;
3237 AssertReturn(uScreenId < pThis->mcMonitors, VERR_INVALID_PARAMETER);
3238
3239 if (pThis->maFramebuffers[uScreenId].fVBVAEnabled)
3240 {
3241 LogRel(("Enabling different vbva mode\n"));
3242#ifdef DEBUG_misha
3243 AssertMsgFailed(("enabling different vbva mode\n"));
3244#endif
3245 return VERR_INVALID_STATE;
3246 }
3247
3248 pThis->maFramebuffers[uScreenId].fVBVAEnabled = true;
3249 pThis->maFramebuffers[uScreenId].pVBVAHostFlags = pHostFlags;
3250 pThis->maFramebuffers[uScreenId].fVBVAForceResize = true;
3251
3252 vbvaSetMemoryFlagsHGSMI(uScreenId, pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, &pThis->maFramebuffers[uScreenId]);
3253
3254 return VINF_SUCCESS;
3255}
3256
3257/**
3258 * @interface_method_impl{PDMIDISPLAYCONNECTOR,pfnVBVADisable}
3259 */
3260DECLCALLBACK(void) Display::i_displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3261{
3262 LogRelFlowFunc(("uScreenId %d\n", uScreenId));
3263
3264 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3265 Display *pThis = pDrv->pDisplay;
3266 AssertReturnVoid(uScreenId < pThis->mcMonitors);
3267
3268 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3269
3270 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3271 {
3272 /* Make sure that the primary screen is visible now.
3273 * The guest can't use VBVA anymore, so only only the VGA device output works.
3274 */
3275 pFBInfo->flags = 0;
3276 if (pFBInfo->fDisabled)
3277 {
3278 pFBInfo->fDisabled = false;
3279 ::FireGuestMonitorChangedEvent(pThis->mParent->i_getEventSource(), GuestMonitorChangedEventType_Enabled, uScreenId,
3280 pFBInfo->xOrigin, pFBInfo->yOrigin, pFBInfo->w, pFBInfo->h);
3281 }
3282 }
3283
3284 pFBInfo->fVBVAEnabled = false;
3285 pFBInfo->fVBVAForceResize = false;
3286
3287 vbvaSetMemoryFlagsHGSMI(uScreenId, 0, false, pFBInfo);
3288
3289 pFBInfo->pVBVAHostFlags = NULL;
3290
3291 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3292 {
3293 /* Force full screen update, because VGA device must take control, do resize, etc. */
3294 pThis->mpDrv->pUpPort->pfnUpdateDisplayAll(pThis->mpDrv->pUpPort, /* fFailOnResize = */ false);
3295 }
3296}
3297
3298DECLCALLBACK(void) Display::i_displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3299{
3300 RT_NOREF(uScreenId);
3301 LogFlowFunc(("uScreenId %d\n", uScreenId));
3302
3303 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3304 Display *pThis = pDrv->pDisplay;
3305
3306 if (ASMAtomicReadU32(&pThis->mu32UpdateVBVAFlags) > 0)
3307 {
3308 vbvaSetMemoryFlagsAllHGSMI(pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, pThis->maFramebuffers,
3309 pThis->mcMonitors);
3310 ASMAtomicDecU32(&pThis->mu32UpdateVBVAFlags);
3311 }
3312}
3313
3314/**
3315 * @interface_method_impl{PDMIDISPLAYCONNECTOR,pfnVBVAUpdateProcess}
3316 */
3317DECLCALLBACK(void) Display::i_displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId,
3318 struct VBVACMDHDR const RT_UNTRUSTED_VOLATILE_GUEST *pCmd, size_t cbCmd)
3319{
3320 LogFlowFunc(("uScreenId %d pCmd %p cbCmd %d, @%d,%d %dx%d\n", uScreenId, pCmd, cbCmd, pCmd->x, pCmd->y, pCmd->w, pCmd->h));
3321 VBVACMDHDR hdrSaved;
3322 RT_COPY_VOLATILE(hdrSaved, *pCmd);
3323 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
3324
3325 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3326 Display *pThis = pDrv->pDisplay;
3327 DISPLAYFBINFO *pFBInfo;
3328 AssertReturnVoid(uScreenId < pThis->mcMonitors);
3329
3330 pFBInfo = &pThis->maFramebuffers[uScreenId];
3331
3332 if (pFBInfo->fDefaultFormat)
3333 {
3334 /* Make sure that framebuffer contains the same image as the guest VRAM. */
3335 if ( uScreenId == VBOX_VIDEO_PRIMARY_SCREEN
3336 && !pFBInfo->fDisabled)
3337 {
3338 pDrv->pUpPort->pfnUpdateDisplayRect(pDrv->pUpPort, hdrSaved.x, hdrSaved.y, hdrSaved.w, hdrSaved.h);
3339 }
3340 else if ( !pFBInfo->pSourceBitmap.isNull()
3341 && !pFBInfo->fDisabled)
3342 {
3343 /* Render VRAM content to the framebuffer. */
3344 BYTE *pAddress = NULL;
3345 ULONG ulWidth = 0;
3346 ULONG ulHeight = 0;
3347 ULONG ulBitsPerPixel = 0;
3348 ULONG ulBytesPerLine = 0;
3349 BitmapFormat_T bitmapFormat = BitmapFormat_Opaque;
3350
3351 HRESULT hrc = pFBInfo->pSourceBitmap->QueryBitmapInfo(&pAddress,
3352 &ulWidth,
3353 &ulHeight,
3354 &ulBitsPerPixel,
3355 &ulBytesPerLine,
3356 &bitmapFormat);
3357 if (SUCCEEDED(hrc))
3358 {
3359 uint32_t width = hdrSaved.w;
3360 uint32_t height = hdrSaved.h;
3361
3362 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
3363 int32_t xSrc = hdrSaved.x - pFBInfo->xOrigin;
3364 int32_t ySrc = hdrSaved.y - pFBInfo->yOrigin;
3365 uint32_t u32SrcWidth = pFBInfo->w;
3366 uint32_t u32SrcHeight = pFBInfo->h;
3367 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
3368 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
3369
3370 uint8_t *pu8Dst = pAddress;
3371 int32_t xDst = xSrc;
3372 int32_t yDst = ySrc;
3373 uint32_t u32DstWidth = u32SrcWidth;
3374 uint32_t u32DstHeight = u32SrcHeight;
3375 uint32_t u32DstLineSize = u32DstWidth * 4;
3376 uint32_t u32DstBitsPerPixel = 32;
3377
3378 pDrv->pUpPort->pfnCopyRect(pDrv->pUpPort,
3379 width, height,
3380 pu8Src,
3381 xSrc, ySrc,
3382 u32SrcWidth, u32SrcHeight,
3383 u32SrcLineSize, u32SrcBitsPerPixel,
3384 pu8Dst,
3385 xDst, yDst,
3386 u32DstWidth, u32DstHeight,
3387 u32DstLineSize, u32DstBitsPerPixel);
3388 }
3389 }
3390 }
3391
3392 /*
3393 * Here is your classic 'temporary' solution.
3394 */
3395 /** @todo New SendUpdate entry which can get a separate cmd header or coords. */
3396 VBVACMDHDR *pHdrUnconst = (VBVACMDHDR *)pCmd;
3397
3398 pHdrUnconst->x -= (int16_t)pFBInfo->xOrigin;
3399 pHdrUnconst->y -= (int16_t)pFBInfo->yOrigin;
3400
3401 pThis->mParent->i_consoleVRDPServer()->SendUpdate(uScreenId, pHdrUnconst, (uint32_t)cbCmd);
3402
3403 *pHdrUnconst = hdrSaved;
3404}
3405
3406DECLCALLBACK(void) Display::i_displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y,
3407 uint32_t cx, uint32_t cy)
3408{
3409 LogFlowFunc(("uScreenId %d %d,%d %dx%d\n", uScreenId, x, y, cx, cy));
3410
3411 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3412 Display *pThis = pDrv->pDisplay;
3413 DISPLAYFBINFO *pFBInfo;
3414 AssertReturnVoid(uScreenId < pThis->mcMonitors);
3415
3416 pFBInfo = &pThis->maFramebuffers[uScreenId];
3417
3418 /** @todo handleFramebufferUpdate (uScreenId,
3419 * x - pThis->maFramebuffers[uScreenId].xOrigin,
3420 * y - pThis->maFramebuffers[uScreenId].yOrigin,
3421 * cx, cy);
3422 */
3423 pThis->i_handleDisplayUpdate(uScreenId, x - pFBInfo->xOrigin, y - pFBInfo->yOrigin, cx, cy);
3424}
3425
3426#ifdef DEBUG_sunlover
3427static void logVBVAResize(PCVBVAINFOVIEW pView, PCVBVAINFOSCREEN pScreen, const DISPLAYFBINFO *pFBInfo)
3428{
3429 LogRel(("displayVBVAResize: [%d] %s\n"
3430 " pView->u32ViewIndex %d\n"
3431 " pView->u32ViewOffset 0x%08X\n"
3432 " pView->u32ViewSize 0x%08X\n"
3433 " pView->u32MaxScreenSize 0x%08X\n"
3434 " pScreen->i32OriginX %d\n"
3435 " pScreen->i32OriginY %d\n"
3436 " pScreen->u32StartOffset 0x%08X\n"
3437 " pScreen->u32LineSize 0x%08X\n"
3438 " pScreen->u32Width %d\n"
3439 " pScreen->u32Height %d\n"
3440 " pScreen->u16BitsPerPixel %d\n"
3441 " pScreen->u16Flags 0x%04X\n"
3442 " pFBInfo->u32Offset 0x%08X\n"
3443 " pFBInfo->u32MaxFramebufferSize 0x%08X\n"
3444 " pFBInfo->u32InformationSize 0x%08X\n"
3445 " pFBInfo->fDisabled %d\n"
3446 " xOrigin, yOrigin, w, h: %d,%d %dx%d\n"
3447 " pFBInfo->u16BitsPerPixel %d\n"
3448 " pFBInfo->pu8FramebufferVRAM %p\n"
3449 " pFBInfo->u32LineSize 0x%08X\n"
3450 " pFBInfo->flags 0x%04X\n"
3451 " pFBInfo->pHostEvents %p\n"
3452 " pFBInfo->fDefaultFormat %d\n"
3453 " pFBInfo->fVBVAEnabled %d\n"
3454 " pFBInfo->fVBVAForceResize %d\n"
3455 " pFBInfo->pVBVAHostFlags %p\n"
3456 "",
3457 pScreen->u32ViewIndex,
3458 (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)? "DISABLED": "ENABLED",
3459 pView->u32ViewIndex,
3460 pView->u32ViewOffset,
3461 pView->u32ViewSize,
3462 pView->u32MaxScreenSize,
3463 pScreen->i32OriginX,
3464 pScreen->i32OriginY,
3465 pScreen->u32StartOffset,
3466 pScreen->u32LineSize,
3467 pScreen->u32Width,
3468 pScreen->u32Height,
3469 pScreen->u16BitsPerPixel,
3470 pScreen->u16Flags,
3471 pFBInfo->u32Offset,
3472 pFBInfo->u32MaxFramebufferSize,
3473 pFBInfo->u32InformationSize,
3474 pFBInfo->fDisabled,
3475 pFBInfo->xOrigin,
3476 pFBInfo->yOrigin,
3477 pFBInfo->w,
3478 pFBInfo->h,
3479 pFBInfo->u16BitsPerPixel,
3480 pFBInfo->pu8FramebufferVRAM,
3481 pFBInfo->u32LineSize,
3482 pFBInfo->flags,
3483 pFBInfo->pHostEvents,
3484 pFBInfo->fDefaultFormat,
3485 pFBInfo->fVBVAEnabled,
3486 pFBInfo->fVBVAForceResize,
3487 pFBInfo->pVBVAHostFlags
3488 ));
3489}
3490#endif /* DEBUG_sunlover */
3491
3492DECLCALLBACK(int) Display::i_displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, PCVBVAINFOVIEW pView,
3493 PCVBVAINFOSCREEN pScreen, void *pvVRAM, bool fResetInputMapping)
3494{
3495 LogRelFlowFunc(("pScreen %p, pvVRAM %p\n", pScreen, pvVRAM));
3496
3497 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3498 Display *pThis = pDrv->pDisplay;
3499
3500 return pThis->processVBVAResize(pView, pScreen, pvVRAM, fResetInputMapping);
3501}
3502
3503int Display::processVBVAResize(PCVBVAINFOVIEW pView, PCVBVAINFOSCREEN pScreen, void *pvVRAM, bool fResetInputMapping)
3504{
3505 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
3506
3507 RT_NOREF(pView);
3508
3509 DISPLAYFBINFO *pFBInfo = &maFramebuffers[pScreen->u32ViewIndex];
3510
3511#ifdef DEBUG_sunlover
3512 logVBVAResize(pView, pScreen, pFBInfo);
3513#endif
3514
3515 if (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)
3516 {
3517 /* Ask the framebuffer to resize using a default format. The framebuffer will be black.
3518 * So if the frontend does not support GuestMonitorChangedEventType_Disabled event,
3519 * the VM window will be black. */
3520 uint32_t u32Width = pFBInfo->w ? pFBInfo->w : 640;
3521 uint32_t u32Height = pFBInfo->h ? pFBInfo->h : 480;
3522 int32_t xOrigin = pFBInfo->xOrigin;
3523 int32_t yOrigin = pFBInfo->yOrigin;
3524
3525 alock.release();
3526
3527 i_handleDisplayResize(pScreen->u32ViewIndex, 0, (uint8_t *)NULL, 0,
3528 u32Width, u32Height, pScreen->u16Flags, xOrigin, yOrigin, false);
3529
3530 return VINF_SUCCESS;
3531 }
3532
3533 VBVAINFOSCREEN screenInfo;
3534 RT_ZERO(screenInfo);
3535
3536 if (pScreen->u16Flags & VBVA_SCREEN_F_BLANK2)
3537 {
3538 /* Init a local VBVAINFOSCREEN structure, which will be used instead of
3539 * the original pScreen. Set VBVA_SCREEN_F_BLANK, which will force
3540 * the code below to choose the "blanking" branches.
3541 */
3542 screenInfo.u32ViewIndex = pScreen->u32ViewIndex;
3543 screenInfo.i32OriginX = pFBInfo->xOrigin;
3544 screenInfo.i32OriginY = pFBInfo->yOrigin;
3545 screenInfo.u32StartOffset = 0; /* Irrelevant */
3546 screenInfo.u32LineSize = pFBInfo->u32LineSize;
3547 screenInfo.u32Width = pFBInfo->w;
3548 screenInfo.u32Height = pFBInfo->h;
3549 screenInfo.u16BitsPerPixel = pFBInfo->u16BitsPerPixel;
3550 screenInfo.u16Flags = pScreen->u16Flags | VBVA_SCREEN_F_BLANK;
3551
3552 pScreen = &screenInfo;
3553 }
3554
3555 if (fResetInputMapping)
3556 {
3557 /// @todo Rename to m* and verify whether some kind of lock is required.
3558 xInputMappingOrigin = 0;
3559 yInputMappingOrigin = 0;
3560 cxInputMapping = 0;
3561 cyInputMapping = 0;
3562 }
3563
3564 alock.release();
3565
3566 return i_handleDisplayResize(pScreen->u32ViewIndex, pScreen->u16BitsPerPixel,
3567 (uint8_t *)pvVRAM + pScreen->u32StartOffset,
3568 pScreen->u32LineSize, pScreen->u32Width, pScreen->u32Height, pScreen->u16Flags,
3569 pScreen->i32OriginX, pScreen->i32OriginY, false);
3570}
3571
3572DECLCALLBACK(int) Display::i_displayVBVAMousePointerShape(PPDMIDISPLAYCONNECTOR pInterface, bool fVisible, bool fAlpha,
3573 uint32_t xHot, uint32_t yHot,
3574 uint32_t cx, uint32_t cy,
3575 const void *pvShape)
3576{
3577 LogFlowFunc(("\n"));
3578 LogRel2(("%s: fVisible=%RTbool\n", __PRETTY_FUNCTION__, fVisible));
3579
3580 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3581
3582 uint32_t cbShape = 0;
3583 if (pvShape)
3584 {
3585 cbShape = (cx + 7) / 8 * cy; /* size of the AND mask */
3586 cbShape = ((cbShape + 3) & ~3) + cx * 4 * cy; /* + gap + size of the XOR mask */
3587 }
3588
3589 /* Tell the console about it */
3590 pDrv->pDisplay->mParent->i_onMousePointerShapeChange(fVisible, fAlpha,
3591 xHot, yHot, cx, cy, (uint8_t *)pvShape, cbShape);
3592
3593 return VINF_SUCCESS;
3594}
3595
3596DECLCALLBACK(void) Display::i_displayVBVAGuestCapabilityUpdate(PPDMIDISPLAYCONNECTOR pInterface, uint32_t fCapabilities)
3597{
3598 LogFlowFunc(("\n"));
3599
3600 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3601 Display *pThis = pDrv->pDisplay;
3602
3603 pThis->i_handleUpdateGuestVBVACapabilities(fCapabilities);
3604}
3605
3606DECLCALLBACK(void) Display::i_displayVBVAInputMappingUpdate(PPDMIDISPLAYCONNECTOR pInterface, int32_t xOrigin, int32_t yOrigin,
3607 uint32_t cx, uint32_t cy)
3608{
3609 LogFlowFunc(("\n"));
3610
3611 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3612 Display *pThis = pDrv->pDisplay;
3613
3614 pThis->i_handleUpdateVBVAInputMapping(xOrigin, yOrigin, cx, cy);
3615}
3616
3617DECLCALLBACK(void) Display::i_displayVBVAReportCursorPosition(PPDMIDISPLAYCONNECTOR pInterface, uint32_t fFlags, uint32_t aScreenId, uint32_t x, uint32_t y)
3618{
3619 LogFlowFunc(("\n"));
3620 LogRel2(("%s: fFlags=%RU32, aScreenId=%RU32, x=%RU32, y=%RU32\n",
3621 __PRETTY_FUNCTION__, fFlags, aScreenId, x, y));
3622
3623 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3624 Display *pThis = pDrv->pDisplay;
3625
3626 if (fFlags & VBVA_CURSOR_SCREEN_RELATIVE)
3627 {
3628 AssertReturnVoid(aScreenId < pThis->mcMonitors);
3629
3630 x += pThis->maFramebuffers[aScreenId].xOrigin;
3631 y += pThis->maFramebuffers[aScreenId].yOrigin;
3632 }
3633 ::FireCursorPositionChangedEvent(pThis->mParent->i_getEventSource(), RT_BOOL(fFlags & VBVA_CURSOR_VALID_DATA), x, y);
3634}
3635
3636#endif /* VBOX_WITH_HGSMI */
3637
3638/**
3639 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
3640 */
3641DECLCALLBACK(void *) Display::i_drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
3642{
3643 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
3644 PDRVMAINDISPLAY pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3645 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
3646 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIDISPLAYCONNECTOR, &pDrv->IConnector);
3647 return NULL;
3648}
3649
3650
3651/**
3652 * @interface_method_impl{PDMDRVREG,pfnPowerOff,
3653 * Tries to ensure no client calls gets to HGCM or the VGA device from here on.}
3654 */
3655DECLCALLBACK(void) Display::i_drvPowerOff(PPDMDRVINS pDrvIns)
3656{
3657 PDRVMAINDISPLAY pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
3658 LogRelFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
3659
3660 /*
3661 * Do much of the work that i_drvDestruct does.
3662 */
3663 if (pThis->pUpPort)
3664 pThis->pUpPort->pfnSetRenderVRAM(pThis->pUpPort, false);
3665
3666 pThis->IConnector.pbData = NULL;
3667 pThis->IConnector.cbScanline = 0;
3668 pThis->IConnector.cBits = 32;
3669 pThis->IConnector.cx = 0;
3670 pThis->IConnector.cy = 0;
3671
3672 if (pThis->pDisplay)
3673 {
3674 AutoWriteLock displayLock(pThis->pDisplay COMMA_LOCKVAL_SRC_POS);
3675#ifdef VBOX_WITH_RECORDING
3676 pThis->pDisplay->mParent->i_recordingStop();
3677#endif
3678#if defined(VBOX_WITH_VIDEOHWACCEL)
3679 pThis->pVBVACallbacks = NULL;
3680#endif
3681 }
3682}
3683
3684
3685/**
3686 * Destruct a display driver instance.
3687 *
3688 * @returns VBox status code.
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 if (!pThis->pVBVACallbacks)
3790 {
3791 AssertMsgFailed(("Configuration error: No VBVA callback interface above!\n"));
3792 return VERR_PDM_MISSING_INTERFACE_ABOVE;
3793 }
3794#endif
3795 /*
3796 * Get the Display object pointer and update the mpDrv member.
3797 */
3798 com::Guid uuid(COM_IIDOF(IDisplay));
3799 IDisplay *pIDisplay = (IDisplay *)PDMDrvHlpQueryGenericUserObject(pDrvIns, uuid.raw());
3800 if (!pIDisplay)
3801 {
3802 AssertMsgFailed(("Configuration error: No/bad Keyboard object!\n"));
3803 return VERR_NOT_FOUND;
3804 }
3805 pThis->pDisplay = static_cast<Display *>(pIDisplay);
3806 pThis->pDisplay->mpDrv = pThis;
3807
3808 /* Disable VRAM to a buffer copy initially. */
3809 pThis->pUpPort->pfnSetRenderVRAM(pThis->pUpPort, false);
3810 pThis->IConnector.cBits = 32; /* DevVGA does nothing otherwise. */
3811
3812 /*
3813 * Start periodic screen refreshes
3814 */
3815 pThis->pUpPort->pfnSetRefreshRate(pThis->pUpPort, 20);
3816
3817 return VINF_SUCCESS;
3818}
3819
3820
3821/**
3822 * Display driver registration record.
3823 */
3824const PDMDRVREG Display::DrvReg =
3825{
3826 /* u32Version */
3827 PDM_DRVREG_VERSION,
3828 /* szName */
3829 "MainDisplay",
3830 /* szRCMod */
3831 "",
3832 /* szR0Mod */
3833 "",
3834 /* pszDescription */
3835 "Main display driver (Main as in the API).",
3836 /* fFlags */
3837 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
3838 /* fClass. */
3839 PDM_DRVREG_CLASS_DISPLAY,
3840 /* cMaxInstances */
3841 ~0U,
3842 /* cbInstance */
3843 sizeof(DRVMAINDISPLAY),
3844 /* pfnConstruct */
3845 Display::i_drvConstruct,
3846 /* pfnDestruct */
3847 Display::i_drvDestruct,
3848 /* pfnRelocate */
3849 NULL,
3850 /* pfnIOCtl */
3851 NULL,
3852 /* pfnPowerOn */
3853 NULL,
3854 /* pfnReset */
3855 NULL,
3856 /* pfnSuspend */
3857 NULL,
3858 /* pfnResume */
3859 NULL,
3860 /* pfnAttach */
3861 NULL,
3862 /* pfnDetach */
3863 NULL,
3864 /* pfnPowerOff */
3865 Display::i_drvPowerOff,
3866 /* pfnSoftReset */
3867 NULL,
3868 /* u32EndVersion */
3869 PDM_DRVREG_VERSION
3870};
3871
3872/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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