mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-07 11:20:09 +00:00
iconhelper: Store surface in ensure_surface()
Do not assign it in the functions that actually load the surface. Make those just return the surface.
This commit is contained in:
parent
b2584eb8ed
commit
2ce67f0098
@ -539,13 +539,12 @@ check_invalidate_surface (GtkIconHelper *self,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static cairo_surface_t *
|
||||||
ensure_surface_from_surface (GtkIconHelper *self,
|
ensure_surface_from_surface (GtkIconHelper *self,
|
||||||
GtkStyleContext *context,
|
GtkStyleContext *context,
|
||||||
cairo_surface_t *orig_surface)
|
cairo_surface_t *orig_surface)
|
||||||
{
|
{
|
||||||
self->priv->rendered_surface =
|
return cairo_surface_reference (orig_surface);
|
||||||
cairo_surface_reference (orig_surface);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -600,13 +599,14 @@ get_pixbuf_size (GtkIconHelper *self,
|
|||||||
return scale_pixmap;
|
return scale_pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static cairo_surface_t *
|
||||||
ensure_surface_from_pixbuf (GtkIconHelper *self,
|
ensure_surface_from_pixbuf (GtkIconHelper *self,
|
||||||
GtkStyleContext *context,
|
GtkStyleContext *context,
|
||||||
GdkPixbuf *orig_pixbuf,
|
GdkPixbuf *orig_pixbuf,
|
||||||
gint orig_scale)
|
gint orig_scale)
|
||||||
{
|
{
|
||||||
gint width, height;
|
gint width, height;
|
||||||
|
cairo_surface_t *surface;
|
||||||
GdkPixbuf *pixbuf, *stated;
|
GdkPixbuf *pixbuf, *stated;
|
||||||
int scale;
|
int scale;
|
||||||
|
|
||||||
@ -625,28 +625,26 @@ ensure_surface_from_pixbuf (GtkIconHelper *self,
|
|||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
pixbuf = stated;
|
pixbuf = stated;
|
||||||
|
|
||||||
self->priv->rendered_surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, self->priv->window);
|
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, self->priv->window);
|
||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
|
|
||||||
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static cairo_surface_t *
|
||||||
ensure_surface_for_icon_set (GtkIconHelper *self,
|
ensure_surface_for_icon_set (GtkIconHelper *self,
|
||||||
GtkStyleContext *context,
|
GtkStyleContext *context,
|
||||||
GtkIconSet *icon_set)
|
GtkIconSet *icon_set)
|
||||||
{
|
{
|
||||||
gint scale;
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
||||||
|
return gtk_icon_set_render_icon_surface (icon_set, context,
|
||||||
scale = get_scale_factor (self, context);
|
self->priv->icon_size,
|
||||||
|
get_scale_factor (self, context),
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
self->priv->window);
|
||||||
self->priv->rendered_surface =
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
||||||
gtk_icon_set_render_icon_surface (icon_set, context,
|
|
||||||
self->priv->icon_size,
|
|
||||||
scale, self->priv->window);
|
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static cairo_surface_t *
|
||||||
ensure_stated_surface_from_info (GtkIconHelper *self,
|
ensure_stated_surface_from_info (GtkIconHelper *self,
|
||||||
GtkStyleContext *context,
|
GtkStyleContext *context,
|
||||||
GtkIconInfo *info,
|
GtkIconInfo *info,
|
||||||
@ -695,10 +693,10 @@ ensure_stated_surface_from_info (GtkIconHelper *self,
|
|||||||
g_object_unref (destination);
|
g_object_unref (destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
self->priv->rendered_surface = surface;
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static cairo_surface_t *
|
||||||
ensure_surface_for_gicon (GtkIconHelper *self,
|
ensure_surface_for_gicon (GtkIconHelper *self,
|
||||||
GtkStyleContext *context,
|
GtkStyleContext *context,
|
||||||
GIcon *gicon)
|
GIcon *gicon)
|
||||||
@ -707,6 +705,7 @@ ensure_surface_for_gicon (GtkIconHelper *self,
|
|||||||
gint width, height, scale;
|
gint width, height, scale;
|
||||||
GtkIconInfo *info;
|
GtkIconInfo *info;
|
||||||
GtkIconLookupFlags flags;
|
GtkIconLookupFlags flags;
|
||||||
|
cairo_surface_t *surface;
|
||||||
|
|
||||||
icon_theme = gtk_icon_theme_get_for_screen (gtk_style_context_get_screen (context));
|
icon_theme = gtk_icon_theme_get_for_screen (gtk_style_context_get_screen (context));
|
||||||
flags = get_icon_lookup_flags (self, context);
|
flags = get_icon_lookup_flags (self, context);
|
||||||
@ -719,17 +718,19 @@ ensure_surface_for_gicon (GtkIconHelper *self,
|
|||||||
MIN (width, height),
|
MIN (width, height),
|
||||||
scale, flags);
|
scale, flags);
|
||||||
|
|
||||||
ensure_stated_surface_from_info (self, context, info, scale);
|
surface = ensure_stated_surface_from_info (self, context, info, scale);
|
||||||
|
|
||||||
if (info)
|
if (info)
|
||||||
g_object_unref (info);
|
g_object_unref (info);
|
||||||
|
|
||||||
|
return surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_surface_t *
|
cairo_surface_t *
|
||||||
_gtk_icon_helper_ensure_surface (GtkIconHelper *self,
|
_gtk_icon_helper_ensure_surface (GtkIconHelper *self,
|
||||||
GtkStyleContext *context)
|
GtkStyleContext *context)
|
||||||
{
|
{
|
||||||
cairo_surface_t *surface = NULL;
|
cairo_surface_t *surface;
|
||||||
GtkIconSet *icon_set;
|
GtkIconSet *icon_set;
|
||||||
GIcon *gicon;
|
GIcon *gicon;
|
||||||
|
|
||||||
@ -739,20 +740,20 @@ _gtk_icon_helper_ensure_surface (GtkIconHelper *self,
|
|||||||
switch (gtk_image_definition_get_storage_type (self->priv->def))
|
switch (gtk_image_definition_get_storage_type (self->priv->def))
|
||||||
{
|
{
|
||||||
case GTK_IMAGE_SURFACE:
|
case GTK_IMAGE_SURFACE:
|
||||||
ensure_surface_from_surface (self, context, gtk_image_definition_get_surface (self->priv->def));
|
surface = ensure_surface_from_surface (self, context, gtk_image_definition_get_surface (self->priv->def));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_IMAGE_PIXBUF:
|
case GTK_IMAGE_PIXBUF:
|
||||||
ensure_surface_from_pixbuf (self, context,
|
surface = ensure_surface_from_pixbuf (self, context,
|
||||||
gtk_image_definition_get_pixbuf (self->priv->def),
|
gtk_image_definition_get_pixbuf (self->priv->def),
|
||||||
gtk_image_definition_get_scale (self->priv->def));
|
gtk_image_definition_get_scale (self->priv->def));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_IMAGE_STOCK:
|
case GTK_IMAGE_STOCK:
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
||||||
icon_set = gtk_icon_factory_lookup_default (gtk_image_definition_get_stock (self->priv->def));
|
icon_set = gtk_icon_factory_lookup_default (gtk_image_definition_get_stock (self->priv->def));
|
||||||
if (icon_set != NULL)
|
if (icon_set != NULL)
|
||||||
ensure_surface_for_icon_set (self, context, icon_set);
|
surface = ensure_surface_for_icon_set (self, context, icon_set);
|
||||||
else
|
else
|
||||||
surface = NULL;
|
surface = NULL;
|
||||||
G_GNUC_END_IGNORE_DEPRECATIONS;
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
||||||
@ -760,7 +761,7 @@ _gtk_icon_helper_ensure_surface (GtkIconHelper *self,
|
|||||||
|
|
||||||
case GTK_IMAGE_ICON_SET:
|
case GTK_IMAGE_ICON_SET:
|
||||||
icon_set = gtk_image_definition_get_icon_set (self->priv->def);
|
icon_set = gtk_image_definition_get_icon_set (self->priv->def);
|
||||||
ensure_surface_for_icon_set (self, context, icon_set);
|
surface = ensure_surface_for_icon_set (self, context, icon_set);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_IMAGE_ICON_NAME:
|
case GTK_IMAGE_ICON_NAME:
|
||||||
@ -768,12 +769,12 @@ _gtk_icon_helper_ensure_surface (GtkIconHelper *self,
|
|||||||
gicon = g_themed_icon_new_with_default_fallbacks (gtk_image_definition_get_icon_name (self->priv->def));
|
gicon = g_themed_icon_new_with_default_fallbacks (gtk_image_definition_get_icon_name (self->priv->def));
|
||||||
else
|
else
|
||||||
gicon = g_themed_icon_new (gtk_image_definition_get_icon_name (self->priv->def));
|
gicon = g_themed_icon_new (gtk_image_definition_get_icon_name (self->priv->def));
|
||||||
ensure_surface_for_gicon (self, context, gicon);
|
surface = ensure_surface_for_gicon (self, context, gicon);
|
||||||
g_object_unref (gicon);
|
g_object_unref (gicon);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_IMAGE_GICON:
|
case GTK_IMAGE_GICON:
|
||||||
ensure_surface_for_gicon (self, context, gtk_image_definition_get_gicon (self->priv->def));
|
surface = ensure_surface_for_gicon (self, context, gtk_image_definition_get_gicon (self->priv->def));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GTK_IMAGE_ANIMATION:
|
case GTK_IMAGE_ANIMATION:
|
||||||
@ -783,11 +784,9 @@ _gtk_icon_helper_ensure_surface (GtkIconHelper *self,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (surface == NULL &&
|
self->priv->rendered_surface = surface;
|
||||||
self->priv->rendered_surface != NULL)
|
|
||||||
surface = cairo_surface_reference (self->priv->rendered_surface);
|
|
||||||
|
|
||||||
return surface;
|
return cairo_surface_reference (surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user