UIFrameBufferQuartz2D.cpp revision c58f1213e628a545081c70e26c6b67a841cff880
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* UIFrameBufferQuartz2D class implementation
*/
/*
* Copyright (C) 2006-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.
*/
#if defined (VBOX_GUI_USE_QUARTZ2D)
# include "precomp.h"
#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
/* Qt includes: */
# include <QApplication>
/* GUI includes: */
# include "UIFrameBufferQuartz2D.h"
# include "UIMachineView.h"
# include "UIMachineLogic.h"
# include "VBoxUtils.h"
# include "UISession.h"
/* COM includes: */
# include "COMEnums.h"
/* Other VBox includes: */
#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
//#define COMP_WITH_SHADOW
//#define OVERLAY_CLIPRECTS
/** @class UIFrameBufferQuartz2D
*
* The UIFrameBufferQuartz2D class is a class that implements the IFrameBuffer
* interface and uses Apples Quartz2D to store and render VM display data.
*/
, m_fUsesGuestVRAM(false)
{
Log (("Quartz2D: Creating\n"));
resizeEvent (&event);
}
{
Log (("Quartz2D: Deleting\n"));
clean();
}
/** @note This method is called on EMT from under this object's lock */
{
/* Log (("Quartz2D: NotifyUpdate %d,%d %dx%d\n", aX, aY, aW, aH));*/
return S_OK;
}
{
if (!rects)
return E_POINTER;
/** @todo r=bird: Is this thread safe? If I remember the code flow correctly, the
* GUI thread could be happily jogging along paintEvent now on another cpu core.
* This function is called on the EMT (emulation thread). Which means, blocking
* execution waiting for a lock is out of the question. A quick solution using
* ASMAtomic(Cmp)XchgPtr and a struct { cAllocated; cRects; aRects[1]; }
* *mRegion, *mUnusedRegion; should suffice (and permit you to reuse allocations). */
{
}
if (!rgnRcts)
{
if (!rgnRcts)
return E_OUTOFMEMORY;
}
// printf ("Region rects follow...\n");
{
/* QRect are inclusive */
/* The rect should intersect with the vm screen. */
++ rects;
/* Make sure only valid rects are distributed */
/* todo: Test if the other framebuffer implementation have the same
else
continue;
// printf ("Region rect[%d - %d]: %d %d %d %d\n", rgnRcts->used, aCount, rect.x(), rect.y(), rect.height(), rect.width());
}
// printf ("..................................\n");
if ( pOld
return S_OK;
}
{
/* If the machine is NOT in 'running' state,
* the link between framebuffer and video memory
* is broken, we should go fallback now... */
if (m_fUsesGuestVRAM &&
/* Online snapshotting: */
{
/* Simulate fallback through fake resize-event: */
resizeEvent(&event);
}
/* For debugging /Developer/Applications/Performance Tools/Quartz
* Debug.app is a nice tool to see which parts of the screen are
* updated.*/
/* Get the dimensions of the viewport */
/* Get the context of this window from Qt */
/* Flip the context */
/* We handle the seamless mode as a special case. */
{
/* Here we paint the windows without any wallpaper.
* So the background would be set transparently. */
/* Create a subimage of the current view.
* Currently this subimage is the whole screen. */
{
subImage = CGImageCreateWithImageInRect(pauseImg, CGRectMake(m_pMachineView->contentsX(), m_pMachineView->contentsY(), m_pMachineView->visibleWidth(), m_pMachineView->visibleHeight()));
}
else
{
#ifdef RT_ARCH_AMD64
/* Not sure who to blame, but it seems on 64bit there goes
* something terrible wrong (on a second monitor) when directly
* using CGImageCreateWithImageInRect without making a copy. We saw
* something like this already with the scale mode. */
CGImageRef tmpImage = CGImageCreateWithImageInRect(m_image, CGRectMake(m_pMachineView->contentsX(), m_pMachineView->contentsY(), m_pMachineView->visibleWidth(), m_pMachineView->visibleHeight()));
#else
subImage = CGImageCreateWithImageInRect(m_image, CGRectMake(m_pMachineView->contentsX(), m_pMachineView->contentsY(), m_pMachineView->visibleWidth(), m_pMachineView->visibleHeight()));
#endif
}
/* Clear the background (Make the rect fully transparent) */
#ifdef OVERLAY_CLIPRECTS
#endif
#ifdef COMP_WITH_SHADOW
/* Enable shadows */
#endif
/* Grab the current visible region. */
if (rgnRcts)
{
{
/* Add the clipping rects all at once. They are defined in
* SetVisibleRegion. */
/* Now convert the path to a clipping path. */
}
/* Put back the visible region, free if we cannot (2+ SetVisibleRegion calls). */
}
/* In any case clip the drawing to the view window */
/* At this point draw the real vm image */
#ifdef COMP_WITH_SHADOW
#endif
#ifdef OVERLAY_CLIPRECTS
{
}
#endif
}
&& m_scaledSize.isValid())
{
/* Here we paint if we didn't care about any masks */
/* Create a subimage of the current view in the size
* of the bounding box of the current paint event */
CGRect is = CGRectMake(CGRectGetMinX(ir), CGRectGetMinY(ir), CGRectGetWidth(ir), CGRectGetHeight(ir));
double iw = 1.0;
double ih = 1.0;
CGImageRef subImage = 0;
{
/* The pause image is already scaled. Maybe we should change that,
* to have a more uniform behavior and the different
* implementations use there own scaling algorithm. */
}
else
{
/* Scale all values needed for the image drawing. */
/* We make sure the image is always bigger than requested to
* compensate rounding errors. */
/* Round down */
/* Round up */
/* Make sure the size is within the image boundaries */
CGRect is1 = CGRectIntersection(is, CGRectMake(0, 0, CGImageGetWidth(m_image), CGImageGetHeight(m_image)));
/* Cause we probably changed the rectangle to update in the origin
* coordinate system, we have to recalculate the update rectangle
* for the screen coordinates as well. Please note that this has to
* be in double precision. */
/* Create the sub image. Note: The copy step is necessary otherwise
* strange things happens especially on Snow Leopard. No idea why. */
}
if (subImage)
{
/* For more performance we set a clipping path of the regions given
* by this paint event. */
if (!a.isEmpty())
{
/* Add all region rects to the current context as path components */
for (int i = 0; i < a.size(); ++i)
/* Now convert the path to a clipping path. */
}
/* In any case clip the drawing to the view window */
/* Turn the high interpolation quality on. */
/* Draw the image. */
}
}
else
{
/* Here we paint if we didn't care about any masks */
/* Create a subimage of the current view in the size
* of the bounding box of the current paint event */
QRect is = QRect(ir.x() + m_pMachineView->contentsX(), ir.y() + m_pMachineView->contentsY(), ir.width(), ir.height());
CGImageRef subImage = 0;
{
}
else
{
#ifdef RT_ARCH_AMD64
/* Not sure who to blame, but it seems on 64bit there goes
* something terrible wrong (on a second monitor) when directly
* using CGImageCreateWithImageInRect without making a copy. We saw
* something like this already with the scale mode. */
#else
#endif
}
if (subImage)
{
/* Ok, for more performance we set a clipping path of the
* regions given by this paint event. */
if (!a.isEmpty())
{
/* Add all region rects to the current context as path components */
for (int i = 0; i < a.size(); ++i)
/* Now convert the path to a clipping path. */
}
/* In any case clip the drawing to the view window */
/* At this point draw the real vm image */
}
}
}
{
#if 0
printf ("fmt=%lu, vram=%X, bpp=%lu, bpl=%lu, width=%lu, height=%lu\n",
#endif
/* Clean out old stuff */
clean();
bool remind = false;
/* We need a color space in any case */
/* Check if we support the pixel format/colordepth and can use the guest VRAM directly.
* Mac OS X supports 16 bit also but not in the 565 mode. So we could use
* 32 bit only. */
{
m_fUsesGuestVRAM = true;
// printf ("VRAM\n");
/* Create the image copy of the framebuffer */
CGDataProviderRef dp = CGDataProviderCreateWithData(NULL, aEvent->VRAM(), aEvent->bytesPerLine() * m_height, NULL);
}
else
{
m_fUsesGuestVRAM = false;
remind = true;
// printf ("No VRAM\n");
/* Create the memory we need for our image copy
* Read somewhere that an alignment of 16 is
* best for optimal performance. So why not. */
// int bitmapBytesPerRow = RT_ALIGN (m_width * 4, 16);
}
#ifdef VBOX_WITH_ICHAT_THEATER
#endif
// if (remind)
// msgCenter().remindAboutWrongColorDepth(aEvent->bitsPerPixel(), 32);
}
void UIFrameBufferQuartz2D::clean()
{
if (m_image)
{
}
if (m_pBitmapData)
{
}
if (mRegion)
{
}
if (mRegionUnused)
{
RTMemFree((void *)mRegionUnused);
}
}
#ifdef VBOX_WITH_VIDEOHWACCEL
{
if (pView)
}
#endif
#endif /* defined (VBOX_GUI_USE_QUARTZ2D) */