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