VirtualBox

source: vbox/trunk/src/VBox/Main/DisplayImpl.cpp@ 23084

Last change on this file since 23084 was 23015, checked in by vboxsync, 16 years ago

VMM,Main,Devices,VBoxBFE: VMReqCallVoid[U] -> VMR3ReqCallVoidWait. Retired the two old APIs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 82.1 KB
Line 
1/* $Id: DisplayImpl.cpp 23015 2009-09-14 17:00:11Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
20 * Clara, CA 95054 USA or visit http://www.sun.com if you need
21 * additional information or have any questions.
22 */
23
24#include "DisplayImpl.h"
25#include "ConsoleImpl.h"
26#include "ConsoleVRDPServer.h"
27#include "VMMDev.h"
28
29#include "Logging.h"
30
31#include <iprt/semaphore.h>
32#include <iprt/thread.h>
33#include <iprt/asm.h>
34
35#include <VBox/pdmdrv.h>
36#ifdef DEBUG /* for VM_ASSERT_EMT(). */
37# include <VBox/vm.h>
38#endif
39
40#ifdef VBOX_WITH_VIDEOHWACCEL
41# include <VBox/VBoxVideo.h>
42#endif
43/**
44 * Display driver instance data.
45 */
46typedef struct DRVMAINDISPLAY
47{
48 /** Pointer to the display object. */
49 Display *pDisplay;
50 /** Pointer to the driver instance structure. */
51 PPDMDRVINS pDrvIns;
52 /** Pointer to the keyboard port interface of the driver/device above us. */
53 PPDMIDISPLAYPORT pUpPort;
54 /** Our display connector interface. */
55 PDMIDISPLAYCONNECTOR Connector;
56#if defined(VBOX_WITH_VIDEOHWACCEL)
57 /** VBVA callbacks */
58 PPDMDDISPLAYVBVACALLBACKS pVBVACallbacks;
59#endif
60} DRVMAINDISPLAY, *PDRVMAINDISPLAY;
61
62/** Converts PDMIDISPLAYCONNECTOR pointer to a DRVMAINDISPLAY pointer. */
63#define PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface) ( (PDRVMAINDISPLAY) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINDISPLAY, Connector)) )
64
65#ifdef DEBUG_sunlover
66static STAMPROFILE StatDisplayRefresh;
67static int stam = 0;
68#endif /* DEBUG_sunlover */
69
70// constructor / destructor
71/////////////////////////////////////////////////////////////////////////////
72
73DEFINE_EMPTY_CTOR_DTOR (Display)
74
75HRESULT Display::FinalConstruct()
76{
77 mpVbvaMemory = NULL;
78 mfVideoAccelEnabled = false;
79 mfVideoAccelVRDP = false;
80 mfu32SupportedOrders = 0;
81 mcVideoAccelVRDPRefs = 0;
82
83 mpPendingVbvaMemory = NULL;
84 mfPendingVideoAccelEnable = false;
85
86 mfMachineRunning = false;
87
88 mpu8VbvaPartial = NULL;
89 mcbVbvaPartial = 0;
90
91 mpDrv = NULL;
92 mpVMMDev = NULL;
93 mfVMMDevInited = false;
94
95 mLastAddress = NULL;
96 mLastBytesPerLine = 0;
97 mLastBitsPerPixel = 0,
98 mLastWidth = 0;
99 mLastHeight = 0;
100
101 return S_OK;
102}
103
104void Display::FinalRelease()
105{
106 uninit();
107}
108
109// public initializer/uninitializer for internal purposes only
110/////////////////////////////////////////////////////////////////////////////
111
112#define sSSMDisplayVer 0x00010001
113
114/**
115 * Save/Load some important guest state
116 */
117DECLCALLBACK(void)
118Display::displaySSMSave(PSSMHANDLE pSSM, void *pvUser)
119{
120 Display *that = static_cast<Display*>(pvUser);
121
122 SSMR3PutU32(pSSM, that->mcMonitors);
123 for (unsigned i = 0; i < that->mcMonitors; i++)
124 {
125 SSMR3PutU32(pSSM, that->maFramebuffers[i].u32Offset);
126 SSMR3PutU32(pSSM, that->maFramebuffers[i].u32MaxFramebufferSize);
127 SSMR3PutU32(pSSM, that->maFramebuffers[i].u32InformationSize);
128 }
129}
130
131DECLCALLBACK(int)
132Display::displaySSMLoad(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass)
133{
134 Display *that = static_cast<Display*>(pvUser);
135
136 if (uVersion != sSSMDisplayVer)
137 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
138 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
139
140 uint32_t cMonitors;
141 int rc = SSMR3GetU32(pSSM, &cMonitors);
142 if (cMonitors != that->mcMonitors)
143 {
144 LogRel(("Display: Number of monitors changed (%d->%d)!\n",
145 cMonitors, that->mcMonitors));
146 return VERR_SSM_LOAD_CONFIG_MISMATCH;
147 }
148
149 for (uint32_t i = 0; i < cMonitors; i++)
150 {
151 SSMR3GetU32(pSSM, &that->maFramebuffers[i].u32Offset);
152 SSMR3GetU32(pSSM, &that->maFramebuffers[i].u32MaxFramebufferSize);
153 SSMR3GetU32(pSSM, &that->maFramebuffers[i].u32InformationSize);
154 }
155
156 return VINF_SUCCESS;
157}
158
159/**
160 * Initializes the display object.
161 *
162 * @returns COM result indicator
163 * @param parent handle of our parent object
164 * @param qemuConsoleData address of common console data structure
165 */
166HRESULT Display::init (Console *aParent)
167{
168 LogFlowThisFunc(("aParent=%p\n", aParent));
169
170 ComAssertRet (aParent, E_INVALIDARG);
171
172 /* Enclose the state transition NotReady->InInit->Ready */
173 AutoInitSpan autoInitSpan(this);
174 AssertReturn(autoInitSpan.isOk(), E_FAIL);
175
176 unconst(mParent) = aParent;
177
178 // by default, we have an internal framebuffer which is
179 // NULL, i.e. a black hole for no display output
180 mFramebufferOpened = false;
181
182 ULONG ul;
183 mParent->machine()->COMGETTER(MonitorCount)(&ul);
184 mcMonitors = ul;
185
186 for (ul = 0; ul < mcMonitors; ul++)
187 {
188 maFramebuffers[ul].u32Offset = 0;
189 maFramebuffers[ul].u32MaxFramebufferSize = 0;
190 maFramebuffers[ul].u32InformationSize = 0;
191
192 maFramebuffers[ul].pFramebuffer = NULL;
193
194 maFramebuffers[ul].xOrigin = 0;
195 maFramebuffers[ul].yOrigin = 0;
196
197 maFramebuffers[ul].w = 0;
198 maFramebuffers[ul].h = 0;
199
200 maFramebuffers[ul].pHostEvents = NULL;
201
202 maFramebuffers[ul].u32ResizeStatus = ResizeStatus_Void;
203
204 maFramebuffers[ul].fDefaultFormat = false;
205
206 memset (&maFramebuffers[ul].dirtyRect, 0 , sizeof (maFramebuffers[ul].dirtyRect));
207 memset (&maFramebuffers[ul].pendingResize, 0 , sizeof (maFramebuffers[ul].pendingResize));
208#ifdef VBOX_WITH_HGSMI
209 maFramebuffers[ul].fVBVAEnabled = false;
210#endif /* VBOX_WITH_HGSMI */
211 }
212
213 mParent->RegisterCallback (this);
214
215 /* Confirm a successful initialization */
216 autoInitSpan.setSucceeded();
217
218 return S_OK;
219}
220
221/**
222 * Uninitializes the instance and sets the ready flag to FALSE.
223 * Called either from FinalRelease() or by the parent when it gets destroyed.
224 */
225void Display::uninit()
226{
227 LogFlowThisFunc(("\n"));
228
229 /* Enclose the state transition Ready->InUninit->NotReady */
230 AutoUninitSpan autoUninitSpan(this);
231 if (autoUninitSpan.uninitDone())
232 return;
233
234 ULONG ul;
235 for (ul = 0; ul < mcMonitors; ul++)
236 maFramebuffers[ul].pFramebuffer = NULL;
237
238 if (mParent)
239 mParent->UnregisterCallback (this);
240
241 unconst(mParent).setNull();
242
243 if (mpDrv)
244 mpDrv->pDisplay = NULL;
245
246 mpDrv = NULL;
247 mpVMMDev = NULL;
248 mfVMMDevInited = true;
249}
250
251/**
252 * Register the SSM methods. Called by the power up thread to be able to
253 * pass pVM
254 */
255int Display::registerSSM(PVM pVM)
256{
257 int rc = SSMR3RegisterExternal(pVM, "DisplayData", 0, sSSMDisplayVer,
258 mcMonitors * sizeof(uint32_t) * 3 + sizeof(uint32_t),
259 NULL, NULL, NULL,
260 NULL, displaySSMSave, NULL,
261 NULL, displaySSMLoad, NULL, this);
262
263 AssertRCReturn(rc, rc);
264
265 /*
266 * Register loaders for old saved states where iInstance was 3 * sizeof(uint32_t *).
267 */
268 rc = SSMR3RegisterExternal(pVM, "DisplayData", 12 /*uInstance*/, sSSMDisplayVer, 0 /*cbGuess*/,
269 NULL, NULL, NULL,
270 NULL, NULL, NULL,
271 NULL, displaySSMLoad, NULL, this);
272 AssertRCReturn(rc, rc);
273
274 rc = SSMR3RegisterExternal(pVM, "DisplayData", 24 /*uInstance*/, sSSMDisplayVer, 0 /*cbGuess*/,
275 NULL, NULL, NULL,
276 NULL, NULL, NULL,
277 NULL, displaySSMLoad, NULL, this);
278 AssertRCReturn(rc, rc);
279 return VINF_SUCCESS;
280}
281
282// IConsoleCallback method
283STDMETHODIMP Display::OnStateChange(MachineState_T machineState)
284{
285 if (machineState == MachineState_Running)
286 {
287 LogFlowFunc (("Machine is running.\n"));
288
289 mfMachineRunning = true;
290 }
291 else
292 mfMachineRunning = false;
293
294 return S_OK;
295}
296
297// public methods only for internal purposes
298/////////////////////////////////////////////////////////////////////////////
299
300/**
301 * @thread EMT
302 */
303static int callFramebufferResize (IFramebuffer *pFramebuffer, unsigned uScreenId,
304 ULONG pixelFormat, void *pvVRAM,
305 uint32_t bpp, uint32_t cbLine,
306 int w, int h)
307{
308 Assert (pFramebuffer);
309
310 /* Call the framebuffer to try and set required pixelFormat. */
311 BOOL finished = TRUE;
312
313 pFramebuffer->RequestResize (uScreenId, pixelFormat, (BYTE *) pvVRAM,
314 bpp, cbLine, w, h, &finished);
315
316 if (!finished)
317 {
318 LogFlowFunc (("External framebuffer wants us to wait!\n"));
319 return VINF_VGA_RESIZE_IN_PROGRESS;
320 }
321
322 return VINF_SUCCESS;
323}
324
325/**
326 * Handles display resize event.
327 * Disables access to VGA device;
328 * calls the framebuffer RequestResize method;
329 * if framebuffer resizes synchronously,
330 * updates the display connector data and enables access to the VGA device.
331 *
332 * @param w New display width
333 * @param h New display height
334 *
335 * @thread EMT
336 */
337int Display::handleDisplayResize (unsigned uScreenId, uint32_t bpp, void *pvVRAM,
338 uint32_t cbLine, int w, int h)
339{
340 LogRel (("Display::handleDisplayResize(): uScreenId = %d, pvVRAM=%p "
341 "w=%d h=%d bpp=%d cbLine=0x%X\n",
342 uScreenId, pvVRAM, w, h, bpp, cbLine));
343
344 /* If there is no framebuffer, this call is not interesting. */
345 if ( uScreenId >= mcMonitors
346 || maFramebuffers[uScreenId].pFramebuffer.isNull())
347 {
348 return VINF_SUCCESS;
349 }
350
351 mLastAddress = pvVRAM;
352 mLastBytesPerLine = cbLine;
353 mLastBitsPerPixel = bpp,
354 mLastWidth = w;
355 mLastHeight = h;
356
357 ULONG pixelFormat;
358
359 switch (bpp)
360 {
361 case 32:
362 case 24:
363 case 16:
364 pixelFormat = FramebufferPixelFormat_FOURCC_RGB;
365 break;
366 default:
367 pixelFormat = FramebufferPixelFormat_Opaque;
368 bpp = cbLine = 0;
369 break;
370 }
371
372 /* Atomically set the resize status before calling the framebuffer. The new InProgress status will
373 * disable access to the VGA device by the EMT thread.
374 */
375 bool f = ASMAtomicCmpXchgU32 (&maFramebuffers[uScreenId].u32ResizeStatus,
376 ResizeStatus_InProgress, ResizeStatus_Void);
377 if (!f)
378 {
379 /* This could be a result of the screenshot taking call Display::TakeScreenShot:
380 * if the framebuffer is processing the resize request and GUI calls the TakeScreenShot
381 * and the guest has reprogrammed the virtual VGA devices again so a new resize is required.
382 *
383 * Save the resize information and return the pending status code.
384 *
385 * Note: the resize information is only accessed on EMT so no serialization is required.
386 */
387 LogRel (("Display::handleDisplayResize(): Warning: resize postponed.\n"));
388
389 maFramebuffers[uScreenId].pendingResize.fPending = true;
390 maFramebuffers[uScreenId].pendingResize.pixelFormat = pixelFormat;
391 maFramebuffers[uScreenId].pendingResize.pvVRAM = pvVRAM;
392 maFramebuffers[uScreenId].pendingResize.bpp = bpp;
393 maFramebuffers[uScreenId].pendingResize.cbLine = cbLine;
394 maFramebuffers[uScreenId].pendingResize.w = w;
395 maFramebuffers[uScreenId].pendingResize.h = h;
396
397 return VINF_VGA_RESIZE_IN_PROGRESS;
398 }
399
400 int rc = callFramebufferResize (maFramebuffers[uScreenId].pFramebuffer, uScreenId,
401 pixelFormat, pvVRAM, bpp, cbLine, w, h);
402 if (rc == VINF_VGA_RESIZE_IN_PROGRESS)
403 {
404 /* Immediately return to the caller. ResizeCompleted will be called back by the
405 * GUI thread. The ResizeCompleted callback will change the resize status from
406 * InProgress to UpdateDisplayData. The latter status will be checked by the
407 * display timer callback on EMT and all required adjustments will be done there.
408 */
409 return rc;
410 }
411
412 /* Set the status so the 'handleResizeCompleted' would work. */
413 f = ASMAtomicCmpXchgU32 (&maFramebuffers[uScreenId].u32ResizeStatus,
414 ResizeStatus_UpdateDisplayData, ResizeStatus_InProgress);
415 AssertRelease(f);NOREF(f);
416
417 AssertRelease(!maFramebuffers[uScreenId].pendingResize.fPending);
418
419 /* The method also unlocks the framebuffer. */
420 handleResizeCompletedEMT();
421
422 return VINF_SUCCESS;
423}
424
425/**
426 * Framebuffer has been resized.
427 * Read the new display data and unlock the framebuffer.
428 *
429 * @thread EMT
430 */
431void Display::handleResizeCompletedEMT (void)
432{
433 LogFlowFunc(("\n"));
434
435 unsigned uScreenId;
436 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
437 {
438 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
439
440 /* Try to into non resizing state. */
441 bool f = ASMAtomicCmpXchgU32 (&pFBInfo->u32ResizeStatus, ResizeStatus_Void, ResizeStatus_UpdateDisplayData);
442
443 if (f == false)
444 {
445 /* This is not the display that has completed resizing. */
446 continue;
447 }
448
449 /* Check whether a resize is pending for this framebuffer. */
450 if (pFBInfo->pendingResize.fPending)
451 {
452 /* Reset the condition, call the display resize with saved data and continue.
453 *
454 * Note: handleDisplayResize can call handleResizeCompletedEMT back,
455 * but infinite recursion is not possible, because when the handleResizeCompletedEMT
456 * is called, the pFBInfo->pendingResize.fPending is equal to false.
457 */
458 pFBInfo->pendingResize.fPending = false;
459 handleDisplayResize (uScreenId, pFBInfo->pendingResize.bpp, pFBInfo->pendingResize.pvVRAM,
460 pFBInfo->pendingResize.cbLine, pFBInfo->pendingResize.w, pFBInfo->pendingResize.h);
461 continue;
462 }
463
464 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN && !pFBInfo->pFramebuffer.isNull())
465 {
466 /* Primary framebuffer has completed the resize. Update the connector data for VGA device. */
467 updateDisplayData();
468
469 /* Check the framebuffer pixel format to setup the rendering in VGA device. */
470 BOOL usesGuestVRAM = FALSE;
471 pFBInfo->pFramebuffer->COMGETTER(UsesGuestVRAM) (&usesGuestVRAM);
472
473 pFBInfo->fDefaultFormat = (usesGuestVRAM == FALSE);
474
475 mpDrv->pUpPort->pfnSetRenderVRAM (mpDrv->pUpPort, pFBInfo->fDefaultFormat);
476 }
477
478#ifdef DEBUG_sunlover
479 if (!stam)
480 {
481 /* protect mpVM */
482 Console::SafeVMPtr pVM (mParent);
483 AssertComRC (pVM.rc());
484
485 STAM_REG(pVM, &StatDisplayRefresh, STAMTYPE_PROFILE, "/PROF/Display/Refresh", STAMUNIT_TICKS_PER_CALL, "Time spent in EMT for display updates.");
486 stam = 1;
487 }
488#endif /* DEBUG_sunlover */
489
490 /* Inform VRDP server about the change of display parameters. */
491 LogFlowFunc (("Calling VRDP\n"));
492 mParent->consoleVRDPServer()->SendResize();
493 }
494}
495
496static void checkCoordBounds (int *px, int *py, int *pw, int *ph, int cx, int cy)
497{
498 /* Correct negative x and y coordinates. */
499 if (*px < 0)
500 {
501 *px += *pw; /* Compute xRight which is also the new width. */
502
503 *pw = (*px < 0)? 0: *px;
504
505 *px = 0;
506 }
507
508 if (*py < 0)
509 {
510 *py += *ph; /* Compute xBottom, which is also the new height. */
511
512 *ph = (*py < 0)? 0: *py;
513
514 *py = 0;
515 }
516
517 /* Also check if coords are greater than the display resolution. */
518 if (*px + *pw > cx)
519 {
520 *pw = cx > *px? cx - *px: 0;
521 }
522
523 if (*py + *ph > cy)
524 {
525 *ph = cy > *py? cy - *py: 0;
526 }
527}
528
529unsigned mapCoordsToScreen(DISPLAYFBINFO *pInfos, unsigned cInfos, int *px, int *py, int *pw, int *ph)
530{
531 DISPLAYFBINFO *pInfo = pInfos;
532 unsigned uScreenId;
533 LogSunlover (("mapCoordsToScreen: %d,%d %dx%d\n", *px, *py, *pw, *ph));
534 for (uScreenId = 0; uScreenId < cInfos; uScreenId++, pInfo++)
535 {
536 LogSunlover ((" [%d] %d,%d %dx%d\n", uScreenId, pInfo->xOrigin, pInfo->yOrigin, pInfo->w, pInfo->h));
537 if ( (pInfo->xOrigin <= *px && *px < pInfo->xOrigin + (int)pInfo->w)
538 && (pInfo->yOrigin <= *py && *py < pInfo->yOrigin + (int)pInfo->h))
539 {
540 /* The rectangle belongs to the screen. Correct coordinates. */
541 *px -= pInfo->xOrigin;
542 *py -= pInfo->yOrigin;
543 LogSunlover ((" -> %d,%d", *px, *py));
544 break;
545 }
546 }
547 if (uScreenId == cInfos)
548 {
549 /* Map to primary screen. */
550 uScreenId = 0;
551 }
552 LogSunlover ((" scr %d\n", uScreenId));
553 return uScreenId;
554}
555
556
557/**
558 * Handles display update event.
559 *
560 * @param x Update area x coordinate
561 * @param y Update area y coordinate
562 * @param w Update area width
563 * @param h Update area height
564 *
565 * @thread EMT
566 */
567void Display::handleDisplayUpdate (int x, int y, int w, int h)
568{
569#ifdef DEBUG_sunlover
570 LogFlowFunc (("%d,%d %dx%d (%d,%d)\n",
571 x, y, w, h, mpDrv->Connector.cx, mpDrv->Connector.cy));
572#endif /* DEBUG_sunlover */
573
574 unsigned uScreenId = mapCoordsToScreen(maFramebuffers, mcMonitors, &x, &y, &w, &h);
575
576#ifdef DEBUG_sunlover
577 LogFlowFunc (("%d,%d %dx%d (checked)\n", x, y, w, h));
578#endif /* DEBUG_sunlover */
579
580 IFramebuffer *pFramebuffer = maFramebuffers[uScreenId].pFramebuffer;
581
582 // if there is no framebuffer, this call is not interesting
583 if (pFramebuffer == NULL)
584 return;
585
586 pFramebuffer->Lock();
587
588 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
589 checkCoordBounds (&x, &y, &w, &h, mpDrv->Connector.cx, mpDrv->Connector.cy);
590 else
591 checkCoordBounds (&x, &y, &w, &h, maFramebuffers[uScreenId].w,
592 maFramebuffers[uScreenId].h);
593
594 if (w != 0 && h != 0)
595 pFramebuffer->NotifyUpdate(x, y, w, h);
596
597 pFramebuffer->Unlock();
598
599#ifndef VBOX_WITH_HGSMI
600 if (!mfVideoAccelEnabled)
601 {
602#else
603 if (!mfVideoAccelEnabled && !maFramebuffers[uScreenId].fVBVAEnabled)
604 {
605#endif /* VBOX_WITH_HGSMI */
606 /* When VBVA is enabled, the VRDP server is informed in the VideoAccelFlush.
607 * Inform the server here only if VBVA is disabled.
608 */
609 if (maFramebuffers[uScreenId].u32ResizeStatus == ResizeStatus_Void)
610 mParent->consoleVRDPServer()->SendUpdateBitmap(uScreenId, x, y, w, h);
611 }
612}
613
614typedef struct _VBVADIRTYREGION
615{
616 /* Copies of object's pointers used by vbvaRgn functions. */
617 DISPLAYFBINFO *paFramebuffers;
618 unsigned cMonitors;
619 Display *pDisplay;
620 PPDMIDISPLAYPORT pPort;
621
622} VBVADIRTYREGION;
623
624static void vbvaRgnInit (VBVADIRTYREGION *prgn, DISPLAYFBINFO *paFramebuffers, unsigned cMonitors, Display *pd, PPDMIDISPLAYPORT pp)
625{
626 prgn->paFramebuffers = paFramebuffers;
627 prgn->cMonitors = cMonitors;
628 prgn->pDisplay = pd;
629 prgn->pPort = pp;
630
631 unsigned uScreenId;
632 for (uScreenId = 0; uScreenId < cMonitors; uScreenId++)
633 {
634 DISPLAYFBINFO *pFBInfo = &prgn->paFramebuffers[uScreenId];
635
636 memset (&pFBInfo->dirtyRect, 0, sizeof (pFBInfo->dirtyRect));
637 }
638}
639
640static void vbvaRgnDirtyRect (VBVADIRTYREGION *prgn, unsigned uScreenId, VBVACMDHDR *phdr)
641{
642 LogSunlover (("x = %d, y = %d, w = %d, h = %d\n",
643 phdr->x, phdr->y, phdr->w, phdr->h));
644
645 /*
646 * Here update rectangles are accumulated to form an update area.
647 * @todo
648 * Now the simpliest method is used which builds one rectangle that
649 * includes all update areas. A bit more advanced method can be
650 * employed here. The method should be fast however.
651 */
652 if (phdr->w == 0 || phdr->h == 0)
653 {
654 /* Empty rectangle. */
655 return;
656 }
657
658 int32_t xRight = phdr->x + phdr->w;
659 int32_t yBottom = phdr->y + phdr->h;
660
661 DISPLAYFBINFO *pFBInfo = &prgn->paFramebuffers[uScreenId];
662
663 if (pFBInfo->dirtyRect.xRight == 0)
664 {
665 /* This is the first rectangle to be added. */
666 pFBInfo->dirtyRect.xLeft = phdr->x;
667 pFBInfo->dirtyRect.yTop = phdr->y;
668 pFBInfo->dirtyRect.xRight = xRight;
669 pFBInfo->dirtyRect.yBottom = yBottom;
670 }
671 else
672 {
673 /* Adjust region coordinates. */
674 if (pFBInfo->dirtyRect.xLeft > phdr->x)
675 {
676 pFBInfo->dirtyRect.xLeft = phdr->x;
677 }
678
679 if (pFBInfo->dirtyRect.yTop > phdr->y)
680 {
681 pFBInfo->dirtyRect.yTop = phdr->y;
682 }
683
684 if (pFBInfo->dirtyRect.xRight < xRight)
685 {
686 pFBInfo->dirtyRect.xRight = xRight;
687 }
688
689 if (pFBInfo->dirtyRect.yBottom < yBottom)
690 {
691 pFBInfo->dirtyRect.yBottom = yBottom;
692 }
693 }
694
695 if (pFBInfo->fDefaultFormat)
696 {
697 //@todo pfnUpdateDisplayRect must take the vram offset parameter for the framebuffer
698 prgn->pPort->pfnUpdateDisplayRect (prgn->pPort, phdr->x, phdr->y, phdr->w, phdr->h);
699 prgn->pDisplay->handleDisplayUpdate (phdr->x + pFBInfo->xOrigin,
700 phdr->y + pFBInfo->yOrigin, phdr->w, phdr->h);
701 }
702
703 return;
704}
705
706static void vbvaRgnUpdateFramebuffer (VBVADIRTYREGION *prgn, unsigned uScreenId)
707{
708 DISPLAYFBINFO *pFBInfo = &prgn->paFramebuffers[uScreenId];
709
710 uint32_t w = pFBInfo->dirtyRect.xRight - pFBInfo->dirtyRect.xLeft;
711 uint32_t h = pFBInfo->dirtyRect.yBottom - pFBInfo->dirtyRect.yTop;
712
713 if (!pFBInfo->fDefaultFormat && pFBInfo->pFramebuffer && w != 0 && h != 0)
714 {
715 //@todo pfnUpdateDisplayRect must take the vram offset parameter for the framebuffer
716 prgn->pPort->pfnUpdateDisplayRect (prgn->pPort, pFBInfo->dirtyRect.xLeft, pFBInfo->dirtyRect.yTop, w, h);
717 prgn->pDisplay->handleDisplayUpdate (pFBInfo->dirtyRect.xLeft + pFBInfo->xOrigin,
718 pFBInfo->dirtyRect.yTop + pFBInfo->yOrigin, w, h);
719 }
720}
721
722static void vbvaSetMemoryFlags (VBVAMEMORY *pVbvaMemory,
723 bool fVideoAccelEnabled,
724 bool fVideoAccelVRDP,
725 uint32_t fu32SupportedOrders,
726 DISPLAYFBINFO *paFBInfos,
727 unsigned cFBInfos)
728{
729 if (pVbvaMemory)
730 {
731 /* This called only on changes in mode. So reset VRDP always. */
732 uint32_t fu32Flags = VBVA_F_MODE_VRDP_RESET;
733
734 if (fVideoAccelEnabled)
735 {
736 fu32Flags |= VBVA_F_MODE_ENABLED;
737
738 if (fVideoAccelVRDP)
739 {
740 fu32Flags |= VBVA_F_MODE_VRDP | VBVA_F_MODE_VRDP_ORDER_MASK;
741
742 pVbvaMemory->fu32SupportedOrders = fu32SupportedOrders;
743 }
744 }
745
746 pVbvaMemory->fu32ModeFlags = fu32Flags;
747 }
748
749 unsigned uScreenId;
750 for (uScreenId = 0; uScreenId < cFBInfos; uScreenId++)
751 {
752 if (paFBInfos[uScreenId].pHostEvents)
753 {
754 paFBInfos[uScreenId].pHostEvents->fu32Events |= VBOX_VIDEO_INFO_HOST_EVENTS_F_VRDP_RESET;
755 }
756 }
757}
758
759bool Display::VideoAccelAllowed (void)
760{
761 return true;
762}
763
764/**
765 * @thread EMT
766 */
767int Display::VideoAccelEnable (bool fEnable, VBVAMEMORY *pVbvaMemory)
768{
769 int rc = VINF_SUCCESS;
770
771 /* Called each time the guest wants to use acceleration,
772 * or when the VGA device disables acceleration,
773 * or when restoring the saved state with accel enabled.
774 *
775 * VGA device disables acceleration on each video mode change
776 * and on reset.
777 *
778 * Guest enabled acceleration at will. And it has to enable
779 * acceleration after a mode change.
780 */
781 LogFlowFunc (("mfVideoAccelEnabled = %d, fEnable = %d, pVbvaMemory = %p\n",
782 mfVideoAccelEnabled, fEnable, pVbvaMemory));
783
784 /* Strictly check parameters. Callers must not pass anything in the case. */
785 Assert((fEnable && pVbvaMemory) || (!fEnable && pVbvaMemory == NULL));
786
787 if (!VideoAccelAllowed ())
788 {
789 return VERR_NOT_SUPPORTED;
790 }
791
792 /*
793 * Verify that the VM is in running state. If it is not,
794 * then this must be postponed until it goes to running.
795 */
796 if (!mfMachineRunning)
797 {
798 Assert (!mfVideoAccelEnabled);
799
800 LogFlowFunc (("Machine is not yet running.\n"));
801
802 if (fEnable)
803 {
804 mfPendingVideoAccelEnable = fEnable;
805 mpPendingVbvaMemory = pVbvaMemory;
806 }
807
808 return rc;
809 }
810
811 /* Check that current status is not being changed */
812 if (mfVideoAccelEnabled == fEnable)
813 {
814 return rc;
815 }
816
817 if (mfVideoAccelEnabled)
818 {
819 /* Process any pending orders and empty the VBVA ring buffer. */
820 VideoAccelFlush ();
821 }
822
823 if (!fEnable && mpVbvaMemory)
824 {
825 mpVbvaMemory->fu32ModeFlags &= ~VBVA_F_MODE_ENABLED;
826 }
827
828 /* Safety precaution. There is no more VBVA until everything is setup! */
829 mpVbvaMemory = NULL;
830 mfVideoAccelEnabled = false;
831
832 /* Update entire display. */
833 if (maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].u32ResizeStatus == ResizeStatus_Void)
834 {
835 mpDrv->pUpPort->pfnUpdateDisplayAll(mpDrv->pUpPort);
836 }
837
838 /* Everything OK. VBVA status can be changed. */
839
840 /* Notify the VMMDev, which saves VBVA status in the saved state,
841 * and needs to know current status.
842 */
843 PPDMIVMMDEVPORT pVMMDevPort = mParent->getVMMDev()->getVMMDevPort ();
844
845 if (pVMMDevPort)
846 {
847 pVMMDevPort->pfnVBVAChange (pVMMDevPort, fEnable);
848 }
849
850 if (fEnable)
851 {
852 mpVbvaMemory = pVbvaMemory;
853 mfVideoAccelEnabled = true;
854
855 /* Initialize the hardware memory. */
856 vbvaSetMemoryFlags (mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
857 mpVbvaMemory->off32Data = 0;
858 mpVbvaMemory->off32Free = 0;
859
860 memset (mpVbvaMemory->aRecords, 0, sizeof (mpVbvaMemory->aRecords));
861 mpVbvaMemory->indexRecordFirst = 0;
862 mpVbvaMemory->indexRecordFree = 0;
863
864 LogRel(("VBVA: Enabled.\n"));
865 }
866 else
867 {
868 LogRel(("VBVA: Disabled.\n"));
869 }
870
871 LogFlowFunc (("VideoAccelEnable: rc = %Rrc.\n", rc));
872
873 return rc;
874}
875
876#ifdef VBOX_WITH_VRDP
877/* Called always by one VRDP server thread. Can be thread-unsafe.
878 */
879void Display::VideoAccelVRDP (bool fEnable)
880{
881 int c = fEnable?
882 ASMAtomicIncS32 (&mcVideoAccelVRDPRefs):
883 ASMAtomicDecS32 (&mcVideoAccelVRDPRefs);
884
885 Assert (c >= 0);
886
887 if (c == 0)
888 {
889 /* The last client has disconnected, and the accel can be
890 * disabled.
891 */
892 Assert (fEnable == false);
893
894 mfVideoAccelVRDP = false;
895 mfu32SupportedOrders = 0;
896
897 vbvaSetMemoryFlags (mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
898
899 LogRel(("VBVA: VRDP acceleration has been disabled.\n"));
900 }
901 else if ( c == 1
902 && !mfVideoAccelVRDP)
903 {
904 /* The first client has connected. Enable the accel.
905 */
906 Assert (fEnable == true);
907
908 mfVideoAccelVRDP = true;
909 /* Supporting all orders. */
910 mfu32SupportedOrders = ~0;
911
912 vbvaSetMemoryFlags (mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
913
914 LogRel(("VBVA: VRDP acceleration has been requested.\n"));
915 }
916 else
917 {
918 /* A client is connected or disconnected but there is no change in the
919 * accel state. It remains enabled.
920 */
921 Assert (mfVideoAccelVRDP == true);
922 }
923}
924#endif /* VBOX_WITH_VRDP */
925
926static bool vbvaVerifyRingBuffer (VBVAMEMORY *pVbvaMemory)
927{
928 return true;
929}
930
931static void vbvaFetchBytes (VBVAMEMORY *pVbvaMemory, uint8_t *pu8Dst, uint32_t cbDst)
932{
933 if (cbDst >= VBVA_RING_BUFFER_SIZE)
934 {
935 AssertMsgFailed (("cbDst = 0x%08X, ring buffer size 0x%08X", cbDst, VBVA_RING_BUFFER_SIZE));
936 return;
937 }
938
939 uint32_t u32BytesTillBoundary = VBVA_RING_BUFFER_SIZE - pVbvaMemory->off32Data;
940 uint8_t *src = &pVbvaMemory->au8RingBuffer[pVbvaMemory->off32Data];
941 int32_t i32Diff = cbDst - u32BytesTillBoundary;
942
943 if (i32Diff <= 0)
944 {
945 /* Chunk will not cross buffer boundary. */
946 memcpy (pu8Dst, src, cbDst);
947 }
948 else
949 {
950 /* Chunk crosses buffer boundary. */
951 memcpy (pu8Dst, src, u32BytesTillBoundary);
952 memcpy (pu8Dst + u32BytesTillBoundary, &pVbvaMemory->au8RingBuffer[0], i32Diff);
953 }
954
955 /* Advance data offset. */
956 pVbvaMemory->off32Data = (pVbvaMemory->off32Data + cbDst) % VBVA_RING_BUFFER_SIZE;
957
958 return;
959}
960
961
962static bool vbvaPartialRead (uint8_t **ppu8, uint32_t *pcb, uint32_t cbRecord, VBVAMEMORY *pVbvaMemory)
963{
964 uint8_t *pu8New;
965
966 LogFlow(("MAIN::DisplayImpl::vbvaPartialRead: p = %p, cb = %d, cbRecord 0x%08X\n",
967 *ppu8, *pcb, cbRecord));
968
969 if (*ppu8)
970 {
971 Assert (*pcb);
972 pu8New = (uint8_t *)RTMemRealloc (*ppu8, cbRecord);
973 }
974 else
975 {
976 Assert (!*pcb);
977 pu8New = (uint8_t *)RTMemAlloc (cbRecord);
978 }
979
980 if (!pu8New)
981 {
982 /* Memory allocation failed, fail the function. */
983 Log(("MAIN::vbvaPartialRead: failed to (re)alocate memory for partial record!!! cbRecord 0x%08X\n",
984 cbRecord));
985
986 if (*ppu8)
987 {
988 RTMemFree (*ppu8);
989 }
990
991 *ppu8 = NULL;
992 *pcb = 0;
993
994 return false;
995 }
996
997 /* Fetch data from the ring buffer. */
998 vbvaFetchBytes (pVbvaMemory, pu8New + *pcb, cbRecord - *pcb);
999
1000 *ppu8 = pu8New;
1001 *pcb = cbRecord;
1002
1003 return true;
1004}
1005
1006/* For contiguous chunks just return the address in the buffer.
1007 * For crossing boundary - allocate a buffer from heap.
1008 */
1009bool Display::vbvaFetchCmd (VBVACMDHDR **ppHdr, uint32_t *pcbCmd)
1010{
1011 uint32_t indexRecordFirst = mpVbvaMemory->indexRecordFirst;
1012 uint32_t indexRecordFree = mpVbvaMemory->indexRecordFree;
1013
1014#ifdef DEBUG_sunlover
1015 LogFlowFunc (("first = %d, free = %d\n",
1016 indexRecordFirst, indexRecordFree));
1017#endif /* DEBUG_sunlover */
1018
1019 if (!vbvaVerifyRingBuffer (mpVbvaMemory))
1020 {
1021 return false;
1022 }
1023
1024 if (indexRecordFirst == indexRecordFree)
1025 {
1026 /* No records to process. Return without assigning output variables. */
1027 return true;
1028 }
1029
1030 VBVARECORD *pRecord = &mpVbvaMemory->aRecords[indexRecordFirst];
1031
1032#ifdef DEBUG_sunlover
1033 LogFlowFunc (("cbRecord = 0x%08X\n", pRecord->cbRecord));
1034#endif /* DEBUG_sunlover */
1035
1036 uint32_t cbRecord = pRecord->cbRecord & ~VBVA_F_RECORD_PARTIAL;
1037
1038 if (mcbVbvaPartial)
1039 {
1040 /* There is a partial read in process. Continue with it. */
1041
1042 Assert (mpu8VbvaPartial);
1043
1044 LogFlowFunc (("continue partial record mcbVbvaPartial = %d cbRecord 0x%08X, first = %d, free = %d\n",
1045 mcbVbvaPartial, pRecord->cbRecord, indexRecordFirst, indexRecordFree));
1046
1047 if (cbRecord > mcbVbvaPartial)
1048 {
1049 /* New data has been added to the record. */
1050 if (!vbvaPartialRead (&mpu8VbvaPartial, &mcbVbvaPartial, cbRecord, mpVbvaMemory))
1051 {
1052 return false;
1053 }
1054 }
1055
1056 if (!(pRecord->cbRecord & VBVA_F_RECORD_PARTIAL))
1057 {
1058 /* The record is completed by guest. Return it to the caller. */
1059 *ppHdr = (VBVACMDHDR *)mpu8VbvaPartial;
1060 *pcbCmd = mcbVbvaPartial;
1061
1062 mpu8VbvaPartial = NULL;
1063 mcbVbvaPartial = 0;
1064
1065 /* Advance the record index. */
1066 mpVbvaMemory->indexRecordFirst = (indexRecordFirst + 1) % VBVA_MAX_RECORDS;
1067
1068#ifdef DEBUG_sunlover
1069 LogFlowFunc (("partial done ok, data = %d, free = %d\n",
1070 mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1071#endif /* DEBUG_sunlover */
1072 }
1073
1074 return true;
1075 }
1076
1077 /* A new record need to be processed. */
1078 if (pRecord->cbRecord & VBVA_F_RECORD_PARTIAL)
1079 {
1080 /* Current record is being written by guest. '=' is important here. */
1081 if (cbRecord >= VBVA_RING_BUFFER_SIZE - VBVA_RING_BUFFER_THRESHOLD)
1082 {
1083 /* Partial read must be started. */
1084 if (!vbvaPartialRead (&mpu8VbvaPartial, &mcbVbvaPartial, cbRecord, mpVbvaMemory))
1085 {
1086 return false;
1087 }
1088
1089 LogFlowFunc (("started partial record mcbVbvaPartial = 0x%08X cbRecord 0x%08X, first = %d, free = %d\n",
1090 mcbVbvaPartial, pRecord->cbRecord, indexRecordFirst, indexRecordFree));
1091 }
1092
1093 return true;
1094 }
1095
1096 /* Current record is complete. If it is not empty, process it. */
1097 if (cbRecord)
1098 {
1099 /* The size of largest contiguos chunk in the ring biffer. */
1100 uint32_t u32BytesTillBoundary = VBVA_RING_BUFFER_SIZE - mpVbvaMemory->off32Data;
1101
1102 /* The ring buffer pointer. */
1103 uint8_t *au8RingBuffer = &mpVbvaMemory->au8RingBuffer[0];
1104
1105 /* The pointer to data in the ring buffer. */
1106 uint8_t *src = &au8RingBuffer[mpVbvaMemory->off32Data];
1107
1108 /* Fetch or point the data. */
1109 if (u32BytesTillBoundary >= cbRecord)
1110 {
1111 /* The command does not cross buffer boundary. Return address in the buffer. */
1112 *ppHdr = (VBVACMDHDR *)src;
1113
1114 /* Advance data offset. */
1115 mpVbvaMemory->off32Data = (mpVbvaMemory->off32Data + cbRecord) % VBVA_RING_BUFFER_SIZE;
1116 }
1117 else
1118 {
1119 /* The command crosses buffer boundary. Rare case, so not optimized. */
1120 uint8_t *dst = (uint8_t *)RTMemAlloc (cbRecord);
1121
1122 if (!dst)
1123 {
1124 LogFlowFunc (("could not allocate %d bytes from heap!!!\n", cbRecord));
1125 mpVbvaMemory->off32Data = (mpVbvaMemory->off32Data + cbRecord) % VBVA_RING_BUFFER_SIZE;
1126 return false;
1127 }
1128
1129 vbvaFetchBytes (mpVbvaMemory, dst, cbRecord);
1130
1131 *ppHdr = (VBVACMDHDR *)dst;
1132
1133#ifdef DEBUG_sunlover
1134 LogFlowFunc (("Allocated from heap %p\n", dst));
1135#endif /* DEBUG_sunlover */
1136 }
1137 }
1138
1139 *pcbCmd = cbRecord;
1140
1141 /* Advance the record index. */
1142 mpVbvaMemory->indexRecordFirst = (indexRecordFirst + 1) % VBVA_MAX_RECORDS;
1143
1144#ifdef DEBUG_sunlover
1145 LogFlowFunc (("done ok, data = %d, free = %d\n",
1146 mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1147#endif /* DEBUG_sunlover */
1148
1149 return true;
1150}
1151
1152void Display::vbvaReleaseCmd (VBVACMDHDR *pHdr, int32_t cbCmd)
1153{
1154 uint8_t *au8RingBuffer = mpVbvaMemory->au8RingBuffer;
1155
1156 if ( (uint8_t *)pHdr >= au8RingBuffer
1157 && (uint8_t *)pHdr < &au8RingBuffer[VBVA_RING_BUFFER_SIZE])
1158 {
1159 /* The pointer is inside ring buffer. Must be continuous chunk. */
1160 Assert (VBVA_RING_BUFFER_SIZE - ((uint8_t *)pHdr - au8RingBuffer) >= cbCmd);
1161
1162 /* Do nothing. */
1163
1164 Assert (!mpu8VbvaPartial && mcbVbvaPartial == 0);
1165 }
1166 else
1167 {
1168 /* The pointer is outside. It is then an allocated copy. */
1169
1170#ifdef DEBUG_sunlover
1171 LogFlowFunc (("Free heap %p\n", pHdr));
1172#endif /* DEBUG_sunlover */
1173
1174 if ((uint8_t *)pHdr == mpu8VbvaPartial)
1175 {
1176 mpu8VbvaPartial = NULL;
1177 mcbVbvaPartial = 0;
1178 }
1179 else
1180 {
1181 Assert (!mpu8VbvaPartial && mcbVbvaPartial == 0);
1182 }
1183
1184 RTMemFree (pHdr);
1185 }
1186
1187 return;
1188}
1189
1190
1191/**
1192 * Called regularly on the DisplayRefresh timer.
1193 * Also on behalf of guest, when the ring buffer is full.
1194 *
1195 * @thread EMT
1196 */
1197void Display::VideoAccelFlush (void)
1198{
1199#ifdef DEBUG_sunlover_2
1200 LogFlowFunc (("mfVideoAccelEnabled = %d\n", mfVideoAccelEnabled));
1201#endif /* DEBUG_sunlover_2 */
1202
1203 if (!mfVideoAccelEnabled)
1204 {
1205 Log(("Display::VideoAccelFlush: called with disabled VBVA!!! Ignoring.\n"));
1206 return;
1207 }
1208
1209 /* Here VBVA is enabled and we have the accelerator memory pointer. */
1210 Assert(mpVbvaMemory);
1211
1212#ifdef DEBUG_sunlover_2
1213 LogFlowFunc (("indexRecordFirst = %d, indexRecordFree = %d, off32Data = %d, off32Free = %d\n",
1214 mpVbvaMemory->indexRecordFirst, mpVbvaMemory->indexRecordFree, mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1215#endif /* DEBUG_sunlover_2 */
1216
1217 /* Quick check for "nothing to update" case. */
1218 if (mpVbvaMemory->indexRecordFirst == mpVbvaMemory->indexRecordFree)
1219 {
1220 return;
1221 }
1222
1223 /* Process the ring buffer */
1224 unsigned uScreenId;
1225 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
1226 {
1227 if (!maFramebuffers[uScreenId].pFramebuffer.isNull())
1228 {
1229 maFramebuffers[uScreenId].pFramebuffer->Lock ();
1230 }
1231 }
1232
1233 /* Initialize dirty rectangles accumulator. */
1234 VBVADIRTYREGION rgn;
1235 vbvaRgnInit (&rgn, maFramebuffers, mcMonitors, this, mpDrv->pUpPort);
1236
1237 for (;;)
1238 {
1239 VBVACMDHDR *phdr = NULL;
1240 uint32_t cbCmd = ~0;
1241
1242 /* Fetch the command data. */
1243 if (!vbvaFetchCmd (&phdr, &cbCmd))
1244 {
1245 Log(("Display::VideoAccelFlush: unable to fetch command. off32Data = %d, off32Free = %d. Disabling VBVA!!!\n",
1246 mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
1247
1248 /* Disable VBVA on those processing errors. */
1249 VideoAccelEnable (false, NULL);
1250
1251 break;
1252 }
1253
1254 if (cbCmd == uint32_t(~0))
1255 {
1256 /* No more commands yet in the queue. */
1257 break;
1258 }
1259
1260 if (cbCmd != 0)
1261 {
1262#ifdef DEBUG_sunlover
1263 LogFlowFunc (("hdr: cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
1264 cbCmd, phdr->x, phdr->y, phdr->w, phdr->h));
1265#endif /* DEBUG_sunlover */
1266
1267 VBVACMDHDR hdrSaved = *phdr;
1268
1269 int x = phdr->x;
1270 int y = phdr->y;
1271 int w = phdr->w;
1272 int h = phdr->h;
1273
1274 uScreenId = mapCoordsToScreen(maFramebuffers, mcMonitors, &x, &y, &w, &h);
1275
1276 phdr->x = (int16_t)x;
1277 phdr->y = (int16_t)y;
1278 phdr->w = (uint16_t)w;
1279 phdr->h = (uint16_t)h;
1280
1281 DISPLAYFBINFO *pFBInfo = &maFramebuffers[uScreenId];
1282
1283 if (pFBInfo->u32ResizeStatus == ResizeStatus_Void)
1284 {
1285 /* Handle the command.
1286 *
1287 * Guest is responsible for updating the guest video memory.
1288 * The Windows guest does all drawing using Eng*.
1289 *
1290 * For local output, only dirty rectangle information is used
1291 * to update changed areas.
1292 *
1293 * Dirty rectangles are accumulated to exclude overlapping updates and
1294 * group small updates to a larger one.
1295 */
1296
1297 /* Accumulate the update. */
1298 vbvaRgnDirtyRect (&rgn, uScreenId, phdr);
1299
1300 /* Forward the command to VRDP server. */
1301 mParent->consoleVRDPServer()->SendUpdate (uScreenId, phdr, cbCmd);
1302
1303 *phdr = hdrSaved;
1304 }
1305 }
1306
1307 vbvaReleaseCmd (phdr, cbCmd);
1308 }
1309
1310 for (uScreenId = 0; uScreenId < mcMonitors; uScreenId++)
1311 {
1312 if (!maFramebuffers[uScreenId].pFramebuffer.isNull())
1313 {
1314 maFramebuffers[uScreenId].pFramebuffer->Unlock ();
1315 }
1316
1317 if (maFramebuffers[uScreenId].u32ResizeStatus == ResizeStatus_Void)
1318 {
1319 /* Draw the framebuffer. */
1320 vbvaRgnUpdateFramebuffer (&rgn, uScreenId);
1321 }
1322 }
1323}
1324
1325
1326// IDisplay properties
1327/////////////////////////////////////////////////////////////////////////////
1328
1329/**
1330 * Returns the current display width in pixel
1331 *
1332 * @returns COM status code
1333 * @param width Address of result variable.
1334 */
1335STDMETHODIMP Display::COMGETTER(Width) (ULONG *width)
1336{
1337 CheckComArgNotNull(width);
1338
1339 AutoCaller autoCaller(this);
1340 CheckComRCReturnRC(autoCaller.rc());
1341
1342 AutoWriteLock alock(this);
1343
1344 CHECK_CONSOLE_DRV (mpDrv);
1345
1346 *width = mpDrv->Connector.cx;
1347
1348 return S_OK;
1349}
1350
1351/**
1352 * Returns the current display height in pixel
1353 *
1354 * @returns COM status code
1355 * @param height Address of result variable.
1356 */
1357STDMETHODIMP Display::COMGETTER(Height) (ULONG *height)
1358{
1359 CheckComArgNotNull(height);
1360
1361 AutoCaller autoCaller(this);
1362 CheckComRCReturnRC(autoCaller.rc());
1363
1364 AutoWriteLock alock(this);
1365
1366 CHECK_CONSOLE_DRV (mpDrv);
1367
1368 *height = mpDrv->Connector.cy;
1369
1370 return S_OK;
1371}
1372
1373/**
1374 * Returns the current display color depth in bits
1375 *
1376 * @returns COM status code
1377 * @param bitsPerPixel Address of result variable.
1378 */
1379STDMETHODIMP Display::COMGETTER(BitsPerPixel) (ULONG *bitsPerPixel)
1380{
1381 if (!bitsPerPixel)
1382 return E_INVALIDARG;
1383
1384 AutoCaller autoCaller(this);
1385 CheckComRCReturnRC(autoCaller.rc());
1386
1387 AutoWriteLock alock(this);
1388
1389 CHECK_CONSOLE_DRV (mpDrv);
1390
1391 uint32_t cBits = 0;
1392 int rc = mpDrv->pUpPort->pfnQueryColorDepth(mpDrv->pUpPort, &cBits);
1393 AssertRC(rc);
1394 *bitsPerPixel = cBits;
1395
1396 return S_OK;
1397}
1398
1399
1400// IDisplay methods
1401/////////////////////////////////////////////////////////////////////////////
1402
1403STDMETHODIMP Display::SetFramebuffer (ULONG aScreenId,
1404 IFramebuffer *aFramebuffer)
1405{
1406 LogFlowFunc (("\n"));
1407
1408 if (aFramebuffer != NULL)
1409 CheckComArgOutPointerValid(aFramebuffer);
1410
1411 AutoCaller autoCaller(this);
1412 CheckComRCReturnRC(autoCaller.rc());
1413
1414 AutoWriteLock alock(this);
1415
1416 Console::SafeVMPtrQuiet pVM (mParent);
1417 if (pVM.isOk())
1418 {
1419 /* Must leave the lock here because the changeFramebuffer will
1420 * also obtain it. */
1421 alock.leave ();
1422
1423 /* send request to the EMT thread */
1424 int vrc = VMR3ReqCallWait (pVM, VMCPUID_ANY,
1425 (PFNRT) changeFramebuffer, 3, this, aFramebuffer, aScreenId);
1426
1427 alock.enter ();
1428
1429 ComAssertRCRet (vrc, E_FAIL);
1430 }
1431 else
1432 {
1433 /* No VM is created (VM is powered off), do a direct call */
1434 int vrc = changeFramebuffer (this, aFramebuffer, aScreenId);
1435 ComAssertRCRet (vrc, E_FAIL);
1436 }
1437
1438 return S_OK;
1439}
1440
1441STDMETHODIMP Display::GetFramebuffer (ULONG aScreenId,
1442 IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin)
1443{
1444 LogFlowFunc (("aScreenId = %d\n", aScreenId));
1445
1446 CheckComArgOutPointerValid(aFramebuffer);
1447
1448 AutoCaller autoCaller(this);
1449 CheckComRCReturnRC(autoCaller.rc());
1450
1451 AutoWriteLock alock(this);
1452
1453 /* @todo this should be actually done on EMT. */
1454 DISPLAYFBINFO *pFBInfo = &maFramebuffers[aScreenId];
1455
1456 *aFramebuffer = pFBInfo->pFramebuffer;
1457 if (*aFramebuffer)
1458 (*aFramebuffer)->AddRef ();
1459 if (aXOrigin)
1460 *aXOrigin = pFBInfo->xOrigin;
1461 if (aYOrigin)
1462 *aYOrigin = pFBInfo->yOrigin;
1463
1464 return S_OK;
1465}
1466
1467STDMETHODIMP Display::SetVideoModeHint(ULONG aWidth, ULONG aHeight,
1468 ULONG aBitsPerPixel, ULONG aDisplay)
1469{
1470 AutoCaller autoCaller(this);
1471 CheckComRCReturnRC(autoCaller.rc());
1472
1473 AutoWriteLock alock(this);
1474
1475 CHECK_CONSOLE_DRV (mpDrv);
1476
1477 /*
1478 * Do some rough checks for valid input
1479 */
1480 ULONG width = aWidth;
1481 if (!width)
1482 width = mpDrv->Connector.cx;
1483 ULONG height = aHeight;
1484 if (!height)
1485 height = mpDrv->Connector.cy;
1486 ULONG bpp = aBitsPerPixel;
1487 if (!bpp)
1488 {
1489 uint32_t cBits = 0;
1490 int rc = mpDrv->pUpPort->pfnQueryColorDepth(mpDrv->pUpPort, &cBits);
1491 AssertRC(rc);
1492 bpp = cBits;
1493 }
1494 ULONG cMonitors;
1495 mParent->machine()->COMGETTER(MonitorCount)(&cMonitors);
1496 if (cMonitors == 0 && aDisplay > 0)
1497 return E_INVALIDARG;
1498 if (aDisplay >= cMonitors)
1499 return E_INVALIDARG;
1500
1501// sunlover 20070614: It is up to the guest to decide whether the hint is valid.
1502// ULONG vramSize;
1503// mParent->machine()->COMGETTER(VRAMSize)(&vramSize);
1504// /* enough VRAM? */
1505// if ((width * height * (bpp / 8)) > (vramSize * 1024 * 1024))
1506// return setError(E_FAIL, tr("Not enough VRAM for the selected video mode"));
1507
1508 /* Have to leave the lock because the pfnRequestDisplayChange
1509 * will call EMT. */
1510 alock.leave ();
1511 if (mParent->getVMMDev())
1512 mParent->getVMMDev()->getVMMDevPort()->
1513 pfnRequestDisplayChange (mParent->getVMMDev()->getVMMDevPort(),
1514 aWidth, aHeight, aBitsPerPixel, aDisplay);
1515 return S_OK;
1516}
1517
1518STDMETHODIMP Display::SetSeamlessMode (BOOL enabled)
1519{
1520 AutoCaller autoCaller(this);
1521 CheckComRCReturnRC(autoCaller.rc());
1522
1523 AutoWriteLock alock(this);
1524
1525 /* Have to leave the lock because the pfnRequestSeamlessChange will call EMT. */
1526 alock.leave ();
1527 if (mParent->getVMMDev())
1528 mParent->getVMMDev()->getVMMDevPort()->
1529 pfnRequestSeamlessChange (mParent->getVMMDev()->getVMMDevPort(),
1530 !!enabled);
1531 return S_OK;
1532}
1533
1534STDMETHODIMP Display::TakeScreenShot (BYTE *address, ULONG width, ULONG height)
1535{
1536 /// @todo (r=dmik) this function may take too long to complete if the VM
1537 // is doing something like saving state right now. Which, in case if it
1538 // is called on the GUI thread, will make it unresponsive. We should
1539 // check the machine state here (by enclosing the check and VMRequCall
1540 // within the Console lock to make it atomic).
1541
1542 LogFlowFuncEnter();
1543 LogFlowFunc (("address=%p, width=%d, height=%d\n",
1544 address, width, height));
1545
1546 CheckComArgNotNull(address);
1547 CheckComArgExpr(width, width != 0);
1548 CheckComArgExpr(height, height != 0);
1549
1550 AutoCaller autoCaller(this);
1551 CheckComRCReturnRC(autoCaller.rc());
1552
1553 AutoWriteLock alock(this);
1554
1555 CHECK_CONSOLE_DRV (mpDrv);
1556
1557 Console::SafeVMPtr pVM (mParent);
1558 CheckComRCReturnRC(pVM.rc());
1559
1560 HRESULT rc = S_OK;
1561
1562 LogFlowFunc (("Sending SCREENSHOT request\n"));
1563
1564 /*
1565 * First try use the graphics device features for making a snapshot.
1566 * This does not support stretching, is an optional feature (returns
1567 * not supported).
1568 *
1569 * Note: It may cause a display resize. Watch out for deadlocks.
1570 */
1571 int rcVBox = VERR_NOT_SUPPORTED;
1572 if ( mpDrv->Connector.cx == width
1573 && mpDrv->Connector.cy == height)
1574 {
1575 size_t cbData = RT_ALIGN_Z(width, 4) * 4 * height;
1576 rcVBox = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)mpDrv->pUpPort->pfnSnapshot, 6, mpDrv->pUpPort,
1577 address, cbData, (uintptr_t)NULL, (uintptr_t)NULL, (uintptr_t)NULL);
1578 }
1579
1580 /*
1581 * If the function returns not supported, or if stretching is requested,
1582 * we'll have to do all the work ourselves using the framebuffer data.
1583 */
1584 if (rcVBox == VERR_NOT_SUPPORTED || rcVBox == VERR_NOT_IMPLEMENTED)
1585 {
1586 /** @todo implement snapshot stretching & generic snapshot fallback. */
1587 rc = setError (E_NOTIMPL, tr ("This feature is not implemented"));
1588 }
1589 else if (RT_FAILURE(rcVBox))
1590 rc = setError (VBOX_E_IPRT_ERROR,
1591 tr ("Could not take a screenshot (%Rrc)"), rcVBox);
1592
1593 LogFlowFunc (("rc=%08X\n", rc));
1594 LogFlowFuncLeave();
1595 return rc;
1596}
1597
1598STDMETHODIMP Display::TakeScreenShotSlow (ULONG width, ULONG height,
1599 ComSafeArrayOut(BYTE, aScreenData))
1600{
1601 HRESULT rc = S_OK;
1602
1603 rc = setError (E_NOTIMPL, tr ("This feature is not implemented"));
1604
1605 return rc;
1606}
1607
1608
1609STDMETHODIMP Display::DrawToScreen (BYTE *address, ULONG x, ULONG y,
1610 ULONG width, ULONG height)
1611{
1612 /// @todo (r=dmik) this function may take too long to complete if the VM
1613 // is doing something like saving state right now. Which, in case if it
1614 // is called on the GUI thread, will make it unresponsive. We should
1615 // check the machine state here (by enclosing the check and VMRequCall
1616 // within the Console lock to make it atomic).
1617
1618 LogFlowFuncEnter();
1619 LogFlowFunc (("address=%p, x=%d, y=%d, width=%d, height=%d\n",
1620 (void *)address, x, y, width, height));
1621
1622 CheckComArgNotNull(address);
1623 CheckComArgExpr(width, width != 0);
1624 CheckComArgExpr(height, height != 0);
1625
1626 AutoCaller autoCaller(this);
1627 CheckComRCReturnRC(autoCaller.rc());
1628
1629 AutoWriteLock alock(this);
1630
1631 CHECK_CONSOLE_DRV (mpDrv);
1632
1633 Console::SafeVMPtr pVM (mParent);
1634 CheckComRCReturnRC(pVM.rc());
1635
1636 /*
1637 * Again we're lazy and make the graphics device do all the
1638 * dirty conversion work.
1639 */
1640 int rcVBox = VMR3ReqCallWait(pVM, VMCPUID_ANY, (PFNRT)mpDrv->pUpPort->pfnDisplayBlt, 6,
1641 mpDrv->pUpPort, address, x, y, width, height);
1642
1643 /*
1644 * If the function returns not supported, we'll have to do all the
1645 * work ourselves using the framebuffer.
1646 */
1647 HRESULT rc = S_OK;
1648 if (rcVBox == VERR_NOT_SUPPORTED || rcVBox == VERR_NOT_IMPLEMENTED)
1649 {
1650 /** @todo implement generic fallback for screen blitting. */
1651 rc = E_NOTIMPL;
1652 }
1653 else if (RT_FAILURE(rcVBox))
1654 rc = setError (VBOX_E_IPRT_ERROR,
1655 tr ("Could not draw to the screen (%Rrc)"), rcVBox);
1656//@todo
1657// else
1658// {
1659// /* All ok. Redraw the screen. */
1660// handleDisplayUpdate (x, y, width, height);
1661// }
1662
1663 LogFlowFunc (("rc=%08X\n", rc));
1664 LogFlowFuncLeave();
1665 return rc;
1666}
1667
1668/**
1669 * Does a full invalidation of the VM display and instructs the VM
1670 * to update it immediately.
1671 *
1672 * @returns COM status code
1673 */
1674STDMETHODIMP Display::InvalidateAndUpdate()
1675{
1676 LogFlowFuncEnter();
1677
1678 AutoCaller autoCaller(this);
1679 CheckComRCReturnRC(autoCaller.rc());
1680
1681 AutoWriteLock alock(this);
1682
1683 CHECK_CONSOLE_DRV (mpDrv);
1684
1685 Console::SafeVMPtr pVM (mParent);
1686 CheckComRCReturnRC(pVM.rc());
1687
1688 HRESULT rc = S_OK;
1689
1690 LogFlowFunc (("Sending DPYUPDATE request\n"));
1691
1692 /* Have to leave the lock when calling EMT. */
1693 alock.leave ();
1694
1695 /* pdm.h says that this has to be called from the EMT thread */
1696 int rcVBox = VMR3ReqCallVoidWait(pVM, VMCPUID_ANY,
1697 (PFNRT)mpDrv->pUpPort->pfnUpdateDisplayAll, 1, mpDrv->pUpPort);
1698 alock.enter ();
1699
1700 if (RT_FAILURE(rcVBox))
1701 rc = setError (VBOX_E_IPRT_ERROR,
1702 tr ("Could not invalidate and update the screen (%Rrc)"), rcVBox);
1703
1704 LogFlowFunc (("rc=%08X\n", rc));
1705 LogFlowFuncLeave();
1706 return rc;
1707}
1708
1709/**
1710 * Notification that the framebuffer has completed the
1711 * asynchronous resize processing
1712 *
1713 * @returns COM status code
1714 */
1715STDMETHODIMP Display::ResizeCompleted(ULONG aScreenId)
1716{
1717 LogFlowFunc (("\n"));
1718
1719 /// @todo (dmik) can we AutoWriteLock alock(this); here?
1720 // do it when we switch this class to VirtualBoxBase_NEXT.
1721 // This will require general code review and may add some details.
1722 // In particular, we may want to check whether EMT is really waiting for
1723 // this notification, etc. It might be also good to obey the caller to make
1724 // sure this method is not called from more than one thread at a time
1725 // (and therefore don't use Display lock at all here to save some
1726 // milliseconds).
1727 AutoCaller autoCaller(this);
1728 CheckComRCReturnRC(autoCaller.rc());
1729
1730 /* this is only valid for external framebuffers */
1731 if (maFramebuffers[aScreenId].pFramebuffer == NULL)
1732 return setError (VBOX_E_NOT_SUPPORTED,
1733 tr ("Resize completed notification is valid only "
1734 "for external framebuffers"));
1735
1736 /* Set the flag indicating that the resize has completed and display
1737 * data need to be updated. */
1738 bool f = ASMAtomicCmpXchgU32 (&maFramebuffers[aScreenId].u32ResizeStatus,
1739 ResizeStatus_UpdateDisplayData, ResizeStatus_InProgress);
1740 AssertRelease(f);NOREF(f);
1741
1742 return S_OK;
1743}
1744
1745/**
1746 * Notification that the framebuffer has completed the
1747 * asynchronous update processing
1748 *
1749 * @returns COM status code
1750 */
1751STDMETHODIMP Display::UpdateCompleted()
1752{
1753 LogFlowFunc (("\n"));
1754
1755 /// @todo (dmik) can we AutoWriteLock alock(this); here?
1756 // do it when we switch this class to VirtualBoxBase_NEXT.
1757 // Tthis will require general code review and may add some details.
1758 // In particular, we may want to check whether EMT is really waiting for
1759 // this notification, etc. It might be also good to obey the caller to make
1760 // sure this method is not called from more than one thread at a time
1761 // (and therefore don't use Display lock at all here to save some
1762 // milliseconds).
1763 AutoCaller autoCaller(this);
1764 CheckComRCReturnRC(autoCaller.rc());
1765
1766 /* this is only valid for external framebuffers */
1767 if (maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer == NULL)
1768 return setError (VBOX_E_NOT_SUPPORTED,
1769 tr ("Resize completed notification is valid only "
1770 "for external framebuffers"));
1771
1772 return S_OK;
1773}
1774
1775STDMETHODIMP Display::CompleteVHWACommand(BYTE *pCommand)
1776{
1777#ifdef VBOX_WITH_VIDEOHWACCEL
1778 mpDrv->pVBVACallbacks->pfnVHWACommandCompleteAsynch(mpDrv->pVBVACallbacks, (PVBOXVHWACMD)pCommand);
1779 return S_OK;
1780#else
1781 return E_NOTIMPL;
1782#endif
1783}
1784
1785// private methods
1786/////////////////////////////////////////////////////////////////////////////
1787
1788/**
1789 * Helper to update the display information from the framebuffer.
1790 *
1791 * @param aCheckParams true to compare the parameters of the current framebuffer
1792 * and the new one and issue handleDisplayResize()
1793 * if they differ.
1794 * @thread EMT
1795 */
1796void Display::updateDisplayData (bool aCheckParams /* = false */)
1797{
1798 /* the driver might not have been constructed yet */
1799 if (!mpDrv)
1800 return;
1801
1802#if DEBUG
1803 /*
1804 * Sanity check. Note that this method may be called on EMT after Console
1805 * has started the power down procedure (but before our #drvDestruct() is
1806 * called, in which case pVM will aleady be NULL but mpDrv will not). Since
1807 * we don't really need pVM to proceed, we avoid this check in the release
1808 * build to save some ms (necessary to construct SafeVMPtrQuiet) in this
1809 * time-critical method.
1810 */
1811 Console::SafeVMPtrQuiet pVM (mParent);
1812 if (pVM.isOk())
1813 VM_ASSERT_EMT (pVM.raw());
1814#endif
1815
1816 /* The method is only relevant to the primary framebuffer. */
1817 IFramebuffer *pFramebuffer = maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
1818
1819 if (pFramebuffer)
1820 {
1821 HRESULT rc;
1822 BYTE *address = 0;
1823 rc = pFramebuffer->COMGETTER(Address) (&address);
1824 AssertComRC (rc);
1825 ULONG bytesPerLine = 0;
1826 rc = pFramebuffer->COMGETTER(BytesPerLine) (&bytesPerLine);
1827 AssertComRC (rc);
1828 ULONG bitsPerPixel = 0;
1829 rc = pFramebuffer->COMGETTER(BitsPerPixel) (&bitsPerPixel);
1830 AssertComRC (rc);
1831 ULONG width = 0;
1832 rc = pFramebuffer->COMGETTER(Width) (&width);
1833 AssertComRC (rc);
1834 ULONG height = 0;
1835 rc = pFramebuffer->COMGETTER(Height) (&height);
1836 AssertComRC (rc);
1837
1838 /*
1839 * Check current parameters with new ones and issue handleDisplayResize()
1840 * to let the new frame buffer adjust itself properly. Note that it will
1841 * result into a recursive updateDisplayData() call but with
1842 * aCheckOld = false.
1843 */
1844 if (aCheckParams &&
1845 (mLastAddress != address ||
1846 mLastBytesPerLine != bytesPerLine ||
1847 mLastBitsPerPixel != bitsPerPixel ||
1848 mLastWidth != (int) width ||
1849 mLastHeight != (int) height))
1850 {
1851 handleDisplayResize (VBOX_VIDEO_PRIMARY_SCREEN, mLastBitsPerPixel,
1852 mLastAddress,
1853 mLastBytesPerLine,
1854 mLastWidth,
1855 mLastHeight);
1856 return;
1857 }
1858
1859 mpDrv->Connector.pu8Data = (uint8_t *) address;
1860 mpDrv->Connector.cbScanline = bytesPerLine;
1861 mpDrv->Connector.cBits = bitsPerPixel;
1862 mpDrv->Connector.cx = width;
1863 mpDrv->Connector.cy = height;
1864 }
1865 else
1866 {
1867 /* black hole */
1868 mpDrv->Connector.pu8Data = NULL;
1869 mpDrv->Connector.cbScanline = 0;
1870 mpDrv->Connector.cBits = 0;
1871 mpDrv->Connector.cx = 0;
1872 mpDrv->Connector.cy = 0;
1873 }
1874}
1875
1876/**
1877 * Changes the current frame buffer. Called on EMT to avoid both
1878 * race conditions and excessive locking.
1879 *
1880 * @note locks this object for writing
1881 * @thread EMT
1882 */
1883/* static */
1884DECLCALLBACK(int) Display::changeFramebuffer (Display *that, IFramebuffer *aFB,
1885 unsigned uScreenId)
1886{
1887 LogFlowFunc (("uScreenId = %d\n", uScreenId));
1888
1889 AssertReturn(that, VERR_INVALID_PARAMETER);
1890 AssertReturn(uScreenId < that->mcMonitors, VERR_INVALID_PARAMETER);
1891
1892 AutoCaller autoCaller(that);
1893 CheckComRCReturnRC(autoCaller.rc());
1894
1895 AutoWriteLock alock(that);
1896
1897 DISPLAYFBINFO *pDisplayFBInfo = &that->maFramebuffers[uScreenId];
1898 pDisplayFBInfo->pFramebuffer = aFB;
1899
1900 that->mParent->consoleVRDPServer()->SendResize ();
1901
1902 that->updateDisplayData (true /* aCheckParams */);
1903
1904 return VINF_SUCCESS;
1905}
1906
1907/**
1908 * Handle display resize event issued by the VGA device for the primary screen.
1909 *
1910 * @see PDMIDISPLAYCONNECTOR::pfnResize
1911 */
1912DECLCALLBACK(int) Display::displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface,
1913 uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy)
1914{
1915 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
1916
1917 LogFlowFunc (("bpp %d, pvVRAM %p, cbLine %d, cx %d, cy %d\n",
1918 bpp, pvVRAM, cbLine, cx, cy));
1919
1920 return pDrv->pDisplay->handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, bpp, pvVRAM, cbLine, cx, cy);
1921}
1922
1923/**
1924 * Handle display update.
1925 *
1926 * @see PDMIDISPLAYCONNECTOR::pfnUpdateRect
1927 */
1928DECLCALLBACK(void) Display::displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
1929 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
1930{
1931 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
1932
1933#ifdef DEBUG_sunlover
1934 LogFlowFunc (("mfVideoAccelEnabled = %d, %d,%d %dx%d\n",
1935 pDrv->pDisplay->mfVideoAccelEnabled, x, y, cx, cy));
1936#endif /* DEBUG_sunlover */
1937
1938 /* This call does update regardless of VBVA status.
1939 * But in VBVA mode this is called only as result of
1940 * pfnUpdateDisplayAll in the VGA device.
1941 */
1942
1943 pDrv->pDisplay->handleDisplayUpdate(x, y, cx, cy);
1944}
1945
1946/**
1947 * Periodic display refresh callback.
1948 *
1949 * @see PDMIDISPLAYCONNECTOR::pfnRefresh
1950 */
1951DECLCALLBACK(void) Display::displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface)
1952{
1953 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
1954
1955#ifdef DEBUG_sunlover
1956 STAM_PROFILE_START(&StatDisplayRefresh, a);
1957#endif /* DEBUG_sunlover */
1958
1959#ifdef DEBUG_sunlover_2
1960 LogFlowFunc (("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
1961 pDrv->pDisplay->mfVideoAccelEnabled));
1962#endif /* DEBUG_sunlover_2 */
1963
1964 Display *pDisplay = pDrv->pDisplay;
1965 bool fNoUpdate = false; /* Do not update the display if any of the framebuffers is being resized. */
1966 unsigned uScreenId;
1967
1968 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
1969 {
1970 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
1971
1972 /* Check the resize status. The status can be checked normally because
1973 * the status affects only the EMT.
1974 */
1975 uint32_t u32ResizeStatus = pFBInfo->u32ResizeStatus;
1976
1977 if (u32ResizeStatus == ResizeStatus_UpdateDisplayData)
1978 {
1979 LogFlowFunc (("ResizeStatus_UpdateDisplayData %d\n", uScreenId));
1980 fNoUpdate = true; /* Always set it here, because pfnUpdateDisplayAll can cause a new resize. */
1981 /* The framebuffer was resized and display data need to be updated. */
1982 pDisplay->handleResizeCompletedEMT ();
1983 if (pFBInfo->u32ResizeStatus != ResizeStatus_Void)
1984 {
1985 /* The resize status could be not Void here because a pending resize is issued. */
1986 continue;
1987 }
1988 /* Continue with normal processing because the status here is ResizeStatus_Void. */
1989 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
1990 {
1991 /* Repaint the display because VM continued to run during the framebuffer resize. */
1992 if (!pFBInfo->pFramebuffer.isNull())
1993 pDrv->pUpPort->pfnUpdateDisplayAll(pDrv->pUpPort);
1994 }
1995 }
1996 else if (u32ResizeStatus == ResizeStatus_InProgress)
1997 {
1998 /* The framebuffer is being resized. Do not call the VGA device back. Immediately return. */
1999 LogFlowFunc (("ResizeStatus_InProcess\n"));
2000 fNoUpdate = true;
2001 continue;
2002 }
2003 }
2004
2005 if (!fNoUpdate)
2006 {
2007 if (pDisplay->mfPendingVideoAccelEnable)
2008 {
2009 /* Acceleration was enabled while machine was not yet running
2010 * due to restoring from saved state. Update entire display and
2011 * actually enable acceleration.
2012 */
2013 Assert(pDisplay->mpPendingVbvaMemory);
2014
2015 /* Acceleration can not be yet enabled.*/
2016 Assert(pDisplay->mpVbvaMemory == NULL);
2017 Assert(!pDisplay->mfVideoAccelEnabled);
2018
2019 if (pDisplay->mfMachineRunning)
2020 {
2021 pDisplay->VideoAccelEnable (pDisplay->mfPendingVideoAccelEnable,
2022 pDisplay->mpPendingVbvaMemory);
2023
2024 /* Reset the pending state. */
2025 pDisplay->mfPendingVideoAccelEnable = false;
2026 pDisplay->mpPendingVbvaMemory = NULL;
2027 }
2028 }
2029 else
2030 {
2031 Assert(pDisplay->mpPendingVbvaMemory == NULL);
2032
2033 if (pDisplay->mfVideoAccelEnabled)
2034 {
2035 Assert(pDisplay->mpVbvaMemory);
2036 pDisplay->VideoAccelFlush ();
2037 }
2038 else
2039 {
2040 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN];
2041 if (!pFBInfo->pFramebuffer.isNull())
2042 {
2043 Assert(pDrv->Connector.pu8Data);
2044 Assert(pFBInfo->u32ResizeStatus == ResizeStatus_Void);
2045 pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
2046 }
2047 }
2048
2049 /* Inform the VRDP server that the current display update sequence is
2050 * completed. At this moment the framebuffer memory contains a definite
2051 * image, that is synchronized with the orders already sent to VRDP client.
2052 * The server can now process redraw requests from clients or initial
2053 * fullscreen updates for new clients.
2054 */
2055 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
2056 {
2057 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
2058
2059 if (!pFBInfo->pFramebuffer.isNull() && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
2060 {
2061 Assert (pDisplay->mParent && pDisplay->mParent->consoleVRDPServer());
2062 pDisplay->mParent->consoleVRDPServer()->SendUpdate (uScreenId, NULL, 0);
2063 }
2064 }
2065 }
2066 }
2067
2068#ifdef DEBUG_sunlover
2069 STAM_PROFILE_STOP(&StatDisplayRefresh, a);
2070#endif /* DEBUG_sunlover */
2071#ifdef DEBUG_sunlover_2
2072 LogFlowFunc (("leave\n"));
2073#endif /* DEBUG_sunlover_2 */
2074}
2075
2076/**
2077 * Reset notification
2078 *
2079 * @see PDMIDISPLAYCONNECTOR::pfnReset
2080 */
2081DECLCALLBACK(void) Display::displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface)
2082{
2083 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2084
2085 LogFlowFunc (("\n"));
2086
2087 /* Disable VBVA mode. */
2088 pDrv->pDisplay->VideoAccelEnable (false, NULL);
2089}
2090
2091/**
2092 * LFBModeChange notification
2093 *
2094 * @see PDMIDISPLAYCONNECTOR::pfnLFBModeChange
2095 */
2096DECLCALLBACK(void) Display::displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled)
2097{
2098 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2099
2100 LogFlowFunc (("fEnabled=%d\n", fEnabled));
2101
2102 NOREF(fEnabled);
2103
2104 /* Disable VBVA mode in any case. The guest driver reenables VBVA mode if necessary. */
2105 pDrv->pDisplay->VideoAccelEnable (false, NULL);
2106}
2107
2108/**
2109 * Adapter information change notification.
2110 *
2111 * @see PDMIDISPLAYCONNECTOR::pfnProcessAdapterData
2112 */
2113DECLCALLBACK(void) Display::displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize)
2114{
2115 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2116
2117 if (pvVRAM == NULL)
2118 {
2119 unsigned i;
2120 for (i = 0; i < pDrv->pDisplay->mcMonitors; i++)
2121 {
2122 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[i];
2123
2124 pFBInfo->u32Offset = 0;
2125 pFBInfo->u32MaxFramebufferSize = 0;
2126 pFBInfo->u32InformationSize = 0;
2127 }
2128 }
2129#ifndef VBOX_WITH_HGSMI
2130 else
2131 {
2132 uint8_t *pu8 = (uint8_t *)pvVRAM;
2133 pu8 += u32VRAMSize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE;
2134
2135 // @todo
2136 uint8_t *pu8End = pu8 + VBOX_VIDEO_ADAPTER_INFORMATION_SIZE;
2137
2138 VBOXVIDEOINFOHDR *pHdr;
2139
2140 for (;;)
2141 {
2142 pHdr = (VBOXVIDEOINFOHDR *)pu8;
2143 pu8 += sizeof (VBOXVIDEOINFOHDR);
2144
2145 if (pu8 >= pu8End)
2146 {
2147 LogRel(("VBoxVideo: Guest adapter information overflow!!!\n"));
2148 break;
2149 }
2150
2151 if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_DISPLAY)
2152 {
2153 if (pHdr->u16Length != sizeof (VBOXVIDEOINFODISPLAY))
2154 {
2155 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "DISPLAY", pHdr->u16Length));
2156 break;
2157 }
2158
2159 VBOXVIDEOINFODISPLAY *pDisplay = (VBOXVIDEOINFODISPLAY *)pu8;
2160
2161 if (pDisplay->u32Index >= pDrv->pDisplay->mcMonitors)
2162 {
2163 LogRel(("VBoxVideo: Guest adapter information invalid display index %d!!!\n", pDisplay->u32Index));
2164 break;
2165 }
2166
2167 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[pDisplay->u32Index];
2168
2169 pFBInfo->u32Offset = pDisplay->u32Offset;
2170 pFBInfo->u32MaxFramebufferSize = pDisplay->u32FramebufferSize;
2171 pFBInfo->u32InformationSize = pDisplay->u32InformationSize;
2172
2173 LogFlow(("VBOX_VIDEO_INFO_TYPE_DISPLAY: %d: at 0x%08X, size 0x%08X, info 0x%08X\n", pDisplay->u32Index, pDisplay->u32Offset, pDisplay->u32FramebufferSize, pDisplay->u32InformationSize));
2174 }
2175 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_QUERY_CONF32)
2176 {
2177 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOQUERYCONF32))
2178 {
2179 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "CONF32", pHdr->u16Length));
2180 break;
2181 }
2182
2183 VBOXVIDEOINFOQUERYCONF32 *pConf32 = (VBOXVIDEOINFOQUERYCONF32 *)pu8;
2184
2185 switch (pConf32->u32Index)
2186 {
2187 case VBOX_VIDEO_QCI32_MONITOR_COUNT:
2188 {
2189 pConf32->u32Value = pDrv->pDisplay->mcMonitors;
2190 } break;
2191
2192 case VBOX_VIDEO_QCI32_OFFSCREEN_HEAP_SIZE:
2193 {
2194 /* @todo make configurable. */
2195 pConf32->u32Value = _1M;
2196 } break;
2197
2198 default:
2199 LogRel(("VBoxVideo: CONF32 %d not supported!!! Skipping.\n", pConf32->u32Index));
2200 }
2201 }
2202 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_END)
2203 {
2204 if (pHdr->u16Length != 0)
2205 {
2206 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "END", pHdr->u16Length));
2207 break;
2208 }
2209
2210 break;
2211 }
2212 else if (pHdr->u8Type != VBOX_VIDEO_INFO_TYPE_NV_HEAP) /** @todo why is Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp pushing this to us? */
2213 {
2214 LogRel(("Guest adapter information contains unsupported type %d. The block has been skipped.\n", pHdr->u8Type));
2215 }
2216
2217 pu8 += pHdr->u16Length;
2218 }
2219 }
2220#endif /* !VBOX_WITH_HGSMI */
2221}
2222
2223/**
2224 * Display information change notification.
2225 *
2226 * @see PDMIDISPLAYCONNECTOR::pfnProcessDisplayData
2227 */
2228DECLCALLBACK(void) Display::displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId)
2229{
2230 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2231
2232 if (uScreenId >= pDrv->pDisplay->mcMonitors)
2233 {
2234 LogRel(("VBoxVideo: Guest display information invalid display index %d!!!\n", uScreenId));
2235 return;
2236 }
2237
2238 /* Get the display information structure. */
2239 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[uScreenId];
2240
2241 uint8_t *pu8 = (uint8_t *)pvVRAM;
2242 pu8 += pFBInfo->u32Offset + pFBInfo->u32MaxFramebufferSize;
2243
2244 // @todo
2245 uint8_t *pu8End = pu8 + pFBInfo->u32InformationSize;
2246
2247 VBOXVIDEOINFOHDR *pHdr;
2248
2249 for (;;)
2250 {
2251 pHdr = (VBOXVIDEOINFOHDR *)pu8;
2252 pu8 += sizeof (VBOXVIDEOINFOHDR);
2253
2254 if (pu8 >= pu8End)
2255 {
2256 LogRel(("VBoxVideo: Guest display information overflow!!!\n"));
2257 break;
2258 }
2259
2260 if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_SCREEN)
2261 {
2262 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOSCREEN))
2263 {
2264 LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "SCREEN", pHdr->u16Length));
2265 break;
2266 }
2267
2268 VBOXVIDEOINFOSCREEN *pScreen = (VBOXVIDEOINFOSCREEN *)pu8;
2269
2270 pFBInfo->xOrigin = pScreen->xOrigin;
2271 pFBInfo->yOrigin = pScreen->yOrigin;
2272
2273 pFBInfo->w = pScreen->u16Width;
2274 pFBInfo->h = pScreen->u16Height;
2275
2276 LogFlow(("VBOX_VIDEO_INFO_TYPE_SCREEN: (%p) %d: at %d,%d, linesize 0x%X, size %dx%d, bpp %d, flags 0x%02X\n",
2277 pHdr, uScreenId, pScreen->xOrigin, pScreen->yOrigin, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height, pScreen->bitsPerPixel, pScreen->u8Flags));
2278
2279 if (uScreenId != VBOX_VIDEO_PRIMARY_SCREEN)
2280 {
2281 /* Primary screen resize is initiated by the VGA device. */
2282 pDrv->pDisplay->handleDisplayResize(uScreenId, pScreen->bitsPerPixel, (uint8_t *)pvVRAM + pFBInfo->u32Offset, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height);
2283 }
2284 }
2285 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_END)
2286 {
2287 if (pHdr->u16Length != 0)
2288 {
2289 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "END", pHdr->u16Length));
2290 break;
2291 }
2292
2293 break;
2294 }
2295 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_HOST_EVENTS)
2296 {
2297 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOHOSTEVENTS))
2298 {
2299 LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "HOST_EVENTS", pHdr->u16Length));
2300 break;
2301 }
2302
2303 VBOXVIDEOINFOHOSTEVENTS *pHostEvents = (VBOXVIDEOINFOHOSTEVENTS *)pu8;
2304
2305 pFBInfo->pHostEvents = pHostEvents;
2306
2307 LogFlow(("VBOX_VIDEO_INFO_TYPE_HOSTEVENTS: (%p)\n",
2308 pHostEvents));
2309 }
2310 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_LINK)
2311 {
2312 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOLINK))
2313 {
2314 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "LINK", pHdr->u16Length));
2315 break;
2316 }
2317
2318 VBOXVIDEOINFOLINK *pLink = (VBOXVIDEOINFOLINK *)pu8;
2319 pu8 += pLink->i32Offset;
2320 }
2321 else
2322 {
2323 LogRel(("Guest display information contains unsupported type %d\n", pHdr->u8Type));
2324 }
2325
2326 pu8 += pHdr->u16Length;
2327 }
2328}
2329
2330#ifdef VBOX_WITH_VIDEOHWACCEL
2331
2332void Display::handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
2333{
2334 unsigned id = (unsigned)pCommand->iDisplay;
2335 int rc = VINF_SUCCESS;
2336 if(id < mcMonitors)
2337 {
2338 IFramebuffer *pFramebuffer = maFramebuffers[id].pFramebuffer;
2339
2340 // if there is no framebuffer, this call is not interesting
2341 if (pFramebuffer == NULL)
2342 return;
2343
2344 pFramebuffer->Lock();
2345
2346 HRESULT hr = pFramebuffer->ProcessVHWACommand((BYTE*)pCommand);
2347 if(FAILED(hr))
2348 {
2349 rc = (hr == E_NOTIMPL) ? VERR_NOT_IMPLEMENTED : VERR_GENERAL_FAILURE;
2350 }
2351
2352 pFramebuffer->Unlock();
2353
2354 }
2355 else
2356 {
2357 rc = VERR_INVALID_PARAMETER;
2358 }
2359
2360 if(RT_FAILURE(rc))
2361 {
2362 /* tell the guest the command is complete */
2363 pCommand->Flags &= (~VBOXVHWACMD_FLAG_HG_ASYNCH);
2364 pCommand->rc = rc;
2365 }
2366}
2367
2368DECLCALLBACK(void) Display::displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
2369{
2370 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2371
2372 pDrv->pDisplay->handleVHWACommandProcess(pInterface, pCommand);
2373}
2374#endif
2375
2376#ifdef VBOX_WITH_HGSMI
2377DECLCALLBACK(int) Display::displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
2378{
2379 LogFlowFunc(("uScreenId %d\n", uScreenId));
2380
2381 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2382 Display *pThis = pDrv->pDisplay;
2383
2384 pThis->maFramebuffers[uScreenId].fVBVAEnabled = true;
2385
2386 return VINF_SUCCESS;
2387}
2388
2389DECLCALLBACK(void) Display::displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
2390{
2391 LogFlowFunc(("uScreenId %d\n", uScreenId));
2392
2393 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2394 Display *pThis = pDrv->pDisplay;
2395
2396 pThis->maFramebuffers[uScreenId].fVBVAEnabled = false;
2397}
2398
2399DECLCALLBACK(void) Display::displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
2400{
2401 LogFlowFunc(("uScreenId %d\n", uScreenId));
2402
2403 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2404 Display *pThis = pDrv->pDisplay;
2405
2406 NOREF(uScreenId);
2407}
2408
2409DECLCALLBACK(void) Display::displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd)
2410{
2411 LogFlowFunc(("uScreenId %d pCmd %p cbCmd %d\n", uScreenId, pCmd, cbCmd));
2412
2413 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2414 Display *pThis = pDrv->pDisplay;
2415
2416 pThis->mParent->consoleVRDPServer()->SendUpdate (uScreenId, pCmd, cbCmd);
2417}
2418
2419DECLCALLBACK(void) Display::displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
2420{
2421 LogFlowFunc(("uScreenId %d %d,%d %dx%d\n", uScreenId, x, y, cx, cy));
2422
2423 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2424 Display *pThis = pDrv->pDisplay;
2425
2426 /* @todo handleFramebufferUpdate (uScreenId,
2427 * x - pThis->maFramebuffers[uScreenId].xOrigin,
2428 * y - pThis->maFramebuffers[uScreenId].yOrigin,
2429 * cx, cy);
2430 */
2431 pThis->handleDisplayUpdate(x, y, cx, cy);
2432}
2433
2434DECLCALLBACK(int) Display::displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM)
2435{
2436 LogFlowFunc(("pScreen %p, pvVRAM %p\n", pScreen, pvVRAM));
2437
2438 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2439 Display *pThis = pDrv->pDisplay;
2440
2441 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[pScreen->u32ViewIndex];
2442
2443 pFBInfo->u32Offset = pView->u32ViewOffset; /* Not used in HGSMI. */
2444 pFBInfo->u32MaxFramebufferSize = pView->u32MaxScreenSize; /* Not used in HGSMI. */
2445 pFBInfo->u32InformationSize = 0; /* Not used in HGSMI. */
2446
2447 pFBInfo->xOrigin = pScreen->i32OriginX;
2448 pFBInfo->yOrigin = pScreen->i32OriginY;
2449
2450 pFBInfo->w = pScreen->u32Width;
2451 pFBInfo->h = pScreen->u32Height;
2452
2453 return pThis->handleDisplayResize(pScreen->u32ViewIndex, pScreen->u16BitsPerPixel,
2454 (uint8_t *)pvVRAM + pScreen->u32StartOffset,
2455 pScreen->u32LineSize, pScreen->u32Width, pScreen->u32Height);
2456}
2457
2458DECLCALLBACK(int) Display::displayVBVAMousePointerShape(PPDMIDISPLAYCONNECTOR pInterface, bool fVisible, bool fAlpha,
2459 uint32_t xHot, uint32_t yHot,
2460 uint32_t cx, uint32_t cy,
2461 const void *pvShape)
2462{
2463 LogFlowFunc(("\n"));
2464
2465 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2466 Display *pThis = pDrv->pDisplay;
2467
2468 /* Tell the console about it */
2469 pDrv->pDisplay->mParent->onMousePointerShapeChange(fVisible, fAlpha,
2470 xHot, yHot, cx, cy, (void *)pvShape);
2471
2472 return VINF_SUCCESS;
2473}
2474#endif /* VBOX_WITH_HGSMI */
2475
2476/**
2477 * Queries an interface to the driver.
2478 *
2479 * @returns Pointer to interface.
2480 * @returns NULL if the interface was not supported by the driver.
2481 * @param pInterface Pointer to this interface structure.
2482 * @param enmInterface The requested interface identification.
2483 */
2484DECLCALLBACK(void *) Display::drvQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
2485{
2486 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
2487 PDRVMAINDISPLAY pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
2488 switch (enmInterface)
2489 {
2490 case PDMINTERFACE_BASE:
2491 return &pDrvIns->IBase;
2492 case PDMINTERFACE_DISPLAY_CONNECTOR:
2493 return &pDrv->Connector;
2494 default:
2495 return NULL;
2496 }
2497}
2498
2499
2500/**
2501 * Destruct a display driver instance.
2502 *
2503 * @returns VBox status.
2504 * @param pDrvIns The driver instance data.
2505 */
2506DECLCALLBACK(void) Display::drvDestruct(PPDMDRVINS pDrvIns)
2507{
2508 PDRVMAINDISPLAY pData = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
2509 LogFlowFunc (("iInstance=%d\n", pDrvIns->iInstance));
2510 if (pData->pDisplay)
2511 {
2512 AutoWriteLock displayLock (pData->pDisplay);
2513 pData->pDisplay->mpDrv = NULL;
2514 pData->pDisplay->mpVMMDev = NULL;
2515 pData->pDisplay->mLastAddress = NULL;
2516 pData->pDisplay->mLastBytesPerLine = 0;
2517 pData->pDisplay->mLastBitsPerPixel = 0,
2518 pData->pDisplay->mLastWidth = 0;
2519 pData->pDisplay->mLastHeight = 0;
2520 }
2521}
2522
2523
2524/**
2525 * Construct a display driver instance.
2526 *
2527 * @copydoc FNPDMDRVCONSTRUCT
2528 */
2529DECLCALLBACK(int) Display::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
2530{
2531 PDRVMAINDISPLAY pData = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
2532 LogFlowFunc (("iInstance=%d\n", pDrvIns->iInstance));
2533
2534 /*
2535 * Validate configuration.
2536 */
2537 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
2538 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
2539 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
2540 ("Configuration error: Not possible to attach anything to this driver!\n"),
2541 VERR_PDM_DRVINS_NO_ATTACH);
2542
2543 /*
2544 * Init Interfaces.
2545 */
2546 pDrvIns->IBase.pfnQueryInterface = Display::drvQueryInterface;
2547
2548 pData->Connector.pfnResize = Display::displayResizeCallback;
2549 pData->Connector.pfnUpdateRect = Display::displayUpdateCallback;
2550 pData->Connector.pfnRefresh = Display::displayRefreshCallback;
2551 pData->Connector.pfnReset = Display::displayResetCallback;
2552 pData->Connector.pfnLFBModeChange = Display::displayLFBModeChangeCallback;
2553 pData->Connector.pfnProcessAdapterData = Display::displayProcessAdapterDataCallback;
2554 pData->Connector.pfnProcessDisplayData = Display::displayProcessDisplayDataCallback;
2555#ifdef VBOX_WITH_VIDEOHWACCEL
2556 pData->Connector.pfnVHWACommandProcess = Display::displayVHWACommandProcess;
2557#endif
2558#ifdef VBOX_WITH_HGSMI
2559 pData->Connector.pfnVBVAEnable = Display::displayVBVAEnable;
2560 pData->Connector.pfnVBVADisable = Display::displayVBVADisable;
2561 pData->Connector.pfnVBVAUpdateBegin = Display::displayVBVAUpdateBegin;
2562 pData->Connector.pfnVBVAUpdateProcess = Display::displayVBVAUpdateProcess;
2563 pData->Connector.pfnVBVAUpdateEnd = Display::displayVBVAUpdateEnd;
2564 pData->Connector.pfnVBVAResize = Display::displayVBVAResize;
2565 pData->Connector.pfnVBVAMousePointerShape = Display::displayVBVAMousePointerShape;
2566#endif
2567
2568
2569 /*
2570 * Get the IDisplayPort interface of the above driver/device.
2571 */
2572 pData->pUpPort = (PPDMIDISPLAYPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_DISPLAY_PORT);
2573 if (!pData->pUpPort)
2574 {
2575 AssertMsgFailed(("Configuration error: No display port interface above!\n"));
2576 return VERR_PDM_MISSING_INTERFACE_ABOVE;
2577 }
2578#if defined(VBOX_WITH_VIDEOHWACCEL)
2579 pData->pVBVACallbacks = (PPDMDDISPLAYVBVACALLBACKS)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_DISPLAY_VBVA_CALLBACKS);
2580 if (!pData->pVBVACallbacks)
2581 {
2582 AssertMsgFailed(("Configuration error: No VBVA callback interface above!\n"));
2583 return VERR_PDM_MISSING_INTERFACE_ABOVE;
2584 }
2585#endif
2586 /*
2587 * Get the Display object pointer and update the mpDrv member.
2588 */
2589 void *pv;
2590 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
2591 if (RT_FAILURE(rc))
2592 {
2593 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
2594 return rc;
2595 }
2596 pData->pDisplay = (Display *)pv; /** @todo Check this cast! */
2597 pData->pDisplay->mpDrv = pData;
2598
2599 /*
2600 * Update our display information according to the framebuffer
2601 */
2602 pData->pDisplay->updateDisplayData();
2603
2604 /*
2605 * Start periodic screen refreshes
2606 */
2607 pData->pUpPort->pfnSetRefreshRate(pData->pUpPort, 20);
2608
2609 return VINF_SUCCESS;
2610}
2611
2612
2613/**
2614 * Display driver registration record.
2615 */
2616const PDMDRVREG Display::DrvReg =
2617{
2618 /* u32Version */
2619 PDM_DRVREG_VERSION,
2620 /* szDriverName */
2621 "MainDisplay",
2622 /* pszDescription */
2623 "Main display driver (Main as in the API).",
2624 /* fFlags */
2625 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
2626 /* fClass. */
2627 PDM_DRVREG_CLASS_DISPLAY,
2628 /* cMaxInstances */
2629 ~0,
2630 /* cbInstance */
2631 sizeof(DRVMAINDISPLAY),
2632 /* pfnConstruct */
2633 Display::drvConstruct,
2634 /* pfnDestruct */
2635 Display::drvDestruct,
2636 /* pfnIOCtl */
2637 NULL,
2638 /* pfnPowerOn */
2639 NULL,
2640 /* pfnReset */
2641 NULL,
2642 /* pfnSuspend */
2643 NULL,
2644 /* pfnResume */
2645 NULL,
2646 /* pfnAttach */
2647 NULL,
2648 /* pfnDetach */
2649 NULL,
2650 /* pfnPowerOff */
2651 NULL,
2652 /* pfnSoftReset */
2653 NULL,
2654 /* u32EndVersion */
2655 PDM_DRVREG_VERSION
2656};
2657/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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