From 6e6f074b45b065b6745caecd25324615bc77ab3b Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 20 Oct 2011 04:49:12 +0000 Subject: [PATCH] Delegate wxGraphicsBitmap::ConvertToImage to the renderer so we do not end up with more than one definition of the method when building with both the GDI+ GC and the Cairo GC enabled at the same time. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69485 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/graphics.h | 13 ++++++++++++- interface/wx/graphics.h | 7 +++++++ src/generic/graphicc.cpp | 30 +++++++++++++----------------- src/msw/graphics.cpp | 28 ++++++++++++---------------- src/osx/carbon/graphics.cpp | 20 +++++++++----------- 5 files changed, 53 insertions(+), 45 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index dc17baf075..d385d7db02 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -842,6 +842,7 @@ public: virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) = 0; #if wxUSE_IMAGE virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image) = 0; + virtual wxImage CreateImageFromBitmap(const wxGraphicsBitmap& bmp) = 0; #endif // wxUSE_IMAGE // create a graphics bitmap from a native bitmap @@ -855,6 +856,16 @@ private: DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer) }; -#endif + +#if wxUSE_IMAGE +inline +wxImage wxGraphicsBitmap::ConvertToImage() const +{ + wxGraphicsRenderer* renderer = GetRenderer(); + return renderer ? renderer->CreateImageFromBitmap(*this) : wxNullImage; +} +#endif // wxUSE_IMAGE + +#endif // wxUSE_GRAPHICS_CONTEXT #endif // _WX_GRAPHICS_H_ diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index 086bf1e952..83627b2ef4 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -969,6 +969,13 @@ public: */ virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image) = 0; + /** + Creates a wxImage from a wxGraphicsBitmap. + + This method is used by the more convenient wxGraphicsBitmap::ConvertToImage. + */ + virtual wxImage CreateImageFromBitmap(const wxGraphicsBitmap& bmp) = 0; + /** Creates wxGraphicsBitmap from a native bitmap handle. diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 215968306f..c8f2506cc4 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -1267,7 +1267,7 @@ wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitm // Create a surface object and copy the bitmap pixel data to it. if the // image has alpha (or a mask represented as alpha) then we'll use a // different format and iterator than if it doesn't... - const cairo_format_t bufferFormat = bmp.GetDepth() == 32 + cairo_format_t bufferFormat = bmp.GetDepth() == 32 #ifdef __WXGTK__ || bmp.GetMask() #endif @@ -1558,22 +1558,6 @@ wxCairoBitmapData::~wxCairoBitmapData() delete [] m_buffer; } -// ---------------------------------------------------------------------------- -// wxGraphicsBitmap implementation -// ---------------------------------------------------------------------------- - -#if wxUSE_IMAGE - -wxImage wxGraphicsBitmap::ConvertToImage() const -{ - const wxCairoBitmapData* const - data = static_cast(GetGraphicsData()); - - return data ? data->ConvertToImage() : wxNullImage; -} - -#endif // wxUSE_IMAGE - //----------------------------------------------------------------------------- // wxCairoContext implementation //----------------------------------------------------------------------------- @@ -2292,6 +2276,7 @@ public : virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ); #if wxUSE_IMAGE virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image); + virtual wxImage CreateImageFromBitmap(const wxGraphicsBitmap& bmp); #endif // wxUSE_IMAGE // create a graphics bitmap from a native bitmap @@ -2558,8 +2543,19 @@ wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromImage(const wxImage& image) return bmp; } +wxImage wxCairoRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp) +{ + ENSURE_LOADED_OR_RETURN(wxNullImage); + + const wxCairoBitmapData* const + data = static_cast(bmp.GetGraphicsData()); + + return data ? data->ConvertToImage() : wxNullImage; +} + #endif // wxUSE_IMAGE + wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromNativeBitmap( void* bitmap ) { ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index e2065c05e9..f5dbc1476f 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -541,6 +541,7 @@ public : virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ); #if wxUSE_IMAGE virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image); + virtual wxImage CreateImageFromBitmap(const wxGraphicsBitmap& bmp); #endif // wxUSE_IMAGE virtual wxGraphicsFont CreateFont( const wxFont& font, @@ -1078,22 +1079,6 @@ wxGDIPlusBitmapData::~wxGDIPlusBitmapData() delete m_helper; } -// ---------------------------------------------------------------------------- -// wxGraphicsBitmap implementation -// ---------------------------------------------------------------------------- - -#if wxUSE_IMAGE - -wxImage wxGraphicsBitmap::ConvertToImage() const -{ - const wxGDIPlusBitmapData* const - data = static_cast(GetGraphicsData()); - - return data ? data->ConvertToImage() : wxNullImage; -} - -#endif // wxUSE_IMAGE - //----------------------------------------------------------------------------- // wxGDIPlusPath implementation //----------------------------------------------------------------------------- @@ -2194,8 +2179,19 @@ wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromImage(const wxImage& image) return wxNullGraphicsBitmap; } + +wxImage wxGDIPlusRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp) +{ + ENSURE_LOADED_OR_RETURN(wxNullImage); + const wxGDIPlusBitmapData* const + data = static_cast(bmp.GetGraphicsData()); + + return data ? data->ConvertToImage() : wxNullImage; +} + #endif // wxUSE_IMAGE + wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap ) { ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 5b50bb5ff7..3a5306d1bb 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -1001,17 +1001,6 @@ wxMacCoreGraphicsBitmapData::~wxMacCoreGraphicsBitmapData() CGImageRelease( m_bitmap ); } -#if wxUSE_IMAGE - -wxImage wxGraphicsBitmap::ConvertToImage() const -{ - wxMacCoreGraphicsBitmapData* const - data = static_cast(GetRefData()); - - return data ? data->ConvertToImage() : wxNullImage; -} - -#endif // wxUSE_IMAGE // // Graphics Matrix @@ -2858,6 +2847,7 @@ public : #if wxUSE_IMAGE virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image); + virtual wxImage CreateImageFromBitmap(const wxGraphicsBitmap& bmp); #endif // wxUSE_IMAGE // create a graphics bitmap from a native bitmap @@ -3049,6 +3039,14 @@ wxMacCoreGraphicsRenderer::CreateBitmapFromImage(const wxImage& image) return CreateBitmap(wxBitmap(image)); } +wxImage wxMacCoreGraphicsRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp) +{ + wxMacCoreGraphicsBitmapData* const + data = static_cast(bmp.GetRefData()); + + return data ? data->ConvertToImage() : wxNullImage; +} + #endif // wxUSE_IMAGE wxGraphicsBitmap wxMacCoreGraphicsRenderer::CreateBitmapFromNativeBitmap( void* bitmap ) -- 2.45.2