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
This commit is contained in:
Robin Dunn 2011-10-20 04:49:12 +00:00
parent c9b7d15bbb
commit 6e6f074b45
5 changed files with 53 additions and 45 deletions

View File

@ -842,6 +842,7 @@ public:
virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) = 0; virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ) = 0;
#if wxUSE_IMAGE #if wxUSE_IMAGE
virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image) = 0; virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image) = 0;
virtual wxImage CreateImageFromBitmap(const wxGraphicsBitmap& bmp) = 0;
#endif // wxUSE_IMAGE #endif // wxUSE_IMAGE
// create a graphics bitmap from a native bitmap // create a graphics bitmap from a native bitmap
@ -855,6 +856,16 @@ private:
DECLARE_ABSTRACT_CLASS(wxGraphicsRenderer) 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_ #endif // _WX_GRAPHICS_H_

View File

@ -969,6 +969,13 @@ public:
*/ */
virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image) = 0; 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. Creates wxGraphicsBitmap from a native bitmap handle.

View File

@ -1267,7 +1267,7 @@ wxCairoBitmapData::wxCairoBitmapData( wxGraphicsRenderer* renderer, const wxBitm
// Create a surface object and copy the bitmap pixel data to it. if the // 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 // image has alpha (or a mask represented as alpha) then we'll use a
// different format and iterator than if it doesn't... // 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__ #ifdef __WXGTK__
|| bmp.GetMask() || bmp.GetMask()
#endif #endif
@ -1558,22 +1558,6 @@ wxCairoBitmapData::~wxCairoBitmapData()
delete [] m_buffer; delete [] m_buffer;
} }
// ----------------------------------------------------------------------------
// wxGraphicsBitmap implementation
// ----------------------------------------------------------------------------
#if wxUSE_IMAGE
wxImage wxGraphicsBitmap::ConvertToImage() const
{
const wxCairoBitmapData* const
data = static_cast<wxCairoBitmapData*>(GetGraphicsData());
return data ? data->ConvertToImage() : wxNullImage;
}
#endif // wxUSE_IMAGE
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxCairoContext implementation // wxCairoContext implementation
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -2292,6 +2276,7 @@ public :
virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ); virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap );
#if wxUSE_IMAGE #if wxUSE_IMAGE
virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image); virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image);
virtual wxImage CreateImageFromBitmap(const wxGraphicsBitmap& bmp);
#endif // wxUSE_IMAGE #endif // wxUSE_IMAGE
// create a graphics bitmap from a native bitmap // create a graphics bitmap from a native bitmap
@ -2558,8 +2543,19 @@ wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromImage(const wxImage& image)
return bmp; return bmp;
} }
wxImage wxCairoRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp)
{
ENSURE_LOADED_OR_RETURN(wxNullImage);
const wxCairoBitmapData* const
data = static_cast<wxCairoBitmapData*>(bmp.GetGraphicsData());
return data ? data->ConvertToImage() : wxNullImage;
}
#endif // wxUSE_IMAGE #endif // wxUSE_IMAGE
wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromNativeBitmap( void* bitmap ) wxGraphicsBitmap wxCairoRenderer::CreateBitmapFromNativeBitmap( void* bitmap )
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);

View File

@ -541,6 +541,7 @@ public :
virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ); virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap );
#if wxUSE_IMAGE #if wxUSE_IMAGE
virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image); virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image);
virtual wxImage CreateImageFromBitmap(const wxGraphicsBitmap& bmp);
#endif // wxUSE_IMAGE #endif // wxUSE_IMAGE
virtual wxGraphicsFont CreateFont( const wxFont& font, virtual wxGraphicsFont CreateFont( const wxFont& font,
@ -1078,22 +1079,6 @@ wxGDIPlusBitmapData::~wxGDIPlusBitmapData()
delete m_helper; delete m_helper;
} }
// ----------------------------------------------------------------------------
// wxGraphicsBitmap implementation
// ----------------------------------------------------------------------------
#if wxUSE_IMAGE
wxImage wxGraphicsBitmap::ConvertToImage() const
{
const wxGDIPlusBitmapData* const
data = static_cast<wxGDIPlusBitmapData*>(GetGraphicsData());
return data ? data->ConvertToImage() : wxNullImage;
}
#endif // wxUSE_IMAGE
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxGDIPlusPath implementation // wxGDIPlusPath implementation
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -2194,8 +2179,19 @@ wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromImage(const wxImage& image)
return wxNullGraphicsBitmap; return wxNullGraphicsBitmap;
} }
wxImage wxGDIPlusRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp)
{
ENSURE_LOADED_OR_RETURN(wxNullImage);
const wxGDIPlusBitmapData* const
data = static_cast<wxGDIPlusBitmapData*>(bmp.GetGraphicsData());
return data ? data->ConvertToImage() : wxNullImage;
}
#endif // wxUSE_IMAGE #endif // wxUSE_IMAGE
wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap ) wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap )
{ {
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);

View File

@ -1001,17 +1001,6 @@ wxMacCoreGraphicsBitmapData::~wxMacCoreGraphicsBitmapData()
CGImageRelease( m_bitmap ); CGImageRelease( m_bitmap );
} }
#if wxUSE_IMAGE
wxImage wxGraphicsBitmap::ConvertToImage() const
{
wxMacCoreGraphicsBitmapData* const
data = static_cast<wxMacCoreGraphicsBitmapData*>(GetRefData());
return data ? data->ConvertToImage() : wxNullImage;
}
#endif // wxUSE_IMAGE
// //
// Graphics Matrix // Graphics Matrix
@ -2858,6 +2847,7 @@ public :
#if wxUSE_IMAGE #if wxUSE_IMAGE
virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image); virtual wxGraphicsBitmap CreateBitmapFromImage(const wxImage& image);
virtual wxImage CreateImageFromBitmap(const wxGraphicsBitmap& bmp);
#endif // wxUSE_IMAGE #endif // wxUSE_IMAGE
// create a graphics bitmap from a native bitmap // create a graphics bitmap from a native bitmap
@ -3049,6 +3039,14 @@ wxMacCoreGraphicsRenderer::CreateBitmapFromImage(const wxImage& image)
return CreateBitmap(wxBitmap(image)); return CreateBitmap(wxBitmap(image));
} }
wxImage wxMacCoreGraphicsRenderer::CreateImageFromBitmap(const wxGraphicsBitmap& bmp)
{
wxMacCoreGraphicsBitmapData* const
data = static_cast<wxMacCoreGraphicsBitmapData*>(bmp.GetRefData());
return data ? data->ConvertToImage() : wxNullImage;
}
#endif // wxUSE_IMAGE #endif // wxUSE_IMAGE
wxGraphicsBitmap wxMacCoreGraphicsRenderer::CreateBitmapFromNativeBitmap( void* bitmap ) wxGraphicsBitmap wxMacCoreGraphicsRenderer::CreateBitmapFromNativeBitmap( void* bitmap )