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