st/egl: add premultiplied alpha support to wayland
authorBenjamin Franzke <benjaminfranzke@googlemail.com>
Thu, 8 Sep 2011 06:01:46 +0000 (08:01 +0200)
committerChia-I Wu <olv@lunarg.com>
Thu, 8 Sep 2011 08:05:41 +0000 (16:05 +0800)
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]

src/gallium/state_trackers/egl/wayland/native_drm.c
src/gallium/state_trackers/egl/wayland/native_shm.c
src/gallium/state_trackers/egl/wayland/native_wayland.c
src/gallium/state_trackers/egl/wayland/native_wayland.h

index 9f6757b3c61f09cf629110dcc7d896815750fee2..5618f3ec2964f4bc7ebaf4000c8bc67a18a9c31e 100644 (file)
@@ -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;
index 8a50915a9c6d9977d78df7a504a58db68f49834b..f9a7d81c04381c8bb3c9fdfc4b73171d8dbe302c 100644 (file)
@@ -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;
index 7273d0ef9a7a2f3f2a6f03e51ae1808acf487043..c6942931ec2d3705d2212f389a40ed95f3ae6359 100644 (file)
@@ -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;
index 0350a958154b163623e161a0d0111662f4d32c28..143428c5f9c3a3a3b4fe61cacb123b6887997e51 100644 (file)
@@ -87,6 +87,7 @@ struct wayland_surface {
    unsigned int attachment_mask;
 
    boolean block_swap_buffers;
+   boolean premultiplied_alpha;
 };
 
 struct wayland_config {