use C++ wrappers around DirectFB API for easier use
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41029 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#ifndef _WX_DFB_APP_H_
|
||||
#define _WX_DFB_APP_H_
|
||||
|
||||
#include "wx/dfb/ifacehelpers.h"
|
||||
#include "wx/dfb/dfbptr.h"
|
||||
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFB);
|
||||
|
||||
@@ -35,11 +35,7 @@ public:
|
||||
virtual wxVideoMode GetDisplayMode() const;
|
||||
virtual bool SetDisplayMode(const wxVideoMode& mode);
|
||||
|
||||
// implementation - get singleton DirectFB interface
|
||||
IDirectFBPtr GetDirectFBInterface();
|
||||
|
||||
private:
|
||||
IDirectFBPtr m_dfb;
|
||||
wxVideoMode m_videoMode;
|
||||
|
||||
DECLARE_DYNAMIC_CLASS(wxApp)
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#ifndef _WX_DFB_BITMAP_H_
|
||||
#define _WX_DFB_BITMAP_H_
|
||||
|
||||
#include "wx/dfb/ifacehelpers.h"
|
||||
#include "wx/dfb/dfbptr.h"
|
||||
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
|
||||
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
virtual void SetDepth(int depth);
|
||||
|
||||
// get underlying native representation:
|
||||
IDirectFBSurfacePtr GetDirectFBSurface() const;
|
||||
wxIDirectFBSurfacePtr GetDirectFBSurface() const;
|
||||
|
||||
protected:
|
||||
bool CreateFromXpm(const char **bits);
|
||||
|
@@ -13,7 +13,7 @@
|
||||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/region.h"
|
||||
#include "wx/dfb/ifacehelpers.h"
|
||||
#include "wx/dfb/dfbptr.h"
|
||||
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
wxDC();
|
||||
|
||||
// Ctor.
|
||||
wxDC(const IDirectFBSurfacePtr& surface);
|
||||
wxDC(const wxIDirectFBSurfacePtr& surface);
|
||||
|
||||
public:
|
||||
// implement base class pure virtuals
|
||||
@@ -140,12 +140,12 @@ public:
|
||||
}
|
||||
|
||||
// Returns the surface (and increases its ref count)
|
||||
IDirectFBSurfacePtr GetDirectFBSurface() const { return m_surface; }
|
||||
wxIDirectFBSurfacePtr GetDirectFBSurface() const { return m_surface; }
|
||||
|
||||
protected:
|
||||
// initializes the DC from a surface, must be called if default ctor
|
||||
// was used
|
||||
void Init(const IDirectFBSurfacePtr& surface);
|
||||
void Init(const wxIDirectFBSurfacePtr& surface);
|
||||
|
||||
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
|
||||
int style = wxFLOOD_SURFACE);
|
||||
@@ -208,7 +208,7 @@ private:
|
||||
void SelectColour(const wxColour& clr);
|
||||
|
||||
protected:
|
||||
IDirectFBSurfacePtr m_surface;
|
||||
wxIDirectFBSurfacePtr m_surface;
|
||||
|
||||
double m_mm_to_pix_x, m_mm_to_pix_y;
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/dfb/ifacehelpers.h
|
||||
// Purpose: helpers for dealing with DFB interfaces
|
||||
// Name: wx/dfb/dfbptr.h
|
||||
// Purpose: wxDfbPtr<T> for holding objects declared in wrapdfb.h
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2006-08-09
|
||||
// RCS-ID: $Id$
|
||||
@@ -8,51 +8,50 @@
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_DFB_IFACEHELPERS_H_
|
||||
#define _WX_DFB_IFACEHELPERS_H_
|
||||
#ifndef _WX_DFB_DFBPTR_H_
|
||||
#define _WX_DFB_DFBPTR_H_
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDFB_DECLARE_INTERFACE
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
Forward declares DirectFB interface @a name.
|
||||
Forward declares wx wrapper around DirectFB interface @a name.
|
||||
|
||||
Also declares name##Ptr typedef for wxDfbPtr<name> pointer.
|
||||
Also declares wx##name##Ptr typedef for wxDfbPtr<wx##name> pointer.
|
||||
|
||||
@param name name of the DirectFB interface
|
||||
*/
|
||||
#define wxDFB_DECLARE_INTERFACE(name) \
|
||||
struct _##name; \
|
||||
typedef _##name name; \
|
||||
typedef wxDfbPtr<name> name##Ptr;
|
||||
class wx##name; \
|
||||
typedef wxDfbPtr<wx##name> wx##name##Ptr;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDfbPtr
|
||||
// wxDfbPtr<T>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// base class for wxDfbPtr
|
||||
class wxDfbWrapperBase;
|
||||
|
||||
class wxDfbPtrBase
|
||||
{
|
||||
protected:
|
||||
// increment/decrement refcount; see ifacehelpers.cpp for why using
|
||||
// void* is safe
|
||||
static void DoAddRef(void *ptr);
|
||||
static void DoRelease(void *ptr);
|
||||
static void DoAddRef(wxDfbWrapperBase *ptr);
|
||||
static void DoRelease(wxDfbWrapperBase *ptr);
|
||||
};
|
||||
|
||||
/**
|
||||
This template implements smart pointer for keeping pointers to DirectFB
|
||||
interfaces. Interface's reference count is increased on copying and the
|
||||
interface is released when the pointer is deleted.
|
||||
wrappers (i.e. wxIFoo classes derived from wxDfbWrapper<T>). Interface's
|
||||
reference count is increased on copying and the interface is released when
|
||||
the pointer is deleted.
|
||||
*/
|
||||
template<typename T>
|
||||
class wxDfbPtr : private wxDfbPtrBase
|
||||
{
|
||||
public:
|
||||
/**
|
||||
Creates the pointer from raw interface pointer.
|
||||
Creates the pointer from raw pointer to the wrapper.
|
||||
|
||||
Takes ownership of @a ptr, i.e. AddRef() is @em not called on it.
|
||||
*/
|
||||
@@ -69,28 +68,23 @@ public:
|
||||
{
|
||||
if ( m_ptr )
|
||||
{
|
||||
DoRelease(m_ptr);
|
||||
this->DoRelease((wxDfbWrapperBase*)m_ptr);
|
||||
m_ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/// Cast to raw pointer
|
||||
/// Cast to the wrapper pointer
|
||||
operator T*() const { return m_ptr; }
|
||||
|
||||
/**
|
||||
Cast to @em writeable raw pointer so that code like
|
||||
"dfb->CreateFont(dfb, NULL, &desc, &fontPtr)" works.
|
||||
// standard operators:
|
||||
|
||||
Note that this operator calls Reset(), so using it looses the value.
|
||||
*/
|
||||
T** operator&()
|
||||
wxDfbPtr& operator=(T *ptr)
|
||||
{
|
||||
Reset();
|
||||
return &m_ptr;
|
||||
m_ptr = ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// standard operators:
|
||||
|
||||
wxDfbPtr& operator=(const wxDfbPtr& ptr)
|
||||
{
|
||||
Reset();
|
||||
@@ -106,11 +100,11 @@ private:
|
||||
{
|
||||
m_ptr = ptr.m_ptr;
|
||||
if ( m_ptr )
|
||||
DoAddRef(m_ptr);
|
||||
this->DoAddRef((wxDfbWrapperBase*)m_ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
T *m_ptr;
|
||||
};
|
||||
|
||||
#endif // _WX_DFB_IFACEHELPERS_H_
|
||||
#endif // _WX_DFB_DFBPTR_H_
|
@@ -11,7 +11,7 @@
|
||||
#ifndef _WX_DFB_EVTLOOP_H_
|
||||
#define _WX_DFB_EVTLOOP_H_
|
||||
|
||||
#include "wx/dfb/ifacehelpers.h"
|
||||
#include "wx/dfb/dfbptr.h"
|
||||
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBEventBuffer);
|
||||
struct wxDFBEvent;
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
virtual bool Dispatch();
|
||||
|
||||
// returns DirectFB event buffer used by wx
|
||||
static IDirectFBEventBufferPtr GetDirectFBEventBuffer();
|
||||
static wxIDirectFBEventBufferPtr GetDirectFBEventBuffer();
|
||||
|
||||
protected:
|
||||
virtual void WakeUp();
|
||||
@@ -41,7 +41,7 @@ private:
|
||||
static void InitBuffer();
|
||||
|
||||
private:
|
||||
static IDirectFBEventBufferPtr ms_buffer;
|
||||
static wxIDirectFBEventBufferPtr ms_buffer;
|
||||
|
||||
friend class wxApp; // calls WakeUp()
|
||||
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#ifndef _WX_DFB_FONT_H_
|
||||
#define _WX_DFB_FONT_H_
|
||||
|
||||
#include "wx/dfb/ifacehelpers.h"
|
||||
#include "wx/dfb/dfbptr.h"
|
||||
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBFont);
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
virtual void SetEncoding(wxFontEncoding encoding);
|
||||
|
||||
// implementation from now on:
|
||||
IDirectFBFontPtr GetDirectFBFont() const;
|
||||
wxIDirectFBFontPtr GetDirectFBFont() const;
|
||||
|
||||
protected:
|
||||
// ref counting code
|
||||
|
@@ -14,16 +14,9 @@
|
||||
#include "wx/intl.h"
|
||||
#include "wx/log.h"
|
||||
|
||||
#include <directfb.h>
|
||||
#include "wx/dfb/wrapdfb.h"
|
||||
#include <directfb_version.h>
|
||||
|
||||
#include "wx/dfb/ifacehelpers.h"
|
||||
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFB);
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBDisplayLayer);
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBPalette);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// strings conversion
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -35,59 +28,6 @@ wxDFB_DECLARE_INTERFACE(IDirectFBPalette);
|
||||
#define wxSTR_TO_DFB(s) wxConvUTF8.cWC2MB((s).wc_str(*wxConvUI))
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// error checking
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
inline bool wxDfbCheckReturn(DFBResult code)
|
||||
{
|
||||
switch ( code )
|
||||
{
|
||||
case DFB_OK:
|
||||
return true;
|
||||
|
||||
// these are programming errors, assert:
|
||||
#define DFB_ASSERT(code) \
|
||||
case code: \
|
||||
wxFAIL_MSG( _T("DirectFB error: ") _T(#code) ); \
|
||||
return false \
|
||||
|
||||
DFB_ASSERT(DFB_DEAD);
|
||||
DFB_ASSERT(DFB_UNSUPPORTED);
|
||||
DFB_ASSERT(DFB_UNIMPLEMENTED);
|
||||
DFB_ASSERT(DFB_INVARG);
|
||||
DFB_ASSERT(DFB_NOIMPL);
|
||||
DFB_ASSERT(DFB_MISSINGFONT);
|
||||
DFB_ASSERT(DFB_THIZNULL);
|
||||
DFB_ASSERT(DFB_INVAREA);
|
||||
DFB_ASSERT(DFB_DESTROYED);
|
||||
DFB_ASSERT(DFB_NOSUCHMETHOD);
|
||||
DFB_ASSERT(DFB_NOSUCHINSTANCE);
|
||||
DFB_ASSERT(DFB_VERSIONMISMATCH);
|
||||
|
||||
#undef DFB_ASSERT
|
||||
|
||||
// these are not errors, but valid return codes:
|
||||
case DFB_INTERRUPTED:
|
||||
case DFB_BUFFEREMPTY:
|
||||
return true;
|
||||
|
||||
default:
|
||||
// FIXME: should handle the errors individually
|
||||
wxLogError(_("DirectFB error %d occured."), (int)code);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Wrap all calls to DirectFB in this macro so that the return value is
|
||||
checked and errors reported as appropriate.
|
||||
|
||||
Returns true if the call succeeded, false otherwise.
|
||||
*/
|
||||
#define DFB_CALL(call) (wxDfbCheckReturn(call))
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// surface manipulation helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -106,49 +46,22 @@ enum wxDfbCloneSurfaceMode
|
||||
either makes exact copy (wxDfbCloneSurface_CopyPixels) or only creates a
|
||||
new surface with the same size and attributes (wxDfbCloneSurface_NoPixels).
|
||||
*/
|
||||
IDirectFBSurfacePtr wxDfbCloneSurface(const IDirectFBSurfacePtr& s,
|
||||
wxDfbCloneSurfaceMode mode);
|
||||
wxIDirectFBSurfacePtr wxDfbCloneSurface(const wxIDirectFBSurfacePtr& s,
|
||||
wxDfbCloneSurfaceMode mode);
|
||||
|
||||
/// Returns bit depth used by the surface
|
||||
int wxDfbGetSurfaceDepth(const IDirectFBSurfacePtr& s);
|
||||
int wxDfbGetSurfaceDepth(const wxIDirectFBSurfacePtr& s);
|
||||
|
||||
/// Returns interface to the primary display layer:
|
||||
IDirectFBDisplayLayerPtr wxDfbGetDisplayLayer();
|
||||
wxIDirectFBDisplayLayerPtr wxDfbGetDisplayLayer();
|
||||
|
||||
/// Returns interface to the primary surface:
|
||||
IDirectFBSurfacePtr wxDfbGetPrimarySurface();
|
||||
|
||||
wxIDirectFBSurfacePtr wxDfbGetPrimarySurface();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDfbEvent
|
||||
// misc helpers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
The struct defined by this macro is a thin wrapper around DFB*Event type.
|
||||
It is needed because DFB*Event are typedefs and so we can't forward declare
|
||||
them, but we need to pass them to methods declared in public headers where
|
||||
<directfb.h> cannot be included. So this struct just holds the event value,
|
||||
it's sole purpose is that it can be forward declared.
|
||||
*/
|
||||
#define WXDFB_DEFINE_EVENT_WRAPPER(T) \
|
||||
struct wx##T \
|
||||
{ \
|
||||
wx##T() {} \
|
||||
wx##T(const T& event) : m_event(event) {} \
|
||||
\
|
||||
operator T&() { return m_event; } \
|
||||
operator const T&() const { return m_event; } \
|
||||
T* operator&() { return &m_event; } \
|
||||
\
|
||||
DFBEventClass GetClass() const { return m_event.clazz; } \
|
||||
\
|
||||
private: \
|
||||
T m_event; \
|
||||
};
|
||||
|
||||
WXDFB_DEFINE_EVENT_WRAPPER(DFBEvent)
|
||||
WXDFB_DEFINE_EVENT_WRAPPER(DFBWindowEvent)
|
||||
|
||||
/// Convert DirectFB timestamp to wxEvent one:
|
||||
#define wxDFB_EVENT_TIMESTAMP(event) \
|
||||
((event).timestamp.tv_sec * 1000 + (event).timestamp.tv_usec / 1000)
|
||||
@@ -156,7 +69,7 @@ WXDFB_DEFINE_EVENT_WRAPPER(DFBWindowEvent)
|
||||
/**
|
||||
Check if DirectFB library version is at least @a major.@a minor.@a release.
|
||||
|
||||
@sa wxCHECK_VERSION
|
||||
@see wxCHECK_VERSION
|
||||
*/
|
||||
#define wxCHECK_DFB_VERSION(major,minor,release) \
|
||||
(DIRECTFB_MAJOR_VERSION > (major) || \
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#ifndef _WX_DFB_TOPLEVEL_H_
|
||||
#define _WX_DFB_TOPLEVEL_H_
|
||||
|
||||
#include "wx/dfb/ifacehelpers.h"
|
||||
#include "wx/dfb/dfbptr.h"
|
||||
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBWindow);
|
||||
|
||||
@@ -75,13 +75,13 @@ public:
|
||||
|
||||
void OnInternalIdle();
|
||||
|
||||
IDirectFBWindowPtr GetDirectFBWindow() const { return m_dfbwin; }
|
||||
wxIDirectFBWindowPtr GetDirectFBWindow() const { return m_dfbwin; }
|
||||
|
||||
protected:
|
||||
// common part of all ctors
|
||||
void Init();
|
||||
|
||||
virtual IDirectFBSurfacePtr ObtainDfbSurface() const;
|
||||
virtual wxIDirectFBSurfacePtr ObtainDfbSurface() const;
|
||||
|
||||
// overriden wxWindow methods
|
||||
virtual void DoGetPosition(int *x, int *y) const;
|
||||
@@ -116,7 +116,7 @@ protected:
|
||||
wxByte m_opacity;
|
||||
|
||||
// interface to the underlying DirectFB window
|
||||
IDirectFBWindowPtr m_dfbwin;
|
||||
wxIDirectFBWindowPtr m_dfbwin;
|
||||
|
||||
private:
|
||||
wxDfbQueuedPaintRequests *m_toPaint;
|
||||
|
@@ -15,7 +15,7 @@
|
||||
// headers
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
#include "wx/dfb/ifacehelpers.h"
|
||||
#include "wx/dfb/dfbptr.h"
|
||||
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
|
||||
struct wxDFBWindowEvent;
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
// --------------------------
|
||||
|
||||
// Returns DirectFB surface used for rendering of this window
|
||||
IDirectFBSurfacePtr GetDfbSurface();
|
||||
wxIDirectFBSurfacePtr GetDfbSurface();
|
||||
|
||||
// returns toplevel window the window belongs to
|
||||
wxTopLevelWindowDFB *GetTLW() const { return m_tlw; }
|
||||
@@ -132,7 +132,7 @@ protected:
|
||||
|
||||
// return DFB surface used to render this window (will be assigned to
|
||||
// m_surface if the window is visible)
|
||||
virtual IDirectFBSurfacePtr ObtainDfbSurface() const;
|
||||
virtual wxIDirectFBSurfacePtr ObtainDfbSurface() const;
|
||||
|
||||
// this method must be called when window's position, size or visibility
|
||||
// changes; it resets m_surface so that ObtainDfbSurface has to be called
|
||||
@@ -161,7 +161,7 @@ protected:
|
||||
|
||||
private:
|
||||
// subsurface of TLW's surface covered by this window
|
||||
IDirectFBSurfacePtr m_surface;
|
||||
wxIDirectFBSurfacePtr m_surface;
|
||||
|
||||
// position of the window (relative to the parent, not used by wxTLW, so
|
||||
// don't access it directly)
|
||||
|
462
include/wx/dfb/wrapdfb.h
Normal file
462
include/wx/dfb/wrapdfb.h
Normal file
@@ -0,0 +1,462 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wx/dfb/wrapdfb.h
|
||||
// Purpose: wx wrappers for DirectFB interfaces
|
||||
// Author: Vaclav Slavik
|
||||
// Created: 2006-08-23
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2006 REA Elektronik GmbH
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _WX_DFB_WRAPDFB_H_
|
||||
#define _WX_DFB_WRAPDFB_H_
|
||||
|
||||
#include "wx/dfb/dfbptr.h"
|
||||
|
||||
#include <directfb.h>
|
||||
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFB);
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBDisplayLayer);
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBWindow);
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBPalette);
|
||||
wxDFB_DECLARE_INTERFACE(IDirectFBEventBuffer);
|
||||
|
||||
|
||||
/**
|
||||
Checks the @a code of a DirectFB call and returns true if it was
|
||||
successful and false if it failed, logging the errors as appropriate
|
||||
(asserts for programming errors, wxLogError for runtime failures).
|
||||
*/
|
||||
bool wxDfbCheckReturn(DFBResult code);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDfbEvent
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
The struct defined by this macro is a thin wrapper around DFB*Event type.
|
||||
It is needed because DFB*Event are typedefs and so we can't forward declare
|
||||
them, but we need to pass them to methods declared in public headers where
|
||||
<directfb.h> cannot be included. So this struct just holds the event value,
|
||||
it's sole purpose is that it can be forward declared.
|
||||
*/
|
||||
#define WXDFB_DEFINE_EVENT_WRAPPER(T) \
|
||||
struct wx##T \
|
||||
{ \
|
||||
wx##T() {} \
|
||||
wx##T(const T& event) : m_event(event) {} \
|
||||
\
|
||||
operator T&() { return m_event; } \
|
||||
operator const T&() const { return m_event; } \
|
||||
T* operator&() { return &m_event; } \
|
||||
\
|
||||
DFBEventClass GetClass() const { return m_event.clazz; } \
|
||||
\
|
||||
private: \
|
||||
T m_event; \
|
||||
};
|
||||
|
||||
WXDFB_DEFINE_EVENT_WRAPPER(DFBEvent)
|
||||
WXDFB_DEFINE_EVENT_WRAPPER(DFBWindowEvent)
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDfbWrapper<T>
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
/// Base class for wxDfbWrapper<T>
|
||||
class wxDfbWrapperBase
|
||||
{
|
||||
public:
|
||||
/// Increases reference count of the object
|
||||
void AddRef()
|
||||
{
|
||||
m_refCnt++;
|
||||
}
|
||||
|
||||
/// Decreases reference count and if it reaches zero, deletes the object
|
||||
void Release()
|
||||
{
|
||||
if ( --m_refCnt == 0 )
|
||||
delete this;
|
||||
}
|
||||
|
||||
/// Returns result code of the last call
|
||||
DFBResult GetLastResult() const { return m_lastResult; }
|
||||
|
||||
protected:
|
||||
wxDfbWrapperBase() : m_refCnt(1), m_lastResult(DFB_OK) {}
|
||||
|
||||
/// Dtor may only be called from Release()
|
||||
virtual ~wxDfbWrapperBase() {}
|
||||
|
||||
/**
|
||||
Checks the @a result of a DirectFB call and returns true if it was
|
||||
successful and false if it failed. Also stores result of the call
|
||||
so that it can be obtained by calling GetLastResult().
|
||||
*/
|
||||
bool Check(DFBResult result)
|
||||
{
|
||||
m_lastResult = result;
|
||||
return wxDfbCheckReturn(result);
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Reference count
|
||||
unsigned m_refCnt;
|
||||
|
||||
/// Result of the last DirectFB call
|
||||
DFBResult m_lastResult;
|
||||
};
|
||||
|
||||
/**
|
||||
This template is base class for friendly C++ wrapper around DirectFB
|
||||
interface T.
|
||||
|
||||
The wrapper provides same API as DirectFB, with a few exceptions:
|
||||
- methods return true/false instead of error code
|
||||
- methods that return or create another interface return pointer to the
|
||||
interface (or NULL on failure) instead of storing it in the last
|
||||
argument
|
||||
- interface arguments use wxFooPtr type instead of raw DirectFB pointer
|
||||
- methods taking flags use int type instead of an enum when the flags
|
||||
can be or-combination of enum elements (this is workaround for
|
||||
C++-unfriendly DirectFB API)
|
||||
*/
|
||||
template<typename T>
|
||||
class wxDfbWrapper : public wxDfbWrapperBase
|
||||
{
|
||||
public:
|
||||
/// "Raw" DirectFB interface type
|
||||
typedef T DirectFBIface;
|
||||
|
||||
/// Returns raw DirectFB pointer
|
||||
T *GetRaw() const { return m_ptr; }
|
||||
|
||||
protected:
|
||||
/// To be called from ctor. Takes ownership of raw object.
|
||||
void Init(T *ptr) { m_ptr = ptr; }
|
||||
|
||||
/// Dtor may only be used from Release
|
||||
~wxDfbWrapper()
|
||||
{
|
||||
if ( m_ptr )
|
||||
m_ptr->Release(m_ptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
// pointer to DirectFB object
|
||||
T *m_ptr;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxIDirectFBFont
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct wxIDirectFBFont : public wxDfbWrapper<IDirectFBFont>
|
||||
{
|
||||
wxIDirectFBFont(IDirectFBFont *s) { Init(s); }
|
||||
|
||||
bool GetStringWidth(const char *text, int bytes, int *w)
|
||||
{ return Check(m_ptr->GetStringWidth(m_ptr, text, bytes, w)); }
|
||||
|
||||
bool GetStringExtents(const char *text, int bytes,
|
||||
DFBRectangle *logicalRect, DFBRectangle *inkRect)
|
||||
{
|
||||
return Check(m_ptr->GetStringExtents(m_ptr, text, bytes,
|
||||
logicalRect, inkRect));
|
||||
}
|
||||
|
||||
bool GetHeight(int *h)
|
||||
{ return Check(m_ptr->GetHeight(m_ptr, h)); }
|
||||
|
||||
bool GetDescender(int *descender)
|
||||
{ return Check(m_ptr->GetDescender(m_ptr, descender)); }
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxIDirectFBPalette
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct wxIDirectFBPalette : public wxDfbWrapper<IDirectFBPalette>
|
||||
{
|
||||
wxIDirectFBPalette(IDirectFBPalette *s) { Init(s); }
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxIDirectFBSurface
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct wxIDirectFBSurface : public wxDfbWrapper<IDirectFBSurface>
|
||||
{
|
||||
wxIDirectFBSurface(IDirectFBSurface *s) { Init(s); }
|
||||
|
||||
bool GetSize(int *w, int *h)
|
||||
{ return Check(m_ptr->GetSize(m_ptr, w, h)); }
|
||||
|
||||
bool GetCapabilities(DFBSurfaceCapabilities *caps)
|
||||
{ return Check(m_ptr->GetCapabilities(m_ptr, caps)); }
|
||||
|
||||
bool GetPixelFormat(DFBSurfacePixelFormat *caps)
|
||||
{ return Check(m_ptr->GetPixelFormat(m_ptr, caps)); }
|
||||
|
||||
bool SetClip(const DFBRegion *clip)
|
||||
{ return Check(m_ptr->SetClip(m_ptr, clip)); }
|
||||
|
||||
bool SetColor(__u8 r, __u8 g, __u8 b, __u8 a)
|
||||
{ return Check(m_ptr->SetColor(m_ptr, r, g, b, a)); }
|
||||
|
||||
bool Clear(__u8 r, __u8 g, __u8 b, __u8 a)
|
||||
{ return Check(m_ptr->Clear(m_ptr, r, g, b, a)); }
|
||||
|
||||
bool DrawLine(int x1, int y1, int x2, int y2)
|
||||
{ return Check(m_ptr->DrawLine(m_ptr, x1, y1, x2, y2)); }
|
||||
|
||||
bool DrawRectangle(int x, int y, int w, int h)
|
||||
{ return Check(m_ptr->DrawRectangle(m_ptr, x, y, w, h)); }
|
||||
|
||||
bool FillRectangle(int x, int y, int w, int h)
|
||||
{ return Check(m_ptr->FillRectangle(m_ptr, x, y, w, h)); }
|
||||
|
||||
bool SetFont(const wxIDirectFBFontPtr& font)
|
||||
{ return Check(m_ptr->SetFont(m_ptr, font->GetRaw())); }
|
||||
|
||||
bool DrawString(const char *text, int bytes, int x, int y, int flags)
|
||||
{
|
||||
return Check(m_ptr->DrawString(m_ptr, text, bytes, x, y,
|
||||
(DFBSurfaceTextFlags)flags));
|
||||
}
|
||||
|
||||
bool Flip(const DFBRegion *region, int flags)
|
||||
{
|
||||
return Check(m_ptr->Flip(m_ptr, region, (DFBSurfaceFlipFlags)flags));
|
||||
}
|
||||
|
||||
wxIDirectFBSurfacePtr GetSubSurface(const DFBRectangle *rect)
|
||||
{
|
||||
IDirectFBSurface *s;
|
||||
if ( Check(m_ptr->GetSubSurface(m_ptr, rect, &s)) )
|
||||
return new wxIDirectFBSurface(s);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxIDirectFBPalettePtr GetPalette()
|
||||
{
|
||||
IDirectFBPalette *s;
|
||||
if ( Check(m_ptr->GetPalette(m_ptr, &s)) )
|
||||
return new wxIDirectFBPalette(s);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool SetPalette(const wxIDirectFBPalettePtr& pal)
|
||||
{ return Check(m_ptr->SetPalette(m_ptr, pal->GetRaw())); }
|
||||
|
||||
bool SetBlittingFlags(int flags)
|
||||
{
|
||||
return Check(
|
||||
m_ptr->SetBlittingFlags(m_ptr, (DFBSurfaceBlittingFlags)flags));
|
||||
}
|
||||
|
||||
bool Blit(const wxIDirectFBSurfacePtr& source,
|
||||
const DFBRectangle *source_rect,
|
||||
int x, int y)
|
||||
{
|
||||
return Check(
|
||||
m_ptr->Blit(m_ptr, source->GetRaw(), source_rect, x, y));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxIDirectFBEventBuffer
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct wxIDirectFBEventBuffer : public wxDfbWrapper<IDirectFBEventBuffer>
|
||||
{
|
||||
wxIDirectFBEventBuffer(IDirectFBEventBuffer *s) { Init(s); }
|
||||
|
||||
bool WakeUp()
|
||||
{
|
||||
return Check(m_ptr->WakeUp(m_ptr));
|
||||
}
|
||||
|
||||
bool HasEvent()
|
||||
{
|
||||
// returns DFB_OK if there is >=1 event, DFB_BUFFEREMPTY otherwise
|
||||
DFBResult r = m_ptr->HasEvent(m_ptr);
|
||||
|
||||
// NB: Check() also returns true for DFB_BUFFEREMPTY, so we can't just
|
||||
// return it's return value:
|
||||
Check(r);
|
||||
return (r == DFB_OK);
|
||||
}
|
||||
|
||||
bool WaitForEventWithTimeout(unsigned secs, unsigned millisecs)
|
||||
{
|
||||
return Check(m_ptr->WaitForEventWithTimeout(m_ptr, secs, millisecs));
|
||||
}
|
||||
|
||||
bool GetEvent(wxDFBEvent& event)
|
||||
{
|
||||
return Check(m_ptr->GetEvent(m_ptr, &event));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxIDirectFBWindow
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct wxIDirectFBWindow : public wxDfbWrapper<IDirectFBWindow>
|
||||
{
|
||||
wxIDirectFBWindow(IDirectFBWindow *s) { Init(s); }
|
||||
|
||||
bool GetID(DFBWindowID *id)
|
||||
{ return Check(m_ptr->GetID(m_ptr, id)); }
|
||||
|
||||
bool GetPosition(int *x, int *y)
|
||||
{ return Check(m_ptr->GetPosition(m_ptr, x, y)); }
|
||||
|
||||
bool GetSize(int *w, int *h)
|
||||
{ return Check(m_ptr->GetSize(m_ptr, w, h)); }
|
||||
|
||||
bool MoveTo(int x, int y)
|
||||
{ return Check(m_ptr->MoveTo(m_ptr, x, y)); }
|
||||
|
||||
bool Resize(int w, int h)
|
||||
{ return Check(m_ptr->Resize(m_ptr, w, h)); }
|
||||
|
||||
bool SetOpacity(__u8 opacity)
|
||||
{ return Check(m_ptr->SetOpacity(m_ptr, opacity)); }
|
||||
|
||||
bool SetStackingClass(DFBWindowStackingClass klass)
|
||||
{ return Check(m_ptr->SetStackingClass(m_ptr, klass)); }
|
||||
|
||||
wxIDirectFBSurfacePtr GetSurface()
|
||||
{
|
||||
IDirectFBSurface *s;
|
||||
if ( Check(m_ptr->GetSurface(m_ptr, &s)) )
|
||||
return new wxIDirectFBSurface(s);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool AttachEventBuffer(const wxIDirectFBEventBufferPtr& buffer)
|
||||
{ return Check(m_ptr->AttachEventBuffer(m_ptr, buffer->GetRaw())); }
|
||||
|
||||
bool RequestFocus()
|
||||
{ return Check(m_ptr->RequestFocus(m_ptr)); }
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxIDirectFBDisplayLayer
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct wxIDirectFBDisplayLayer : public wxDfbWrapper<IDirectFBDisplayLayer>
|
||||
{
|
||||
wxIDirectFBDisplayLayer(IDirectFBDisplayLayer *s) { Init(s); }
|
||||
|
||||
wxIDirectFBWindowPtr CreateWindow(const DFBWindowDescription *desc)
|
||||
{
|
||||
IDirectFBWindow *w;
|
||||
if ( Check(m_ptr->CreateWindow(m_ptr, desc, &w)) )
|
||||
return new wxIDirectFBWindow(w);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxIDirectFBSurfacePtr GetSurface()
|
||||
{
|
||||
IDirectFBSurface *s;
|
||||
if ( Check(m_ptr->GetSurface(m_ptr, &s)) )
|
||||
return new wxIDirectFBSurface(s);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool GetCursorPosition(int *x, int *y)
|
||||
{ return Check(m_ptr->GetCursorPosition(m_ptr, x, y)); }
|
||||
|
||||
bool WarpCursor(int x, int y)
|
||||
{ return Check(m_ptr->WarpCursor(m_ptr, x, y)); }
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxIDirectFB
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct wxIDirectFB : public wxDfbWrapper<IDirectFB>
|
||||
{
|
||||
/**
|
||||
Returns pointer to DirectFB singleton object, it never returns NULL
|
||||
after wxApp was initialized. The object is cached, so calling this
|
||||
method is cheap.
|
||||
*/
|
||||
static wxIDirectFBPtr Get()
|
||||
{
|
||||
if ( !ms_ptr ) CreateDirectFB();
|
||||
return ms_ptr;
|
||||
}
|
||||
|
||||
bool SetVideoMode(int w, int h, int bpp)
|
||||
{ return Check(m_ptr->SetVideoMode(m_ptr, w, h, bpp)); }
|
||||
|
||||
wxIDirectFBSurfacePtr CreateSurface(const DFBSurfaceDescription *desc)
|
||||
{
|
||||
IDirectFBSurface *s;
|
||||
if ( Check(m_ptr->CreateSurface(m_ptr, desc, &s)) )
|
||||
return new wxIDirectFBSurface(s);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxIDirectFBEventBufferPtr CreateEventBuffer()
|
||||
{
|
||||
IDirectFBEventBuffer *b;
|
||||
if ( Check(m_ptr->CreateEventBuffer(m_ptr, &b)) )
|
||||
return new wxIDirectFBEventBuffer(b);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxIDirectFBFontPtr CreateFont(const char *filename,
|
||||
const DFBFontDescription *desc)
|
||||
{
|
||||
IDirectFBFont *f;
|
||||
if ( Check(m_ptr->CreateFont(m_ptr, filename, desc, &f)) )
|
||||
return new wxIDirectFBFont(f);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wxIDirectFBDisplayLayerPtr GetDisplayLayer(DFBDisplayLayerID id)
|
||||
{
|
||||
IDirectFBDisplayLayer *l;
|
||||
if ( Check(m_ptr->GetDisplayLayer(m_ptr, id, &l)) )
|
||||
return new wxIDirectFBDisplayLayer(l);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
wxIDirectFB(IDirectFB *ptr) { Init(ptr); }
|
||||
|
||||
// creates ms_ptr instance
|
||||
static void CreateDirectFB();
|
||||
|
||||
static void CleanUp();
|
||||
friend class wxApp; // calls CleanUp
|
||||
|
||||
// pointer to the singleton IDirectFB object
|
||||
static wxIDirectFBPtr ms_ptr;
|
||||
};
|
||||
|
||||
#endif // _WX_DFB_WRAPDFB_H_
|
Reference in New Issue
Block a user