[gnome-shell] st/texture-cache: Split out load_cairo_surface_to_gicon() method
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] st/texture-cache: Split out load_cairo_surface_to_gicon() method
- Date: Sun, 14 Mar 2021 20:41:08 +0000 (UTC)
commit 07a819f62bfb9355f5a3b8caa98c7733260edb33
Author: Florian Müllner <fmuellner gnome org>
Date: Sat Mar 13 00:07:05 2021 +0100
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>
src/st/st-texture-cache.c | 48 +++++++++++++++++++++++++++++++++++++----------
src/st/st-texture-cache.h | 3 +++
2 files changed, 41 insertions(+), 10 deletions(-)
---
diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c
index f235ace6ec..b7b547a782 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 0e8407ea26..55d84952d6 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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]