From patchwork Thu Aug 30 21:47:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11115 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 C074023F27 for ; Thu, 30 Aug 2012 21:47:39 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 137D4A192F9 for ; Thu, 30 Aug 2012 21:47:02 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id j25so3732075iaf.11 for ; Thu, 30 Aug 2012 14:47:39 -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=GIRgT1udPQlYd0gLVCuHSCgjXYMpqLYP0UQHyUVkKeM=; b=mpq4vmhaH8MDKAQ06Vuh+Br/eXFNrsK+OnNcAYDqcDO0jIUTvvgCSTZhGT699v6f7s rD0CCAiatEGtFJ+bPcYmQ6BRmT4Q8/JppoB1rUkGiufdPj7ZIFZ8t7nL/0R4ScmaTaYj RJzNosutGxXxco6MLUz+K7HrjmYejeVxfdGgGzZcohjyFmpR5qERsTLRhNk/jmJH4rn1 RxFBF72g88hYR3VAygMl7F2A6mdPDFhSfTxv2Uq6Pha0UWfbOPy9WSles5MpNunot0oq nbCucxRuYVLZacHmTaMjbHorAbjBItFPQ6iqrU9fqI7lKKEhmbuJdzgLJmNxAs2qZ6Rm Q3SQ== Received: by 10.50.237.41 with SMTP id uz9mr2437835igc.43.1346363259165; Thu, 30 Aug 2012 14:47: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.50.184.232 with SMTP id ex8csp33034igc; Thu, 30 Aug 2012 14:47:38 -0700 (PDT) Received: by 10.68.217.100 with SMTP id ox4mr13512543pbc.87.1346363258560; Thu, 30 Aug 2012 14:47:38 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id iq5si4768719pbc.314.2012.08.30.14.47.38 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Aug 2012 14:47:38 -0700 (PDT) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.160.50 as permitted sender) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.160.50 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by mail-pb0-f50.google.com with SMTP id md12so4150965pbc.37 for ; Thu, 30 Aug 2012 14:47:38 -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=GIRgT1udPQlYd0gLVCuHSCgjXYMpqLYP0UQHyUVkKeM=; b=zUE4bWOrx4TfYMwhmH5QbahJkGly8joMCAACfSNC6Q+0KfL5pEGacUcm3ZEZ2qbIn5 o/wUyzzDZEZ8y9MSPTMVfYGZcWoWIioFzvSoI9UNDOCdhY5liLRywHSJIs4G2EB+X74E 2k6cm1u2Ni+PUhToJYQ2CPgreCnJe2KxtqSWfVjcnFxNnua+NKqv/MuNQaIFERDvnw8K /OPIL6zgC6nDsJeK0JH/80Vn5yQyQ7a5bVyhZW2b3jkuGtnR84/hOvDaacGZYolkobyu C7zHj/QLSObGCIA0ZNMxqCRme6g/aAKXrs2DvIahiTbpq09tECpquDW0QRXMPA4kbRZp 2eUw== Received: by 10.68.234.7 with SMTP id ua7mr13755642pbc.91.1346363258192; Thu, 30 Aug 2012 14:47:38 -0700 (PDT) Received: from localhost ([38.96.16.75]) by mx.google.com with ESMTPS id qo8sm2223987pbb.19.2012.08.30.14.47.36 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 30 Aug 2012 14:47:36 -0700 (PDT) Sender: Rob Clark From: Rob Clark To: wayland-devel@lists.freedesktop.org Cc: patches@linaro.org, Pekka Paalanen Subject: [PATCH weston 3/5] compositor: specialised fragment shader for RGBX Date: Thu, 30 Aug 2012 16:47:19 -0500 Message-Id: <1346363241-29219-4-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1346363241-29219-1-git-send-email-rob.clark@linaro.org> References: <1346363241-29219-1-git-send-email-rob.clark@linaro.org> X-Gm-Message-State: ALoCoQkJKoVEQyWy28wqLXtMBmJWp+d7sAzKnznDRJlqrE8ofkazznx8DPBhYv8iekUqg3rydOzm From: Pekka Paalanen Remove the weston_surface::blend attribute, which really meant that the texture produced valid alpha values. This was used to override the opaque region for RGBX surfaces, which produce undefined values for alpha. Instead, compile a new shader especially for RGBX surfaces, that hardcodes the sampled alpha as 1.0. Before "compositor: optimize/simplify shaders" there was a 'vec4 opaque' in the shaders, that would cause part of the texture to be forced to alpha=1.0. Now that is gone, and we need this replacement. To test: launch simple-shm, and use the super+alt+mousewheel combination to make it transparent. It should not show a light cross over the window. Signed-off-by: Pekka Paalanen --- src/compositor.c | 22 +++++++++++++++++----- src/compositor.h | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/compositor.c b/src/compositor.c index 228ffe4..030ec8f 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -240,7 +240,6 @@ weston_surface_create(struct weston_compositor *compositor) surface->compositor = compositor; surface->alpha = 1.0; - surface->blend = 1; surface->opaque_rect[0] = 0.0; surface->opaque_rect[1] = 0.0; surface->opaque_rect[2] = 0.0; @@ -790,7 +789,6 @@ 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); @@ -799,9 +797,9 @@ weston_surface_attach(struct wl_surface *surface, struct wl_buffer *buffer) es->pitch, es->buffer->height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL); if (wl_shm_buffer_get_format(buffer) == WL_SHM_FORMAT_XRGB8888) - es->blend = 0; + es->shader = &ec->texture_shader_rgbx; else - es->blend = 1; + es->shader = &ec->texture_shader_rgba; } else if (ec->query_buffer(ec->egl_display, buffer, EGL_TEXTURE_FORMAT, &format)) { for (i = 0; i < es->num_images; i++) @@ -1307,7 +1305,7 @@ weston_surface_draw(struct weston_surface *es, struct weston_output *output, &ec->primary_plane.damage, &repaint); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - if (es->blend || es->alpha < 1.0) { + if (1 || es->alpha < 1.0) { /* blended region is whole surface minus opaque region: */ pixman_region32_init_rect(&surface_blend, 0, 0, es->geometry.width, es->geometry.height); @@ -3204,6 +3202,17 @@ static const char texture_fragment_shader_rgba[] = " gl_FragColor = alpha * texture2D(tex, v_texcoord)\n;" "}\n"; +static const char texture_fragment_shader_rgbx[] = + "precision mediump float;\n" + "varying vec2 v_texcoord;\n" + "uniform sampler2D tex;\n" + "uniform float alpha;\n" + "void main()\n" + "{\n" + " gl_FragColor.rgb = alpha * texture2D(tex, v_texcoord).rgb\n;" + " gl_FragColor.a = alpha;\n" + "}\n"; + static const char texture_fragment_shader_egl_external[] = "#extension GL_OES_EGL_image_external : require\n" "precision mediump float;\n" @@ -3621,6 +3630,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_rgbx, + vertex_shader, texture_fragment_shader_rgbx) < 0) + return -1; if (has_egl_image_external && weston_shader_init(&ec->texture_shader_egl_external, vertex_shader, texture_fragment_shader_egl_external) < 0) diff --git a/src/compositor.h b/src/compositor.h index 3b8c705..74b154a 100644 --- a/src/compositor.h +++ b/src/compositor.h @@ -274,6 +274,7 @@ struct weston_compositor { EGLConfig egl_config; GLuint fbo; struct weston_shader texture_shader_rgba; + struct weston_shader texture_shader_rgbx; struct weston_shader texture_shader_egl_external; struct weston_shader texture_shader_y_uv; struct weston_shader texture_shader_y_u_v; @@ -398,7 +399,6 @@ struct weston_surface { GLfloat color[4]; GLfloat opaque_rect[4]; GLfloat alpha; - int blend; struct weston_plane *plane; /* Surface geometry state, mutable.