diff mbox

[8/9] gl: Replace GLEW by using the facilities provided by cairo-gl-info

Message ID 1311602713-6182-8-git-send-email-alexandros.frantzis@linaro.org
State Accepted
Headers show

Commit Message

alexandros.frantzis@linaro.org July 25, 2011, 2:05 p.m. UTC
From: Alexandros Frantzis <alexandros.frantzis@linaro.org>

---
 src/cairo-gl-device.c           |   52 +++++++++++++-------------------------
 src/cairo-gl-gradient-private.h |    5 +--
 src/cairo-gl-private.h          |    6 ++--
 src/cairo-gl-shaders.c          |   16 +++++------
 src/cairo-gl-surface.c          |    6 +++-
 5 files changed, 34 insertions(+), 51 deletions(-)
diff mbox

Patch

diff --git a/src/cairo-gl-device.c b/src/cairo-gl-device.c
index a6aec42..3793f9d 100644
--- a/src/cairo-gl-device.c
+++ b/src/cairo-gl-device.c
@@ -3,6 +3,7 @@ 
  * Copyright © 2009 Eric Anholt
  * Copyright © 2009 Chris Wilson
  * Copyright © 2005,2010 Red Hat, Inc
+ * Copyright © 2010 Linaro Limited
  *
  * This library is free software; you can redistribute it and/or
  * modify it either under the terms of the GNU Lesser General Public
@@ -36,6 +37,7 @@ 
  *	Carl Worth <cworth@cworth.org>
  *	Chris Wilson <chris@chris-wilson.co.uk>
  *	Eric Anholt <eric@anholt.net>
+ *	Alexandros Frantzis <alexandros.frantzis@linaro.org>
  */
 
 #include "cairoint.h"
@@ -153,6 +155,7 @@  _cairo_gl_context_init (cairo_gl_context_t *ctx)
 {
     cairo_status_t status;
     cairo_gl_dispatch_t *dispatch = &ctx->dispatch;
+    int gl_version = _cairo_gl_get_version ();
     int n;
 
     _cairo_device_init (&ctx->base, &_cairo_gl_device_backend);
@@ -160,43 +163,24 @@  _cairo_gl_context_init (cairo_gl_context_t *ctx)
     memset (ctx->glyph_cache, 0, sizeof (ctx->glyph_cache));
     cairo_list_init (&ctx->fonts);
 
-    if (glewInit () != GLEW_OK)
-	return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); /* XXX */
+    /* Support only GL version >= 1.3 */
+    if (gl_version < CAIRO_GL_VERSION_ENCODE (1, 3))
+	return _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
 
-    if (! GLEW_EXT_framebuffer_object ||
-	! GLEW_ARB_texture_env_combine ||
-	! GLEW_EXT_bgra)
-    {
-	fprintf (stderr,
-		 "Required GL extensions not available:\n");
-	if (! GLEW_EXT_framebuffer_object)
-	    fprintf (stderr, "    GL_EXT_framebuffer_object\n");
-	if (! GLEW_ARB_texture_env_combine)
-	    fprintf (stderr, "    GL_ARB_texture_env_combine\n");
-        if (! GLEW_ARB_vertex_buffer_object)
-	    fprintf (stderr, "    GL_ARB_vertex_buffer_object\n");
-
-	/* EXT_bgra is used in two places:
-	 * - draw_image to upload common pixman formats without hand-swizzling.
-	 * - get_image to download common pixman formats without hand-swizzling.
-	 */
-	if (! GLEW_EXT_bgra)
-	    fprintf (stderr, "    GL_EXT_bgra\n");
-
-	return _cairo_error (CAIRO_STATUS_INVALID_FORMAT); /* XXX */
-    }
-
-    if (! GLEW_ARB_texture_non_power_of_two &&
-	! GLEW_ARB_texture_rectangle ) {
-	fprintf (stderr,
-		 "Required GL extensions not available:\n");
-	fprintf (stderr, "    GL_ARB_texture_non_power_of_two, GL_ARB_texture_rectangle\n");
-    }
-
-    if (! GLEW_ARB_texture_non_power_of_two)
+    /* Check for required extensions */
+    if (_cairo_gl_has_extension ("GL_ARB_texture_non_power_of_two"))
+	ctx->tex_target = GL_TEXTURE_2D;
+    else if (_cairo_gl_has_extension ("GL_ARB_texture_rectangle"))
 	ctx->tex_target = GL_TEXTURE_RECTANGLE;
     else
