st-texture-cache: Use StContentImage to create actor contents
This will allow to use resource-scale aware content that will use a preferred size that takes in account the icon scaling and the resource scaling. If no size is passed we should just divide the actual resource size by the resource scale, as we assume that it's loaded with such scaling applied. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/5 https://bugzilla.gnome.org/show_bug.cgi?id=765011
This commit is contained in:
parent
0464361ca5
commit
aaf69b2898
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "st-image-content.h"
|
||||||
#include "st-texture-cache.h"
|
#include "st-texture-cache.h"
|
||||||
#include "st-private.h"
|
#include "st-private.h"
|
||||||
#include "st-settings.h"
|
#include "st-settings.h"
|
||||||
@ -486,12 +487,26 @@ load_pixbuf_async_finish (StTextureCache *cache, GAsyncResult *result, GError **
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ClutterContent *
|
static ClutterContent *
|
||||||
pixbuf_to_clutter_image (GdkPixbuf *pixbuf)
|
pixbuf_to_st_content_image (GdkPixbuf *pixbuf,
|
||||||
|
int width,
|
||||||
|
int height,
|
||||||
|
int paint_scale,
|
||||||
|
float resource_scale)
|
||||||
{
|
{
|
||||||
ClutterContent *image;
|
ClutterContent *image;
|
||||||
g_autoptr(GError) error = NULL;
|
g_autoptr(GError) error = NULL;
|
||||||
|
|
||||||
image = clutter_image_new ();
|
if (width < 0)
|
||||||
|
width = ceilf (gdk_pixbuf_get_width (pixbuf) / resource_scale);
|
||||||
|
else
|
||||||
|
width *= paint_scale;
|
||||||
|
|
||||||
|
if (height < 0)
|
||||||
|
height = ceilf (gdk_pixbuf_get_width (pixbuf) / resource_scale);
|
||||||
|
else
|
||||||
|
height *= paint_scale;
|
||||||
|
|
||||||
|
image = st_image_content_new_with_preferred_size (width, height);
|
||||||
clutter_image_set_data (CLUTTER_IMAGE (image),
|
clutter_image_set_data (CLUTTER_IMAGE (image),
|
||||||
gdk_pixbuf_get_pixels (pixbuf),
|
gdk_pixbuf_get_pixels (pixbuf),
|
||||||
gdk_pixbuf_get_has_alpha (pixbuf) ?
|
gdk_pixbuf_get_has_alpha (pixbuf) ?
|
||||||
@ -553,7 +568,10 @@ finish_texture_load (AsyncTextureLoadData *data,
|
|||||||
if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
|
if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
|
||||||
&orig_key, &value))
|
&orig_key, &value))
|
||||||
{
|
{
|
||||||
image = pixbuf_to_clutter_image (pixbuf);
|
image = pixbuf_to_st_content_image (pixbuf,
|
||||||
|
data->width, data->height,
|
||||||
|
data->paint_scale,
|
||||||
|
data->resource_scale);
|
||||||
if (!image)
|
if (!image)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
@ -567,7 +585,10 @@ finish_texture_load (AsyncTextureLoadData *data,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
image = pixbuf_to_clutter_image (pixbuf);
|
image = pixbuf_to_st_content_image (pixbuf,
|
||||||
|
data->width, data->height,
|
||||||
|
data->paint_scale,
|
||||||
|
data->resource_scale);
|
||||||
if (!image)
|
if (!image)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -994,7 +1015,7 @@ load_from_pixbuf (GdkPixbuf *pixbuf)
|
|||||||
int width = gdk_pixbuf_get_width (pixbuf);
|
int width = gdk_pixbuf_get_width (pixbuf);
|
||||||
int height = gdk_pixbuf_get_height (pixbuf);
|
int height = gdk_pixbuf_get_height (pixbuf);
|
||||||
|
|
||||||
image = pixbuf_to_clutter_image (pixbuf);
|
image = pixbuf_to_st_content_image (pixbuf, width, height, 1, 1.0f);
|
||||||
|
|
||||||
actor = clutter_actor_new ();
|
actor = clutter_actor_new ();
|
||||||
clutter_actor_set_size (actor, width, height);
|
clutter_actor_set_size (actor, width, height);
|
||||||
@ -1326,7 +1347,9 @@ st_texture_cache_load_file_sync_to_cogl_texture (StTextureCache *cache,
|
|||||||
if (!pixbuf)
|
if (!pixbuf)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
image = pixbuf_to_clutter_image (pixbuf);
|
image = pixbuf_to_st_content_image (pixbuf,
|
||||||
|
available_height, available_width,
|
||||||
|
paint_scale, resource_scale);
|
||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
|
|
||||||
if (!image)
|
if (!image)
|
||||||
|
Loading…
Reference in New Issue
Block a user