Merge branch 'max-texture-size' into 'main'

gsk: Add a way to limit texture sizes

See merge request GNOME/gtk!5656
This commit is contained in:
Matthias Clasen 2023-03-16 03:03:41 +00:00
commit d72a6167ed
3 changed files with 19 additions and 4 deletions

View File

@ -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);
}
@ -1454,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)

View File

@ -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;

View File

@ -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);