VirtualBox

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

Last change on this file since 23012 was 23012, checked in by vboxsync, 15 years ago

VMM,Devices,Main: VMR3ReqCall w/ RT_INDEFINITE_WAIT -> VMR3ReqCallWait.

  • 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 23012 2009-09-14 16:38:13Z 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 PVMREQ pReq;
1697 int rcVBox = VMR3ReqCallVoid(pVM, VMCPUID_ANY, &pReq, RT_INDEFINITE_WAIT,
1698 (PFNRT)mpDrv->pUpPort->pfnUpdateDisplayAll, 1, mpDrv->pUpPort);
1699 if (RT_SUCCESS(rcVBox))
1700 VMR3ReqFree(pReq);
1701
1702 alock.enter ();
1703
1704 if (RT_FAILURE(rcVBox))
1705 rc = setError (VBOX_E_IPRT_ERROR,
1706 tr ("Could not invalidate and update the screen (%Rrc)"), rcVBox);
1707
1708 LogFlowFunc (("rc=%08X\n", rc));
1709 LogFlowFuncLeave();
1710 return rc;
1711}
1712
1713/**
1714 * Notification that the framebuffer has completed the
1715 * asynchronous resize processing
1716 *
1717 * @returns COM status code
1718 */
1719STDMETHODIMP Display::ResizeCompleted(ULONG aScreenId)
1720{
1721 LogFlowFunc (("\n"));
1722
1723 /// @todo (dmik) can we AutoWriteLock alock(this); here?
1724 // do it when we switch this class to VirtualBoxBase_NEXT.
1725 // This will require general code review and may add some details.
1726 // In particular, we may want to check whether EMT is really waiting for
1727 // this notification, etc. It might be also good to obey the caller to make
1728 // sure this method is not called from more than one thread at a time
1729 // (and therefore don't use Display lock at all here to save some
1730 // milliseconds).
1731 AutoCaller autoCaller(this);
1732 CheckComRCReturnRC(autoCaller.rc());
1733
1734 /* this is only valid for external framebuffers */
1735 if (maFramebuffers[aScreenId].pFramebuffer == NULL)
1736 return setError (VBOX_E_NOT_SUPPORTED,
1737 tr ("Resize completed notification is valid only "
1738 "for external framebuffers"));
1739
1740 /* Set the flag indicating that the resize has completed and display
1741 * data need to be updated. */
1742 bool f = ASMAtomicCmpXchgU32 (&maFramebuffers[aScreenId].u32ResizeStatus,
1743 ResizeStatus_UpdateDisplayData, ResizeStatus_InProgress);
1744 AssertRelease(f);NOREF(f);
1745
1746 return S_OK;
1747}
1748
1749/**
1750 * Notification that the framebuffer has completed the
1751 * asynchronous update processing
1752 *
1753 * @returns COM status code
1754 */
1755STDMETHODIMP Display::UpdateCompleted()
1756{
1757 LogFlowFunc (("\n"));
1758
1759 /// @todo (dmik) can we AutoWriteLock alock(this); here?
1760 // do it when we switch this class to VirtualBoxBase_NEXT.
1761 // Tthis will require general code review and may add some details.
1762 // In particular, we may want to check whether EMT is really waiting for
1763 // this notification, etc. It might be also good to obey the caller to make
1764 // sure this method is not called from more than one thread at a time
1765 // (and therefore don't use Display lock at all here to save some
1766 // milliseconds).
1767 AutoCaller autoCaller(this);
1768 CheckComRCReturnRC(autoCaller.rc());
1769
1770 /* this is only valid for external framebuffers */
1771 if (maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer == NULL)
1772 return setError (VBOX_E_NOT_SUPPORTED,
1773 tr ("Resize completed notification is valid only "
1774 "for external framebuffers"));
1775
1776 return S_OK;
1777}
1778
1779STDMETHODIMP Display::CompleteVHWACommand(BYTE *pCommand)
1780{
1781#ifdef VBOX_WITH_VIDEOHWACCEL
1782 mpDrv->pVBVACallbacks->pfnVHWACommandCompleteAsynch(mpDrv->pVBVACallbacks, (PVBOXVHWACMD)pCommand);
1783 return S_OK;
1784#else
1785 return E_NOTIMPL;
1786#endif
1787}
1788
1789// private methods
1790/////////////////////////////////////////////////////////////////////////////
1791
1792/**
1793 * Helper to update the display information from the framebuffer.
1794 *
1795 * @param aCheckParams true to compare the parameters of the current framebuffer
1796 * and the new one and issue handleDisplayResize()
1797 * if they differ.
1798 * @thread EMT
1799 */
1800void Display::updateDisplayData (bool aCheckParams /* = false */)
1801{
1802 /* the driver might not have been constructed yet */
1803 if (!mpDrv)
1804 return;
1805
1806#if DEBUG
1807 /*
1808 * Sanity check. Note that this method may be called on EMT after Console
1809 * has started the power down procedure (but before our #drvDestruct() is
1810 * called, in which case pVM will aleady be NULL but mpDrv will not). Since
1811 * we don't really need pVM to proceed, we avoid this check in the release
1812 * build to save some ms (necessary to construct SafeVMPtrQuiet) in this
1813 * time-critical method.
1814 */
1815 Console::SafeVMPtrQuiet pVM (mParent);
1816 if (pVM.isOk())
1817 VM_ASSERT_EMT (pVM.raw());
1818#endif
1819
1820 /* The method is only relevant to the primary framebuffer. */
1821 IFramebuffer *pFramebuffer = maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer;
1822
1823 if (pFramebuffer)
1824 {
1825 HRESULT rc;
1826 BYTE *address = 0;
1827 rc = pFramebuffer->COMGETTER(Address) (&address);
1828 AssertComRC (rc);
1829 ULONG bytesPerLine = 0;
1830 rc = pFramebuffer->COMGETTER(BytesPerLine) (&bytesPerLine);
1831 AssertComRC (rc);
1832 ULONG bitsPerPixel = 0;
1833 rc = pFramebuffer->COMGETTER(BitsPerPixel) (&bitsPerPixel);
1834 AssertComRC (rc);
1835 ULONG width = 0;
1836 rc = pFramebuffer->COMGETTER(Width) (&width);
1837 AssertComRC (rc);
1838 ULONG height = 0;
1839 rc = pFramebuffer->COMGETTER(Height) (&height);
1840 AssertComRC (rc);
1841
1842 /*
1843 * Check current parameters with new ones and issue handleDisplayResize()
1844 * to let the new frame buffer adjust itself properly. Note that it will
1845 * result into a recursive updateDisplayData() call but with
1846 * aCheckOld = false.
1847 */
1848 if (aCheckParams &&
1849 (mLastAddress != address ||
1850 mLastBytesPerLine != bytesPerLine ||
1851 mLastBitsPerPixel != bitsPerPixel ||
1852 mLastWidth != (int) width ||
1853 mLastHeight != (int) height))
1854 {
1855 handleDisplayResize (VBOX_VIDEO_PRIMARY_SCREEN, mLastBitsPerPixel,
1856 mLastAddress,
1857 mLastBytesPerLine,
1858 mLastWidth,
1859 mLastHeight);
1860 return;
1861 }
1862
1863 mpDrv->Connector.pu8Data = (uint8_t *) address;
1864 mpDrv->Connector.cbScanline = bytesPerLine;
1865 mpDrv->Connector.cBits = bitsPerPixel;
1866 mpDrv->Connector.cx = width;
1867 mpDrv->Connector.cy = height;
1868 }
1869 else
1870 {
1871 /* black hole */
1872 mpDrv->Connector.pu8Data = NULL;
1873 mpDrv->Connector.cbScanline = 0;
1874 mpDrv->Connector.cBits = 0;
1875 mpDrv->Connector.cx = 0;
1876 mpDrv->Connector.cy = 0;
1877 }
1878}
1879
1880/**
1881 * Changes the current frame buffer. Called on EMT to avoid both
1882 * race conditions and excessive locking.
1883 *
1884 * @note locks this object for writing
1885 * @thread EMT
1886 */
1887/* static */
1888DECLCALLBACK(int) Display::changeFramebuffer (Display *that, IFramebuffer *aFB,
1889 unsigned uScreenId)
1890{
1891 LogFlowFunc (("uScreenId = %d\n", uScreenId));
1892
1893 AssertReturn(that, VERR_INVALID_PARAMETER);
1894 AssertReturn(uScreenId < that->mcMonitors, VERR_INVALID_PARAMETER);
1895
1896 AutoCaller autoCaller(that);
1897 CheckComRCReturnRC(autoCaller.rc());
1898
1899 AutoWriteLock alock(that);
1900
1901 DISPLAYFBINFO *pDisplayFBInfo = &that->maFramebuffers[uScreenId];
1902 pDisplayFBInfo->pFramebuffer = aFB;
1903
1904 that->mParent->consoleVRDPServer()->SendResize ();
1905
1906 that->updateDisplayData (true /* aCheckParams */);
1907
1908 return VINF_SUCCESS;
1909}
1910
1911/**
1912 * Handle display resize event issued by the VGA device for the primary screen.
1913 *
1914 * @see PDMIDISPLAYCONNECTOR::pfnResize
1915 */
1916DECLCALLBACK(int) Display::displayResizeCallback(PPDMIDISPLAYCONNECTOR pInterface,
1917 uint32_t bpp, void *pvVRAM, uint32_t cbLine, uint32_t cx, uint32_t cy)
1918{
1919 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
1920
1921 LogFlowFunc (("bpp %d, pvVRAM %p, cbLine %d, cx %d, cy %d\n",
1922 bpp, pvVRAM, cbLine, cx, cy));
1923
1924 return pDrv->pDisplay->handleDisplayResize(VBOX_VIDEO_PRIMARY_SCREEN, bpp, pvVRAM, cbLine, cx, cy);
1925}
1926
1927/**
1928 * Handle display update.
1929 *
1930 * @see PDMIDISPLAYCONNECTOR::pfnUpdateRect
1931 */
1932DECLCALLBACK(void) Display::displayUpdateCallback(PPDMIDISPLAYCONNECTOR pInterface,
1933 uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
1934{
1935 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
1936
1937#ifdef DEBUG_sunlover
1938 LogFlowFunc (("mfVideoAccelEnabled = %d, %d,%d %dx%d\n",
1939 pDrv->pDisplay->mfVideoAccelEnabled, x, y, cx, cy));
1940#endif /* DEBUG_sunlover */
1941
1942 /* This call does update regardless of VBVA status.
1943 * But in VBVA mode this is called only as result of
1944 * pfnUpdateDisplayAll in the VGA device.
1945 */
1946
1947 pDrv->pDisplay->handleDisplayUpdate(x, y, cx, cy);
1948}
1949
1950/**
1951 * Periodic display refresh callback.
1952 *
1953 * @see PDMIDISPLAYCONNECTOR::pfnRefresh
1954 */
1955DECLCALLBACK(void) Display::displayRefreshCallback(PPDMIDISPLAYCONNECTOR pInterface)
1956{
1957 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
1958
1959#ifdef DEBUG_sunlover
1960 STAM_PROFILE_START(&StatDisplayRefresh, a);
1961#endif /* DEBUG_sunlover */
1962
1963#ifdef DEBUG_sunlover_2
1964 LogFlowFunc (("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
1965 pDrv->pDisplay->mfVideoAccelEnabled));
1966#endif /* DEBUG_sunlover_2 */
1967
1968 Display *pDisplay = pDrv->pDisplay;
1969 bool fNoUpdate = false; /* Do not update the display if any of the framebuffers is being resized. */
1970 unsigned uScreenId;
1971
1972 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
1973 {
1974 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
1975
1976 /* Check the resize status. The status can be checked normally because
1977 * the status affects only the EMT.
1978 */
1979 uint32_t u32ResizeStatus = pFBInfo->u32ResizeStatus;
1980
1981 if (u32ResizeStatus == ResizeStatus_UpdateDisplayData)
1982 {
1983 LogFlowFunc (("ResizeStatus_UpdateDisplayData %d\n", uScreenId));
1984 fNoUpdate = true; /* Always set it here, because pfnUpdateDisplayAll can cause a new resize. */
1985 /* The framebuffer was resized and display data need to be updated. */
1986 pDisplay->handleResizeCompletedEMT ();
1987 if (pFBInfo->u32ResizeStatus != ResizeStatus_Void)
1988 {
1989 /* The resize status could be not Void here because a pending resize is issued. */
1990 continue;
1991 }
1992 /* Continue with normal processing because the status here is ResizeStatus_Void. */
1993 if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
1994 {
1995 /* Repaint the display because VM continued to run during the framebuffer resize. */
1996 if (!pFBInfo->pFramebuffer.isNull())
1997 pDrv->pUpPort->pfnUpdateDisplayAll(pDrv->pUpPort);
1998 }
1999 }
2000 else if (u32ResizeStatus == ResizeStatus_InProgress)
2001 {
2002 /* The framebuffer is being resized. Do not call the VGA device back. Immediately return. */
2003 LogFlowFunc (("ResizeStatus_InProcess\n"));
2004 fNoUpdate = true;
2005 continue;
2006 }
2007 }
2008
2009 if (!fNoUpdate)
2010 {
2011 if (pDisplay->mfPendingVideoAccelEnable)
2012 {
2013 /* Acceleration was enabled while machine was not yet running
2014 * due to restoring from saved state. Update entire display and
2015 * actually enable acceleration.
2016 */
2017 Assert(pDisplay->mpPendingVbvaMemory);
2018
2019 /* Acceleration can not be yet enabled.*/
2020 Assert(pDisplay->mpVbvaMemory == NULL);
2021 Assert(!pDisplay->mfVideoAccelEnabled);
2022
2023 if (pDisplay->mfMachineRunning)
2024 {
2025 pDisplay->VideoAccelEnable (pDisplay->mfPendingVideoAccelEnable,
2026 pDisplay->mpPendingVbvaMemory);
2027
2028 /* Reset the pending state. */
2029 pDisplay->mfPendingVideoAccelEnable = false;
2030 pDisplay->mpPendingVbvaMemory = NULL;
2031 }
2032 }
2033 else
2034 {
2035 Assert(pDisplay->mpPendingVbvaMemory == NULL);
2036
2037 if (pDisplay->mfVideoAccelEnabled)
2038 {
2039 Assert(pDisplay->mpVbvaMemory);
2040 pDisplay->VideoAccelFlush ();
2041 }
2042 else
2043 {
2044 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN];
2045 if (!pFBInfo->pFramebuffer.isNull())
2046 {
2047 Assert(pDrv->Connector.pu8Data);
2048 Assert(pFBInfo->u32ResizeStatus == ResizeStatus_Void);
2049 pDrv->pUpPort->pfnUpdateDisplay(pDrv->pUpPort);
2050 }
2051 }
2052
2053 /* Inform the VRDP server that the current display update sequence is
2054 * completed. At this moment the framebuffer memory contains a definite
2055 * image, that is synchronized with the orders already sent to VRDP client.
2056 * The server can now process redraw requests from clients or initial
2057 * fullscreen updates for new clients.
2058 */
2059 for (uScreenId = 0; uScreenId < pDisplay->mcMonitors; uScreenId++)
2060 {
2061 DISPLAYFBINFO *pFBInfo = &pDisplay->maFramebuffers[uScreenId];
2062
2063 if (!pFBInfo->pFramebuffer.isNull() && pFBInfo->u32ResizeStatus == ResizeStatus_Void)
2064 {
2065 Assert (pDisplay->mParent && pDisplay->mParent->consoleVRDPServer());
2066 pDisplay->mParent->consoleVRDPServer()->SendUpdate (uScreenId, NULL, 0);
2067 }
2068 }
2069 }
2070 }
2071
2072#ifdef DEBUG_sunlover
2073 STAM_PROFILE_STOP(&StatDisplayRefresh, a);
2074#endif /* DEBUG_sunlover */
2075#ifdef DEBUG_sunlover_2
2076 LogFlowFunc (("leave\n"));
2077#endif /* DEBUG_sunlover_2 */
2078}
2079
2080/**
2081 * Reset notification
2082 *
2083 * @see PDMIDISPLAYCONNECTOR::pfnReset
2084 */
2085DECLCALLBACK(void) Display::displayResetCallback(PPDMIDISPLAYCONNECTOR pInterface)
2086{
2087 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2088
2089 LogFlowFunc (("\n"));
2090
2091 /* Disable VBVA mode. */
2092 pDrv->pDisplay->VideoAccelEnable (false, NULL);
2093}
2094
2095/**
2096 * LFBModeChange notification
2097 *
2098 * @see PDMIDISPLAYCONNECTOR::pfnLFBModeChange
2099 */
2100DECLCALLBACK(void) Display::displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled)
2101{
2102 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2103
2104 LogFlowFunc (("fEnabled=%d\n", fEnabled));
2105
2106 NOREF(fEnabled);
2107
2108 /* Disable VBVA mode in any case. The guest driver reenables VBVA mode if necessary. */
2109 pDrv->pDisplay->VideoAccelEnable (false, NULL);
2110}
2111
2112/**
2113 * Adapter information change notification.
2114 *
2115 * @see PDMIDISPLAYCONNECTOR::pfnProcessAdapterData
2116 */
2117DECLCALLBACK(void) Display::displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize)
2118{
2119 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2120
2121 if (pvVRAM == NULL)
2122 {
2123 unsigned i;
2124 for (i = 0; i < pDrv->pDisplay->mcMonitors; i++)
2125 {
2126 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[i];
2127
2128 pFBInfo->u32Offset = 0;
2129 pFBInfo->u32MaxFramebufferSize = 0;
2130 pFBInfo->u32InformationSize = 0;
2131 }
2132 }
2133#ifndef VBOX_WITH_HGSMI
2134 else
2135 {
2136 uint8_t *pu8 = (uint8_t *)pvVRAM;
2137 pu8 += u32VRAMSize - VBOX_VIDEO_ADAPTER_INFORMATION_SIZE;
2138
2139 // @todo
2140 uint8_t *pu8End = pu8 + VBOX_VIDEO_ADAPTER_INFORMATION_SIZE;
2141
2142 VBOXVIDEOINFOHDR *pHdr;
2143
2144 for (;;)
2145 {
2146 pHdr = (VBOXVIDEOINFOHDR *)pu8;
2147 pu8 += sizeof (VBOXVIDEOINFOHDR);
2148
2149 if (pu8 >= pu8End)
2150 {
2151 LogRel(("VBoxVideo: Guest adapter information overflow!!!\n"));
2152 break;
2153 }
2154
2155 if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_DISPLAY)
2156 {
2157 if (pHdr->u16Length != sizeof (VBOXVIDEOINFODISPLAY))
2158 {
2159 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "DISPLAY", pHdr->u16Length));
2160 break;
2161 }
2162
2163 VBOXVIDEOINFODISPLAY *pDisplay = (VBOXVIDEOINFODISPLAY *)pu8;
2164
2165 if (pDisplay->u32Index >= pDrv->pDisplay->mcMonitors)
2166 {
2167 LogRel(("VBoxVideo: Guest adapter information invalid display index %d!!!\n", pDisplay->u32Index));
2168 break;
2169 }
2170
2171 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[pDisplay->u32Index];
2172
2173 pFBInfo->u32Offset = pDisplay->u32Offset;
2174 pFBInfo->u32MaxFramebufferSize = pDisplay->u32FramebufferSize;
2175 pFBInfo->u32InformationSize = pDisplay->u32InformationSize;
2176
2177 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));
2178 }
2179 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_QUERY_CONF32)
2180 {
2181 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOQUERYCONF32))
2182 {
2183 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "CONF32", pHdr->u16Length));
2184 break;
2185 }
2186
2187 VBOXVIDEOINFOQUERYCONF32 *pConf32 = (VBOXVIDEOINFOQUERYCONF32 *)pu8;
2188
2189 switch (pConf32->u32Index)
2190 {
2191 case VBOX_VIDEO_QCI32_MONITOR_COUNT:
2192 {
2193 pConf32->u32Value = pDrv->pDisplay->mcMonitors;
2194 } break;
2195
2196 case VBOX_VIDEO_QCI32_OFFSCREEN_HEAP_SIZE:
2197 {
2198 /* @todo make configurable. */
2199 pConf32->u32Value = _1M;
2200 } break;
2201
2202 default:
2203 LogRel(("VBoxVideo: CONF32 %d not supported!!! Skipping.\n", pConf32->u32Index));
2204 }
2205 }
2206 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_END)
2207 {
2208 if (pHdr->u16Length != 0)
2209 {
2210 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "END", pHdr->u16Length));
2211 break;
2212 }
2213
2214 break;
2215 }
2216 else if (pHdr->u8Type != VBOX_VIDEO_INFO_TYPE_NV_HEAP) /** @todo why is Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp pushing this to us? */
2217 {
2218 LogRel(("Guest adapter information contains unsupported type %d. The block has been skipped.\n", pHdr->u8Type));
2219 }
2220
2221 pu8 += pHdr->u16Length;
2222 }
2223 }
2224#endif /* !VBOX_WITH_HGSMI */
2225}
2226
2227/**
2228 * Display information change notification.
2229 *
2230 * @see PDMIDISPLAYCONNECTOR::pfnProcessDisplayData
2231 */
2232DECLCALLBACK(void) Display::displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId)
2233{
2234 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2235
2236 if (uScreenId >= pDrv->pDisplay->mcMonitors)
2237 {
2238 LogRel(("VBoxVideo: Guest display information invalid display index %d!!!\n", uScreenId));
2239 return;
2240 }
2241
2242 /* Get the display information structure. */
2243 DISPLAYFBINFO *pFBInfo = &pDrv->pDisplay->maFramebuffers[uScreenId];
2244
2245 uint8_t *pu8 = (uint8_t *)pvVRAM;
2246 pu8 += pFBInfo->u32Offset + pFBInfo->u32MaxFramebufferSize;
2247
2248 // @todo
2249 uint8_t *pu8End = pu8 + pFBInfo->u32InformationSize;
2250
2251 VBOXVIDEOINFOHDR *pHdr;
2252
2253 for (;;)
2254 {
2255 pHdr = (VBOXVIDEOINFOHDR *)pu8;
2256 pu8 += sizeof (VBOXVIDEOINFOHDR);
2257
2258 if (pu8 >= pu8End)
2259 {
2260 LogRel(("VBoxVideo: Guest display information overflow!!!\n"));
2261 break;
2262 }
2263
2264 if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_SCREEN)
2265 {
2266 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOSCREEN))
2267 {
2268 LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "SCREEN", pHdr->u16Length));
2269 break;
2270 }
2271
2272 VBOXVIDEOINFOSCREEN *pScreen = (VBOXVIDEOINFOSCREEN *)pu8;
2273
2274 pFBInfo->xOrigin = pScreen->xOrigin;
2275 pFBInfo->yOrigin = pScreen->yOrigin;
2276
2277 pFBInfo->w = pScreen->u16Width;
2278 pFBInfo->h = pScreen->u16Height;
2279
2280 LogFlow(("VBOX_VIDEO_INFO_TYPE_SCREEN: (%p) %d: at %d,%d, linesize 0x%X, size %dx%d, bpp %d, flags 0x%02X\n",
2281 pHdr, uScreenId, pScreen->xOrigin, pScreen->yOrigin, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height, pScreen->bitsPerPixel, pScreen->u8Flags));
2282
2283 if (uScreenId != VBOX_VIDEO_PRIMARY_SCREEN)
2284 {
2285 /* Primary screen resize is initiated by the VGA device. */
2286 pDrv->pDisplay->handleDisplayResize(uScreenId, pScreen->bitsPerPixel, (uint8_t *)pvVRAM + pFBInfo->u32Offset, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height);
2287 }
2288 }
2289 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_END)
2290 {
2291 if (pHdr->u16Length != 0)
2292 {
2293 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "END", pHdr->u16Length));
2294 break;
2295 }
2296
2297 break;
2298 }
2299 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_HOST_EVENTS)
2300 {
2301 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOHOSTEVENTS))
2302 {
2303 LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "HOST_EVENTS", pHdr->u16Length));
2304 break;
2305 }
2306
2307 VBOXVIDEOINFOHOSTEVENTS *pHostEvents = (VBOXVIDEOINFOHOSTEVENTS *)pu8;
2308
2309 pFBInfo->pHostEvents = pHostEvents;
2310
2311 LogFlow(("VBOX_VIDEO_INFO_TYPE_HOSTEVENTS: (%p)\n",
2312 pHostEvents));
2313 }
2314 else if (pHdr->u8Type == VBOX_VIDEO_INFO_TYPE_LINK)
2315 {
2316 if (pHdr->u16Length != sizeof (VBOXVIDEOINFOLINK))
2317 {
2318 LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "LINK", pHdr->u16Length));
2319 break;
2320 }
2321
2322 VBOXVIDEOINFOLINK *pLink = (VBOXVIDEOINFOLINK *)pu8;
2323 pu8 += pLink->i32Offset;
2324 }
2325 else
2326 {
2327 LogRel(("Guest display information contains unsupported type %d\n", pHdr->u8Type));
2328 }
2329
2330 pu8 += pHdr->u16Length;
2331 }
2332}
2333
2334#ifdef VBOX_WITH_VIDEOHWACCEL
2335
2336void Display::handleVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
2337{
2338 unsigned id = (unsigned)pCommand->iDisplay;
2339 int rc = VINF_SUCCESS;
2340 if(id < mcMonitors)
2341 {
2342 IFramebuffer *pFramebuffer = maFramebuffers[id].pFramebuffer;
2343
2344 // if there is no framebuffer, this call is not interesting
2345 if (pFramebuffer == NULL)
2346 return;
2347
2348 pFramebuffer->Lock();
2349
2350 HRESULT hr = pFramebuffer->ProcessVHWACommand((BYTE*)pCommand);
2351 if(FAILED(hr))
2352 {
2353 rc = (hr == E_NOTIMPL) ? VERR_NOT_IMPLEMENTED : VERR_GENERAL_FAILURE;
2354 }
2355
2356 pFramebuffer->Unlock();
2357
2358 }
2359 else
2360 {
2361 rc = VERR_INVALID_PARAMETER;
2362 }
2363
2364 if(RT_FAILURE(rc))
2365 {
2366 /* tell the guest the command is complete */
2367 pCommand->Flags &= (~VBOXVHWACMD_FLAG_HG_ASYNCH);
2368 pCommand->rc = rc;
2369 }
2370}
2371
2372DECLCALLBACK(void) Display::displayVHWACommandProcess(PPDMIDISPLAYCONNECTOR pInterface, PVBOXVHWACMD pCommand)
2373{
2374 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2375
2376 pDrv->pDisplay->handleVHWACommandProcess(pInterface, pCommand);
2377}
2378#endif
2379
2380#ifdef VBOX_WITH_HGSMI
2381DECLCALLBACK(int) Display::displayVBVAEnable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
2382{
2383 LogFlowFunc(("uScreenId %d\n", uScreenId));
2384
2385 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2386 Display *pThis = pDrv->pDisplay;
2387
2388 pThis->maFramebuffers[uScreenId].fVBVAEnabled = true;
2389
2390 return VINF_SUCCESS;
2391}
2392
2393DECLCALLBACK(void) Display::displayVBVADisable(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
2394{
2395 LogFlowFunc(("uScreenId %d\n", uScreenId));
2396
2397 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2398 Display *pThis = pDrv->pDisplay;
2399
2400 pThis->maFramebuffers[uScreenId].fVBVAEnabled = false;
2401}
2402
2403DECLCALLBACK(void) Display::displayVBVAUpdateBegin(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId)
2404{
2405 LogFlowFunc(("uScreenId %d\n", uScreenId));
2406
2407 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2408 Display *pThis = pDrv->pDisplay;
2409
2410 NOREF(uScreenId);
2411}
2412
2413DECLCALLBACK(void) Display::displayVBVAUpdateProcess(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, const PVBVACMDHDR pCmd, size_t cbCmd)
2414{
2415 LogFlowFunc(("uScreenId %d pCmd %p cbCmd %d\n", uScreenId, pCmd, cbCmd));
2416
2417 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2418 Display *pThis = pDrv->pDisplay;
2419
2420 pThis->mParent->consoleVRDPServer()->SendUpdate (uScreenId, pCmd, cbCmd);
2421}
2422
2423DECLCALLBACK(void) Display::displayVBVAUpdateEnd(PPDMIDISPLAYCONNECTOR pInterface, unsigned uScreenId, uint32_t x, uint32_t y, uint32_t cx, uint32_t cy)
2424{
2425 LogFlowFunc(("uScreenId %d %d,%d %dx%d\n", uScreenId, x, y, cx, cy));
2426
2427 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2428 Display *pThis = pDrv->pDisplay;
2429
2430 /* @todo handleFramebufferUpdate (uScreenId,
2431 * x - pThis->maFramebuffers[uScreenId].xOrigin,
2432 * y - pThis->maFramebuffers[uScreenId].yOrigin,
2433 * cx, cy);
2434 */
2435 pThis->handleDisplayUpdate(x, y, cx, cy);
2436}
2437
2438DECLCALLBACK(int) Display::displayVBVAResize(PPDMIDISPLAYCONNECTOR pInterface, const PVBVAINFOVIEW pView, const PVBVAINFOSCREEN pScreen, void *pvVRAM)
2439{
2440 LogFlowFunc(("pScreen %p, pvVRAM %p\n", pScreen, pvVRAM));
2441
2442 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2443 Display *pThis = pDrv->pDisplay;
2444
2445 DISPLAYFBINFO *pFBInfo = &pThis->maFramebuffers[pScreen->u32ViewIndex];
2446
2447 pFBInfo->u32Offset = pView->u32ViewOffset; /* Not used in HGSMI. */
2448 pFBInfo->u32MaxFramebufferSize = pView->u32MaxScreenSize; /* Not used in HGSMI. */
2449 pFBInfo->u32InformationSize = 0; /* Not used in HGSMI. */
2450
2451 pFBInfo->xOrigin = pScreen->i32OriginX;
2452 pFBInfo->yOrigin = pScreen->i32OriginY;
2453
2454 pFBInfo->w = pScreen->u32Width;
2455 pFBInfo->h = pScreen->u32Height;
2456
2457 return pThis->handleDisplayResize(pScreen->u32ViewIndex, pScreen->u16BitsPerPixel,
2458 (uint8_t *)pvVRAM + pScreen->u32StartOffset,
2459 pScreen->u32LineSize, pScreen->u32Width, pScreen->u32Height);
2460}
2461
2462DECLCALLBACK(int) Display::displayVBVAMousePointerShape(PPDMIDISPLAYCONNECTOR pInterface, bool fVisible, bool fAlpha,
2463 uint32_t xHot, uint32_t yHot,
2464 uint32_t cx, uint32_t cy,
2465 const void *pvShape)
2466{
2467 LogFlowFunc(("\n"));
2468
2469 PDRVMAINDISPLAY pDrv = PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface);
2470 Display *pThis = pDrv->pDisplay;
2471
2472 /* Tell the console about it */
2473 pDrv->pDisplay->mParent->onMousePointerShapeChange(fVisible, fAlpha,
2474 xHot, yHot, cx, cy, (void *)pvShape);
2475
2476 return VINF_SUCCESS;
2477}
2478#endif /* VBOX_WITH_HGSMI */
2479
2480/**
2481 * Queries an interface to the driver.
2482 *
2483 * @returns Pointer to interface.
2484 * @returns NULL if the interface was not supported by the driver.
2485 * @param pInterface Pointer to this interface structure.
2486 * @param enmInterface The requested interface identification.
2487 */
2488DECLCALLBACK(void *) Display::drvQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
2489{
2490 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
2491 PDRVMAINDISPLAY pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
2492 switch (enmInterface)
2493 {
2494 case PDMINTERFACE_BASE:
2495 return &pDrvIns->IBase;
2496 case PDMINTERFACE_DISPLAY_CONNECTOR:
2497 return &pDrv->Connector;
2498 default:
2499 return NULL;
2500 }
2501}
2502
2503
2504/**
2505 * Destruct a display driver instance.
2506 *
2507 * @returns VBox status.
2508 * @param pDrvIns The driver instance data.
2509 */
2510DECLCALLBACK(void) Display::drvDestruct(PPDMDRVINS pDrvIns)
2511{
2512 PDRVMAINDISPLAY pData = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
2513 LogFlowFunc (("iInstance=%d\n", pDrvIns->iInstance));
2514 if (pData->pDisplay)
2515 {
2516 AutoWriteLock displayLock (pData->pDisplay);
2517 pData->pDisplay->mpDrv = NULL;
2518 pData->pDisplay->mpVMMDev = NULL;
2519 pData->pDisplay->mLastAddress = NULL;
2520 pData->pDisplay->mLastBytesPerLine = 0;
2521 pData->pDisplay->mLastBitsPerPixel = 0,
2522 pData->pDisplay->mLastWidth = 0;
2523 pData->pDisplay->mLastHeight = 0;
2524 }
2525}
2526
2527
2528/**
2529 * Construct a display driver instance.
2530 *
2531 * @copydoc FNPDMDRVCONSTRUCT
2532 */
2533DECLCALLBACK(int) Display::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
2534{
2535 PDRVMAINDISPLAY pData = PDMINS_2_DATA(pDrvIns, PDRVMAINDISPLAY);
2536 LogFlowFunc (("iInstance=%d\n", pDrvIns->iInstance));
2537
2538 /*
2539 * Validate configuration.
2540 */
2541 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
2542 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
2543 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
2544 ("Configuration error: Not possible to attach anything to this driver!\n"),
2545 VERR_PDM_DRVINS_NO_ATTACH);
2546
2547 /*
2548 * Init Interfaces.
2549 */
2550 pDrvIns->IBase.pfnQueryInterface = Display::drvQueryInterface;
2551
2552 pData->Connector.pfnResize = Display::displayResizeCallback;
2553 pData->Connector.pfnUpdateRect = Display::displayUpdateCallback;
2554 pData->Connector.pfnRefresh = Display::displayRefreshCallback;
2555 pData->Connector.pfnReset = Display::displayResetCallback;
2556 pData->Connector.pfnLFBModeChange = Display::displayLFBModeChangeCallback;
2557 pData->Connector.pfnProcessAdapterData = Display::displayProcessAdapterDataCallback;
2558 pData->Connector.pfnProcessDisplayData = Display::displayProcessDisplayDataCallback;
2559#ifdef VBOX_WITH_VIDEOHWACCEL
2560 pData->Connector.pfnVHWACommandProcess = Display::displayVHWACommandProcess;
2561#endif
2562#ifdef VBOX_WITH_HGSMI
2563 pData->Connector.pfnVBVAEnable = Display::displayVBVAEnable;
2564 pData->Connector.pfnVBVADisable = Display::displayVBVADisable;
2565 pData->Connector.pfnVBVAUpdateBegin = Display::displayVBVAUpdateBegin;
2566 pData->Connector.pfnVBVAUpdateProcess = Display::displayVBVAUpdateProcess;
2567 pData->Connector.pfnVBVAUpdateEnd = Display::displayVBVAUpdateEnd;
2568 pData->Connector.pfnVBVAResize = Display::displayVBVAResize;
2569 pData->Connector.pfnVBVAMousePointerShape = Display::displayVBVAMousePointerShape;
2570#endif
2571
2572
2573 /*
2574 * Get the IDisplayPort interface of the above driver/device.
2575 */
2576 pData->pUpPort = (PPDMIDISPLAYPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_DISPLAY_PORT);
2577 if (!pData->pUpPort)
2578 {
2579 AssertMsgFailed(("Configuration error: No display port interface above!\n"));
2580 return VERR_PDM_MISSING_INTERFACE_ABOVE;
2581 }
2582#if defined(VBOX_WITH_VIDEOHWACCEL)
2583 pData->pVBVACallbacks = (PPDMDDISPLAYVBVACALLBACKS)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_DISPLAY_VBVA_CALLBACKS);
2584 if (!pData->pVBVACallbacks)
2585 {
2586 AssertMsgFailed(("Configuration error: No VBVA callback interface above!\n"));
2587 return VERR_PDM_MISSING_INTERFACE_ABOVE;
2588 }
2589#endif
2590 /*
2591 * Get the Display object pointer and update the mpDrv member.
2592 */
2593 void *pv;
2594 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
2595 if (RT_FAILURE(rc))
2596 {
2597 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
2598 return rc;
2599 }
2600 pData->pDisplay = (Display *)pv; /** @todo Check this cast! */
2601 pData->pDisplay->mpDrv = pData;
2602
2603 /*
2604 * Update our display information according to the framebuffer
2605 */
2606 pData->pDisplay->updateDisplayData();
2607
2608 /*
2609 * Start periodic screen refreshes
2610 */
2611 pData->pUpPort->pfnSetRefreshRate(pData->pUpPort, 20);
2612
2613 return VINF_SUCCESS;
2614}
2615
2616
2617/**
2618 * Display driver registration record.
2619 */
2620const PDMDRVREG Display::DrvReg =
2621{
2622 /* u32Version */
2623 PDM_DRVREG_VERSION,
2624 /* szDriverName */
2625 "MainDisplay",
2626 /* pszDescription */
2627 "Main display driver (Main as in the API).",
2628 /* fFlags */
2629 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
2630 /* fClass. */
2631 PDM_DRVREG_CLASS_DISPLAY,
2632 /* cMaxInstances */
2633 ~0,
2634 /* cbInstance */
2635 sizeof(DRVMAINDISPLAY),
2636 /* pfnConstruct */
2637 Display::drvConstruct,
2638 /* pfnDestruct */
2639 Display::drvDestruct,
2640 /* pfnIOCtl */
2641 NULL,
2642 /* pfnPowerOn */
2643 NULL,
2644 /* pfnReset */
2645 NULL,
2646 /* pfnSuspend */
2647 NULL,
2648 /* pfnResume */
2649 NULL,
2650 /* pfnAttach */
2651 NULL,
2652 /* pfnDetach */
2653 NULL,
2654 /* pfnPowerOff */
2655 NULL,
2656 /* pfnSoftReset */
2657 NULL,
2658 /* u32EndVersion */
2659 PDM_DRVREG_VERSION
2660};
2661/* 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