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:
@ -884,8 +884,8 @@ gtk_drag_get_cursor (GtkWidget *widget,
|
|||||||
_gtk_icon_helper_get_size (info->icon_helper,
|
_gtk_icon_helper_get_size (info->icon_helper,
|
||||||
gtk_widget_get_style_context (widget),
|
gtk_widget_get_style_context (widget),
|
||||||
&icon_width, &icon_height);
|
&icon_width, &icon_height);
|
||||||
icon_surface = _gtk_icon_helper_ensure_surface (info->icon_helper,
|
icon_surface = gtk_icon_helper_load_surface (info->icon_helper,
|
||||||
gtk_widget_get_style_context (widget));
|
gtk_widget_get_style_context (widget));
|
||||||
|
|
||||||
icon_x = info->hot_x;
|
icon_x = info->hot_x;
|
||||||
icon_y = info->hot_y;
|
icon_y = info->hot_y;
|
||||||
@ -2791,7 +2791,7 @@ set_icon_helper (GdkDragContext *context,
|
|||||||
|
|
||||||
gtk_widget_set_size_request (window, width, height);
|
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),
|
surface = gdk_window_create_similar_surface (gdk_screen_get_root_window (screen),
|
||||||
CAIRO_CONTENT_COLOR,
|
CAIRO_CONTENT_COLOR,
|
||||||
width, height);
|
width, height);
|
||||||
|
|||||||
@ -727,16 +727,13 @@ ensure_surface_for_gicon (GtkIconHelper *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cairo_surface_t *
|
cairo_surface_t *
|
||||||
_gtk_icon_helper_ensure_surface (GtkIconHelper *self,
|
gtk_icon_helper_load_surface (GtkIconHelper *self,
|
||||||
GtkStyleContext *context)
|
GtkStyleContext *context)
|
||||||
{
|
{
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
GtkIconSet *icon_set;
|
GtkIconSet *icon_set;
|
||||||
GIcon *gicon;
|
GIcon *gicon;
|
||||||
|
|
||||||
if (!check_invalidate_surface (self, context))
|
|
||||||
return self->priv->rendered_surface;
|
|
||||||
|
|
||||||
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:
|
||||||
@ -784,9 +781,18 @@ _gtk_icon_helper_ensure_surface (GtkIconHelper *self,
|
|||||||
break;
|
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
|
void
|
||||||
@ -795,7 +801,6 @@ _gtk_icon_helper_get_size (GtkIconHelper *self,
|
|||||||
gint *width_out,
|
gint *width_out,
|
||||||
gint *height_out)
|
gint *height_out)
|
||||||
{
|
{
|
||||||
cairo_surface_t *surface;
|
|
||||||
gint width, height, scale;
|
gint width, height, scale;
|
||||||
|
|
||||||
width = height = 0;
|
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 */
|
/* Otherwise we load the surface to guarantee we get a size */
|
||||||
if (width == 0)
|
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);
|
get_surface_size (self, self->priv->rendered_surface, &width, &height);
|
||||||
cairo_surface_destroy (surface);
|
|
||||||
}
|
}
|
||||||
else if (self->priv->icon_size != GTK_ICON_SIZE_INVALID)
|
else if (self->priv->icon_size != GTK_ICON_SIZE_INVALID)
|
||||||
{
|
{
|
||||||
@ -1046,13 +1050,13 @@ _gtk_icon_helper_draw (GtkIconHelper *self,
|
|||||||
gdouble x,
|
gdouble x,
|
||||||
gdouble y)
|
gdouble y)
|
||||||
{
|
{
|
||||||
cairo_surface_t *surface;
|
gtk_icon_helper_ensure_surface (self, context);
|
||||||
|
|
||||||
surface = _gtk_icon_helper_ensure_surface (self, context);
|
if (self->priv->rendered_surface != NULL)
|
||||||
if (surface != NULL)
|
|
||||||
{
|
{
|
||||||
gtk_render_icon_surface (context, cr, surface, x, y);
|
gtk_render_icon_surface (context, cr,
|
||||||
cairo_surface_destroy (surface);
|
self->priv->rendered_surface,
|
||||||
|
x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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_stock_id (GtkIconHelper *self);
|
||||||
const gchar *_gtk_icon_helper_get_icon_name (GtkIconHelper *self);
|
const gchar *_gtk_icon_helper_get_icon_name (GtkIconHelper *self);
|
||||||
|
|
||||||
cairo_surface_t *_gtk_icon_helper_ensure_surface (GtkIconHelper *self,
|
cairo_surface_t *gtk_icon_helper_load_surface (GtkIconHelper *self,
|
||||||
GtkStyleContext *context);
|
GtkStyleContext *context);
|
||||||
GdkPixbuf *_gtk_icon_helper_ensure_pixbuf (GtkIconHelper *self,
|
GdkPixbuf *_gtk_icon_helper_ensure_pixbuf (GtkIconHelper *self,
|
||||||
GtkStyleContext *context);
|
GtkStyleContext *context);
|
||||||
void _gtk_icon_helper_get_size (GtkIconHelper *self,
|
void _gtk_icon_helper_get_size (GtkIconHelper *self,
|
||||||
|
|||||||
Reference in New Issue
Block a user