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:
Václav Slavík
2006-09-06 09:40:31 +00:00
parent 42e2bbb9e1
commit 52c8d32a71
23 changed files with 752 additions and 366 deletions

View File

@@ -1669,15 +1669,16 @@ COND_TOOLKIT_DFB_LOWLEVEL_HDR = \
wx/dfb/dcclient.h \ wx/dfb/dcclient.h \
wx/dfb/dcmemory.h \ wx/dfb/dcmemory.h \
wx/dfb/dcscreen.h \ wx/dfb/dcscreen.h \
wx/dfb/dfbptr.h \
wx/dfb/evtloop.h \ wx/dfb/evtloop.h \
wx/dfb/font.h \ wx/dfb/font.h \
wx/dfb/ifacehelpers.h \
wx/dfb/pen.h \ wx/dfb/pen.h \
wx/dfb/popupwin.h \ wx/dfb/popupwin.h \
wx/dfb/private.h \ wx/dfb/private.h \
wx/dfb/region.h \ wx/dfb/region.h \
wx/dfb/toplevel.h \ wx/dfb/toplevel.h \
wx/dfb/window.h \ wx/dfb/window.h \
wx/dfb/wrapdfb.h \
wx/generic/caret.h \ wx/generic/caret.h \
wx/generic/colour.h \ wx/generic/colour.h \
wx/generic/icon.h \ wx/generic/icon.h \
@@ -3570,13 +3571,13 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS = \
monodll_evtloop.o \ monodll_evtloop.o \
monodll_font.o \ monodll_font.o \
monodll_fontenum.o \ monodll_fontenum.o \
monodll_ifacehelpers.o \
monodll_pen.o \ monodll_pen.o \
monodll_region.o \ monodll_region.o \
monodll_settings.o \ monodll_settings.o \
monodll_toplevel.o \ monodll_toplevel.o \
monodll_utils.o \ monodll_utils.o \
monodll_window.o \ monodll_window.o \
monodll_wrapdfb.o \
monodll_caret.o \ monodll_caret.o \
monodll_colour.o \ monodll_colour.o \
monodll_icon.o \ monodll_icon.o \
@@ -4386,13 +4387,13 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_1 = \
monodll_evtloop.o \ monodll_evtloop.o \
monodll_font.o \ monodll_font.o \
monodll_fontenum.o \ monodll_fontenum.o \
monodll_ifacehelpers.o \
monodll_pen.o \ monodll_pen.o \
monodll_region.o \ monodll_region.o \
monodll_settings.o \ monodll_settings.o \
monodll_toplevel.o \ monodll_toplevel.o \
monodll_utils.o \ monodll_utils.o \
monodll_window.o \ monodll_window.o \
monodll_wrapdfb.o \
monodll_caret.o \ monodll_caret.o \
monodll_colour.o \ monodll_colour.o \
monodll_icon.o \ monodll_icon.o \
@@ -5269,13 +5270,13 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_2 = \
monolib_evtloop.o \ monolib_evtloop.o \
monolib_font.o \ monolib_font.o \
monolib_fontenum.o \ monolib_fontenum.o \
monolib_ifacehelpers.o \
monolib_pen.o \ monolib_pen.o \
monolib_region.o \ monolib_region.o \
monolib_settings.o \ monolib_settings.o \
monolib_toplevel.o \ monolib_toplevel.o \
monolib_utils.o \ monolib_utils.o \
monolib_window.o \ monolib_window.o \
monolib_wrapdfb.o \
monolib_caret.o \ monolib_caret.o \
monolib_colour.o \ monolib_colour.o \
monolib_icon.o \ monolib_icon.o \
@@ -6086,13 +6087,13 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_3 = \
monolib_evtloop.o \ monolib_evtloop.o \
monolib_font.o \ monolib_font.o \
monolib_fontenum.o \ monolib_fontenum.o \
monolib_ifacehelpers.o \
monolib_pen.o \ monolib_pen.o \
monolib_region.o \ monolib_region.o \
monolib_settings.o \ monolib_settings.o \
monolib_toplevel.o \ monolib_toplevel.o \
monolib_utils.o \ monolib_utils.o \
monolib_window.o \ monolib_window.o \
monolib_wrapdfb.o \
monolib_caret.o \ monolib_caret.o \
monolib_colour.o \ monolib_colour.o \
monolib_icon.o \ monolib_icon.o \
@@ -7187,13 +7188,13 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_4 = \
coredll_evtloop.o \ coredll_evtloop.o \
coredll_font.o \ coredll_font.o \
coredll_fontenum.o \ coredll_fontenum.o \
coredll_ifacehelpers.o \
coredll_pen.o \ coredll_pen.o \
coredll_region.o \ coredll_region.o \
coredll_settings.o \ coredll_settings.o \
coredll_toplevel.o \ coredll_toplevel.o \
coredll_utils.o \ coredll_utils.o \
coredll_window.o \ coredll_window.o \
coredll_wrapdfb.o \
coredll_caret.o \ coredll_caret.o \
coredll_colour.o \ coredll_colour.o \
coredll_icon.o \ coredll_icon.o \
@@ -8004,13 +8005,13 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_5 = \
coredll_evtloop.o \ coredll_evtloop.o \
coredll_font.o \ coredll_font.o \
coredll_fontenum.o \ coredll_fontenum.o \
coredll_ifacehelpers.o \
coredll_pen.o \ coredll_pen.o \
coredll_region.o \ coredll_region.o \
coredll_settings.o \ coredll_settings.o \
coredll_toplevel.o \ coredll_toplevel.o \
coredll_utils.o \ coredll_utils.o \
coredll_window.o \ coredll_window.o \
coredll_wrapdfb.o \
coredll_caret.o \ coredll_caret.o \
coredll_colour.o \ coredll_colour.o \
coredll_icon.o \ coredll_icon.o \
@@ -8583,13 +8584,13 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_6 = \
corelib_evtloop.o \ corelib_evtloop.o \
corelib_font.o \ corelib_font.o \
corelib_fontenum.o \ corelib_fontenum.o \
corelib_ifacehelpers.o \
corelib_pen.o \ corelib_pen.o \
corelib_region.o \ corelib_region.o \
corelib_settings.o \ corelib_settings.o \
corelib_toplevel.o \ corelib_toplevel.o \
corelib_utils.o \ corelib_utils.o \
corelib_window.o \ corelib_window.o \
corelib_wrapdfb.o \
corelib_caret.o \ corelib_caret.o \
corelib_colour.o \ corelib_colour.o \
corelib_icon.o \ corelib_icon.o \
@@ -9400,13 +9401,13 @@ COND_TOOLKIT_DFB___LOWLEVEL_SRC_OBJECTS_7 = \
corelib_evtloop.o \ corelib_evtloop.o \
corelib_font.o \ corelib_font.o \
corelib_fontenum.o \ corelib_fontenum.o \
corelib_ifacehelpers.o \
corelib_pen.o \ corelib_pen.o \
corelib_region.o \ corelib_region.o \
corelib_settings.o \ corelib_settings.o \
corelib_toplevel.o \ corelib_toplevel.o \
corelib_utils.o \ corelib_utils.o \
corelib_window.o \ corelib_window.o \
corelib_wrapdfb.o \
corelib_caret.o \ corelib_caret.o \
corelib_colour.o \ corelib_colour.o \
corelib_icon.o \ corelib_icon.o \
@@ -13938,8 +13939,8 @@ monodll_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONODLL_ODEP)
@COND_TOOLKIT_MGL_USE_GUI_1@monodll_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(MONODLL_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@monodll_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(MONODLL_ODEP)
@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp
@COND_TOOLKIT_DFB_USE_GUI_1@monodll_ifacehelpers.o: $(srcdir)/src/dfb/ifacehelpers.cpp $(MONODLL_ODEP) @COND_TOOLKIT_DFB_USE_GUI_1@monodll_wrapdfb.o: $(srcdir)/src/dfb/wrapdfb.cpp $(MONODLL_ODEP)
@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/dfb/ifacehelpers.cpp @COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/dfb/wrapdfb.cpp
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@monodll_accel.o: $(srcdir)/src/generic/accel.cpp $(MONODLL_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@monodll_accel.o: $(srcdir)/src/generic/accel.cpp $(MONODLL_ODEP)
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/accel.cpp @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/generic/accel.cpp
@@ -17868,8 +17869,8 @@ monolib_sound_sdl.o: $(srcdir)/src/unix/sound_sdl.cpp $(MONOLIB_ODEP)
@COND_TOOLKIT_MGL_USE_GUI_1@monolib_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@monolib_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(MONOLIB_ODEP)
@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp
@COND_TOOLKIT_DFB_USE_GUI_1@monolib_ifacehelpers.o: $(srcdir)/src/dfb/ifacehelpers.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_DFB_USE_GUI_1@monolib_wrapdfb.o: $(srcdir)/src/dfb/wrapdfb.cpp $(MONOLIB_ODEP)
@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/dfb/ifacehelpers.cpp @COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/dfb/wrapdfb.cpp
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@monolib_accel.o: $(srcdir)/src/generic/accel.cpp $(MONOLIB_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@monolib_accel.o: $(srcdir)/src/generic/accel.cpp $(MONOLIB_ODEP)
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/accel.cpp @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/generic/accel.cpp
@@ -22179,8 +22180,8 @@ coredll_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(COREDLL_ODEP)
@COND_TOOLKIT_MGL_USE_GUI_1@coredll_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(COREDLL_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@coredll_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(COREDLL_ODEP)
@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp
@COND_TOOLKIT_DFB_USE_GUI_1@coredll_ifacehelpers.o: $(srcdir)/src/dfb/ifacehelpers.cpp $(COREDLL_ODEP) @COND_TOOLKIT_DFB_USE_GUI_1@coredll_wrapdfb.o: $(srcdir)/src/dfb/wrapdfb.cpp $(COREDLL_ODEP)
@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/dfb/ifacehelpers.cpp @COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/dfb/wrapdfb.cpp
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@coredll_accel.o: $(srcdir)/src/generic/accel.cpp $(COREDLL_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@coredll_accel.o: $(srcdir)/src/generic/accel.cpp $(COREDLL_ODEP)
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/generic/accel.cpp @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(COREDLL_CXXFLAGS) $(srcdir)/src/generic/accel.cpp
@@ -25044,8 +25045,8 @@ corelib_win32.o: $(srcdir)/src/univ/themes/win32.cpp $(CORELIB_ODEP)
@COND_TOOLKIT_MGL_USE_GUI_1@corelib_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(CORELIB_ODEP) @COND_TOOLKIT_MGL_USE_GUI_1@corelib_dirmgl.o: $(srcdir)/src/mgl/dirmgl.cpp $(CORELIB_ODEP)
@COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp @COND_TOOLKIT_MGL_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/mgl/dirmgl.cpp
@COND_TOOLKIT_DFB_USE_GUI_1@corelib_ifacehelpers.o: $(srcdir)/src/dfb/ifacehelpers.cpp $(CORELIB_ODEP) @COND_TOOLKIT_DFB_USE_GUI_1@corelib_wrapdfb.o: $(srcdir)/src/dfb/wrapdfb.cpp $(CORELIB_ODEP)
@COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/dfb/ifacehelpers.cpp @COND_TOOLKIT_DFB_USE_GUI_1@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/dfb/wrapdfb.cpp
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@corelib_accel.o: $(srcdir)/src/generic/accel.cpp $(CORELIB_ODEP) @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@corelib_accel.o: $(srcdir)/src/generic/accel.cpp $(CORELIB_ODEP)
@COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/generic/accel.cpp @COND_TOOLKIT_GTK_TOOLKIT_VERSION_2_USE_GUI_1_WXUNIV_0@ $(CXXC) -c -o $@ $(CORELIB_CXXFLAGS) $(srcdir)/src/generic/accel.cpp

View File

@@ -1790,13 +1790,13 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/dfb/evtloop.cpp src/dfb/evtloop.cpp
src/dfb/font.cpp src/dfb/font.cpp
src/dfb/fontenum.cpp src/dfb/fontenum.cpp
src/dfb/ifacehelpers.cpp
src/dfb/pen.cpp src/dfb/pen.cpp
src/dfb/region.cpp src/dfb/region.cpp
src/dfb/settings.cpp src/dfb/settings.cpp
src/dfb/toplevel.cpp src/dfb/toplevel.cpp
src/dfb/utils.cpp src/dfb/utils.cpp
src/dfb/window.cpp src/dfb/window.cpp
src/dfb/wrapdfb.cpp
src/generic/caret.cpp src/generic/caret.cpp
src/generic/colour.cpp src/generic/colour.cpp
src/generic/icon.cpp src/generic/icon.cpp
@@ -1812,15 +1812,16 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
wx/dfb/dcclient.h wx/dfb/dcclient.h
wx/dfb/dcmemory.h wx/dfb/dcmemory.h
wx/dfb/dcscreen.h wx/dfb/dcscreen.h
wx/dfb/dfbptr.h
wx/dfb/evtloop.h wx/dfb/evtloop.h
wx/dfb/font.h wx/dfb/font.h
wx/dfb/ifacehelpers.h
wx/dfb/pen.h wx/dfb/pen.h
wx/dfb/popupwin.h wx/dfb/popupwin.h
wx/dfb/private.h wx/dfb/private.h
wx/dfb/region.h wx/dfb/region.h
wx/dfb/toplevel.h wx/dfb/toplevel.h
wx/dfb/window.h wx/dfb/window.h
wx/dfb/wrapdfb.h
wx/generic/caret.h wx/generic/caret.h
wx/generic/colour.h wx/generic/colour.h
wx/generic/icon.h wx/generic/icon.h

View File

@@ -11,7 +11,7 @@
#ifndef _WX_DFB_APP_H_ #ifndef _WX_DFB_APP_H_
#define _WX_DFB_APP_H_ #define _WX_DFB_APP_H_
#include "wx/dfb/ifacehelpers.h" #include "wx/dfb/dfbptr.h"
wxDFB_DECLARE_INTERFACE(IDirectFB); wxDFB_DECLARE_INTERFACE(IDirectFB);
@@ -35,11 +35,7 @@ public:
virtual wxVideoMode GetDisplayMode() const; virtual wxVideoMode GetDisplayMode() const;
virtual bool SetDisplayMode(const wxVideoMode& mode); virtual bool SetDisplayMode(const wxVideoMode& mode);
// implementation - get singleton DirectFB interface
IDirectFBPtr GetDirectFBInterface();
private: private:
IDirectFBPtr m_dfb;
wxVideoMode m_videoMode; wxVideoMode m_videoMode;
DECLARE_DYNAMIC_CLASS(wxApp) DECLARE_DYNAMIC_CLASS(wxApp)

View File

@@ -11,7 +11,7 @@
#ifndef _WX_DFB_BITMAP_H_ #ifndef _WX_DFB_BITMAP_H_
#define _WX_DFB_BITMAP_H_ #define _WX_DFB_BITMAP_H_
#include "wx/dfb/ifacehelpers.h" #include "wx/dfb/dfbptr.h"
wxDFB_DECLARE_INTERFACE(IDirectFBSurface); wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
@@ -110,7 +110,7 @@ public:
virtual void SetDepth(int depth); virtual void SetDepth(int depth);
// get underlying native representation: // get underlying native representation:
IDirectFBSurfacePtr GetDirectFBSurface() const; wxIDirectFBSurfacePtr GetDirectFBSurface() const;
protected: protected:
bool CreateFromXpm(const char **bits); bool CreateFromXpm(const char **bits);

View File

@@ -13,7 +13,7 @@
#include "wx/defs.h" #include "wx/defs.h"
#include "wx/region.h" #include "wx/region.h"
#include "wx/dfb/ifacehelpers.h" #include "wx/dfb/dfbptr.h"
wxDFB_DECLARE_INTERFACE(IDirectFBSurface); wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
@@ -27,7 +27,7 @@ public:
wxDC(); wxDC();
// Ctor. // Ctor.
wxDC(const IDirectFBSurfacePtr& surface); wxDC(const wxIDirectFBSurfacePtr& surface);
public: public:
// implement base class pure virtuals // implement base class pure virtuals
@@ -140,12 +140,12 @@ public:
} }
// Returns the surface (and increases its ref count) // Returns the surface (and increases its ref count)
IDirectFBSurfacePtr GetDirectFBSurface() const { return m_surface; } wxIDirectFBSurfacePtr GetDirectFBSurface() const { return m_surface; }
protected: protected:
// initializes the DC from a surface, must be called if default ctor // initializes the DC from a surface, must be called if default ctor
// was used // was used
void Init(const IDirectFBSurfacePtr& surface); void Init(const wxIDirectFBSurfacePtr& surface);
virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, virtual bool DoFloodFill(wxCoord x, wxCoord y, const wxColour& col,
int style = wxFLOOD_SURFACE); int style = wxFLOOD_SURFACE);
@@ -208,7 +208,7 @@ private:
void SelectColour(const wxColour& clr); void SelectColour(const wxColour& clr);
protected: protected:
IDirectFBSurfacePtr m_surface; wxIDirectFBSurfacePtr m_surface;
double m_mm_to_pix_x, m_mm_to_pix_y; double m_mm_to_pix_x, m_mm_to_pix_y;

View File

@@ -1,6 +1,6 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: wx/dfb/ifacehelpers.h // Name: wx/dfb/dfbptr.h
// Purpose: helpers for dealing with DFB interfaces // Purpose: wxDfbPtr<T> for holding objects declared in wrapdfb.h
// Author: Vaclav Slavik // Author: Vaclav Slavik
// Created: 2006-08-09 // Created: 2006-08-09
// RCS-ID: $Id$ // RCS-ID: $Id$
@@ -8,51 +8,50 @@
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
#ifndef _WX_DFB_IFACEHELPERS_H_ #ifndef _WX_DFB_DFBPTR_H_
#define _WX_DFB_IFACEHELPERS_H_ #define _WX_DFB_DFBPTR_H_
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxDFB_DECLARE_INTERFACE // 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 @param name name of the DirectFB interface
*/ */
#define wxDFB_DECLARE_INTERFACE(name) \ #define wxDFB_DECLARE_INTERFACE(name) \
struct _##name; \ class wx##name; \
typedef _##name name; \ typedef wxDfbPtr<wx##name> wx##name##Ptr;
typedef wxDfbPtr<name> name##Ptr;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxDfbPtr // wxDfbPtr<T>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// base class for wxDfbPtr class wxDfbWrapperBase;
class wxDfbPtrBase class wxDfbPtrBase
{ {
protected: protected:
// increment/decrement refcount; see ifacehelpers.cpp for why using static void DoAddRef(wxDfbWrapperBase *ptr);
// void* is safe static void DoRelease(wxDfbWrapperBase *ptr);
static void DoAddRef(void *ptr);
static void DoRelease(void *ptr);
}; };
/** /**
This template implements smart pointer for keeping pointers to DirectFB This template implements smart pointer for keeping pointers to DirectFB
interfaces. Interface's reference count is increased on copying and the wrappers (i.e. wxIFoo classes derived from wxDfbWrapper<T>). Interface's
interface is released when the pointer is deleted. reference count is increased on copying and the interface is released when
the pointer is deleted.
*/ */
template<typename T> template<typename T>
class wxDfbPtr : private wxDfbPtrBase class wxDfbPtr : private wxDfbPtrBase
{ {
public: 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. Takes ownership of @a ptr, i.e. AddRef() is @em not called on it.
*/ */
@@ -69,28 +68,23 @@ public:
{ {
if ( m_ptr ) if ( m_ptr )
{ {
DoRelease(m_ptr); this->DoRelease((wxDfbWrapperBase*)m_ptr);
m_ptr = NULL; m_ptr = NULL;
} }
} }
/// Cast to raw pointer /// Cast to the wrapper pointer
operator T*() const { return m_ptr; } operator T*() const { return m_ptr; }
/** // standard operators:
Cast to @em writeable raw pointer so that code like
"dfb->CreateFont(dfb, NULL, &desc, &fontPtr)" works.
Note that this operator calls Reset(), so using it looses the value. wxDfbPtr& operator=(T *ptr)
*/
T** operator&()
{ {
Reset(); Reset();
return &m_ptr; m_ptr = ptr;
return *this;
} }
// standard operators:
wxDfbPtr& operator=(const wxDfbPtr& ptr) wxDfbPtr& operator=(const wxDfbPtr& ptr)
{ {
Reset(); Reset();
@@ -106,11 +100,11 @@ private:
{ {
m_ptr = ptr.m_ptr; m_ptr = ptr.m_ptr;
if ( m_ptr ) if ( m_ptr )
DoAddRef(m_ptr); this->DoAddRef((wxDfbWrapperBase*)m_ptr);
} }
private: private:
T *m_ptr; T *m_ptr;
}; };
#endif // _WX_DFB_IFACEHELPERS_H_ #endif // _WX_DFB_DFBPTR_H_

View File

@@ -11,7 +11,7 @@
#ifndef _WX_DFB_EVTLOOP_H_ #ifndef _WX_DFB_EVTLOOP_H_
#define _WX_DFB_EVTLOOP_H_ #define _WX_DFB_EVTLOOP_H_
#include "wx/dfb/ifacehelpers.h" #include "wx/dfb/dfbptr.h"
wxDFB_DECLARE_INTERFACE(IDirectFBEventBuffer); wxDFB_DECLARE_INTERFACE(IDirectFBEventBuffer);
struct wxDFBEvent; struct wxDFBEvent;
@@ -29,7 +29,7 @@ public:
virtual bool Dispatch(); virtual bool Dispatch();
// returns DirectFB event buffer used by wx // returns DirectFB event buffer used by wx
static IDirectFBEventBufferPtr GetDirectFBEventBuffer(); static wxIDirectFBEventBufferPtr GetDirectFBEventBuffer();
protected: protected:
virtual void WakeUp(); virtual void WakeUp();
@@ -41,7 +41,7 @@ private:
static void InitBuffer(); static void InitBuffer();
private: private:
static IDirectFBEventBufferPtr ms_buffer; static wxIDirectFBEventBufferPtr ms_buffer;
friend class wxApp; // calls WakeUp() friend class wxApp; // calls WakeUp()

View File

@@ -11,7 +11,7 @@
#ifndef _WX_DFB_FONT_H_ #ifndef _WX_DFB_FONT_H_
#define _WX_DFB_FONT_H_ #define _WX_DFB_FONT_H_
#include "wx/dfb/ifacehelpers.h" #include "wx/dfb/dfbptr.h"
wxDFB_DECLARE_INTERFACE(IDirectFBFont); wxDFB_DECLARE_INTERFACE(IDirectFBFont);
@@ -64,7 +64,7 @@ public:
virtual void SetEncoding(wxFontEncoding encoding); virtual void SetEncoding(wxFontEncoding encoding);
// implementation from now on: // implementation from now on:
IDirectFBFontPtr GetDirectFBFont() const; wxIDirectFBFontPtr GetDirectFBFont() const;
protected: protected:
// ref counting code // ref counting code

View File

@@ -14,16 +14,9 @@
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/log.h" #include "wx/log.h"
#include <directfb.h> #include "wx/dfb/wrapdfb.h"
#include <directfb_version.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 // strings conversion
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -35,59 +28,6 @@ wxDFB_DECLARE_INTERFACE(IDirectFBPalette);
#define wxSTR_TO_DFB(s) wxConvUTF8.cWC2MB((s).wc_str(*wxConvUI)) #define wxSTR_TO_DFB(s) wxConvUTF8.cWC2MB((s).wc_str(*wxConvUI))
#endif #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 // surface manipulation helpers
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -106,49 +46,22 @@ enum wxDfbCloneSurfaceMode
either makes exact copy (wxDfbCloneSurface_CopyPixels) or only creates a either makes exact copy (wxDfbCloneSurface_CopyPixels) or only creates a
new surface with the same size and attributes (wxDfbCloneSurface_NoPixels). new surface with the same size and attributes (wxDfbCloneSurface_NoPixels).
*/ */
IDirectFBSurfacePtr wxDfbCloneSurface(const IDirectFBSurfacePtr& s, wxIDirectFBSurfacePtr wxDfbCloneSurface(const wxIDirectFBSurfacePtr& s,
wxDfbCloneSurfaceMode mode); wxDfbCloneSurfaceMode mode);
/// Returns bit depth used by the surface /// Returns bit depth used by the surface
int wxDfbGetSurfaceDepth(const IDirectFBSurfacePtr& s); int wxDfbGetSurfaceDepth(const wxIDirectFBSurfacePtr& s);
/// Returns interface to the primary display layer: /// Returns interface to the primary display layer:
IDirectFBDisplayLayerPtr wxDfbGetDisplayLayer(); wxIDirectFBDisplayLayerPtr wxDfbGetDisplayLayer();
/// Returns interface to the primary surface: /// 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: /// Convert DirectFB timestamp to wxEvent one:
#define wxDFB_EVENT_TIMESTAMP(event) \ #define wxDFB_EVENT_TIMESTAMP(event) \
((event).timestamp.tv_sec * 1000 + (event).timestamp.tv_usec / 1000) ((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. 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) \ #define wxCHECK_DFB_VERSION(major,minor,release) \
(DIRECTFB_MAJOR_VERSION > (major) || \ (DIRECTFB_MAJOR_VERSION > (major) || \

View File

@@ -11,7 +11,7 @@
#ifndef _WX_DFB_TOPLEVEL_H_ #ifndef _WX_DFB_TOPLEVEL_H_
#define _WX_DFB_TOPLEVEL_H_ #define _WX_DFB_TOPLEVEL_H_
#include "wx/dfb/ifacehelpers.h" #include "wx/dfb/dfbptr.h"
wxDFB_DECLARE_INTERFACE(IDirectFBWindow); wxDFB_DECLARE_INTERFACE(IDirectFBWindow);
@@ -75,13 +75,13 @@ public:
void OnInternalIdle(); void OnInternalIdle();
IDirectFBWindowPtr GetDirectFBWindow() const { return m_dfbwin; } wxIDirectFBWindowPtr GetDirectFBWindow() const { return m_dfbwin; }
protected: protected:
// common part of all ctors // common part of all ctors
void Init(); void Init();
virtual IDirectFBSurfacePtr ObtainDfbSurface() const; virtual wxIDirectFBSurfacePtr ObtainDfbSurface() const;
// overriden wxWindow methods // overriden wxWindow methods
virtual void DoGetPosition(int *x, int *y) const; virtual void DoGetPosition(int *x, int *y) const;
@@ -116,7 +116,7 @@ protected:
wxByte m_opacity; wxByte m_opacity;
// interface to the underlying DirectFB window // interface to the underlying DirectFB window
IDirectFBWindowPtr m_dfbwin; wxIDirectFBWindowPtr m_dfbwin;
private: private:
wxDfbQueuedPaintRequests *m_toPaint; wxDfbQueuedPaintRequests *m_toPaint;

View File

@@ -15,7 +15,7 @@
// headers // headers
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
#include "wx/dfb/ifacehelpers.h" #include "wx/dfb/dfbptr.h"
wxDFB_DECLARE_INTERFACE(IDirectFBSurface); wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
struct wxDFBWindowEvent; struct wxDFBWindowEvent;
@@ -102,7 +102,7 @@ public:
// -------------------------- // --------------------------
// Returns DirectFB surface used for rendering of this window // Returns DirectFB surface used for rendering of this window
IDirectFBSurfacePtr GetDfbSurface(); wxIDirectFBSurfacePtr GetDfbSurface();
// returns toplevel window the window belongs to // returns toplevel window the window belongs to
wxTopLevelWindowDFB *GetTLW() const { return m_tlw; } wxTopLevelWindowDFB *GetTLW() const { return m_tlw; }
@@ -132,7 +132,7 @@ protected:
// return DFB surface used to render this window (will be assigned to // return DFB surface used to render this window (will be assigned to
// m_surface if the window is visible) // 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 // this method must be called when window's position, size or visibility
// changes; it resets m_surface so that ObtainDfbSurface has to be called // changes; it resets m_surface so that ObtainDfbSurface has to be called
@@ -161,7 +161,7 @@ protected:
private: private:
// subsurface of TLW's surface covered by this window // 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 // position of the window (relative to the parent, not used by wxTLW, so
// don't access it directly) // don't access it directly)

462
include/wx/dfb/wrapdfb.h Normal file
View 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_

View File

@@ -39,20 +39,15 @@ wxApp::~wxApp()
{ {
} }
IDirectFBPtr wxApp::GetDirectFBInterface()
{
return m_dfb;
}
bool wxApp::Initialize(int& argc, wxChar **argv) bool wxApp::Initialize(int& argc, wxChar **argv)
{ {
if ( !wxAppBase::Initialize(argc, argv) ) if ( !wxAppBase::Initialize(argc, argv) )
return false; return false;
if ( !DFB_CALL( DirectFBInit(&argc, &argv) ) ) if ( !wxDfbCheckReturn(DirectFBInit(&argc, &argv)) )
return false; return false;
if ( !DFB_CALL( DirectFBCreate(&m_dfb) ) ) if ( !wxIDirectFB::Get() )
return false; return false;
#warning "FIXME: theme override is temporary" #warning "FIXME: theme override is temporary"
@@ -65,7 +60,7 @@ void wxApp::CleanUp()
{ {
wxAppBase::CleanUp(); wxAppBase::CleanUp();
m_dfb.Reset(); wxIDirectFB::CleanUp();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -76,11 +71,11 @@ static wxVideoMode GetCurrentVideoMode()
{ {
wxVideoMode m; wxVideoMode m;
IDirectFBSurfacePtr surface(wxDfbGetPrimarySurface()); wxIDirectFBSurfacePtr surface(wxDfbGetPrimarySurface());
if ( !surface ) if ( !surface )
return m; // invalid return m; // invalid
DFB_CALL( surface->GetSize(surface, &m.w, &m.h) ); surface->GetSize(&m.w, &m.h);
m.bpp = wxDfbGetSurfaceDepth(surface); m.bpp = wxDfbGetSurfaceDepth(surface);
return m; return m;
@@ -96,7 +91,7 @@ wxVideoMode wxApp::GetDisplayMode() const
bool wxApp::SetDisplayMode(const wxVideoMode& mode) bool wxApp::SetDisplayMode(const wxVideoMode& mode)
{ {
if ( !DFB_CALL( m_dfb->SetVideoMode(m_dfb, mode.w, mode.h, mode.bpp) ) ) if ( !wxIDirectFB::Get()->SetVideoMode(mode.w, mode.h, mode.bpp) )
return false; return false;
m_videoMode = mode; m_videoMode = mode;

View File

@@ -174,10 +174,10 @@ public:
#endif #endif
} }
IDirectFBSurfacePtr m_surface; wxIDirectFBSurfacePtr m_surface;
wxMask *m_mask; wxMask *m_mask;
#if wxUSE_PALETTE #if wxUSE_PALETTE
wxPalette *m_palette; wxPalette *m_palette;
#endif #endif
}; };
@@ -208,9 +208,8 @@ bool wxBitmap::Create(int width, int height, int depth)
desc.width = width; desc.width = width;
desc.height = height; desc.height = height;
IDirectFBSurfacePtr surface; wxIDirectFBSurfacePtr surface(wxIDirectFB::Get()->CreateSurface(&desc));
IDirectFBPtr dfb(wxTheApp->GetDirectFBInterface()); if ( !surface )
if ( !DFB_CALL( dfb->CreateSurface(dfb, &desc, &surface) ) )
return false; return false;
m_refData = new wxBitmapRefData(); m_refData = new wxBitmapRefData();
@@ -278,7 +277,7 @@ int wxBitmap::GetHeight() const
wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
int h = -1; int h = -1;
DFB_CALL( M_BITMAP->m_surface->GetSize(M_BITMAP->m_surface, NULL, &h) ); M_BITMAP->m_surface->GetSize(NULL, &h);
return h; return h;
} }
@@ -287,7 +286,7 @@ int wxBitmap::GetWidth() const
wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
int w = -1; int w = -1;
DFB_CALL( M_BITMAP->m_surface->GetSize(M_BITMAP->m_surface, &w, NULL) ); M_BITMAP->m_surface->GetSize(&w, NULL);
return w; return w;
} }
@@ -424,7 +423,7 @@ void wxBitmap::SetDepth(int depth)
#warning "todo" #warning "todo"
} }
IDirectFBSurfacePtr wxBitmap::GetDirectFBSurface() const wxIDirectFBSurfacePtr wxBitmap::GetDirectFBSurface() const
{ {
wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ); wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );

View File

@@ -46,12 +46,12 @@ wxDC::wxDC()
m_ok = false; m_ok = false;
} }
wxDC::wxDC(const IDirectFBSurfacePtr& surface) wxDC::wxDC(const wxIDirectFBSurfacePtr& surface)
{ {
Init(surface); Init(surface);
} }
void wxDC::Init(const IDirectFBSurfacePtr& surface) void wxDC::Init(const wxIDirectFBSurfacePtr& surface)
{ {
m_ok = (surface != NULL); m_ok = (surface != NULL);
wxCHECK_RET( surface != NULL, _T("invalid surface") ); wxCHECK_RET( surface != NULL, _T("invalid surface") );
@@ -93,7 +93,7 @@ void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch)
r.x2 = r.x1 + XLOG2DEVREL(cw) - 1; r.x2 = r.x1 + XLOG2DEVREL(cw) - 1;
r.y2 = r.y1 + XLOG2DEVREL(ch) - 1; r.y2 = r.y1 + XLOG2DEVREL(ch) - 1;
if ( !DFB_CALL( m_surface->SetClip(m_surface, &r) ) ) if ( !m_surface->SetClip(&r) )
return; return;
m_clipX1 = cx; m_clipX1 = cx;
@@ -114,7 +114,7 @@ void wxDC::DestroyClippingRegion()
{ {
wxCHECK_RET( Ok(), wxT("invalid dc") ); wxCHECK_RET( Ok(), wxT("invalid dc") );
DFB_CALL( m_surface->SetClip(m_surface, NULL) ); m_surface->SetClip(NULL);
ResetClipping(); ResetClipping();
} }
@@ -140,8 +140,7 @@ void wxDC::Clear()
return; return;
wxColour clr = m_backgroundBrush.GetColour(); wxColour clr = m_backgroundBrush.GetColour();
DFB_CALL( m_surface->Clear(m_surface, m_surface->Clear(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
clr.Red(), clr.Green(), clr.Blue(), clr.Alpha()) );
} }
extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y, extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
@@ -175,9 +174,8 @@ void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
if ( m_pen.GetStyle() == wxTRANSPARENT ) if ( m_pen.GetStyle() == wxTRANSPARENT )
return; return;
DFB_CALL( m_surface->DrawLine(m_surface, m_surface->DrawLine(XLOG2DEV(x1), YLOG2DEV(y1),
XLOG2DEV(x1), YLOG2DEV(y1), XLOG2DEV(x2), YLOG2DEV(y2));
XLOG2DEV(x2), YLOG2DEV(y2)) );
CalcBoundingBox(x1, y1); CalcBoundingBox(x1, y1);
CalcBoundingBox(x2, y2); CalcBoundingBox(x2, y2);
@@ -241,14 +239,14 @@ void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
if ( m_brush.GetStyle() != wxTRANSPARENT ) if ( m_brush.GetStyle() != wxTRANSPARENT )
{ {
SelectColour(m_brush.GetColour()); SelectColour(m_brush.GetColour());
DFB_CALL( m_surface->FillRectangle(m_surface, xx, yy, ww, hh) ); m_surface->FillRectangle(xx, yy, ww, hh);
// restore pen's colour // restore pen's colour
SelectColour(m_pen.GetColour()); SelectColour(m_pen.GetColour());
} }
if ( m_pen.GetStyle() != wxTRANSPARENT ) if ( m_pen.GetStyle() != wxTRANSPARENT )
{ {
DFB_CALL( m_surface->DrawRectangle(m_surface, xx, yy, ww, hh) ); m_surface->DrawRectangle(xx, yy, ww, hh);
} }
CalcBoundingBox(x, y); CalcBoundingBox(x, y);
@@ -295,18 +293,13 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
wxCHECK_RET( m_backgroundBrush.Ok(), wxT("invalid background brush") ); wxCHECK_RET( m_backgroundBrush.Ok(), wxT("invalid background brush") );
SelectColour(m_backgroundBrush.GetColour()); SelectColour(m_backgroundBrush.GetColour());
DFB_CALL( m_surface->FillRectangle(m_surface, m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h));
xx, yy,
XLOG2DEVREL(w), YLOG2DEVREL(h)) );
// restore pen's colour // restore pen's colour
SelectColour(m_pen.GetColour()); SelectColour(m_pen.GetColour());
} }
// finally draw the text itself: // finally draw the text itself:
DFB_CALL(m_surface->DrawString(m_surface, m_surface->DrawString(wxSTR_TO_DFB(text), -1, xx, yy, DSTF_LEFT | DSTF_TOP);
wxSTR_TO_DFB(text), -1,
xx, yy,
DFBSurfaceTextFlags(DSTF_LEFT | DSTF_TOP)));
} }
void wxDC::DoDrawRotatedText(const wxString& text, void wxDC::DoDrawRotatedText(const wxString& text,
@@ -338,8 +331,7 @@ void wxDC::SetBrush(const wxBrush& brush)
void wxDC::SelectColour(const wxColour& clr) void wxDC::SelectColour(const wxColour& clr)
{ {
DFB_CALL( m_surface->SetColor(m_surface, m_surface->SetColor(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
clr.Red(), clr.Green(), clr.Blue(), clr.Alpha()) );
#warning "use SetColorIndex?" #warning "use SetColorIndex?"
} }
@@ -359,7 +351,7 @@ void wxDC::SetFont(const wxFont& font)
if ( !font.Ok() ) if ( !font.Ok() )
return; return;
if ( !DFB_CALL( m_surface->SetFont(m_surface, font.GetDirectFBFont()) ) ) if ( !m_surface->SetFont(font.GetDirectFBFont()) )
return; return;
m_font = font; m_font = font;
@@ -416,8 +408,7 @@ wxCoord wxDC::GetCharHeight() const
wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
int h = -1; int h = -1;
IDirectFBFontPtr f = m_font.GetDirectFBFont(); m_font.GetDirectFBFont()->GetHeight(&h);
DFB_CALL( f->GetHeight(f, &h) );
return YDEV2LOGREL(h); return YDEV2LOGREL(h);
} }
@@ -427,8 +418,7 @@ wxCoord wxDC::GetCharWidth() const
wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
int w = -1; int w = -1;
IDirectFBFontPtr f = m_font.GetDirectFBFont(); m_font.GetDirectFBFont()->GetStringWidth("H", 1, &w);
DFB_CALL( f->GetStringWidth(f, "H", 1, &w) );
// VS: YDEV is corrent, it should *not* be XDEV, because font's are only // VS: YDEV is corrent, it should *not* be XDEV, because font's are only
// scaled according to m_scaleY // scaled according to m_scaleY
return YDEV2LOGREL(w); return YDEV2LOGREL(w);
@@ -451,9 +441,9 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
wxCoord xx = 0, yy = 0; wxCoord xx = 0, yy = 0;
DFBRectangle rect; DFBRectangle rect;
IDirectFBFontPtr f = m_font.GetDirectFBFont(); wxIDirectFBFontPtr f = m_font.GetDirectFBFont();
if (DFB_CALL(f->GetStringExtents(f, wxSTR_TO_DFB(string), -1, &rect, NULL))) if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) )
{ {
// VS: YDEV is corrent, it should *not* be XDEV, because font's are // VS: YDEV is corrent, it should *not* be XDEV, because font's are
// only scaled according to m_scaleY // only scaled according to m_scaleY
@@ -463,7 +453,7 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
if ( descent ) if ( descent )
{ {
int d; int d;
if ( DFB_CALL( f->GetDescender(f, &d) ) ) if ( f->GetDescender(&d) )
*descent = YDEV2LOGREL(-d); *descent = YDEV2LOGREL(-d);
else else
*descent = 0; *descent = 0;
@@ -614,7 +604,7 @@ void wxDC::DoGetSize(int *w, int *h) const
{ {
wxCHECK_RET( Ok(), wxT("invalid dc") ); wxCHECK_RET( Ok(), wxT("invalid dc") );
DFB_CALL( m_surface->GetSize(m_surface, w, h) ); m_surface->GetSize(w, h);
} }
void wxDC::DoGetSizeMM(int *width, int *height) const void wxDC::DoGetSizeMM(int *width, int *height) const

View File

@@ -65,9 +65,9 @@ wxClientDCBase::wxClientDCBase(wxWindow *win)
wxRect rect = win->GetClientRect(); wxRect rect = win->GetClientRect();
DFBRectangle dfbrect = { rect.x, rect.y, rect.width, rect.height }; DFBRectangle dfbrect = { rect.x, rect.y, rect.width, rect.height };
IDirectFBSurfacePtr winsurf(win->GetDfbSurface()); wxIDirectFBSurfacePtr subsurf(
IDirectFBSurfacePtr subsurf; win->GetDfbSurface()->GetSubSurface(&dfbrect));
if ( !DFB_CALL( winsurf->GetSubSurface(winsurf, &dfbrect, &subsurf) ) ) if ( !subsurf )
return; return;
Init(subsurf); Init(subsurf);
@@ -86,9 +86,9 @@ IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
wxClientDC::~wxClientDC() wxClientDC::~wxClientDC()
{ {
// flip to surface so that the changes become visible // flip to surface so that the changes become visible
IDirectFBSurfacePtr surface(GetDirectFBSurface()); wxIDirectFBSurfacePtr surface(GetDirectFBSurface());
if ( surface ) if ( surface )
surface->Flip(surface, NULL, DSFLIP_NONE); surface->Flip(NULL, DSFLIP_NONE);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@@ -38,7 +38,7 @@
// wxEventLoop initialization // wxEventLoop initialization
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
IDirectFBEventBufferPtr wxEventLoop::ms_buffer; wxIDirectFBEventBufferPtr wxEventLoop::ms_buffer;
wxEventLoop::wxEventLoop() wxEventLoop::wxEventLoop()
{ {
@@ -49,12 +49,11 @@ wxEventLoop::wxEventLoop()
/* static */ /* static */
void wxEventLoop::InitBuffer() void wxEventLoop::InitBuffer()
{ {
IDirectFBPtr dfb(wxTheApp->GetDirectFBInterface()); ms_buffer = wxIDirectFB::Get()->CreateEventBuffer();
DFB_CALL( dfb->CreateEventBuffer(dfb, &ms_buffer) );
} }
/* static */ /* static */
IDirectFBEventBufferPtr wxEventLoop::GetDirectFBEventBuffer() wxIDirectFBEventBufferPtr wxEventLoop::GetDirectFBEventBuffer()
{ {
if ( !ms_buffer ) if ( !ms_buffer )
InitBuffer(); InitBuffer();
@@ -70,8 +69,7 @@ bool wxEventLoop::Pending() const
{ {
wxCHECK_MSG( ms_buffer, false, _T("invalid event buffer") ); wxCHECK_MSG( ms_buffer, false, _T("invalid event buffer") );
// returns DFB_OK if there is >=1 event, DFB_BUFFER_EMPTY otherwise return ms_buffer->HasEvent();
return ms_buffer->HasEvent(ms_buffer) == DFB_OK;
} }
bool wxEventLoop::Dispatch() bool wxEventLoop::Dispatch()
@@ -85,27 +83,28 @@ bool wxEventLoop::Dispatch()
// FIXME: call NotifyTimers() from here (and loop) instead? // FIXME: call NotifyTimers() from here (and loop) instead?
const int TIMEOUT = 100; const int TIMEOUT = 100;
DFBResult ret = ms_buffer->WaitForEventWithTimeout(ms_buffer, 0, TIMEOUT); if ( ms_buffer->WaitForEventWithTimeout(0, TIMEOUT) )
switch ( ret )
{ {
case DFB_OK: switch ( ms_buffer->GetLastResult() )
{ {
wxDFBEvent e; case DFB_OK:
ms_buffer->GetEvent(ms_buffer, &e); {
HandleDFBEvent(e); wxDFBEvent e;
break; ms_buffer->GetEvent(e);
HandleDFBEvent(e);
break;
}
case DFB_TIMEOUT:
// timed out, pretend we processed an event so that
// OnNextIteration is called
break;
default:
// don't terminate the loop due to errors (they were reported
// already by ms_buffer)
break;
} }
case DFB_TIMEOUT:
// timed out, pretend we processed an event so that OnNextIteration
// is called
break;
default:
// report any errors, but don't terminate the loop due to them
wxDfbCheckReturn(ret);
break;
} }
return true; return true;
@@ -115,7 +114,7 @@ void wxEventLoop::WakeUp()
{ {
wxCHECK_RET( ms_buffer, _T("invalid event buffer") ); wxCHECK_RET( ms_buffer, _T("invalid event buffer") );
DFB_CALL( ms_buffer->WakeUp(ms_buffer) ); ms_buffer->WakeUp();
} }
void wxEventLoop::OnNextIteration() void wxEventLoop::OnNextIteration()

View File

@@ -37,7 +37,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// FIXME: for now, always use single font // FIXME: for now, always use single font
static IDirectFBFontPtr gs_font = NULL; static wxIDirectFBFontPtr gs_font = NULL;
static unsigned gs_fontRefCnt = 0; static unsigned gs_fontRefCnt = 0;
class wxFontRefData : public wxObjectRefData class wxFontRefData : public wxObjectRefData
@@ -71,12 +71,10 @@ public:
// FIXME: always use default font for now // FIXME: always use default font for now
if ( !gs_font ) if ( !gs_font )
{ {
IDirectFBPtr dfb(wxTheApp->GetDirectFBInterface());
DFBFontDescription desc; DFBFontDescription desc;
desc.flags = (DFBFontDescriptionFlags)0; desc.flags = (DFBFontDescriptionFlags)0;
IDirectFBFontPtr f; wxIDirectFBFontPtr f(wxIDirectFB::Get()->CreateFont(NULL, &desc));
if ( DFB_CALL( dfb->CreateFont(dfb, NULL, &desc, &f) ) ) if ( f )
gs_font = f; gs_font = f;
} }
if ( gs_font ) // the above may fail if ( gs_font ) // the above may fail
@@ -104,7 +102,7 @@ public:
} }
wxNativeFontInfo m_info; wxNativeFontInfo m_info;
IDirectFBFontPtr m_font; wxIDirectFBFontPtr m_font;
}; };
@@ -148,7 +146,7 @@ wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
// accessors // accessors
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
IDirectFBFontPtr wxFont::GetDirectFBFont() const wxIDirectFBFontPtr wxFont::GetDirectFBFont() const
{ {
wxCHECK_MSG( Ok(), NULL, wxT("invalid font") ); wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );

View File

@@ -1,48 +0,0 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/dfb/ifacehelpers.cpp
// Purpose: helpers for dealing with DFB interfaces
// Author: Vaclav Slavik
// Created: 2006-08-09
// RCS-ID: $Id$
// Copyright: (c) 2006 REA Elektronik GmbH
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/dfb/ifacehelpers.h"
#include <directfb.h>
//-----------------------------------------------------------------------------
// wxDfbPtr
//-----------------------------------------------------------------------------
// NB: We can't call AddRef() and Release() directly from wxDfbPtr<T> because
// we don't have full type declarations for them if we don't include
// <directfb.h> (which user wx headers can't). Fortunately, all DirectFB
// interfaces are structs with common beginning that contains pointers to
// AddRef and Release, so we can safely cast interface pointer to void* and
// then back to arbitrary interface pointer and these calls will still work
// correctly. For this purpose, we declare a dummy DFB interface here.
DECLARE_INTERFACE(wxDummyDFBInterface)
DEFINE_INTERFACE(wxDummyDFBInterface, )
/* static */
void wxDfbPtrBase::DoAddRef(void *ptr)
{
wxDummyDFBInterface *p = (wxDummyDFBInterface*)ptr;
p->AddRef(p);
}
/* static */
void wxDfbPtrBase::DoRelease(void *ptr)
{
wxDummyDFBInterface *p = (wxDummyDFBInterface*)ptr;
p->Release(p);
}

View File

@@ -99,7 +99,7 @@ bool wxTopLevelWindowDFB::Create(wxWindow *parent,
pos.y = 0; pos.y = 0;
// create DirectFB window: // create DirectFB window:
IDirectFBDisplayLayerPtr layer = wxDfbGetDisplayLayer(); wxIDirectFBDisplayLayerPtr layer = wxDfbGetDisplayLayer();
wxCHECK_MSG( layer, false, _T("no display layer") ); wxCHECK_MSG( layer, false, _T("no display layer") );
DFBWindowDescription desc; DFBWindowDescription desc;
@@ -111,17 +111,18 @@ bool wxTopLevelWindowDFB::Create(wxWindow *parent,
desc.posy = pos.y; desc.posy = pos.y;
desc.width = size.x; desc.width = size.x;
desc.height = size.y; desc.height = size.y;
if ( !DFB_CALL( layer->CreateWindow(layer, &desc, &m_dfbwin) ) ) m_dfbwin = layer->CreateWindow(&desc);
if ( !layer )
return false; return false;
// add the new TLW to DFBWindowID->wxTLW map: // add the new TLW to DFBWindowID->wxTLW map:
DFBWindowID winid; DFBWindowID winid;
if ( !DFB_CALL( m_dfbwin->GetID(m_dfbwin, &winid) ) ) if ( !m_dfbwin->GetID(&winid) )
return false; return false;
gs_dfbWindowsMap[winid] = this; gs_dfbWindowsMap[winid] = this;
// TLWs are created initially hidden: // TLWs are created initially hidden:
if ( !DFB_CALL( m_dfbwin->SetOpacity(m_dfbwin, 0) ) ) if ( !m_dfbwin->SetOpacity(wxALPHA_TRANSPARENT) )
return false; return false;
wxWindow::Create(NULL, id, pos, size, style, name); wxWindow::Create(NULL, id, pos, size, style, name);
@@ -135,12 +136,11 @@ bool wxTopLevelWindowDFB::Create(wxWindow *parent,
if ( style & (wxSTAY_ON_TOP | wxPOPUP_WINDOW) ) if ( style & (wxSTAY_ON_TOP | wxPOPUP_WINDOW) )
{ {
DFB_CALL( m_dfbwin->SetStackingClass(m_dfbwin, DWSC_UPPER) ); m_dfbwin->SetStackingClass(DWSC_UPPER);
} }
// direct events in this window to the global event buffer: // direct events in this window to the global event buffer:
DFB_CALL( m_dfbwin->AttachEventBuffer( m_dfbwin->AttachEventBuffer(wxEventLoop::GetDirectFBEventBuffer());
m_dfbwin, wxEventLoop::GetDirectFBEventBuffer()) );
return true; return true;
} }
@@ -164,7 +164,7 @@ wxTopLevelWindowDFB::~wxTopLevelWindowDFB()
// remove the TLW from DFBWindowID->wxTLW map: // remove the TLW from DFBWindowID->wxTLW map:
DFBWindowID winid; DFBWindowID winid;
if ( DFB_CALL( m_dfbwin->GetID(m_dfbwin, &winid) ) ) if ( m_dfbwin->GetID(&winid) )
gs_dfbWindowsMap.erase(winid); gs_dfbWindowsMap.erase(winid);
} }
@@ -174,12 +174,12 @@ wxTopLevelWindowDFB::~wxTopLevelWindowDFB()
void wxTopLevelWindowDFB::DoGetPosition(int *x, int *y) const void wxTopLevelWindowDFB::DoGetPosition(int *x, int *y) const
{ {
DFB_CALL( m_dfbwin->GetPosition(m_dfbwin, x, y) ); m_dfbwin->GetPosition(x, y);
} }
void wxTopLevelWindowDFB::DoGetSize(int *width, int *height) const void wxTopLevelWindowDFB::DoGetSize(int *width, int *height) const
{ {
DFB_CALL( m_dfbwin->GetSize(m_dfbwin, width, height) ); m_dfbwin->GetSize(width, height);
} }
void wxTopLevelWindowDFB::DoMoveWindow(int x, int y, int width, int height) void wxTopLevelWindowDFB::DoMoveWindow(int x, int y, int width, int height)
@@ -187,13 +187,13 @@ void wxTopLevelWindowDFB::DoMoveWindow(int x, int y, int width, int height)
wxPoint curpos = GetPosition(); wxPoint curpos = GetPosition();
if ( curpos.x != x || curpos.y != y ) if ( curpos.x != x || curpos.y != y )
{ {
DFB_CALL( m_dfbwin->MoveTo(m_dfbwin, x, y) ); m_dfbwin->MoveTo(x, y);
} }
wxSize cursize = GetSize(); wxSize cursize = GetSize();
if ( cursize.x != width || cursize.y != height ) if ( cursize.x != width || cursize.y != height )
{ {
DFB_CALL( m_dfbwin->Resize(m_dfbwin, width, height) ); m_dfbwin->Resize(width, height);
// we must repaint the window after it changed size: // we must repaint the window after it changed size:
Refresh(); Refresh();
} }
@@ -242,7 +242,7 @@ bool wxTopLevelWindowDFB::Show(bool show)
return false; return false;
// hide/show the window by setting its opacity to 0/full: // hide/show the window by setting its opacity to 0/full:
DFB_CALL( m_dfbwin->SetOpacity(m_dfbwin, show ? m_opacity : 0) ); m_dfbwin->SetOpacity(show ? m_opacity : 0);
// If this is the first time Show was called, send size event, // If this is the first time Show was called, send size event,
// so that the frame can adjust itself (think auto layout or single child) // so that the frame can adjust itself (think auto layout or single child)
@@ -266,7 +266,7 @@ bool wxTopLevelWindowDFB::SetTransparent(wxByte alpha)
{ {
if ( IsShown() ) if ( IsShown() )
{ {
if ( !DFB_CALL( m_dfbwin->SetOpacity(m_dfbwin, alpha) ) ) if ( !m_dfbwin->SetOpacity(alpha) )
return false; return false;
} }
@@ -328,11 +328,9 @@ bool wxTopLevelWindowDFB::IsIconized() const
// surfaces and painting // surfaces and painting
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
IDirectFBSurfacePtr wxTopLevelWindowDFB::ObtainDfbSurface() const wxIDirectFBSurfacePtr wxTopLevelWindowDFB::ObtainDfbSurface() const
{ {
IDirectFBSurfacePtr surface; return m_dfbwin->GetSurface();
DFB_CALL( m_dfbwin->GetSurface(m_dfbwin, &surface) );
return surface;
} }
void wxTopLevelWindowDFB::HandleQueuedPaintRequests() void wxTopLevelWindowDFB::HandleQueuedPaintRequests()
@@ -380,8 +378,7 @@ void wxTopLevelWindowDFB::HandleQueuedPaintRequests()
paintedRect.GetRight(), paintedRect.GetBottom()}; paintedRect.GetRight(), paintedRect.GetBottom()};
DFBRegion *rptr = (winRect == paintedRect) ? NULL : &r; DFBRegion *rptr = (winRect == paintedRect) ? NULL : &r;
IDirectFBSurfacePtr surface(GetDfbSurface()); GetDfbSurface()->Flip(rptr, DSFLIP_NONE);
DFB_CALL( surface->Flip(surface, rptr, DSFLIP_NONE) );
} }
void wxTopLevelWindowDFB::DoRefreshRect(const wxRect& rect, bool eraseBack) void wxTopLevelWindowDFB::DoRefreshRect(const wxRect& rect, bool eraseBack)

View File

@@ -87,8 +87,8 @@ void wxClientDisplayRect(int *x, int *y, int *width, int *height)
// surface manipulation helpers // surface manipulation helpers
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
IDirectFBSurfacePtr wxDfbCloneSurface(const IDirectFBSurfacePtr& s, wxIDirectFBSurfacePtr wxDfbCloneSurface(const wxIDirectFBSurfacePtr& s,
wxDfbCloneSurfaceMode mode) wxDfbCloneSurfaceMode mode)
{ {
if ( !s ) if ( !s )
return NULL; return NULL;
@@ -96,63 +96,56 @@ IDirectFBSurfacePtr wxDfbCloneSurface(const IDirectFBSurfacePtr& s,
DFBSurfaceDescription desc; DFBSurfaceDescription desc;
desc.flags = (DFBSurfaceDescriptionFlags)( desc.flags = (DFBSurfaceDescriptionFlags)(
DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT); DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
s->GetCapabilities(s, &desc.caps); s->GetCapabilities(&desc.caps);
s->GetSize(s, &desc.width, &desc.height); s->GetSize(&desc.width, &desc.height);
s->GetPixelFormat(s, &desc.pixelformat); s->GetPixelFormat(&desc.pixelformat);
IDirectFBPtr dfb(wxTheApp->GetDirectFBInterface()); wxIDirectFBSurfacePtr snew(wxIDirectFB::Get()->CreateSurface(&desc));
if ( !snew )
IDirectFBSurfacePtr snew;
if ( !DFB_CALL( dfb->CreateSurface(dfb, &desc, &snew) ) )
return NULL; return NULL;
IDirectFBPalettePtr pal; if ( desc.pixelformat == DSPF_LUT8 )
if ( s->GetPalette(s, &pal) == DFB_OK )
{ {
if ( !DFB_CALL( snew->SetPalette(snew, pal) ) ) wxIDirectFBPalettePtr pal(s->GetPalette());
return NULL; if ( s )
{
if ( !snew->SetPalette(pal) )
return NULL;
}
} }
if ( mode == wxDfbCloneSurface_CopyPixels ) if ( mode == wxDfbCloneSurface_CopyPixels )
{ {
if ( !DFB_CALL( snew->SetBlittingFlags(snew, DSBLIT_NOFX) ) ) if ( !snew->SetBlittingFlags(DSBLIT_NOFX) )
return NULL; return NULL;
if ( !DFB_CALL( snew->Blit(snew, s, NULL, 0, 0) ) ) if ( !snew->Blit(s, NULL, 0, 0) )
return NULL; return NULL;
} }
return snew; return snew;
} }
int wxDfbGetSurfaceDepth(const IDirectFBSurfacePtr& s) int wxDfbGetSurfaceDepth(const wxIDirectFBSurfacePtr& s)
{ {
wxCHECK_MSG( s, -1, _T("invalid surface") ); wxCHECK_MSG( s, -1, _T("invalid surface") );
DFBSurfacePixelFormat format = DSPF_UNKNOWN; DFBSurfacePixelFormat format = DSPF_UNKNOWN;
if ( !DFB_CALL( s->GetPixelFormat(s, &format) ) ) if ( !s->GetPixelFormat(&format) )
return -1; return -1;
return DFB_BITS_PER_PIXEL(format); return DFB_BITS_PER_PIXEL(format);
} }
IDirectFBDisplayLayerPtr wxDfbGetDisplayLayer() wxIDirectFBDisplayLayerPtr wxDfbGetDisplayLayer()
{ {
IDirectFBPtr dfb(wxTheApp->GetDirectFBInterface()); return wxIDirectFB::Get()->GetDisplayLayer(DLID_PRIMARY);
IDirectFBDisplayLayerPtr layer;
if ( !DFB_CALL( dfb->GetDisplayLayer(dfb, DLID_PRIMARY, &layer) ) )
return NULL;
return layer;
} }
IDirectFBSurfacePtr wxDfbGetPrimarySurface() wxIDirectFBSurfacePtr wxDfbGetPrimarySurface()
{ {
IDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer()); wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
IDirectFBSurfacePtr surface; return layer ? layer->GetSurface() : NULL;
DFB_CALL( layer->GetSurface(layer, &surface) );
return surface;
} }
@@ -162,8 +155,9 @@ IDirectFBSurfacePtr wxDfbGetPrimarySurface()
void wxGetMousePosition(int *x, int *y) void wxGetMousePosition(int *x, int *y)
{ {
IDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer()); wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
DFB_CALL( layer->GetCursorPosition(layer, x, y) ); if ( layer )
layer->GetCursorPosition(x, y);
} }
wxPoint wxGetMousePosition() wxPoint wxGetMousePosition()

View File

@@ -141,23 +141,21 @@ bool wxWindowDFB::Create(wxWindow *parent,
// surface access // surface access
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
IDirectFBSurfacePtr wxWindowDFB::ObtainDfbSurface() const wxIDirectFBSurfacePtr wxWindowDFB::ObtainDfbSurface() const
{ {
wxCHECK_MSG( m_parent, NULL, _T("parentless window?") ); wxCHECK_MSG( m_parent, NULL, _T("parentless window?") );
IDirectFBSurfacePtr parentSurface(m_parent->GetDfbSurface()); wxIDirectFBSurfacePtr parentSurface(m_parent->GetDfbSurface());
wxCHECK_MSG( parentSurface, NULL, _T("invalid parent surface") ); wxCHECK_MSG( parentSurface, NULL, _T("invalid parent surface") );
wxRect r(GetRect()); wxRect r(GetRect());
AdjustForParentClientOrigin(r.x, r.y, 0); AdjustForParentClientOrigin(r.x, r.y, 0);
DFBRectangle rect = { r.x, r.y, r.width, r.height }; DFBRectangle rect = { r.x, r.y, r.width, r.height };
IDirectFBSurfacePtr surface; return parentSurface->GetSubSurface(&rect);
DFB_CALL( parentSurface->GetSubSurface(parentSurface, &rect, &surface) );
return surface;
} }
IDirectFBSurfacePtr wxWindowDFB::GetDfbSurface() wxIDirectFBSurfacePtr wxWindowDFB::GetDfbSurface()
{ {
if ( !m_surface ) if ( !m_surface )
{ {
@@ -192,9 +190,9 @@ void wxWindowDFB::SetFocus()
#warning "FIXME: implement in terms of DWET_{GOT,LOST}FOCUS" #warning "FIXME: implement in terms of DWET_{GOT,LOST}FOCUS"
IDirectFBWindowPtr dfbwin(m_tlw->GetDirectFBWindow()); wxIDirectFBWindowPtr dfbwin(m_tlw->GetDirectFBWindow());
#warning "FIXME: RequestFocus() may only be called on visible TLW" #warning "FIXME: RequestFocus() may only be called on visible TLW"
if ( !DFB_CALL( dfbwin->RequestFocus(dfbwin) ) ) if ( !dfbwin->RequestFocus() )
return; return;
gs_focusedWindow = this; gs_focusedWindow = this;
@@ -368,10 +366,10 @@ void wxWindowDFB::WarpPointer(int x, int y)
if ( x >= w ) x = w-1; if ( x >= w ) x = w-1;
if ( y >= h ) y = h-1; if ( y >= h ) y = h-1;
IDirectFBDisplayLayerPtr layer = wxDfbGetDisplayLayer(); wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
wxCHECK_RET( layer, _T("no display layer") ); wxCHECK_RET( layer, _T("no display layer") );
layer->WarpCursor(layer, x, y); layer->WarpCursor(x, y);
} }
// Set this window to be the child of 'parent'. // Set this window to be the child of 'parent'.

97
src/dfb/wrapdfb.cpp Normal file
View File

@@ -0,0 +1,97 @@
/////////////////////////////////////////////////////////////////////////////
// Name: src/dfb/wrapdfb.cpp
// Purpose: wx wrappers for DirectFB interfaces
// Author: Vaclav Slavik
// Created: 2006-09-04
// RCS-ID: $Id$
// Copyright: (c) 2006 REA Elektronik GmbH
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/dfb/wrapdfb.h"
//-----------------------------------------------------------------------------
// wxDfbCheckReturn
//-----------------------------------------------------------------------------
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;
}
}
//-----------------------------------------------------------------------------
// wxDfbPtrBase
//-----------------------------------------------------------------------------
/* static */
void wxDfbPtrBase::DoAddRef(wxDfbWrapperBase *ptr)
{
ptr->AddRef();
}
void wxDfbPtrBase::DoRelease(wxDfbWrapperBase *ptr)
{
ptr->Release();
}
//-----------------------------------------------------------------------------
// wxIDirectFB
//-----------------------------------------------------------------------------
wxIDirectFBPtr wxIDirectFB::ms_ptr;
/* static */
void wxIDirectFB::CreateDirectFB()
{
IDirectFB *dfb;
if ( wxDfbCheckReturn(DirectFBCreate(&dfb)) )
ms_ptr = new wxIDirectFB(dfb);
}
/* static */
void wxIDirectFB::CleanUp()
{
ms_ptr.Reset();
}