UIFrameBufferQImage.cpp revision c58f1213e628a545081c70e26c6b67a841cff880
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIFrameBufferQImage class implementation
*/
/*
* Copyright (C) 2010-2012 Oracle Corporation
*
* 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.
*/
#ifdef VBOX_GUI_USE_QIMAGE
# include "precomp.h"
#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
/* Local includes */
# include "UIFrameBufferQImage.h"
# include "UIMachineView.h"
# include "UIMessageCenter.h"
# include "VBoxGlobal.h"
# include "UISession.h"
/* Global includes */
# include <QPainter>
# include <QApplication>
#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
/** @class UIFrameBufferQImage
*
* The UIFrameBufferQImage class is a class that implements the IFrameBuffer
* interface and uses QImage as the direct storage for VM display data. QImage
* is then converted to QPixmap and blitted to the console view widget.
*/
{
/* Initialize the framebuffer the first time */
resizeEvent(&event);
}
/** @note This method is called on EMT from under this object's lock */
{
/* We're not on the GUI thread and update() isn't thread safe in
* Qt 4.3.x on the Win, Qt 3.3.x on the Mac (4.2.x is),
* on Linux (didn't check Qt 4.x there) and probably on other
* non-DOS platforms, so post the event instead. */
return S_OK;
}
{
/* on mode switch the paint event may come while the view is null (before the new view gets set)
* this is seen on Windows hosts with 3D enabled,
* ignore paint events in that case */
if (!m_pMachineView)
return;
/* If the machine is NOT in 'running' state,
* the link between framebuffer and video memory
* is broken, we should go fallback now... */
if (m_bUsesGuestVRAM &&
/* Online snapshotting: */
goFallback();
/* Scaled image by default is empty: */
/* If scaled-factor is set and current image is NOT null: */
{
/* We are doing a deep copy of image to make sure it will not be
* detached during scale process, otherwise we can get a frozen frame-buffer. */
/* Scale image to scaled-factor: */
}
/* Choose required image: */
/* Apply image-size restriction: */
/* Some outdated rectangle during processing UIResizeEvent */
if (r.isEmpty())
return;
#if 0
LogFlowFunc (("%dx%d-%dx%d (img=%dx%d)\n", r.x(), r.y(), r.width(), r.height(), img.width(), img.height()));
#endif
{
/* This method is faster for narrow updates */
r.y() + m_pMachineView->contentsY(),
}
else
{
/* This method is faster for wide updates */
QImage::Format_RGB32));
}
}
{
#if 0
LogFlowFunc (("fmt=%d, vram=%p, bpp=%d, bpl=%d, width=%d, height=%d\n",
#endif
bool bRemind = false;
bool bFallback = false;
/* check if we support the pixel format and can use the guest VRAM directly */
{
switch (pEvent->bitsPerPixel())
{
/* 32-, 8- and 1-bpp are the only depths supported by QImage */
case 32:
break;
case 8:
bRemind = true;
break;
case 1:
bRemind = true;
break;
default:
bRemind = true;
bFallback = true;
break;
}
if (!bFallback)
{
/* QImage only supports 32-bit aligned scan lines... */
}
if (!bFallback)
{
/* ...and the scan lines ought to be a whole number of pixels. */
}
if (!bFallback)
{
}
if (!bFallback)
{
m_bUsesGuestVRAM = true;
}
}
else
{
bFallback = true;
}
if (bFallback)
{
goFallback();
}
if (bRemind)
}
void UIFrameBufferQImage::goFallback()
{
/* We don't support either the pixel format or the color depth;
* or the machine is in the state which breaks link between
* the framebuffer and the actual video-memory: */
m_bUsesGuestVRAM = false;
}
#endif /* VBOX_GUI_USE_QIMAGE */