texture-cache: Port to modern Cogl
This commit is contained in:
parent
4184edc7f8
commit
6f00d81abf
@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#define COGL_ENABLE_EXPERIMENTAL_API /* for cogl_framebuffer_allocate */
|
||||||
|
|
||||||
#include "st-texture-cache.h"
|
#include "st-texture-cache.h"
|
||||||
#include "st-private.h"
|
#include "st-private.h"
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
@ -60,7 +62,7 @@ static guint signals[LAST_SIGNAL] = { 0, };
|
|||||||
G_DEFINE_TYPE(StTextureCache, st_texture_cache, G_TYPE_OBJECT);
|
G_DEFINE_TYPE(StTextureCache, st_texture_cache, G_TYPE_OBJECT);
|
||||||
|
|
||||||
/* We want to preserve the aspect ratio by default, also the default
|
/* 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.
|
* definitely don't want. Skip that by setting 0 opacity.
|
||||||
*/
|
*/
|
||||||
static ClutterTexture *
|
static ClutterTexture *
|
||||||
@ -73,7 +75,7 @@ create_default_texture (void)
|
|||||||
|
|
||||||
/* Reverse the opacity we added while loading */
|
/* Reverse the opacity we added while loading */
|
||||||
static void
|
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);
|
clutter_texture_set_cogl_texture (clutter_texture, cogl_texture);
|
||||||
g_object_set (clutter_texture, "opacity", 255, NULL);
|
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);
|
G_CALLBACK (on_icon_theme_changed), self);
|
||||||
|
|
||||||
self->priv->keyed_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
|
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,
|
self->priv->outstanding_requests = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
g_free, NULL);
|
g_free, NULL);
|
||||||
self->priv->file_monitors = g_hash_table_new_full (g_str_hash, g_str_equal,
|
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);
|
return g_simple_async_result_get_op_res_gpointer (simple);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CoglHandle
|
static CoglTexture *
|
||||||
pixbuf_to_cogl_handle (GdkPixbuf *pixbuf)
|
pixbuf_to_cogl_texture (GdkPixbuf *pixbuf)
|
||||||
{
|
{
|
||||||
return cogl_texture_new_from_data (gdk_pixbuf_get_width (pixbuf),
|
ClutterBackend *backend = clutter_get_default_backend ();
|
||||||
gdk_pixbuf_get_height (pixbuf),
|
CoglContext *ctx = clutter_backend_get_cogl_context (backend);
|
||||||
COGL_TEXTURE_NONE,
|
|
||||||
gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
|
return COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx,
|
||||||
COGL_PIXEL_FORMAT_ANY,
|
gdk_pixbuf_get_width (pixbuf),
|
||||||
gdk_pixbuf_get_rowstride (pixbuf),
|
gdk_pixbuf_get_height (pixbuf),
|
||||||
gdk_pixbuf_get_pixels (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 *
|
static cairo_surface_t *
|
||||||
@ -570,7 +575,7 @@ finish_texture_load (AsyncTextureLoadData *data,
|
|||||||
{
|
{
|
||||||
GSList *iter;
|
GSList *iter;
|
||||||
StTextureCache *cache;
|
StTextureCache *cache;
|
||||||
CoglHandle texdata = NULL;
|
CoglTexture *texdata = NULL;
|
||||||
|
|
||||||
cache = data->cache;
|
cache = data->cache;
|
||||||
|
|
||||||
@ -579,7 +584,7 @@ finish_texture_load (AsyncTextureLoadData *data,
|
|||||||
if (pixbuf == NULL)
|
if (pixbuf == NULL)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
texdata = pixbuf_to_cogl_handle (pixbuf);
|
texdata = pixbuf_to_cogl_texture (pixbuf);
|
||||||
|
|
||||||
if (data->policy != ST_TEXTURE_CACHE_POLICY_NONE)
|
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,
|
if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
|
||||||
&orig_key, &value))
|
&orig_key, &value))
|
||||||
{
|
{
|
||||||
cogl_handle_ref (texdata);
|
cogl_object_ref (texdata);
|
||||||
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (data->key),
|
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (data->key),
|
||||||
texdata);
|
texdata);
|
||||||
}
|
}
|
||||||
@ -602,7 +607,7 @@ finish_texture_load (AsyncTextureLoadData *data,
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
if (texdata)
|
if (texdata)
|
||||||
cogl_handle_unref (texdata);
|
cogl_object_unref (texdata);
|
||||||
|
|
||||||
texture_load_data_free (data);
|
texture_load_data_free (data);
|
||||||
}
|
}
|
||||||
@ -693,7 +698,7 @@ st_texture_cache_reset_texture (StTextureCachePropertyBind *bind,
|
|||||||
const char *propname)
|
const char *propname)
|
||||||
{
|
{
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
CoglHandle texdata;
|
CoglTexture *texdata;
|
||||||
|
|
||||||
g_object_get (bind->source, propname, &pixbuf, NULL);
|
g_object_get (bind->source, propname, &pixbuf, NULL);
|
||||||
|
|
||||||
@ -701,11 +706,11 @@ st_texture_cache_reset_texture (StTextureCachePropertyBind *bind,
|
|||||||
|
|
||||||
if (pixbuf != NULL)
|
if (pixbuf != NULL)
|
||||||
{
|
{
|
||||||
texdata = pixbuf_to_cogl_handle (pixbuf);
|
texdata = pixbuf_to_cogl_texture (pixbuf);
|
||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
|
|
||||||
clutter_texture_set_cogl_texture (bind->texture, texdata);
|
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);
|
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
|
* Create a #ClutterTexture which tracks the #GdkPixbuf value of a GObject property
|
||||||
* named by @property_name. Unlike other methods in StTextureCache, the underlying
|
* 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
|
* If the source object is destroyed, the texture will continue to show the last
|
||||||
* value of the property.
|
* 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
|
* Returns: (transfer full): A newly-referenced handle to the texture
|
||||||
*/
|
*/
|
||||||
CoglHandle
|
CoglTexture *
|
||||||
st_texture_cache_load (StTextureCache *cache,
|
st_texture_cache_load (StTextureCache *cache,
|
||||||
const char *key,
|
const char *key,
|
||||||
StTextureCachePolicy policy,
|
StTextureCachePolicy policy,
|
||||||
@ -807,7 +812,7 @@ st_texture_cache_load (StTextureCache *cache,
|
|||||||
void *data,
|
void *data,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
CoglHandle texture;
|
CoglTexture *texture;
|
||||||
|
|
||||||
texture = g_hash_table_lookup (cache->priv->keyed_cache, key);
|
texture = g_hash_table_lookup (cache->priv->keyed_cache, key);
|
||||||
if (!texture)
|
if (!texture)
|
||||||
@ -816,9 +821,10 @@ st_texture_cache_load (StTextureCache *cache,
|
|||||||
if (texture)
|
if (texture)
|
||||||
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texture);
|
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texture);
|
||||||
else
|
else
|
||||||
return COGL_INVALID_HANDLE;
|
return NULL;
|
||||||
}
|
}
|
||||||
cogl_handle_ref (texture);
|
|
||||||
|
cogl_object_ref (texture);
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -843,7 +849,7 @@ ensure_request (StTextureCache *cache,
|
|||||||
AsyncTextureLoadData **request,
|
AsyncTextureLoadData **request,
|
||||||
ClutterActor *texture)
|
ClutterActor *texture)
|
||||||
{
|
{
|
||||||
CoglHandle texdata;
|
CoglTexture *texdata;
|
||||||
AsyncTextureLoadData *pending;
|
AsyncTextureLoadData *pending;
|
||||||
gboolean had_pending;
|
gboolean had_pending;
|
||||||
|
|
||||||
@ -978,7 +984,7 @@ static ClutterActor *
|
|||||||
load_from_pixbuf (GdkPixbuf *pixbuf)
|
load_from_pixbuf (GdkPixbuf *pixbuf)
|
||||||
{
|
{
|
||||||
ClutterTexture *texture;
|
ClutterTexture *texture;
|
||||||
CoglHandle texdata;
|
CoglTexture *texdata;
|
||||||
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);
|
||||||
|
|
||||||
@ -986,11 +992,11 @@ load_from_pixbuf (GdkPixbuf *pixbuf)
|
|||||||
|
|
||||||
clutter_actor_set_size (CLUTTER_ACTOR (texture), width, height);
|
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);
|
set_texture_cogl_texture (texture, texdata);
|
||||||
|
|
||||||
cogl_handle_unref (texdata);
|
cogl_object_unref (texdata);
|
||||||
return CLUTTER_ACTOR (texture);
|
return CLUTTER_ACTOR (texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1266,7 +1272,7 @@ st_texture_cache_load_uri_async (StTextureCache *cache,
|
|||||||
return CLUTTER_ACTOR (texture);
|
return CLUTTER_ACTOR (texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
static CoglHandle
|
static CoglTexture *
|
||||||
st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache,
|
st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache,
|
||||||
StTextureCachePolicy policy,
|
StTextureCachePolicy policy,
|
||||||
const gchar *uri,
|
const gchar *uri,
|
||||||
@ -1275,7 +1281,7 @@ st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache,
|
|||||||
int scale,
|
int scale,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
CoglHandle texdata;
|
CoglTexture *texdata;
|
||||||
GdkPixbuf *pixbuf;
|
GdkPixbuf *pixbuf;
|
||||||
char *key;
|
char *key;
|
||||||
|
|
||||||
@ -1289,17 +1295,17 @@ st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache,
|
|||||||
if (!pixbuf)
|
if (!pixbuf)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
texdata = pixbuf_to_cogl_handle (pixbuf);
|
texdata = pixbuf_to_cogl_texture (pixbuf);
|
||||||
g_object_unref (pixbuf);
|
g_object_unref (pixbuf);
|
||||||
|
|
||||||
if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER)
|
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);
|
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
cogl_handle_ref (texdata);
|
cogl_object_ref (texdata);
|
||||||
|
|
||||||
ensure_monitor_for_uri (cache, uri);
|
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
|
* @cache: A #StTextureCache
|
||||||
* @file_path: Path to a file in supported image format
|
* @file_path: Path to a file in supported image format
|
||||||
* @scale: Scale factor of the display
|
* @scale: Scale factor of the display
|
||||||
*
|
*
|
||||||
* This function synchronously loads the given file path
|
* This function synchronously loads the given file path
|
||||||
* into a COGL texture. On error, a warning is emitted
|
* 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,
|
st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
|
||||||
const gchar *file_path,
|
const gchar *file_path,
|
||||||
gint scale)
|
gint scale)
|
||||||
{
|
{
|
||||||
CoglHandle texture;
|
CoglTexture *texture;
|
||||||
GFile *file;
|
GFile *file;
|
||||||
char *uri;
|
char *uri;
|
||||||
GError *error = NULL;
|
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_warning ("Failed to load %s: %s", file_path, error->message);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
return COGL_INVALID_HANDLE;
|
return NULL;
|
||||||
}
|
}
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
@ -93,9 +93,9 @@ ClutterActor *st_texture_cache_load_uri_async (StTextureCache *cache,
|
|||||||
int available_height,
|
int available_height,
|
||||||
int scale);
|
int scale);
|
||||||
|
|
||||||
CoglHandle st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
|
CoglTexture *st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
|
||||||
const gchar *file_path,
|
const gchar *file_path,
|
||||||
gint scale);
|
gint scale);
|
||||||
|
|
||||||
cairo_surface_t *st_texture_cache_load_file_to_cairo_surface (StTextureCache *cache,
|
cairo_surface_t *st_texture_cache_load_file_to_cairo_surface (StTextureCache *cache,
|
||||||
const gchar *file_path,
|
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.
|
* 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,
|
CoglTexture * st_texture_cache_load (StTextureCache *cache,
|
||||||
const char *key,
|
const char *key,
|
||||||
StTextureCachePolicy policy,
|
StTextureCachePolicy policy,
|
||||||
StTextureCacheLoader load,
|
StTextureCacheLoader load,
|
||||||
void *data,
|
void *data,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
|
||||||
#endif /* __ST_TEXTURE_CACHE_H__ */
|
#endif /* __ST_TEXTURE_CACHE_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user