]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/wrapdfb.cpp
Bring back double border
[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: \
a5001e93 39 wxFAIL_MSG( "DirectFB error: " _T(#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;
108 desc.caps = DSCAPS_PRIMARY;
109 return CreateSurface(&desc);
a5b31f4e
VS
110}
111
112//-----------------------------------------------------------------------------
113// wxIDirectFBSurface
114//-----------------------------------------------------------------------------
115
b39fc8d7
VS
116DFBSurfacePixelFormat wxIDirectFBSurface::GetPixelFormat()
117{
118 DFBSurfacePixelFormat format = DSPF_UNKNOWN;
119 GetPixelFormat(&format);
120 return format;
121}
122
a5b31f4e
VS
123int 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
7e2baeb4
VS
133wxIDirectFBSurfacePtr
134wxIDirectFBSurface::CreateCompatible(const wxSize& sz, int flags)
a5b31f4e
VS
135{
136 wxSize size(sz);
137 if ( size == wxDefaultSize )
138 {
139 if ( !GetSize(&size.x, &size.y) )
140 return NULL;
141 }
142
a5001e93 143 wxCHECK_MSG( size.x > 0 && size.y > 0, NULL, "invalid size" );
a5b31f4e
VS
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
7e2baeb4
VS
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
a5b31f4e
VS
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
181wxIDirectFBSurfacePtr 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}
20671963
VS
195
196bool wxIDirectFBSurface::Flip(const DFBRegion *region, int flags)
197{
198 return Check(m_ptr->Flip(m_ptr, region, (DFBSurfaceFlipFlags)flags));
199}
200
201bool 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}
fa28b00c
VS
209
210//-----------------------------------------------------------------------------
211// wxIDirectFBDisplayLayer
212//-----------------------------------------------------------------------------
213
214wxVideoMode 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}