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( _T("DirectFB error: ") _T(#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 occured."), (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 desc
.caps
= DSCAPS_PRIMARY
;
109 return CreateSurface(&desc
);
112 //-----------------------------------------------------------------------------
113 // wxIDirectFBSurface
114 //-----------------------------------------------------------------------------
116 DFBSurfacePixelFormat
wxIDirectFBSurface::GetPixelFormat()
118 DFBSurfacePixelFormat format
= DSPF_UNKNOWN
;
119 GetPixelFormat(&format
);
123 int wxIDirectFBSurface::GetDepth()
125 DFBSurfacePixelFormat format
= DSPF_UNKNOWN
;
127 if ( !GetPixelFormat(&format
) )
130 return DFB_BITS_PER_PIXEL(format
);
133 wxIDirectFBSurfacePtr
134 wxIDirectFBSurface::CreateCompatible(const wxSize
& sz
, int flags
)
137 if ( size
== wxDefaultSize
)
139 if ( !GetSize(&size
.x
, &size
.y
) )
143 wxCHECK_MSG( size
.x
> 0 && size
.y
> 0, NULL
, _T("invalid size") );
145 DFBSurfaceDescription desc
;
146 desc
.flags
= (DFBSurfaceDescriptionFlags
)(
147 DSDESC_CAPS
| DSDESC_WIDTH
| DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
);
148 GetCapabilities(&desc
.caps
);
149 GetPixelFormat(&desc
.pixelformat
);
151 desc
.height
= size
.y
;
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
)
159 caps
&= ~DSCAPS_DOUBLE
;
160 caps
&= ~DSCAPS_TRIPLE
;
162 desc
.caps
= (DFBSurfaceCapabilities
)caps
;
164 wxIDirectFBSurfacePtr
snew(wxIDirectFB::Get()->CreateSurface(&desc
));
168 if ( desc
.pixelformat
== DSPF_LUT8
)
170 wxIDirectFBPalettePtr
pal(GetPalette());
173 if ( !snew
->SetPalette(pal
) )
181 wxIDirectFBSurfacePtr
wxIDirectFBSurface::Clone()
183 wxIDirectFBSurfacePtr
snew(CreateCompatible());
187 if ( !snew
->SetBlittingFlags(DSBLIT_NOFX
) )
190 if ( !snew
->Blit(GetRaw(), NULL
, 0, 0) )
196 bool wxIDirectFBSurface::Flip(const DFBRegion
*region
, int flags
)
198 return Check(m_ptr
->Flip(m_ptr
, region
, (DFBSurfaceFlipFlags
)flags
));
201 bool wxIDirectFBSurface::FlipToFront(const DFBRegion
*region
)
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
207 return Flip(region
, DSFLIP_BLIT
);
210 //-----------------------------------------------------------------------------
211 // wxIDirectFBDisplayLayer
212 //-----------------------------------------------------------------------------
214 wxVideoMode
wxIDirectFBDisplayLayer::GetVideoMode()
216 DFBDisplayLayerConfig cfg
;
217 if ( !GetConfiguration(&cfg
) )
218 return wxVideoMode(); // invalid
220 if ( !((cfg
.flags
& DLCONF_WIDTH
) &&
221 (cfg
.flags
& DLCONF_HEIGHT
) &&
222 (cfg
.flags
& DLCONF_PIXELFORMAT
)) )
223 return wxVideoMode(); // invalid
229 DFB_BITS_PER_PIXEL(cfg
.pixelformat
)