mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 22:30:22 +00:00
vulkan: Batch uploads from the glyph cache
This uses the new api that was introduced in the previous commit.
This commit is contained in:
parent
64322a2c41
commit
dbc0caf27d
@ -54,6 +54,7 @@ static gboolean glyph_cache_equal (gconstpointer v1,
|
|||||||
gconstpointer v2);
|
gconstpointer v2);
|
||||||
static void glyph_cache_key_free (gpointer v);
|
static void glyph_cache_key_free (gpointer v);
|
||||||
static void glyph_cache_value_free (gpointer v);
|
static void glyph_cache_value_free (gpointer v);
|
||||||
|
static void dirty_glyph_free (gpointer v);
|
||||||
|
|
||||||
static Atlas *
|
static Atlas *
|
||||||
create_atlas (GskVulkanGlyphCache *cache)
|
create_atlas (GskVulkanGlyphCache *cache)
|
||||||
@ -81,7 +82,7 @@ free_atlas (gpointer v)
|
|||||||
if (atlas->surface)
|
if (atlas->surface)
|
||||||
cairo_surface_destroy (atlas->surface);
|
cairo_surface_destroy (atlas->surface);
|
||||||
g_clear_object (&atlas->image);
|
g_clear_object (&atlas->image);
|
||||||
g_list_free_full (atlas->dirty_glyphs, g_free);
|
g_list_free_full (atlas->dirty_glyphs, dirty_glyph_free);
|
||||||
g_free (atlas);
|
g_free (atlas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,8 +154,19 @@ glyph_cache_value_free (gpointer v)
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
GlyphCacheKey *key;
|
GlyphCacheKey *key;
|
||||||
GskVulkanCachedGlyph *value;
|
GskVulkanCachedGlyph *value;
|
||||||
|
cairo_surface_t *surface;
|
||||||
} DirtyGlyph;
|
} DirtyGlyph;
|
||||||
|
|
||||||
|
static void
|
||||||
|
dirty_glyph_free (gpointer v)
|
||||||
|
{
|
||||||
|
DirtyGlyph *glyph = v;
|
||||||
|
|
||||||
|
if (glyph->surface)
|
||||||
|
cairo_surface_destroy (glyph->surface);
|
||||||
|
g_free (glyph);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_to_cache (GskVulkanGlyphCache *cache,
|
add_to_cache (GskVulkanGlyphCache *cache,
|
||||||
GlyphCacheKey *key,
|
GlyphCacheKey *key,
|
||||||
@ -230,11 +242,12 @@ add_to_cache (GskVulkanGlyphCache *cache,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
upload_glyph (Atlas *atlas,
|
render_glyph (Atlas *atlas,
|
||||||
GskVulkanUploader *uploader,
|
DirtyGlyph *glyph,
|
||||||
GlyphCacheKey *key,
|
GskImageRegion *region)
|
||||||
GskVulkanCachedGlyph *value)
|
|
||||||
{
|
{
|
||||||
|
GlyphCacheKey *key = glyph->key;
|
||||||
|
GskVulkanCachedGlyph *value = glyph->value;
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
cairo_t *cr;
|
cairo_t *cr;
|
||||||
cairo_scaled_font_t *scaled_font;
|
cairo_scaled_font_t *scaled_font;
|
||||||
@ -261,16 +274,38 @@ upload_glyph (Atlas *atlas,
|
|||||||
|
|
||||||
cairo_destroy (cr);
|
cairo_destroy (cr);
|
||||||
|
|
||||||
gsk_vulkan_image_upload_region (atlas->image,
|
glyph->surface = surface;
|
||||||
uploader,
|
|
||||||
cairo_image_surface_get_data (surface),
|
|
||||||
cairo_image_surface_get_width (surface),
|
|
||||||
cairo_image_surface_get_height (surface),
|
|
||||||
cairo_image_surface_get_stride (surface),
|
|
||||||
(gsize)(value->tx * atlas->width),
|
|
||||||
(gsize)(value->ty * atlas->height));
|
|
||||||
|
|
||||||
cairo_surface_destroy (surface);
|
region->data = cairo_image_surface_get_data (surface);
|
||||||
|
region->width = cairo_image_surface_get_width (surface);
|
||||||
|
region->height = cairo_image_surface_get_height (surface);
|
||||||
|
region->stride = cairo_image_surface_get_stride (surface);
|
||||||
|
region->x = (gsize)(value->tx * atlas->width);
|
||||||
|
region->y = (gsize)(value->ty * atlas->height);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
upload_dirty_glyphs (Atlas *atlas,
|
||||||
|
GskVulkanUploader *uploader)
|
||||||
|
{
|
||||||
|
GList *l;
|
||||||
|
guint num_regions;
|
||||||
|
GskImageRegion *regions;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
num_regions = g_list_length (atlas->dirty_glyphs);
|
||||||
|
regions = alloca (sizeof (GskImageRegion) * num_regions);
|
||||||
|
|
||||||
|
for (l = atlas->dirty_glyphs, i = 0; l; l = l->next, i++)
|
||||||
|
render_glyph (atlas, (DirtyGlyph *)l->data, ®ions[i]);
|
||||||
|
|
||||||
|
GSK_NOTE (GLYPH_CACHE,
|
||||||
|
g_print ("uploading %d glyphs to cache\n", num_regions));
|
||||||
|
|
||||||
|
gsk_vulkan_image_upload_regions (atlas->image, uploader, num_regions, regions);
|
||||||
|
|
||||||
|
g_list_free_full (atlas->dirty_glyphs, dirty_glyph_free);
|
||||||
|
atlas->dirty_glyphs = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
GskVulkanGlyphCache *
|
GskVulkanGlyphCache *
|
||||||
@ -345,7 +380,6 @@ gsk_vulkan_glyph_cache_get_glyph_image (GskVulkanGlyphCache *cache,
|
|||||||
guint index)
|
guint index)
|
||||||
{
|
{
|
||||||
Atlas *atlas;
|
Atlas *atlas;
|
||||||
GList *l;
|
|
||||||
|
|
||||||
g_return_val_if_fail (index < cache->atlases->len, NULL);
|
g_return_val_if_fail (index < cache->atlases->len, NULL);
|
||||||
|
|
||||||
@ -354,13 +388,8 @@ gsk_vulkan_glyph_cache_get_glyph_image (GskVulkanGlyphCache *cache,
|
|||||||
if (atlas->image == NULL)
|
if (atlas->image == NULL)
|
||||||
atlas->image = gsk_vulkan_image_new_for_atlas (cache->vulkan, atlas->width, atlas->height);
|
atlas->image = gsk_vulkan_image_new_for_atlas (cache->vulkan, atlas->width, atlas->height);
|
||||||
|
|
||||||
for (l = atlas->dirty_glyphs; l; l = l->next)
|
if (atlas->dirty_glyphs)
|
||||||
{
|
upload_dirty_glyphs (atlas, uploader);
|
||||||
DirtyGlyph *glyph = l->data;
|
|
||||||
upload_glyph (atlas, uploader, glyph->key, glyph->value);
|
|
||||||
}
|
|
||||||
g_list_free_full (atlas->dirty_glyphs, g_free);
|
|
||||||
atlas->dirty_glyphs = NULL;
|
|
||||||
|
|
||||||
return atlas->image;
|
return atlas->image;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user