remove redundant GdkBitmap representation from wxBitmap

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39796 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Paul Cornett
2006-06-19 18:30:13 +00:00
parent 0006b9a540
commit b85229d15b
5 changed files with 32 additions and 75 deletions

View File

@@ -113,11 +113,9 @@ public:
void SetWidth( int width ); void SetWidth( int width );
void SetDepth( int depth ); void SetDepth( int depth );
void SetPixmap( GdkPixmap *pixmap ); void SetPixmap( GdkPixmap *pixmap );
void SetBitmap( GdkBitmap *bitmap );
void SetPixbuf(GdkPixbuf *pixbuf); void SetPixbuf(GdkPixbuf *pixbuf);
GdkPixmap *GetPixmap() const; GdkPixmap *GetPixmap() const;
GdkBitmap *GetBitmap() const;
bool HasPixmap() const; bool HasPixmap() const;
bool HasPixbuf() const; bool HasPixbuf() const;
GdkPixbuf *GetPixbuf() const; GdkPixbuf *GetPixbuf() const;

View File

@@ -203,7 +203,7 @@ bool wxMask::Create( const wxBitmap& bitmap )
if (!bitmap.Ok()) return false; if (!bitmap.Ok()) return false;
wxCHECK_MSG( bitmap.GetBitmap(), false, wxT("Cannot create mask from colour bitmap") ); wxCHECK_MSG( bitmap.GetDepth() == 1, false, wxT("Cannot create mask from colour bitmap") );
m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, bitmap.GetWidth(), bitmap.GetHeight(), 1 ); m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, bitmap.GetWidth(), bitmap.GetHeight(), 1 );
@@ -211,7 +211,7 @@ bool wxMask::Create( const wxBitmap& bitmap )
GdkGC *gc = gdk_gc_new( m_bitmap ); GdkGC *gc = gdk_gc_new( m_bitmap );
gdk_wx_draw_bitmap( m_bitmap, gc, bitmap.GetBitmap(), 0, 0, 0, 0, bitmap.GetWidth(), bitmap.GetHeight() ); gdk_wx_draw_bitmap( m_bitmap, gc, bitmap.GetPixmap(), 0, 0, 0, 0, bitmap.GetWidth(), bitmap.GetHeight() );
g_object_unref (gc); g_object_unref (gc);
@@ -234,7 +234,6 @@ public:
~wxBitmapRefData(); ~wxBitmapRefData();
GdkPixmap *m_pixmap; GdkPixmap *m_pixmap;
GdkBitmap *m_bitmap;
GdkPixbuf *m_pixbuf; GdkPixbuf *m_pixbuf;
wxMask *m_mask; wxMask *m_mask;
int m_width; int m_width;
@@ -246,7 +245,6 @@ public:
wxBitmapRefData::wxBitmapRefData() wxBitmapRefData::wxBitmapRefData()
{ {
m_pixmap = (GdkPixmap *) NULL; m_pixmap = (GdkPixmap *) NULL;
m_bitmap = (GdkBitmap *) NULL;
m_pixbuf = (GdkPixbuf *) NULL; m_pixbuf = (GdkPixbuf *) NULL;
m_mask = (wxMask *) NULL; m_mask = (wxMask *) NULL;
m_width = 0; m_width = 0;
@@ -259,8 +257,6 @@ wxBitmapRefData::~wxBitmapRefData()
{ {
if (m_pixmap) if (m_pixmap)
g_object_unref (m_pixmap); g_object_unref (m_pixmap);
if (m_bitmap)
g_object_unref (m_bitmap);
if (m_pixbuf) if (m_pixbuf)
g_object_unref (m_pixbuf); g_object_unref (m_pixbuf);
delete m_mask; delete m_mask;
@@ -271,7 +267,7 @@ wxBitmapRefData::~wxBitmapRefData()
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#define M_BMPDATA ((wxBitmapRefData *)m_refData) #define M_BMPDATA wx_static_cast(wxBitmapRefData*, m_refData)
IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxGDIObject)
@@ -305,21 +301,15 @@ bool wxBitmap::Create( int width, int height, int depth )
M_BMPDATA->m_mask = (wxMask *) NULL; M_BMPDATA->m_mask = (wxMask *) NULL;
M_BMPDATA->m_width = width; M_BMPDATA->m_width = width;
M_BMPDATA->m_height = height; M_BMPDATA->m_height = height;
if (depth == 1) M_BMPDATA->m_bpp = depth;
{ if (depth == 32)
M_BMPDATA->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 );
M_BMPDATA->m_bpp = 1;
}
else if (depth == 32)
{ {
M_BMPDATA->m_pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, true, M_BMPDATA->m_pixbuf = gdk_pixbuf_new( GDK_COLORSPACE_RGB, true,
8, width, height); 8, width, height);
M_BMPDATA->m_bpp = 32;
} }
else else
{ {
M_BMPDATA->m_pixmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, depth ); M_BMPDATA->m_pixmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, depth );
M_BMPDATA->m_bpp = visual->depth;
} }
return Ok(); return Ok();
@@ -387,8 +377,6 @@ wxBitmap wxBitmap::Rescale( int clipx, int clipy, int clipwidth, int clipheight,
GdkImage *img = (GdkImage*) NULL; GdkImage *img = (GdkImage*) NULL;
if (GetPixmap()) if (GetPixmap())
img = gdk_image_get( GetPixmap(), 0, 0, GetWidth(), GetHeight() ); img = gdk_image_get( GetPixmap(), 0, 0, GetWidth(), GetHeight() );
else if (GetBitmap())
img = gdk_image_get( GetBitmap(), 0, 0, GetWidth(), GetHeight() );
else else
wxFAIL_MSG( wxT("Ill-formed bitmap") ); wxFAIL_MSG( wxT("Ill-formed bitmap") );
@@ -399,7 +387,7 @@ wxBitmap wxBitmap::Rescale( int clipx, int clipy, int clipwidth, int clipheight,
GdkGC *gc = NULL; GdkGC *gc = NULL;
GdkPixmap *dstpix = NULL; GdkPixmap *dstpix = NULL;
if (GetPixmap()) if (GetDepth() != 1)
{ {
GdkVisual *visual = gdk_drawable_get_visual( GetPixmap() ); GdkVisual *visual = gdk_drawable_get_visual( GetPixmap() );
if (visual == NULL) if (visual == NULL)
@@ -414,7 +402,7 @@ wxBitmap wxBitmap::Rescale( int clipx, int clipy, int clipwidth, int clipheight,
char *dst = NULL; char *dst = NULL;
long dstbyteperline = 0; long dstbyteperline = 0;
if (GetBitmap()) if (GetDepth() == 1)
{ {
bpp = 1; bpp = 1;
dstbyteperline = width/8*M_BMPDATA->m_bpp; dstbyteperline = width/8*M_BMPDATA->m_bpp;
@@ -592,7 +580,7 @@ bool wxBitmap::CreateFromImageAsBitmap(const wxImage& img)
SetHeight( height ); SetHeight( height );
SetWidth( width ); SetWidth( width );
SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) ); SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) );
SetDepth( 1 ); SetDepth( 1 );
@@ -657,9 +645,9 @@ bool wxBitmap::CreateFromImageAsBitmap(const wxImage& img)
// Blit picture // Blit picture
GdkGC *data_gc = gdk_gc_new( GetBitmap() ); GdkGC *data_gc = gdk_gc_new( GetPixmap() );
gdk_draw_image( GetBitmap(), data_gc, data_image, 0, 0, 0, 0, width, height ); gdk_draw_image( GetPixmap(), data_gc, data_image, 0, 0, 0, 0, width, height );
g_object_unref (data_image); g_object_unref (data_image);
g_object_unref (data_gc); g_object_unref (data_gc);
@@ -866,12 +854,6 @@ wxImage wxBitmap::ConvertToImage() const
0, 0, 0, 0,
GetWidth(), GetHeight() ); GetWidth(), GetHeight() );
} }
else if (GetBitmap())
{
gdk_image = gdk_image_get( GetBitmap(),
0, 0,
GetWidth(), GetHeight() );
}
else else
{ {
wxFAIL_MSG( wxT("Ill-formed bitmap") ); wxFAIL_MSG( wxT("Ill-formed bitmap") );
@@ -898,7 +880,7 @@ wxImage wxBitmap::ConvertToImage() const
int blue_shift_left = 0; int blue_shift_left = 0;
bool use_shift = false; bool use_shift = false;
if (GetPixmap()) if (GetDepth() != 1)
{ {
GdkVisual *visual = gdk_drawable_get_visual( GetPixmap() ); GdkVisual *visual = gdk_drawable_get_visual( GetPixmap() );
if (visual == NULL) if (visual == NULL)
@@ -916,7 +898,7 @@ wxImage wxBitmap::ConvertToImage() const
use_shift = (visual->type == GDK_VISUAL_TRUE_COLOR) || (visual->type == GDK_VISUAL_DIRECT_COLOR); use_shift = (visual->type == GDK_VISUAL_TRUE_COLOR) || (visual->type == GDK_VISUAL_DIRECT_COLOR);
} }
if (GetBitmap()) else
{ {
bpp = 1; bpp = 1;
} }
@@ -1002,7 +984,7 @@ wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth
m_refData = new wxBitmapRefData(); m_refData = new wxBitmapRefData();
M_BMPDATA->m_mask = (wxMask *) NULL; M_BMPDATA->m_mask = (wxMask *) NULL;
M_BMPDATA->m_bitmap = gdk_bitmap_create_from_data M_BMPDATA->m_pixmap = gdk_bitmap_create_from_data
( (
wxGetRootWindow()->window, wxGetRootWindow()->window,
(gchar *) bits, (gchar *) bits,
@@ -1013,7 +995,7 @@ wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth
M_BMPDATA->m_height = height; M_BMPDATA->m_height = height;
M_BMPDATA->m_bpp = 1; M_BMPDATA->m_bpp = 1;
wxASSERT_MSG( M_BMPDATA->m_bitmap, wxT("couldn't create bitmap") ); wxASSERT_MSG( M_BMPDATA->m_pixmap, wxT("couldn't create bitmap") );
} }
} }
@@ -1036,7 +1018,7 @@ bool wxBitmap::Ok() const
return (m_refData != NULL) && return (m_refData != NULL) &&
( (
M_BMPDATA->m_pixbuf || M_BMPDATA->m_pixbuf ||
M_BMPDATA->m_bitmap || M_BMPDATA->m_pixmap M_BMPDATA->m_pixmap
); );
} }
@@ -1105,7 +1087,7 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
} }
else else
{ {
if (ret.GetPixmap()) if (ret.GetDepth() != 1)
{ {
GdkGC *gc = gdk_gc_new( ret.GetPixmap() ); GdkGC *gc = gdk_gc_new( ret.GetPixmap() );
gdk_draw_drawable( ret.GetPixmap(), gc, GetPixmap(), rect.x, rect.y, 0, 0, rect.width, rect.height ); gdk_draw_drawable( ret.GetPixmap(), gc, GetPixmap(), rect.x, rect.y, 0, 0, rect.width, rect.height );
@@ -1113,13 +1095,13 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const
} }
else else
{ {
GdkGC *gc = gdk_gc_new( ret.GetBitmap() ); GdkGC *gc = gdk_gc_new( ret.GetPixmap() );
GdkColor col; GdkColor col;
col.pixel = 0xFFFFFF; col.pixel = 0xFFFFFF;
gdk_gc_set_foreground( gc, &col ); gdk_gc_set_foreground( gc, &col );
col.pixel = 0; col.pixel = 0;
gdk_gc_set_background( gc, &col ); gdk_gc_set_background( gc, &col );
gdk_wx_draw_bitmap( ret.GetBitmap(), gc, GetBitmap(), rect.x, rect.y, 0, 0, rect.width, rect.height ); gdk_wx_draw_bitmap( ret.GetPixmap(), gc, GetPixmap(), rect.x, rect.y, 0, 0, rect.width, rect.height );
g_object_unref (gc); g_object_unref (gc);
} }
} }
@@ -1250,15 +1232,6 @@ void wxBitmap::SetPixmap( GdkPixmap *pixmap )
PurgeOtherRepresentations(Pixmap); PurgeOtherRepresentations(Pixmap);
} }
void wxBitmap::SetBitmap( GdkPixmap *bitmap )
{
if (!m_refData)
m_refData = new wxBitmapRefData();
M_BMPDATA->m_bitmap = bitmap;
PurgeOtherRepresentations(Pixmap);
}
GdkPixmap *wxBitmap::GetPixmap() const GdkPixmap *wxBitmap::GetPixmap() const
{ {
wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, wxT("invalid bitmap") ); wxCHECK_MSG( Ok(), (GdkPixmap *) NULL, wxT("invalid bitmap") );
@@ -1284,13 +1257,6 @@ bool wxBitmap::HasPixmap() const
return M_BMPDATA->m_pixmap != NULL; return M_BMPDATA->m_pixmap != NULL;
} }
GdkBitmap *wxBitmap::GetBitmap() const
{
wxCHECK_MSG( Ok(), (GdkBitmap *) NULL, wxT("invalid bitmap") );
return M_BMPDATA->m_bitmap;
}
GdkPixbuf *wxBitmap::GetPixbuf() const GdkPixbuf *wxBitmap::GetPixbuf() const
{ {
wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ); wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );

