Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 51 additions & 11 deletions src/st/st-icon.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct _StIconPrivate
gint theme_icon_size; /* icon size from theme node */
gint icon_size; /* icon size we are using */
gint icon_scale;
gfloat resource_scale;

CoglPipeline *shadow_pipeline;

Expand All @@ -72,6 +73,7 @@ static void st_icon_update (StIcon *icon);
static gboolean st_icon_update_icon_size (StIcon *icon);
static void st_icon_update_shadow_pipeline (StIcon *icon);
static void st_icon_clear_shadow_pipeline (StIcon *icon);
static gfloat st_icon_get_resource_scale (StIcon *icon);

#define DEFAULT_ICON_SIZE 48
#define DEFAULT_ICON_TYPE ST_ICON_SYMBOLIC
Expand Down Expand Up @@ -244,6 +246,33 @@ st_icon_style_changed (StWidget *widget)
st_icon_update (self);
}

static gfloat
st_icon_get_resource_scale (StIcon *icon)
{
gfloat resource_scale = 1.0;

clutter_actor_get_resource_scale (CLUTTER_ACTOR (icon), &resource_scale);

return resource_scale;
}

static void
st_icon_resource_scale_changed (GObject *gobject,
GParamSpec *pspec,
gpointer user_data)
{
StIcon *icon = ST_ICON (gobject);
StIconPrivate *priv = icon->priv;
gfloat resource_scale;

resource_scale = st_icon_get_resource_scale (icon);
if (priv->resource_scale == resource_scale)
return;

priv->resource_scale = resource_scale;
st_icon_update (icon);
}

static void
st_icon_class_init (StIconClass *klass)
{
Expand Down Expand Up @@ -309,8 +338,12 @@ st_icon_init (StIcon *self)
self->priv->shadow_pipeline = NULL;

self->priv->icon_scale = 1;
self->priv->resource_scale = 1.0;

self->priv->file_uri = NULL;

g_signal_connect (self, "notify::resource-scale",
G_CALLBACK (st_icon_resource_scale_changed), NULL);
}

static void
Expand Down Expand Up @@ -436,24 +469,31 @@ st_icon_update (StIcon *icon)
return;

priv->icon_scale = st_theme_context_get_scale_for_stage ();
priv->resource_scale = st_icon_get_resource_scale (icon);

cache = st_texture_cache_get_default ();
if (priv->gicon)
{
priv->pending_texture = st_texture_cache_load_gicon (cache,
(priv->icon_type != ST_ICON_APPLICATION &&
priv->icon_type != ST_ICON_DOCUMENT) ?
theme_node : NULL,
priv->gicon,
priv->icon_size);
priv->pending_texture =
st_texture_cache_load_gicon_with_scale (cache,
(priv->icon_type != ST_ICON_APPLICATION &&
priv->icon_type != ST_ICON_DOCUMENT) ?
theme_node : NULL,
priv->gicon,
priv->icon_size,
priv->icon_scale,
priv->resource_scale);
}
else if (priv->icon_name)
{
priv->pending_texture = st_texture_cache_load_icon_name (cache,
theme_node,
priv->icon_name,
priv->icon_type,
priv->icon_size);
priv->pending_texture =
st_texture_cache_load_icon_name_with_scale (cache,
theme_node,
priv->icon_name,
priv->icon_type,
priv->icon_size,
priv->icon_scale,
priv->resource_scale);
}

if (priv->pending_texture)
Expand Down
54 changes: 39 additions & 15 deletions src/st/st-texture-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,8 @@ pixbuf_to_st_content_image (GdkPixbuf *pixbuf,
}

