gsk/gl: allow configuring atlas size

This commit is contained in:
Christian Hergert 2022-03-17 16:43:58 -07:00
parent 2efc1729e2
commit 1b9da2bb17
4 changed files with 25 additions and 14 deletions

View File

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

View File

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

View File

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

View File

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