[gtk/wip/chergert/glyphy] gsk/gl: allow texture libraries to define atlas size
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/glyphy] gsk/gl: allow texture libraries to define atlas size
- Date: Wed, 16 Mar 2022 21:39:26 +0000 (UTC)
commit 07ab9bf06bf282b89c89fa0111256122944e41b9
Author: Christian Hergert <chergert redhat com>
Date: Wed Mar 16 14:38:37 2022 -0700
gsk/gl: allow texture libraries to define atlas size
This allows for some texture libraries to use a different size of atlas
which could be more appropriate for the data stored within the texture.
For example, Glyphy would likely benefit from a different atlas size than
the Icon or CPU-generated glyph cache.
gsk/gl/gskgldriver.c | 11 +++++++----
gsk/gl/gskgldriverprivate.h | 4 +++-
gsk/gl/gskgltexturelibrary.c | 29 +++++++++++++++++++++--------
gsk/gl/gskgltexturelibraryprivate.h | 2 ++
4 files changed, 33 insertions(+), 13 deletions(-)
---
diff --git a/gsk/gl/gskgldriver.c b/gsk/gl/gskgldriver.c
index 712cc59ed0..12be8df515 100644
--- a/gsk/gl/gskgldriver.c
+++ b/gsk/gl/gskgldriver.c
@@ -45,7 +45,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)
@@ -171,15 +170,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 5878591396..f277b3f683 100644
--- a/gsk/gl/gskgldriverprivate.h
+++ b/gsk/gl/gskgldriverprivate.h
@@ -185,7 +185,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..e5c00240cc 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,16 +316,25 @@ 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)
{
GskGLTextureAtlas *atlas = NULL;
+ GskGLDriver *driver;
int x, y;
+ g_assert (GSK_IS_GL_TEXTURE_LIBRARY (self));
+ g_assert (GSK_IS_GL_DRIVER (self->driver));
+ g_assert (out_atlas != NULL);
+ g_assert (out_x != NULL);
+ g_assert (out_y != NULL);
+
+ driver = self->driver;
+
for (guint i = 0; i < driver->atlases->len; i++)
{
atlas = g_ptr_array_index (driver->atlases, i);
@@ -335,7 +348,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 +409,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..6f99786d53 100644
--- a/gsk/gl/gskgltexturelibraryprivate.h
+++ b/gsk/gl/gskgltexturelibraryprivate.h
@@ -94,6 +94,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]