]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/wrapdfb.cpp
Always link with expat in monolithic build.
[wxWidgets.git] / src / dfb / wrapdfb.cpp
CommitLineData
52c8d32a
VS
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
23205be8
VS
18#ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/log.h"
21#endif
22
52c8d32a
VS
23#include "wx/dfb/wrapdfb.h"
24
25//-----------------------------------------------------------------------------
26// wxDfbCheckReturn
27//-----------------------------------------------------------------------------
28
29bool 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: \
9a83f860 39 wxFAIL_MSG( "DirectFB error: " wxT(#code) ); \
52c8d32a
VS
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 */
74void wxDfbPtrBase::DoAddRef(wxDfbWrapperBase *ptr)
75{
76 ptr->AddRef();
77}
78
79void wxDfbPtrBase::DoRelease(wxDfbWrapperBase *ptr)
80{
81 ptr->Release();
82}
83
84//-----------------------------------------------------------------------------
85// wxIDirectFB
86//-----------------------------------------------------------------------------
87
88wxIDirectFBPtr wxIDirectFB::ms_ptr;
89
90/* static */
91void wxIDirectFB::CreateDirectFB()
92{
93 IDirectFB *dfb;
94 if ( wxDfbCheckReturn(DirectFBCreate(&dfb)) )
95 ms_ptr = new wxIDirectFB(dfb);
96}
97
98/* static */
99void wxIDirectFB::CleanUp()
100{
101 ms_ptr.Reset();
102}
a5b31f4e
VS
103
104wxIDirectFBSurfacePtr wxIDirectFB::GetPrimarySurface()
105{
fa28b00c
VS
106 DFBSurfaceDescription desc;
107 desc.flags = DSDESC_CAPS;
f94d33c5
VS
108 // NB: see dcscreen.cpp for why we request double-buffered surface
109 //
110 // This assumes the cooperative level is DFSCL_NORMAL (that's the
111 // default and wx doesn't modify it anywhere); if we ever support
112 // other cooperative levels, DSCAPS_DOUBLE should *not* be used with
113 // them.
114 desc.caps = DFBSurfaceCapabilities(DSCAPS_PRIMARY | DSCAPS_DOUBLE);
fa28b00c 115 return CreateSurface(&desc);
a5b31f4e
VS
116}
117
118//-----------------------------------------------------------------------------
119// wxIDirectFBSurface
120//-----------------------------------------------------------------------------
121
b39fc8d7
VS
122DFBSurfacePixelFormat wxIDirectFBSurface::GetPixelFormat()
123{
124 DFBSurfacePixelFormat format = DSPF_UNKNOWN;
125 GetPixelFormat(&format);
126 return format;
127}
128
a5b31f4e
VS
129int wxIDirectFBSurface::GetDepth()
130{
131 DFBSurfacePixelFormat format = DSPF_UNKNOWN;
132
133 if ( !GetPixelFormat(&format) )
134 return -1;
135
136 return DFB_BITS_PER_PIXEL(format);
137}
138
7e2baeb4
VS
139wxIDirectFBSurfacePtr
140wxIDirectFBSurface::CreateCompatible(const wxSize& sz, int flags)
a5b31f4e
VS
141{
142 wxSize size(sz);
143 if ( size == wxDefaultSize )
144 {
145 if ( !GetSize(&size.x, &size.y) )
146 return NULL;
147 }
148
a5001e93 149 wxCHECK_MSG( size.x > 0 && size.y > 0, NULL, "invalid size" );
a5b31f4e
VS
150
151 DFBSurfaceDescription desc;
152 desc.flags = (DFBSurfaceDescriptionFlags)(
153 DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
154 GetCapabilities(&desc.caps);
155 GetPixelFormat(&desc.pixelformat);
156 desc.width = size.x;
157 desc.height = size.y;
158
7e2baeb4
VS
159 // filter out caps that don't make sense for a new compatible surface:
160 int caps = desc.caps;
161 caps &= ~DSCAPS_PRIMARY;
162 caps &= ~DSCAPS_SUBSURFACE;
163 if ( flags & CreateCompatible_NoBackBuffer )
164 {
165 caps &= ~DSCAPS_DOUBLE;
166 caps &= ~DSCAPS_TRIPLE;
167 }
168 desc.caps = (DFBSurfaceCapabilities)caps;
169
a5b31f4e
VS
170 wxIDirectFBSurfacePtr snew(wxIDirectFB::Get()->CreateSurface(&desc));
171 if ( !snew )
172 return NULL;
173
174 if ( desc.pixelformat == DSPF_LUT8 )
175 {
176 wxIDirectFBPalettePtr pal(GetPalette());
177 if ( pal )
178 {
179 if ( !snew->SetPalette(pal) )
180 return NULL;
181 }
182 }
183
184 return snew;
185}
186
187wxIDirectFBSurfacePtr wxIDirectFBSurface::Clone()
188{
189 wxIDirectFBSurfacePtr snew(CreateCompatible());
190 if ( !snew )
191 return NULL;
192
193 if ( !snew->SetBlittingFlags(DSBLIT_NOFX) )
194 return NULL;
195
196 if ( !snew->Blit(GetRaw(), NULL, 0, 0) )
197 return NULL;
198
199 return snew;
200}
20671963
VS
201
202bool wxIDirectFBSurface::Flip(const DFBRegion *region, int flags)
203{
204 return Check(m_ptr->Flip(m_ptr, region, (DFBSurfaceFlipFlags)flags));
205}
206
207bool wxIDirectFBSurface::FlipToFront(const DFBRegion *region)
208{
209 // Blit to the front buffer instead of exchanging front and back ones.
210 // Always doing this ensures that back and front buffer have same content
211 // and so painting to the back buffer will never lose any previous
212 // drawings:
213 return Flip(region, DSFLIP_BLIT);
214}
fa28b00c
VS
215
216//-----------------------------------------------------------------------------
217// wxIDirectFBDisplayLayer
218//-----------------------------------------------------------------------------
219
220wxVideoMode wxIDirectFBDisplayLayer::GetVideoMode()
221{
222 DFBDisplayLayerConfig cfg;
223 if ( !GetConfiguration(&cfg) )
224 return wxVideoMode(); // invalid
225
226 if ( !((cfg.flags & DLCONF_WIDTH) &&
227 (cfg.flags & DLCONF_HEIGHT) &&
228 (cfg.flags & DLCONF_PIXELFORMAT)) )
229 return wxVideoMode(); // invalid
230
231 return wxVideoMode
232 (
233 cfg.width,
234 cfg.height,
235 DFB_BITS_PER_PIXEL(cfg.pixelformat)
236 );
237}