]> git.saurik.com Git - wxWidgets.git/blob - src/dfb/wrapdfb.cpp
forward port from 2.8
[wxWidgets.git] / src / dfb / wrapdfb.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/wrapdfb.cpp
3 // Purpose: wx wrappers for DirectFB interfaces
4 // Author: Vaclav Slavik
5 // Created: 2006-09-04
6 // RCS-ID: $Id$
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/log.h"
21 #endif
22
23 #include "wx/dfb/wrapdfb.h"
24
25 //-----------------------------------------------------------------------------
26 // wxDfbCheckReturn
27 //-----------------------------------------------------------------------------
28
29 bool wxDfbCheckReturn(DFBResult code)
30 {
31 switch ( code )
32 {
33 case DFB_OK:
34 return true;
35
36 // these are programming errors, assert:
37 #define DFB_ASSERT(code) \
38 case code: \
39 wxFAIL_MSG( "DirectFB error: " _T(#code) ); \
40 return false \
41
42 DFB_ASSERT(DFB_DEAD);
43 DFB_ASSERT(DFB_UNSUPPORTED);
44 DFB_ASSERT(DFB_UNIMPLEMENTED);
45 DFB_ASSERT(DFB_INVARG);
46 DFB_ASSERT(DFB_NOIMPL);
47 DFB_ASSERT(DFB_MISSINGFONT);
48 DFB_ASSERT(DFB_THIZNULL);
49 DFB_ASSERT(DFB_INVAREA);
50 DFB_ASSERT(DFB_DESTROYED);
51 DFB_ASSERT(DFB_NOSUCHMETHOD);
52 DFB_ASSERT(DFB_NOSUCHINSTANCE);
53 DFB_ASSERT(DFB_VERSIONMISMATCH);
54
55 #undef DFB_ASSERT
56
57 // these are not errors, but valid return codes:
58 case DFB_INTERRUPTED:
59 case DFB_BUFFEREMPTY:
60 return true;
61
62 default:
63 // FIXME: should handle the errors individually
64 wxLogError(_("DirectFB error %d occured."), (int)code);
65 return false;
66 }
67 }
68
69 //-----------------------------------------------------------------------------
70 // wxDfbPtrBase
71 //-----------------------------------------------------------------------------
72
73 /* static */
74 void wxDfbPtrBase::DoAddRef(wxDfbWrapperBase *ptr)
75 {
76 ptr->AddRef();
77 }
78
79 void wxDfbPtrBase::DoRelease(wxDfbWrapperBase *ptr)
80 {
81 ptr->Release();
82 }
83
84 //-----------------------------------------------------------------------------
85 // wxIDirectFB
86 //-----------------------------------------------------------------------------
87
88 wxIDirectFBPtr wxIDirectFB::ms_ptr;
89
90 /* static */
91 void wxIDirectFB::CreateDirectFB()
92 {
93 IDirectFB *dfb;
94 if ( wxDfbCheckReturn(DirectFBCreate(&dfb)) )
95 ms_ptr = new wxIDirectFB(dfb);
96 }
97
98 /* static */
99 void wxIDirectFB::CleanUp()
100 {
101 ms_ptr.Reset();
102 }
103
104 wxIDirectFBSurfacePtr wxIDirectFB::GetPrimarySurface()
105 {
106 DFBSurfaceDescription desc;
107 desc.flags = DSDESC_CAPS;
108 desc.caps = DSCAPS_PRIMARY;
109 return CreateSurface(&desc);
110 }
111
112 //-----------------------------------------------------------------------------
113 // wxIDirectFBSurface
114 //-----------------------------------------------------------------------------
115
116 DFBSurfacePixelFormat wxIDirectFBSurface::GetPixelFormat()
117 {
118 DFBSurfacePixelFormat format = DSPF_UNKNOWN;
119 GetPixelFormat(&format);
120 return format;
121 }
122
123 int wxIDirectFBSurface::GetDepth()
124 {
125 DFBSurfacePixelFormat format = DSPF_UNKNOWN;
126
127 if ( !GetPixelFormat(&format) )
128 return -1;
129
130 return DFB_BITS_PER_PIXEL(format);
131 }
132
133 wxIDirectFBSurfacePtr
134 wxIDirectFBSurface::CreateCompatible(const wxSize& sz, int flags)
135 {
136 wxSize size(sz);
137 if ( size == wxDefaultSize )
138 {
139 if ( !GetSize(&size.x, &size.y) )
140 return NULL;
141 }
142
143 wxCHECK_MSG( size.x > 0 && size.y > 0, NULL, "invalid size" );
144
145 DFBSurfaceDescription desc;
146 desc.flags = (DFBSurfaceDescriptionFlags)(
147 DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
148 GetCapabilities(&desc.caps);
149 GetPixelFormat(&desc.pixelformat);
150 desc.width = size.x;
151 desc.height = size.y;
152
153 // filter out caps that don't make sense for a new compatible surface:
154 int caps = desc.caps;
155 caps &= ~DSCAPS_PRIMARY;
156 caps &= ~DSCAPS_SUBSURFACE;
157 if ( flags & CreateCompatible_NoBackBuffer )
158 {
159 caps &= ~DSCAPS_DOUBLE;
160 caps &= ~DSCAPS_TRIPLE;
161 }
162 desc.caps = (DFBSurfaceCapabilities)caps;
163
164 wxIDirectFBSurfacePtr snew(wxIDirectFB::Get()->CreateSurface(&desc));
165 if ( !snew )
166 return NULL;
167
168 if ( desc.pixelformat == DSPF_LUT8 )
169 {
170 wxIDirectFBPalettePtr pal(GetPalette());
171 if ( pal )
172 {
173 if ( !snew->SetPalette(pal) )
174 return NULL;
175 }
176 }
177
178 return snew;
179 }
180
181 wxIDirectFBSurfacePtr wxIDirectFBSurface::Clone()
182 {
183 wxIDirectFBSurfacePtr snew(CreateCompatible());
184 if ( !snew )
185 return NULL;
186
187 if ( !snew->SetBlittingFlags(DSBLIT_NOFX) )
188 return NULL;
189
190 if ( !snew->Blit(GetRaw(), NULL, 0, 0) )
191 return NULL;
192
193 return snew;
194 }
195
196 bool wxIDirectFBSurface::Flip(const DFBRegion *region, int flags)
197 {
198 return Check(m_ptr->Flip(m_ptr, region, (DFBSurfaceFlipFlags)flags));
199 }
200
201 bool wxIDirectFBSurface::FlipToFront(const DFBRegion *region)
202 {
203 // Blit to the front buffer instead of exchanging front and back ones.
204 // Always doing this ensures that back and front buffer have same content
205 // and so painting to the back buffer will never lose any previous
206 // drawings:
207 return Flip(region, DSFLIP_BLIT);
208 }
209
210 //-----------------------------------------------------------------------------
211 // wxIDirectFBDisplayLayer
212 //-----------------------------------------------------------------------------
213
214 wxVideoMode wxIDirectFBDisplayLayer::GetVideoMode()
215 {
216 DFBDisplayLayerConfig cfg;
217 if ( !GetConfiguration(&cfg) )
218 return wxVideoMode(); // invalid
219
220 if ( !((cfg.flags & DLCONF_WIDTH) &&
221 (cfg.flags & DLCONF_HEIGHT) &&
222 (cfg.flags & DLCONF_PIXELFORMAT)) )
223 return wxVideoMode(); // invalid
224
225 return wxVideoMode
226 (
227 cfg.width,
228 cfg.height,
229 DFB_BITS_PER_PIXEL(cfg.pixelformat)
230 );
231 }