From patchwork Mon Jul 25 14:05:12 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 3104 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 9E60C23E54 for ; Mon, 25 Jul 2011 14:05:39 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id 4E5CCA1844E for ; Mon, 25 Jul 2011 14:05:39 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so3010075qwb.11 for ; Mon, 25 Jul 2011 07:05:39 -0700 (PDT) Received: by 10.229.68.200 with SMTP id w8mr3739831qci.114.1311602739020; Mon, 25 Jul 2011 07:05:39 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.217.78 with SMTP id hl14cs78183qcb; Mon, 25 Jul 2011 07:05:38 -0700 (PDT) Received: by 10.223.55.209 with SMTP id v17mr6725746fag.77.1311602738144; Mon, 25 Jul 2011 07:05:38 -0700 (PDT) Received: from mail-fx0-f44.google.com (mail-fx0-f44.google.com [209.85.161.44]) by mx.google.com with ESMTPS id o15si7048838fal.135.2011.07.25.07.05.37 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 07:05:38 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.161.44 is neither permitted nor denied by best guess record for domain of alexandros.frantzis@linaro.org) client-ip=209.85.161.44; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.161.44 is neither permitted nor denied by best guess record for domain of alexandros.frantzis@linaro.org) smtp.mail=alexandros.frantzis@linaro.org Received: by mail-fx0-f44.google.com with SMTP id 6so6811099fxe.17 for ; Mon, 25 Jul 2011 07:05:37 -0700 (PDT) Received: by 10.223.144.140 with SMTP id z12mr6868021fau.147.1311602737735; Mon, 25 Jul 2011 07:05:37 -0700 (PDT) Received: from localhost (77.49.93.204.dsl.dyn.forthnet.gr [77.49.93.204]) by mx.google.com with ESMTPS id j19sm3805868faa.41.2011.07.25.07.05.36 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 07:05:37 -0700 (PDT) From: alexandros.frantzis@linaro.org To: patches@linaro.org Subject: =?UTF-8?q?=5BPATCH=208/9=5D=20gl=3A=20Replace=20GLEW=20by=20using=20the=20facilities=20provided=20by=20cairo-gl-info?= Date: Mon, 25 Jul 2011 17:05:12 +0300 Message-Id: <1311602713-6182-8-git-send-email-alexandros.frantzis@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1311602713-6182-1-git-send-email-alexandros.frantzis@linaro.org> References: <1311602713-6182-1-git-send-email-alexandros.frantzis@linaro.org> MIME-Version: 1.0 From: Alexandros Frantzis --- 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 --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 * Chris Wilson * Eric Anholt + * Alexandros Frantzis */ #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 - #include "cairo-gl.h" #include -#define GL_GLEXT_PROTOTYPES #include #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 -#include - #include "cairo-gl.h" #include -#define GL_GLEXT_PROTOTYPES #include #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);