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 int wxIDirectFBSurface::GetDepth()
118 DFBSurfacePixelFormat format
= DSPF_UNKNOWN
;
120 if ( !GetPixelFormat(&format
) )
123 return DFB_BITS_PER_PIXEL(format
);
126 wxIDirectFBSurfacePtr
127 wxIDirectFBSurface::CreateCompatible(const wxSize
& sz
, int flags
)
130 if ( size
== wxDefaultSize
)
132 if ( !GetSize(&size
.x
, &size
.y
) )
136 wxCHECK_MSG( size
.x
> 0 && size
.y
> 0, NULL
, _T("invalid size") );
138 DFBSurfaceDescription desc
;
139 desc
.flags
= (DFBSurfaceDescriptionFlags
)(
140 DSDESC_CAPS
| DSDESC_WIDTH
| DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
);
141 GetCapabilities(&desc
.caps
);
142 GetPixelFormat(&desc
.pixelformat
);
144 desc
.height
= size
.y
;
146 // filter out caps that don't make sense for a new compatible surface:
147 int caps
= desc
.caps
;
148 caps
&= ~DSCAPS_PRIMARY
;
149 caps
&= ~DSCAPS_SUBSURFACE
;
150 if ( flags
& CreateCompatible_NoBackBuffer
)
152 caps
&= ~DSCAPS_DOUBLE
;
153 caps
&= ~DSCAPS_TRIPLE
;
155 desc
.caps
= (DFBSurfaceCapabilities
)caps
;
157 wxIDirectFBSurfacePtr
snew(wxIDirectFB::Get()->CreateSurface(&desc
));
161 if ( desc
.pixelformat
== DSPF_LUT8
)
163 wxIDirectFBPalettePtr
pal(GetPalette());
166 if ( !snew
->SetPalette(pal
) )
174 wxIDirectFBSurfacePtr
wxIDirectFBSurface::Clone()
176 wxIDirectFBSurfacePtr
snew(CreateCompatible());
180 if ( !snew
->SetBlittingFlags(DSBLIT_NOFX
) )
183 if ( !snew
->Blit(GetRaw(), NULL
, 0, 0) )
189 bool wxIDirectFBSurface::Flip(const DFBRegion
*region
, int flags
)
191 return Check(m_ptr
->Flip(m_ptr
, region
, (DFBSurfaceFlipFlags
)flags
));
194 bool wxIDirectFBSurface::FlipToFront(const DFBRegion
*region
)
196 // Blit to the front buffer instead of exchanging front and back ones.
197 // Always doing this ensures that back and front buffer have same content
198 // and so painting to the back buffer will never lose any previous
200 return Flip(region
, DSFLIP_BLIT
);
203 //-----------------------------------------------------------------------------
204 // wxIDirectFBDisplayLayer
205 //-----------------------------------------------------------------------------
207 wxVideoMode
wxIDirectFBDisplayLayer::GetVideoMode()
209 DFBDisplayLayerConfig cfg
;
210 if ( !GetConfiguration(&cfg
) )
211 return wxVideoMode(); // invalid
213 if ( !((cfg
.flags
& DLCONF_WIDTH
) &&
214 (cfg
.flags
& DLCONF_HEIGHT
) &&
215 (cfg
.flags
& DLCONF_PIXELFORMAT
)) )
216 return wxVideoMode(); // invalid
222 DFB_BITS_PER_PIXEL(cfg
.pixelformat
)