VirtualBox

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

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

Main/Display: properly save/restore some important members, see xtracker 3927

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