92
94
0, /* no default handler slot */
98
* st_texture_cache_clear_uri:
99
* @cache: A #StTextureCache
100
* @uri: URI of cached object
102
* If the given @uri is known to have been modified
103
* externally, this function may be used to invalidate
104
* the in-memory cache.
107
st_texture_cache_clear_uri (StTextureCache *cache,
112
g_return_if_fail (ST_IS_TEXTURE_CACHE (cache));
113
g_return_if_fail (uri != NULL);
115
key = g_strconcat (CACHE_PREFIX_URI, uri, NULL);
116
g_hash_table_remove (cache->priv->keyed_cache, key);
119
key = g_strconcat (CACHE_PREFIX_URI_FOR_CAIRO, uri, NULL);
120
g_hash_table_remove (cache->priv->keyed_cache, key);
98
signals[TEXTURE_FILE_CHANGED] =
99
g_signal_new ("texture-file-changed",
100
G_TYPE_FROM_CLASS (klass),
102
0, /* no default handler slot */
104
G_TYPE_NONE, 1, G_TYPE_STRING);
124
107
/* Evicts all cached textures for named icons */
179
165
self->priv->icon_theme = NULL;
182
if (self->priv->keyed_cache)
183
g_hash_table_destroy (self->priv->keyed_cache);
184
self->priv->keyed_cache = NULL;
186
if (self->priv->outstanding_requests)
187
g_hash_table_destroy (self->priv->outstanding_requests);
188
self->priv->outstanding_requests = NULL;
168
g_clear_pointer (&self->priv->keyed_cache, g_hash_table_destroy);
169
g_clear_pointer (&self->priv->outstanding_requests, g_hash_table_destroy);
170
g_clear_pointer (&self->priv->file_monitors, g_hash_table_destroy);
190
172
G_OBJECT_CLASS (st_texture_cache_parent_class)->dispose (object);
258
240
rgba->alpha = color->alpha / 255.;
262
impl_load_pixbuf_gicon (GtkIconInfo *info,
264
StIconColors *colors,
267
int scaled_width, scaled_height;
273
GdkRGBA foreground_color;
274
GdkRGBA success_color;
275
GdkRGBA warning_color;
278
rgba_from_clutter (&foreground_color, &colors->foreground);
279
rgba_from_clutter (&success_color, &colors->success);
280
rgba_from_clutter (&warning_color, &colors->warning);
281
rgba_from_clutter (&error_color, &colors->error);
283
pixbuf = gtk_icon_info_load_symbolic (info,
284
&foreground_color, &success_color,
285
&warning_color, &error_color,
290
pixbuf = gtk_icon_info_load_icon (info, error);
296
width = gdk_pixbuf_get_width (pixbuf);
297
height = gdk_pixbuf_get_height (pixbuf);
299
if (compute_pixbuf_scale (width,
302
&scaled_width, &scaled_height))
304
GdkPixbuf *scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
305
g_object_unref (pixbuf);
311
243
/* A private structure for keeping width and height. */
559
493
data = g_async_result_get_user_data (G_ASYNC_RESULT (result));
560
494
g_assert (data != NULL);
495
g_assert (data->uri != NULL);
563
pixbuf = impl_load_pixbuf_file (data->uri, data->width, data->height, &error);
564
else if (data->icon_info)
565
pixbuf = impl_load_pixbuf_gicon (data->icon_info, data->width, data->colors, &error);
567
g_assert_not_reached ();
497
pixbuf = impl_load_pixbuf_file (data->uri, data->width, data->height, &error);
569
499
if (error != NULL)
668
on_pixbuf_loaded (GObject *source,
669
GAsyncResult *result,
598
finish_texture_load (AsyncTextureLoadData *data,
673
602
StTextureCache *cache;
674
AsyncTextureLoadData *data;
676
GError *error = NULL;
677
603
CoglHandle texdata = NULL;
680
cache = ST_TEXTURE_CACHE (source);
682
607
g_hash_table_remove (cache->priv->outstanding_requests, data->key);
684
pixbuf = load_pixbuf_async_finish (cache, result, &error);
685
609
if (pixbuf == NULL)
688
612
texdata = pixbuf_to_cogl_handle (pixbuf, data->enforced_square);
690
g_object_unref (pixbuf);
692
614
if (data->policy != ST_TEXTURE_CACHE_POLICY_NONE)
694
616
gpointer orig_key, value;
713
635
cogl_handle_unref (texdata);
715
texture_load_data_destroy (data);
718
g_clear_error (&error);
637
texture_load_data_free (data);
641
on_symbolic_icon_loaded (GObject *source,
642
GAsyncResult *result,
646
pixbuf = gtk_icon_info_load_symbolic_finish (GTK_ICON_INFO (source), result, NULL, NULL);
647
finish_texture_load (user_data, pixbuf);
648
g_clear_object (&pixbuf);
652
on_icon_loaded (GObject *source,
653
GAsyncResult *result,
657
pixbuf = gtk_icon_info_load_icon_finish (GTK_ICON_INFO (source), result, NULL);
658
finish_texture_load (user_data, pixbuf);
659
g_clear_object (&pixbuf);
663
on_pixbuf_loaded (GObject *source,
664
GAsyncResult *result,
668
pixbuf = load_pixbuf_async_finish (ST_TEXTURE_CACHE (source), result, NULL);
669
finish_texture_load (user_data, pixbuf);
670
g_clear_object (&pixbuf);
722
674
load_texture_async (StTextureCache *cache,
723
675
AsyncTextureLoadData *data)
725
GSimpleAsyncResult *result;
726
result = g_simple_async_result_new (G_OBJECT (cache), on_pixbuf_loaded, data, load_texture_async);
727
g_simple_async_result_run_in_thread (result, load_pixbuf_thread, G_PRIORITY_DEFAULT, NULL);
728
g_object_unref (result);
679
GSimpleAsyncResult *result;
680
result = g_simple_async_result_new (G_OBJECT (cache), on_pixbuf_loaded, data, load_texture_async);
681
g_simple_async_result_run_in_thread (result, load_pixbuf_thread, G_PRIORITY_DEFAULT, NULL);
682
g_object_unref (result);
684
else if (data->icon_info)
686
StIconColors *colors = data->colors;
689
GdkRGBA foreground_color;
690
GdkRGBA success_color;
691
GdkRGBA warning_color;
694
rgba_from_clutter (&foreground_color, &colors->foreground);
695
rgba_from_clutter (&success_color, &colors->success);
696
rgba_from_clutter (&warning_color, &colors->warning);
697
rgba_from_clutter (&error_color, &colors->error);
699
gtk_icon_info_load_symbolic_async (data->icon_info,
700
&foreground_color, &success_color,
701
&warning_color, &error_color,
702
NULL, on_symbolic_icon_loaded, data);
706
gtk_icon_info_load_icon_async (data->icon_info, NULL, on_icon_loaded, data);
710
g_assert_not_reached ();
1039
1021
return CLUTTER_ACTOR (texture);
1025
file_changed_cb (GFileMonitor *monitor,
1028
GFileMonitorEvent event_type,
1031
StTextureCache *cache = user_data;
1034
if (event_type != G_FILE_MONITOR_EVENT_CHANGED)
1037
uri = g_file_get_uri (file);
1039
key = g_strconcat (CACHE_PREFIX_URI, uri, NULL);
1040
g_hash_table_remove (cache->priv->keyed_cache, key);
1043
key = g_strconcat (CACHE_PREFIX_URI_FOR_CAIRO, uri, NULL);
1044
g_hash_table_remove (cache->priv->keyed_cache, key);
1047
g_signal_emit (cache, signals[TEXTURE_FILE_CHANGED], 0, uri);
1053
ensure_monitor_for_uri (StTextureCache *cache,
1056
StTextureCachePrivate *priv = cache->priv;
1057
GFile *file = g_file_new_for_uri (uri);
1059
if (g_hash_table_lookup (priv->file_monitors, uri) == NULL)
1061
GFileMonitor *monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE,
1063
g_signal_connect (monitor, "changed",
1064
G_CALLBACK (file_changed_cb), cache);
1065
g_hash_table_insert (priv->file_monitors, g_strdup (uri), monitor);
1067
g_object_unref (file);
1042
1070
typedef struct {
1044
1072
gint grid_width, grid_height;
1045
1073
ClutterActor *actor;
1074
GFunc load_callback;
1075
gpointer load_callback_data;
1046
1076
} AsyncImageData;
1126
1160
* @path: Path to a filename
1127
1161
* @grid_width: Width in pixels
1128
1162
* @grid_height: Height in pixels
1163
* @load_callback: (scope async) (allow-none): Function called when the image is loaded, or %NULL
1164
* @user_data: Data to pass to the load callback
1130
1166
* This function reads a single image file which contains multiple images internally.
1131
1167
* The image file will be divided using @grid_width and @grid_height;
1149
1187
data->grid_height = grid_height;
1150
1188
data->path = g_strdup (path);
1151
1189
data->actor = actor;
1190
data->load_callback = load_callback;
1191
data->load_callback_data = user_data;
1152
1192
g_object_ref (G_OBJECT (actor));
1154
1194
result = g_simple_async_result_new (G_OBJECT (cache), on_sliced_image_loaded, data, st_texture_cache_load_sliced_image);
1165
* st_texture_cache_load_icon_name:
1166
* @cache: The texture cache instance
1167
* @theme_node: (allow-none): a #StThemeNode
1168
* @name: Name of a themed icon
1169
* @size: Size of themed icon
1171
* Load a themed icon into a texture. The colors used for symbolic
1172
* icons are derived from @theme_node.
1174
* Return Value: (transfer none): A new #ClutterTexture for the icon
1177
st_texture_cache_load_icon_name (StTextureCache *cache,
1178
StThemeNode *theme_node,
1182
ClutterActor *texture;
1185
themed = g_themed_icon_new_with_default_fallbacks (name);
1186
texture = load_gicon_with_colors (cache, themed, size,
1187
theme_node ? st_theme_node_get_icon_colors (theme_node) : NULL);
1188
g_object_unref (themed);
1190
if (texture == NULL)
1192
texture = (ClutterActor *) create_default_texture ();
1193
clutter_actor_set_size (texture, size, size);
1200
1205
* st_texture_cache_load_uri_async:
1201
1206
* @cache: The texture cache instance
1202
1207
* @uri: uri of the image file from which to create a pixbuf
1401
1412
return surface;
1405
* st_texture_cache_load_from_raw:
1406
* @cache: a #StTextureCache
1407
* @data: (array length=len): raw pixel data
1408
* @len: the length of @data
1409
* @has_alpha: whether @data includes an alpha channel
1410
* @width: width in pixels of @data
1411
* @height: width in pixels of @data
1412
* @rowstride: rowstride of @data
1413
* @size: size of icon to return
1415
* Creates (or retrieves from cache) an icon based on raw pixel data.
1417
* Return value: (transfer none): a new #ClutterActor displaying a
1418
* pixbuf created from @data and the other parameters.
1421
st_texture_cache_load_from_raw (StTextureCache *cache,
1431
ClutterTexture *texture;
1436
texture = create_default_texture ();
1437
clutter_actor_set_size (CLUTTER_ACTOR (texture), size, size);
1439
/* In theory, two images of with different width and height could have the same
1440
* pixel data and thus hash the same. (Say, a 16x16 and a 8x32 blank image.)
1441
* We ignore this for now. If anybody hits this problem they should use
1442
* GChecksum directly to compute a checksum including the width and height.
1444
checksum = g_compute_checksum_for_data (G_CHECKSUM_SHA1, data, len);
1445
key = g_strdup_printf (CACHE_PREFIX_RAW_CHECKSUM "checksum=%s", checksum);
1448
texdata = g_hash_table_lookup (cache->priv->keyed_cache, key);
1449
if (texdata == NULL)
1451
texdata = data_to_cogl_handle (data, has_alpha, width, height, rowstride, TRUE);
1452
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata);
1457
set_texture_cogl_texture (texture, texdata);
1458
return CLUTTER_ACTOR (texture);
1461
1415
static StTextureCache *instance = NULL;