From a5b31f4e11c860fa5d9949c8694a7499793c3b98 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Mon, 11 Sep 2006 09:08:57 +0000 Subject: [PATCH] move misc surface helpers to wxIDirectFBSurface class git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41154 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dfb/private.h | 38 ------------------ include/wx/dfb/wrapdfb.h | 37 ++++++++++++++--- src/dfb/app.cpp | 4 +- src/dfb/bitmap.cpp | 7 ++-- src/dfb/dc.cpp | 2 +- src/dfb/dcclient.cpp | 2 +- src/dfb/dcscreen.cpp | 2 +- src/dfb/toplevel.cpp | 2 +- src/dfb/utils.cpp | 86 +--------------------------------------- src/dfb/window.cpp | 2 +- src/dfb/wrapdfb.cpp | 71 +++++++++++++++++++++++++++++++++ 11 files changed, 115 insertions(+), 138 deletions(-) diff --git a/include/wx/dfb/private.h b/include/wx/dfb/private.h index 8e005dace1..9a36a5ea5e 100644 --- a/include/wx/dfb/private.h +++ b/include/wx/dfb/private.h @@ -28,44 +28,6 @@ #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 //----------------------------------------------------------------------------- diff --git a/include/wx/dfb/wrapdfb.h b/include/wx/dfb/wrapdfb.h index 970c6ebf96..30ef307513 100644 --- a/include/wx/dfb/wrapdfb.h +++ b/include/wx/dfb/wrapdfb.h @@ -266,10 +266,33 @@ struct wxIDirectFBSurface : public wxDfbWrapper 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 return NULL; } - wxIDirectFBDisplayLayerPtr GetDisplayLayer(DFBDisplayLayerID id) + wxIDirectFBDisplayLayerPtr + GetDisplayLayer(DFBDisplayLayerID id = DLID_PRIMARY) { IDirectFBDisplayLayer *l; if ( Check(m_ptr->GetDisplayLayer(m_ptr, id, &l)) ) @@ -455,6 +479,9 @@ struct wxIDirectFB : public wxDfbWrapper return NULL; } + /// Returns primary surface + wxIDirectFBSurfacePtr GetPrimarySurface(); + private: wxIDirectFB(IDirectFB *ptr) { Init(ptr); } diff --git a/src/dfb/app.cpp b/src/dfb/app.cpp index 65d2be4478..4618b16e4b 100644 --- a/src/dfb/app.cpp +++ b/src/dfb/app.cpp @@ -71,12 +71,12 @@ static wxVideoMode GetCurrentVideoMode() { wxVideoMode m; - wxIDirectFBSurfacePtr surface(wxDfbGetPrimarySurface()); + wxIDirectFBSurfacePtr surface(wxIDirectFB::Get()->GetPrimarySurface()); if ( !surface ) return m; // invalid surface->GetSize(&m.w, &m.h); - m.bpp = wxDfbGetSurfaceDepth(surface); + m.bpp = surface->GetDepth(); return m; } diff --git a/src/dfb/bitmap.cpp b/src/dfb/bitmap.cpp index dbb25257a5..8ba352f12b 100644 --- a/src/dfb/bitmap.cpp +++ b/src/dfb/bitmap.cpp @@ -158,8 +158,9 @@ public: 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; @@ -294,7 +295,7 @@ int wxBitmap::GetDepth() const { wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") ); - return wxDfbGetSurfaceDepth(M_BITMAP->m_surface); + return M_BITMAP->m_surface->GetDepth(); } wxMask *wxBitmap::GetMask() const diff --git a/src/dfb/dc.cpp b/src/dfb/dc.cpp index a02dd8f7a1..752291010e 100644 --- a/src/dfb/dc.cpp +++ b/src/dfb/dc.cpp @@ -130,7 +130,7 @@ void wxDC::DestroyClippingRegion() int wxDC::GetDepth() const { - return wxDfbGetSurfaceDepth(m_surface); + return m_surface->GetDepth(); } // --------------------------------------------------------------------------- diff --git a/src/dfb/dcclient.cpp b/src/dfb/dcclient.cpp index 17940083ea..c51e6a509e 100644 --- a/src/dfb/dcclient.cpp +++ b/src/dfb/dcclient.cpp @@ -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()); - surface = wxDfbCreateCompatibleSurface(win->GetDfbSurface(), size); + surface = win->GetDfbSurface()->CreateCompatible(size); } else if ( !rect ) { diff --git a/src/dfb/dcscreen.cpp b/src/dfb/dcscreen.cpp index f1218a936c..4d9ba71e76 100644 --- a/src/dfb/dcscreen.cpp +++ b/src/dfb/dcscreen.cpp @@ -38,7 +38,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxDC) wxScreenDC::wxScreenDC() { - Init(wxDfbGetPrimarySurface()); + Init(wxIDirectFB::Get()->GetPrimarySurface()); } #warning "FIXME: does wxScreenDC need Flip call in dtor?" diff --git a/src/dfb/toplevel.cpp b/src/dfb/toplevel.cpp index ffa3dcaaac..41b05ce9b1 100644 --- a/src/dfb/toplevel.cpp +++ b/src/dfb/toplevel.cpp @@ -122,7 +122,7 @@ bool wxTopLevelWindowDFB::Create(wxWindow *parent, pos.y = 0; // create DirectFB window: - wxIDirectFBDisplayLayerPtr layer = wxDfbGetDisplayLayer(); + wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer()); wxCHECK_MSG( layer, false, _T("no display layer") ); DFBWindowDescription desc; diff --git a/src/dfb/utils.cpp b/src/dfb/utils.cpp index 2f1e7da32e..87700dbbb9 100644 --- a/src/dfb/utils.cpp +++ b/src/dfb/utils.cpp @@ -83,90 +83,6 @@ void wxClientDisplayRect(int *x, int *y, int *width, int *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 @@ -174,7 +90,7 @@ wxIDirectFBSurfacePtr wxDfbGetPrimarySurface() void wxGetMousePosition(int *x, int *y) { - wxIDirectFBDisplayLayerPtr layer(wxDfbGetDisplayLayer()); + wxIDirectFBDisplayLayerPtr layer(wxIDirectFB::Get()->GetDisplayLayer()); if ( layer ) layer->GetCursorPosition(x, y); } diff --git a/src/dfb/window.cpp b/src/dfb/window.cpp index 014e7c32be..f2b090be72 100644 --- a/src/dfb/window.cpp +++ b/src/dfb/window.cpp @@ -370,7 +370,7 @@ void wxWindowDFB::WarpPointer(int x, int y) 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); diff --git a/src/dfb/wrapdfb.cpp b/src/dfb/wrapdfb.cpp index 406d7a6893..873f040cde 100644 --- a/src/dfb/wrapdfb.cpp +++ b/src/dfb/wrapdfb.cpp @@ -95,3 +95,74 @@ void wxIDirectFB::CleanUp() { 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; +} -- 2.45.2