From 895d427c6a7e883b13d0aeddce18bc271318a63d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 15 Mar 2023 14:31:45 -0400 Subject: [PATCH 1/4] gsk: Add a way to limit texture sizes Allow to set max texture size using the GSK_MAX_TEXTURE_SIZE environment variable. We only allow to lower the max (for obvious reasons), and we don't allow values smaller than 512 (since our atlases use that size). --- gsk/gl/gskglcommandqueue.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/gsk/gl/gskglcommandqueue.c b/gsk/gl/gskglcommandqueue.c index 8fee49fd15..30617898e8 100644 --- a/gsk/gl/gskglcommandqueue.c +++ b/gsk/gl/gskglcommandqueue.c @@ -449,7 +449,22 @@ gsk_gl_command_queue_new (GdkGLContext *context, /* Determine max texture size immediately and restore context */ gdk_gl_context_make_current (context); + glGetIntegerv (GL_MAX_TEXTURE_SIZE, &self->max_texture_size); + if (g_getenv ("GSK_MAX_TEXTURE_SIZE")) + { + int max_texture_size = atoi (g_getenv ("GSK_MAX_TEXTURE_SIZE")); + if (max_texture_size == 0) + { + g_warning ("Failed to parse GSK_MAX_TEXTURE_SIZE"); + } + else + { + max_texture_size = MAX (max_texture_size, 512); + GSK_DEBUG(OPENGL, "Limiting max texture size to %d", max_texture_size); + self->max_texture_size = MIN (self->max_texture_size, max_texture_size); + } + } return g_steal_pointer (&self); } From 2e2c41cef60112140533d9bf61fd56ce04ca50a0 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 15 Mar 2023 15:33:32 -0400 Subject: [PATCH 2/4] gsk: Fix handling of large textures When the texture is too large, actually shrink the size to max_texture_size. --- gsk/gl/gskglcommandqueue.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gsk/gl/gskglcommandqueue.c b/gsk/gl/gskglcommandqueue.c index 30617898e8..39917877ad 100644 --- a/gsk/gl/gskglcommandqueue.c +++ b/gsk/gl/gskglcommandqueue.c @@ -1469,8 +1469,8 @@ gsk_gl_command_queue_upload_texture (GskGLCommandQueue *self, g_warning ("Attempt to create texture of size %ux%u but max size is %d. " "Clipping will occur.", width, height, self->max_texture_size); - width = MAX (width, self->max_texture_size); - height = MAX (height, self->max_texture_size); + width = MIN (width, self->max_texture_size); + height = MIN (height, self->max_texture_size); } texture_id = gsk_gl_command_queue_create_texture (self, width, height, GL_RGBA8, min_filter, mag_filter); if (texture_id == -1) From 2322fecf3b0ab4674f83d35e1e4ffc33b31030c9 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 15 Mar 2023 15:45:01 -0400 Subject: [PATCH 3/4] gsk: Fix texture slicing We were just returning NULL for slices here, which wasn't the intention. --- gsk/gl/gskgldriverprivate.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gsk/gl/gskgldriverprivate.h b/gsk/gl/gskgldriverprivate.h index 2b39217919..e1f30c2d2d 100644 --- a/gsk/gl/gskgldriverprivate.h +++ b/gsk/gl/gskgldriverprivate.h @@ -243,7 +243,7 @@ gsk_gl_driver_slice_texture (GskGLDriver *self, if ((t = gdk_texture_get_render_data (texture, self))) { - if (min_cols == 0 && min_rows == 0) + if (min_cols == 0 && min_rows == 0 && t->slices) { *out_slices = t->slices; *out_n_slices = t->n_slices; From d1256648f41e1ad7fbd5ce1b75a86dba3e98def2 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 15 Mar 2023 17:50:01 -0400 Subject: [PATCH 4/4] gsk: Use linear filtering for sliced textures We use linear for unsliced textures, so we need to do the same for sliced ones. --- gsk/gl/gskglrenderjob.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gsk/gl/gskglrenderjob.c b/gsk/gl/gskglrenderjob.c index 53a759e293..aca5797b53 100644 --- a/gsk/gl/gskglrenderjob.c +++ b/gsk/gl/gskglrenderjob.c @@ -3575,7 +3575,7 @@ gsk_gl_render_job_visit_texture (GskGLRenderJob *job, GskGLTextureSlice *slices = NULL; guint n_slices = 0; - gsk_gl_driver_slice_texture (job->driver, texture, GL_NEAREST, GL_NEAREST, 0, 0, &slices, &n_slices); + gsk_gl_driver_slice_texture (job->driver, texture, GL_LINEAR, GL_LINEAR, 0, 0, &slices, &n_slices); g_assert (slices != NULL); g_assert (n_slices > 0);