DisplayImpl.cpp revision 26d2a42f095ded346df2e41cc4837cb426b4753a
/* $Id$ */
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2008 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "DisplayImpl.h"
#include "FramebufferImpl.h"
#include "ConsoleImpl.h"
#include "ConsoleVRDPServer.h"
#include "VMMDev.h"
#include "Logging.h"
#include <iprt/semaphore.h>
#ifdef DEBUG /* for VM_ASSERT_EMT(). */
#endif
/**
* Display driver instance data.
*/
typedef struct DRVMAINDISPLAY
{
/** Pointer to the display object. */
/** Pointer to the driver instance structure. */
/** Our display connector interface. */
/** Converts PDMIDISPLAYCONNECTOR pointer to a DRVMAINDISPLAY pointer. */
#define PDMIDISPLAYCONNECTOR_2_MAINDISPLAY(pInterface) ( (PDRVMAINDISPLAY) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINDISPLAY, Connector)) )
#ifdef DEBUG_sunlover
static STAMPROFILE StatDisplayRefresh;
static int stam = 0;
#endif /* DEBUG_sunlover */
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
mpVbvaMemory = NULL;
mfVideoAccelEnabled = false;
mfVideoAccelVRDP = false;
mfu32SupportedOrders = 0;
mcVideoAccelVRDPRefs = 0;
mfPendingVideoAccelEnable = false;
mfMachineRunning = false;
mcbVbvaPartial = 0;
mfVMMDevInited = false;
mLastAddress = NULL;
mLastBytesPerLine = 0;
mLastBitsPerPixel = 0,
mLastWidth = 0;
mLastHeight = 0;
return S_OK;
}
void Display::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the display object.
*
* @returns COM result indicator
* @param parent handle of our parent object
* @param qemuConsoleData address of common console data structure
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan (this);
/* reset the event sems */
// by default, we have an internal framebuffer which is
// NULL, i.e. a black hole for no display output
mInternalFramebuffer = true;
mFramebufferOpened = false;
mSupportedAccelOps = 0;
mcMonitors = ul;
{
maFramebuffers[ul].w = 0;
maFramebuffers[ul].h = 0;
}
mParent->RegisterCallback (this);
/* Confirm a successful initialization */
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
{
LogFlowThisFunc (("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan (this);
if (autoUninitSpan.uninitDone())
return;
if (mParent)
mParent->UnregisterCallback (this);
if (mpDrv)
mfVMMDevInited = true;
}
// IConsoleCallback method
{
if (machineState == MachineState_Running)
{
LogFlowFunc (("Machine running\n"));
mfMachineRunning = true;
}
else
mfMachineRunning = false;
return S_OK;
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* @thread EMT
*/
int w, int h)
{
/* Call the framebuffer to try and set required pixelFormat. */
if (!finished)
{
LogFlowFunc (("External framebuffer wants us to wait!\n"));
return VINF_VGA_RESIZE_IN_PROGRESS;
}
return VINF_SUCCESS;
}
/**
* Handles display resize event.
* Disables access to VGA device;
* calls the framebuffer RequestResize method;
* if framebuffer resizes synchronously,
* updates the display connector data and enables access to the VGA device.
*
* @param w New display width
* @param h New display height
*
* @thread EMT
*/
{
LogRel (("Display::handleDisplayResize(): uScreenId = %d, pvVRAM=%p "
"w=%d h=%d bpp=%d cbLine=0x%X\n",
/* If there is no framebuffer, this call is not interesting. */
if ( uScreenId >= mcMonitors
{
return VINF_SUCCESS;
}
mLastWidth = w;
mLastHeight = h;
switch (bpp)
{
case 32:
case 24:
case 16:
break;
default:
break;
}
/* Atomically set the resize status before calling the framebuffer. The new InProgress status will
* disable access to the VGA device by the EMT thread.
*/
/* The framebuffer is locked in the state.
* The lock is kept, because the framebuffer is in undefined state.
*/
if (rc == VINF_VGA_RESIZE_IN_PROGRESS)
{
/* Immediately return to the caller. ResizeCompleted will be called back by the
* GUI thread. The ResizeCompleted callback will change the resize status from
* InProgress to UpdateDisplayData. The latter status will be checked by the
* display timer callback on EMT and all required adjustments will be done there.
*/
return rc;
}
/* Set the status so the 'handleResizeCompleted' would work. */
AssertRelease(f);NOREF(f);
/* The method also unlocks the framebuffer. */
return VINF_SUCCESS;
}
/**
* Framebuffer has been resized.
* Read the new display data and unlock the framebuffer.
*
* @thread EMT
*/
void Display::handleResizeCompletedEMT (void)
{
LogFlowFunc(("\n"));
unsigned uScreenId;
{
/* Try to into non resizing state. */
bool f = ASMAtomicCmpXchgU32 (&pFBInfo->u32ResizeStatus, ResizeStatus_Void, ResizeStatus_UpdateDisplayData);
if (f == false)
{
/* This is not the display that has completed resizing. */
continue;
}
{
/* Primary framebuffer has completed the resize. Update the connector data for VGA device. */
/* Check the framebuffer pixel format to setup the rendering in VGA device. */
}
#ifdef DEBUG_sunlover
if (!stam)
{
/* protect mpVM */
STAM_REG(pVM, &StatDisplayRefresh, STAMTYPE_PROFILE, "/PROF/Display/Refresh", STAMUNIT_TICKS_PER_CALL, "Time spent in EMT for display updates.");
stam = 1;
}
#endif /* DEBUG_sunlover */
/* Inform VRDP server about the change of display parameters. */
LogFlowFunc (("Calling VRDP\n"));
{
/* Unlock framebuffer after evrything is done. */
}
}
}
{
/* Correct negative x and y coordinates. */
if (*px < 0)
{
*px = 0;
}
if (*py < 0)
{
*py = 0;
}
/* Also check if coords are greater than the display resolution. */
{
}
{
}
}
unsigned mapCoordsToScreen(DISPLAYFBINFO *pInfos, unsigned cInfos, int *px, int *py, int *pw, int *ph)
{
unsigned uScreenId;
{
LogSunlover ((" [%d] %d,%d %dx%d\n", uScreenId, pInfo->xOrigin, pInfo->yOrigin, pInfo->w, pInfo->h));
{
/* The rectangle belongs to the screen. Correct coordinates. */
break;
}
}
{
/* Map to primary screen. */
uScreenId = 0;
}
return uScreenId;
}
/**
* Handles display update event.
*
* @param x Update area x coordinate
* @param y Update area y coordinate
* @param w Update area width
* @param h Update area height
*
* @thread EMT
*/
void Display::handleDisplayUpdate (int x, int y, int w, int h)
{
#ifdef DEBUG_sunlover
LogFlowFunc (("%d,%d %dx%d (%d,%d)\n",
#endif /* DEBUG_sunlover */
#ifdef DEBUG_sunlover
LogFlowFunc (("%d,%d %dx%d (checked)\n", x, y, w, h));
#endif /* DEBUG_sunlover */
// if there is no framebuffer, this call is not interesting
if (pFramebuffer == NULL)
return;
pFramebuffer->Lock();
/* special processing for the internal framebuffer */
if (mInternalFramebuffer)
{
pFramebuffer->Unlock();
} else
{
/* callback into the framebuffer to notify it */
if (w == 0 || h == 0)
{
/* Nothing to be updated. */
}
else
{
}
if (!finished)
{
/*
* the framebuffer needs more time to process
* the event so we have to halt the VM until it's done
*/
pFramebuffer->Unlock();
} else
{
pFramebuffer->Unlock();
}
if (!mfVideoAccelEnabled)
{
/* When VBVA is enabled, the VRDP server is informed in the VideoAccelFlush.
* Inform the server here only if VBVA is disabled.
*/
{
}
}
}
return;
}
typedef struct _VBVADIRTYREGION
{
/* Copies of object's pointers used by vbvaRgn functions. */
unsigned cMonitors;
static void vbvaRgnInit (VBVADIRTYREGION *prgn, DISPLAYFBINFO *paFramebuffers, unsigned cMonitors, Display *pd, PPDMIDISPLAYPORT pp)
{
unsigned uScreenId;
{
}
}
{
LogSunlover (("x = %d, y = %d, w = %d, h = %d\n",
/*
* Here update rectangles are accumulated to form an update area.
* @todo
* Now the simpliest method is used which builds one rectangle that
* includes all update areas. A bit more advanced method can be
* employed here. The method should be fast however.
*/
{
/* Empty rectangle. */
return;
}
{
/* This is the first rectangle to be added. */
}
else
{
/* Adjust region coordinates. */
{
}
{
}
{
}
{
}
}
if (pFBInfo->fDefaultFormat)
{
//@todo pfnUpdateDisplayRect must take the vram offset parameter for the framebuffer
}
return;
}
{
{
//@todo pfnUpdateDisplayRect must take the vram offset parameter for the framebuffer
prgn->pPort->pfnUpdateDisplayRect (prgn->pPort, pFBInfo->dirtyRect.xLeft, pFBInfo->dirtyRect.yTop, w, h);
}
}
bool fVideoAccelEnabled,
bool fVideoAccelVRDP,
unsigned cFBInfos)
{
if (pVbvaMemory)
{
/* This called only on changes in mode. So reset VRDP always. */
if (fVideoAccelEnabled)
{
if (fVideoAccelVRDP)
{
}
}
}
unsigned uScreenId;
{
{
}
}
}
bool Display::VideoAccelAllowed (void)
{
return true;
}
/**
* @thread EMT
*/
{
int rc = VINF_SUCCESS;
/* Called each time the guest wants to use acceleration,
* or when the VGA device disables acceleration,
* or when restoring the saved state with accel enabled.
*
* VGA device disables acceleration on each video mode change
* and on reset.
*
* Guest enabled acceleration at will. And it has to enable
* acceleration after a mode change.
*/
LogFlowFunc (("mfVideoAccelEnabled = %d, fEnable = %d, pVbvaMemory = %p\n",
/* Strictly check parameters. Callers must not pass anything in the case. */
if (!VideoAccelAllowed ())
{
return VERR_NOT_SUPPORTED;
}
/*
* Verify that the VM is in running state. If it is not,
* then this must be postponed until it goes to running.
*/
if (!mfMachineRunning)
{
LogFlowFunc (("Machine is not yet running.\n"));
if (fEnable)
{
}
return rc;
}
/* Check that current status is not being changed */
if (mfVideoAccelEnabled == fEnable)
{
return rc;
}
if (mfVideoAccelEnabled)
{
/* Process any pending orders and empty the VBVA ring buffer. */
VideoAccelFlush ();
}
if (!fEnable && mpVbvaMemory)
{
}
/* Safety precaution. There is no more VBVA until everything is setup! */
mpVbvaMemory = NULL;
mfVideoAccelEnabled = false;
/* Update entire display. */
{
}
/* Everything OK. VBVA status can be changed. */
/* Notify the VMMDev, which saves VBVA status in the saved state,
* and needs to know current status.
*/
if (pVMMDevPort)
{
}
if (fEnable)
{
mfVideoAccelEnabled = true;
/* Initialize the hardware memory. */
vbvaSetMemoryFlags (mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
mpVbvaMemory->off32Data = 0;
mpVbvaMemory->off32Free = 0;
mpVbvaMemory->indexRecordFirst = 0;
mpVbvaMemory->indexRecordFree = 0;
LogRel(("VBVA: Enabled.\n"));
}
else
{
LogRel(("VBVA: Disabled.\n"));
}
return rc;
}
#ifdef VBOX_WITH_VRDP
/* Called always by one VRDP server thread. Can be thread-unsafe.
*/
{
int c = fEnable?
Assert (c >= 0);
if (c == 0)
{
/* The last client has disconnected, and the accel can be
* disabled.
*/
mfVideoAccelVRDP = false;
mfu32SupportedOrders = 0;
vbvaSetMemoryFlags (mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
LogRel(("VBVA: VRDP acceleration has been disabled.\n"));
}
else if ( c == 1
&& !mfVideoAccelVRDP)
{
/* The first client has connected. Enable the accel.
*/
mfVideoAccelVRDP = true;
/* Supporting all orders. */
mfu32SupportedOrders = ~0;
vbvaSetMemoryFlags (mpVbvaMemory, mfVideoAccelEnabled, mfVideoAccelVRDP, mfu32SupportedOrders, maFramebuffers, mcMonitors);
LogRel(("VBVA: VRDP acceleration has been requested.\n"));
}
else
{
/* A client is connected or disconnected but there is no change in the
* accel state. It remains enabled.
*/
Assert (mfVideoAccelVRDP == true);
}
}
#endif /* VBOX_WITH_VRDP */
{
return true;
}
{
if (cbDst >= VBVA_RING_BUFFER_SIZE)
{
return;
}
if (i32Diff <= 0)
{
/* Chunk will not cross buffer boundary. */
}
else
{
/* Chunk crosses buffer boundary. */
}
/* Advance data offset. */
return;
}
static bool vbvaPartialRead (uint8_t **ppu8, uint32_t *pcb, uint32_t cbRecord, VBVAMEMORY *pVbvaMemory)
{
LogFlow(("MAIN::DisplayImpl::vbvaPartialRead: p = %p, cb = %d, cbRecord 0x%08X\n",
if (*ppu8)
{
}
else
{
}
if (!pu8New)
{
/* Memory allocation failed, fail the function. */
Log(("MAIN::vbvaPartialRead: failed to (re)alocate memory for partial record!!! cbRecord 0x%08X\n",
cbRecord));
if (*ppu8)
{
}
*pcb = 0;
return false;
}
/* Fetch data from the ring buffer. */
return true;
}
/* For contiguous chunks just return the address in the buffer.
* For crossing boundary - allocate a buffer from heap.
*/
{
#ifdef DEBUG_sunlover
LogFlowFunc (("first = %d, free = %d\n",
#endif /* DEBUG_sunlover */
if (!vbvaVerifyRingBuffer (mpVbvaMemory))
{
return false;
}
if (indexRecordFirst == indexRecordFree)
{
/* No records to process. Return without assigning output variables. */
return true;
}
#ifdef DEBUG_sunlover
#endif /* DEBUG_sunlover */
if (mcbVbvaPartial)
{
/* There is a partial read in process. Continue with it. */
LogFlowFunc (("continue partial record mcbVbvaPartial = %d cbRecord 0x%08X, first = %d, free = %d\n",
if (cbRecord > mcbVbvaPartial)
{
/* New data has been added to the record. */
{
return false;
}
}
{
/* The record is completed by guest. Return it to the caller. */
*pcbCmd = mcbVbvaPartial;
mcbVbvaPartial = 0;
/* Advance the record index. */
#ifdef DEBUG_sunlover
LogFlowFunc (("partial done ok, data = %d, free = %d\n",
#endif /* DEBUG_sunlover */
}
return true;
}
/* A new record need to be processed. */
{
/* Current record is being written by guest. '=' is important here. */
{
/* Partial read must be started. */
{
return false;
}
LogFlowFunc (("started partial record mcbVbvaPartial = 0x%08X cbRecord 0x%08X, first = %d, free = %d\n",
}
return true;
}
/* Current record is complete. If it is not empty, process it. */
if (cbRecord)
{
/* The size of largest contiguos chunk in the ring biffer. */
/* The ring buffer pointer. */
/* The pointer to data in the ring buffer. */
/* Fetch or point the data. */
if (u32BytesTillBoundary >= cbRecord)
{
/* The command does not cross buffer boundary. Return address in the buffer. */
/* Advance data offset. */
}
else
{
/* The command crosses buffer boundary. Rare case, so not optimized. */
if (!dst)
{
return false;
}
#ifdef DEBUG_sunlover
#endif /* DEBUG_sunlover */
}
}
/* Advance the record index. */
#ifdef DEBUG_sunlover
LogFlowFunc (("done ok, data = %d, free = %d\n",
#endif /* DEBUG_sunlover */
return true;
}
{
{
/* The pointer is inside ring buffer. Must be continuous chunk. */
/* Do nothing. */
}
else
{
/* The pointer is outside. It is then an allocated copy. */
#ifdef DEBUG_sunlover
#endif /* DEBUG_sunlover */
{
mcbVbvaPartial = 0;
}
else
{
}
}
return;
}
/**
* Called regularly on the DisplayRefresh timer.
* Also on behalf of guest, when the ring buffer is full.
*
* @thread EMT
*/
void Display::VideoAccelFlush (void)
{
#ifdef DEBUG_sunlover_2
#endif /* DEBUG_sunlover_2 */
if (!mfVideoAccelEnabled)
{
Log(("Display::VideoAccelFlush: called with disabled VBVA!!! Ignoring.\n"));
return;
}
/* Here VBVA is enabled and we have the accelerator memory pointer. */
#ifdef DEBUG_sunlover_2
LogFlowFunc (("indexRecordFirst = %d, indexRecordFree = %d, off32Data = %d, off32Free = %d\n",
mpVbvaMemory->indexRecordFirst, mpVbvaMemory->indexRecordFree, mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
#endif /* DEBUG_sunlover_2 */
/* Quick check for "nothing to update" case. */
{
return;
}
/* Process the ring buffer */
unsigned uScreenId;
{
{
}
}
/* Initialize dirty rectangles accumulator. */
for (;;)
{
/* Fetch the command data. */
{
Log(("Display::VideoAccelFlush: unable to fetch command. off32Data = %d, off32Free = %d. Disabling VBVA!!!\n",
/* Disable VBVA on those processing errors. */
VideoAccelEnable (false, NULL);
break;
}
{
/* No more commands yet in the queue. */
break;
}
if (cbCmd != 0)
{
#ifdef DEBUG_sunlover
LogFlowFunc (("hdr: cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
#endif /* DEBUG_sunlover */
int x = phdr->x;
int y = phdr->y;
int w = phdr->w;
int h = phdr->h;
{
/* Handle the command.
*
* Guest is responsible for updating the guest video memory.
* The Windows guest does all drawing using Eng*.
*
* For local output, only dirty rectangle information is used
* to update changed areas.
*
* Dirty rectangles are accumulated to exclude overlapping updates and
* group small updates to a larger one.
*/
/* Accumulate the update. */
/* Forward the command to VRDP server. */
}
}
}
{
{
}
{
/* Draw the framebuffer. */
}
}
}
// IDisplay properties
/////////////////////////////////////////////////////////////////////////////
/**
* Returns the current display width in pixel
*
* @returns COM status code
* @param width Address of result variable.
*/
{
if (!width)
return E_POINTER;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
return S_OK;
}
/**
* Returns the current display height in pixel
*
* @returns COM status code
* @param height Address of result variable.
*/
{
if (!height)
return E_POINTER;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
return S_OK;
}
/**
* Returns the current display color depth in bits
*
* @returns COM status code
* @param bitsPerPixel Address of result variable.
*/
{
if (!bitsPerPixel)
return E_INVALIDARG;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
*bitsPerPixel = cBits;
return S_OK;
}
// IDisplay methods
/////////////////////////////////////////////////////////////////////////////
{
LogFlowFunc (("\n"));
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
/*
* Create an internal framebuffer only if depth is not zero. Otherwise, we
* reset back to the "black hole" state as it was at Display construction.
*/
if (depth)
{
}
{
/* Must leave the lock here because the changeFramebuffer will also obtain it. */
/* send request to the EMT thread */
this, static_cast <IFramebuffer *> (frameBuf),
true /* aInternal */, VBOX_VIDEO_PRIMARY_SCREEN);
if (RT_SUCCESS (vrc))
VMR3ReqFree (pReq);
}
else
{
/* No VM is created (VM is powered off), do a direct call */
}
return S_OK;
}
{
if (!address)
return E_POINTER;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
/* only allowed for internal framebuffers */
if (mInternalFramebuffer && !mFramebufferOpened && !maFramebuffers[VBOX_VIDEO_PRIMARY_SCREEN].pFramebuffer.isNull())
{
mFramebufferOpened = true;
return S_OK;
}
tr ("Framebuffer locking is allowed only for the internal framebuffer"));
}
{
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
if (mFramebufferOpened)
{
mFramebufferOpened = false;
return S_OK;
}
tr ("Framebuffer locking is allowed only for the internal framebuffer"));
}
{
LogFlowFunc (("\n"));
if (!frameBuf)
return E_POINTER;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
{
/* Must leave the lock here because the changeFramebuffer will also obtain it. */
/* send request to the EMT thread */
if (RT_SUCCESS (vrc))
VMR3ReqFree (pReq);
}
else
{
/* No VM is created (VM is powered off), do a direct call */
}
return S_OK;
}
{
LogFlowFunc (("\n"));
if (!aFramebuffer)
return E_POINTER;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
{
/* Must leave the lock here because the changeFramebuffer will also obtain it. */
/* send request to the EMT thread */
if (RT_SUCCESS (vrc))
VMR3ReqFree (pReq);
}
else
{
/* No VM is created (VM is powered off), do a direct call */
}
return S_OK;
}
STDMETHODIMP Display::GetFramebuffer (ULONG aScreenId, IFramebuffer **aFramebuffer, LONG *aXOrigin, LONG *aYOrigin)
{
if (!aFramebuffer)
return E_POINTER;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
/* @todo this should be actually done on EMT. */
if (*aFramebuffer)
(*aFramebuffer)->AddRef ();
if (aXOrigin)
if (aYOrigin)
return S_OK;
}
STDMETHODIMP Display::SetVideoModeHint(ULONG aWidth, ULONG aHeight, ULONG aBitsPerPixel, ULONG aDisplay)
{
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
/*
* Do some rough checks for valid input
*/
if (!width)
if (!height)
if (!bpp)
{
}
return E_INVALIDARG;
return E_INVALIDARG;
// sunlover 20070614: It is up to the guest to decide whether the hint is valid.
// ULONG vramSize;
// mParent->machine()->COMGETTER(VRAMSize)(&vramSize);
// /* enough VRAM? */
// if ((width * height * (bpp / 8)) > (vramSize * 1024 * 1024))
// return setError(E_FAIL, tr("Not enough VRAM for the selected video mode"));
/* Have to leave the lock because the pfnRequestDisplayChange will call EMT. */
return S_OK;
}
{
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
/* Have to leave the lock because the pfnRequestSeamlessChange will call EMT. */
!!enabled);
return S_OK;
}
{
/// @todo (r=dmik) this function may take too long to complete if the VM
// is doing something like saving state right now. Which, in case if it
// is called on the GUI thread, will make it unresponsive. We should
// check the machine state here (by enclosing the check and VMRequCall
// within the Console lock to make it atomic).
LogFlowFunc (("address=%p, width=%d, height=%d\n",
if (!address)
return E_POINTER;
return E_INVALIDARG;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
LogFlowFunc (("Sending SCREENSHOT request\n"));
/*
* First try use the graphics device features for making a snapshot.
* This does not support stretching, is an optional feature (returns not supported).
*
* Note: It may cause a display resize. Watch out for deadlocks.
*/
int rcVBox = VERR_NOT_SUPPORTED;
{
if (RT_SUCCESS(rcVBox))
{
}
}
/*
* If the function returns not supported, or if stretching is requested,
* we'll have to do all the work ourselves using the framebuffer data.
*/
{
/** @todo implement snapshot stretching and generic snapshot fallback. */
}
else if (RT_FAILURE(rcVBox))
return rc;
}
{
/// @todo (r=dmik) this function may take too long to complete if the VM
// is doing something like saving state right now. Which, in case if it
// is called on the GUI thread, will make it unresponsive. We should
// check the machine state here (by enclosing the check and VMRequCall
// within the Console lock to make it atomic).
LogFlowFunc (("address=%p, x=%d, y=%d, width=%d, height=%d\n",
if (!address)
return E_POINTER;
return E_INVALIDARG;
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
/*
* Again we're lazy and make the graphics device do all the
* dirty conversion work.
*/
if (RT_SUCCESS(rcVBox))
{
}
/*
* If the function returns not supported, we'll have to do all the
* work ourselves using the framebuffer.
*/
{
/** @todo implement generic fallback for screen blitting. */
}
else if (RT_FAILURE(rcVBox))
//@todo
// else
// {
// /* All ok. Redraw the screen. */
// handleDisplayUpdate (x, y, width, height);
// }
return rc;
}
/**
* Does a full invalidation of the VM display and instructs the VM
* to update it immediately.
*
* @returns COM status code
*/
{
AutoCaller autoCaller (this);
AutoWriteLock alock (this);
LogFlowFunc (("Sending DPYUPDATE request\n"));
/* pdm.h says that this has to be called from the EMT thread */
if (RT_SUCCESS(rcVBox))
if (RT_FAILURE(rcVBox))
return rc;
}
/**
* Notification that the framebuffer has completed the
* asynchronous resize processing
*
* @returns COM status code
*/
{
LogFlowFunc (("\n"));
/// @todo (dmik) can we AutoWriteLock alock (this); here?
// do it when we switch this class to VirtualBoxBase_NEXT.
// This will require general code review and may add some details.
// In particular, we may want to check whether EMT is really waiting for
// this notification, etc. It might be also good to obey the caller to make
// sure this method is not called from more than one thread at a time
// (and therefore don't use Display lock at all here to save some
// milliseconds).
AutoCaller autoCaller (this);
/* this is only valid for external framebuffers */
if (mInternalFramebuffer)
tr ("Resize completed notification is valid only "
"for external framebuffers"));
/* Set the flag indicating that the resize has completed and display data need to be updated. */
bool f = ASMAtomicCmpXchgU32 (&maFramebuffers[aScreenId].u32ResizeStatus, ResizeStatus_UpdateDisplayData, ResizeStatus_InProgress);
AssertRelease(f);NOREF(f);
return S_OK;
}
/**
* Notification that the framebuffer has completed the
* asynchronous update processing
*
* @returns COM status code
*/
{
LogFlowFunc (("\n"));
/// @todo (dmik) can we AutoWriteLock alock (this); here?
// do it when we switch this class to VirtualBoxBase_NEXT.
// Tthis will require general code review and may add some details.
// In particular, we may want to check whether EMT is really waiting for
// this notification, etc. It might be also good to obey the caller to make
// sure this method is not called from more than one thread at a time
// (and therefore don't use Display lock at all here to save some
// milliseconds).
AutoCaller autoCaller (this);
/* this is only valid for external framebuffers */
if (mInternalFramebuffer)
tr ("Resize completed notification is valid only "
"for external framebuffers"));
/* signal our semaphore */
return S_OK;
}
// private methods
/////////////////////////////////////////////////////////////////////////////
/**
* Helper to update the display information from the framebuffer.
*
* @param aCheckParams true to compare the parameters of the current framebuffer
* and the new one and issue handleDisplayResize()
* if they differ.
* @thread EMT
*/
{
/* the driver might not have been constructed yet */
if (!mpDrv)
return;
#if DEBUG
/*
* Sanity check. Note that this method may be called on EMT after Console
* has started the power down procedure (but before our #drvDestruct() is
* called, in which case pVM will aleady be NULL but mpDrv will not). Since
* we don't really need pVM to proceed, we avoid this check in the release
* build to save some ms (necessary to construct SafeVMPtrQuiet) in this
* time-critical method.
*/
#endif
/* The method is only relevant to the primary framebuffer. */
if (pFramebuffer)
{
AssertComRC (rc);
ULONG bytesPerLine = 0;
AssertComRC (rc);
ULONG bitsPerPixel = 0;
AssertComRC (rc);
AssertComRC (rc);
AssertComRC (rc);
/*
* Check current parameters with new ones and issue handleDisplayResize()
* to let the new frame buffer adjust itself properly. Note that it will
* result into a recursive updateDisplayData() call but with
* aCheckOld = false.
*/
if (aCheckParams &&
(mLastAddress != address ||
mLastWidth != (int) width ||
mLastHeight != (int) height))
{
return;
}
}
else
{
/* black hole */
}
}
/**
* Changes the current frame buffer. Called on EMT to avoid both
* race conditions and excessive locking.
*
* @note locks this object for writing
* @thread EMT
*/
/* static */
{
that->mSupportedAccelOps = 0;
/* determine which acceleration functions are supported by this framebuffer */
{
AssertComRC (rc);
if (accelSupported)
AssertComRC (rc);
if (accelSupported)
}
return VINF_SUCCESS;
}
/**
* Handle display resize event issued by the VGA device for the primary screen.
*
* @see PDMIDISPLAYCONNECTOR::pfnResize
*/
{
LogFlowFunc (("bpp %d, pvVRAM %p, cbLine %d, cx %d, cy %d\n",
}
/**
* Handle display update.
*
* @see PDMIDISPLAYCONNECTOR::pfnUpdateRect
*/
{
#ifdef DEBUG_sunlover
LogFlowFunc (("mfVideoAccelEnabled = %d, %d,%d %dx%d\n",
#endif /* DEBUG_sunlover */
/* This call does update regardless of VBVA status.
* But in VBVA mode this is called only as result of
* pfnUpdateDisplayAll in the VGA device.
*/
}
/**
* Periodic display refresh callback.
*
* @see PDMIDISPLAYCONNECTOR::pfnRefresh
*/
{
#ifdef DEBUG_sunlover
#endif /* DEBUG_sunlover */
#ifdef DEBUG_sunlover_2
LogFlowFunc (("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
#endif /* DEBUG_sunlover_2 */
unsigned uScreenId;
{
/* Check the resize status. The status can be checked normally because
* the status affects only the EMT.
*/
{
/* The framebuffer was resized and display data need to be updated. */
/* Continue with normal processing because the status here is ResizeStatus_Void. */
if (uScreenId == VBOX_VIDEO_PRIMARY_SCREEN)
{
/* Repaint the display because VM continued to run during the framebuffer resize. */
}
/* Ignore the refresh for the screen to replay the logic. */
continue;
}
else if (u32ResizeStatus == ResizeStatus_InProgress)
{
/* The framebuffer is being resized. Do not call the VGA device back. Immediately return. */
LogFlowFunc (("ResizeStatus_InProcess\n"));
continue;
}
{
/*
* Do nothing in the "black hole" mode to avoid copying guest
* video memory to the frame buffer
*/
}
else
{
{
/* Acceleration was enabled while machine was not yet running
* due to restoring from saved state. Update entire display and
* actually enable acceleration.
*/
/* Acceleration can not be yet enabled.*/
if (pDisplay->mfMachineRunning)
{
/* Reset the pending state. */
pDisplay->mfPendingVideoAccelEnable = false;
}
}
else
{
if (pDisplay->mfVideoAccelEnabled)
{
pDisplay->VideoAccelFlush ();
}
else
{
}
}
/* Inform the VRDP server that the current display update sequence is
* completed. At this moment the framebuffer memory contains a definite
* image, that is synchronized with the orders already sent to VRDP client.
* The server can now process redraw requests from clients or initial
* fullscreen updates for new clients.
*/
{
}
}
}
#ifdef DEBUG_sunlover
#endif /* DEBUG_sunlover */
#ifdef DEBUG_sunlover_2
LogFlowFunc (("leave\n"));
#endif /* DEBUG_sunlover_2 */
}
/**
* Reset notification
*
* @see PDMIDISPLAYCONNECTOR::pfnReset
*/
{
LogFlowFunc (("\n"));
/* Disable VBVA mode. */
}
/**
* LFBModeChange notification
*
* @see PDMIDISPLAYCONNECTOR::pfnLFBModeChange
*/
DECLCALLBACK(void) Display::displayLFBModeChangeCallback(PPDMIDISPLAYCONNECTOR pInterface, bool fEnabled)
{
/* Disable VBVA mode in any case. The guest driver reenables VBVA mode if necessary. */
}
/**
* Adapter information change notification.
*
* @see PDMIDISPLAYCONNECTOR::pfnProcessAdapterData
*/
DECLCALLBACK(void) Display::displayProcessAdapterDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, uint32_t u32VRAMSize)
{
{
unsigned i;
{
pFBInfo->u32MaxFramebufferSize = 0;
pFBInfo->u32InformationSize = 0;
}
}
else
{
// @todo
for (;;)
{
pu8 += sizeof (VBOXVIDEOINFOHDR);
{
LogRel(("VBoxVideo: Guest adapter information overflow!!!\n"));
break;
}
{
{
LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "DISPLAY", pHdr->u16Length));
break;
}
{
break;
}
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));
}
{
{
LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "CONF32", pHdr->u16Length));
break;
}
{
{
} break;
{
/* @todo make configurable. */
} break;
default:
}
}
{
{
break;
}
break;
}
else
{
LogRel(("Guest adapter information contains unsupported type %d. The block has been skipped.\n", pHdr->u8Type));
}
}
}
}
/**
* Display information change notification.
*
* @see PDMIDISPLAYCONNECTOR::pfnProcessDisplayData
*/
DECLCALLBACK(void) Display::displayProcessDisplayDataCallback(PPDMIDISPLAYCONNECTOR pInterface, void *pvVRAM, unsigned uScreenId)
{
{
return;
}
/* Get the display information structure. */
// @todo
for (;;)
{
pu8 += sizeof (VBOXVIDEOINFOHDR);
{
LogRel(("VBoxVideo: Guest display information overflow!!!\n"));
break;
}
{
{
LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "SCREEN", pHdr->u16Length));
break;
}
LogFlow(("VBOX_VIDEO_INFO_TYPE_SCREEN: (%p) %d: at %d,%d, linesize 0x%X, size %dx%d, bpp %d, flags 0x%02X\n",
pHdr, uScreenId, pScreen->xOrigin, pScreen->yOrigin, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height, pScreen->bitsPerPixel, pScreen->u8Flags));
if (uScreenId != VBOX_VIDEO_PRIMARY_SCREEN)
{
/* Primary screen resize is initiated by the VGA device. */
pDrv->pDisplay->handleDisplayResize(uScreenId, pScreen->bitsPerPixel, (uint8_t *)pvVRAM + pFBInfo->u32Offset, pScreen->u32LineSize, pScreen->u16Width, pScreen->u16Height);
}
}
{
{
break;
}
break;
}
{
{
LogRel(("VBoxVideo: Guest display information %s invalid length %d!!!\n", "HOST_EVENTS", pHdr->u16Length));
break;
}
LogFlow(("VBOX_VIDEO_INFO_TYPE_HOSTEVENTS: (%p)\n",
pHostEvents));
}
{
{
LogRel(("VBoxVideo: Guest adapter information %s invalid length %d!!!\n", "LINK", pHdr->u16Length));
break;
}
}
else
{
}
}
}
/**
* Queries an interface to the driver.
*
* @returns Pointer to interface.
* @returns NULL if the interface was not supported by the driver.
* @param pInterface Pointer to this interface structure.
* @param enmInterface The requested interface identification.
*/
{
switch (enmInterface)
{
case PDMINTERFACE_BASE:
default:
return NULL;
}
}
/**
* Destruct a display driver instance.
*
* @returns VBox status.
* @param pDrvIns The driver instance data.
*/
{
{
}
}
/**
* Construct a display driver instance.
*
* @returns VBox status.
* @param pDrvIns The driver instance data.
* If the registration structure is needed, pDrvIns->pDrvReg points to it.
* @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
* of the driver instance. It's also found in pDrvIns->pCfgHandle, but like
* iInstance it's expected to be used a bit in this function.
*/
{
/*
* Validate configuration.
*/
if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
{
AssertMsgFailed(("Configuration error: Not possible to attach anything to this driver!\n"));
return VERR_PDM_DRVINS_NO_ATTACH;
}
/*
* Init Interfaces.
*/
/*
*/
pData->pUpPort = (PPDMIDISPLAYPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_DISPLAY_PORT);
{
AssertMsgFailed(("Configuration error: No display port interface above!\n"));
return VERR_PDM_MISSING_INTERFACE_ABOVE;
}
/*
* Get the Display object pointer and update the mpDrv member.
*/
void *pv;
if (RT_FAILURE(rc))
{
return rc;
}
/*
* Update our display information according to the framebuffer
*/
/*
* Start periodic screen refreshes
*/
return VINF_SUCCESS;
}
/**
* Display driver registration record.
*/
{
/* u32Version */
/* szDriverName */
"MainDisplay",
/* pszDescription */
"Main display driver (Main as in the API).",
/* fFlags */
/* fClass. */
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(DRVMAINDISPLAY),
/* pfnConstruct */
/* pfnDestruct */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
NULL,
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnDetach */
};