Drop pixbuf support in IconHelper and ImageDefinition

These are no longer used, instead we always covert to surface as
early as possible and drop the pixbuf.

This means we never store both the pixbuf and the surface at
for any longer time, which is wasteful. Also, its one step further
to drop GdkPixbufs from generic use in our APIs.
This commit is contained in:
Alexander Larsson
2017-10-23 15:25:46 +02:00
parent 61b2ab5d90
commit 0089e4ad58
9 changed files with 4 additions and 131 deletions

View File

@@ -298,7 +298,6 @@ gtk_image_accessible_get_image_size (AtkImage *image,
break;
}
case GTK_IMAGE_EMPTY:
case GTK_IMAGE_PIXBUF:
default:
{
*height = -1;

View File

@@ -295,9 +295,6 @@ notify_storage_type (GtkCellRendererPixbuf *cellpixbuf,
case GTK_IMAGE_SURFACE:
g_object_notify (G_OBJECT (cellpixbuf), "surface");
break;
case GTK_IMAGE_PIXBUF:
g_object_notify (G_OBJECT (cellpixbuf), "pixbuf");
break;
case GTK_IMAGE_ICON_NAME:
g_object_notify (G_OBJECT (cellpixbuf), "icon-name");
break;
@@ -416,7 +413,7 @@ create_icon_helper (GtkIconHelper *icon_helper,
widget);
_gtk_icon_helper_set_force_scale_pixbuf (icon_helper, TRUE);
_gtk_icon_helper_set_definition (icon_helper, priv->image_def);
if (gtk_image_definition_get_storage_type (priv->image_def) != GTK_IMAGE_PIXBUF)
if (gtk_image_definition_get_storage_type (priv->image_def) != GTK_IMAGE_SURFACE)
_gtk_icon_helper_set_icon_size (icon_helper, priv->icon_size);
}

View File

@@ -6643,7 +6643,6 @@ gtk_entry_clear_icon (GtkEntry *entry,
case GTK_IMAGE_EMPTY:
case GTK_IMAGE_ANIMATION:
case GTK_IMAGE_PIXBUF:
default:
g_assert_not_reached ();
break;

View File

@@ -284,34 +284,6 @@ get_pixbuf_size (GtkIconHelper *self,
return scale_pixmap;
}
static cairo_surface_t *
ensure_surface_from_pixbuf (GtkIconHelper *self,
GtkCssStyle *style,
gint scale,
GdkPixbuf *orig_pixbuf,
gint orig_scale)
{
gint width, height;
cairo_surface_t *surface;
GdkPixbuf *pixbuf;
if (get_pixbuf_size (self,
scale,
orig_pixbuf,
orig_scale,
&width, &height, &scale))
pixbuf = gdk_pixbuf_scale_simple (orig_pixbuf,
width, height,
GDK_INTERP_BILINEAR);
else
pixbuf = g_object_ref (orig_pixbuf);
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, _gtk_widget_get_window (self->owner));
g_object_unref (pixbuf);
return surface;
}
static cairo_surface_t *
ensure_surface_for_gicon (GtkIconHelper *self,
GtkCssStyle *style,
@@ -405,14 +377,6 @@ gtk_icon_helper_load_surface (GtkIconHelper *self,
surface = ensure_surface_from_surface (self, gtk_image_definition_get_surface (self->def));
break;
case GTK_IMAGE_PIXBUF:
surface = ensure_surface_from_pixbuf (self,
gtk_css_node_get_style (self->node),
scale,
gtk_image_definition_get_pixbuf (self->def),
gtk_image_definition_get_scale (self->def));
break;
case GTK_IMAGE_ICON_NAME:
if (self->use_fallback)
gicon = g_themed_icon_new_with_default_fallbacks (gtk_image_definition_get_icon_name (self->def));
@@ -491,7 +455,6 @@ find_cached_texture (GtkIconHelper *self)
gicon = g_themed_icon_new (gtk_image_definition_get_icon_name (self->def));
break;
case GTK_IMAGE_EMPTY:
case GTK_IMAGE_PIXBUF:
case GTK_IMAGE_ANIMATION:
case GTK_IMAGE_SURFACE:
default:
@@ -566,7 +529,7 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
gint *width_out,
gint *height_out)
{
gint width, height, scale;
gint width, height;
width = height = 0;
@@ -582,16 +545,6 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
&height);
break;
case GTK_IMAGE_PIXBUF:
get_pixbuf_size (self,
gtk_widget_get_scale_factor (self->owner),
gtk_image_definition_get_pixbuf (self->def),
gtk_image_definition_get_scale (self->def),
&width, &height, &scale);
width = (width + scale - 1) / scale;
height = (height + scale - 1) / scale;
break;
case GTK_IMAGE_ANIMATION:
{
GdkPixbufAnimation *animation = gtk_image_definition_get_animation (self->def);
@@ -661,13 +614,6 @@ _gtk_icon_helper_set_icon_name (GtkIconHelper *self,
_gtk_icon_helper_set_icon_size (self, icon_size);
}
void
_gtk_icon_helper_set_pixbuf (GtkIconHelper *self,
GdkPixbuf *pixbuf)
{
gtk_icon_helper_take_definition (self, gtk_image_definition_new_pixbuf (pixbuf, 1));
}
void
_gtk_icon_helper_set_animation (GtkIconHelper *self,
GdkPixbufAnimation *animation)
@@ -751,12 +697,6 @@ gtk_icon_helper_get_definition (GtkIconHelper *self)
return self->def;
}
GdkPixbuf *
_gtk_icon_helper_peek_pixbuf (GtkIconHelper *self)
{
return gtk_image_definition_get_pixbuf (self->def);
}
GIcon *
_gtk_icon_helper_peek_gicon (GtkIconHelper *self)
{
@@ -849,12 +789,6 @@ _gtk_icon_helper_set_pixbuf_scale (GtkIconHelper *self,
{
switch (gtk_image_definition_get_storage_type (self->def))
{
case GTK_IMAGE_PIXBUF:
gtk_icon_helper_take_definition (self,
gtk_image_definition_new_pixbuf (gtk_image_definition_get_pixbuf (self->def),
scale));
break;
case GTK_IMAGE_ANIMATION:
gtk_icon_helper_take_definition (self,
gtk_image_definition_new_animation (gtk_image_definition_get_animation (self->def),

View File

@@ -64,8 +64,6 @@ void _gtk_icon_helper_set_definition (GtkIconHelper *self,
void _gtk_icon_helper_set_gicon (GtkIconHelper *self,
GIcon *gicon,
GtkIconSize icon_size);
void _gtk_icon_helper_set_pixbuf (GtkIconHelper *self,
GdkPixbuf *pixbuf);
void _gtk_icon_helper_set_pixbuf_scale (GtkIconHelper *self,
int scale);
void _gtk_icon_helper_set_animation (GtkIconHelper *self,
@@ -89,7 +87,6 @@ GtkIconSize _gtk_icon_helper_get_icon_size (GtkIconHelper *self);
gint _gtk_icon_helper_get_pixel_size (GtkIconHelper *self);
gboolean _gtk_icon_helper_get_use_fallback (GtkIconHelper *self);
GdkPixbuf *_gtk_icon_helper_peek_pixbuf (GtkIconHelper *self);
GIcon *_gtk_icon_helper_peek_gicon (GtkIconHelper *self);
GdkPixbufAnimation *_gtk_icon_helper_peek_animation (GtkIconHelper *self);
cairo_surface_t *_gtk_icon_helper_peek_surface (GtkIconHelper *self);

View File

@@ -1378,9 +1378,6 @@ gtk_image_notify_for_storage_type (GtkImage *image,
case GTK_IMAGE_SURFACE:
g_object_notify_by_pspec (G_OBJECT (image), image_props[PROP_SURFACE]);
break;
case GTK_IMAGE_PIXBUF:
g_warning ("pixbuf not supported");
break;
case GTK_IMAGE_EMPTY:
default:
break;

View File

@@ -51,7 +51,6 @@ typedef struct _GtkImageClass GtkImageClass;
/**
* GtkImageType:
* @GTK_IMAGE_EMPTY: there is no image displayed by the widget
* @GTK_IMAGE_PIXBUF: the widget contains a #GdkPixbuf
* @GTK_IMAGE_ANIMATION: the widget contains a #GdkPixbufAnimation
* @GTK_IMAGE_ICON_NAME: the widget contains a named icon.
* This image type was added in GTK+ 2.6
@@ -63,19 +62,14 @@ typedef struct _GtkImageClass GtkImageClass;
* Describes the image data representation used by a #GtkImage. If you
* want to get the image from the widget, you can only get the
* currently-stored representation. e.g. if the
* gtk_image_get_storage_type() returns #GTK_IMAGE_PIXBUF, then you can
* call gtk_image_get_pixbuf(). For empty images, you can request any
* gtk_image_get_storage_type() returns #GTK_IMAGE_SURFACE, then you can
* call gtk_image_get_surface(). For empty images, you can request any
* storage type (call any of the "get" functions), but they will all
* return %NULL values.
*
* Note: GTK_IMAGE_PIXBUF is not not supported as storage by GtkImage. Any
* pixbuf set on the GtkImage will be converted to a surface and can only
* be read back as a GTK_IMAGE_SURFACE.
*/
typedef enum
{
GTK_IMAGE_EMPTY,
GTK_IMAGE_PIXBUF,
GTK_IMAGE_ANIMATION,
GTK_IMAGE_ICON_NAME,
GTK_IMAGE_GICON,

View File

@@ -20,7 +20,6 @@
#include "gtkimagedefinitionprivate.h"
typedef struct _GtkImageDefinitionEmpty GtkImageDefinitionEmpty;
typedef struct _GtkImageDefinitionPixbuf GtkImageDefinitionPixbuf;
typedef struct _GtkImageDefinitionStock GtkImageDefinitionStock;
typedef struct _GtkImageDefinitionAnimation GtkImageDefinitionAnimation;
typedef struct _GtkImageDefinitionIconName GtkImageDefinitionIconName;
@@ -32,14 +31,6 @@ struct _GtkImageDefinitionEmpty {
gint ref_count;
};
struct _GtkImageDefinitionPixbuf {
GtkImageType type;
gint ref_count;
GdkPixbuf *pixbuf;
int scale;
};
struct _GtkImageDefinitionStock {
GtkImageType type;
gint ref_count;
@@ -80,7 +71,6 @@ union _GtkImageDefinition
{
GtkImageType type;
GtkImageDefinitionEmpty empty;
GtkImageDefinitionPixbuf pixbuf;
GtkImageDefinitionStock stock;
GtkImageDefinitionAnimation animation;
GtkImageDefinitionIconName icon_name;
@@ -101,7 +91,6 @@ gtk_image_definition_alloc (GtkImageType type)
{
static gsize sizes[] = {
sizeof (GtkImageDefinitionEmpty),
sizeof (GtkImageDefinitionPixbuf),
sizeof (GtkImageDefinitionStock),
sizeof (GtkImageDefinitionAnimation),
sizeof (GtkImageDefinitionIconName),
@@ -119,22 +108,6 @@ gtk_image_definition_alloc (GtkImageType type)
return def;
}
GtkImageDefinition *
gtk_image_definition_new_pixbuf (GdkPixbuf *pixbuf,
int scale)
{
GtkImageDefinition *def;
if (pixbuf == NULL || scale <= 0)
return NULL;
def = gtk_image_definition_alloc (GTK_IMAGE_PIXBUF);
def->pixbuf.pixbuf = g_object_ref (pixbuf);
def->pixbuf.scale = scale;
return def;
}
GtkImageDefinition *
gtk_image_definition_new_animation (GdkPixbufAnimation *animation,
int scale)
@@ -215,9 +188,6 @@ gtk_image_definition_unref (GtkImageDefinition *def)
case GTK_IMAGE_EMPTY:
g_assert_not_reached ();
break;
case GTK_IMAGE_PIXBUF:
g_object_unref (def->pixbuf.pixbuf);
break;
case GTK_IMAGE_ANIMATION:
g_object_unref (def->animation.animation);
break;
@@ -253,22 +223,11 @@ gtk_image_definition_get_scale (const GtkImageDefinition *def)
case GTK_IMAGE_ICON_NAME:
case GTK_IMAGE_GICON:
return 1;
case GTK_IMAGE_PIXBUF:
return def->pixbuf.scale;
case GTK_IMAGE_ANIMATION:
return def->animation.scale;
}
}
GdkPixbuf *
gtk_image_definition_get_pixbuf (const GtkImageDefinition *def)
{
if (def->type != GTK_IMAGE_PIXBUF)
return NULL;
return def->pixbuf.pixbuf;
}
GdkPixbufAnimation *
gtk_image_definition_get_animation (const GtkImageDefinition *def)
{

View File

@@ -26,8 +26,6 @@ G_BEGIN_DECLS
typedef union _GtkImageDefinition GtkImageDefinition;
GtkImageDefinition * gtk_image_definition_new_empty (void);
GtkImageDefinition * gtk_image_definition_new_pixbuf (GdkPixbuf *pixbuf,
int scale);
GtkImageDefinition * gtk_image_definition_new_animation (GdkPixbufAnimation *animation,
int scale);
GtkImageDefinition * gtk_image_definition_new_icon_name (const char *icon_name);
@@ -39,7 +37,6 @@ void gtk_image_definition_unref (GtkImageDefinit
GtkImageType gtk_image_definition_get_storage_type (const GtkImageDefinition *def);
gint gtk_image_definition_get_scale (const GtkImageDefinition *def);
GdkPixbuf * gtk_image_definition_get_pixbuf (const GtkImageDefinition *def);
GdkPixbufAnimation * gtk_image_definition_get_animation (const GtkImageDefinition *def);
const gchar * gtk_image_definition_get_icon_name (const GtkImageDefinition *def);
GIcon * gtk_image_definition_get_gicon (const GtkImageDefinition *def);