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