st/texture-cache: Split out load_cairo_surface_to_gicon() method

This is essentially st_texture_cache_bind_cairo_surface_property()
without the binding part.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1761>
This commit is contained in:
Florian Müllner 2021-03-13 00:07:05 +01:00 committed by Marge Bot
parent 5652550688
commit 07a819f62b
2 changed files with 41 additions and 10 deletions

View File

@ -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

View File

@ -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,