Fixed creating wxGraphicsContext from wxMemoryDC with Cairo renderer (wxMSW).

Create RGB Cairo surface as a fallback if we failed to create ARGB surface for 32bpp wxBitmap.
This commit is contained in:
Artur Wieczorek
2016-04-09 23:47:58 +02:00
parent ac49e3829a
commit 42c08aae12

View File

@@ -1887,12 +1887,10 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC&
// We need to pass a pointer to the location // We need to pass a pointer to the location
// of the bit values to Cairo function. // of the bit values to Cairo function.
BITMAP info; BITMAP info;
if (::GetObject(bmp.GetHBITMAP(), sizeof(info), &info) == 0) if ( ::GetObject(bmp.GetHBITMAP(), sizeof(info), &info) == sizeof(info) )
{
if( info.bmBits )
{ {
wxLogLastError(wxS("wxCairoContext ctor - GetObject"));
}
wxASSERT_MSG(info.bmBits != NULL, wxS("Invalid bitmap"));
m_mswSurface = cairo_image_surface_create_for_data((unsigned char*)info.bmBits, m_mswSurface = cairo_image_surface_create_for_data((unsigned char*)info.bmBits,
bmp.HasAlpha() ? bmp.HasAlpha() ?
CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24,
@@ -1902,6 +1900,22 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC&
hasBitmap = true; hasBitmap = true;
} }
else
{
wxFAIL_MSG( wxS("Invalid bitmap") );
}
}
else
{
wxLogLastError( wxS("wxCairoContext ctor - GetObject") );
}
// Fallback if we failed to create Cairo surface from 32bpp bitmap.
if( !hasBitmap )
{
m_mswSurface = cairo_win32_surface_create(dc.GetHDC());
}
}
Init( cairo_create(m_mswSurface) ); Init( cairo_create(m_mswSurface) );
// If we've created a image surface, we need: // If we've created a image surface, we need: