2017-11-18 13:30:57 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskglglyphcacheprivate.h"
|
|
|
|
#include "gskgldriverprivate.h"
|
|
|
|
#include "gskdebugprivate.h"
|
|
|
|
#include "gskprivate.h"
|
2019-05-22 05:33:45 +00:00
|
|
|
#include "gskgltextureatlasprivate.h"
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-04-24 11:27:43 +00:00
|
|
|
#include "gdk/gdkglcontextprivate.h"
|
2020-09-24 13:03:48 +00:00
|
|
|
#include "gdk/gdkmemorytextureprivate.h"
|
2019-04-24 11:27:43 +00:00
|
|
|
|
2017-11-18 13:30:57 +00:00
|
|
|
#include <graphene.h>
|
2018-03-28 03:23:43 +00:00
|
|
|
#include <cairo.h>
|
2017-11-18 13:30:57 +00:00
|
|
|
#include <epoxy/gl.h>
|
2019-10-09 21:46:36 +00:00
|
|
|
#include <string.h>
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
/* Cache eviction strategy
|
2017-11-18 13:30:57 +00:00
|
|
|
*
|
2019-10-12 22:26:09 +00:00
|
|
|
* We mark glyphs as accessed every time we use them.
|
|
|
|
* Every few frames, we mark glyphs that haven't been
|
|
|
|
* accessed since the last check as old.
|
2019-06-04 21:27:09 +00:00
|
|
|
*
|
2019-10-12 22:26:09 +00:00
|
|
|
* We keep count of the pixels of each atlas that are
|
|
|
|
* taken up by old data. When the fraction of old pixels
|
|
|
|
* gets too high, we drop the atlas and all the items it
|
|
|
|
* contained.
|
|
|
|
*
|
|
|
|
* Big glyphs are not stored in the atlas, they get their
|
|
|
|
* own texture, but they are still cached.
|
2017-11-18 13:30:57 +00:00
|
|
|
*/
|
|
|
|
|
2019-10-12 16:34:56 +00:00
|
|
|
#define MAX_FRAME_AGE (60)
|
2019-07-28 09:57:43 +00:00
|
|
|
#define MAX_GLYPH_SIZE 128 /* Will get its own texture if bigger */
|
2017-11-18 13:30:57 +00:00
|
|
|
|
|
|
|
static guint glyph_cache_hash (gconstpointer v);
|
|
|
|
static gboolean glyph_cache_equal (gconstpointer v1,
|
|
|
|
gconstpointer v2);
|
|
|
|
static void glyph_cache_key_free (gpointer v);
|
|
|
|
static void glyph_cache_value_free (gpointer v);
|
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
GskGLGlyphCache *
|
|
|
|
gsk_gl_glyph_cache_new (GdkDisplay *display,
|
|
|
|
GskGLTextureAtlases *atlases)
|
2017-11-18 13:30:57 +00:00
|
|
|
{
|
2019-06-04 21:27:09 +00:00
|
|
|
GskGLGlyphCache *glyph_cache;
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
glyph_cache = g_new0 (GskGLGlyphCache, 1);
|
2019-02-10 09:12:47 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
glyph_cache->display = display;
|
|
|
|
glyph_cache->hash_table = g_hash_table_new_full (glyph_cache_hash, glyph_cache_equal,
|
|
|
|
glyph_cache_key_free, glyph_cache_value_free);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
glyph_cache->atlases = gsk_gl_texture_atlases_ref (atlases);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
glyph_cache->ref_count = 1;
|
2019-01-06 14:35:54 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
return glyph_cache;
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
GskGLGlyphCache *
|
|
|
|
gsk_gl_glyph_cache_ref (GskGLGlyphCache *self)
|
2017-11-18 13:30:57 +00:00
|
|
|
{
|
2019-06-04 21:27:09 +00:00
|
|
|
self->ref_count++;
|
|
|
|
|
|
|
|
return self;
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-06-04 21:27:09 +00:00
|
|
|
gsk_gl_glyph_cache_unref (GskGLGlyphCache *self)
|
2017-11-18 13:30:57 +00:00
|
|
|
{
|
2019-06-04 21:27:09 +00:00
|
|
|
g_assert (self->ref_count > 0);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
if (self->ref_count == 1)
|
2017-11-18 13:30:57 +00:00
|
|
|
{
|
2019-06-04 21:27:09 +00:00
|
|
|
gsk_gl_texture_atlases_unref (self->atlases);
|
|
|
|
g_hash_table_unref (self->hash_table);
|
|
|
|
g_free (self);
|
|
|
|
return;
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
self->ref_count--;
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
glyph_cache_equal (gconstpointer v1, gconstpointer v2)
|
|
|
|
{
|
2019-10-13 00:09:14 +00:00
|
|
|
return memcmp (v1, v2, sizeof (CacheKeyData)) == 0;
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
glyph_cache_hash (gconstpointer v)
|
|
|
|
{
|
|
|
|
const GlyphCacheKey *key = v;
|
|
|
|
|
2019-10-10 01:49:43 +00:00
|
|
|
return key->hash;
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
glyph_cache_key_free (gpointer v)
|
|
|
|
{
|
|
|
|
GlyphCacheKey *f = v;
|
|
|
|
|
2019-10-13 00:09:14 +00:00
|
|
|
g_object_unref (f->data.font);
|
2017-11-18 13:30:57 +00:00
|
|
|
g_free (f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
glyph_cache_value_free (gpointer v)
|
|
|
|
{
|
|
|
|
g_free (v);
|
|
|
|
}
|
|
|
|
|
2019-05-20 13:12:15 +00:00
|
|
|
static gboolean
|
2019-06-04 21:27:09 +00:00
|
|
|
render_glyph (GlyphCacheKey *key,
|
|
|
|
GskGLCachedGlyph *value,
|
|
|
|
GskImageRegion *region)
|
2017-11-18 13:30:57 +00:00
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
cairo_scaled_font_t *scaled_font;
|
2019-08-01 04:18:19 +00:00
|
|
|
PangoGlyphString glyph_string;
|
|
|
|
PangoGlyphInfo glyph_info;
|
2019-05-20 13:12:15 +00:00
|
|
|
int surface_width, surface_height;
|
2019-06-03 02:46:12 +00:00
|
|
|
int stride;
|
|
|
|
unsigned char *data;
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-10-13 00:09:14 +00:00
|
|
|
scaled_font = pango_cairo_font_get_scaled_font ((PangoCairoFont *)key->data.font);
|
2017-11-18 13:30:57 +00:00
|
|
|
if (G_UNLIKELY (!scaled_font || cairo_scaled_font_status (scaled_font) != CAIRO_STATUS_SUCCESS))
|
2019-06-04 21:27:09 +00:00
|
|
|
{
|
|
|
|
g_warning ("Failed to get a font");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2019-05-20 13:12:15 +00:00
|
|
|
|
2019-10-13 00:09:14 +00:00
|
|
|
surface_width = value->draw_width * key->data.scale / 1024;
|
|
|
|
surface_height = value->draw_height * key->data.scale / 1024;
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-06-03 02:46:12 +00:00
|
|
|
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, surface_width);
|
|
|
|
data = g_malloc0 (stride * surface_height);
|
|
|
|
surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32,
|
|
|
|
surface_width, surface_height,
|
|
|
|
stride);
|
2019-10-13 00:09:14 +00:00
|
|
|
cairo_surface_set_device_scale (surface, key->data.scale / 1024.0, key->data.scale / 1024.0);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
|
|
|
cr = cairo_create (surface);
|
|
|
|
|
|
|
|
cairo_set_scaled_font (cr, scaled_font);
|
|
|
|
cairo_set_source_rgba (cr, 1, 1, 1, 1);
|
|
|
|
|
2019-10-13 00:09:14 +00:00
|
|
|
glyph_info.glyph = key->data.glyph;
|
2019-08-01 04:18:19 +00:00
|
|
|
glyph_info.geometry.width = value->draw_width * 1024;
|
2019-10-10 01:49:43 +00:00
|
|
|
if (glyph_info.glyph & PANGO_GLYPH_UNKNOWN_FLAG)
|
2021-01-28 23:16:16 +00:00
|
|
|
glyph_info.geometry.x_offset = 250 * key->data.xshift;
|
2018-01-06 12:02:31 +00:00
|
|
|
else
|
2021-01-28 23:16:16 +00:00
|
|
|
glyph_info.geometry.x_offset = 250 * key->data.xshift - value->draw_x * 1024;
|
|
|
|
glyph_info.geometry.y_offset = 250 * key->data.yshift - value->draw_y * 1024;
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-08-01 04:18:19 +00:00
|
|
|
glyph_string.num_glyphs = 1;
|
|
|
|
glyph_string.glyphs = &glyph_info;
|
|
|
|
|
2019-10-13 00:09:14 +00:00
|
|
|
pango_cairo_show_glyph_string (cr, key->data.font, &glyph_string);
|
2017-11-18 13:30:57 +00:00
|
|
|
cairo_destroy (cr);
|
|
|
|
|
2019-02-08 10:01:39 +00:00
|
|
|
cairo_surface_flush (surface);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
|
|
|
region->width = cairo_image_surface_get_width (surface);
|
|
|
|
region->height = cairo_image_surface_get_height (surface);
|
|
|
|
region->stride = cairo_image_surface_get_stride (surface);
|
2019-06-03 02:46:12 +00:00
|
|
|
region->data = data;
|
2019-06-04 21:27:09 +00:00
|
|
|
if (value->atlas)
|
|
|
|
{
|
|
|
|
region->x = (gsize)(value->tx * value->atlas->width);
|
|
|
|
region->y = (gsize)(value->ty * value->atlas->height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
region->x = 0;
|
|
|
|
region->y = 0;
|
|
|
|
}
|
2019-02-08 10:01:39 +00:00
|
|
|
|
|
|
|
cairo_surface_destroy (surface);
|
2019-06-04 21:27:09 +00:00
|
|
|
|
2019-05-20 13:12:15 +00:00
|
|
|
return TRUE;
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-04 21:27:09 +00:00
|
|
|
upload_glyph (GlyphCacheKey *key,
|
|
|
|
GskGLCachedGlyph *value)
|
2017-11-18 13:30:57 +00:00
|
|
|
{
|
2019-06-04 21:27:09 +00:00
|
|
|
GskImageRegion r;
|
2020-09-24 13:03:48 +00:00
|
|
|
guchar *pixel_data;
|
|
|
|
guchar *free_data = NULL;
|
|
|
|
guint gl_format;
|
|
|
|
guint gl_type;
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
gdk_gl_context_push_debug_group_printf (gdk_gl_context_get_current (),
|
|
|
|
"Uploading glyph %d",
|
2019-10-13 00:09:14 +00:00
|
|
|
key->data.glyph);
|
2019-04-24 11:28:11 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
if (render_glyph (key, value, &r))
|
2019-05-20 13:12:15 +00:00
|
|
|
{
|
2019-10-12 01:16:40 +00:00
|
|
|
glPixelStorei (GL_UNPACK_ROW_LENGTH, r.stride / 4);
|
2019-06-04 21:27:09 +00:00
|
|
|
glBindTexture (GL_TEXTURE_2D, value->texture_id);
|
2019-12-17 08:14:54 +00:00
|
|
|
|
|
|
|
if (gdk_gl_context_get_use_es (gdk_gl_context_get_current ()))
|
2020-09-24 13:03:48 +00:00
|
|
|
{
|
|
|
|
pixel_data = free_data = g_malloc (r.width * r.height * 4);
|
|
|
|
gdk_memory_convert (pixel_data, r.width * 4,
|
|
|
|
GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
|
|
|
|
r.data, r.width * 4,
|
|
|
|
GDK_MEMORY_DEFAULT, r.width, r.height);
|
|
|
|
gl_format = GL_RGBA;
|
|
|
|
gl_type = GL_UNSIGNED_BYTE;
|
|
|
|
}
|
2019-12-17 08:14:54 +00:00
|
|
|
else
|
2020-09-24 13:03:48 +00:00
|
|
|
{
|
|
|
|
pixel_data = r.data;
|
|
|
|
gl_format = GL_BGRA;
|
|
|
|
gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
|
|
|
}
|
|
|
|
|
|
|
|
glTexSubImage2D (GL_TEXTURE_2D, 0, r.x, r.y, r.width, r.height,
|
|
|
|
gl_format, gl_type, pixel_data);
|
2019-10-12 01:16:40 +00:00
|
|
|
glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
|
2019-06-04 21:27:09 +00:00
|
|
|
g_free (r.data);
|
2020-09-24 13:03:48 +00:00
|
|
|
g_free (free_data);
|
2019-06-04 21:27:09 +00:00
|
|
|
}
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
gdk_gl_context_pop_debug_group (gdk_gl_context_get_current ());
|
|
|
|
}
|
2019-04-24 11:28:11 +00:00
|
|
|
|
2019-06-04 21:27:09 +00:00
|
|
|
static void
|
|
|
|
add_to_cache (GskGLGlyphCache *self,
|
|
|
|
GlyphCacheKey *key,
|
2019-07-28 09:57:43 +00:00
|
|
|
GskGLDriver *driver,
|
2019-06-04 21:27:09 +00:00
|
|
|
GskGLCachedGlyph *value)
|
|
|
|
{
|
2019-10-13 00:09:14 +00:00
|
|
|
const int width = value->draw_width * key->data.scale / 1024;
|
|
|
|
const int height = value->draw_height * key->data.scale / 1024;
|
2019-06-04 21:27:09 +00:00
|
|
|
|
2019-07-28 09:57:43 +00:00
|
|
|
if (width < MAX_GLYPH_SIZE && height < MAX_GLYPH_SIZE)
|
|
|
|
{
|
|
|
|
GskGLTextureAtlas *atlas = NULL;
|
|
|
|
int packed_x = 0;
|
|
|
|
int packed_y = 0;
|
2019-06-04 21:27:09 +00:00
|
|
|
|
2019-07-28 09:57:43 +00:00
|
|
|
gsk_gl_texture_atlases_pack (self->atlases, width + 2, height + 2, &atlas, &packed_x, &packed_y);
|
2019-06-04 21:27:09 +00:00
|
|
|
|
2019-07-28 09:57:43 +00:00
|
|
|
value->tx = (float)(packed_x + 1) / atlas->width;
|
|
|
|
value->ty = (float)(packed_y + 1) / atlas->height;
|
|
|
|
value->tw = (float)width / atlas->width;
|
|
|
|
value->th = (float)height / atlas->height;
|
|
|
|
value->used = TRUE;
|
2019-06-04 21:27:09 +00:00
|
|
|
|
2019-07-28 09:57:43 +00:00
|
|
|
value->atlas = atlas;
|
|
|
|
value->texture_id = atlas->texture_id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value->atlas = NULL;
|
|
|
|
value->texture_id = gsk_gl_driver_create_texture (driver, width, height);
|
2019-10-12 22:26:09 +00:00
|
|
|
gsk_gl_driver_mark_texture_permanent (driver, value->texture_id);
|
2019-06-04 21:27:09 +00:00
|
|
|
|
2019-07-28 09:57:43 +00:00
|
|
|
gsk_gl_driver_bind_source_texture (driver, value->texture_id);
|
2019-07-31 02:21:52 +00:00
|
|
|
gsk_gl_driver_init_texture_empty (driver, value->texture_id, GL_LINEAR, GL_LINEAR);
|
2019-06-04 21:27:09 +00:00
|
|
|
|
2019-07-28 09:57:43 +00:00
|
|
|
value->tx = 0.0f;
|
|
|
|
value->ty = 0.0f;
|
|
|
|
value->tw = 1.0f;
|
|
|
|
value->th = 1.0f;
|
|
|
|
}
|
2019-02-08 10:01:39 +00:00
|
|
|
|
2019-07-28 09:57:43 +00:00
|
|
|
upload_glyph (key, value);
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
2019-10-12 05:35:13 +00:00
|
|
|
void
|
|
|
|
gsk_gl_glyph_cache_lookup_or_add (GskGLGlyphCache *cache,
|
|
|
|
GlyphCacheKey *lookup,
|
|
|
|
GskGLDriver *driver,
|
|
|
|
const GskGLCachedGlyph **cached_glyph_out)
|
2017-11-18 13:30:57 +00:00
|
|
|
{
|
|
|
|
GskGLCachedGlyph *value;
|
2019-10-10 01:49:43 +00:00
|
|
|
|
|
|
|
value = g_hash_table_lookup (cache->hash_table, lookup);
|
2017-11-18 13:30:57 +00:00
|
|
|
|
|
|
|
if (value)
|
|
|
|
{
|
2019-10-22 05:34:56 +00:00
|
|
|
if (value->atlas && !value->used)
|
|
|
|
{
|
|
|
|
gsk_gl_texture_atlas_mark_used (value->atlas, value->draw_width, value->draw_height);
|
|
|
|
value->used = TRUE;
|
|
|
|
}
|
|
|
|
value->accessed = TRUE;
|
|
|
|
|
2019-10-09 21:27:48 +00:00
|
|
|
*cached_glyph_out = value;
|
2019-10-12 05:35:13 +00:00
|
|
|
return;
|
2019-06-04 21:27:09 +00:00
|
|
|
}
|
2017-11-18 13:30:57 +00:00
|
|
|
|
2019-10-12 05:35:13 +00:00
|
|
|
{
|
|
|
|
GlyphCacheKey *key;
|
|
|
|
PangoRectangle ink_rect;
|
|
|
|
|
2019-10-13 00:09:14 +00:00
|
|
|
pango_font_get_glyph_extents (lookup->data.font, lookup->data.glyph, &ink_rect, NULL);
|
2019-10-12 05:35:13 +00:00
|
|
|
pango_extents_to_pixels (&ink_rect, NULL);
|
2019-10-13 00:09:14 +00:00
|
|
|
if (lookup->data.xshift != 0)
|
2019-10-12 05:35:13 +00:00
|
|
|
ink_rect.width += 1;
|
2019-10-13 00:09:14 +00:00
|
|
|
if (lookup->data.yshift != 0)
|
2019-10-12 05:35:13 +00:00
|
|
|
ink_rect.height += 1;
|
|
|
|
|
|
|
|
value = g_new0 (GskGLCachedGlyph, 1);
|
|
|
|
|
|
|
|
value->draw_x = ink_rect.x;
|
|
|
|
value->draw_y = ink_rect.y;
|
|
|
|
value->draw_width = ink_rect.width;
|
|
|
|
value->draw_height = ink_rect.height;
|
2019-10-12 15:03:04 +00:00
|
|
|
value->accessed = TRUE;
|
2019-10-12 05:35:13 +00:00
|
|
|
value->atlas = NULL; /* For now */
|
|
|
|
|
|
|
|
key = g_new0 (GlyphCacheKey, 1);
|
|
|
|
|
2019-10-13 00:09:14 +00:00
|
|
|
key->data.font = g_object_ref (lookup->data.font);
|
|
|
|
key->data.glyph = lookup->data.glyph;
|
|
|
|
key->data.xshift = lookup->data.xshift;
|
|
|
|
key->data.yshift = lookup->data.yshift;
|
|
|
|
key->data.scale = lookup->data.scale;
|
2019-10-12 05:35:13 +00:00
|
|
|
key->hash = lookup->hash;
|
|
|
|
|
2019-10-13 00:09:14 +00:00
|
|
|
if (key->data.scale > 0 &&
|
|
|
|
value->draw_width * key->data.scale / 1024 > 0 &&
|
|
|
|
value->draw_height * key->data.scale / 1024 > 0)
|
2019-10-12 05:35:13 +00:00
|
|
|
add_to_cache (cache, key, driver, value);
|
|
|
|
|
|
|
|
*cached_glyph_out = value;
|
|
|
|
g_hash_table_insert (cache->hash_table, key, value);
|
|
|
|
}
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-10-12 00:42:24 +00:00
|
|
|
gsk_gl_glyph_cache_begin_frame (GskGLGlyphCache *self,
|
2019-10-12 22:26:09 +00:00
|
|
|
GskGLDriver *driver,
|
2019-10-12 00:42:24 +00:00
|
|
|
GPtrArray *removed_atlases)
|
2017-11-18 13:30:57 +00:00
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
GlyphCacheKey *key;
|
|
|
|
GskGLCachedGlyph *value;
|
2019-10-16 10:34:10 +00:00
|
|
|
guint dropped = 0;
|
2017-11-18 13:30:57 +00:00
|
|
|
|
|
|
|
self->timestamp++;
|
|
|
|
|
2019-10-12 00:42:24 +00:00
|
|
|
if (removed_atlases->len > 0)
|
2019-06-02 22:21:05 +00:00
|
|
|
{
|
2019-10-12 00:42:24 +00:00
|
|
|
g_hash_table_iter_init (&iter, self->hash_table);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&value))
|
2019-06-02 22:21:05 +00:00
|
|
|
{
|
2019-10-12 00:42:24 +00:00
|
|
|
if (g_ptr_array_find (removed_atlases, value->atlas, NULL))
|
|
|
|
{
|
|
|
|
g_hash_table_iter_remove (&iter);
|
|
|
|
dropped++;
|
|
|
|
}
|
2019-05-22 05:33:45 +00:00
|
|
|
}
|
2019-10-12 00:42:24 +00:00
|
|
|
}
|
|
|
|
|
2019-10-12 16:33:43 +00:00
|
|
|
if (self->timestamp % MAX_FRAME_AGE == 30)
|
2019-10-12 00:42:24 +00:00
|
|
|
{
|
2019-10-12 15:03:04 +00:00
|
|
|
g_hash_table_iter_init (&iter, self->hash_table);
|
|
|
|
while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&value))
|
2019-05-22 05:33:45 +00:00
|
|
|
{
|
2019-10-12 15:03:04 +00:00
|
|
|
if (!value->accessed)
|
2019-06-02 22:21:05 +00:00
|
|
|
{
|
2019-10-12 22:26:09 +00:00
|
|
|
if (value->atlas)
|
|
|
|
{
|
|
|
|
if (value->used)
|
|
|
|
{
|
|
|
|
gsk_gl_texture_atlas_mark_unused (value->atlas, value->draw_width, value->draw_height);
|
|
|
|
value->used = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2019-10-12 15:03:04 +00:00
|
|
|
{
|
2019-10-12 22:26:09 +00:00
|
|
|
gsk_gl_driver_destroy_texture (driver, value->texture_id);
|
|
|
|
g_hash_table_iter_remove (&iter);
|
2019-10-16 02:52:28 +00:00
|
|
|
|
|
|
|
/* Sadly, if we drop an atlas-less cached glyph, we
|
|
|
|
* have to treat it like a dropped atlas and purge
|
|
|
|
* text node render data.
|
|
|
|
*/
|
2019-10-16 10:34:10 +00:00
|
|
|
dropped++;
|
2019-10-12 15:03:04 +00:00
|
|
|
}
|
2019-06-02 22:21:05 +00:00
|
|
|
}
|
2019-10-12 22:26:09 +00:00
|
|
|
else
|
|
|
|
value->accessed = FALSE;
|
2019-10-12 15:03:04 +00:00
|
|
|
}
|
2019-10-12 16:32:49 +00:00
|
|
|
|
|
|
|
GSK_NOTE(GLYPH_CACHE, g_message ("%d glyphs cached", g_hash_table_size (self->hash_table)));
|
2017-11-18 13:30:57 +00:00
|
|
|
}
|
2019-10-16 10:34:10 +00:00
|
|
|
|
|
|
|
GSK_NOTE(GLYPH_CACHE, if (dropped > 0) g_message ("Dropped %d glyphs", dropped));
|
2019-10-15 04:14:43 +00:00
|
|
|
}
|