From e34d1b8a26496760445d4e9f057b637a34072594 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 15 Oct 2019 07:51:05 -0400 Subject: [PATCH] gl: Slightly rework the icon cache api Return a pointer to the IconData struct. This is closer to the glyph cache api, and will allow us to add similar shortcuts. For now, just store texture coords in the form we need, avoiding converting them over and over. --- gsk/gl/gskgliconcache.c | 40 ++++++++++++---------------------- gsk/gl/gskgliconcacheprivate.h | 13 +++++++++-- gsk/gl/gskglrenderer.c | 29 ++++++++++++------------ 3 files changed, 39 insertions(+), 43 deletions(-) diff --git a/gsk/gl/gskgliconcache.c b/gsk/gl/gskgliconcache.c index fc518b8851..6c0315db1c 100644 --- a/gsk/gl/gskgliconcache.c +++ b/gsk/gl/gskgliconcache.c @@ -7,15 +7,6 @@ #define MAX_FRAME_AGE 60 -typedef struct -{ - graphene_rect_t texture_rect; - GskGLTextureAtlas *atlas; - GdkTexture *source_texture; - guint accessed : 1; - guint used : 1; -} IconData; - static void icon_data_free (gpointer p) { @@ -100,9 +91,9 @@ gsk_gl_icon_cache_begin_frame (GskGLIconCache *self, { if (icon_data->used) { - const int w = icon_data->texture_rect.size.width * icon_data->atlas->width; - const int h = icon_data->texture_rect.size.height * icon_data->atlas->height; - gsk_gl_texture_atlas_mark_unused (icon_data->atlas, w + 2, h + 2); + const int width = gdk_texture_get_width (icon_data->source_texture); + const int height = gdk_texture_get_height (icon_data->source_texture); + gsk_gl_texture_atlas_mark_unused (icon_data->atlas, width + 2, height + 2); icon_data->used = FALSE; } } @@ -117,8 +108,7 @@ gsk_gl_icon_cache_begin_frame (GskGLIconCache *self, void gsk_gl_icon_cache_lookup_or_add (GskGLIconCache *self, GdkTexture *texture, - int *out_texture_id, - graphene_rect_t *out_texture_rect) + const IconData **out_icon_data) { IconData *icon_data = g_hash_table_lookup (self->icons, texture); @@ -126,16 +116,15 @@ gsk_gl_icon_cache_lookup_or_add (GskGLIconCache *self, { if (!icon_data->used) { - const int w = icon_data->texture_rect.size.width * icon_data->atlas->width; - const int h = icon_data->texture_rect.size.height * icon_data->atlas->height; + const int width = gdk_texture_get_width (texture); + const int height = gdk_texture_get_height (texture); - gsk_gl_texture_atlas_mark_used (icon_data->atlas, w + 2, h + 2); + gsk_gl_texture_atlas_mark_used (icon_data->atlas, width + 2, height + 2); icon_data->used = TRUE; } icon_data->accessed = TRUE; - *out_texture_id = icon_data->atlas->texture_id; - *out_texture_rect = icon_data->texture_rect; + *out_icon_data = icon_data; return; } @@ -155,12 +144,12 @@ gsk_gl_icon_cache_lookup_or_add (GskGLIconCache *self, icon_data->atlas = atlas; icon_data->accessed = TRUE; icon_data->used = TRUE; + icon_data->texture_id = atlas->texture_id; icon_data->source_texture = g_object_ref (texture); - graphene_rect_init (&icon_data->texture_rect, - (float)(packed_x + 1) / atlas->width, - (float)(packed_y + 1) / atlas->height, - (float)width / atlas->width, - (float)height / atlas->height); + icon_data->x = (float)(packed_x + 1) / atlas->width; + icon_data->y = (float)(packed_y + 1) / atlas->width; + icon_data->x2 = icon_data->x + (float)width / atlas->width; + icon_data->y2 = icon_data->y + (float)height / atlas->height; g_hash_table_insert (self->icons, texture, icon_data); @@ -240,8 +229,7 @@ gsk_gl_icon_cache_lookup_or_add (GskGLIconCache *self, gdk_gl_context_pop_debug_group (gdk_gl_context_get_current ()); - *out_texture_id = atlas->texture_id; - *out_texture_rect = icon_data->texture_rect; + *out_icon_data = icon_data; cairo_surface_destroy (surface); diff --git a/gsk/gl/gskgliconcacheprivate.h b/gsk/gl/gskgliconcacheprivate.h index 367e08ceb4..e076278a4e 100644 --- a/gsk/gl/gskgliconcacheprivate.h +++ b/gsk/gl/gskgliconcacheprivate.h @@ -21,6 +21,16 @@ typedef struct int timestamp; } GskGLIconCache; +typedef struct +{ + float x, y, x2, y2; + GskGLTextureAtlas *atlas; + guint used : 1; + guint accessed : 1; + int texture_id; + GdkTexture *source_texture; +} IconData; + GskGLIconCache * gsk_gl_icon_cache_new (GdkDisplay *display, GskGLTextureAtlases *atlases); GskGLIconCache * gsk_gl_icon_cache_ref (GskGLIconCache *self); @@ -29,7 +39,6 @@ void gsk_gl_icon_cache_begin_frame (GskGLIconCache *self, GPtrArray *removed_atlases); void gsk_gl_icon_cache_lookup_or_add (GskGLIconCache *self, GdkTexture *texture, - int *out_texture_id, - graphene_rect_t *out_texture_rect); + const IconData **out_icon_data); #endif diff --git a/gsk/gl/gskglrenderer.c b/gsk/gl/gskglrenderer.c index 886b9fdc4e..9824622505 100644 --- a/gsk/gl/gskglrenderer.c +++ b/gsk/gl/gskglrenderer.c @@ -827,36 +827,35 @@ upload_texture (GskGLRenderer *self, GdkTexture *texture, TextureRegion *out_region) { - int texture_id; - if (texture->width <= 128 && texture->height <= 128 && !GDK_IS_GL_TEXTURE (texture)) { - graphene_rect_t trect; + const IconData *icon_data; gsk_gl_icon_cache_lookup_or_add (self->icon_cache, texture, - &texture_id, - &trect); - out_region->x = trect.origin.x; - out_region->y = trect.origin.y; - out_region->x2 = out_region->x + trect.size.width; - out_region->y2 = out_region->y + trect.size.height; + &icon_data); + + out_region->texture_id = icon_data->texture_id; + out_region->x = icon_data->x; + out_region->y = icon_data->y; + out_region->x2 = icon_data->x2; + out_region->y2 = icon_data->y2; } else { - texture_id = gsk_gl_driver_get_texture_for_texture (self->gl_driver, - texture, - GL_LINEAR, - GL_LINEAR); + out_region->texture_id = + gsk_gl_driver_get_texture_for_texture (self->gl_driver, + texture, + GL_LINEAR, + GL_LINEAR); + out_region->x = 0; out_region->y = 0; out_region->x2 = 1; out_region->y2 = 1; } - - out_region->texture_id = texture_id; } static inline void