[PATCH v5 4/5] drm: add generic blending related properties

2016-02-29 Thread Ville Syrjälä
On Wed, Jan 27, 2016 at 03:44:42PM +0100, Marek Szyprowski wrote:
> This patch adds code and documentation for the following blending
> related properties: 'alpha', 'blending' and 'alpha_premult'.
> 
> 'alpha' property defines plane's transparency used for some blending
> modes.
> 
> 'alpha_premult' property defines if RGB pixel data in the framebuffer
> contains values pre-multiplied by its alpha value or full range RGB
> values (0-255), which needs to be multiplied by pixel alpha value for
> blending operation.
> 
> 'blending' property selects blending mode - by selecting one of the
> predefined values, user can select a pair of factors, which will be
> used in the generic blending equation. For more information, see
> the kerneldoc for the added code.
> 
> Signed-off-by: Marek Szyprowski 
> ---
>  Documentation/DocBook/gpu.tmpl |  47 +-
>  drivers/gpu/drm/drm_atomic.c   |  12 +
>  drivers/gpu/drm/drm_blend.c| 110 
> +
>  include/drm/drm_crtc.h |  15 ++
>  include/uapi/drm/drm_mode.h| 101 +
>  5 files changed, 283 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
> index ae7d913adf60..e5197368e68f 100644
> --- a/Documentation/DocBook/gpu.tmpl
> +++ b/Documentation/DocBook/gpu.tmpl
> @@ -1110,6 +1110,22 @@ int max_width, max_height;
>  
>
>  
> +  
> +
> +  
> +Plane blending
> +
> +
> +  Plane Blending Overview
> +!Pinclude/uapi/drm/drm_mode.h Generic plane blending operation
> +
> +
> +  Blending Function Reference
> +!Iinclude/uapi/drm/drm_mode.h
> +!Edrivers/gpu/drm/drm_blend.c
> +
> +  
> +
>
>  
>
> @@ -1816,7 +1832,7 @@ void intel_crt_init(struct drm_device *dev)
>   Description/Restrictions
>   
>   
> - DRM
> + DRM
>   Generic
>   “rotation”
>   BITMASK
> @@ -2068,7 +2084,7 @@ void intel_crt_init(struct drm_device *dev)
>   property to suggest an Y offset for a connector
>   
>   
> - Optional
> + Optional
>   “scaling mode”
>   ENUM
>   { "None", "Full", "Center", "Full aspect" }
> @@ -2102,6 +2118,33 @@ void intel_crt_init(struct drm_device *dev)
>   planes' order. Exact value range is driver dependent.
>   
>   
> +  "alpha" 
> + RANGE
> + Min=0, Max= driver dependent
> + Plane
> + Plane's alpha value (transparency) for blending 
> operation. Used in some blending modes. 
> + 
> + 
> +  "alpha_premult" 
> + BOOL
> + Min=0, Max=1
> + Plane
> + Indicates the range of the RGB data of the 
> framebuffer attached to the given plane.
> + When enabled, RGB values fits the range from 0 to pixel's alpha 
> value. When disabled, RGB
> + values are from 0 to 255 range and during blending operations 
> they will be multiplied by
> + the pixel's alpha value first before computing result of 
> blending equations. Value of this
> + property is used in some blending modes and only when user 
> attaches framebuffer with pixel
> + format, which contains non-binary alpha channel.

I have a hard to figure out what that is saying. The fact that it goes
on talking about ranges of the RGB values is IMO just confusing.

I'm pretty sure I've suggested it before, but I would just make this
some kind of 'alpha_premultiply' which when enabled will perform the
premultiplication, and when disabled it won't.

Description could IMO be something as simple as 
"Premultiply the source RGB values with the source alpha before blending?"

