VBoxFrameBuffer.h revision 64082f4699f276693cf5b1ec5886ac12234af115
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* VBoxFrameBuffer class and subclasses declarations
*/
/*
* Copyright (C) 2006-2007 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.
*/
#ifndef ___VBoxFrameBuffer_h___
#define ___VBoxFrameBuffer_h___
//#define VBOXQGL_PROF_BASE 1
//#define VBOXQGL_DBG_SURF 1
#include "COMDefs.h"
#include <iprt/critsect.h>
/* Qt includes */
#include <QImage>
#include <QPixmap>
#include <QMutex>
#include <QPaintEvent>
#include <QMoveEvent>
#if defined (VBOX_GUI_USE_QGL)
#include <QGLWidget>
#endif
#if defined (VBOX_GUI_USE_SDL)
#include <SDL.h>
#include <signal.h>
#endif
#if defined (Q_WS_WIN) && defined (VBOX_GUI_USE_DDRAW)
#include <ddraw.h>
#endif
/////////////////////////////////////////////////////////////////////////////
/**
* Frame buffer resize event.
*/
{
};
/**
* Frame buffer repaint event.
*/
{
VBoxRepaintEvent (int x, int y, int w, int h) :
{}
int x() { return ex; }
int y() { return ey; }
};
/**
* Frame buffer set region event.
*/
{
};
/////////////////////////////////////////////////////////////////////////////
/**
* Common IFramebuffer implementation for all methods used by GUI to maintain
* the VM display video memory.
*
* Note that although this class can be called from multiple threads
* (in particular, the GUI thread and EMT) it doesn't protect access to every
* data field using its mutex lock. This is because all synchronization between
* the GUI and the EMT thread is supposed to be done using the
* IFramebuffer::NotifyUpdate() and IFramebuffer::RequestResize() methods
* (in particular, the \a aFinished parameter of these methods is responsible
* for the synchronization). These methods are always called on EMT and
* therefore always follow one another but never in parallel.
*
* Using this object's mutex lock (exposed also in IFramebuffer::Lock() and
* IFramebuffer::Unlock() implementations) usually makes sense only if some
* third-party thread (i.e. other than GUI or EMT) needs to make sure that
* *no* VM display update or resize event can occur while it is accessing
* IFramebuffer properties or the underlying display memory storage area.
*
* See IFramebuffer documentation for more info.
*/
{
#if defined (Q_OS_WIN32)
{
return ::InterlockedIncrement (&refcnt);
}
{
if (cnt == 0)
return cnt;
}
#endif
// IFramebuffer COM methods
BOOL *aSupported);
{
}
virtual bool usesGuestVRAM()
{
return false;
}
/**
* Called on the GUI thread (from VBoxConsoleView) when some part of the
* VM display viewport needs to be repainted on the host screen.
*/
/**
* Called on the GUI thread (from VBoxConsoleView) after it gets a
* VBoxResizeEvent posted from the RequestResize() method implementation.
*/
{
}
/**
* Called on the GUI thread (from VBoxConsoleView) when the VM console
* window is moved.
*/
#ifdef VBOX_WITH_VIDEOHWACCEL
/* this method is called from the GUI thread
* to perform the actual Video HW Acceleration command processing
* the event is framebuffer implementation specific */
#endif
int mWdt;
int mHgt;
#if defined (Q_OS_WIN32)
long refcnt;
#endif
};
/////////////////////////////////////////////////////////////////////////////
#if defined (VBOX_GUI_USE_QIMAGE)
{
bool usesGuestVRAM() { return mUsesGuestVRAM; }
bool mUsesGuestVRAM;
};
#endif
/////////////////////////////////////////////////////////////////////////////
#if defined (VBOX_GUI_USE_QGL)
#ifdef DEBUG
#else
#define VBOXQGLLOG(_m)
#endif
#define VBOXQGLLOG_ENTER(_m)
//do{VBOXQGLLOG(("==>[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0)
#define VBOXQGLLOG_EXIT(_m)
//do{VBOXQGLLOG(("<==[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0)
#ifdef DEBUG
#define VBOXQGL_ASSERTNOERR() \
}while(0)
#define VBOXQGL_CHECKERR(_op) \
do { \
glGetError(); \
_op \
VBOXQGL_ASSERTNOERR(); \
}while(0)
#else
#define VBOXQGL_ASSERTNOERR() \
do {}while(0)
#define VBOXQGL_CHECKERR(_op) \
do { \
_op \
}while(0)
#endif
#ifdef DEBUG
#define VBOXGETTIME() RTTimeNanoTS()
VBOXQGLLOG(_m); \
}while(0)
{
const char* mMsg;
};
#else
#define VBOXQGLLOG_METHODTIME(_m)
#endif
VBOXQGLLOG((_p " x(%d), y(%d), w(%d), h(%d)" _s, (_pr)->x(), (_pr)->y(), (_pr)->width(), (_pr)->height()));\
}while(0)
}while(0)
{
mIsClear(true)
{}
{
{
mIsClear = false;
}
else
{
mIsClear = true;
}
}
{
return;
mIsClear = false;
}
{
return;
}
{
{
mIsClear = true;
}
else
{
mIsClear = false;
}
}
bool intersects(const VBoxVHWADirtyRect & aRect) const {return mIsClear ? false : aRect.intersects(mRect);}
bool mIsClear;
};
{
VBoxVHWAColorKey() :
mUpper(0),
mLower(0)
{}
{}
bool operator==(const VBoxVHWAColorKey & other) const { return mUpper == other.mUpper && mLower == other.mLower; }
};
{
mMask(0),
mRange(0),
mOffset(32),
mcBits(0)
{}
};
{
// VBoxVHWAColorFormat(GLint aInternalFormat, GLenum aFormat, GLenum aType, uint32_t aDataFormat);
bool isValid() const {return mBitsPerPixel != 0; }
// uint32_t bitsPerPixelDd() const { return mBitsPerPixelDd; }
const VBoxVHWAColorComponent& r() const {return mR;}
const VBoxVHWAColorComponent& g() const {return mG;}
const VBoxVHWAColorComponent& b() const {return mB;}
const VBoxVHWAColorComponent& a() const {return mA;}
// uint32_t mBitsPerPixelDd;
};
{
VBoxVHWATexture() {}
// GLuint texture() {return mTexture;}
uint32_t rectSizeTex(const QRect * pRect) {return pRect->width() * pRect->height() * mBytesPerPixelTex;}
uchar * pointAddress(int x, int y)
{
x = toXTex(x);
y = toYTex(y);
return pointAddressTex(x, y);
}
virtual void initParams();
void uninit();
};
{
VBoxVHWATextureNP2() : VBoxVHWATexture() {}
mTexRect = QRect(0, 0, aRect.width()/aFormat.widthCompression(), aRect.height()/aFormat.heightCompression());
}
};
{
VBoxVHWATextureNP2Rect() : VBoxVHWATextureNP2() {}
};
{
};
{
void** mTable;
};
/* data flow:
* I. NON-Yinverted surface:
* mem->tex->fb
* 2.blt
* srcTex->invFB->tex->fb
* |->mem
*
* II. Yinverted surface:
* mem->tex->fb
* 2.blt
* srcTex->fb->tex
* |->mem
*
* III. flip support:
* 1. Yinverted<->NON-YInverted conversion :
* mem->tex-(rotate model view, force LAZY complete fb update)->invFB->tex
* fb-->| |->mem
* */
{
#if 0
bool aIsYInverted,
#endif
bool bVGA);
void uninit();
static void globalInit();
// int blt(const QRect * aDstRect, VBoxVHWASurfaceBase * aSrtSurface, const QRect * aSrcRect, const VBoxVHWAColorKey * pDstCKeyOverride, const VBoxVHWAColorKey * pSrcCKeyOverride);
int unlock();
bool addressAlocated() const { return mFreeAddress; }
// ulong bytesPerPixel() { return mpTex[0]->bytesPerPixel(); }
// ulong bitsPerPixelDd() { return mColorFormat.bitsPerPixelDd(); }
{
if(ckey)
{
mDstBltCKey = *ckey;
}
else
{
mpDstBltCKey = NULL;
}
}
{
if(ckey)
{
mSrcBltCKey = *ckey;
}
else
{
mpSrcBltCKey = NULL;
}
}
{
if(ckey)
{
}
else
{
}
}
{
if(ckey)
{
}
else
{
}
}
{
if(ckey)
{
}
else
{
}
}
{
if(ckey)
{
}
else
{
}
}
const VBoxVHWAColorKey * getActiveSrcOverlayCKey()
{
return mpSrcOverlayCKey;
}
{
}
static int setCKey(class VBoxVHWAGlProgramVHWA * pProgram, const VBoxVHWAColorFormat * pFormat, const VBoxVHWAColorKey * pCKey, bool bDst);
void deleteDisplay();
int performBlt(const QRect * pDstRect, VBoxVHWASurfaceBase * pSrcSurface, const QRect * pSrcRect, const VBoxVHWAColorKey * pDstCKey, const VBoxVHWAColorKey * pSrcCKey, bool blt);
void doMultiTex2FB(const QRect * pDstRect, VBoxVHWATexture * pDstTex, const QRect * pSrcRect, int cSrcTex);
int mLockCount;
/* memory buffer not reflected in fm and texture, e.g if memory buffer is replaced or in case of lock/unlock */
bool mFreeAddress;
#ifdef DEBUG
#endif
};
{
{
if(pOld)
{
}
}
void clear()
{
{
}
}
{
}
{
}
};
{
VBoxVHWADisplay() :
// ,
// mSurfPrimary(NULL)
{}
{
if(pVga)
{
}
// mSurfPrimary = pVga;
return old;
}
{
return mSurfVGA;
}
{
}
{
}
{
if(!hasOverlay(pSurf))
}
{
{
{
return true;
}
}
return false;
}
{
}
void performDisplay()
{
{
if(pOverlay)
{
}
}
}
};
typedef void (VBoxGLWidget::*PFNVBOXQGLOP)(void* );
typedef enum
{
typedef struct VBOXVHWACALLBACKINFO
{
void * pContext;
{
{
}
{
}
{
}
{
switch(aType)
{
case VBOXVHWA_PIPECMD_PAINT:
break;
case VBOXVHWA_PIPECMD_VHWA:
break;
case VBOXVHWA_PIPECMD_OP:
break;
default:
Assert(0);
break;
}
}
union
{
struct _VBOXVHWACMD * mpCmd;
}u;
};
{
{}
{
if(mpLast)
{
}
else
{
}
}
{
if(mpLast)
{
return pHead;
}
return NULL;
}
};
{
{
}
{
}
{
if(mpFirst)
{
return ret;
}
return NULL;
}
};
{
~VBoxGLWidget();
bool vboxUsesGuestVRAM() { return mUsesGuestVRAM; }
#ifdef VBOX_WITH_VIDEOHWACCEL
#endif
void vboxProcessVHWACommands(class VBoxVHWACommandProcessEvent * pEvent) {vboxPerformGLOp(&VBoxGLWidget::vboxDoProcessVHWACommands, pEvent);}
#ifdef VBOX_WITH_VIDEOHWACCEL
void vboxVHWACmd (struct _VBOXVHWACMD * pCmd) {vboxPerformGLOp(&VBoxGLWidget::vboxDoVHWACmd, pCmd);}
#endif
void paintGL()
{
if(mpfnOp)
{
}
else
{
}
}
void initializeGL();
void vboxDoResize(void *re);
void vboxDoPaint(void *rec);
#ifdef VBOXQGL_DBG_SURF
void vboxDoTestSurfaces(void *context);
#endif
#ifdef VBOX_WITH_VIDEOHWACCEL
void vboxDoVHWACmdExec(void *cmd);
void vboxDoVHWACmdAndFree(void *cmd);
void vboxDoVHWACmd(void *cmd);
{
if (pSurface->addressAlocated())
{
if(addr)
{
}
}
}
void vhwaDoSurfaceOverlayUpdate(VBoxVHWASurfaceBase *pDstSurf, VBoxVHWASurfaceBase *pSrcSurf, struct _VBOXVHWACMD_SURF_OVERLAY_UPDATE *pCmd);
#endif
static const QGLFormat & vboxGLFormat();
/* we do all opengl stuff in the paintGL context,
* submit the operation to be performed
* @todo: could be moved outside the updateGL */
void vboxPerformGLOp(PFNVBOXQGLOP pfn, void* pContext) {mpfnOp = pfn; mOpContext = pContext; updateGL();}
// /* posts op to UI thread */
// int vboxExecOpSynch(PFNVBOXQGLOP pfn, void* pContext);
void cmdPipeInit();
void cmdPipeDelete();
void vboxDoProcessVHWACommands(void *pContext);
class VBoxVHWACommandElement * detachCmdList(class VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
{
return pSurf;
}
void *mOpContext;
bool mUsesGuestVRAM;
bool mbVGASurfCreated;
bool mbNewEvent;
/* this is used in saved state restore to postpone surface restoration
* till the framebuffer size is restored */
};
{
#ifdef VBOXQGL_PROF_BASE
#endif
#ifdef VBOX_WITH_VIDEOHWACCEL
static bool isAcceleration2DVideoAvailable();
#endif
// void vboxMakeCurrent();
VBoxGLWidget * vboxWidget();
};
#endif
/////////////////////////////////////////////////////////////////////////////
#if defined (VBOX_GUI_USE_SDL)
{
{
}
{
}
{
}
{
return mPixelFormat;
}
bool usesGuestVRAM()
{
}
};
#endif
/////////////////////////////////////////////////////////////////////////////
#if defined (VBOX_GUI_USE_DDRAW)
{
bool usesGuestVRAM() { return mUsesGuestVRAM; }
void releaseObjects();
void deleteSurface();
void getWindowPosition (void);
bool mUsesGuestVRAM;
int mWndX;
int mWndY;
bool mSynchronousUpdates;
};
#endif
/////////////////////////////////////////////////////////////////////////////
#if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D)
{
void clean();
void *mBitmapData;
typedef struct
{
/** The size of this structure expressed in rcts entries. */
/** The number of entries in the rcts array. */
/** Variable sized array of the rectangle that makes up the region. */
} RegionRects;
/** The current valid region, all access is by atomic cmpxchg or atomic xchg.
*
* The protocol for updating and using this has to take into account that
* the producer (SetVisibleRegion) and consumer (paintEvent) are running
* on different threads. Therefore the producer will create a new RegionRects
* structure before atomically replace the existing one. While the consumer
* will read the value by atomically replace it by NULL, and then when its
* done try restore it by cmpxchg. If the producer has already put a new
* region there, it will be discarded (see mRegionUnused).
*/
RegionRects volatile *mRegion;
/** For keeping the unused region and thus avoid some RTMemAlloc/RTMemFree calls.
* This is operated with atomic cmpxchg and atomic xchg. */
RegionRects volatile *mRegionUnused;
};
#endif /* Q_WS_MAC && VBOX_GUI_USE_QUARTZ2D */
#endif // !___VBoxFrameBuffer_h___