VirtualBox

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

Last change on this file since 47148 was 47117, checked in by vboxsync, 11 years ago

Main: RT_ZERO() / RTStrCopy()

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