From 6f00d81abf426e17b7ccbbd1efbf55dd363f2ae2 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Thu, 7 Aug 2014 14:40:01 -0400 Subject: [PATCH] texture-cache: Port to modern Cogl --- src/st/st-texture-cache.c | 84 +++++++++++++++++++++------------------ src/st/st-texture-cache.h | 20 +++++----- 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c index f3d88cb2d..64b9651ad 100644 --- a/src/st/st-texture-cache.c +++ b/src/st/st-texture-cache.c @@ -21,6 +21,8 @@ #include "config.h" +#define COGL_ENABLE_EXPERIMENTAL_API /* for cogl_framebuffer_allocate */ + #include "st-texture-cache.h" #include "st-private.h" #include @@ -60,7 +62,7 @@ static guint signals[LAST_SIGNAL] = { 0, }; G_DEFINE_TYPE(StTextureCache, st_texture_cache, G_TYPE_OBJECT); /* We want to preserve the aspect ratio by default, also the default - * material for an empty texture is full opacity white, which we + * pipeline for an empty texture is full opacity white, which we * definitely don't want. Skip that by setting 0 opacity. */ static ClutterTexture * @@ -73,7 +75,7 @@ create_default_texture (void) /* Reverse the opacity we added while loading */ static void -set_texture_cogl_texture (ClutterTexture *clutter_texture, CoglHandle cogl_texture) +set_texture_cogl_texture (ClutterTexture *clutter_texture, CoglTexture *cogl_texture) { clutter_texture_set_cogl_texture (clutter_texture, cogl_texture); g_object_set (clutter_texture, "opacity", 255, NULL); @@ -144,7 +146,7 @@ st_texture_cache_init (StTextureCache *self) G_CALLBACK (on_icon_theme_changed), self); self->priv->keyed_cache = g_hash_table_new_full (g_str_hash, g_str_equal, - g_free, cogl_handle_unref); + g_free, cogl_object_unref); self->priv->outstanding_requests = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); self->priv->file_monitors = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -531,16 +533,19 @@ load_pixbuf_async_finish (StTextureCache *cache, GAsyncResult *result, GError ** return g_simple_async_result_get_op_res_gpointer (simple); } -static CoglHandle -pixbuf_to_cogl_handle (GdkPixbuf *pixbuf) +static CoglTexture * +pixbuf_to_cogl_texture (GdkPixbuf *pixbuf) { - return cogl_texture_new_from_data (gdk_pixbuf_get_width (pixbuf), - gdk_pixbuf_get_height (pixbuf), - COGL_TEXTURE_NONE, - gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888, - COGL_PIXEL_FORMAT_ANY, - gdk_pixbuf_get_rowstride (pixbuf), - gdk_pixbuf_get_pixels (pixbuf)); + ClutterBackend *backend = clutter_get_default_backend (); + CoglContext *ctx = clutter_backend_get_cogl_context (backend); + + return COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888, + gdk_pixbuf_get_rowstride (pixbuf), + gdk_pixbuf_get_pixels (pixbuf), + NULL)); } static cairo_surface_t * @@ -570,7 +575,7 @@ finish_texture_load (AsyncTextureLoadData *data, { GSList *iter; StTextureCache *cache; - CoglHandle texdata = NULL; + CoglTexture *texdata = NULL; cache = data->cache; @@ -579,7 +584,7 @@ finish_texture_load (AsyncTextureLoadData *data, if (pixbuf == NULL) goto out; - texdata = pixbuf_to_cogl_handle (pixbuf); + texdata = pixbuf_to_cogl_texture (pixbuf); if (data->policy != ST_TEXTURE_CACHE_POLICY_NONE) { @@ -588,7 +593,7 @@ finish_texture_load (AsyncTextureLoadData *data, if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key, &orig_key, &value)) { - cogl_handle_ref (texdata); + cogl_object_ref (texdata); g_hash_table_insert (cache->priv->keyed_cache, g_strdup (data->key), texdata); } @@ -602,7 +607,7 @@ finish_texture_load (AsyncTextureLoadData *data, out: if (texdata) - cogl_handle_unref (texdata); + cogl_object_unref (texdata); texture_load_data_free (data); } @@ -693,7 +698,7 @@ st_texture_cache_reset_texture (StTextureCachePropertyBind *bind, const char *propname) { GdkPixbuf *pixbuf; - CoglHandle texdata; + CoglTexture *texdata; g_object_get (bind->source, propname, &pixbuf, NULL); @@ -701,11 +706,11 @@ st_texture_cache_reset_texture (StTextureCachePropertyBind *bind, if (pixbuf != NULL) { - texdata = pixbuf_to_cogl_handle (pixbuf); + texdata = pixbuf_to_cogl_texture (pixbuf); g_object_unref (pixbuf); clutter_texture_set_cogl_texture (bind->texture, texdata); - cogl_handle_unref (texdata); + cogl_object_unref (texdata); clutter_actor_set_opacity (CLUTTER_ACTOR (bind->texture), 255); } @@ -748,7 +753,7 @@ st_texture_cache_free_bind (gpointer data) * * Create a #ClutterTexture which tracks the #GdkPixbuf value of a GObject property * named by @property_name. Unlike other methods in StTextureCache, the underlying - * CoglHandle is not shared by default with other invocations to this method. + * #CoglTexture is not shared by default with other invocations to this method. * * If the source object is destroyed, the texture will continue to show the last * value of the property. @@ -799,7 +804,7 @@ st_texture_cache_bind_pixbuf_property (StTextureCache *cache, * * Returns: (transfer full): A newly-referenced handle to the texture */ -CoglHandle +CoglTexture * st_texture_cache_load (StTextureCache *cache, const char *key, StTextureCachePolicy policy, @@ -807,7 +812,7 @@ st_texture_cache_load (StTextureCache *cache, void *data, GError **error) { - CoglHandle texture; + CoglTexture *texture; texture = g_hash_table_lookup (cache->priv->keyed_cache, key); if (!texture) @@ -816,9 +821,10 @@ st_texture_cache_load (StTextureCache *cache, if (texture) g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texture); else - return COGL_INVALID_HANDLE; + return NULL; } - cogl_handle_ref (texture); + + cogl_object_ref (texture); return texture; } @@ -843,7 +849,7 @@ ensure_request (StTextureCache *cache, AsyncTextureLoadData **request, ClutterActor *texture) { - CoglHandle texdata; + CoglTexture *texdata; AsyncTextureLoadData *pending; gboolean had_pending; @@ -978,7 +984,7 @@ static ClutterActor * load_from_pixbuf (GdkPixbuf *pixbuf) { ClutterTexture *texture; - CoglHandle texdata; + CoglTexture *texdata; int width = gdk_pixbuf_get_width (pixbuf); int height = gdk_pixbuf_get_height (pixbuf); @@ -986,11 +992,11 @@ load_from_pixbuf (GdkPixbuf *pixbuf) clutter_actor_set_size (CLUTTER_ACTOR (texture), width, height); - texdata = pixbuf_to_cogl_handle (pixbuf); + texdata = pixbuf_to_cogl_texture (pixbuf); set_texture_cogl_texture (texture, texdata); - cogl_handle_unref (texdata); + cogl_object_unref (texdata); return CLUTTER_ACTOR (texture); } @@ -1266,7 +1272,7 @@ st_texture_cache_load_uri_async (StTextureCache *cache, return CLUTTER_ACTOR (texture); } -static CoglHandle +static CoglTexture * st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache, StTextureCachePolicy policy, const gchar *uri, @@ -1275,7 +1281,7 @@ st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache, int scale, GError **error) { - CoglHandle texdata; + CoglTexture *texdata; GdkPixbuf *pixbuf; char *key; @@ -1289,17 +1295,17 @@ st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache, if (!pixbuf) goto out; - texdata = pixbuf_to_cogl_handle (pixbuf); + texdata = pixbuf_to_cogl_texture (pixbuf); g_object_unref (pixbuf); if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER) { - cogl_handle_ref (texdata); + cogl_object_ref (texdata); g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata); } } else - cogl_handle_ref (texdata); + cogl_object_ref (texdata); ensure_monitor_for_uri (cache, uri); @@ -1351,23 +1357,23 @@ out: } /** - * st_texture_cache_load_file_to_cogl_texture: + * st_texture_cache_load_file_to_cogl_texture: (skip) * @cache: A #StTextureCache * @file_path: Path to a file in supported image format * @scale: Scale factor of the display * * This function synchronously loads the given file path * into a COGL texture. On error, a warning is emitted - * and %COGL_INVALID_HANDLE is returned. + * and %NULL is returned. * - * Returns: (transfer full): a new #CoglHandle + * Returns: (transfer full): a new #CoglTexture */ -CoglHandle +CoglTexture * st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache, const gchar *file_path, gint scale) { - CoglHandle texture; + CoglTexture *texture; GFile *file; char *uri; GError *error = NULL; @@ -1384,7 +1390,7 @@ st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache, { g_warning ("Failed to load %s: %s", file_path, error->message); g_clear_error (&error); - return COGL_INVALID_HANDLE; + return NULL; } return texture; } diff --git a/src/st/st-texture-cache.h b/src/st/st-texture-cache.h index af14181b9..46652832b 100644 --- a/src/st/st-texture-cache.h +++ b/src/st/st-texture-cache.h @@ -93,9 +93,9 @@ ClutterActor *st_texture_cache_load_uri_async (StTextureCache *cache, int available_height, int scale); -CoglHandle st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache, - const gchar *file_path, - gint scale); +CoglTexture *st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache, + const gchar *file_path, + gint scale); cairo_surface_t *st_texture_cache_load_file_to_cairo_surface (StTextureCache *cache, const gchar *file_path, @@ -112,13 +112,13 @@ cairo_surface_t *st_texture_cache_load_file_to_cairo_surface (StTextureCache *ca * texture handle for the given key, or set @error. * */ -typedef CoglHandle (*StTextureCacheLoader) (StTextureCache *cache, const char *key, void *data, GError **error); +typedef CoglTexture * (*StTextureCacheLoader) (StTextureCache *cache, const char *key, void *data, GError **error); -CoglHandle st_texture_cache_load (StTextureCache *cache, - const char *key, - StTextureCachePolicy policy, - StTextureCacheLoader load, - void *data, - GError **error); +CoglTexture * st_texture_cache_load (StTextureCache *cache, + const char *key, + StTextureCachePolicy policy, + StTextureCacheLoader load, + void *data, + GError **error); #endif /* __ST_TEXTURE_CACHE_H__ */