DisplayImpl.cpp revision b80ab4eb3844fa4a810de4e66291059f09773eea
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
#include "DisplayImpl.h"
#include "FramebufferImpl.h"
#include "ConsoleImpl.h"
#include "ConsoleVRDPServer.h"
#include "VMMDev.h"
#include "Logging.h"
#include <iprt/semaphore.h>
/**
* 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;
mLastLineSize = 0;
mLastColorDepth = 0,
mLastWidth = 0;
mLastHeight = 0;
return S_OK;
}
void Display::FinalRelease()
{
if (isReady())
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
*/
{
/* reset the event sems */
// by default, we have an internal framebuffer which is
// NULL, i.e. a black hole for no display output
mFramebuffer = 0;
mInternalFramebuffer = true;
mFramebufferOpened = false;
mSupportedAccelOps = 0;
mParent->RegisterCallback(this);
setReady (true);
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.
*/
{
AssertReturn (isReady(), (void) 0);
if (mParent)
{
mParent->UnregisterCallback(this);
}
if (mpDrv)
mfVMMDevInited = true;
setReady (false);
}
// 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
*/
static int callFramebufferResize (IFramebuffer *pFramebuffer, FramebufferPixelFormat_T pixelFormat, void *pvVRAM, uint32_t cbLine, 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(): pvVRAM=%p w=%d h=%d bpp=%d cbLine=0x%X\n",
/* If there is no framebuffer, this call is not interesting. */
if (mFramebuffer.isNull())
{
return VINF_SUCCESS;
}
mLastWidth = w;
mLastHeight = h;
switch (bpp)
{
}
/* 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.
*/
mFramebuffer->Lock();
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. */
f = ASMAtomicCmpXchgU32 (&mu32ResizeStatus, ResizeStatus_UpdateDisplayData, ResizeStatus_InProgress);
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"));
if (!mFramebuffer.isNull())
{
/* Framebuffer has completed the resize. Update the connector data. */
/* Check the framebuffer pixel format to setup the rendering in VGA device. */
mpDrv->pUpPort->pfnSetRenderVRAM (mpDrv->pUpPort, newPixelFormat == FramebufferPixelFormat_PixelFormatDefault);
}
#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"));
/* Go into non resizing state. */
bool f = ASMAtomicCmpXchgU32 (&mu32ResizeStatus, ResizeStatus_Void, ResizeStatus_UpdateDisplayData);
AssertRelease(f);NOREF(f);
if (!mFramebuffer.isNull())
{
/* Unlock framebuffer after evrything is done. */
mFramebuffer->Unlock();
}
}
{
/* 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. */
{
}
{
}
}
/**
* 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)
{
// if there is no framebuffer, this call is not interesting
if (mFramebuffer.isNull())
return;
mFramebuffer->Lock();
#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 */
/* special processing for the internal framebuffer */
if (mInternalFramebuffer)
{
mFramebuffer->Unlock();
} else
{
/* callback into the framebuffer to notify it */
if (!finished)
{
/*
* the framebuffer needs more time to process
* the event so we have to halt the VM until it's done
*/
mFramebuffer->Unlock();
} else
{
mFramebuffer->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. */
/* Merged rectangles. */
static void vbvaRgnInit (VBVADIRTYREGION *prgn, IFramebuffer *pfb, Display *pd, PPDMIDISPLAYPORT pp)
{
return;
}
{
LogFlowFunc (("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. */
{
}
{
}
{
}
{
}
}
return;
}
{
if (prgn->pFramebuffer && w != 0 && h != 0)
{
}
}
bool fVideoAccelEnabled,
bool fVideoAccelVRDP,
{
if (pVbvaMemory)
{
/* This called only on changes in mode. So reset VRDP always. */
if (fVideoAccelEnabled)
{
if (fVideoAccelVRDP)
{
}
}
}
}
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. */
if (mu32ResizeStatus == ResizeStatus_Void)
{
}
/* 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. */
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_VRDP
#ifdef VRDP_MC
/* Called always by one VRDP server thread. Can be thread-unsafe.
*/
{
#if 0
/* Supporting all orders. */
uint32_t fu32SupportedOrders = ~0;
#endif
int c = fEnable?
Assert (c >= 0);
if (c == 0)
{
/* The last client has disconnected, and the accel can be
* disabled.
*/
mfVideoAccelVRDP = false;
mfu32SupportedOrders = 0;
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;
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);
}
}
#else
{
if (fEnable)
{
}
else
{
mfu32SupportedOrders = 0;
}
}
#endif /* VRDP_MC */
#endif /* VBOX_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
#endif /* DEBUG_sunlover */
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
LogFlowFunc (("indexRecordFirst = %d, indexRecordFree = %d, off32Data = %d, off32Free = %d\n",
mpVbvaMemory->indexRecordFirst, mpVbvaMemory->indexRecordFree, mpVbvaMemory->off32Data, mpVbvaMemory->off32Free));
#endif /* DEBUG_sunlover */
/* Quick check for "nothing to update" case. */
{
return;
}
/* Process the ring buffer */
if (!fFramebufferIsNull)
{
mFramebuffer->Lock();
}
/* 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 && !fFramebufferIsNull)
{
#ifdef DEBUG_sunlover
LogFlowFunc (("hdr: cbCmd = %d, x=%d, y=%d, w=%d, h=%d\n",
#endif /* DEBUG_sunlover */
/* 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. */
}
}
if (!fFramebufferIsNull)
{
mFramebuffer->Unlock ();
}
/* 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;
CHECK_READY();
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;
CHECK_READY();
return S_OK;
}
/**
* Returns the current display color depth in bits
*
* @returns COM status code
* @param colorDepth Address of result variable.
*/
{
if (!colorDepth)
return E_INVALIDARG;
CHECK_READY();
*colorDepth = cBits;
return S_OK;
}
// IDisplay methods
/////////////////////////////////////////////////////////////////////////////
{
LogFlowFunc (("\n"));
CHECK_READY();
/*
* 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 */);
if (VBOX_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;
CHECK_READY();
/* only allowed for internal framebuffers */
{
mFramebuffer->Lock();
mFramebufferOpened = true;
return S_OK;
}
tr ("Framebuffer locking is allowed only for the internal framebuffer"));
}
{
CHECK_READY();
if (mFramebufferOpened)
{
mFramebuffer->Unlock();
mFramebufferOpened = false;
return S_OK;
}
tr ("Framebuffer locking is allowed only for the internal framebuffer"));
}
{
LogFlowFunc (("\n"));
if (!frameBuf)
return E_POINTER;
CHECK_READY();
{
/* Must leave the lock here because the changeFramebuffer will also obtain it. */
/* send request to the EMT thread */
this, frameBuf, false /* aInternal */);
if (VBOX_SUCCESS (vrc))
VMR3ReqFree (pReq);
}
else
{
/* No VM is created (VM is powered off), do a direct call */
}
return S_OK;
}
{
CHECK_READY();
/*
* Do some rough checks for valid input
*/
if (!width)
if (!height)
if (!bpp)
{
}
/* enough VRAM? */
mParent->getVMMDev()->getVMMDevPort()->pfnRequestDisplayChange(mParent->getVMMDev()->getVMMDevPort(), aWidth, aHeight, aColorDepth);
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;
CHECK_READY();
LogFlowFunc (("Sending SCREENSHOT request\n"));
/*
* First try use the graphics device features for making a snapshot.
* This does not support streatching, is an optional feature (returns not supported).
*
* Note: It may cause a display resize. Watch out for deadlocks.
*/
int rcVBox = VERR_NOT_SUPPORTED;
{
if (VBOX_SUCCESS(rcVBox))
{
}
}
/*
* If the function returns not supported, or if streaching is requested,
* we'll have to do all the work ourselves using the framebuffer data.
*/
{
/** @todo implement snapshot streching and generic snapshot fallback. */
}
else if (VBOX_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;
CHECK_READY();
/*
* Again we're lazy and make the graphics device do all the
* dirty convertion work.
*/
if (VBOX_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 (VBOX_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
*/
{
CHECK_READY();
LogFlowFunc (("Sending DPYUPDATE request\n"));
/* pdm.h says that this has to be called from the EMT thread */
if (VBOX_SUCCESS(rcVBox))
if (VBOX_FAILURE(rcVBox))
return rc;
}
/**
* Notification that the framebuffer has completed the
* asynchronous resize processing
*
* @returns COM status code
*/
{
LogFlowFunc (("\n"));
/// @todo (dmik) can we AutoLock 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).
CHECK_READY();
/* 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 (&mu32ResizeStatus, 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 AutoLock 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).
CHECK_READY();
/* this is only valid for external framebuffers */
if (mInternalFramebuffer)
tr ("Resize completed notification is valid only "
"for external framebuffers"));
mFramebuffer->Lock();
/* signal our semaphore */
mFramebuffer->Unlock();
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
if (mFramebuffer)
{
AssertComRC (rc);
AssertComRC (rc);
ULONG colorDepth = 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 ||
mLastLineSize != lineSize ||
mLastColorDepth != colorDepth ||
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 */
bool aInternal)
{
LogFlowFunc (("\n"));
/// @todo (r=dmik) AutoCaller
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.
*
* @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 (("pDrv->pDisplay->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
LogFlowFunc (("pDrv->pDisplay->mfVideoAccelEnabled = %d\n",
#endif /* DEBUG_sunlover */
/* Check the resize status. The status can be checked normally because
* the status affects only the EMT.
*/
{
LogFlowFunc (("ResizeStatus_UpdateDisplayData\n"));
/* The framebuffer was resized and display data need to be updated. */
/* Continue with normal processing because the status here is ResizeStatus_Void. */
/* Repaint the display because VM continued to run during the framebuffer resize. */
/* Ignore the refresh to replay the logic. */
return;
}
else if (u32ResizeStatus == ResizeStatus_InProgress)
{
/* The framebuffer is being resized. Do not call the VGA device back. Immediately return. */
LogFlowFunc (("ResizeStatus_InProcess\n"));
return;
}
{
/*
* 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
{
}
}
#ifdef VRDP_MC
/* Inform to 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.
*/
#endif /* VRDP_MC */
}
#ifdef DEBUG_sunlover
#endif /* DEBUG_sunlover */
}
/**
* 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. */
}
/**
* 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 (VBOX_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 */
};