[gtk/wip/chergert/glproto: 415/526] inline buffer advance and offset




commit 3a15d82dc9d2616e05d2226ac826fcd7e7bbebee
Author: Christian Hergert <chergert redhat com>
Date:   Tue Feb 2 17:19:52 2021 -0800

    inline buffer advance and offset

 gsk/next/gskglbuffer.c        | 41 ++++---------------------------------
 gsk/next/gskglbufferprivate.h | 47 ++++++++++++++++++++++++++++++++++---------
 2 files changed, 41 insertions(+), 47 deletions(-)
---
diff --git a/gsk/next/gskglbuffer.c b/gsk/next/gskglbuffer.c
index c9ee140ec0..fd3896be5f 100644
--- a/gsk/next/gskglbuffer.c
+++ b/gsk/next/gskglbuffer.c
@@ -24,23 +24,8 @@
 
 #include "gskglbufferprivate.h"
 
-#define N_BUFFERS 2
 #define RESERVED_SIZE 1024
 
-typedef struct
-{
-  GLuint   id;
-  guint    size_on_gpu;
-} GskGLBufferShadow;
-
-struct _GskGLBuffer
-{
-  GArray            *buffer;
-  GskGLBufferShadow  shadows[N_BUFFERS];
-  GLenum             target;
-  guint              current;
-};
-
 static void
 gsk_gl_buffer_shadow_init (GskGLBufferShadow *shadow,
                            GLenum             target,
@@ -129,8 +114,9 @@ gsk_gl_buffer_new (GLenum target,
   buffer->buffer = g_array_sized_new (FALSE, FALSE, element_size, RESERVED_SIZE);
   buffer->target = target;
   buffer->current = 0;
+  buffer->element_size = element_size;
 
-  for (guint i = 0; i < N_BUFFERS; i++)
+  for (guint i = 0; i < GSK_GL_BUFFER_N_BUFFERS; i++)
     gsk_gl_buffer_shadow_init (&buffer->shadows[i],
                                target,
                                element_size,
@@ -145,7 +131,7 @@ gsk_gl_buffer_submit (GskGLBuffer *buffer)
   gsk_gl_buffer_shadow_submit (&buffer->shadows[buffer->current],
                                buffer->target,
                                buffer->buffer);
-  buffer->current = (buffer->current + 1) % N_BUFFERS;
+  buffer->current = (buffer->current + 1) % GSK_GL_BUFFER_N_BUFFERS;
   buffer->buffer->len = 0;
 }
 
@@ -154,26 +140,7 @@ gsk_gl_buffer_free (GskGLBuffer *buffer)
 {
   buffer->target = 0;
   buffer->current = 0;
-  for (guint i = 0; i < N_BUFFERS; i++)
+  for (guint i = 0; i < GSK_GL_BUFFER_N_BUFFERS; i++)
     gsk_gl_buffer_shadow_destroy (&buffer->shadows[i]);
   g_free (buffer);
 }
-
-gpointer
-gsk_gl_buffer_advance (GskGLBuffer *buffer,
-                       guint        count,
-                       guint       *offset)
-{
-
-  *offset = buffer->buffer->len;
-  g_array_set_size (buffer->buffer, buffer->buffer->len + count);
-  return (guint8 *)buffer->buffer->data + (*offset * g_array_get_element_size (buffer->buffer));
-}
-
-guint
-gsk_gl_buffer_get_offset (GskGLBuffer *buffer)
-{
-  g_return_val_if_fail (buffer != NULL, 0);
-
-  return buffer->buffer->len;
-}
diff --git a/gsk/next/gskglbufferprivate.h b/gsk/next/gskglbufferprivate.h
index 3150dd7eeb..43c80108d7 100644
--- a/gsk/next/gskglbufferprivate.h
+++ b/gsk/next/gskglbufferprivate.h
@@ -26,16 +26,43 @@
 
 G_BEGIN_DECLS
 
-typedef struct _GskGLBuffer GskGLBuffer;
-
-GskGLBuffer *gsk_gl_buffer_new        (GLenum       target,
-                                       guint        element_size);
-void         gsk_gl_buffer_free       (GskGLBuffer *buffer);
-void         gsk_gl_buffer_submit     (GskGLBuffer *buffer);
-guint        gsk_gl_buffer_get_offset (GskGLBuffer *buffer);
-gpointer     gsk_gl_buffer_advance    (GskGLBuffer *buffer,
-                                       guint        count,
-                                       guint       *offset);
+#define GSK_GL_BUFFER_N_BUFFERS 2
+
+typedef struct _GskGLBufferShadow
+{
+  GLuint   id;
+  guint    size_on_gpu;
+} GskGLBufferShadow;
+
+typedef struct _GskGLBuffer
+{
+  GArray            *buffer;
+  GskGLBufferShadow  shadows[GSK_GL_BUFFER_N_BUFFERS];
+  GLenum             target;
+  guint              current;
+  guint              element_size;
+} GskGLBuffer;
+
+GskGLBuffer *gsk_gl_buffer_new    (GLenum       target,
+                                   guint        element_size);
+void         gsk_gl_buffer_free   (GskGLBuffer *buffer);
+void         gsk_gl_buffer_submit (GskGLBuffer *buffer);
+
+static inline gpointer
+gsk_gl_buffer_advance (GskGLBuffer *buffer,
+                       guint        count,
+                       guint       *offset)
+{
+  *offset = buffer->buffer->len;
+  g_array_set_size (buffer->buffer, buffer->buffer->len + count);
+  return (guint8 *)buffer->buffer->data + (*offset * buffer->element_size);
+}
+
+static inline guint
+gsk_gl_buffer_get_offset (GskGLBuffer *buffer)
+{
+  return buffer->buffer->len;
+}
 
 G_END_DECLS
 


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