From patchwork Mon Aug 13 22:39:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 10712 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 C33D923E29 for ; Mon, 13 Aug 2012 22:39:32 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id 8C36CA18928 for ; Mon, 13 Aug 2012 22:39:32 +0000 (UTC) Received: by mail-gg0-f180.google.com with SMTP id i2so2034211ggm.11 for ; Mon, 13 Aug 2012 15:39:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :dkim-signature:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=XFka6LoV11FirTd9x1n6btbMZQeT1shI1uqVEcTURNE=; b=VBPw9Tzx85ikj+qrmUwekC9LZFGV4Bf5j1oKYcPwhvPctAQg1ZsK0vKE8LfgNZXLGX 2YKXhYR0HF+4JlLV01VL2EfVvps5X6bXl90JWQ5NdteUbUrWQEuOQ0UOT96jkwRE9T/0 yglGsv15Wf1qcj3F/bigdh12L1YjaqXOnD6le6Zboaae5QMKmMe/S4vc3TDk2uqwbjMs sa0OCahqCfMX29Hcgq0tppZXiTzTuXT8fQL2w9cG+PhIt2as4z+xAO/RlXDwFA1eFaN0 cD5K9XKjrLbgHxr5cQNsGUnAsru6fmmbyMufozEgegI1etV+dhkvNhU3jzpKSV1hzj6f pYUw== Received: by 10.50.154.132 with SMTP id vo4mr7864722igb.31.1344897572008; Mon, 13 Aug 2012 15:39:32 -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.50.184.200 with SMTP id ew8csp201633igc; Mon, 13 Aug 2012 15:39:31 -0700 (PDT) Received: by 10.60.13.228 with SMTP id k4mr16321676oec.28.1344897571574; Mon, 13 Aug 2012 15:39:31 -0700 (PDT) Received: from mail-ob0-f178.google.com (mail-ob0-f178.google.com [209.85.214.178]) by mx.google.com with ESMTPS id fy3si964299obc.174.2012.08.13.15.39.31 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 13 Aug 2012 15:39:31 -0700 (PDT) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.214.178 as permitted sender) client-ip=209.85.214.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.214.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by mail-ob0-f178.google.com with SMTP id wd20so9747767obb.37 for ; Mon, 13 Aug 2012 15:39:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=XFka6LoV11FirTd9x1n6btbMZQeT1shI1uqVEcTURNE=; b=Q0ChJ1Zy0J15ox959oFCY2houpZLVTjBOiwBsBuo9WNjbGgUSl66BoEPkI96ChLTT9 0gIIOCAptKOuWGns2LaY7CL8QfXIck9hNmzcUsxeUmUv0DsELPZ/VRTokFFlEzoTKDL3 39WSUU5EoaPmITyHo0h5gFR51uabmHTxkQhiGG/N68qR0kp6YnCn25ecsazWxqDVAkpH P/TX9ZJRi2G96jeL4S/HHW/ndowMoyP9avoMTonZ90n+UxJA+dTEKyh6Tx1F6sgdBZap E4uF6Ofc9x9DfYkPT1vWST1f0I5uvFzndArSFveKLetOlEkeuI2XX3TedUmHI0kkFJbj SBTw== Received: by 10.60.172.143 with SMTP id bc15mr17001470oec.73.1344897571344; Mon, 13 Aug 2012 15:39:31 -0700 (PDT) Received: from localhost (dragon.ti.com. [192.94.94.33]) by mx.google.com with ESMTPS id l9sm714790oeg.3.2012.08.13.15.39.30 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 13 Aug 2012 15:39:30 -0700 (PDT) Sender: Rob Clark From: Rob Clark To: wayland-devel@lists.freedesktop.org, mesa-dev@lists.freedesktop.org Cc: patches@linaro.org, Rob Clark Subject: [PATCH weston 2/2] compositor: add support for OES_EGL_image_external Date: Mon, 13 Aug 2012 17:39:18 -0500 Message-Id: <1344897558-1976-3-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1344897558-1976-1-git-send-email-rob.clark@linaro.org> References: <1344897558-1976-1-git-send-email-rob.clark@linaro.org> X-Gm-Message-State: ALoCoQmgTutxv5DkXzP/9tQrMk/2CytQBxx0RVsmYFnIxQADZuPT0Jt0Icv4YFKo1kWfQ/tpbamn From: Rob Clark In cases where the GPU can natively handle certain YUV formats, eglQueryWaylandBufferWL() can return the value EGL_TEXTURE_EXTERNAL_OES and the compositor will treat the buffer as a single egl-image-external. See: http://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image_external.txt Signed-off-by: Rob Clark --- src/compositor.c | 42 ++++++++++++++++++++++++++++++++---------- src/compositor.h | 2 ++ src/weston-egl-ext.h | 1 + 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index b2a3ae9..08e575a 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -719,14 +719,14 @@ ensure_textures(struct weston_surface *es, int num_textures) for (i = es->num_textures; i < num_textures; i++) { glGenTextures(1, &es->textures[i]); - glBindTexture(GL_TEXTURE_2D, es->textures[i]); - glTexParameteri(GL_TEXTURE_2D, + glBindTexture(es->target, es->textures[i]); + glTexParameteri(es->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, + glTexParameteri(es->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); } es->num_textures = num_textures; - glBindTexture(GL_TEXTURE_2D, 0); + glBindTexture(es->target, 0); } static void @@ -771,6 +771,7 @@ weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer) if (wl_buffer_is_shm(buffer)) { es->pitch = wl_shm_buffer_get_stride(buffer) / 4; es->shader = &ec->texture_shader_rgba; + es->target = GL_TEXTURE_2D; ensure_textures(es, 1); glBindTexture(GL_TEXTURE_2D, es->textures[0]); @@ -786,7 +787,7 @@ weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer) for (i = 0; i < es->num_images; i++) ec->destroy_image(ec->egl_display, es->images[i]); es->num_images = 0; - + es->target = GL_TEXTURE_2D; switch (format) { case EGL_TEXTURE_RGB: case EGL_TEXTURE_RGBA: @@ -794,6 +795,11 @@ weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer) num_planes = 1; es->shader = &ec->texture_shader_rgba; break; + case EGL_TEXTURE_EXTERNAL_OES: + num_planes = 1; + es->target = GL_TEXTURE_EXTERNAL_OES; + es->shader = &ec->texture_shader_egl_external; + break; case EGL_TEXTURE_Y_UV_WL: num_planes = 2; es->shader = &ec->texture_shader_y_uv; @@ -824,8 +830,8 @@ weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer) es->num_images++; glActiveTexture(GL_TEXTURE0 + i); - glBindTexture(GL_TEXTURE_2D, es->textures[i]); - ec->image_target_texture_2d(GL_TEXTURE_2D, + glBindTexture(es->target, es->textures[i]); + ec->image_target_texture_2d(es->target, es->images[i]); } @@ -942,9 +948,9 @@ weston_surface_draw(struct weston_surface *es, struct weston_output *output, for (i = 0; i < es->num_textures; i++) { glUniform1i(es->shader->tex_uniforms[i], i); glActiveTexture(GL_TEXTURE0 + i); - glBindTexture(GL_TEXTURE_2D, es->textures[i]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); + glBindTexture(es->target, es->textures[i]); + glTexParameteri(es->target, GL_TEXTURE_MIN_FILTER, filter); + glTexParameteri(es->target, GL_TEXTURE_MAG_FILTER, filter); } v = ec->vertices.data; @@ -2842,6 +2848,19 @@ static const char texture_fragment_shader_rgba[] = FRAGMENT_SHADER_EXIT "}\n"; +static const char texture_fragment_shader_egl_external[] = + "#extension GL_OES_EGL_image_external : require\n" + "precision mediump float;\n" + "varying vec2 v_texcoord;\n" + "uniform samplerExternalOES tex;\n" + FRAGMENT_SHADER_UNIFORMS + "void main()\n" + "{\n" + FRAGMENT_SHADER_INIT + " gl_FragColor = texture2D(tex, v_texcoord)\n;" + FRAGMENT_SHADER_EXIT + "}\n"; + static const char texture_fragment_shader_y_uv[] = "precision mediump float;\n" "uniform sampler2D tex;\n" @@ -3251,6 +3270,9 @@ weston_compositor_init_gl(struct weston_compositor *ec) if (weston_shader_init(&ec->texture_shader_rgba, vertex_shader, texture_fragment_shader_rgba) < 0) return -1; + if (weston_shader_init(&ec->texture_shader_egl_external, + vertex_shader, texture_fragment_shader_egl_external) < 0) + return -1; if (weston_shader_init(&ec->texture_shader_y_uv, vertex_shader, texture_fragment_shader_y_uv) < 0) return -1; diff --git a/src/compositor.h b/src/compositor.h index 22c0174..be1c2d2 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -271,6 +271,7 @@ struct weston_compositor { EGLConfig egl_config; GLuint fbo; struct weston_shader texture_shader_rgba; + struct weston_shader texture_shader_egl_external; struct weston_shader texture_shader_y_uv; struct weston_shader texture_shader_y_u_v; struct weston_shader texture_shader_y_xuxv; @@ -452,6 +453,7 @@ struct weston_surface { struct wl_list frame_callback_list; EGLImageKHR images[3]; + GLenum target; int num_images; struct wl_buffer *buffer; diff --git a/src/weston-egl-ext.h b/src/weston-egl-ext.h index 8e132c0..5dae03e 100644 --- a/src/weston-egl-ext.h +++ b/src/weston-egl-ext.h @@ -39,6 +39,7 @@ #define EGL_TEXTURE_Y_U_V_WL 0x31D7 #define EGL_TEXTURE_Y_UV_WL 0x31D8 #define EGL_TEXTURE_Y_XUXV_WL 0x31D9 +#define EGL_TEXTURE_EXTERNAL_OES 0x31DA struct wl_display; struct wl_buffer;