]> git.saurik.com Git - wxWidgets.git/commitdiff
move misc surface helpers to wxIDirectFBSurface class
authorVáclav Slavík <vslavik@fastmail.fm>
Mon, 11 Sep 2006 09:08:57 +0000 (09:08 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Mon, 11 Sep 2006 09:08:57 +0000 (09:08 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41154 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dfb/private.h
include/wx/dfb/wrapdfb.h
src/dfb/app.cpp
src/dfb/bitmap.cpp
src/dfb/dc.cpp
src/dfb/dcclient.cpp
src/dfb/dcscreen.cpp
src/dfb/toplevel.cpp
src/dfb/utils.cpp
src/dfb/window.cpp
src/dfb/wrapdfb.cpp

index 8e005dace13c92ef4c3409ccdd672f9b4c46015e..9a36a5ea5e4b4170910b8d36f4e8a529ae2a1ccc 100644 (file)
     #define wxSTR_TO_DFB(s)    wxConvUTF8.cWC2MB((s).wc_str(*wxConvUI))
 #endif
 
     #define wxSTR_TO_DFB(s)    wxConvUTF8.cWC2MB((s).wc_str(*wxConvUI))
 #endif
 
-//-----------------------------------------------------------------------------
-// surface manipulation helpers
-//-----------------------------------------------------------------------------
-
-/// Mode of wxDfbCloneSurface() call
-enum wxDfbCloneSurfaceMode
-{
-    /// Don't copy surface pixels, just clone surface size and attributes
-    wxDfbCloneSurface_NoPixels = 0,
-    /// Make exact copy, including the pixels
-    wxDfbCloneSurface_CopyPixels
-};
-
-/**
-    Creates surface that is compatible with given @a surface (i.e. has same
-    capabilities, pixel format etc.) and has given @a size.
- */
-wxIDirectFBSurfacePtr wxDfbCreateCompatibleSurface(
-                                    const wxIDirectFBSurfacePtr& surface,
-                                    const wxSize& size);
-
-/**
-    Creates a new surface by cloning existing one. Depending on @a mode,
-    either makes exact copy (wxDfbCloneSurface_CopyPixels) or only creates a
-    new surface with the same size and attributes (wxDfbCloneSurface_NoPixels).
- */
-wxIDirectFBSurfacePtr wxDfbCloneSurface(const wxIDirectFBSurfacePtr& s,
-                                        wxDfbCloneSurfaceMode mode);
-
-/// Returns bit depth used by the surface
-int wxDfbGetSurfaceDepth(const wxIDirectFBSurfacePtr& s);
-
-/// Returns interface to the primary display layer:
-wxIDirectFBDisplayLayerPtr wxDfbGetDisplayLayer();
-
-/// Returns interface to the primary surface:
-wxIDirectFBSurfacePtr wxDfbGetPrimarySurface();
-
 //-----------------------------------------------------------------------------
 // misc helpers
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // misc helpers
 //-----------------------------------------------------------------------------
index 970c6ebf96d9fe82f461639778e49f6a3b8cc4d2..30ef307513db7d45897e677647dde92905e5d789 100644 (file)
@@ -266,10 +266,33 @@ struct wxIDirectFBSurface : public wxDfbWrapper<IDirectFBSurface>
     bool Blit(const wxIDirectFBSurfacePtr& source,
               const DFBRectangle *source_rect,
               int x, int y)
     bool Blit(const wxIDirectFBSurfacePtr& source,
               const DFBRectangle *source_rect,
               int x, int y)
-    {
-        return Check(
-                m_ptr->Blit(m_ptr, source->GetRaw(), source_rect, x, y));
-    }
+        { return Blit(source->GetRaw(), source_rect, x, y); }
+
+    bool Blit(IDirectFBSurface *source,
+              const DFBRectangle *source_rect,
+              int x, int y)
+        { return Check(m_ptr->Blit(m_ptr, source, source_rect, x, y)); }
+
+
+    /// Returns bit depth used by the surface or -1 on error
+    int GetDepth();
+
+    /**
+        Creates a new surface by cloning this one. New surface will have same
+        capabilities, pixel format and pixel data as the existing one.
+
+        @see CreateCompatible
+     */
+    wxIDirectFBSurfacePtr Clone();
+
+    /**
+        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.
+     */
+    wxIDirectFBSurfacePtr CreateCompatible(const wxSize& size = wxDefaultSize);
 };
 
 
 };
 
 
