diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c index f235ace6e..b7b547a78 100644 --- a/src/st/st-texture-cache.c +++ b/src/st/st-texture-cache.c @@ -742,12 +742,10 @@ typedef struct { } StTextureCachePropertyBind; static void -st_texture_cache_reset_texture (StTextureCachePropertyBind *bind, - const char *propname) +st_texture_cache_load_surface (ClutterContent **image, + cairo_surface_t *surface) { - cairo_surface_t *surface; - - g_object_get (bind->source, propname, &surface, NULL); + g_return_if_fail (image != NULL); if (surface != NULL && cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE && @@ -761,10 +759,10 @@ st_texture_cache_reset_texture (StTextureCachePropertyBind *bind, height = cairo_image_surface_get_width (surface); size = MAX(width, height); - if (!bind->image) - bind->image = st_image_content_new_with_preferred_size (size, size); + if (*image == NULL) + *image = st_image_content_new_with_preferred_size (size, size); - clutter_image_set_data (CLUTTER_IMAGE (bind->image), + clutter_image_set_data (CLUTTER_IMAGE (*image), cairo_image_surface_get_data (surface), cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32 ? COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888, @@ -776,12 +774,23 @@ st_texture_cache_reset_texture (StTextureCachePropertyBind *bind, if (error) g_warning ("Failed to allocate texture: %s", error->message); } - else if (!bind->image) + else if (*image == NULL) { - bind->image = st_image_content_new_with_preferred_size (0, 0); + *image = st_image_content_new_with_preferred_size (0, 0); } } +static void +st_texture_cache_reset_texture (StTextureCachePropertyBind *bind, + const char *propname) +{ + cairo_surface_t *surface; + + g_object_get (bind->source, propname, &surface, NULL); + + st_texture_cache_load_surface (&bind->image, surface); +} + static void st_texture_cache_on_pixbuf_notify (GObject *object, GParamSpec *paramspec, @@ -849,6 +858,25 @@ st_texture_cache_bind_cairo_surface_property (StTextureCache *cache, return G_ICON (bind->image); } +/** + * st_texture_cache_load_cairo_surface_to_gicon: + * @cache: A #StTextureCache + * @surface: A #cairo_surface_t + * + * Create a #GIcon from @surface. + * + * Returns: (transfer full): A new #GIcon + */ +GIcon * +st_texture_cache_load_cairo_surface_to_gicon (StTextureCache *cache, + cairo_surface_t *surface) +{ + ClutterContent *image = NULL; + st_texture_cache_load_surface (&image, surface); + + return G_ICON (image); +} + /** * st_texture_cache_load: (skip) * @cache: A #StTextureCache diff --git a/src/st/st-texture-cache.h b/src/st/st-texture-cache.h index 0e8407ea2..55d84952d 100644 --- a/src/st/st-texture-cache.h +++ b/src/st/st-texture-cache.h @@ -67,6 +67,9 @@ st_texture_cache_load_sliced_image (StTextureCache *cache, GIcon *st_texture_cache_bind_cairo_surface_property (StTextureCache *cache, GObject *object, const char *property_name); +GIcon * +st_texture_cache_load_cairo_surface_to_gicon (StTextureCache *cache, + cairo_surface_t *surface); ClutterActor *st_texture_cache_load_gicon (StTextureCache *cache, StThemeNode *theme_node,