// Purpose: wx wrappers for DirectFB interfaces
// Author: Vaclav Slavik
// Created: 2006-08-23
-// RCS-ID: $Id$
// Copyright: (c) 2006 REA Elektronik GmbH
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#define _WX_DFB_WRAPDFB_H_
#include "wx/dfb/dfbptr.h"
+#include "wx/gdicmn.h"
+#include "wx/vidmode.h"
#include <directfb.h>
+#include <directfb_version.h>
+
+// DFB < 1.0 didn't have u8 type, only __u8
+#if DIRECTFB_MAJOR_VERSION == 0
+typedef __u8 u8;
+#endif
+
wxDFB_DECLARE_INTERFACE(IDirectFB);
wxDFB_DECLARE_INTERFACE(IDirectFBDisplayLayer);
+wxDFB_DECLARE_INTERFACE(IDirectFBFont);
wxDFB_DECLARE_INTERFACE(IDirectFBWindow);
wxDFB_DECLARE_INTERFACE(IDirectFBSurface);
wxDFB_DECLARE_INTERFACE(IDirectFBPalette);
bool GetPixelFormat(DFBSurfacePixelFormat *caps)
{ return Check(m_ptr->GetPixelFormat(m_ptr, caps)); }
+ // convenience version of GetPixelFormat, returns DSPF_UNKNOWN if fails
+ DFBSurfacePixelFormat GetPixelFormat();
+
bool SetClip(const DFBRegion *clip)
{ return Check(m_ptr->SetClip(m_ptr, clip)); }
- bool SetColor(__u8 r, __u8 g, __u8 b, __u8 a)
+ bool SetColor(u8 r, u8 g, u8 b, u8 a)
{ return Check(m_ptr->SetColor(m_ptr, r, g, b, a)); }
- bool Clear(__u8 r, __u8 g, __u8 b, __u8 a)
+ bool Clear(u8 r, u8 g, u8 b, u8 a)
{ return Check(m_ptr->Clear(m_ptr, r, g, b, a)); }
bool DrawLine(int x1, int y1, int x2, int y2)
(DFBSurfaceTextFlags)flags));
}
- bool Flip(const DFBRegion *region, int flags)
- {
- return Check(m_ptr->Flip(m_ptr, region, (DFBSurfaceFlipFlags)flags));
- }
+ /**
+ Updates the front buffer from the back buffer. If @a region is not
+ NULL, only given rectangle is updated.
+ */
+ bool FlipToFront(const DFBRegion *region = NULL);
wxIDirectFBSurfacePtr GetSubSurface(const DFBRectangle *rect)
{
int x, int y)
{ return Check(m_ptr->Blit(m_ptr, source, source_rect, x, y)); }
+ bool StretchBlit(const wxIDirectFBSurfacePtr& source,
+ const DFBRectangle *source_rect,
+ const DFBRectangle *dest_rect)
+ {
+ return Check(m_ptr->StretchBlit(m_ptr, source->GetRaw(),
+ source_rect, dest_rect));
+ }
/// Returns bit depth used by the surface or -1 on error
int GetDepth();
*/
wxIDirectFBSurfacePtr Clone();
+ /// Flags for CreateCompatible()
+ enum CreateCompatibleFlags
+ {
+ /// Don't create double-buffered surface
+ CreateCompatible_NoBackBuffer = 1
+ };
+
/**
Creates a surface compatible with this one, i.e. surface with the same
capabilities and pixel format, but with different and size.
- @param size Size of the surface to create. If wxDefaultSize, use the
- size of this surface.
+ @param size Size of the surface to create. If wxDefaultSize, use the
+ size of this surface.
+ @param flags Or-combination of CreateCompatibleFlags values
*/
- wxIDirectFBSurfacePtr CreateCompatible(const wxSize& size = wxDefaultSize);
+ wxIDirectFBSurfacePtr CreateCompatible(const wxSize& size = wxDefaultSize,
+ int flags = 0);
+
+ bool Lock(DFBSurfaceLockFlags flags, void **ret_ptr, int *ret_pitch)
+ { return Check(m_ptr->Lock(m_ptr, flags, ret_ptr, ret_pitch)); }
+
+ bool Unlock()
+ { return Check(m_ptr->Unlock(m_ptr)); }
+
+ /// Helper struct for safe locking & unlocking of surfaces
+ struct Locked
+ {
+ Locked(const wxIDirectFBSurfacePtr& surface, DFBSurfaceLockFlags flags)
+ : m_surface(surface)
+ {
+ if ( !surface->Lock(flags, &ptr, &pitch) )
+ ptr = NULL;
+ }
+
+ ~Locked()
+ {
+ if ( ptr )
+ m_surface->Unlock();
+ }
+
+ void *ptr;
+ int pitch;
+
+ private:
+ wxIDirectFBSurfacePtr m_surface;
+ };
+
+
+private:
+ // this is private because we want user code to use FlipToFront()
+ bool Flip(const DFBRegion *region, int flags);
};
{
wxIDirectFBEventBuffer(IDirectFBEventBuffer *s) { Init(s); }
- bool WakeUp()
- {
- return Check(m_ptr->WakeUp(m_ptr));
- }
-
- bool HasEvent()
- {
- // returns DFB_OK if there is >=1 event, DFB_BUFFEREMPTY otherwise
- DFBResult r = m_ptr->HasEvent(m_ptr);
-
- // NB: Check() also returns true for DFB_BUFFEREMPTY, so we can't just
- // return it's return value:
- Check(r);
- return (r == DFB_OK);
- }
-
- bool WaitForEventWithTimeout(unsigned secs, unsigned millisecs)
+ bool CreateFileDescriptor(int *ret_fd)
{
- DFBResult r = m_ptr->WaitForEventWithTimeout(m_ptr, secs, millisecs);
-
- // DFB_TIMEOUT is not an error in this function:
- if ( r == DFB_TIMEOUT )
- {
- m_lastResult = DFB_TIMEOUT;
- return true;
- }
-
- return Check(r);
- }
-
- bool GetEvent(wxDFBEvent& event)
- {
- return Check(m_ptr->GetEvent(m_ptr, &event));
+ return Check(m_ptr->CreateFileDescriptor(m_ptr, ret_fd));
}
};
bool Resize(int w, int h)
{ return Check(m_ptr->Resize(m_ptr, w, h)); }
- bool SetOpacity(__u8 opacity)
+ bool SetOpacity(u8 opacity)
{ return Check(m_ptr->SetOpacity(m_ptr, opacity)); }
bool SetStackingClass(DFBWindowStackingClass klass)
{ return Check(m_ptr->SetStackingClass(m_ptr, klass)); }
+ bool RaiseToTop()
+ { return Check(m_ptr->RaiseToTop(m_ptr)); }
+
+ bool LowerToBottom()
+ { return Check(m_ptr->LowerToBottom(m_ptr)); }
+
wxIDirectFBSurfacePtr GetSurface()
{
IDirectFBSurface *s;
bool RequestFocus()
{ return Check(m_ptr->RequestFocus(m_ptr)); }
+
+ bool Destroy()
+ { return Check(m_ptr->Destroy(m_ptr)); }
};
return NULL;
}
- wxIDirectFBSurfacePtr GetSurface()
- {
- IDirectFBSurface *s;
- if ( Check(m_ptr->GetSurface(m_ptr, &s)) )
- return new wxIDirectFBSurface(s);
- else
- return NULL;
- }
+ bool GetConfiguration(DFBDisplayLayerConfig *config)
+ { return Check(m_ptr->GetConfiguration(m_ptr, config)); }
+
+ wxVideoMode GetVideoMode();
bool GetCursorPosition(int *x, int *y)
{ return Check(m_ptr->GetCursorPosition(m_ptr, x, y)); }