[gtk/wip/chergert/glproto: 486/493] DRY the bits available in packed struct




commit e09e7b88b36fc8f01d509fc0579cfeaf9e2c29d6
Author: Christian Hergert <chergert redhat com>
Date:   Wed Feb 17 13:46:14 2021 -0800

    DRY the bits available in packed struct

 gsk/next/gskglrenderjob.c           |  2 +-
 gsk/next/gskgluniformstate.c        |  2 +-
 gsk/next/gskgluniformstateprivate.h | 16 +++++++++++-----
 3 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/gsk/next/gskglrenderjob.c b/gsk/next/gskglrenderjob.c
index 57956ebd6c..998c1aa10b 100644
--- a/gsk/next/gskglrenderjob.c
+++ b/gsk/next/gskglrenderjob.c
@@ -50,7 +50,7 @@
 #define SHADOW_EXTRA_SIZE   4
 
 /* Make sure gradient stops fits in packed array_count */
-G_STATIC_ASSERT (MAX_GRADIENT_STOPS*5 < (1<<5));
+G_STATIC_ASSERT ((MAX_GRADIENT_STOPS * 5) < (1 << GSK_GL_UNIFORM_ARRAY_BITS));
 
 #define rounded_rect_top_left(r)                                                        \
   (GRAPHENE_RECT_INIT(r->bounds.origin.x,                                               \
diff --git a/gsk/next/gskgluniformstate.c b/gsk/next/gskgluniformstate.c
index d87a0070a8..8345accdb1 100644
--- a/gsk/next/gskgluniformstate.c
+++ b/gsk/next/gskgluniformstate.c
@@ -153,7 +153,7 @@ setup_info:
                                 &offset);
 
   /* we have 21 bits for offset */
-  g_assert (offset < (1 << 21));
+  g_assert (offset < (1 << GSK_GL_UNIFORM_OFFSET_BITS));
 
   info->info.format = format;
   info->info.offset = offset;
diff --git a/gsk/next/gskgluniformstateprivate.h b/gsk/next/gskgluniformstateprivate.h
index 32e0413730..a2934d1130 100644
--- a/gsk/next/gskgluniformstateprivate.h
+++ b/gsk/next/gskgluniformstateprivate.h
@@ -37,12 +37,16 @@ typedef struct { int v0; int v1; int v2; int v3; } Uniform4i;
 
 typedef struct { guint v0; } Uniform1ui;
 
+#define GSK_GL_UNIFORM_ARRAY_BITS  5
+#define GSK_GL_UNIFORM_FORMAT_BITS 5
+#define GSK_GL_UNIFORM_OFFSET_BITS 21
+
 typedef struct _GskGLUniformInfo
 {
-  guint format : 5;
-  guint array_count : 5;
-  guint initial : 1;
-  guint offset : 21;
+  guint initial     : 1;
+  guint format      : GSK_GL_UNIFORM_FORMAT_BITS;
+  guint array_count : GSK_GL_UNIFORM_ARRAY_BITS;
+  guint offset      : GSK_GL_UNIFORM_OFFSET_BITS;
 } GskGLUniformInfo;
 
 G_STATIC_ASSERT (sizeof (GskGLUniformInfo) == 4);
@@ -123,6 +127,8 @@ typedef enum _GskGLUniformKind
   GSK_GL_UNIFORM_FORMAT_LAST
 } GskGLUniformFormat;
 
+G_STATIC_ASSERT (GSK_GL_UNIFORM_FORMAT_LAST < (1 << GSK_GL_UNIFORM_FORMAT_BITS));
+
 GskGLUniformState   *gsk_gl_uniform_state_new         (void);
 GskGLUniformState   *gsk_gl_uniform_state_ref         (GskGLUniformState         *state);
 void                 gsk_gl_uniform_state_unref       (GskGLUniformState         *state);
@@ -237,7 +243,7 @@ gsk_gl_uniform_state_realloc (GskGLUniformState *state,
       {                                                                                   \
         guint offset;                                                                     \
         u = gsk_gl_uniform_state_realloc (state, sizeof(type) * MAX (1, count), &offset); \
-        g_assert (offset < (1 << 21));                                                    \
+        g_assert (offset < (1 << GSK_GL_UNIFORM_ARRAY_BITS));                             \
         (info)->info.offset = offset;                                                     \
         /* We might have increased array length */                                        \
         (info)->info.array_count = count;                                                 \


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