1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/dfb/wrapdfb.cpp
3 // Purpose: wx wrappers for DirectFB interfaces
4 // Author: Vaclav Slavik
6 // Copyright: (c) 2006 REA Elektronik GmbH
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
22 #include "wx/dfb/wrapdfb.h"
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 bool wxDfbCheckReturn(DFBResult code
)
35 // these are programming errors, assert:
36 #define DFB_ASSERT(code) \
38 wxFAIL_MSG( "DirectFB error: " wxT(#code) ); \
42 DFB_ASSERT(DFB_UNSUPPORTED
);
43 DFB_ASSERT(DFB_UNIMPLEMENTED
);
44 DFB_ASSERT(DFB_INVARG
);
45 DFB_ASSERT(DFB_NOIMPL
);
46 DFB_ASSERT(DFB_MISSINGFONT
);
47 DFB_ASSERT(DFB_THIZNULL
);
48 DFB_ASSERT(DFB_INVAREA
);
49 DFB_ASSERT(DFB_DESTROYED
);
50 DFB_ASSERT(DFB_NOSUCHMETHOD
);
51 DFB_ASSERT(DFB_NOSUCHINSTANCE
);
52 DFB_ASSERT(DFB_VERSIONMISMATCH
);
56 // these are not errors, but valid return codes:
62 // FIXME: should handle the errors individually
63 wxLogError(_("DirectFB error %d occurred."), (int)code
);
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
73 void wxDfbPtrBase::DoAddRef(wxDfbWrapperBase
*ptr
)
78 void wxDfbPtrBase::DoRelease(wxDfbWrapperBase
*ptr
)
83 //-----------------------------------------------------------------------------
85 //-----------------------------------------------------------------------------
87 wxIDirectFBPtr
wxIDirectFB::ms_ptr
;
90 void wxIDirectFB::CreateDirectFB()
93 if ( wxDfbCheckReturn(DirectFBCreate(&dfb
)) )
94 ms_ptr
= new wxIDirectFB(dfb
);
98 void wxIDirectFB::CleanUp()
103 wxIDirectFBSurfacePtr
wxIDirectFB::GetPrimarySurface()
105 DFBSurfaceDescription desc
;
106 desc
.flags
= DSDESC_CAPS
;
107 // NB: see dcscreen.cpp for why we request double-buffered surface
109 // This assumes the cooperative level is DFSCL_NORMAL (that's the
110 // default and wx doesn't modify it anywhere); if we ever support
111 // other cooperative levels, DSCAPS_DOUBLE should *not* be used with
113 desc
.caps
= DFBSurfaceCapabilities(DSCAPS_PRIMARY
| DSCAPS_DOUBLE
);
114 return CreateSurface(&desc
);
117 //-----------------------------------------------------------------------------
118 // wxIDirectFBSurface
119 //-----------------------------------------------------------------------------
121 DFBSurfacePixelFormat
wxIDirectFBSurface::GetPixelFormat()
123 DFBSurfacePixelFormat format
= DSPF_UNKNOWN
;
124 GetPixelFormat(&format
);
128 int wxIDirectFBSurface::GetDepth()
130 DFBSurfacePixelFormat format
= DSPF_UNKNOWN
;
132 if ( !GetPixelFormat(&format
) )
135 return DFB_BITS_PER_PIXEL(format
);
138 wxIDirectFBSurfacePtr
139 wxIDirectFBSurface::CreateCompatible(const wxSize
& sz
, int flags
)
142 if ( size
== wxDefaultSize
)
144 if ( !GetSize(&size
.x
, &size
.y
) )
148 wxCHECK_MSG( size
.x
> 0 && size
.y
> 0, NULL
, "invalid size" );
150 DFBSurfaceDescription desc
;
151 desc
.flags
= (DFBSurfaceDescriptionFlags
)(
152 DSDESC_CAPS
| DSDESC_WIDTH
| DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
);
153 GetCapabilities(&desc
.caps
);
154 GetPixelFormat(&desc
.pixelformat
);
156 desc
.height
= size
.y
;
158 // filter out caps that don't make sense for a new compatible surface:
159 int caps
= desc
.caps
;
160 caps
&= ~DSCAPS_PRIMARY
;
161 caps
&= ~DSCAPS_SUBSURFACE
;
162 if ( flags
& CreateCompatible_NoBackBuffer
)
164 caps
&= ~DSCAPS_DOUBLE
;
165 caps
&= ~DSCAPS_TRIPLE
;
167 desc
.caps
= (DFBSurfaceCapabilities
)caps
;
169 wxIDirectFBSurfacePtr
snew(wxIDirectFB::Get()->CreateSurface(&desc
));
173 if ( desc
.pixelformat
== DSPF_LUT8
)
175 wxIDirectFBPalettePtr
pal(GetPalette());
178 if ( !snew
->SetPalette(pal
) )
186 wxIDirectFBSurfacePtr
wxIDirectFBSurface::Clone()
188 wxIDirectFBSurfacePtr
snew(CreateCompatible());
192 if ( !snew
->SetBlittingFlags(DSBLIT_NOFX
) )
195 if ( !snew
->Blit(GetRaw(), NULL
, 0, 0) )
201 bool wxIDirectFBSurface::Flip(const DFBRegion
*region
, int flags
)
203 return Check(m_ptr
->Flip(m_ptr
, region
, (DFBSurfaceFlipFlags
)flags
));
206 bool wxIDirectFBSurface::FlipToFront(const DFBRegion
*region
)
208 // Blit to the front buffer instead of exchanging front and back ones.
209 // Always doing this ensures that back and front buffer have same content
210 // and so painting to the back buffer will never lose any previous
212 return Flip(region
, DSFLIP_BLIT
);
215 //-----------------------------------------------------------------------------
216 // wxIDirectFBDisplayLayer
217 //-----------------------------------------------------------------------------
219 wxVideoMode
wxIDirectFBDisplayLayer::GetVideoMode()
221 DFBDisplayLayerConfig cfg
;
222 if ( !GetConfiguration(&cfg
) )
223 return wxVideoMode(); // invalid
225 if ( !((cfg
.flags
& DLCONF_WIDTH
) &&
226 (cfg
.flags
& DLCONF_HEIGHT
) &&
227 (cfg
.flags
& DLCONF_PIXELFORMAT
)) )
228 return wxVideoMode(); // invalid
234 DFB_BITS_PER_PIXEL(cfg
.pixelformat
)