VirtualBox

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

Last change on this file since 46667 was 46667, checked in by vboxsync, 12 years ago

Main/idl: clarify IMachine.videoCaptureFile to be an absolute path, and many naming convention cleanups for method/attribute names starting with an uppercase letter or containing an acronym
Main/xml/Settings.cpp: clean up default video capture file handling and related path conversions, version handling of the new functionality
Main/Machine: handle default value for video capture file better, store relative path in settings if possible, cleanups
Main/src-client/VideoRec.cpp: do not overwrite a file ever
Main/Display: generate a unique name if there is a collision, matching cleanups for name changes
Frontends/VirtualBox: matching name changes
Frontends/VBoxManage: matching name changes, fixing the machine readable output

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 152.7 KB
Line 
1/* $Id: DisplayImpl.cpp 46667 2013-06-19 15:30:23Z 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 memset (&mVBVALock, 0, sizeof (mVBVALock));
152 }
153
154 if (RTCritSectIsInitialized(&mSaveSeamlessRectLock))
155 {
156 RTCritSectDelete(&mSaveSeamlessRectLock);
157 memset(&mSaveSeamlessRectLock, 0, sizeof (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 memset (&maFramebuffers[ul].dirtyRect, 0 , sizeof (maFramebuffers[ul].dirtyRect));
492 memset (&maFramebuffers[ul].pendingResize, 0 , sizeof (maFramebuffers[ul].pendingResize));
493#ifdef VBOX_WITH_HGSMI
494 maFramebuffers[ul].fVBVAEnabled = false;
495 maFramebuffers[ul].cVBVASkipUpdate = 0;
496 memset (&maFramebuffers[ul].vbvaSkippedRect, 0, sizeof (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 memset (&pFBInfo->dirtyRect, 0, sizeof (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 for (unsigned uScreen = 0; uScreen < mcMonitors; uScreen++)
2726 {
2727 char *pszAbsPath = RTPathAbsDup(com::Utf8Str(strFile).c_str());
2728 char *pszExt = RTPathExt(pszAbsPath);
2729 if (pszExt)
2730 pszExt = RTStrDup(pszExt);
2731 RTPathStripExt(pszAbsPath);
2732 if (!pszAbsPath)
2733 rc = VERR_INVALID_PARAMETER;
2734 if (!pszExt)
2735 pszExt = RTStrDup(".webm");
2736 char *pszName = NULL;
2737 if (RT_SUCCESS(rc))
2738 {
2739 if (mcMonitors > 1)
2740 rc = RTStrAPrintf(&pszName, "%s-%u%s", pszAbsPath, uScreen+1, pszExt);
2741 else
2742 rc = RTStrAPrintf(&pszName, "%s%s", pszAbsPath, pszExt);
2743 }
2744 if (RT_SUCCESS(rc))
2745 {
2746 rc = VideoRecStrmInit(mpVideoRecCtx, uScreen,
2747 pszName, ulWidth, ulHeight, ulRate, ulFPS);
2748 if (rc == VERR_ALREADY_EXISTS)
2749 {
2750 RTStrFree(pszName);
2751 pszName = NULL;
2752
2753 static RTTIMESPEC ts = { 0 };
2754 if (!RTTimeSpecGetNano(&ts))
2755 RTTimeNow(&ts);
2756 RTTIME time;
2757 RTTimeExplode(&time, &ts);
2758 if (mcMonitors > 1)
2759 rc = RTStrAPrintf(&pszName, "%s-%04d-%02u-%02uT%02u-%02u-%02u-%09uZ-%u%s",
2760 pszAbsPath, time.i32Year, time.u8Month, time.u8MonthDay,
2761 time.u8Hour, time.u8Minute, time.u8Second, time.u32Nanosecond,
2762 uScreen+1, pszExt);
2763 else
2764 rc = RTStrAPrintf(&pszName, "%s-%04d-%02u-%02uT%02u-%02u-%02u-%09uZ%s",
2765 pszAbsPath, time.i32Year, time.u8Month, time.u8MonthDay,
2766 time.u8Hour, time.u8Minute, time.u8Second, time.u32Nanosecond,
2767 pszExt);
2768 if (RT_SUCCESS(rc))
2769 rc = VideoRecStrmInit(mpVideoRecCtx, uScreen,
2770 pszName, ulWidth, ulHeight, ulRate, ulFPS);
2771 }
2772 }
2773
2774 if (RT_SUCCESS(rc))
2775 LogRel(("WebM/VP8 video recording screen #%u with %ux%u @ %u kbps, %u fps to '%s' enabled.\n",
2776 uScreen, ulWidth, ulHeight, ulRate, ulFPS, pszName));
2777 else
2778 LogRel(("Failed to initialize video recording context #%u (%Rrc)!\n", uScreen, rc));
2779 RTStrFree(pszName);
2780 RTStrFree(pszExt);
2781 RTStrFree(pszAbsPath);
2782 }
2783 return rc;
2784#else
2785 return VERR_NOT_IMPLEMENTED;
2786#endif
2787}
2788
2789/**
2790 * Stop video capturing. Does nothing if video capturing is not active.
2791 */
2792void Display::VideoCaptureStop()
2793{
2794#ifdef VBOX_WITH_VPX
2795 if (VideoRecIsEnabled(mpVideoRecCtx))
2796 LogRel(("WebM/VP8 video recording stopped.\n"));
2797 VideoRecContextClose(mpVideoRecCtx);
2798 mpVideoRecCtx = NULL;
2799#endif
2800}
2801
2802int Display::drawToScreenEMT(Display *pDisplay, ULONG aScreenId, BYTE *address,
2803 ULONG x, ULONG y, ULONG width, ULONG height)
2804{
2805 int rc = VINF_SUCCESS;
2806 pDisplay->vbvaLock();
2807
2808 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[aScreenId];
2809
2810 if (aScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
2811 {
2812 if (pFBInfo->u32ResizeStatus == ResizeStatus_Void)
2813 {
2814 rc = pDisplay->mpDrv->pUpPort->pfnDisplayBlt(pDisplay->mpDrv->pUpPort, address, x, y, width, height);
2815 }
2816 }
2817 else if (aScreenId < pDisplay->mcMonitors)
2818 {
2819 /* Copy the bitmap to the guest VRAM. */
2820 const uint8_t *pu8Src = address;
2821 int32_t xSrc = 0;
2822 int32_t ySrc = 0;
2823 uint32_t u32SrcWidth = width;
2824 uint32_t u32SrcHeight = height;
2825 uint32_t u32SrcLineSize = width * 4;
2826 uint32_t u32SrcBitsPerPixel = 32;
2827
2828 uint8_t *pu8Dst = pFBInfo->pu8FramebufferVRAM;
2829 int32_t xDst = x;
2830 int32_t yDst = y;
2831 uint32_t u32DstWidth = pFBInfo->w;
2832 uint32_t u32DstHeight = pFBInfo->h;
2833 uint32_t u32DstLineSize = pFBInfo->u32LineSize;
2834 uint32_t u32DstBitsPerPixel = pFBInfo->u16BitsPerPixel;
2835
2836 rc = pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2837 width, height,
2838 pu8Src,
2839 xSrc, ySrc,
2840 u32SrcWidth, u32SrcHeight,
2841 u32SrcLineSize, u32SrcBitsPerPixel,
2842 pu8Dst,
2843 xDst, yDst,
2844 u32DstWidth, u32DstHeight,
2845 u32DstLineSize, u32DstBitsPerPixel);
2846 if (RT_SUCCESS(rc))
2847 {
2848 if (!pFBInfo->pFramebuffer.isNull())
2849 {
2850 /* Update the changed screen area. When framebuffer uses VRAM directly, just notify
2851 * it to update. And for default format, render the guest VRAM to framebuffer.
2852 */
2853 if ( pFBInfo->fDefaultFormat
2854 && !pFBInfo->fDisabled)
2855 {
2856 address = NULL;
2857 HRESULT hrc = pFBInfo->pFramebuffer->COMGETTER(Address) (&address);
2858 if (SUCCEEDED(hrc) && address != NULL)
2859 {
2860 pu8Src = pFBInfo->pu8FramebufferVRAM;
2861 xSrc = x;
2862 ySrc = y;
2863 u32SrcWidth = pFBInfo->w;
2864 u32SrcHeight = pFBInfo->h;
2865 u32SrcLineSize = pFBInfo->u32LineSize;
2866 u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
2867
2868 /* Default format is 32 bpp. */
2869 pu8Dst = address;
2870 xDst = xSrc;
2871 yDst = ySrc;
2872 u32DstWidth = u32SrcWidth;
2873 u32DstHeight = u32SrcHeight;
2874 u32DstLineSize = u32DstWidth * 4;
2875 u32DstBitsPerPixel = 32;
2876
2877 pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
2878 width, height,
2879 pu8Src,
2880 xSrc, ySrc,
2881 u32SrcWidth, u32SrcHeight,
2882 u32SrcLineSize, u32SrcBitsPerPixel,
2883 pu8Dst,
2884 xDst, yDst,
2885 u32DstWidth, u32DstHeight,
2886 u32DstLineSize, u32DstBitsPerPixel);
2887 }
2888 }
2889
2890 pDisplay->handleDisplayUpdate(aScreenId, x, y, width, height);
2891 }
2892 }
2893 }
2894 else
2895 {
2896 rc = VERR_INVALID_PARAMETER;
2897 }
2898
2899 if ( RT_SUCCESS(rc)
2900 && pDisplay->maFramebuffers[aScreenId].u32ResizeStatus == ResizeStatus_Void)
2901 pDisplay->mParent->consoleVRDPServer()->SendUpdateBitmap(aScreenId, x, y, width, height);
2902
2903 pDisplay->vbvaUnlock();
2904 return rc;
2905}
2906
2907STDMETHODIMP Display::DrawToScreen(ULONG aScreenId, BYTE *address,
2908 ULONG x, ULONG y, ULONG width, ULONG height)
2909{
2910 /// @todo (r=dmik) this function may take too long to complete if the VM
2911 // is doing something like saving state right now. Which, in case if it
2912 // is called on the GUI thread, will make it unresponsive. We should
2913 // check the machine state here (by enclosing the check and VMRequCall
2914 // within the Console lock to make it atomic).
2915
2916 LogRelFlowFunc(("address=%p, x=%d, y=%d, width=%d, height=%d\n",
2917 (void *)address, x, y, width, height));
2918
2919 CheckComArgNotNull(address);
2920 CheckComArgExpr(width, width != 0);
2921 CheckComArgExpr(height, height != 0);
2922
2923 AutoCaller autoCaller(this);
2924 if (FAILED(autoCaller.rc())) return autoCaller.rc();
2925
2926 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
2927
2928 CHECK_CONSOLE_DRV(mpDrv);
2929
2930 Console::SafeVMPtr ptrVM(mParent);
2931 if (!ptrVM.isOk())
2932 return ptrVM.rc();
2933
2934 /* Release lock because the call scheduled on EMT may also try to take it. */
2935 alock.release();
2936
2937 /*
2938 * Again we're lazy and make the graphics device do all the
2939 * dirty conversion work.
2940 */
2941 int rcVBox = VMR3ReqCallWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::drawToScreenEMT, 7,
2942 this, aScreenId, address, x, y, width, height);
2943
2944 /*
2945 * If the function returns not supported, we'll have to do all the
2946 * work ourselves using the framebuffer.
2947 */
2948 HRESULT rc = S_OK;
2949 if (rcVBox == VERR_NOT_SUPPORTED || rcVBox == VERR_NOT_IMPLEMENTED)
2950 {
2951 /** @todo implement generic fallback for screen blitting. */
2952 rc = E_NOTIMPL;
2953 }
2954 else if (RT_FAILURE(rcVBox))
2955 rc = setError(VBOX_E_IPRT_ERROR,
2956 tr("Could not draw to the screen (%Rrc)"), rcVBox);
2957//@todo
2958// else
2959// {
2960// /* All ok. Redraw the screen. */
2961// handleDisplayUpdate (x, y, width, height);
2962// }
2963
2964 LogRelFlowFunc(("rc=%Rhrc\n", rc));
2965 return rc;
2966}
2967
2968void Display::InvalidateAndUpdateEMT(Display *pDisplay, unsigned uId, bool fUpdateAll)
2969{
2970 pDisplay->vbvaLock();
2971 unsigned uScreenId;
2972 for (uScreenId = (fUpdateAll ? 0 : uId); uScreenId < pDisplay->mcMonitors; uScreenId++)
2973 {
2974 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
2975
2976 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN && !pFBInfo->pFramebuffer.isNull())
2977 {
2978 pDisplay->mpDrv->pUpPort->pfnUpdateDisplayAll(pDisplay->mpDrv->pUpPort);
2979 }
2980 else
2981 {
2982 if ( !pFBInfo->pFramebuffer.isNull()
2983 && !pFBInfo->fDisabled
2984 && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
2985 {
2986 /* Render complete VRAM screen to the framebuffer.
2987 * When framebuffer uses VRAM directly, just notify it to update.
2988 */
2989 if (pFBInfo->fDefaultFormat)
2990 {
2991 BYTE *address = NULL;
2992 ULONG uWidth = 0;
2993 ULONG uHeight = 0;
2994 pFBInfo->pFramebuffer->COMGETTER(Width) (&uWidth);
2995 pFBInfo->pFramebuffer->COMGETTER(Height) (&uHeight);
2996 HRESULT hrc = pFBInfo->pFramebuffer->COMGETTER(Address) (&address);
2997 if (SUCCEEDED(hrc) && address != NULL)
2998 {
2999 uint32_t width = pFBInfo->w;
3000 uint32_t height = pFBInfo->h;
3001
3002 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
3003 int32_t xSrc = 0;
3004 int32_t ySrc = 0;
3005 uint32_t u32SrcWidth = pFBInfo->w;
3006 uint32_t u32SrcHeight = pFBInfo->h;
3007 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
3008 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
3009
3010 /* Default format is 32 bpp. */
3011 uint8_t *pu8Dst = address;
3012 int32_t xDst = xSrc;
3013 int32_t yDst = ySrc;
3014 uint32_t u32DstWidth = u32SrcWidth;
3015 uint32_t u32DstHeight = u32SrcHeight;
3016 uint32_t u32DstLineSize = u32DstWidth * 4;
3017 uint32_t u32DstBitsPerPixel = 32;
3018
3019 /* if uWidth != pFBInfo->w and uHeight != pFBInfo->h
3020 * implies resize of Framebuffer is in progress and
3021 * copyrect should not be called.
3022 */
3023 if (uWidth == pFBInfo->w && uHeight == pFBInfo->h)
3024 {
3025
3026 pDisplay->mpDrv->pUpPort->pfnCopyRect(pDisplay->mpDrv->pUpPort,
3027 width, height,
3028 pu8Src,
3029 xSrc, ySrc,
3030 u32SrcWidth, u32SrcHeight,
3031 u32SrcLineSize, u32SrcBitsPerPixel,
3032 pu8Dst,
3033 xDst, yDst,
3034 u32DstWidth, u32DstHeight,
3035 u32DstLineSize, u32DstBitsPerPixel);
3036 }
3037 }
3038 }
3039
3040 pDisplay->handleDisplayUpdate (uScreenId, 0, 0, pFBInfo->w, pFBInfo->h);
3041 }
3042 }
3043 if (!fUpdateAll)
3044 break;
3045 }
3046 pDisplay->vbvaUnlock();
3047}
3048
3049/**
3050 * Does a full invalidation of the VM display and instructs the VM
3051 * to update it immediately.
3052 *
3053 * @returns COM status code
3054 */
3055STDMETHODIMP Display::InvalidateAndUpdate()
3056{
3057 LogRelFlowFunc(("\n"));
3058
3059 AutoCaller autoCaller(this);
3060 if (FAILED(autoCaller.rc())) return autoCaller.rc();
3061
3062 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
3063
3064 CHECK_CONSOLE_DRV(mpDrv);
3065
3066 Console::SafeVMPtr ptrVM(mParent);
3067 if (!ptrVM.isOk())
3068 return ptrVM.rc();
3069
3070 HRESULT rc = S_OK;
3071
3072 LogRelFlowFunc(("Sending DPYUPDATE request\n"));
3073
3074 /* Have to release the lock when calling EMT. */
3075 alock.release();
3076
3077 /* pdm.h says that this has to be called from the EMT thread */
3078 int rcVBox = VMR3ReqCallVoidWaitU(ptrVM.rawUVM(), VMCPUID_ANY, (PFNRT)Display::InvalidateAndUpdateEMT,
3079 3, this, 0, true);
3080 alock.acquire();
3081
3082 if (RT_FAILURE(rcVBox))
3083 rc = setError(VBOX_E_IPRT_ERROR,
3084 tr("Could not invalidate and update the screen (%Rrc)"), rcVBox);
3085
3086 LogRelFlowFunc(("rc=%Rhrc\n", rc));
3087 return rc;
3088}
3089
3090/**
3091 * Notification that the framebuffer has completed the
3092 * asynchronous resize processing
3093 *
3094 * @returns COM status code
3095 */
3096STDMETHODIMP Display::ResizeCompleted(ULONG aScreenId)
3097{
3098 LogRelFlowFunc(("\n"));
3099
3100 /// @todo (dmik) can we AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); here?
3101 // This will require general code review and may add some details.
3102 // In particular, we may want to check whether EMT is really waiting for
3103 // this notification, etc. It might be also good to obey the caller to make
3104 // sure this method is not called from more than one thread at a time
3105 // (and therefore don't use Display lock at all here to save some
3106 // milliseconds).
3107 AutoCaller autoCaller(this);
3108 if (FAILED(autoCaller.rc())) return autoCaller.rc();
3109
3110 /* this is only valid for external framebuffers */
3111 if (maFramebuffers[aScreenId].pFramebuffer == NULL)
3112 return setError(VBOX_E_NOT_SUPPORTED,
3113 tr("Resize completed notification is valid only for external framebuffers"));
3114
3115 /* Set the flag indicating that the resize has completed and display
3116 * data need to be updated. */
3117 bool f = ASMAtomicCmpXchgU32 (&maFramebuffers[aScreenId].u32ResizeStatus,
3118 ResizeStatus_UpdateDisplayData, ResizeStatus_InProgress);
3119 AssertRelease(f);NOREF(f);
3120
3121 return S_OK;
3122}
3123
3124STDMETHODIMP Display::CompleteVHWACommand(BYTE *pCommand)
3125{
3126#ifdef VBOX_WITH_VIDEOHWACCEL
3127 mpDrv->pVBVACallbacks->pfnVHWACommandCompleteAsynch(mpDrv->pVBVACallbacks, (PVBOXVHWACMD)pCommand);
3128 return S_OK;
3129#else
3130 return E_NOTIMPL;
3131#endif
3132}
3133
3134STDMETHODIMP Display::ViewportChanged(ULONG aScreenId, ULONG x, ULONG y, ULONG width, ULONG height)
3135{
3136#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
3137 BOOL is3denabled;
3138 mParent->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
3139
3140 if (is3denabled)
3141 {
3142 VBOXHGCMSVCPARM aParms[5];
3143
3144 aParms[0].type = VBOX_HGCM_SVC_PARM_32BIT;
3145 aParms[0].u.uint32 = aScreenId;
3146
3147 aParms[1].type = VBOX_HGCM_SVC_PARM_32BIT;
3148 aParms[1].u.uint32 = x;
3149
3150 aParms[2].type = VBOX_HGCM_SVC_PARM_32BIT;
3151 aParms[2].u.uint32 = y;
3152
3153
3154 aParms[3].type = VBOX_HGCM_SVC_PARM_32BIT;
3155 aParms[3].u.uint32 = width;
3156
3157 aParms[4].type = VBOX_HGCM_SVC_PARM_32BIT;
3158 aParms[4].u.uint32 = height;
3159
3160 VMMDev *pVMMDev = mParent->getVMMDev();
3161
3162 if (pVMMDev)
3163 pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_VIEWPORT_CHANGED, SHCRGL_CPARMS_VIEWPORT_CHANGED, aParms);
3164 }
3165#endif /* VBOX_WITH_CROGL && VBOX_WITH_HGCM */
3166 return S_OK;
3167}
3168
3169// private methods
3170/////////////////////////////////////////////////////////////////////////////
3171
3172/**
3173 * Helper to update the display information from the framebuffer.
3174 *
3175 * @thread EMT
3176 */
3177void Display::updateDisplayData(void)
3178{
3179 LogRelFlowFunc(("\n"));
3180
3181 /* the driver might not have been constructed yet */
3182 if (!mpDrv)
3183 return;
3184
3185#ifdef VBOX_STRICT
3186 /*
3187 * Sanity check. Note that this method may be called on EMT after Console
3188 * has started the power down procedure (but before our #drvDestruct() is
3189 * called, in which case pVM will already be NULL but mpDrv will not). Since
3190 * we don't really need pVM to proceed, we avoid this check in the release
3191 * build to save some ms (necessary to construct SafeVMPtrQuiet) in this
3192 * time-critical method.
3193 */
3194 Console::SafeVMPtrQuiet ptrVM(mParent);
3195 if (ptrVM.isOk())
3196 {
3197 PVM pVM = VMR3GetVM(ptrVM.rawUVM());
3198 Assert(VM_IS_EMT(pVM));
3199 }
3200#endif
3201
3202 /* The method is only relevant to the primary framebuffer. */
3203 IFramebuffer *pFramebuffer = maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
3204
3205 if (pFramebuffer)
3206 {
3207 HRESULT rc;
3208 BYTE *address = 0;
3209 rc = pFramebuffer->COMGETTER(Address) (&address);
3210 AssertComRC (rc);
3211 ULONG bytesPerLine = 0;
3212 rc = pFramebuffer->COMGETTER(BytesPerLine) (&bytesPerLine);
3213 AssertComRC (rc);
3214 ULONG bitsPerPixel = 0;
3215 rc = pFramebuffer->COMGETTER(BitsPerPixel) (&bitsPerPixel);
3216 AssertComRC (rc);
3217 ULONG width = 0;
3218 rc = pFramebuffer->COMGETTER(Width) (&width);
3219 AssertComRC (rc);
3220 ULONG height = 0;
3221 rc = pFramebuffer->COMGETTER(Height) (&height);
3222 AssertComRC (rc);
3223
3224 mpDrv->IConnector.pu8Data = (uint8_t *) address;
3225 mpDrv->IConnector.cbScanline = bytesPerLine;
3226 mpDrv->IConnector.cBits = bitsPerPixel;
3227 mpDrv->IConnector.cx = width;
3228 mpDrv->IConnector.cy = height;
3229 }
3230 else
3231 {
3232 /* black hole */
3233 mpDrv->IConnector.pu8Data = NULL;
3234 mpDrv->IConnector.cbScanline = 0;
3235 mpDrv->IConnector.cBits = 0;
3236 mpDrv->IConnector.cx = 0;
3237 mpDrv->IConnector.cy = 0;
3238 }
3239 LogRelFlowFunc(("leave\n"));
3240}
3241
3242#ifdef VBOX_WITH_CRHGSMI
3243void Display::setupCrHgsmiData(void)
3244{
3245 VMMDev *pVMMDev = mParent->getVMMDev();
3246 Assert(pVMMDev);
3247 int rc = VERR_GENERAL_FAILURE;
3248 if (pVMMDev)
3249 rc = pVMMDev->hgcmHostSvcHandleCreate("VBoxSharedCrOpenGL", &mhCrOglSvc);
3250
3251 if (RT_SUCCESS(rc))
3252 {
3253 Assert(mhCrOglSvc);
3254 /* setup command completion callback */
3255 VBOXVDMACMD_CHROMIUM_CTL_CRHGSMI_SETUP_COMPLETION Completion;
3256 Completion.Hdr.enmType = VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP_COMPLETION;
3257 Completion.Hdr.cbCmd = sizeof (Completion);
3258 Completion.hCompletion = mpDrv->pVBVACallbacks;
3259 Completion.pfnCompletion = mpDrv->pVBVACallbacks->pfnCrHgsmiCommandCompleteAsync;
3260
3261 VBOXHGCMSVCPARM parm;
3262 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3263 parm.u.pointer.addr = &Completion;
3264 parm.u.pointer.size = 0;
3265
3266 rc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_CRHGSMI_CTL, 1, &parm);
3267 if (RT_SUCCESS(rc))
3268 return;
3269
3270 AssertMsgFailed(("VBOXVDMACMD_CHROMIUM_CTL_TYPE_CRHGSMI_SETUP_COMPLETION failed rc %d", rc));
3271 }
3272
3273 mhCrOglSvc = NULL;
3274}
3275
3276void Display::destructCrHgsmiData(void)
3277{
3278 mhCrOglSvc = NULL;
3279}
3280#endif
3281
3282/**
3283 * Changes the current frame buffer. Called on EMT to avoid both
3284 * race conditions and excessive locking.
3285 *
3286 * @note locks this object for writing
3287 * @thread EMT
3288 */
3289/* static */
3290DECLCALLBACK(int) Display::changeFramebuffer (Display *that, IFramebuffer *aFB,
3291 unsigned uScreenId)
3292{
3293 LogRelFlowFunc(("uScreenId = %d\n", uScreenId));
3294
3295 AssertReturn(that, VERR_INVALID_PARAMETER);
3296 AssertReturn(uScreenId < that->mcMonitors, VERR_INVALID_PARAMETER);
3297
3298 AutoCaller autoCaller(that);
3299 if (FAILED(autoCaller.rc())) return autoCaller.rc();
3300
3301 AutoWriteLock alock(that COMMA_LOCKVAL_SRC_POS);
3302
3303 DISPLAYFBINFO *pDisplayFBInfo = &that->maFramebuffers[uScreenId];
3304 pDisplayFBInfo->pFramebuffer = aFB;
3305
3306 that->mParent->consoleVRDPServer()->SendResize ();
3307
3308 /* The driver might not have been constructed yet */
3309 if (that->mpDrv)
3310 {
3311 /* Setup the new framebuffer, the resize will lead to an updateDisplayData call. */
3312 DISPLAYFBINFO *pFBInfo = &that->maFramebuffers[uScreenId];
3313
3314#if defined(VBOX_WITH_CROGL)
3315 /* Release the lock, because SHCRGL_HOST_FN_SCREEN_CHANGED will read current framebuffer */
3316 {
3317 BOOL is3denabled;
3318 that->mParent->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
3319
3320 if (is3denabled)
3321 {
3322 alock.release();
3323 }
3324 }
3325#endif
3326
3327 if (pFBInfo->fVBVAEnabled && pFBInfo->pu8FramebufferVRAM)
3328 {
3329 /* This display in VBVA mode. Resize it to the last guest resolution,
3330 * if it has been reported.
3331 */
3332 that->handleDisplayResize(uScreenId, pFBInfo->u16BitsPerPixel,
3333 pFBInfo->pu8FramebufferVRAM,
3334 pFBInfo->u32LineSize,
3335 pFBInfo->w,
3336 pFBInfo->h,
3337 pFBInfo->flags);
3338 }
3339 else if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3340 {
3341 /* VGA device mode, only for the primary screen. */
3342 that->handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, that->mLastBitsPerPixel,
3343 that->mLastAddress,
3344 that->mLastBytesPerLine,
3345 that->mLastWidth,
3346 that->mLastHeight,
3347 that->mLastFlags);
3348 }
3349 }
3350
3351 LogRelFlowFunc(("leave\n"));
3352 return VINF_SUCCESS;
3353}
3354
3355/**
3356 * Handle display resize event issued by the VGA device for the primary screen.
3357 *
3358 * @see PDMIDISPLAYCONNECTOR::pfnResize
3359 */
3360DECLCALLBACK(int) Display::displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface,
3361 uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy)
3362{
3363 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3364
3365 LogRelFlowFunc(("bpp %d, pvVRAM %p, cbLine %d, cx %d, cy %d\n",
3366 bpp, pvVRAM, cbLine, cx, cy));
3367
3368 return pDrv->pDisplay->handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, bpp, pvVRAM, cbLine, cx, cy, VBVA_SCREEN_F_ACTIVE);
3369}
3370
3371/**
3372 * Handle display update.
3373 *
3374 * @see PDMIDISPLAYCONNECTOR::pfnUpdateRect
3375 */
3376DECLCALLBACK(void) Display::displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
3377 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
3378{
3379 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3380
3381#ifdef DEBUG_sunlover
3382 LogFlowFunc(("mfVideoAccelEnabled = %d, %d,%d %dx%d\n",
3383 pDrv->pDisplay->mfVideoAccelEnabled, x, y, cx, cy));
3384#endif /* DEBUG_sunlover */
3385
3386 /* This call does update regardless of VBVA status.
3387 * But in VBVA mode this is called only as result of
3388 * pfnUpdateDisplayAll in the VGA device.
3389 */
3390
3391 pDrv->pDisplay->handleDisplayUpdate(VBOX_VIDEO_PRIMARY_SCREEN, x, y, cx, cy);
3392}
3393
3394/**
3395 * Periodic display refresh callback.
3396 *
3397 * @see PDMIDISPLAYCONNECTOR::pfnRefresh
3398 * @thread EMT
3399 */
3400DECLCALLBACK(void) Display::displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface)
3401{
3402 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3403
3404#ifdef DEBUG_sunlover
3405 STAM_PROFILE_START(&g_StatDisplayRefresh, a);
3406#endif /* DEBUG_sunlover */
3407
3408#ifdef DEBUG_sunlover_2
3409 LogFlowFunc(("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
3410 pDrv->pDisplay->mfVideoAccelEnabled));
3411#endif /* DEBUG_sunlover_2 */
3412
3413 Display *pDisplay = pDrv->pDisplay;
3414 bool fNoUpdate = false; /* Do not update the display if any of the framebuffers is being resized. */
3415 unsigned uScreenId;
3416
3417 Log2(("DisplayRefreshCallback\n"));
3418 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3419 {
3420 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3421
3422 /* Check the resize status. The status can be checked normally because
3423 * the status affects only the EMT.
3424 */
3425 uint32_t u32ResizeStatus = pFBInfo->u32ResizeStatus;
3426
3427 if (u32ResizeStatus == ResizeStatus_UpdateDisplayData)
3428 {
3429 LogRelFlowFunc(("ResizeStatus_UpdateDisplayData %d\n", uScreenId));
3430 fNoUpdate = true; /* Always set it here, because pfnUpdateDisplayAll can cause a new resize. */
3431 /* The framebuffer was resized and display data need to be updated. */
3432 pDisplay->handleResizeCompletedEMT ();
3433 if (pFBInfo->u32ResizeStatus != ResizeStatus_Void)
3434 {
3435 /* The resize status could be not Void here because a pending resize is issued. */
3436 continue;
3437 }
3438 /* Continue with normal processing because the status here is ResizeStatus_Void.
3439 * Repaint all displays because VM continued to run during the framebuffer resize.
3440 */
3441 pDisplay->InvalidateAndUpdateEMT(pDisplay, uScreenId, false);
3442 }
3443 else if (u32ResizeStatus == ResizeStatus_InProgress)
3444 {
3445 /* The framebuffer is being resized. Do not call the VGA device back. Immediately return. */
3446 LogRelFlowFunc(("ResizeStatus_InProcess\n"));
3447 fNoUpdate = true;
3448 continue;
3449 }
3450 }
3451
3452 if (!fNoUpdate)
3453 {
3454 int rc = pDisplay->videoAccelRefreshProcess();
3455 if (rc != VINF_TRY_AGAIN) /* Means 'do nothing' here. */
3456 {
3457 if (rc == VWRN_INVALID_STATE)
3458 {
3459 /* No VBVA do a display update. */
3460 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN];
3461 if (!pFBInfo->pFramebuffer.isNull() && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
3462 {
3463 Assert(pDrv->IConnector.pu8Data);
3464 pDisplay->vbvaLock();
3465 pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
3466 pDisplay->vbvaUnlock();
3467 }
3468 }
3469
3470 /* Inform the VRDP server that the current display update sequence is
3471 * completed. At this moment the framebuffer memory contains a definite
3472 * image, that is synchronized with the orders already sent to VRDP client.
3473 * The server can now process redraw requests from clients or initial
3474 * fullscreen updates for new clients.
3475 */
3476 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3477 {
3478 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3479
3480 if (!pFBInfo->pFramebuffer.isNull() && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
3481 {
3482 Assert (pDisplay->mParent && pDisplay->mParent->consoleVRDPServer());
3483 pDisplay->mParent->consoleVRDPServer()->SendUpdate (uScreenId, NULL, 0);
3484 }
3485 }
3486 }
3487 }
3488
3489#ifdef VBOX_WITH_VPX
3490 if (VideoRecIsEnabled(pDisplay->mpVideoRecCtx))
3491 {
3492 uint64_t u64Now = RTTimeProgramMilliTS();
3493 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
3494 {
3495 if (!pDisplay->maVideoRecEnabled[uScreenId])
3496 continue;
3497
3498 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
3499
3500 if ( !pFBInfo->pFramebuffer.isNull()
3501 && !pFBInfo->fDisabled
3502 && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
3503 {
3504 int rc;
3505 if ( pFBInfo->fVBVAEnabled
3506 && pFBInfo->pu8FramebufferVRAM)
3507 {
3508 rc = VideoRecCopyToIntBuf(pDisplay->mpVideoRecCtx, uScreenId, 0, 0,
3509 FramebufferPixelFormat_FOURCC_RGB,
3510 pFBInfo->u16BitsPerPixel,
3511 pFBInfo->u32LineSize, pFBInfo->w, pFBInfo->h,
3512 pFBInfo->pu8FramebufferVRAM, u64Now);
3513 }
3514 else
3515 {
3516 rc = VideoRecCopyToIntBuf(pDisplay->mpVideoRecCtx, uScreenId, 0, 0,
3517 FramebufferPixelFormat_FOURCC_RGB,
3518 pDrv->IConnector.cBits,
3519 pDrv->IConnector.cbScanline, pDrv->IConnector.cx,
3520 pDrv->IConnector.cy, pDrv->IConnector.pu8Data, u64Now);
3521 }
3522 if (rc == VINF_TRY_AGAIN)
3523 break;
3524 }
3525 }
3526 }
3527#endif
3528
3529#ifdef DEBUG_sunlover
3530 STAM_PROFILE_STOP(&g_StatDisplayRefresh, a);
3531#endif /* DEBUG_sunlover */
3532#ifdef DEBUG_sunlover_2
3533 LogFlowFunc(("leave\n"));
3534#endif /* DEBUG_sunlover_2 */
3535}
3536
3537/**
3538 * Reset notification
3539 *
3540 * @see PDMIDISPLAYCONNECTOR::pfnReset
3541 */
3542DECLCALLBACK(void) Display::displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface)
3543{
3544 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3545
3546 LogRelFlowFunc(("\n"));
3547
3548 /* Disable VBVA mode. */
3549 pDrv->pDisplay->VideoAccelEnable (false, NULL);
3550}
3551
3552/**
3553 * LFBModeChange notification
3554 *
3555 * @see PDMIDISPLAYCONNECTOR::pfnLFBModeChange
3556 */
3557DECLCALLBACK(void) Display::displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled)
3558{
3559 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3560
3561 LogRelFlowFunc(("fEnabled=%d\n", fEnabled));
3562
3563 NOREF(fEnabled);
3564
3565 /* Disable VBVA mode in any case. The guest driver reenables VBVA mode if necessary. */
3566 /* The LFBModeChange function is called under DevVGA lock. Postpone disabling VBVA, do it in the refresh timer. */
3567 ASMAtomicWriteU32(&pDrv->pDisplay->mfu32PendingVideoAccelDisable, true);
3568}
3569
3570/**
3571 * Adapter information change notification.
3572 *
3573 * @see PDMIDISPLAYCONNECTOR::pfnProcessAdapterData
3574 */
3575DECLCALLBACK(void) Display::displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize)
3576{
3577 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3578
3579 if (pvVRAM == NULL)
3580 {
3581 unsigned i;
3582 for (i = 0; i < pDrv->pDisplay->mcMonitors; i++)
3583 {
3584 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[i];
3585
3586 pFBInfo->u32Offset = 0;
3587 pFBInfo->u32MaxFramebufferSize = 0;
3588 pFBInfo->u32InformationSize = 0;
3589 }
3590 }
3591#ifndef VBOX_WITH_HGSMI
3592 else
3593 {
3594 uint8_t *pu8 = (uint8_t *)pvVRAM;
3595 pu8 += u32VRAMSize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE;
3596
3597 // @todo
3598 uint8_t *pu8End = pu8 + VBOX_VIDEO_ADAPTER_INFORMATION_SIZE;
3599
3600 VBOXVIDEOINFOHDR *pHdr;
3601
3602 for (;;)
3603 {
3604 pHdr = (VBOXVIDEOINFOHDR *)pu8;
3605 pu8 += sizeof (VBOXVIDEOINFOHDR);
3606
3607 if (pu8 >= pu8End)
3608 {
3609 LogRel(("VBoxVideo: Guest adapter information overflow!!!\n"));
3610 break;
3611 }
3612
3613 if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_DISPLAY)
3614 {
3615 if (pHdr->u16Length != sizeof (VBOXVIDEOINFODISPLAY))
3616 {
3617 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "DISPLAY", pHdr->u16Length));
3618 break;
3619 }
3620
3621 VBOXVIDEOINFODISPLAY *pDisplay = (VBOXVIDEOINFODISPLAY *)pu8;
3622
3623 if (pDisplay->u32Index >= pDrv->pDisplay->mcMonitors)
3624 {
3625 LogRel(("VBoxVideo: Guest adapter information invalid display index %d!!!\n", pDisplay->u32Index));
3626 break;
3627 }
3628
3629 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[pDisplay->u32Index];
3630
3631 pFBInfo->u32Offset = pDisplay->u32Offset;
3632 pFBInfo->u32MaxFramebufferSize = pDisplay->u32FramebufferSize;
3633 pFBInfo->u32InformationSize = pDisplay->u32InformationSize;
3634
3635 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));
3636 }
3637 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_QUERY_CONF32)
3638 {
3639 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOQUERYCONF32))
3640 {
3641 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "CONF32", pHdr->u16Length));
3642 break;
3643 }
3644
3645 VBOXVIDEOINFOQUERYCONF32 *pConf32 = (VBOXVIDEOINFOQUERYCONF32 *)pu8;
3646
3647 switch (pConf32->u32Index)
3648 {
3649 case VBOX_VIDEO_QCI32_MONITOR_COUNT:
3650 {
3651 pConf32->u32Value = pDrv->pDisplay->mcMonitors;
3652 } break;
3653
3654 case VBOX_VIDEO_QCI32_OFFSCREEN_HEAP_SIZE:
3655 {
3656 /* @todo make configurable. */
3657 pConf32->u32Value = _1M;
3658 } break;
3659
3660 default:
3661 LogRel(("VBoxVideo: CONF32 %d not supported!!! Skipping.\n", pConf32->u32Index));
3662 }
3663 }
3664 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_END)
3665 {
3666 if (pHdr->u16Length != 0)
3667 {
3668 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "END", pHdr->u16Length));
3669 break;
3670 }
3671
3672 break;
3673 }
3674 else if (pHdr->u8Type != VBOX_VIDEO_INFO_TYPE_NV_HEAP) /** @todo why is Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp pushing this to us? */
3675 {
3676 LogRel(("Guest adapter information contains unsupported type %d. The block has been skipped.\n", pHdr->u8Type));
3677 }
3678
3679 pu8 += pHdr->u16Length;
3680 }
3681 }
3682#endif /* !VBOX_WITH_HGSMI */
3683}
3684
3685/**
3686 * Display information change notification.
3687 *
3688 * @see PDMIDISPLAYCONNECTOR::pfnProcessDisplayData
3689 */
3690DECLCALLBACK(void) Display::displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId)
3691{
3692 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3693
3694 if (uScreenId >= pDrv->pDisplay->mcMonitors)
3695 {
3696 LogRel(("VBoxVideo: Guest display information invalid display index %d!!!\n", uScreenId));
3697 return;
3698 }
3699
3700 /* Get the display information structure. */
3701 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[uScreenId];
3702
3703 uint8_t *pu8 = (uint8_t *)pvVRAM;
3704 pu8 += pFBInfo->u32Offset + pFBInfo->u32MaxFramebufferSize;
3705
3706 // @todo
3707 uint8_t *pu8End = pu8 + pFBInfo->u32InformationSize;
3708
3709 VBOXVIDEOINFOHDR *pHdr;
3710
3711 for (;;)
3712 {
3713 pHdr = (VBOXVIDEOINFOHDR *)pu8;
3714 pu8 += sizeof (VBOXVIDEOINFOHDR);
3715
3716 if (pu8 >= pu8End)
3717 {
3718 LogRel(("VBoxVideo: Guest display information overflow!!!\n"));
3719 break;
3720 }
3721
3722 if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_SCREEN)
3723 {
3724 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOSCREEN))
3725 {
3726 LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "SCREEN", pHdr->u16Length));
3727 break;
3728 }
3729
3730 VBOXVIDEOINFOSCREEN *pScreen = (VBOXVIDEOINFOSCREEN *)pu8;
3731
3732 pFBInfo->xOrigin = pScreen->xOrigin;
3733 pFBInfo->yOrigin = pScreen->yOrigin;
3734
3735 pFBInfo->w = pScreen->u16Width;
3736 pFBInfo->h = pScreen->u16Height;
3737
3738 LogRelFlow(("VBOX_VIDEO_INFO_TYPE_SCREEN: (%p) %d: at %d,%d, linesize 0x%X, size %dx%d, bpp %d, flags 0x%02X\n",
3739 pHdr, uScreenId, pScreen->xOrigin, pScreen->yOrigin, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height, pScreen->bitsPerPixel, pScreen->u8Flags));
3740
3741 if (uScreenId != VBOX_VIDEO_PRIMARY_SCREEN)
3742 {
3743 /* Primary screen resize is eeeeeeeee by the VGA device. */
3744 if (pFBInfo->fDisabled)
3745 {
3746 pFBInfo->fDisabled = false;
3747 fireGuestMonitorChangedEvent(pDrv->pDisplay->mParent->getEventSource(),
3748 GuestMonitorChangedEventType_Enabled,
3749 uScreenId,
3750 pFBInfo->xOrigin, pFBInfo->yOrigin,
3751 pFBInfo->w, pFBInfo->h);
3752 }
3753
3754 pDrv->pDisplay->handleDisplayResize(uScreenId, pScreen->bitsPerPixel, (uint8_t *)pvVRAM + pFBInfo->u32Offset, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height, VBVA_SCREEN_F_ACTIVE);
3755 }
3756 }
3757 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_END)
3758 {
3759 if (pHdr->u16Length != 0)
3760 {
3761 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "END", pHdr->u16Length));
3762 break;
3763 }
3764
3765 break;
3766 }
3767 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_HOST_EVENTS)
3768 {
3769 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOHOSTEVENTS))
3770 {
3771 LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "HOST_EVENTS", pHdr->u16Length));
3772 break;
3773 }
3774
3775 VBOXVIDEOINFOHOSTEVENTS *pHostEvents = (VBOXVIDEOINFOHOSTEVENTS *)pu8;
3776
3777 pFBInfo->pHostEvents = pHostEvents;
3778
3779 LogFlow(("VBOX_VIDEO_INFO_TYPE_HOSTEVENTS: (%p)\n",
3780 pHostEvents));
3781 }
3782 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_LINK)
3783 {
3784 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOLINK))
3785 {
3786 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "LINK", pHdr->u16Length));
3787 break;
3788 }
3789
3790 VBOXVIDEOINFOLINK *pLink = (VBOXVIDEOINFOLINK *)pu8;
3791 pu8 += pLink->i32Offset;
3792 }
3793 else
3794 {
3795 LogRel(("Guest display information contains unsupported type %d\n", pHdr->u8Type));
3796 }
3797
3798 pu8 += pHdr->u16Length;
3799 }
3800}
3801
3802#ifdef VBOX_WITH_VIDEOHWACCEL
3803
3804void Display::handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
3805{
3806 unsigned id = (unsigned)pCommand->iDisplay;
3807 int rc = VINF_SUCCESS;
3808 if (id < mcMonitors)
3809 {
3810 IFramebuffer *pFramebuffer = maFramebuffers[id].pFramebuffer;
3811#ifdef DEBUG_misha
3812 Assert (pFramebuffer);
3813#endif
3814
3815 if (pFramebuffer != NULL)
3816 {
3817 HRESULT hr = pFramebuffer->ProcessVHWACommand((BYTE*)pCommand);
3818 if (FAILED(hr))
3819 {
3820 rc = (hr == E_NOTIMPL) ? VERR_NOT_IMPLEMENTED : VERR_GENERAL_FAILURE;
3821 }
3822 }
3823 else
3824 {
3825 rc = VERR_NOT_IMPLEMENTED;
3826 }
3827 }
3828 else
3829 {
3830 rc = VERR_INVALID_PARAMETER;
3831 }
3832
3833 if (RT_FAILURE(rc))
3834 {
3835 /* tell the guest the command is complete */
3836 pCommand->Flags &= (~VBOXVHWACMD_FLAG_HG_ASYNCH);
3837 pCommand->rc = rc;
3838 }
3839}
3840
3841DECLCALLBACK(void) Display::displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
3842{
3843 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3844
3845 pDrv->pDisplay->handleVHWACommandProcess(pInterface, pCommand);
3846}
3847#endif
3848
3849#ifdef VBOX_WITH_CRHGSMI
3850void Display::handleCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam)
3851{
3852 mpDrv->pVBVACallbacks->pfnCrHgsmiCommandCompleteAsync(mpDrv->pVBVACallbacks, (PVBOXVDMACMD_CHROMIUM_CMD)pParam->u.pointer.addr, result);
3853}
3854
3855void Display::handleCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam)
3856{
3857 mpDrv->pVBVACallbacks->pfnCrHgsmiControlCompleteAsync(mpDrv->pVBVACallbacks, (PVBOXVDMACMD_CHROMIUM_CTL)pParam->u.pointer.addr, result);
3858}
3859
3860void Display::handleCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd)
3861{
3862 int rc = VERR_INVALID_FUNCTION;
3863 VBOXHGCMSVCPARM parm;
3864 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3865 parm.u.pointer.addr = pCmd;
3866 parm.u.pointer.size = cbCmd;
3867
3868 if (mhCrOglSvc)
3869 {
3870 VMMDev *pVMMDev = mParent->getVMMDev();
3871 if (pVMMDev)
3872 {
3873 /* no completion callback is specified with this call,
3874 * the CrOgl code will complete the CrHgsmi command once it processes it */
3875 rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CRHGSMI_CMD, &parm, NULL, NULL);
3876 AssertRC(rc);
3877 if (RT_SUCCESS(rc))
3878 return;
3879 }
3880 else
3881 rc = VERR_INVALID_STATE;
3882 }
3883
3884 /* we are here because something went wrong with command processing, complete it */
3885 handleCrHgsmiCommandCompletion(rc, SHCRGL_HOST_FN_CRHGSMI_CMD, &parm);
3886}
3887
3888void Display::handleCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCtl, uint32_t cbCtl)
3889{
3890 int rc = VERR_INVALID_FUNCTION;
3891 VBOXHGCMSVCPARM parm;
3892 parm.type = VBOX_HGCM_SVC_PARM_PTR;
3893 parm.u.pointer.addr = pCtl;
3894 parm.u.pointer.size = cbCtl;
3895
3896 if (mhCrOglSvc)
3897 {
3898 VMMDev *pVMMDev = mParent->getVMMDev();
3899 if (pVMMDev)
3900 {
3901 rc = pVMMDev->hgcmHostFastCallAsync(mhCrOglSvc, SHCRGL_HOST_FN_CRHGSMI_CTL, &parm, Display::displayCrHgsmiControlCompletion, this);
3902 AssertRC(rc);
3903 if (RT_SUCCESS(rc))
3904 return;
3905 }
3906 else
3907 rc = VERR_INVALID_STATE;
3908 }
3909
3910 /* we are here because something went wrong with command processing, complete it */
3911 handleCrHgsmiControlCompletion(rc, SHCRGL_HOST_FN_CRHGSMI_CTL, &parm);
3912}
3913
3914
3915DECLCALLBACK(void) Display::displayCrHgsmiCommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CMD pCmd, uint32_t cbCmd)
3916{
3917 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3918
3919 pDrv->pDisplay->handleCrHgsmiCommandProcess(pInterface, pCmd, cbCmd);
3920}
3921
3922DECLCALLBACK(void) Display::displayCrHgsmiControlProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVDMACMD_CHROMIUM_CTL pCmd, uint32_t cbCmd)
3923{
3924 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3925
3926 pDrv->pDisplay->handleCrHgsmiControlProcess(pInterface, pCmd, cbCmd);
3927}
3928
3929DECLCALLBACK(void) Display::displayCrHgsmiCommandCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext)
3930{
3931 AssertMsgFailed(("not expected!"));
3932 Display *pDisplay = (Display *)pvContext;
3933 pDisplay->handleCrHgsmiCommandCompletion(result, u32Function, pParam);
3934}
3935
3936DECLCALLBACK(void) Display::displayCrHgsmiControlCompletion(int32_t result, uint32_t u32Function, PVBOXHGCMSVCPARM pParam, void *pvContext)
3937{
3938 Display *pDisplay = (Display *)pvContext;
3939 pDisplay->handleCrHgsmiControlCompletion(result, u32Function, pParam);
3940}
3941#endif
3942
3943
3944#ifdef VBOX_WITH_HGSMI
3945DECLCALLBACK(int) Display::displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, PVBVAHOSTFLAGS pHostFlags)
3946{
3947 LogRelFlowFunc(("uScreenId %d\n", uScreenId));
3948
3949 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3950 Display *pThis = pDrv->pDisplay;
3951
3952 pThis->maFramebuffers[uScreenId].fVBVAEnabled = true;
3953 pThis->maFramebuffers[uScreenId].pVBVAHostFlags = pHostFlags;
3954
3955 vbvaSetMemoryFlagsHGSMI(uScreenId, pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, &pThis->maFramebuffers[uScreenId]);
3956
3957 return VINF_SUCCESS;
3958}
3959
3960DECLCALLBACK(void) Display::displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
3961{
3962 LogRelFlowFunc(("uScreenId %d\n", uScreenId));
3963
3964 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
3965 Display *pThis = pDrv->pDisplay;
3966
3967 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
3968
3969 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
3970 {
3971 /* Make sure that the primary screen is visible now.
3972 * The guest can't use VBVA anymore, so only only the VGA device output works.
3973 */
3974 if (pFBInfo->fDisabled)
3975 {
3976 pFBInfo->fDisabled = false;
3977 fireGuestMonitorChangedEvent(pThis->mParent->getEventSource(),
3978 GuestMonitorChangedEventType_Enabled,
3979 uScreenId,
3980 pFBInfo->xOrigin, pFBInfo->yOrigin,
3981 pFBInfo->w, pFBInfo->h);
3982 }
3983 }
3984
3985 pFBInfo->fVBVAEnabled = false;
3986
3987 vbvaSetMemoryFlagsHGSMI(uScreenId, 0, false, pFBInfo);
3988
3989 pFBInfo->pVBVAHostFlags = NULL;
3990
3991 pFBInfo->u32Offset = 0; /* Not used in HGSMI. */
3992 pFBInfo->u32MaxFramebufferSize = 0; /* Not used in HGSMI. */
3993 pFBInfo->u32InformationSize = 0; /* Not used in HGSMI. */
3994
3995 pFBInfo->xOrigin = 0;
3996 pFBInfo->yOrigin = 0;
3997
3998 pFBInfo->w = 0;
3999 pFBInfo->h = 0;
4000
4001 pFBInfo->u16BitsPerPixel = 0;
4002 pFBInfo->pu8FramebufferVRAM = NULL;
4003 pFBInfo->u32LineSize = 0;
4004}
4005
4006DECLCALLBACK(void) Display::displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
4007{
4008 LogFlowFunc(("uScreenId %d\n", uScreenId));
4009
4010 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
4011 Display *pThis = pDrv->pDisplay;
4012 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
4013
4014 if (ASMAtomicReadU32(&pThis->mu32UpdateVBVAFlags) > 0)
4015 {
4016 vbvaSetMemoryFlagsAllHGSMI(pThis->mfu32SupportedOrders, pThis->mfVideoAccelVRDP, pThis->maFramebuffers, pThis->mcMonitors);
4017 ASMAtomicDecU32(&pThis->mu32UpdateVBVAFlags);
4018 }
4019
4020 if (RT_LIKELY(pFBInfo->u32ResizeStatus == ResizeStatus_Void))
4021 {
4022 if (RT_UNLIKELY(pFBInfo->cVBVASkipUpdate != 0))
4023 {
4024 /* Some updates were skipped. Note: displayVBVAUpdate* callbacks are called
4025 * under display device lock, so thread safe.
4026 */
4027 pFBInfo->cVBVASkipUpdate = 0;
4028 pThis->handleDisplayUpdate(uScreenId, pFBInfo->vbvaSkippedRect.xLeft - pFBInfo->xOrigin,
4029 pFBInfo->vbvaSkippedRect.yTop - pFBInfo->yOrigin,
4030 pFBInfo->vbvaSkippedRect.xRight - pFBInfo->vbvaSkippedRect.xLeft,
4031 pFBInfo->vbvaSkippedRect.yBottom - pFBInfo->vbvaSkippedRect.yTop);
4032 }
4033 }
4034 else
4035 {
4036 /* The framebuffer is being resized. */
4037 pFBInfo->cVBVASkipUpdate++;
4038 }
4039}
4040
4041DECLCALLBACK(void) Display::displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd)
4042{
4043 LogFlowFunc(("uScreenId %d pCmd %p cbCmd %d, @%d,%d %dx%d\n", uScreenId, pCmd, cbCmd, pCmd->x, pCmd->y, pCmd->w, pCmd->h));
4044
4045 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
4046 Display *pThis = pDrv->pDisplay;
4047 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
4048
4049 if (RT_LIKELY(pFBInfo->cVBVASkipUpdate == 0))
4050 {
4051 if (pFBInfo->fDefaultFormat)
4052 {
4053 /* Make sure that framebuffer contains the same image as the guest VRAM. */
4054 if ( uScreenId == VBOX_VIDEO_PRIMARY_SCREEN
4055 && !pFBInfo->pFramebuffer.isNull()
4056 && !pFBInfo->fDisabled)
4057 {
4058 pDrv->pUpPort->pfnUpdateDisplayRect (pDrv->pUpPort, pCmd->x, pCmd->y, pCmd->w, pCmd->h);
4059 }
4060 else if ( !pFBInfo->pFramebuffer.isNull()
4061 && !pFBInfo->fDisabled)
4062 {
4063 /* Render VRAM content to the framebuffer. */
4064 BYTE *address = NULL;
4065 HRESULT hrc = pFBInfo->pFramebuffer->COMGETTER(Address) (&address);
4066 if (SUCCEEDED(hrc) && address != NULL)
4067 {
4068 uint32_t width = pCmd->w;
4069 uint32_t height = pCmd->h;
4070
4071 const uint8_t *pu8Src = pFBInfo->pu8FramebufferVRAM;
4072 int32_t xSrc = pCmd->x - pFBInfo->xOrigin;
4073 int32_t ySrc = pCmd->y - pFBInfo->yOrigin;
4074 uint32_t u32SrcWidth = pFBInfo->w;
4075 uint32_t u32SrcHeight = pFBInfo->h;
4076 uint32_t u32SrcLineSize = pFBInfo->u32LineSize;
4077 uint32_t u32SrcBitsPerPixel = pFBInfo->u16BitsPerPixel;
4078
4079 uint8_t *pu8Dst = address;
4080 int32_t xDst = xSrc;
4081 int32_t yDst = ySrc;
4082 uint32_t u32DstWidth = u32SrcWidth;
4083 uint32_t u32DstHeight = u32SrcHeight;
4084 uint32_t u32DstLineSize = u32DstWidth * 4;
4085 uint32_t u32DstBitsPerPixel = 32;
4086
4087 pDrv->pUpPort->pfnCopyRect(pDrv->pUpPort,
4088 width, height,
4089 pu8Src,
4090 xSrc, ySrc,
4091 u32SrcWidth, u32SrcHeight,
4092 u32SrcLineSize, u32SrcBitsPerPixel,
4093 pu8Dst,
4094 xDst, yDst,
4095 u32DstWidth, u32DstHeight,
4096 u32DstLineSize, u32DstBitsPerPixel);
4097 }
4098 }
4099 }
4100
4101 VBVACMDHDR hdrSaved = *pCmd;
4102
4103 VBVACMDHDR *pHdrUnconst = (VBVACMDHDR *)pCmd;
4104
4105 pHdrUnconst->x -= (int16_t)pFBInfo->xOrigin;
4106 pHdrUnconst->y -= (int16_t)pFBInfo->yOrigin;
4107
4108 /* @todo new SendUpdate entry which can get a separate cmd header or coords. */
4109 pThis->mParent->consoleVRDPServer()->SendUpdate (uScreenId, pCmd, (uint32_t)cbCmd);
4110
4111 *pHdrUnconst = hdrSaved;
4112 }
4113}
4114
4115DECLCALLBACK(void) Display::displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, int32_t x, int32_t y, uint32_t cx, uint32_t cy)
4116{
4117 LogFlowFunc(("uScreenId %d %d,%d %dx%d\n", uScreenId, x, y, cx, cy));
4118
4119 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
4120 Display *pThis = pDrv->pDisplay;
4121 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[uScreenId];
4122
4123 /* @todo handleFramebufferUpdate (uScreenId,
4124 * x - pThis->maFramebuffers[uScreenId].xOrigin,
4125 * y - pThis->maFramebuffers[uScreenId].yOrigin,
4126 * cx, cy);
4127 */
4128 if (RT_LIKELY(pFBInfo->cVBVASkipUpdate == 0))
4129 {
4130 pThis->handleDisplayUpdate(uScreenId, x - pFBInfo->xOrigin, y - pFBInfo->yOrigin, cx, cy);
4131 }
4132 else
4133 {
4134 /* Save the updated rectangle. */
4135 int32_t xRight = x + cx;
4136 int32_t yBottom = y + cy;
4137
4138 if (pFBInfo->cVBVASkipUpdate == 1)
4139 {
4140 pFBInfo->vbvaSkippedRect.xLeft = x;
4141 pFBInfo->vbvaSkippedRect.yTop = y;
4142 pFBInfo->vbvaSkippedRect.xRight = xRight;
4143 pFBInfo->vbvaSkippedRect.yBottom = yBottom;
4144 }
4145 else
4146 {
4147 if (pFBInfo->vbvaSkippedRect.xLeft > x)
4148 {
4149 pFBInfo->vbvaSkippedRect.xLeft = x;
4150 }
4151 if (pFBInfo->vbvaSkippedRect.yTop > y)
4152 {
4153 pFBInfo->vbvaSkippedRect.yTop = y;
4154 }
4155 if (pFBInfo->vbvaSkippedRect.xRight < xRight)
4156 {
4157 pFBInfo->vbvaSkippedRect.xRight = xRight;
4158 }
4159 if (pFBInfo->vbvaSkippedRect.yBottom < yBottom)
4160 {
4161 pFBInfo->vbvaSkippedRect.yBottom = yBottom;
4162 }
4163 }
4164 }
4165}
4166
4167#ifdef DEBUG_sunlover
4168static void logVBVAResize(const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, const DISPLAYFBINFO *pFBInfo)
4169{
4170 LogRel(("displayVBVAResize: [%d] %s\n"
4171 " pView->u32ViewIndex %d\n"
4172 " pView->u32ViewOffset 0x%08X\n"
4173 " pView->u32ViewSize 0x%08X\n"
4174 " pView->u32MaxScreenSize 0x%08X\n"
4175 " pScreen->i32OriginX %d\n"
4176 " pScreen->i32OriginY %d\n"
4177 " pScreen->u32StartOffset 0x%08X\n"
4178 " pScreen->u32LineSize 0x%08X\n"
4179 " pScreen->u32Width %d\n"
4180 " pScreen->u32Height %d\n"
4181 " pScreen->u16BitsPerPixel %d\n"
4182 " pScreen->u16Flags 0x%04X\n"
4183 " pFBInfo->u32Offset 0x%08X\n"
4184 " pFBInfo->u32MaxFramebufferSize 0x%08X\n"
4185 " pFBInfo->u32InformationSize 0x%08X\n"
4186 " pFBInfo->fDisabled %d\n"
4187 " xOrigin, yOrigin, w, h: %d,%d %dx%d\n"
4188 " pFBInfo->u16BitsPerPixel %d\n"
4189 " pFBInfo->pu8FramebufferVRAM %p\n"
4190 " pFBInfo->u32LineSize 0x%08X\n"
4191 " pFBInfo->flags 0x%04X\n"
4192 " pFBInfo->pHostEvents %p\n"
4193 " pFBInfo->u32ResizeStatus %d\n"
4194 " pFBInfo->fDefaultFormat %d\n"
4195 " dirtyRect %d-%d %d-%d\n"
4196 " pFBInfo->pendingResize.fPending %d\n"
4197 " pFBInfo->pendingResize.pixelFormat %d\n"
4198 " pFBInfo->pendingResize.pvVRAM %p\n"
4199 " pFBInfo->pendingResize.bpp %d\n"
4200 " pFBInfo->pendingResize.cbLine 0x%08X\n"
4201 " pFBInfo->pendingResize.w,h %dx%d\n"
4202 " pFBInfo->pendingResize.flags 0x%04X\n"
4203 " pFBInfo->fVBVAEnabled %d\n"
4204 " pFBInfo->cVBVASkipUpdate %d\n"
4205 " pFBInfo->vbvaSkippedRect %d-%d %d-%d\n"
4206 " pFBInfo->pVBVAHostFlags %p\n"
4207 "",
4208 pScreen->u32ViewIndex,
4209 (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)? "DISABLED": "ENABLED",
4210 pView->u32ViewIndex,
4211 pView->u32ViewOffset,
4212 pView->u32ViewSize,
4213 pView->u32MaxScreenSize,
4214 pScreen->i32OriginX,
4215 pScreen->i32OriginY,
4216 pScreen->u32StartOffset,
4217 pScreen->u32LineSize,
4218 pScreen->u32Width,
4219 pScreen->u32Height,
4220 pScreen->u16BitsPerPixel,
4221 pScreen->u16Flags,
4222 pFBInfo->u32Offset,
4223 pFBInfo->u32MaxFramebufferSize,
4224 pFBInfo->u32InformationSize,
4225 pFBInfo->fDisabled,
4226 pFBInfo->xOrigin,
4227 pFBInfo->yOrigin,
4228 pFBInfo->w,
4229 pFBInfo->h,
4230 pFBInfo->u16BitsPerPixel,
4231 pFBInfo->pu8FramebufferVRAM,
4232 pFBInfo->u32LineSize,
4233 pFBInfo->flags,
4234 pFBInfo->pHostEvents,
4235 pFBInfo->u32ResizeStatus,
4236 pFBInfo->fDefaultFormat,
4237 pFBInfo->dirtyRect.xLeft,
4238 pFBInfo->dirtyRect.xRight,
4239 pFBInfo->dirtyRect.yTop,
4240 pFBInfo->dirtyRect.yBottom,
4241 pFBInfo->pendingResize.fPending,
4242 pFBInfo->pendingResize.pixelFormat,
4243 pFBInfo->pendingResize.pvVRAM,
4244 pFBInfo->pendingResize.bpp,
4245 pFBInfo->pendingResize.cbLine,
4246 pFBInfo->pendingResize.w,
4247 pFBInfo->pendingResize.h,
4248 pFBInfo->pendingResize.flags,
4249 pFBInfo->fVBVAEnabled,
4250 pFBInfo->cVBVASkipUpdate,
4251 pFBInfo->vbvaSkippedRect.xLeft,
4252 pFBInfo->vbvaSkippedRect.yTop,
4253 pFBInfo->vbvaSkippedRect.xRight,
4254 pFBInfo->vbvaSkippedRect.yBottom,
4255 pFBInfo->pVBVAHostFlags
4256 ));
4257}
4258#endif /* DEBUG_sunlover */
4259
4260DECLCALLBACK(int) Display::displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM)
4261{
4262 LogRelFlowFunc(("pScreen %p, pvVRAM %p\n", pScreen, pvVRAM));
4263
4264 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
4265 Display *pThis = pDrv->pDisplay;
4266
4267 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[pScreen->u32ViewIndex];
4268
4269 if (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)
4270 {
4271 pFBInfo->fDisabled = true;
4272 pFBInfo->flags = pScreen->u16Flags;
4273
4274 /* Ask the framebuffer to resize using a default format. The framebuffer will be black.
4275 * So if the frontend does not support GuestMonitorChangedEventType_Disabled event,
4276 * the VM window will be black. */
4277 uint32_t u32Width = pFBInfo->w ? pFBInfo->w : 640;
4278 uint32_t u32Height = pFBInfo->h ? pFBInfo->h : 480;
4279 pThis->handleDisplayResize(pScreen->u32ViewIndex, 0, (uint8_t *)NULL, 0,
4280 u32Width, u32Height, pScreen->u16Flags);
4281
4282 fireGuestMonitorChangedEvent(pThis->mParent->getEventSource(),
4283 GuestMonitorChangedEventType_Disabled,
4284 pScreen->u32ViewIndex,
4285 0, 0, 0, 0);
4286 return VINF_SUCCESS;
4287 }
4288
4289 /* If display was disabled or there is no framebuffer, a resize will be required,
4290 * because the framebuffer was/will be changed.
4291 */
4292 bool fResize = pFBInfo->fDisabled || pFBInfo->pFramebuffer.isNull();
4293
4294 if (pFBInfo->fDisabled)
4295 {
4296 pFBInfo->fDisabled = false;
4297 fireGuestMonitorChangedEvent(pThis->mParent->getEventSource(),
4298 GuestMonitorChangedEventType_Enabled,
4299 pScreen->u32ViewIndex,
4300 pScreen->i32OriginX, pScreen->i32OriginY,
4301 pScreen->u32Width, pScreen->u32Height);
4302 /* Continue to update pFBInfo. */
4303 }
4304
4305 /* Check if this is a real resize or a notification about the screen origin.
4306 * The guest uses this VBVAResize call for both.
4307 */
4308 fResize = fResize
4309 || pFBInfo->u16BitsPerPixel != pScreen->u16BitsPerPixel
4310 || pFBInfo->pu8FramebufferVRAM != (uint8_t *)pvVRAM + pScreen->u32StartOffset
4311 || pFBInfo->u32LineSize != pScreen->u32LineSize
4312 || pFBInfo->w != pScreen->u32Width
4313 || pFBInfo->h != pScreen->u32Height;
4314
4315 bool fNewOrigin = pFBInfo->xOrigin != pScreen->i32OriginX
4316 || pFBInfo->yOrigin != pScreen->i32OriginY;
4317
4318 pFBInfo->u32Offset = pView->u32ViewOffset; /* Not used in HGSMI. */
4319 pFBInfo->u32MaxFramebufferSize = pView->u32MaxScreenSize; /* Not used in HGSMI. */
4320 pFBInfo->u32InformationSize = 0; /* Not used in HGSMI. */
4321
4322 pFBInfo->xOrigin = pScreen->i32OriginX;
4323 pFBInfo->yOrigin = pScreen->i32OriginY;
4324
4325 pFBInfo->w = pScreen->u32Width;
4326 pFBInfo->h = pScreen->u32Height;
4327
4328 pFBInfo->u16BitsPerPixel = pScreen->u16BitsPerPixel;
4329 pFBInfo->pu8FramebufferVRAM = (uint8_t *)pvVRAM + pScreen->u32StartOffset;
4330 pFBInfo->u32LineSize = pScreen->u32LineSize;
4331
4332 pFBInfo->flags = pScreen->u16Flags;
4333
4334 if (fNewOrigin)
4335 {
4336 fireGuestMonitorChangedEvent(pThis->mParent->getEventSource(),
4337 GuestMonitorChangedEventType_NewOrigin,
4338 pScreen->u32ViewIndex,
4339 pScreen->i32OriginX, pScreen->i32OriginY,
4340 0, 0);
4341 }
4342
4343#if defined(VBOX_WITH_HGCM) && defined(VBOX_WITH_CROGL)
4344 if (fNewOrigin && !fResize)
4345 {
4346 BOOL is3denabled;
4347 pThis->mParent->machine()->COMGETTER(Accelerate3DEnabled)(&is3denabled);
4348
4349 if (is3denabled)
4350 {
4351 VBOXHGCMSVCPARM parm;
4352
4353 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
4354 parm.u.uint32 = pScreen->u32ViewIndex;
4355
4356 VMMDev *pVMMDev = pThis->mParent->getVMMDev();
4357
4358 if (pVMMDev)
4359 pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SCREEN_CHANGED, SHCRGL_CPARMS_SCREEN_CHANGED, &parm);
4360 }
4361 }
4362#endif /* VBOX_WITH_CROGL */
4363
4364 if (!fResize)
4365 {
4366 /* No parameters of the framebuffer have actually changed. */
4367 if (fNewOrigin)
4368 {
4369 /* VRDP server still need this notification. */
4370 LogRelFlowFunc(("Calling VRDP\n"));
4371 pThis->mParent->consoleVRDPServer()->SendResize();
4372 }
4373 return VINF_SUCCESS;
4374 }
4375
4376 if (pFBInfo->pFramebuffer.isNull())
4377 {
4378 /* If no framebuffer, the resize will be done later when a new framebuffer will be set in changeFramebuffer. */
4379 return VINF_SUCCESS;
4380 }
4381
4382 /* If the framebuffer already set for the screen, do a regular resize. */
4383 return pThis->handleDisplayResize(pScreen->u32ViewIndex, pScreen->u16BitsPerPixel,
4384 (uint8_t *)pvVRAM + pScreen->u32StartOffset,
4385 pScreen->u32LineSize, pScreen->u32Width, pScreen->u32Height, pScreen->u16Flags);
4386}
4387
4388DECLCALLBACK(int) Display::displayVBVAMousePointerShape(PPDMIDISPLAYCONNECTOR pInterface, bool fVisible, bool fAlpha,
4389 uint32_t xHot, uint32_t yHot,
4390 uint32_t cx, uint32_t cy,
4391 const void *pvShape)
4392{
4393 LogFlowFunc(("\n"));
4394
4395 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
4396 Display *pThis = pDrv->pDisplay;
4397
4398 size_t cbShapeSize = 0;
4399
4400 if (pvShape)
4401 {
4402 cbShapeSize = (cx + 7) / 8 * cy; /* size of the AND mask */
4403 cbShapeSize = ((cbShapeSize + 3) & ~3) + cx * 4 * cy; /* + gap + size of the XOR mask */
4404 }
4405 com::SafeArray<BYTE> shapeData(cbShapeSize);
4406
4407 if (pvShape)
4408 ::memcpy(shapeData.raw(), pvShape, cbShapeSize);
4409
4410 /* Tell the console about it */
4411 pDrv->pDisplay->mParent->onMousePointerShapeChange(fVisible, fAlpha,
4412 xHot, yHot, cx, cy, ComSafeArrayAsInParam(shapeData));
4413
4414 return VINF_SUCCESS;
4415}
4416#endif /* VBOX_WITH_HGSMI */
4417
4418/**
4419 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
4420 */
4421DECLCALLBACK(void *) Display::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
4422{
4423 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
4424 PDRVMAINDISPLAY pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
4425 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
4426 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIDISPLAYCONNECTOR, &pDrv->IConnector);
4427 return NULL;
4428}
4429
4430
4431/**
4432 * Destruct a display driver instance.
4433 *
4434 * @returns VBox status.
4435 * @param pDrvIns The driver instance data.
4436 */
4437DECLCALLBACK(void) Display::drvDestruct(PPDMDRVINS pDrvIns)
4438{
4439 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
4440 PDRVMAINDISPLAY pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
4441 LogRelFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
4442
4443 if (pThis->pDisplay)
4444 {
4445 AutoWriteLock displayLock(pThis->pDisplay COMMA_LOCKVAL_SRC_POS);
4446#ifdef VBOX_WITH_VPX
4447 pThis->pDisplay->VideoCaptureStop();
4448#endif
4449#ifdef VBOX_WITH_CRHGSMI
4450 pThis->pDisplay->destructCrHgsmiData();
4451#endif
4452 pThis->pDisplay->mpDrv = NULL;
4453 pThis->pDisplay->mpVMMDev = NULL;
4454 pThis->pDisplay->mLastAddress = NULL;
4455 pThis->pDisplay->mLastBytesPerLine = 0;
4456 pThis->pDisplay->mLastBitsPerPixel = 0,
4457 pThis->pDisplay->mLastWidth = 0;
4458 pThis->pDisplay->mLastHeight = 0;
4459 }
4460}
4461
4462
4463/**
4464 * Construct a display driver instance.
4465 *
4466 * @copydoc FNPDMDRVCONSTRUCT
4467 */
4468DECLCALLBACK(int) Display::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
4469{
4470 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
4471 PDRVMAINDISPLAY pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
4472 LogRelFlowFunc(("iInstance=%d\n", pDrvIns->iInstance));
4473
4474 /*
4475 * Validate configuration.
4476 */
4477 if (!CFGMR3AreValuesValid(pCfg, "Object\0"))
4478 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
4479 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
4480 ("Configuration error: Not possible to attach anything to this driver!\n"),
4481 VERR_PDM_DRVINS_NO_ATTACH);
4482
4483 /*
4484 * Init Interfaces.
4485 */
4486 pDrvIns->IBase.pfnQueryInterface = Display::drvQueryInterface;
4487
4488 pThis->IConnector.pfnResize = Display::displayResizeCallback;
4489 pThis->IConnector.pfnUpdateRect = Display::displayUpdateCallback;
4490 pThis->IConnector.pfnRefresh = Display::displayRefreshCallback;
4491 pThis->IConnector.pfnReset = Display::displayResetCallback;
4492 pThis->IConnector.pfnLFBModeChange = Display::displayLFBModeChangeCallback;
4493 pThis->IConnector.pfnProcessAdapterData = Display::displayProcessAdapterDataCallback;
4494 pThis->IConnector.pfnProcessDisplayData = Display::displayProcessDisplayDataCallback;
4495#ifdef VBOX_WITH_VIDEOHWACCEL
4496 pThis->IConnector.pfnVHWACommandProcess = Display::displayVHWACommandProcess;
4497#endif
4498#ifdef VBOX_WITH_CRHGSMI
4499 pThis->IConnector.pfnCrHgsmiCommandProcess = Display::displayCrHgsmiCommandProcess;
4500 pThis->IConnector.pfnCrHgsmiControlProcess = Display::displayCrHgsmiControlProcess;
4501#endif
4502#ifdef VBOX_WITH_HGSMI
4503 pThis->IConnector.pfnVBVAEnable = Display::displayVBVAEnable;
4504 pThis->IConnector.pfnVBVADisable = Display::displayVBVADisable;
4505 pThis->IConnector.pfnVBVAUpdateBegin = Display::displayVBVAUpdateBegin;
4506 pThis->IConnector.pfnVBVAUpdateProcess = Display::displayVBVAUpdateProcess;
4507 pThis->IConnector.pfnVBVAUpdateEnd = Display::displayVBVAUpdateEnd;
4508 pThis->IConnector.pfnVBVAResize = Display::displayVBVAResize;
4509 pThis->IConnector.pfnVBVAMousePointerShape = Display::displayVBVAMousePointerShape;
4510#endif
4511
4512 /*
4513 * Get the IDisplayPort interface of the above driver/device.
4514 */
4515 pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYPORT);
4516 if (!pThis->pUpPort)
4517 {
4518 AssertMsgFailed(("Configuration error: No display port interface above!\n"));
4519 return VERR_PDM_MISSING_INTERFACE_ABOVE;
4520 }
4521#if defined(VBOX_WITH_VIDEOHWACCEL) || defined(VBOX_WITH_CRHGSMI)
4522 pThis->pVBVACallbacks = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIDISPLAYVBVACALLBACKS);
4523 if (!pThis->pVBVACallbacks)
4524 {
4525 AssertMsgFailed(("Configuration error: No VBVA callback interface above!\n"));
4526 return VERR_PDM_MISSING_INTERFACE_ABOVE;
4527 }
4528#endif
4529 /*
4530 * Get the Display object pointer and update the mpDrv member.
4531 */
4532 void *pv;
4533 int rc = CFGMR3QueryPtr(pCfg, "Object", &pv);
4534 if (RT_FAILURE(rc))
4535 {
4536 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
4537 return rc;
4538 }
4539 Display *pDisplay = (Display *)pv; /** @todo Check this cast! */
4540 pThis->pDisplay = pDisplay;
4541 pThis->pDisplay->mpDrv = pThis;
4542 /*
4543 * Update our display information according to the framebuffer
4544 */
4545 pDisplay->updateDisplayData();
4546
4547 /*
4548 * Start periodic screen refreshes
4549 */
4550 pThis->pUpPort->pfnSetRefreshRate(pThis->pUpPort, 20);
4551
4552#ifdef VBOX_WITH_CRHGSMI
4553 pDisplay->setupCrHgsmiData();
4554#endif
4555
4556#ifdef VBOX_WITH_VPX
4557 ComPtr<IMachine> pMachine = pDisplay->mParent->machine();
4558 BOOL fEnabled = false;
4559 HRESULT hrc = pMachine->COMGETTER(VideoCaptureEnabled)(&fEnabled);
4560 AssertComRCReturn(hrc, VERR_COM_UNEXPECTED);
4561 if (fEnabled)
4562 {
4563 rc = pDisplay->VideoCaptureStart();
4564 fireVideoCaptureChangedEvent(pDisplay->mParent->getEventSource());
4565 }
4566#endif
4567
4568 return rc;
4569}
4570
4571
4572/**
4573 * Display driver registration record.
4574 */
4575const PDMDRVREG Display::DrvReg =
4576{
4577 /* u32Version */
4578 PDM_DRVREG_VERSION,
4579 /* szName */
4580 "MainDisplay",
4581 /* szRCMod */
4582 "",
4583 /* szR0Mod */
4584 "",
4585 /* pszDescription */
4586 "Main display driver (Main as in the API).",
4587 /* fFlags */
4588 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
4589 /* fClass. */
4590 PDM_DRVREG_CLASS_DISPLAY,
4591 /* cMaxInstances */
4592 ~0U,
4593 /* cbInstance */
4594 sizeof(DRVMAINDISPLAY),
4595 /* pfnConstruct */
4596 Display::drvConstruct,
4597 /* pfnDestruct */
4598 Display::drvDestruct,
4599 /* pfnRelocate */
4600 NULL,
4601 /* pfnIOCtl */
4602 NULL,
4603 /* pfnPowerOn */
4604 NULL,
4605 /* pfnReset */
4606 NULL,
4607 /* pfnSuspend */
4608 NULL,
4609 /* pfnResume */
4610 NULL,
4611 /* pfnAttach */
4612 NULL,
4613 /* pfnDetach */
4614 NULL,
4615 /* pfnPowerOff */
4616 NULL,
4617 /* pfnSoftReset */
4618 NULL,
4619 /* u32EndVersion */
4620 PDM_DRVREG_VERSION
4621};
4622/* 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