Mesa (master): st/egl: add premultiplied alpha support to wayland

Chia-I Wu olv at kemper.freedesktop.org
Thu Sep 8 08:05:56 UTC 2011


Module: Mesa
Branch: master
Commit: 7645c49e07b638de94f03d5f71fde397066a46ee
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7645c49e07b638de94f03d5f71fde397066a46ee

Author: Benjamin Franzke <benjaminfranzke at googlemail.com>
Date:   Thu Sep  8 08:01:46 2011 +0200

st/egl: add premultiplied alpha support to wayland

Return true for NATIVE_PARAM_PREMULTIPLIED_ALPHA when all formats with
alpha support premultiplied alpha.

(Based on Chia-I Wu's patch)

[olv: remove the use of param_premultiplied_alpha from the original
      patch]

---

 .../state_trackers/egl/wayland/native_drm.c        |    4 ++--
 .../state_trackers/egl/wayland/native_shm.c        |    4 ++--
 .../state_trackers/egl/wayland/native_wayland.c    |   19 +++++++++++++++++++
 .../state_trackers/egl/wayland/native_wayland.h    |    1 +
 4 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/gallium/state_trackers/egl/wayland/native_drm.c b/src/gallium/state_trackers/egl/wayland/native_drm.c
index 9f6757b..5618f3e 100644
--- a/src/gallium/state_trackers/egl/wayland/native_drm.c
+++ b/src/gallium/state_trackers/egl/wayland/native_drm.c
@@ -109,8 +109,8 @@ wayland_create_drm_buffer(struct wayland_display *display,
 
    switch (surface->color_format) {
    case PIPE_FORMAT_B8G8R8A8_UNORM:
-      /* assume premultiplied */
-      format = WL_DRM_FORMAT_PREMULTIPLIED_ARGB32;
+      format = (surface->premultiplied_alpha) ?
+         WL_DRM_FORMAT_PREMULTIPLIED_ARGB32 : WL_DRM_FORMAT_ARGB32;
       break;
    case PIPE_FORMAT_B8G8R8X8_UNORM:
       format = WL_DRM_FORMAT_XRGB32;
diff --git a/src/gallium/state_trackers/egl/wayland/native_shm.c b/src/gallium/state_trackers/egl/wayland/native_shm.c
index 8a50915..f9a7d81 100644
--- a/src/gallium/state_trackers/egl/wayland/native_shm.c
+++ b/src/gallium/state_trackers/egl/wayland/native_shm.c
@@ -94,8 +94,8 @@ wayland_create_shm_buffer(struct wayland_display *display,
 
    switch (surface->color_format) {
    case PIPE_FORMAT_B8G8R8A8_UNORM:
-      /* assume premultiplied */
-      format = WL_SHM_FORMAT_PREMULTIPLIED_ARGB32;
+      format = (surface->premultiplied_alpha) ?
+         WL_SHM_FORMAT_PREMULTIPLIED_ARGB32 : WL_SHM_FORMAT_ARGB32;
       break;
    case PIPE_FORMAT_B8G8R8X8_UNORM:
       format = WL_SHM_FORMAT_XRGB32;
diff --git a/src/gallium/state_trackers/egl/wayland/native_wayland.c b/src/gallium/state_trackers/egl/wayland/native_wayland.c
index 7273d0e..c694293 100644
--- a/src/gallium/state_trackers/egl/wayland/native_wayland.c
+++ b/src/gallium/state_trackers/egl/wayland/native_wayland.c
@@ -99,9 +99,14 @@ static int
 wayland_display_get_param(struct native_display *ndpy,
                           enum native_param_type param)
 {
+   struct wayland_display *display = wayland_display(ndpy);
    int val;
 
    switch (param) {
+   case NATIVE_PARAM_PREMULTIPLIED_ALPHA:
+      val = ((display->formats & HAS_ARGB32) &&
+             (display->formats & HAS_PREMUL_ARGB32));
+      break;
    case NATIVE_PARAM_USE_NATIVE_BUFFER:
    case NATIVE_PARAM_PRESERVE_BUFFER:
    case NATIVE_PARAM_MAX_SWAP_INTERVAL:
@@ -322,6 +327,20 @@ wayland_surface_present(struct native_surface *nsurf,
    if (ctrl->preserve || ctrl->swap_interval)
       return FALSE;
 
+   /* force buffers to be re-created if they will be presented differently */
+   if (surface->premultiplied_alpha != ctrl->premultiplied_alpha) {
+      enum wayland_buffer_type buffer;
+
+      for (buffer = 0; buffer < WL_BUFFER_COUNT; ++buffer) {
+         if (surface->buffer[buffer]) {
+            wl_buffer_destroy(surface->buffer[buffer]);
+            surface->buffer[buffer] = NULL;
+         }
+      }
+
+      surface->premultiplied_alpha = ctrl->premultiplied_alpha;
+   }
+
    switch (ctrl->natt) {
    case NATIVE_ATTACHMENT_FRONT_LEFT:
       ret = TRUE;
diff --git a/src/gallium/state_trackers/egl/wayland/native_wayland.h b/src/gallium/state_trackers/egl/wayland/native_wayland.h
index 0350a95..143428c 100644
--- a/src/gallium/state_trackers/egl/wayland/native_wayland.h
+++ b/src/gallium/state_trackers/egl/wayland/native_wayland.h
@@ -87,6 +87,7 @@ struct wayland_surface {
    unsigned int attachment_mask;
 
    boolean block_swap_buffers;
+   boolean premultiplied_alpha;
 };
 
 struct wayland_config {




More information about the mesa-commit mailing list