[gtk/glyphy2: 32/53] gsk/gl: allow configuring atlas size




commit 203aea90b5de1593dceacce67725bea0218e9d27
Author: Christian Hergert <chergert redhat com>
Date:   Thu Mar 17 16:43:58 2022 -0700

    gsk/gl: allow configuring atlas size

 gsk/gl/gskgldriver.c                | 11 +++++++----
 gsk/gl/gskgldriverprivate.h         |  4 +++-
 gsk/gl/gskgltexturelibrary.c        | 21 +++++++++++++--------
 gsk/gl/gskgltexturelibraryprivate.h |  3 ++-
 4 files changed, 25 insertions(+), 14 deletions(-)
---
diff --git a/gsk/gl/gskgldriver.c b/gsk/gl/gskgldriver.c
index 327dea93ff..ddd5bed5e9 100644
--- a/gsk/gl/gskgldriver.c
+++ b/gsk/gl/gskgldriver.c
@@ -44,7 +44,6 @@
 #include <gdk/gdkprofilerprivate.h>
 #include <gdk/gdktextureprivate.h>
 
-#define ATLAS_SIZE 512
 #define MAX_OLD_RATIO 0.5
 
 G_DEFINE_TYPE (GskGLDriver, gsk_gl_driver, G_TYPE_OBJECT)
@@ -170,15 +169,19 @@ gsk_gl_texture_atlas_free (GskGLTextureAtlas *atlas)
 }
 
 GskGLTextureAtlas *
-gsk_gl_driver_create_atlas (GskGLDriver *self)
+gsk_gl_driver_create_atlas (GskGLDriver *self,
+                            guint        width,
+                            guint        height)
 {
   GskGLTextureAtlas *atlas;
 
   g_return_val_if_fail (GSK_IS_GL_DRIVER (self), NULL);
+  g_return_val_if_fail (width > 0, NULL);
+  g_return_val_if_fail (height > 0, NULL);
 
   atlas = g_slice_new0 (GskGLTextureAtlas);
-  atlas->width = ATLAS_SIZE;
-  atlas->height = ATLAS_SIZE;
+  atlas->width = width;
+  atlas->height = height;
   /* TODO: We might want to change the strategy about the amount of
    *       nodes here? stb_rect_pack.h says width is optimal. */
   atlas->nodes = g_malloc0_n (atlas->width, sizeof (struct stbrp_node));
diff --git a/gsk/gl/gskgldriverprivate.h b/gsk/gl/gskgldriverprivate.h
index 4500962ed8..37c4cbb77a 100644
--- a/gsk/gl/gskgldriverprivate.h
+++ b/gsk/gl/gskgldriverprivate.h
@@ -184,7 +184,9 @@ void                gsk_gl_driver_add_texture_slices     (GskGLDriver         *s
 GskGLProgram      * gsk_gl_driver_lookup_shader          (GskGLDriver         *self,
                                                           GskGLShader         *shader,
                                                           GError             **error);
-GskGLTextureAtlas * gsk_gl_driver_create_atlas           (GskGLDriver         *self);
+GskGLTextureAtlas * gsk_gl_driver_create_atlas           (GskGLDriver         *self,
+                                                          guint                width,
+                                                          guint                height);
 
 #ifdef G_ENABLE_DEBUG
 void                gsk_gl_driver_save_atlases_to_png    (GskGLDriver         *self,
diff --git a/gsk/gl/gskgltexturelibrary.c b/gsk/gl/gskgltexturelibrary.c
index b0694e7afb..8951f78829 100644
--- a/gsk/gl/gskgltexturelibrary.c
+++ b/gsk/gl/gskgltexturelibrary.c
@@ -28,6 +28,8 @@
 #include "gskgltexturelibraryprivate.h"
 
 #define DEFAULT_MAX_FRAME_AGE 60
+#define DEFAULT_ATLAS_WIDTH 512
+#define DEFAULT_ATLAS_HEIGHT 512
 
 G_DEFINE_ABSTRACT_TYPE (GskGLTextureLibrary, gsk_gl_texture_library, G_TYPE_OBJECT)
 
@@ -119,6 +121,8 @@ static void
 gsk_gl_texture_library_init (GskGLTextureLibrary *self)
 {
   self->max_frame_age = DEFAULT_MAX_FRAME_AGE;
+  self->atlas_width = DEFAULT_ATLAS_WIDTH;
+  self->atlas_height = DEFAULT_ATLAS_HEIGHT;
 }
 
 void
@@ -312,13 +316,14 @@ gsk_gl_texture_atlas_initialize (GskGLDriver       *driver,
 }
 
 static void
-gsk_gl_texture_atlases_pack (GskGLDriver        *driver,
-                             int                 width,
-                             int                 height,
-                             GskGLTextureAtlas **out_atlas,
-                             int                *out_x,
-                             int                *out_y)
+gsk_gl_texture_atlases_pack (GskGLTextureLibrary *self,
+                             int                  width,
+                             int                  height,
+                             GskGLTextureAtlas  **out_atlas,
+                             int                 *out_x,
+                             int                 *out_y)
 {
+  GskGLDriver *driver = self->driver;
   GskGLTextureAtlas *atlas = NULL;
   int x, y;
 
@@ -335,7 +340,7 @@ gsk_gl_texture_atlases_pack (GskGLDriver        *driver,
   if (atlas == NULL)
     {
       /* No atlas has enough space, so create a new one... */
-      atlas = gsk_gl_driver_create_atlas (driver);
+      atlas = gsk_gl_driver_create_atlas (driver, self->atlas_width, self->atlas_height);
 
       gsk_gl_texture_atlas_initialize (driver, atlas);
 
@@ -396,7 +401,7 @@ gsk_gl_texture_library_pack (GskGLTextureLibrary *self,
       int packed_x;
       int packed_y;
 
-      gsk_gl_texture_atlases_pack (self->driver,
+      gsk_gl_texture_atlases_pack (self,
                                    padding + width + padding,
                                    padding + height + padding,
                                    &atlas,
diff --git a/gsk/gl/gskgltexturelibraryprivate.h b/gsk/gl/gskgltexturelibraryprivate.h
index 39276ff69d..26a35bd4af 100644
--- a/gsk/gl/gskgltexturelibraryprivate.h
+++ b/gsk/gl/gskgltexturelibraryprivate.h
@@ -50,7 +50,6 @@ typedef struct _GskGLTextureAtlas
    */
   int unused_pixels;
 
-  void *user_data;
 } GskGLTextureAtlas;
 
 typedef struct _GskGLTextureAtlasEntry
@@ -94,6 +93,8 @@ typedef struct _GskGLTextureLibrary
   GHashTable  *hash_table;
   guint        max_entry_size;
   guint        max_frame_age;
+  guint        atlas_width;
+  guint        atlas_height;
 } GskGLTextureLibrary;
 
 typedef struct _GskGLTextureLibraryClass


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]