static cairo_surface_t *
pixbuf_to_cairo_surface (GdkPixbuf *pixbuf)
pixbuf_to_cairo_surface (GdkPixbuf *pixbuf,
float resource_scale)
{
cairo_surface_t *dummy_surface;
cairo_pattern_t *pattern;
Expand All @@ -609,6 +610,7 @@ pixbuf_to_cairo_surface (GdkPixbuf *pixbuf)
pattern = cairo_get_source (cr);
cairo_pattern_get_surface (pattern, &surface);
cairo_surface_reference (surface);
cairo_surface_set_device_scale (surface, resource_scale, resource_scale);
cairo_destroy (cr);
cairo_surface_destroy (dummy_surface);

Expand Down Expand Up @@ -1835,11 +1837,13 @@ symbolic_name_for_icon (const char *name)
* Return Value: (transfer none): A new #ClutterTexture for the icon
*/
ClutterActor *
st_texture_cache_load_icon_name (StTextureCache *cache,
StThemeNode *theme_node,
const char *name,
StIconType icon_type,
gint size)
st_texture_cache_load_icon_name_with_scale (StTextureCache *cache,
StThemeNode *theme_node,
const char *name,
StIconType icon_type,
gint size,
gint paint_scale,
gfloat resource_scale)
{
ClutterActor *texture;
GIcon *themed;
Expand All @@ -1851,24 +1855,28 @@ st_texture_cache_load_icon_name (StTextureCache *cache,
{
case ST_ICON_APPLICATION:
themed = g_themed_icon_new (name);
texture = st_texture_cache_load_gicon (cache, theme_node, themed, size);
texture = st_texture_cache_load_gicon_with_scale (cache, theme_node, themed, size,
paint_scale, resource_scale);
g_object_unref (themed);
if (texture == NULL)
{
themed = g_themed_icon_new ("application-x-executable");
texture = st_texture_cache_load_gicon (cache, theme_node, themed, size);
texture = st_texture_cache_load_gicon_with_scale (cache, theme_node, themed, size,
paint_scale, resource_scale);
g_object_unref (themed);
}
return CLUTTER_ACTOR (texture);
break;
case ST_ICON_DOCUMENT:
themed = g_themed_icon_new (name);
texture = st_texture_cache_load_gicon (cache, theme_node, themed, size);
texture = st_texture_cache_load_gicon_with_scale (cache, theme_node, themed, size,
paint_scale, resource_scale);
g_object_unref (themed);
if (texture == NULL)
{
themed = g_themed_icon_new ("x-office-document");
texture = st_texture_cache_load_gicon (cache, theme_node, themed, size);
texture = st_texture_cache_load_gicon_with_scale (cache, theme_node, themed, size,
paint_scale, resource_scale);
g_object_unref (themed);
}

Expand All @@ -1878,19 +1886,22 @@ st_texture_cache_load_icon_name (StTextureCache *cache,
symbolic_name = symbolic_name_for_icon (name);
themed = g_themed_icon_new (symbolic_name);
g_free (symbolic_name);
texture = st_texture_cache_load_gicon (cache, theme_node, themed, size);
texture = st_texture_cache_load_gicon_with_scale (cache, theme_node, themed, size,
paint_scale, resource_scale);
g_object_unref (themed);

return CLUTTER_ACTOR (texture);
break;
case ST_ICON_FULLCOLOR:
themed = g_themed_icon_new (name);
texture = st_texture_cache_load_gicon (cache, theme_node, themed, size);
texture = st_texture_cache_load_gicon_with_scale (cache, theme_node, themed, size,
paint_scale, resource_scale);
g_object_unref (themed);
if (texture == NULL)
{
themed = g_themed_icon_new ("image-missing");
texture = st_texture_cache_load_gicon (cache, theme_node, themed, size);
texture = st_texture_cache_load_gicon_with_scale (cache, theme_node, themed, size,
paint_scale, resource_scale);
g_object_unref (themed);
}

Expand All @@ -1901,6 +1912,19 @@ st_texture_cache_load_icon_name (StTextureCache *cache,
}
}

ClutterActor *
st_texture_cache_load_icon_name (StTextureCache *cache,
StThemeNode *theme_node,
const char *name,
StIconType icon_type,
gint size)
{
return st_texture_cache_load_icon_name_with_scale (cache, theme_node, name,
icon_type, size,
st_theme_context_get_scale_for_stage (),
1.0);
}

/**
* st_texture_cache_load_uri_async:
* @cache: The texture cache instance
Expand Down Expand Up @@ -2012,7 +2036,7 @@ st_texture_cache_load_file_sync_to_cairo_surface (StTextureCache *cache,
if (!pixbuf)
goto out;

surface = pixbuf_to_cairo_surface (pixbuf);
surface = pixbuf_to_cairo_surface (pixbuf, resource_scale);
g_object_unref (pixbuf);

if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER)
Expand Down Expand Up @@ -2214,4 +2238,4 @@ st_texture_cache_can_load_mime_type (StTextureCache *cache,
return FALSE;

return g_hash_table_contains (priv->image_type_table, mime_type);
}
}
8 changes: 8 additions & 0 deletions src/st/st-texture-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ ClutterActor *st_texture_cache_load_icon_name (StTextureCache *cache,
StIconType icon_type,
gint size);

ClutterActor *st_texture_cache_load_icon_name_with_scale (StTextureCache *cache,
StThemeNode *theme_node,
const char *name,
StIconType icon_type,
gint size,
gint paint_scale,
gfloat resource_scale);

ClutterActor *st_texture_cache_load_file_async (StTextureCache *cache,
GFile *file,
int available_width,
Expand Down
Loading
Loading