initial (not yet working) code for DirectFB port
[wxWidgets.git] / include / wx / dfb / private.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/dfb/private.h
3 // Purpose: private helpers for wxDFB implementation
4 // Author: Vaclav Slavik
5 // Created: 2006-08-09
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_DFB_PRIVATE_H_
12 #define _WX_DFB_PRIVATE_H_
13
14 #include "wx/intl.h"
15 #include "wx/log.h"
16
17 #include <directfb.h>
18
19 #include "wx/dfb/ifacehelpers.h"
20
21 wxDFB_DECLARE_INTERFACE(IDirectFB);
22 wxDFB_DECLARE_INTERFACE(IDirectFBDisplayLayer);
23 wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
24 wxDFB_DECLARE_INTERFACE(IDirectFBPalette);
25
26 //-----------------------------------------------------------------------------
27 // strings conversion
28 //-----------------------------------------------------------------------------
29
30 // convert string from wxString to UTF-8 encoded const char*
31 #if wxUSE_UNICODE
32 #define wxSTR_TO_DFB(s) (s).mb_str(wxConvUTF8)
33 #else
34 #define wxSTR_TO_DFB(s) wxConvUTF8.cWC2MB((s).wc_str(*wxConvUI))
35 #endif
36
37 //-----------------------------------------------------------------------------
38 // error checking
39 //-----------------------------------------------------------------------------
40
41 inline bool wxDfbCheckReturn(DFBResult code)
42 {
43 switch ( code )
44 {
45 case DFB_OK:
46 return true;
47
48 // these are programming errors, assert:
49 #define DFB_ASSERT(code) \
50 case code: \
51 wxFAIL_MSG( _T("DirectFB error: ") _T(#code) ); \
52 return false \
53
54 DFB_ASSERT(DFB_DEAD);
55 DFB_ASSERT(DFB_UNSUPPORTED);
56 DFB_ASSERT(DFB_UNIMPLEMENTED);
57 DFB_ASSERT(DFB_INVARG);
58 DFB_ASSERT(DFB_NOIMPL);
59 DFB_ASSERT(DFB_MISSINGFONT);
60 DFB_ASSERT(DFB_THIZNULL);
61 DFB_ASSERT(DFB_INVAREA);
62 DFB_ASSERT(DFB_DESTROYED);
63 DFB_ASSERT(DFB_NOSUCHMETHOD);
64 DFB_ASSERT(DFB_NOSUCHINSTANCE);
65 DFB_ASSERT(DFB_VERSIONMISMATCH);
66
67 #undef DFB_ASSERT
68
69 // these are not errors, but valid return codes:
70 case DFB_INTERRUPTED:
71 case DFB_BUFFEREMPTY:
72 return true;
73
74 default:
75 // FIXME: should handle the errors individually
76 wxLogError(_("DirectFB error %d occured."), (int)code);
77 return false;
78 }
79 }
80
81 /**
82 Wrap all calls to DirectFB in this macro so that the return value is
83 checked and errors reported as appropriate.
84
85 Returns true if the call succeeded, false otherwise.
86 */
87 #define DFB_CALL(call) (wxDfbCheckReturn(call))
88
89
90 //-----------------------------------------------------------------------------
91 // surface manipulation helpers
92 //-----------------------------------------------------------------------------
93
94 /// Mode of wxDfbCloneSurface() call
95 enum wxDfbCloneSurfaceMode
96 {
97 /// Don't copy surface pixels, just clone surface size and attributes
98 wxDfbCloneSurface_NoPixels = 0,
99 /// Make exact copy, including the pixels
100 wxDfbCloneSurface_CopyPixels
101 };
102
103 /**
104 Creates a new surface by cloning existing one. Depending on @a mode,
105 either makes exact copy (wxDfbCloneSurface_CopyPixels) or only creates a
106 new surface with the same size and attributes (wxDfbCloneSurface_NoPixels).
107 */
108 IDirectFBSurfacePtr wxDfbCloneSurface(const IDirectFBSurfacePtr& s,
109 wxDfbCloneSurfaceMode mode);
110
111 /// Returns bit depth used by the surface
112 int wxDfbGetSurfaceDepth(const IDirectFBSurfacePtr& s);
113
114 /// Returns interface to the primary display layer:
115 IDirectFBDisplayLayerPtr wxDfbGetDisplayLayer();
116
117 /// Returns interface to the primary surface:
118 IDirectFBSurfacePtr wxDfbGetPrimarySurface();
119
120
121 //-----------------------------------------------------------------------------
122 // wxDfbEvent
123 //-----------------------------------------------------------------------------
124
125 /**
126 The struct defined by this macro is a thin wrapper around DFB*Event type.
127 It is needed because DFB*Event are typedefs and so we can't forward declare
128 them, but we need to pass them to methods declared in public headers where
129 <directfb.h> cannot be included. So this struct just holds the event value,
130 it's sole purpose is that it can be forward declared.
131 */
132 #define WXDFB_DEFINE_EVENT_WRAPPER(T) \
133 struct wx##T \
134 { \
135 wx##T() {} \
136 wx##T(const T& event) : m_event(event) {} \
137 \
138 operator T&() { return m_event; } \
139 operator const T&() const { return m_event; } \
140 T* operator&() { return &m_event; } \
141 \
142 DFBEventClass GetClass() const { return m_event.clazz; } \
143 \
144 private: \
145 T m_event; \
146 };
147
148 WXDFB_DEFINE_EVENT_WRAPPER(DFBEvent)
149 WXDFB_DEFINE_EVENT_WRAPPER(DFBWindowEvent)
150
151 /// Convert DirectFB timestamp to wxEvent one:
152 #define wxDFB_EVENT_TIMESTAMP(event) \
153 ((event).timestamp.tv_sec * 1000 + (event).timestamp.tv_usec / 1000)
154
155
156 #endif // _WX_DFB_PRIVATE_H_