mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-09-20 05:50:11 +00:00
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.
This commit is contained in:
parent
c5af463843
commit
e34d1b8a26
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user