iconhelper: Refactor ensure_surface()

Make gtk_icon_helper_ensure_surface() a private function that just
ensures the surface was loaded.

Add gtk_icon_helper_load_surface() that is called by the above function
and the dnd code to actually load the surface.
This commit is contained in:
Benjamin Otte 2015-11-30 00:55:43 +01:00
parent 2ce67f0098
commit afad393b15
3 changed files with 26 additions and 22 deletions

View File

@ -884,8 +884,8 @@ gtk_drag_get_cursor (GtkWidget *widget,
_gtk_icon_helper_get_size (info->icon_helper,
gtk_widget_get_style_context (widget),
&icon_width, &icon_height);
icon_surface = _gtk_icon_helper_ensure_surface (info->icon_helper,
gtk_widget_get_style_context (widget));
icon_surface = gtk_icon_helper_load_surface (info->icon_helper,
gtk_widget_get_style_context (widget));
icon_x = info->hot_x;
icon_y = info->hot_y;
@ -2791,7 +2791,7 @@ set_icon_helper (GdkDragContext *context,
gtk_widget_set_size_request (window, width, height);
source = _gtk_icon_helper_ensure_surface (helper, gtk_widget_get_style_context (window));
source = gtk_icon_helper_load_surface (helper, gtk_widget_get_style_context (window));
surface = gdk_window_create_similar_surface (gdk_screen_get_root_window (screen),
CAIRO_CONTENT_COLOR,
width, height);

View File

@ -727,16 +727,13 @@ ensure_surface_for_gicon (GtkIconHelper *self,
}
cairo_surface_t *
_gtk_icon_helper_ensure_surface (GtkIconHelper *self,
GtkStyleContext *context)
gtk_icon_helper_load_surface (GtkIconHelper *self,
GtkStyleContext *context)
{
cairo_surface_t *surface;
GtkIconSet *icon_set;
GIcon *gicon;
if (!check_invalidate_surface (self, context))
return self->priv->rendered_surface;
switch (gtk_image_definition_get_storage_type (self->priv->def))
{
case GTK_IMAGE_SURFACE:
@ -784,9 +781,18 @@ _gtk_icon_helper_ensure_surface (GtkIconHelper *self,
break;
}
self->priv->rendered_surface = surface;
return surface;
return cairo_surface_reference (surface);
}
static void
gtk_icon_helper_ensure_surface (GtkIconHelper *self,
GtkStyleContext *context)
{
if (!check_invalidate_surface (self, context))
return;
self->priv->rendered_surface = gtk_icon_helper_load_surface (self, context);
}
void
@ -795,7 +801,6 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
gint *width_out,
gint *height_out)
{
cairo_surface_t *surface;
gint width, height, scale;
width = height = 0;
@ -846,12 +851,11 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
/* Otherwise we load the surface to guarantee we get a size */
if (width == 0)
{
surface = _gtk_icon_helper_ensure_surface (self, context);
gtk_icon_helper_ensure_surface (self, context);
if (surface != NULL)
if (self->priv->rendered_surface != NULL)
{
get_surface_size (self, surface, &width, &height);
cairo_surface_destroy (surface);
get_surface_size (self, self->priv->rendered_surface, &width, &height);
}
else if (self->priv->icon_size != GTK_ICON_SIZE_INVALID)
{
@ -1046,13 +1050,13 @@ _gtk_icon_helper_draw (GtkIconHelper *self,
gdouble x,
gdouble y)
{
cairo_surface_t *surface;
gtk_icon_helper_ensure_surface (self, context);
surface = _gtk_icon_helper_ensure_surface (self, context);
if (surface != NULL)
if (self->priv->rendered_surface != NULL)
{
gtk_render_icon_surface (context, cr, surface, x, y);
cairo_surface_destroy (surface);
gtk_render_icon_surface (context, cr,
self->priv->rendered_surface,
x, y);
}
}

View File

@ -121,8 +121,8 @@ cairo_surface_t *_gtk_icon_helper_peek_surface (GtkIconHelper *self);
const gchar *_gtk_icon_helper_get_stock_id (GtkIconHelper *self);
const gchar *_gtk_icon_helper_get_icon_name (GtkIconHelper *self);
cairo_surface_t *_gtk_icon_helper_ensure_surface (GtkIconHelper *self,
GtkStyleContext *context);
cairo_surface_t *gtk_icon_helper_load_surface (GtkIconHelper *self,
GtkStyleContext *context);
GdkPixbuf *_gtk_icon_helper_ensure_pixbuf (GtkIconHelper *self,
GtkStyleContext *context);
void _gtk_icon_helper_get_size (GtkIconHelper *self,