[Mesa-dev] [PATCH 5/5] st/egl: add premultiplied alpha support to wayland

Benjamin Franzke benjaminfranzke at googlemail.com
Thu Sep 8 00:56:59 PDT 2011


2011/9/8 Chia-I Wu <olvaffe at gmail.com>:
> On Thu, Sep 8, 2011 at 3:13 PM, Benjamin Franzke
> <benjaminfranzke at googlemail.com> wrote:
>> 2011/9/8 Chia-I Wu <olvaffe at gmail.com>:
>>> From: Chia-I Wu <olv at lunarg.com>
>>>
>>> Return true for NATIVE_PARAM_PREMULTIPLIED_ALPHA when all formats with
>>> alpha support premultiplied alpha.  Currently, it means when argb32 and
>>> argb32_pre are both supported.
>>> ---
>>>  .../state_trackers/egl/wayland/native_drm.c        |    8 ++++++--
>>>  .../state_trackers/egl/wayland/native_shm.c        |    6 +++++-
>>>  .../state_trackers/egl/wayland/native_wayland.c    |   18 ++++++++++++++++++
>>>  .../state_trackers/egl/wayland/native_wayland.h    |    3 +++
>>>  4 files changed, 32 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/src/gallium/state_trackers/egl/wayland/native_drm.c b/src/gallium/state_trackers/egl/wayland/native_drm.c
>>> index facab32..e177e7c 100644
>>> --- a/src/gallium/state_trackers/egl/wayland/native_drm.c
>>> +++ b/src/gallium/state_trackers/egl/wayland/native_drm.c
>>> @@ -114,8 +114,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;
>>> @@ -255,6 +255,10 @@ wayland_drm_display_init_screen(struct native_display *ndpy)
>>>    if (!wayland_drm_display_add_configs(drmdpy))
>>>       return FALSE;
>>>
>>> +   /* check that premultiplied alpha is supported for all formats with alpha */
>>> +   if (!drmdpy->argb32 || drmdpy->argb32_pre)
>>> +      drmdpy->base.param_premultiplied_alpha = TRUE;
>>
>> Why enable premultiplied alpha if argb32 is not exposed?
>> What isnt covered with just: "if (drmdpy->argb32_pre)"?.
> Yes, it is simpler.  What I intended to do is to enable pre-multiplied
> alpha when all formats that have alpha also support pre-multiplied
> alpha.  In the case there is no format that has alpha
> (!drmdpy->argb32), pre-multiplied alpha can be enabled.

Ok, I see, my idea was to enable only whats actually useful for a configuration,
but I dont know whats the general egl rule here. So I'm ok with both.
>
>>> +
>>>    drmdpy->base.base.screen =
>>>       drmdpy->event_handler->new_drm_screen(&drmdpy->base.base,
>>>                                             NULL, drmdpy->fd);
>>> diff --git a/src/gallium/state_trackers/egl/wayland/native_shm.c b/src/gallium/state_trackers/egl/wayland/native_shm.c
>>> index 5882e74..e2d2437 100644
>>> --- a/src/gallium/state_trackers/egl/wayland/native_shm.c
>>> +++ b/src/gallium/state_trackers/egl/wayland/native_shm.c
>>> @@ -95,7 +95,8 @@ wayland_create_shm_buffer(struct wayland_display *display,
>>>
>>>    switch (surface->color_format) {
>>>    case PIPE_FORMAT_B8G8R8A8_UNORM:
>>> -      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;
>>> @@ -165,6 +166,9 @@ wayland_shm_display_init_screen(struct native_display *ndpy)
>>>    if (!wayland_shm_display_add_configs(shmdpy))
>>>       return FALSE;
>>>
>>> +   /* assume all formats are supported */
>>> +   shmdpy->base.param_premultiplied_alpha = TRUE;
>>> +
>>>    winsys = wayland_create_sw_winsys(shmdpy->base.dpy);
>>>    if (!winsys)
>>>       return FALSE;
>>> diff --git a/src/gallium/state_trackers/egl/wayland/native_wayland.c b/src/gallium/state_trackers/egl/wayland/native_wayland.c
>>> index 14cc908..b2dab8f 100644
>>> --- a/src/gallium/state_trackers/egl/wayland/native_wayland.c
>>> +++ b/src/gallium/state_trackers/egl/wayland/native_wayland.c
>>> @@ -60,9 +60,13 @@ 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->param_premultiplied_alpha;
>>> +      break;
>>>    case NATIVE_PARAM_USE_NATIVE_BUFFER:
>>>    case NATIVE_PARAM_PRESERVE_BUFFER:
>>>    case NATIVE_PARAM_MAX_SWAP_INTERVAL:
>>> @@ -283,6 +287,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 93e670b..6cf98a8 100644
>>> --- a/src/gallium/state_trackers/egl/wayland/native_wayland.h
>>> +++ b/src/gallium/state_trackers/egl/wayland/native_wayland.h
>>> @@ -44,6 +44,8 @@ struct wayland_display {
>>>
>>>    struct wayland_config *configs;
>>>    int num_configs;
>>> +   /* true if all formats with alpha support premultiplied alpha */
>>> +   boolean param_premultiplied_alpha;
>>>
>>>    struct wl_buffer *(*create_buffer)(struct wayland_display *display,
>>>                                       struct wayland_surface *surface,
>>> @@ -79,6 +81,7 @@ struct wayland_surface {
>>>    unsigned int attachment_mask;
>>>
>>>    boolean block_swap_buffers;
>>> +   boolean premultiplied_alpha;
>>>  };
>>>
>>>  struct wayland_config {
>>> --
>>> 1.7.5.4
>>>
>>>
>>
>
>
>
> --
> olv at LunarG.com
>


More information about the mesa-dev mailing list