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"
18 #include "wx/dfb/wrapdfb.h"
20 //-----------------------------------------------------------------------------
22 //-----------------------------------------------------------------------------
24 bool wxDfbCheckReturn(DFBResult code
)
31 // these are programming errors, assert:
32 #define DFB_ASSERT(code) \
34 wxFAIL_MSG( _T("DirectFB error: ") _T(#code) ); \
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
);
52 // these are not errors, but valid return codes:
58 // FIXME: should handle the errors individually
59 wxLogError(_("DirectFB error %d occured."), (int)code
);
64 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
69 void wxDfbPtrBase::DoAddRef(wxDfbWrapperBase
*ptr
)
74 void wxDfbPtrBase::DoRelease(wxDfbWrapperBase
*ptr
)
79 //-----------------------------------------------------------------------------
81 //-----------------------------------------------------------------------------
83 wxIDirectFBPtr
wxIDirectFB::ms_ptr
;
86 void wxIDirectFB::CreateDirectFB()
89 if ( wxDfbCheckReturn(DirectFBCreate(&dfb
)) )
90 ms_ptr
= new wxIDirectFB(dfb
);
94 void wxIDirectFB::CleanUp()
99 wxIDirectFBSurfacePtr
wxIDirectFB::GetPrimarySurface()
101 wxIDirectFBDisplayLayerPtr
layer(GetDisplayLayer());
102 return layer
? layer
->GetSurface() : NULL
;
105 //-----------------------------------------------------------------------------
106 // wxIDirectFBSurface
107 //-----------------------------------------------------------------------------
109 int wxIDirectFBSurface::GetDepth()
111 DFBSurfacePixelFormat format
= DSPF_UNKNOWN
;
113 if ( !GetPixelFormat(&format
) )
116 return DFB_BITS_PER_PIXEL(format
);
119 wxIDirectFBSurfacePtr
120 wxIDirectFBSurface::CreateCompatible(const wxSize
& sz
, int flags
)
123 if ( size
== wxDefaultSize
)
125 if ( !GetSize(&size
.x
, &size
.y
) )
129 wxCHECK_MSG( size
.x
> 0 && size
.y
> 0, NULL
, _T("invalid size") );
131 DFBSurfaceDescription desc
;
132 desc
.flags
= (DFBSurfaceDescriptionFlags
)(
133 DSDESC_CAPS
| DSDESC_WIDTH
| DSDESC_HEIGHT
| DSDESC_PIXELFORMAT
);
134 GetCapabilities(&desc
.caps
);
135 GetPixelFormat(&desc
.pixelformat
);
137 desc
.height
= size
.y
;
139 // filter out caps that don't make sense for a new compatible surface:
140 int caps
= desc
.caps
;
141 caps
&= ~DSCAPS_PRIMARY
;
142 caps
&= ~DSCAPS_SUBSURFACE
;
143 if ( flags
& CreateCompatible_NoBackBuffer
)
145 caps
&= ~DSCAPS_DOUBLE
;
146 caps
&= ~DSCAPS_TRIPLE
;
148 desc
.caps
= (DFBSurfaceCapabilities
)caps
;
150 wxIDirectFBSurfacePtr
snew(wxIDirectFB::Get()->CreateSurface(&desc
));
154 if ( desc
.pixelformat
== DSPF_LUT8
)
156 wxIDirectFBPalettePtr
pal(GetPalette());
159 if ( !snew
->SetPalette(pal
) )
167 wxIDirectFBSurfacePtr
wxIDirectFBSurface::Clone()
169 wxIDirectFBSurfacePtr
snew(CreateCompatible());
173 if ( !snew
->SetBlittingFlags(DSBLIT_NOFX
) )
176 if ( !snew
->Blit(GetRaw(), NULL
, 0, 0) )
182 bool wxIDirectFBSurface::Flip(const DFBRegion
*region
, int flags
)
184 return Check(m_ptr
->Flip(m_ptr
, region
, (DFBSurfaceFlipFlags
)flags
));
187 bool wxIDirectFBSurface::FlipToFront(const DFBRegion
*region
)
189 // Blit to the front buffer instead of exchanging front and back ones.
190 // Always doing this ensures that back and front buffer have same content
191 // and so painting to the back buffer will never lose any previous
193 return Flip(region
, DSFLIP_BLIT
);