From patchwork Mon Jul 25 13:56:38 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: 3085 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 A9FEE23E54 for ; Mon, 25 Jul 2011 13:57:31 +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 717BCA183B4 for ; Mon, 25 Jul 2011 13:57:31 +0000 (UTC) Received: by mail-qy0-f180.google.com with SMTP id 30so2963572qyk.11 for ; Mon, 25 Jul 2011 06:57:31 -0700 (PDT) Received: by 10.229.1.217 with SMTP id 25mr1001361qcg.38.1311602251193; Mon, 25 Jul 2011 06:57:31 -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 hl14cs77886qcb; Mon, 25 Jul 2011 06:57:31 -0700 (PDT) Received: by 10.14.29.11 with SMTP id h11mr1590304eea.45.1311602249910; Mon, 25 Jul 2011 06:57:29 -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.29 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 06:57:29 -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:29 -0700 (PDT) Received: by 10.204.154.194 with SMTP id p2mr1350432bkw.257.1311602249372; Mon, 25 Jul 2011 06:57:29 -0700 (PDT) Received: from localhost (77.49.93.204.dsl.dyn.forthnet.gr [77.49.93.204]) by mx.google.com with ESMTPS id q1sm1325147faa.1.2011.07.25.06.57.27 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 25 Jul 2011 06:57:28 -0700 (PDT) From: alexandros.frantzis@linaro.org To: patches@linaro.org Subject: [PATCH 11/21] gl: Add support for creating image surfaces for GLES2 Date: Mon, 25 Jul 2011 16:56:38 +0300 Message-Id: <1311602208-5973-11-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 Signed-off-by: Chris Wilson --- src/cairo-gl-ext-def-private.h | 4 +++ src/cairo-gl-surface.c | 55 +++++++++++++++++++++++++++++++-------- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/src/cairo-gl-ext-def-private.h b/src/cairo-gl-ext-def-private.h index 0701c5b..a4b7d34 100644 --- a/src/cairo-gl-ext-def-private.h +++ b/src/cairo-gl-ext-def-private.h @@ -112,4 +112,8 @@ #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 #endif +#ifndef GL_PACK_ROW_LENGTH +#define GL_PACK_ROW_LENGTH 0x0D02 +#endif + #endif /* CAIRO_GL_EXT_DEF_PRIVATE_H */ diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c index 211fe02..b67a1ea 100644 --- a/src/cairo-gl-surface.c +++ b/src/cairo-gl-surface.c @@ -703,24 +703,24 @@ _cairo_gl_surface_get_image (cairo_gl_surface_t *surface, cairo_image_surface_t *image; cairo_gl_context_t *ctx; GLenum format, type; - cairo_format_t cairo_format; + pixman_format_code_t pixman_format; unsigned int cpp; cairo_status_t status; /* Want to use a switch statement here but the compiler gets whiny. */ if (surface->base.content == CAIRO_CONTENT_COLOR_ALPHA) { format = GL_BGRA; - cairo_format = CAIRO_FORMAT_ARGB32; + pixman_format = PIXMAN_a8r8g8b8; type = GL_UNSIGNED_INT_8_8_8_8_REV; cpp = 4; } else if (surface->base.content == CAIRO_CONTENT_COLOR) { format = GL_BGRA; - cairo_format = CAIRO_FORMAT_RGB24; + pixman_format = PIXMAN_x8r8g8b8; type = GL_UNSIGNED_INT_8_8_8_8_REV; cpp = 4; } else if (surface->base.content == CAIRO_CONTENT_ALPHA) { format = GL_ALPHA; - cairo_format = CAIRO_FORMAT_A8; + pixman_format = PIXMAN_a8; type = GL_UNSIGNED_BYTE; cpp = 1; } else { @@ -728,25 +728,56 @@ _cairo_gl_surface_get_image (cairo_gl_surface_t *surface, return CAIRO_INT_STATUS_UNSUPPORTED; } + status = _cairo_gl_context_acquire (surface->base.device, &ctx); + if (unlikely (status)) + return status; + + /* + * GLES2 supports only RGBA, UNSIGNED_BYTE so use that. + * We are also using this format for ALPHA as GLES2 does not + * support GL_PACK_ROW_LENGTH anyway, and this makes sure that the + * pixman image that is created has row_stride = row_width * bpp. + */ + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_ES) { + format = GL_RGBA; + if (!_cairo_is_little_endian ()) { + ASSERT_NOT_REACHED; + /* TODO: Add r8g8b8a8 support to pixman and enable this + if (surface->base.content == CAIRO_CONTENT_COLOR) + pixman_format = PIXMAN_r8g8b8x8; + else + pixman_format = PIXMAN_r8g8b8a8; + */ + } + else { + if (surface->base.content == CAIRO_CONTENT_COLOR) + pixman_format = PIXMAN_x8b8g8r8; + else + pixman_format = PIXMAN_a8b8g8r8; + } + type = GL_UNSIGNED_BYTE; + cpp = 4; + } + image = (cairo_image_surface_t*) - cairo_image_surface_create (cairo_format, - interest->width, interest->height); + _cairo_image_surface_create_with_pixman_format (NULL, + pixman_format, + interest->width, + interest->height, + -1); if (unlikely (image->base.status)) - return image->base.status; + return _cairo_gl_context_release (ctx, image->base.status); /* This is inefficient, as we'd rather just read the thing without making * it the destination. But then, this is the fallback path, so let's not * fall back instead. */ - status = _cairo_gl_context_acquire (surface->base.device, &ctx); - if (unlikely (status)) - return status; - _cairo_gl_composite_flush (ctx); _cairo_gl_context_set_destination (ctx, surface); glPixelStorei (GL_PACK_ALIGNMENT, 1); - glPixelStorei (GL_PACK_ROW_LENGTH, image->stride / cpp); + if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP) + glPixelStorei (GL_PACK_ROW_LENGTH, image->stride / cpp); if (! _cairo_gl_surface_is_texture (surface) && ctx->has_mesa_pack_invert) glPixelStorei (GL_PACK_INVERT_MESA, 1);