> + 
> + 
> +  "blending" 
> + ENUM
> + { "disabled", "pixel-alpha", "const-alpha" 
> "pixel-const-alpha" }
> + Plane
> + Selects algorithm used in plane blending operation. 
> For more information, see
> + DRM_BLEND_* symbolic constant documentation. 
> + 
> + 
>   i915
>   Generic
>   "Broadcast RGB"
> diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
> index a19201efb7d1..a85da144fd95 100644
> --- a/drivers/gpu/drm/drm_atomic.c
> +++ b/drivers/gpu/drm/drm_atomic.c
> @@ -632,6 +632,12 @@ int drm_atomic_plane_set_property(struct drm_plane 
> *plane,
>   state->rotation = val;
>   } else if (property == config->zpos_property) {
>   state->zpos = val;
> + } else if (property == config->alpha_property) {
> + state->alpha = val;
> + } else if (property == config->alpha_premult_property) {
> + state->alpha_premult = val;
> + } else if (property == config->blending_property) {
> + state->blending = val;
>   } else if (plane->funcs->atomic_set_property) {
>   return plane->funcs->atomic_set_property(plane, state,
>   property, val);
> @@ -690,6 +696,12 @@ 

[PATCH v5 4/5] drm: add generic blending related properties

2016-01-27 Thread Marek Szyprowski
This patch adds code and documentation for the following blending
related properties: 'alpha', 'blending' and 'alpha_premult'.

'alpha' property defines plane's transparency used for some blending
modes.

'alpha_premult' property defines if RGB pixel data in the framebuffer
contains values pre-multiplied by its alpha value or full range RGB
values (0-255), which needs to be multiplied by pixel alpha value for
blending operation.

'blending' property selects blending mode - by selecting one of the
predefined values, user can select a pair of factors, which will be
used in the generic blending equation. For more information, see
the kerneldoc for the added code.

Signed-off-by: Marek Szyprowski 
---
 Documentation/DocBook/gpu.tmpl |  47 +-
 drivers/gpu/drm/drm_atomic.c   |  12 +
 drivers/gpu/drm/drm_blend.c| 110 +
 include/drm/drm_crtc.h |  15 ++
 include/uapi/drm/drm_mode.h| 101 +
 5 files changed, 283 insertions(+), 2 deletions(-)

diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
index ae7d913adf60..e5197368e68f 100644
--- a/Documentation/DocBook/gpu.tmpl
+++ b/Documentation/DocBook/gpu.tmpl
@@ -1110,6 +1110,22 @@ int max_width, max_height;
 
   

+  
+
+  
+Plane blending
+
+
+  Plane Blending Overview
+!Pinclude/uapi/drm/drm_mode.h Generic plane blending operation
+
+
+  Blending Function Reference
+!Iinclude/uapi/drm/drm_mode.h
+!Edrivers/gpu/drm/drm_blend.c
+
+  
+
   

   
@@ -1816,7 +1832,7 @@ void intel_crt_init(struct drm_device *dev)
Description/Restrictions


-   DRM
+   DRM
Generic
“rotation”
BITMASK
@@ -2068,7 +2084,7 @@ void intel_crt_init(struct drm_device *dev)
property to suggest an Y offset for a connector


-   Optional
+   Optional
“scaling mode”
ENUM
{ "None", "Full", "Center", "Full aspect" }
@@ -2102,6 +2118,33 @@ void intel_crt_init(struct drm_device *dev)
planes' order. Exact value range is driver dependent.


+"alpha" 
+   RANGE
+   Min=0, Max= driver dependent
+   Plane
+   Plane's alpha value (transparency) for blending 
operation. Used in some blending modes. 
+   
+   
+"alpha_premult" 
+   BOOL
+   Min=0, Max=1
+   Plane
+   Indicates the range of the RGB data of the 
framebuffer attached to the given plane.
+   When enabled, RGB values fits the range from 0 to pixel's alpha 
value. When disabled, RGB
+   values are from 0 to 255 range and during blending operations 
they will be multiplied by
+   the pixel's alpha value first before computing result of 
blending equations. Value of this
+   property is used in some blending modes and only when user 
attaches framebuffer with pixel
+   format, which contains non-binary alpha channel.
+   
+   
+"blending" 
+   ENUM
+   { "disabled", "pixel-alpha", "const-alpha" 
"pixel-const-alpha" }
+   Plane
+   Selects algorithm used in plane blending operation. 
For more information, see
+   DRM_BLEND_* symbolic constant documentation. 
+   
+   
i915
Generic
"Broadcast RGB"
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index a19201efb7d1..a85da144fd95 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -632,6 +632,12 @@ int drm_atomic_plane_set_property(struct drm_plane *plane,
state->rotation = val;
} else if (property == config->zpos_property) {
state->zpos = val;
+   } else if (property == config->alpha_property) {
+   state->alpha = val;
+   } else if (property == config->alpha_premult_property) {
+   state->alpha_premult = val;
+   } else if (property == config->blending_property) {
+   state->blending = val;
} else if (plane->funcs->atomic_set_property) {
return plane->funcs->atomic_set_property(plane, state,
property, val);
@@ -690,6 +696,12 @@ drm_atomic_plane_get_property(struct drm_plane *plane,
*val = state->rotation;
} else if (property == config->zpos_property) {
*val = state->zpos;
+   } else if (property == config->alpha_property) {
+   *val = state->alpha;
+   } else if (property == config->alpha_premult_property) {
+   *val = state->alpha_premult;
+   } else if (property == config->blending_property) {
+   *val = state->blending;
} else if (plane->funcs->atomic_get_property) {
return plane->funcs->atomic_get_property(plane, state, 
property, val);
} else {
diff --git a/drivers/gpu/drm/drm_blend.c