-	ctx->tex_target = GL_TEXTURE_2D;
+	return _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
+
+    if (gl_version < CAIRO_GL_VERSION_ENCODE (2, 1) &&
+	! _cairo_gl_has_extension ("GL_ARB_pixel_buffer_object"))
+	return _cairo_error (CAIRO_STATUS_DEVICE_ERROR);
+
+    ctx->has_mesa_pack_invert =
+	_cairo_gl_has_extension ("GL_MESA_pack_invert");
 
     ctx->current_operator = -1;
 
diff --git a/src/cairo-gl-gradient-private.h b/src/cairo-gl-gradient-private.h
index 383a118..9e34847 100644
--- a/src/cairo-gl-gradient-private.h
+++ b/src/cairo-gl-gradient-private.h
@@ -41,17 +41,16 @@ 
 #ifndef CAIRO_GL_GRADIENT_PRIVATE_H
 #define CAIRO_GL_GRADIENT_PRIVATE_H
 
+#define GL_GLEXT_PROTOTYPES
+
 #include "cairo-cache-private.h"
 #include "cairo-device-private.h"
 #include "cairo-reference-count-private.h"
 #include "cairo-types-private.h"
 
-#include <GL/glew.h>
-
 #include "cairo-gl.h"
 
 #include <GL/gl.h>
-#define GL_GLEXT_PROTOTYPES
 #include <GL/glext.h>
 
 #define CAIRO_GL_GRADIENT_CACHE_SIZE 4096
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index c9851ff..2f47b9a 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -42,6 +42,8 @@ 
 #ifndef CAIRO_GL_PRIVATE_H
 #define CAIRO_GL_PRIVATE_H
 
+#define GL_GLEXT_PROTOTYPES
+
 #include "cairoint.h"
 
 #include "cairo-gl-gradient-private.h"
@@ -52,12 +54,9 @@ 
 
 #include <assert.h>
 
-#include <GL/glew.h>
-
 #include "cairo-gl.h"
 
 #include <GL/gl.h>
-#define GL_GLEXT_PROTOTYPES
 #include <GL/glext.h>
 #include "cairo-gl-ext-def-private.h"
 
@@ -263,6 +262,7 @@  struct _cairo_gl_context {
     unsigned int vertex_size;
     cairo_region_t *clip_region;
 
+    cairo_bool_t has_mesa_pack_invert;
     cairo_gl_dispatch_t dispatch;
 
     void (*acquire) (void *ctx);
diff --git a/src/cairo-gl-shaders.c b/src/cairo-gl-shaders.c
index a89c42b..f9bbc37 100644
--- a/src/cairo-gl-shaders.c
+++ b/src/cairo-gl-shaders.c
@@ -355,15 +355,13 @@  _cairo_gl_context_init_shaders (cairo_gl_context_t *ctx)
 	"}\n";
     cairo_status_t status;
 
-    /* XXX multiple device support? */
-    if (GLEW_VERSION_2_0 ||
-	(GLEW_ARB_shader_objects &&
-	 GLEW_ARB_fragment_shader &&
-	 GLEW_ARB_vertex_program)) {
-        ctx->shader_impl = &shader_impl_core_2_0;
-    } else {
-        ctx->shader_impl = NULL;
-    }
+    if (_cairo_gl_get_version () >= CAIRO_GL_VERSION_ENCODE (2, 0) ||
+	(_cairo_gl_has_extension ("GL_ARB_shader_objects") &&
+	 _cairo_gl_has_extension ("GL_ARB_fragment_shader") &&
+	 _cairo_gl_has_extension ("GL_ARB_vertex_shader")))
+	ctx->shader_impl = &shader_impl_core_2_0;
+    else
+	ctx->shader_impl = NULL;
 
     memset (ctx->vertex_shaders, 0, sizeof (ctx->vertex_shaders));
 
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index 61a0e9d..d20fb98 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -743,12 +743,14 @@  _cairo_gl_surface_get_image (cairo_gl_surface_t      *surface,
 
     glPixelStorei (GL_PACK_ALIGNMENT, 1);
     glPixelStorei (GL_PACK_ROW_LENGTH, image->stride / cpp);
-    if (! _cairo_gl_surface_is_texture (surface) && GLEW_MESA_pack_invert)
+    if (! _cairo_gl_surface_is_texture (surface) &&
+	ctx->has_mesa_pack_invert)
 	glPixelStorei (GL_PACK_INVERT_MESA, 1);
     glReadPixels (interest->x, interest->y,
 		  interest->width, interest->height,
 		  format, type, image->data);
-    if (! _cairo_gl_surface_is_texture (surface) && GLEW_MESA_pack_invert)
+    if (! _cairo_gl_surface_is_texture (surface) &&
+	ctx->has_mesa_pack_invert)
 	glPixelStorei (GL_PACK_INVERT_MESA, 0);
 
     status = _cairo_gl_context_release (ctx, status);