@@ -446,7 +469,8 @@ struct wxIDirectFB : public wxDfbWrapper<IDirectFB>
             return NULL;
     }
 
             return NULL;
     }
 
-    wxIDirectFBDisplayLayerPtr GetDisplayLayer(DFBDisplayLayerID id)
+    wxIDirectFBDisplayLayerPtr
+    GetDisplayLayer(DFBDisplayLayerID id = DLID_PRIMARY)
     {
         IDirectFBDisplayLayer *l;
         if ( Check(m_ptr->GetDisplayLayer(m_ptr, id, &l)) )
     {
         IDirectFBDisplayLayer *l;
         if ( Check(m_ptr->GetDisplayLayer(m_ptr, id, &l)) )
@@ -455,6 +479,9 @@ struct wxIDirectFB : public wxDfbWrapper<IDirectFB>
             return NULL;
     }
 
             return NULL;
     }
 
+    /// Returns primary surface
+    wxIDirectFBSurfacePtr GetPrimarySurface();
+
 private:
     wxIDirectFB(IDirectFB *ptr) { Init(ptr); }
 
 private:
     wxIDirectFB(IDirectFB *ptr) { Init(ptr); }
 
index 65d2be4478e8e6e398bc3f52c6c16694656d93ab..4618b16e4b9789412dd32174fcd697a77fad4657 100644 (file)
@@ -71,12 +71,12 @@ static wxVideoMode GetCurrentVideoMode()
 {
     wxVideoMode m;
 
 {
     wxVideoMode m;
 
-    wxIDirectFBSurfacePtr surface(wxDfbGetPrimarySurface());
+    wxIDirectFBSurfacePtr surface(wxIDirectFB::Get()->GetPrimarySurface());
     if ( !surface )
         return m; // invalid
 
     surface->GetSize(&m.w, &m.h);
     if ( !surface )
         return m; // invalid
 
     surface->GetSize(&m.w, &m.h);
-    m.bpp = wxDfbGetSurfaceDepth(surface);
+    m.bpp = surface->GetDepth();
 
     return m;
 }
 
     return m;
 }
index dbb25257a504630ed9ea6214d4631a06d258a0d1..8ba352f12b0f45c12dec9e9d4bada2c4845ea024 100644 (file)
@@ -158,8 +158,9 @@ public:
 
     wxBitmapRefData(const wxBitmapRefData& data)
     {
 
     wxBitmapRefData(const wxBitmapRefData& data)
     {
-        m_surface = wxDfbCloneSurface(data.m_surface,
-                                      wxDfbCloneSurface_NoPixels);
+        if ( data.m_surface )
+            m_surface = data.m_surface->Clone();
+
         m_mask = data.m_mask ? new wxMask(*data.m_mask) : NULL;
 #if wxUSE_PALETTE
         m_palette = data.m_palette ? new wxPalette(*data.m_palette) : NULL;
         m_mask = data.m_mask ? new wxMask(*data.m_mask) : NULL;
 #if wxUSE_PALETTE
         m_palette = data.m_palette ? new wxPalette(*data.m_palette) : NULL;
@@ -294,7 +295,7 @@ int wxBitmap::GetDepth() const
 {
     wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
 
 {
     wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
 
-    return wxDfbGetSurfaceDepth(M_BITMAP->m_surface);
+    return M_BITMAP->m_surface->GetDepth();
 }
 
 wxMask *wxBitmap::GetMask() const
 }
 
 wxMask *wxBitmap::GetMask() const
index a02dd8f7a1fd40aca367be9c94bd0103462cc624..752291010e1073b02f901ae06447eb80b37e5936 100644 (file)
@@ -130,7 +130,7 @@ void wxDC::DestroyClippingRegion()
 
 int wxDC::GetDepth() const
 {
 
 int wxDC::GetDepth() const
 {
-    return wxDfbGetSurfaceDepth(m_surface);
+    return m_surface->GetDepth();
 }
 
 // ---------------------------------------------------------------------------
 }
 
 // ---------------------------------------------------------------------------
index 17940083ea629be46881aa8fcff909caf5971e3f..c51e6a509e39c347cb32f3f8d7779ccd7d4a26b4 100644 (file)
@@ -65,7 +65,7 @@ void wxWindowDC::InitForWin(wxWindow *win, const wxRect *rect)
         // so let's create a dummy surface that has the same format as the real
         // one would have and let the code paint on it:
         wxSize size(rect ? rect->GetSize() : win->GetSize());
         // so let's create a dummy surface that has the same format as the real
         // one would have and let the code paint on it:
         wxSize size(rect ? rect->GetSize() : win->GetSize());
-        surface = wxDfbCreateCompatibleSurface(win->GetDfbSurface(), size);
+        surface = win->GetDfbSurface()->CreateCompatible(size);
     }
     else if ( !rect )
     {
     }
     else if ( !rect )
     {
index f1218a936cab6294a3693dfa32d615253de4fb99..4d9ba71e76cecfc08babf676500b30d1d7602d7a 100644 (file)
@@ -38,7 +38,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxDC)
 
 wxScreenDC::wxScreenDC()
 {
 
 wxScreenDC::wxScreenDC()
 {
-    Init(wxDfbGetPrimarySurface());
+    Init(wxIDirectFB::Get()->GetPrimarySurface());
 }
 
 #warning "FIXME: does wxScreenDC need Flip call in dtor?"
 }
 
 #warning "FIXME: does wxScreenDC need Flip call in dtor?"
index ffa3dcaaaca4a0f1c17ca1f8d98447895d625039..41b05ce9b1a74273aa0ec8d5c72c339701c99bfa 100644 (file)
@@ -122,7 +122,7 @@ bool wxTopLevelWindowDFB::Create(wxWindow *parent,
         pos.y = 0;
 
     // create DirectFB window:
         pos.y = 0;
 
     // create DirectFB window:
-    wxIDirectFBDisplayLayerPtr layer = wxDfbGetDisplayLayer();
+    wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
     wxCHECK_MSG( layer, false, _T("no display layer") );
 
     DFBWindowDescription desc;
     wxCHECK_MSG( layer, false, _T("no display layer") );
 
     DFBWindowDescription desc;
index 2f1e7da32ea35d3fc26b9be2d605f70148b6b6d8..87700dbbb979cb830f408e6d4a196d0d9d679c20 100644 (file)
@@ -83,90 +83,6 @@ void wxClientDisplayRect(int *x, int *y, int *width, int *height)
     wxDisplaySize(width, height);
 }
 
     wxDisplaySize(width, height);
 }
 
