From 8b180bded61df267e5f45f4ec0cccf6b52d36ae2 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 11 May 2012 22:06:50 +0000 Subject: [PATCH] Enable access to the native bitmap object wrapped by wxGraphicsBitmap git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71416 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/graphics.h | 8 ++++++++ include/wx/private/graphics.h | 12 ++++++++++++ interface/wx/graphics.h | 8 ++++++++ src/common/graphcmn.cpp | 5 +++++ src/generic/graphicc.cpp | 9 +++++---- src/msw/graphics.cpp | 7 ++++--- src/osx/carbon/graphics.cpp | 7 ++++--- 7 files changed, 46 insertions(+), 10 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index ad0206e2d3..0e534a6e61 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -107,6 +107,7 @@ class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmap; // class WXDLLIMPEXP_FWD_CORE wxGraphicsObjectRefData; +class WXDLLIMPEXP_FWD_CORE wxGraphicsBitmapData; class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrixData; class WXDLLIMPEXP_FWD_CORE wxGraphicsPathData; @@ -174,6 +175,13 @@ public: #if wxUSE_IMAGE wxImage ConvertToImage() const; #endif // wxUSE_IMAGE + + void* GetNativeBitmap() const; + + const wxGraphicsBitmapData* GetBitmapData() const + { return (const wxGraphicsBitmapData*) GetRefData(); } + wxGraphicsBitmapData* GetBitmapData() + { return (wxGraphicsBitmapData*) GetRefData(); } private: DECLARE_DYNAMIC_CLASS(wxGraphicsBitmap) diff --git a/include/wx/private/graphics.h b/include/wx/private/graphics.h index 8fb65d0197..4fbab11653 100644 --- a/include/wx/private/graphics.h +++ b/include/wx/private/graphics.h @@ -28,6 +28,18 @@ class WXDLLIMPEXP_CORE wxGraphicsObjectRefData : public wxObjectRefData wxGraphicsRenderer* m_renderer; } ; +class WXDLLIMPEXP_CORE wxGraphicsBitmapData : public wxGraphicsObjectRefData +{ +public : + wxGraphicsBitmapData( wxGraphicsRenderer* renderer) : + wxGraphicsObjectRefData(renderer) {} + + virtual ~wxGraphicsBitmapData() {} + + // returns the native representation + virtual void * GetNativeBitmap() const = 0; +} ; + class WXDLLIMPEXP_CORE wxGraphicsMatrixData : public wxGraphicsObjectRefData { public : diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index 912763c38f..630662f47a 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -296,6 +296,14 @@ public: @since 2.9.3 */ wxImage ConvertToImage() const; + + /** + Return the pointer to the native bitmap data. (CGImageRef for Core Graphics, + cairo_surface_t for Cairo, Bitmap* for GDI+.) + + @since 2.9.4 + */ + void* GetNativeBitmap() const; }; /** diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index 33009406c4..9a75c2bf71 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -524,6 +524,11 @@ void wxGraphicsGradientStops::Add(const wxGraphicsGradientStop& stop) } } +void * wxGraphicsBitmap::GetNativeBitmap() const +{ + return GetBitmapData()->GetNativeBitmap(); +} + //----------------------------------------------------------------------------- // wxGraphicsContext Convenience Methods //----------------------------------------------------------------------------- diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 534238a96e..04bb3432bf 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -323,7 +323,7 @@ private : cairo_font_weight_t m_weight; }; -class wxCairoBitmapData : public wxGraphicsObjectRefData +class wxCairoBitmapData : public wxGraphicsBitmapData { public: wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp ); @@ -335,6 +335,7 @@ public: virtual cairo_surface_t* GetCairoSurface() { return m_surface; } virtual cairo_pattern_t* GetCairoPattern() { return m_pattern; } + void* GetNativeBitmap() const { return (void*)m_surface; } virtual wxSize GetSize() { return wxSize(m_width, m_height); } #if wxUSE_IMAGE @@ -1248,13 +1249,13 @@ void wxCairoBitmapData::InitSurface(cairo_format_t format, int stride) } wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, cairo_surface_t* bitmap ) : - wxGraphicsObjectRefData( renderer ) + wxGraphicsBitmapData( renderer ) { m_surface = bitmap; m_pattern = cairo_pattern_create_for_surface(m_surface); } -wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp ) : wxGraphicsObjectRefData( renderer ) +wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitmap& bmp ) : wxGraphicsBitmapData( renderer ) { wxCHECK_RET( bmp.IsOk(), wxT("Invalid bitmap in wxCairoContext::DrawBitmap")); @@ -1394,7 +1395,7 @@ inline unsigned char Unpremultiply(unsigned char alpha, unsigned char data) wxCairoBitmapData::wxCairoBitmapData(wxGraphicsRenderer* renderer, const wxImage& image) - : wxGraphicsObjectRefData(renderer) + : wxGraphicsBitmapData(renderer) { const cairo_format_t bufferFormat = image.HasAlpha() ? CAIRO_FORMAT_ARGB32 diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index cad53a46d0..dd6ff85899 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -272,7 +272,7 @@ private: GraphicsPath* m_brushPath; }; -class WXDLLIMPEXP_CORE wxGDIPlusBitmapData : public wxGraphicsObjectRefData +class WXDLLIMPEXP_CORE wxGDIPlusBitmapData : public wxGraphicsBitmapData { public: wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, Bitmap* bitmap ); @@ -280,6 +280,7 @@ public: ~wxGDIPlusBitmapData (); virtual Bitmap* GetGDIPlusBitmap() { return m_bitmap; } + void* GetNativeBitmap() const { return (void*)m_bitmap; } #if wxUSE_IMAGE wxImage ConvertToImage() const; @@ -943,13 +944,13 @@ wxGDIPlusFontData::~wxGDIPlusFontData() //----------------------------------------------------------------------------- wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, Bitmap* bitmap ) : - wxGraphicsObjectRefData( renderer ), m_bitmap( bitmap ) + wxGraphicsBitmapData( renderer ), m_bitmap( bitmap ) { m_helper = NULL; } wxGDIPlusBitmapData::wxGDIPlusBitmapData( wxGraphicsRenderer* renderer, - const wxBitmap &bmp) : wxGraphicsObjectRefData( renderer ) + const wxBitmap &bmp) : wxGraphicsBitmapData( renderer ) { m_bitmap = NULL; m_helper = NULL; diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index afaec66fa4..59350b04dd 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -969,13 +969,14 @@ wxMacCoreGraphicsFontData::~wxMacCoreGraphicsFontData() #endif } -class wxMacCoreGraphicsBitmapData : public wxGraphicsObjectRefData +class wxMacCoreGraphicsBitmapData : public wxGraphicsBitmapData { public: wxMacCoreGraphicsBitmapData( wxGraphicsRenderer* renderer, CGImageRef bitmap, bool monochrome ); ~wxMacCoreGraphicsBitmapData(); virtual CGImageRef GetBitmap() { return m_bitmap; } + void* GetNativeBitmap() const { return (void*)m_bitmap; } bool IsMonochrome() { return m_monochrome; } #if wxUSE_IMAGE @@ -990,7 +991,7 @@ private : bool m_monochrome; }; -wxMacCoreGraphicsBitmapData::wxMacCoreGraphicsBitmapData( wxGraphicsRenderer* renderer, CGImageRef bitmap, bool monochrome ) : wxGraphicsObjectRefData( renderer ), +wxMacCoreGraphicsBitmapData::wxMacCoreGraphicsBitmapData( wxGraphicsRenderer* renderer, CGImageRef bitmap, bool monochrome ) : wxGraphicsBitmapData( renderer ), m_bitmap(bitmap), m_monochrome(monochrome) { } @@ -2245,7 +2246,7 @@ void wxMacCoreGraphicsContext::DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble return; #ifdef __WXMAC__ - wxMacCoreGraphicsBitmapData* refdata =static_cast(bmp.GetRefData()); + wxMacCoreGraphicsBitmapData* refdata = static_cast(bmp.GetRefData()); CGImageRef image = refdata->GetBitmap(); CGRect r = CGRectMake( (CGFloat) x , (CGFloat) y , (CGFloat) w , (CGFloat) h ); if ( refdata->IsMonochrome() == 1 )