1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/wrapdfb.cpp
3 // Purpose: wx wrappers for DirectFB interfaces
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2006 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
23 #include "wx/dfb/wrapdfb.h"
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 bool wxDfbCheckReturn(DFBResult code
)
36 // these are programming errors, assert:
37 #define DFB_ASSERT(code) \
39 wxFAIL_MSG( "DirectFB error: " wxT(#code) ); \
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
);
57 // these are not errors, but valid return codes:
63 // FIXME: should handle the errors individually
64 wxLogError(_("DirectFB error %d occurred."), (int)code
);
69 //-----------------------------------------------------------------------------
71 //-----------------------------------------------------------------------------
74 void wxDfbPtrBase::DoAddRef(wxDfbWrapperBase
*ptr
)
79 void wxDfbPtrBase::DoRelease(wxDfbWrapperBase
*ptr
)
84 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
88 wxIDirectFBPtr
wxIDirectFB::ms_ptr
;
91 void wxIDirectFB::CreateDirectFB()
94 if ( wxDfbCheckReturn(DirectFBCreate(&dfb
)) )
95 ms_ptr
= new wxIDirectFB(dfb
);
99 void wxIDirectFB::CleanUp()
104 wxIDirectFBSurfacePtr
wxIDirectFB::GetPrimarySurface()
106 DFBSurfaceDescription desc
;
107 desc
.flags
= DSDESC_CAPS
;
108 // NB: see dcscreen.cpp for why we request double-buffered surface
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
114 desc
.caps
= DFBSurfaceCapabilities(DSCAPS_PRIMARY
| DSCAPS_DOUBLE
);
115 return CreateSurface(&desc
);
118 //-----------------------------------------------------------------------------
119 // wxIDirectFBSurface
120 //-----------------------------------------------------------------------------
122 DFBSurfacePixelFormat
wxIDirectFBSurface::GetPixelFormat()
124 DFBSurfacePixelFormat format
= DSPF_UNKNOWN
;
125 GetPixelFormat(&format
);
129 int wxIDirectFBSurface::GetDepth()
131 DFBSurfacePixelFormat format
= DSPF_UNKNOWN
;
133 if ( !GetPixelFormat(&format
) )
136 return DFB_BITS_PER_PIXEL(format
);
139 wxIDirectFBSurfacePtr
140 wxIDirectFBSurface::CreateCompatible(const wxSize
& sz
, int flags
)
143 if ( size
== wxDefaultSize
)
145 if ( !GetSize(&size
.x
, &size
.y
) )
149 wxCHECK_MSG( size
.x
> 0 && size
.y
> 0, NULL
, "invalid size" );
151 DFBSurfaceDescription desc
;
152 desc
.flags
= (DFBSurfaceDescriptionFlags
)(
153 DSDESC_CAPS
| DSDESC_WIDTH
| DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
);
154 GetCapabilities(&desc
.caps
);
155 GetPixelFormat(&desc
.pixelformat
);
157 desc
.height
= size
.y
;
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
)
165 caps
&= ~DSCAPS_DOUBLE
;
166 caps
&= ~DSCAPS_TRIPLE
;
168 desc
.caps
= (DFBSurfaceCapabilities
)caps
;
170 wxIDirectFBSurfacePtr
snew(wxIDirectFB::Get()->CreateSurface(&desc
));
174 if ( desc
.pixelformat
== DSPF_LUT8
)
176 wxIDirectFBPalettePtr
pal(GetPalette());
179 if ( !snew
->SetPalette(pal
) )
187 wxIDirectFBSurfacePtr
wxIDirectFBSurface::Clone()
189 wxIDirectFBSurfacePtr
snew(CreateCompatible());
193 if ( !snew
->SetBlittingFlags(DSBLIT_NOFX
) )
196 if ( !snew
->Blit(GetRaw(), NULL
, 0, 0) )
202 bool wxIDirectFBSurface::Flip(const DFBRegion
*region
, int flags
)
204 return Check(m_ptr
->Flip(m_ptr
, region
, (DFBSurfaceFlipFlags
)flags
));
207 bool wxIDirectFBSurface::FlipToFront(const DFBRegion
*region
)
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
213 return Flip(region
, DSFLIP_BLIT
);
216 //-----------------------------------------------------------------------------
217 // wxIDirectFBDisplayLayer
218 //-----------------------------------------------------------------------------
220 wxVideoMode
wxIDirectFBDisplayLayer::GetVideoMode()
222 DFBDisplayLayerConfig cfg
;
223 if ( !GetConfiguration(&cfg
) )
224 return wxVideoMode(); // invalid
226 if ( !((cfg
.flags
& DLCONF_WIDTH
) &&
227 (cfg
.flags
& DLCONF_HEIGHT
) &&
228 (cfg
.flags
& DLCONF_PIXELFORMAT
)) )
229 return wxVideoMode(); // invalid
235 DFB_BITS_PER_PIXEL(cfg
.pixelformat
)