[cairo] [PATCH 1/3] cairo-gl: Make VBO size run-time settable

Bryce Harrington bryce at osg.samsung.com
Thu Jul 31 18:51:33 PDT 2014


The default VBO size was reduced from 256k to 16k last year in commit
90860241 due to problems with larger VBOs on embedded hardware.
However, that change resulted in a 5% performance impact to the
firefox-fishbowl benchmark when using the spans or traps compositors.

This patch doesn't change the VBO size, but does permit it to be
altered via an environment variable, to facilitate testing.

Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>
---
 src/cairo-gl-composite.c |    2 +-
 src/cairo-gl-device.c    |    2 +-
 src/cairo-gl-info.c      |   22 ++++++++++++++++++++++
 src/cairo-gl-private.h   |    8 ++++++--
 4 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index 30b7931..65b0f26 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -875,7 +875,7 @@ _cairo_gl_composite_prepare_buffer (cairo_gl_context_t *ctx,
 	ctx->primitive_type = primitive_type;
     }
 
-    if (ctx->vb_offset + n_vertices * ctx->vertex_size > CAIRO_GL_VBO_SIZE)
+    if (ctx->vb_offset + n_vertices * ctx->vertex_size > _cairo_gl_get_vbo_size())
 	_cairo_gl_composite_flush (ctx);
 }
 
diff --git a/src/cairo-gl-device.c b/src/cairo-gl-device.c
index 054f145..dc2b6d6 100644
--- a/src/cairo-gl-device.c
+++ b/src/cairo-gl-device.c
@@ -297,7 +297,7 @@ _cairo_gl_context_init (cairo_gl_context_t *ctx)
     if (unlikely (status))
         return status;
 
-    ctx->vb = malloc (CAIRO_GL_VBO_SIZE);
+    ctx->vb = malloc (_cairo_gl_get_vbo_size());
     if (unlikely (ctx->vb == NULL)) {
 	    _cairo_cache_fini (&ctx->gradients);
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
diff --git a/src/cairo-gl-info.c b/src/cairo-gl-info.c
index 12a618d..c47033e 100644
--- a/src/cairo-gl-info.c
+++ b/src/cairo-gl-info.c
@@ -29,6 +29,8 @@
  *      Alexandros Frantzis <alexandros.frantzis at linaro.org>
  */
 
+#include <errno.h>
+
 #include "cairoint.h"
 #include "cairo-gl-private.h"
 
@@ -71,6 +73,26 @@ _cairo_gl_get_flavor (void)
     return flavor;
 }
 
+long
+_cairo_gl_get_vbo_size (void)
+{
+    static long vbo_size = -1;
+
+    if (vbo_size < 0) {
+        const char *env = getenv ("CAIRO_GL_VBO_SIZE");
+        if (env == NULL) {
+            vbo_size = CAIRO_GL_VBO_SIZE_DEFAULT;
+	} else {
+	    errno = 0;
+	    vbo_size = strtol (env, NULL, 10);
+	    assert (errno == 0);
+	    assert (vbo_size > 0);
+	}
+    }
+
+    return vbo_size;
+}
+
 cairo_bool_t
 _cairo_gl_has_extension (const char *ext)
 {
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 8379abc..79b67a5 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -93,8 +93,9 @@
 
 /* VBO size that we allocate, smaller size means we gotta flush more often,
  * but larger means hogging more memory and can cause trouble for drivers
- * (especially on embedded devices). */
-#define CAIRO_GL_VBO_SIZE (16*1024)
+ * (especially on embedded devices). Use the CAIRO_GL_VBO_SIZE environment
+ * variable to set this to a different size. */
+#define CAIRO_GL_VBO_SIZE_DEFAULT (16*1024)
 
 typedef struct _cairo_gl_surface cairo_gl_surface_t;
 
@@ -702,6 +703,9 @@ _cairo_gl_get_version (void);
 cairo_private cairo_gl_flavor_t
 _cairo_gl_get_flavor (void);
 
+cairo_private long
+_cairo_gl_get_vbo_size (void);
+
 cairo_private cairo_bool_t
 _cairo_gl_has_extension (const char *ext);
 
-- 
1.7.9.5



More information about the cairo mailing list