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:
parent
5652550688
commit
07a819f62b
@ -742,12 +742,10 @@ typedef struct {
|
|||||||
} StTextureCachePropertyBind;
|
} StTextureCachePropertyBind;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
st_texture_cache_reset_texture (StTextureCachePropertyBind *bind,
|
st_texture_cache_load_surface (ClutterContent **image,
|
||||||
const char *propname)
|
cairo_surface_t *surface)
|
||||||
{
|
{
|
||||||
cairo_surface_t *surface;
|
g_return_if_fail (image != NULL);
|
||||||
|
|
||||||
g_object_get (bind->source, propname, &surface, NULL);
|
|
||||||
|
|
||||||
if (surface != NULL &&
|
if (surface != NULL &&
|
||||||
cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE &&
|
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);
|
height = cairo_image_surface_get_width (surface);
|
||||||
size = MAX(width, height);
|
size = MAX(width, height);
|
||||||
|
|
||||||
if (!bind->image)
|
if (*image == NULL)
|
||||||
bind->image = st_image_content_new_with_preferred_size (size, size);
|
*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_data (surface),
|
||||||
cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32 ?
|
cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32 ?
|
||||||
COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888,
|
COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888,
|
||||||
@ -776,12 +774,23 @@ st_texture_cache_reset_texture (StTextureCachePropertyBind *bind,
|
|||||||
if (error)
|
if (error)
|
||||||
g_warning ("Failed to allocate texture: %s", error->message);
|
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
|
static void
|
||||||
st_texture_cache_on_pixbuf_notify (GObject *object,
|
st_texture_cache_on_pixbuf_notify (GObject *object,
|
||||||
GParamSpec *paramspec,
|
GParamSpec *paramspec,
|
||||||
@ -849,6 +858,25 @@ st_texture_cache_bind_cairo_surface_property (StTextureCache *cache,
|
|||||||
return G_ICON (bind->image);
|
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)
|
* st_texture_cache_load: (skip)
|
||||||
* @cache: A #StTextureCache
|
* @cache: A #StTextureCache
|
||||||
|
@ -67,6 +67,9 @@ st_texture_cache_load_sliced_image (StTextureCache *cache,
|
|||||||
GIcon *st_texture_cache_bind_cairo_surface_property (StTextureCache *cache,
|
GIcon *st_texture_cache_bind_cairo_surface_property (StTextureCache *cache,
|
||||||
GObject *object,
|
GObject *object,
|
||||||
const char *property_name);
|
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,
|
ClutterActor *st_texture_cache_load_gicon (StTextureCache *cache,
|
||||||
StThemeNode *theme_node,
|
StThemeNode *theme_node,
|
||||||
|
Loading…
Reference in New Issue
Block a user