From patchwork Mon Jul 25 13:56:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: alexandros.frantzis@linaro.org X-Patchwork-Id: 3083 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 2707323E54 for ; Mon, 25 Jul 2011 13:57:25 +0000 (UTC) Received: from mail-qy0-f180.google.com (mail-qy0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id DC46DA1844E for ; Mon, 25 Jul 2011 13:57:24 +0000 (UTC) Received: by mail-qy0-f180.google.com with SMTP id 30so2963572qyk.11 for ; Mon, 25 Jul 2011 06:57:24 -0700 (PDT) Received: by 10.229.25.212 with SMTP id a20mr3469792qcc.148.1311602244607; Mon, 25 Jul 2011 06:57:24 -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 hl14cs77880qcb; Mon, 25 Jul 2011 06:57:24 -0700 (PDT) Received: by 10.14.20.75 with SMTP id o51mr1568247eeo.145.1311602243554; Mon, 25 Jul 2011 06:57:23 -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 18si7042659fat.105.2011.07.25.06.57.23 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 06:57:23 -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 6so6802455fxe.17 for ; Mon, 25 Jul 2011 06:57:23 -0700 (PDT) Received: by 10.223.7.65 with SMTP id c1mr2104653fac.131.1311602243073; Mon, 25 Jul 2011 06:57:23 -0700 (PDT) Received: from localhost (77.49.93.204.dsl.dyn.forthnet.gr [77.49.93.204]) by mx.google.com with ESMTPS id h20sm3801016fai.44.2011.07.25.06.57.21 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 06:57:22 -0700 (PDT) From: alexandros.frantzis@linaro.org To: patches@linaro.org Subject: [PATCH 09/21] gl: Require the GL_EXT_texture_format_BGRA8888 extension for GLES2 Date: Mon, 25 Jul 2011 16:56:36 +0300 Message-Id: <1311602208-5973-9-git-send-email-alexandros.frantzis@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1311602208-5973-1-git-send-email-alexandros.frantzis@linaro.org> References: <1311602208-5973-1-git-send-email-alexandros.frantzis@linaro.org> From: Alexandros Frantzis This extension adds limited BGRA support to GLES2. It is better than nothing... Signed-off-by: Chris Wilson --- src/cairo-gl-device.c | 7 ++++++- src/cairo-gl-ext-def-private.h | 12 ++++++++++++ src/cairo-gl-gradient.c | 23 ++++++++++++++++++++--- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/cairo-gl-device.c b/src/cairo-gl-device.c index 35339aa..ca7b6e8 100644 --- a/src/cairo-gl-device.c +++ b/src/cairo-gl-device.c @@ -156,6 +156,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 (); + cairo_gl_flavor_t gl_flavor = _cairo_gl_get_flavor (); int n; _cairo_device_init (&ctx->base, &_cairo_gl_device_backend); @@ -179,11 +180,15 @@ _cairo_gl_context_init (cairo_gl_context_t *ctx) ! _cairo_gl_has_extension ("GL_ARB_pixel_buffer_object")) return _cairo_error (CAIRO_STATUS_DEVICE_ERROR); + if (gl_flavor == CAIRO_GL_FLAVOR_ES && + ! _cairo_gl_has_extension ("GL_EXT_texture_format_BGRA8888")) + return _cairo_error (CAIRO_STATUS_DEVICE_ERROR); + ctx->has_mesa_pack_invert = _cairo_gl_has_extension ("GL_MESA_pack_invert"); ctx->current_operator = -1; - ctx->gl_flavor = _cairo_gl_get_flavor (); + ctx->gl_flavor = gl_flavor; status = _cairo_gl_context_init_shaders (ctx); if (unlikely (status)) diff --git a/src/cairo-gl-ext-def-private.h b/src/cairo-gl-ext-def-private.h index 389d356..0701c5b 100644 --- a/src/cairo-gl-ext-def-private.h +++ b/src/cairo-gl-ext-def-private.h @@ -100,4 +100,16 @@ #define GL_CLAMP_TO_BORDER 0x812D #endif +#ifndef GL_BGRA +#define GL_BGRA 0x80E1 +#endif + +#ifndef GL_RGBA8 +#define GL_RGBA8 0x8058 +#endif + +#ifndef GL_UNSIGNED_INT_8_8_8_8_REV +#define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 +#endif + #endif /* CAIRO_GL_EXT_DEF_PRIVATE_H */ diff --git a/src/cairo-gl-gradient.c b/src/cairo-gl-gradient.c index ef7fd53..0718c75 100644 --- a/src/cairo-gl-gradient.c +++ b/src/cairo-gl-gradient.c @@ -44,6 +44,7 @@ #include "cairo-gl-gradient-private.h" #include "cairo-gl-private.h" + static int _cairo_gl_gradient_sample_width (unsigned int n_stops, const cairo_gradient_stop_t *stops) @@ -95,6 +96,17 @@ _cairo_gl_gradient_render (const cairo_gl_context_t *ctx, pixman_gradient_stop_t *pixman_stops; pixman_point_fixed_t p1, p2; unsigned int i; + pixman_format_code_t gradient_pixman_format; + + /* + * Ensure that the order of the gradient's components in memory is BGRA. + * This is done so that the gradient's pixel data is always suitable for + * texture upload using format=GL_BGRA and type=GL_UNSIGNED_BYTE. + */ + if (_cairo_is_little_endian ()) + gradient_pixman_format = PIXMAN_a8r8g8b8; + else + gradient_pixman_format = PIXMAN_b8g8r8a8; pixman_stops = pixman_stops_stack; if (unlikely (n_stops > ARRAY_LENGTH (pixman_stops_stack))) { @@ -129,7 +141,7 @@ _cairo_gl_gradient_render (const cairo_gl_context_t *ctx, pixman_image_set_filter (gradient, PIXMAN_FILTER_BILINEAR, NULL, 0); pixman_image_set_repeat (gradient, PIXMAN_REPEAT_PAD); - image = pixman_image_create_bits (PIXMAN_a8r8g8b8, width, 1, + image = pixman_image_create_bits (gradient_pixman_format, width, 1, bytes, sizeof(uint32_t)*width); if (unlikely (image == NULL)) { pixman_image_unref (gradient); @@ -240,8 +252,13 @@ _cairo_gl_gradient_create (cairo_gl_context_t *ctx, glGenTextures (1, &gradient->tex); _cairo_gl_context_activate (ctx, CAIRO_GL_TEX_TEMP); glBindTexture (ctx->tex_target, gradient->tex); - glTexImage2D (ctx->tex_target, 0, GL_RGBA8, tex_width, 1, 0, - GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0); + + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + glTexImage2D (ctx->tex_target, 0, GL_RGBA8, tex_width, 1, 0, + GL_BGRA, GL_UNSIGNED_BYTE, 0); + else + glTexImage2D (ctx->tex_target, 0, GL_BGRA, tex_width, 1, 0, + GL_BGRA, GL_UNSIGNED_BYTE, data); dispatch->BindBuffer (GL_PIXEL_UNPACK_BUFFER, 0);