View File

@@ -1069,7 +1069,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap,
wxCHECK_RET( bitmap.Ok(), wxT("invalid bitmap") ); wxCHECK_RET( bitmap.Ok(), wxT("invalid bitmap") );
bool is_mono = (bitmap.GetBitmap() != NULL); bool is_mono = bitmap.GetDepth() == 1;
// scale/translate size and position // scale/translate size and position
int xx = XLOG2DEV(x); int xx = XLOG2DEV(x);
@@ -1162,7 +1162,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap,
GdkGC *gc = gdk_gc_new( bitmap2 ); GdkGC *gc = gdk_gc_new( bitmap2 );
gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() ); gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() );
gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() ); gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() );
gdk_wx_draw_bitmap( bitmap2, gc, use_bitmap.GetBitmap(), 0, 0, 0, 0, -1, -1 ); gdk_wx_draw_bitmap( bitmap2, gc, use_bitmap.GetPixmap(), 0, 0, 0, 0, -1, -1 );
gdk_draw_drawable( m_window, m_textGC, bitmap2, 0, 0, xx, yy, -1, -1 ); gdk_draw_drawable( m_window, m_textGC, bitmap2, 0, 0, xx, yy, -1, -1 );
@@ -1416,7 +1416,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest,
GdkGC *gc = gdk_gc_new( bitmap ); GdkGC *gc = gdk_gc_new( bitmap );
gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() ); gdk_gc_set_foreground( gc, m_textForegroundColour.GetColor() );
gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() ); gdk_gc_set_background( gc, m_textBackgroundColour.GetColor() );
gdk_wx_draw_bitmap( bitmap, gc, use_bitmap.GetBitmap(), 0, 0, 0, 0, -1, -1 ); gdk_wx_draw_bitmap( bitmap, gc, use_bitmap.GetPixmap(), 0, 0, 0, 0, -1, -1 );
gdk_draw_drawable( m_window, m_textGC, bitmap, xsrc, ysrc, cx, cy, cw, ch ); gdk_draw_drawable( m_window, m_textGC, bitmap, xsrc, ysrc, cx, cy, cw, ch );
@@ -2009,7 +2009,7 @@ void wxWindowDC::SetBrush( const wxBrush &brush )
if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->Ok())) if ((m_brush.GetStyle() == wxSTIPPLE) && (m_brush.GetStipple()->Ok()))
{ {
if (m_brush.GetStipple()->GetPixmap()) if (m_brush.GetStipple()->GetDepth() != 1)
{ {
gdk_gc_set_fill( m_brushGC, GDK_TILED ); gdk_gc_set_fill( m_brushGC, GDK_TILED );
gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() ); gdk_gc_set_tile( m_brushGC, m_brush.GetStipple()->GetPixmap() );
@@ -2017,7 +2017,7 @@ void wxWindowDC::SetBrush( const wxBrush &brush )
else else
{ {
gdk_gc_set_fill( m_brushGC, GDK_STIPPLED ); gdk_gc_set_fill( m_brushGC, GDK_STIPPLED );
gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetBitmap() ); gdk_gc_set_stipple( m_brushGC, m_brush.GetStipple()->GetPixmap() );
} }
} }
@@ -2060,7 +2060,7 @@ void wxWindowDC::SetBackground( const wxBrush &brush )
if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok())) if ((m_backgroundBrush.GetStyle() == wxSTIPPLE) && (m_backgroundBrush.GetStipple()->Ok()))
{ {
if (m_backgroundBrush.GetStipple()->GetPixmap()) if (m_backgroundBrush.GetStipple()->GetDepth() != 1)
{ {
gdk_gc_set_fill( m_bgGC, GDK_TILED ); gdk_gc_set_fill( m_bgGC, GDK_TILED );
gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() ); gdk_gc_set_tile( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
@@ -2068,7 +2068,7 @@ void wxWindowDC::SetBackground( const wxBrush &brush )
else else
{ {
gdk_gc_set_fill( m_bgGC, GDK_STIPPLED ); gdk_gc_set_fill( m_bgGC, GDK_STIPPLED );
gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetBitmap() ); gdk_gc_set_stipple( m_bgGC, m_backgroundBrush.GetStipple()->GetPixmap() );
} }
} }

View File

@@ -59,14 +59,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
m_selected = bitmap; m_selected = bitmap;
if (m_selected.Ok()) if (m_selected.Ok())
{ {
if (m_selected.GetPixmap()) m_window = m_selected.GetPixmap();
{
m_window = m_selected.GetPixmap();
}
else
{
m_window = m_selected.GetBitmap();
}
m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap); m_selected.PurgeOtherRepresentations(wxBitmap::Pixmap);
@@ -85,7 +78,7 @@ void wxMemoryDC::SetPen( const wxPen& penOrig )
{ {
wxPen pen( penOrig ); wxPen pen( penOrig );
if ( m_selected.Ok() && if ( m_selected.Ok() &&
m_selected.GetBitmap() && m_selected.GetDepth() == 1 &&
(pen != *wxTRANSPARENT_PEN) ) (pen != *wxTRANSPARENT_PEN) )
{ {
pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE ); pen.SetColour( pen.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
@@ -98,7 +91,7 @@ void wxMemoryDC::SetBrush( const wxBrush& brushOrig )
{ {
wxBrush brush( brushOrig ); wxBrush brush( brushOrig );
if ( m_selected.Ok() && if ( m_selected.Ok() &&
m_selected.GetBitmap() && m_selected.GetDepth() == 1 &&
(brush != *wxTRANSPARENT_BRUSH) ) (brush != *wxTRANSPARENT_BRUSH) )
{ {
brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE); brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE);
@@ -112,7 +105,7 @@ void wxMemoryDC::SetBackground( const wxBrush& brushOrig )
wxBrush brush(brushOrig); wxBrush brush(brushOrig);
if ( m_selected.Ok() && if ( m_selected.Ok() &&
m_selected.GetBitmap() && m_selected.GetDepth() == 1 &&
(brush != *wxTRANSPARENT_BRUSH) ) (brush != *wxTRANSPARENT_BRUSH) )
{ {
brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE ); brush.SetColour( brush.GetColour() == *wxWHITE ? *wxBLACK : *wxWHITE );
@@ -123,7 +116,7 @@ void wxMemoryDC::SetBackground( const wxBrush& brushOrig )
void wxMemoryDC::SetTextForeground( const wxColour& col ) void wxMemoryDC::SetTextForeground( const wxColour& col )
{ {
if ( m_selected.Ok() && m_selected.GetBitmap() ) if ( m_selected.Ok() && m_selected.GetDepth() == 1 )
{ {
wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE); wxWindowDC::SetTextForeground( col == *wxWHITE ? *wxBLACK : *wxWHITE);
} }
@@ -135,7 +128,7 @@ void wxMemoryDC::SetTextForeground( const wxColour& col )
void wxMemoryDC::SetTextBackground( const wxColour &col ) void wxMemoryDC::SetTextBackground( const wxColour &col )
{ {
if (m_selected.Ok() && m_selected.GetBitmap()) if (m_selected.Ok() && m_selected.GetDepth() == 1)
{ {
wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE ); wxWindowDC::SetTextBackground( col == *wxWHITE ? *wxBLACK : *wxWHITE );
} }

View File

@@ -365,7 +365,7 @@ bool wxToolBar::DoInsertTool(size_t pos, wxToolBarToolBase *toolBase)
wxCHECK_MSG( bitmap.Ok(), false, wxCHECK_MSG( bitmap.Ok(), false,
wxT("invalid bitmap for wxToolBar icon") ); wxT("invalid bitmap for wxToolBar icon") );
wxCHECK_MSG( bitmap.GetBitmap() == NULL, false, wxCHECK_MSG( bitmap.GetDepth() != 1, false,
wxT("wxToolBar doesn't support GdkBitmap") ); wxT("wxToolBar doesn't support GdkBitmap") );
wxCHECK_MSG( bitmap.GetPixmap() != NULL, false, wxCHECK_MSG( bitmap.GetPixmap() != NULL, false,