-//-----------------------------------------------------------------------------
-// surface manipulation helpers
-//-----------------------------------------------------------------------------
-
-wxIDirectFBSurfacePtr wxDfbCreateCompatibleSurface(
-                                    const wxIDirectFBSurfacePtr& s,
-                                    const wxSize& size)
-{
-    if ( !s )
-        return NULL;
-
-    DFBSurfaceDescription desc;
-    desc.flags = (DFBSurfaceDescriptionFlags)(
-            DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
-    s->GetCapabilities(&desc.caps);
-    s->GetPixelFormat(&desc.pixelformat);
-    desc.width = size.x;
-    desc.height = size.y;
-
-    wxIDirectFBSurfacePtr snew(wxIDirectFB::Get()->CreateSurface(&desc));
-    if ( !snew )
-        return NULL;
-
-    if ( desc.pixelformat == DSPF_LUT8 )
-    {
-        wxIDirectFBPalettePtr pal(s->GetPalette());
-        if ( s )
-        {
-            if ( !snew->SetPalette(pal) )
-                return NULL;
-        }
-    }
-
-    return snew;
-}
-
-wxIDirectFBSurfacePtr wxDfbCloneSurface(const wxIDirectFBSurfacePtr& s,
-                                        wxDfbCloneSurfaceMode mode)
-{
-    if ( !s )
-        return NULL;
-
-    wxSize size;
-    if ( !s->GetSize(&size.x, &size.y) )
-        return NULL;
-
-    wxIDirectFBSurfacePtr snew(wxDfbCreateCompatibleSurface(s, size));
-    if ( !snew )
-        return NULL;
-
-    if ( mode == wxDfbCloneSurface_CopyPixels )
-    {
-        if ( !snew->SetBlittingFlags(DSBLIT_NOFX) )
-            return NULL;
-        if ( !snew->Blit(s, NULL, 0, 0) )
-            return NULL;
-    }
-
-    return snew;
-}
-
-int wxDfbGetSurfaceDepth(const wxIDirectFBSurfacePtr& s)
-{
-    wxCHECK_MSG( s, -1, _T("invalid surface") );
-
-    DFBSurfacePixelFormat format = DSPF_UNKNOWN;
-
-    if ( !s->GetPixelFormat(&format) )
-        return -1;
-
-    return DFB_BITS_PER_PIXEL(format);
-}
-
-wxIDirectFBDisplayLayerPtr wxDfbGetDisplayLayer()
-{
-    return wxIDirectFB::Get()->GetDisplayLayer(DLID_PRIMARY);
-}
-
-wxIDirectFBSurfacePtr wxDfbGetPrimarySurface()
-{
-    wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
-    return layer ? layer->GetSurface() : NULL;
-}
-
 
 //-----------------------------------------------------------------------------
 // mouse
 
 //-----------------------------------------------------------------------------
 // mouse
@@ -174,7 +90,7 @@ wxIDirectFBSurfacePtr wxDfbGetPrimarySurface()
 
 void wxGetMousePosition(int *x, int *y)
 {
 
 void wxGetMousePosition(int *x, int *y)
 {
-    wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
+    wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
     if ( layer )
         layer->GetCursorPosition(x, y);
 }
     if ( layer )
         layer->GetCursorPosition(x, y);
 }
index 014e7c32be0c47f173188e4edf6596781e84eae5..f2b090be72e044f10191c960c1c71af2afdcb366 100644 (file)
@@ -370,7 +370,7 @@ void wxWindowDFB::WarpPointer(int x, int y)
     if ( x >= w ) x = w-1;
     if ( y >= h ) y = h-1;
 
     if ( x >= w ) x = w-1;
     if ( y >= h ) y = h-1;
 
-    wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer());
+    wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer());
     wxCHECK_RET( layer, _T("no display layer") );
 
     layer->WarpCursor(x, y);
     wxCHECK_RET( layer, _T("no display layer") );
 
     layer->WarpCursor(x, y);
index 406d7a6893bce54cd8c0c21ef2d5b041c992ffee..873f040cdefac3b135e67b7ead116a94f5b38e0e 100644 (file)
@@ -95,3 +95,74 @@ void wxIDirectFB::CleanUp()
 {
     ms_ptr.Reset();
 }
 {
     ms_ptr.Reset();
 }
+
+wxIDirectFBSurfacePtr wxIDirectFB::GetPrimarySurface()
+{
+    wxIDirectFBDisplayLayerPtr layer(GetDisplayLayer());
+    return layer ? layer->GetSurface() : NULL;
+}
+
+//-----------------------------------------------------------------------------
+// wxIDirectFBSurface
+//-----------------------------------------------------------------------------
+
+int wxIDirectFBSurface::GetDepth()
+{
+    DFBSurfacePixelFormat format = DSPF_UNKNOWN;
+
+    if ( !GetPixelFormat(&format) )
+        return -1;
+
+    return DFB_BITS_PER_PIXEL(format);
+}
+
+wxIDirectFBSurfacePtr wxIDirectFBSurface::CreateCompatible(const wxSize& sz)
+{
+    wxSize size(sz);
+    if ( size == wxDefaultSize )
+    {
+        if ( !GetSize(&size.x, &size.y) )
+            return NULL;
+    }
+
+    wxCHECK_MSG( size.x > 0 && size.y > 0, NULL, _T("invalid size") );
+
+    DFBSurfaceDescription desc;
+    desc.flags = (DFBSurfaceDescriptionFlags)(
+            DSDESC_CAPS | DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT);
+    GetCapabilities(&desc.caps);
+    GetPixelFormat(&desc.pixelformat);
+    desc.width = size.x;
+    desc.height = size.y;
+
+    wxIDirectFBSurfacePtr snew(wxIDirectFB::Get()->CreateSurface(&desc));
+    if ( !snew )
+        return NULL;
+
+    if ( desc.pixelformat == DSPF_LUT8 )
+    {
+        wxIDirectFBPalettePtr pal(GetPalette());
+        if ( pal )
+        {
+            if ( !snew->SetPalette(pal) )
+                return NULL;
+        }
+    }
+
+    return snew;
+}
+
+wxIDirectFBSurfacePtr wxIDirectFBSurface::Clone()
+{
+    wxIDirectFBSurfacePtr snew(CreateCompatible());
+    if ( !snew )
+        return NULL;
+
+    if ( !snew->SetBlittingFlags(DSBLIT_NOFX) )
+        return NULL;
+
+    if ( !snew->Blit(GetRaw(), NULL, 0, 0) )
+        return NULL;
+
+    return snew;
+}