gl: Check if texture has a mipmap

When reusing an exiting texture, check if it has a mipmap, in case
we need one.
This commit is contained in:
Matthias Clasen 2024-01-03 12:05:07 -05:00
parent 3ebbcc981a
commit cfa53de9af
2 changed files with 18 additions and 9 deletions

View File

@ -202,6 +202,7 @@ gsk_gl_driver_get_texture_by_id (GskGLDriver *self,
* gsk_gl_driver_lookup_texture: * gsk_gl_driver_lookup_texture:
* @self: a `GskGLDriver` * @self: a `GskGLDriver`
* @key: the key for the texture * @key: the key for the texture
* @has_mipmap: (out): Return location for whether the texture has a mipmap
* *
* Looks up a texture in the texture cache by @key. * Looks up a texture in the texture cache by @key.
* *
@ -211,7 +212,8 @@ gsk_gl_driver_get_texture_by_id (GskGLDriver *self,
*/ */
static inline guint static inline guint
gsk_gl_driver_lookup_texture (GskGLDriver *self, gsk_gl_driver_lookup_texture (GskGLDriver *self,
const GskTextureKey *key) const GskTextureKey *key,
gboolean *has_mipmap)
{ {
gpointer id; gpointer id;
@ -222,6 +224,9 @@ gsk_gl_driver_lookup_texture (GskGLDriver *self,
if (texture != NULL) if (texture != NULL)
texture->last_used_in_frame = self->current_frame_id; texture->last_used_in_frame = self->current_frame_id;
if (has_mipmap)
*has_mipmap = texture ? texture->has_mipmap : FALSE;
return GPOINTER_TO_UINT (id); return GPOINTER_TO_UINT (id);
} }

View File

@ -1190,7 +1190,7 @@ gsk_gl_render_job_visit_as_fallback (GskGLRenderJob *job,
key.scale_x = scale_x; key.scale_x = scale_x;
key.scale_y = scale_y; key.scale_y = scale_y;
texture_id = gsk_gl_driver_lookup_texture (job->driver, &key); texture_id = gsk_gl_driver_lookup_texture (job->driver, &key, NULL);
if (texture_id != 0) if (texture_id != 0)
goto done; goto done;
@ -2216,7 +2216,7 @@ gsk_gl_render_job_visit_blurred_inset_shadow_node (GskGLRenderJob *job,
key.scale_x = scale_x; key.scale_x = scale_x;
key.scale_y = scale_y; key.scale_y = scale_y;
blurred_texture_id = gsk_gl_driver_lookup_texture (job->driver, &key); blurred_texture_id = gsk_gl_driver_lookup_texture (job->driver, &key, NULL);
if (blurred_texture_id == 0) if (blurred_texture_id == 0)
{ {
@ -3216,7 +3216,7 @@ gsk_gl_render_job_visit_blur_node (GskGLRenderJob *job,
key.scale_x = job->scale_x; key.scale_x = job->scale_x;
key.scale_y = job->scale_y; key.scale_y = job->scale_y;
offscreen.texture_id = gsk_gl_driver_lookup_texture (job->driver, &key); offscreen.texture_id = gsk_gl_driver_lookup_texture (job->driver, &key, NULL);
cache_texture = offscreen.texture_id == 0; cache_texture = offscreen.texture_id == 0;
blur_node (job, blur_node (job,
@ -3771,6 +3771,8 @@ gsk_gl_render_job_visit_texture_scale_node (GskGLRenderJob *job,
float u0, u1, v0, v1; float u0, u1, v0, v1;
GskTextureKey key; GskTextureKey key;
guint texture_id; guint texture_id;
gboolean need_mipmap;
gboolean has_mipmap;
gsk_gl_render_job_untransform_bounds (job, &job->current_clip->rect.bounds, &clip_rect); gsk_gl_render_job_untransform_bounds (job, &job->current_clip->rect.bounds, &clip_rect);
@ -3783,9 +3785,11 @@ gsk_gl_render_job_visit_texture_scale_node (GskGLRenderJob *job,
key.scale_x = 1.; key.scale_x = 1.;
key.scale_y = 1.; key.scale_y = 1.;
texture_id = gsk_gl_driver_lookup_texture (job->driver, &key); need_mipmap = (filter == GSK_SCALING_FILTER_TRILINEAR);
if (texture_id != 0) texture_id = gsk_gl_driver_lookup_texture (job->driver, &key, &has_mipmap);
if (texture_id != 0 && (!need_mipmap || has_mipmap))
goto render_texture; goto render_texture;
viewport = GRAPHENE_RECT_INIT (0, 0, viewport = GRAPHENE_RECT_INIT (0, 0,
@ -3816,7 +3820,7 @@ gsk_gl_render_job_visit_texture_scale_node (GskGLRenderJob *job,
{ {
gpointer sync; gpointer sync;
texture_id = gsk_gl_driver_load_texture (job->driver, texture, filter == GSK_SCALING_FILTER_TRILINEAR); texture_id = gsk_gl_driver_load_texture (job->driver, texture, need_mipmap);
if (GDK_IS_GL_TEXTURE (texture) && texture_id == gdk_gl_texture_get_id (GDK_GL_TEXTURE (texture))) if (GDK_IS_GL_TEXTURE (texture) && texture_id == gdk_gl_texture_get_id (GDK_GL_TEXTURE (texture)))
sync = gdk_gl_texture_get_sync (GDK_GL_TEXTURE (texture)); sync = gdk_gl_texture_get_sync (GDK_GL_TEXTURE (texture));
@ -3853,7 +3857,7 @@ gsk_gl_render_job_visit_texture_scale_node (GskGLRenderJob *job,
GskGLTextureSlice *slices = NULL; GskGLTextureSlice *slices = NULL;
guint n_slices = 0; guint n_slices = 0;
gsk_gl_driver_slice_texture (job->driver, texture, filter == GSK_SCALING_FILTER_TRILINEAR, &slices, &n_slices); gsk_gl_driver_slice_texture (job->driver, texture, need_mipmap, &slices, &n_slices);
if (gsk_gl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit))) if (gsk_gl_render_job_begin_draw (job, CHOOSE_PROGRAM (job, blit)))
{ {
@ -4352,7 +4356,7 @@ gsk_gl_render_job_visit_node_with_offscreen (GskGLRenderJob *job,
} }
/* Check if we've already cached the drawn texture. */ /* Check if we've already cached the drawn texture. */
cached_id = gsk_gl_driver_lookup_texture (job->driver, &key); cached_id = gsk_gl_driver_lookup_texture (job->driver, &key, NULL);
if (cached_id != 0) if (cached_id != 0)
{ {