gsk: Add a way to limit texture sizes
authorMatthias Clasen <mclasen@redhat.com>
Wed, 15 Mar 2023 18:31:45 +0000 (14:31 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 15 Mar 2023 18:35:57 +0000 (14:35 -0400)
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

index 8fee49fd15b4cb6659f03146d24d0233267b6384..30617898e801a5cd8e5b4f72e5979b0b48f4b13e 100644 (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);
 }