diff mbox series

drm/vkms: Use alpha value to blend values.

Message ID 20190831172546.GA1972@raspberrypi (mailing list archive)
State New, archived
Headers show
Series drm/vkms: Use alpha value to blend values. | expand

Commit Message

Sidong Yang Aug. 31, 2019, 5:25 p.m. UTC
Use alpha value to blend source value and destination value Instead of
just overwrite with source value.

Signed-off-by: Sidong Yang <realwakka@gmail.com>
---
 drivers/gpu/drm/vkms/vkms_composer.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Comments

Ville Syrjala Sept. 2, 2019, 12:28 p.m. UTC | #1
On Sat, Aug 31, 2019 at 06:25:46PM +0100, Sidong Yang wrote:
> Use alpha value to blend source value and destination value Instead of
> just overwrite with source value.
> 
> Signed-off-by: Sidong Yang <realwakka@gmail.com>
> ---
>  drivers/gpu/drm/vkms/vkms_composer.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
> index d5585695c64d..b776185e5cb5 100644
> --- a/drivers/gpu/drm/vkms/vkms_composer.c
> +++ b/drivers/gpu/drm/vkms/vkms_composer.c
> @@ -75,6 +75,9 @@ static void blend(void *vaddr_dst, void *vaddr_src,
>  	int y_limit = y_src + h_dst;
>  	int x_limit = x_src + w_dst;
>  
> +	u8 *src, *dst;
> +	u32 alpha, inv_alpha;

These could all live in a tighter scope.

Apart from that lgtm
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

> +
>  	for (i = y_src, i_dst = y_dst; i < y_limit; ++i) {
>  		for (j = x_src, j_dst = x_dst; j < x_limit; ++j) {
>  			offset_dst = dest_composer->offset
> @@ -84,8 +87,14 @@ static void blend(void *vaddr_dst, void *vaddr_src,
>  				     + (i * src_composer->pitch)
>  				     + (j * src_composer->cpp);
>  
> -			memcpy(vaddr_dst + offset_dst,
> -			       vaddr_src + offset_src, sizeof(u32));
> +			src = vaddr_src + offset_src;
> +			dst = vaddr_dst + offset_dst;
> +			alpha = src[3] + 1;
> +			inv_alpha = 256 - src[3];
> +			dst[0] = (alpha * src[0] + inv_alpha * dst[0]) >> 8;
> +			dst[1] = (alpha * src[1] + inv_alpha * dst[1]) >> 8;
> +			dst[2] = (alpha * src[2] + inv_alpha * dst[2]) >> 8;
> +			dst[3] = 0xff;
>  		}
>  		i_dst++;
>  	}
> -- 
> 2.20.1
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
Sidong Yang Sept. 4, 2019, 7:27 a.m. UTC | #2
On Mon, Sep 02, 2019 at 03:28:58PM +0300, Ville Syrjälä wrote:
> On Sat, Aug 31, 2019 at 06:25:46PM +0100, Sidong Yang wrote:
> > Use alpha value to blend source value and destination value Instead of
> > just overwrite with source value.
> > 
> > Signed-off-by: Sidong Yang <realwakka@gmail.com>
> > ---
> >  drivers/gpu/drm/vkms/vkms_composer.c | 13 +++++++++++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
> > index d5585695c64d..b776185e5cb5 100644
> > --- a/drivers/gpu/drm/vkms/vkms_composer.c
> > +++ b/drivers/gpu/drm/vkms/vkms_composer.c
> > @@ -75,6 +75,9 @@ static void blend(void *vaddr_dst, void *vaddr_src,
> >  	int y_limit = y_src + h_dst;
> >  	int x_limit = x_src + w_dst;
> >  
> > +	u8 *src, *dst;
> > +	u32 alpha, inv_alpha;
> 
> These could all live in a tighter scope.

Hi, Ville.

Thank you for reviewing my patch.
I think that's good idea and I'll do that in next version.
I found some patch in mailing list that is similar with this patch.
So should I drop this patch and find other thing?

Sidong.

> 
> Apart from that lgtm
> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> > +
> >  	for (i = y_src, i_dst = y_dst; i < y_limit; ++i) {
> >  		for (j = x_src, j_dst = x_dst; j < x_limit; ++j) {
> >  			offset_dst = dest_composer->offset
> > @@ -84,8 +87,14 @@ static void blend(void *vaddr_dst, void *vaddr_src,
> >  				     + (i * src_composer->pitch)
> >  				     + (j * src_composer->cpp);
> >  
> > -			memcpy(vaddr_dst + offset_dst,
> > -			       vaddr_src + offset_src, sizeof(u32));
> > +			src = vaddr_src + offset_src;
> > +			dst = vaddr_dst + offset_dst;
> > +			alpha = src[3] + 1;
> > +			inv_alpha = 256 - src[3];
> > +			dst[0] = (alpha * src[0] + inv_alpha * dst[0]) >> 8;
> > +			dst[1] = (alpha * src[1] + inv_alpha * dst[1]) >> 8;
> > +			dst[2] = (alpha * src[2] + inv_alpha * dst[2]) >> 8;
> > +			dst[3] = 0xff;
> >  		}
> >  		i_dst++;
> >  	}
> > -- 
> > 2.20.1
> > 
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> 
> -- 
> Ville Syrjälä
> Intel
Ville Syrjala Sept. 4, 2019, 3:48 p.m. UTC | #3
On Wed, Sep 04, 2019 at 08:27:07AM +0100, Sidong Yang wrote:
> On Mon, Sep 02, 2019 at 03:28:58PM +0300, Ville Syrjälä wrote:
> > On Sat, Aug 31, 2019 at 06:25:46PM +0100, Sidong Yang wrote:
> > > Use alpha value to blend source value and destination value Instead of
> > > just overwrite with source value.
> > > 
> > > Signed-off-by: Sidong Yang <realwakka@gmail.com>
> > > ---
> > >  drivers/gpu/drm/vkms/vkms_composer.c | 13 +++++++++++--
> > >  1 file changed, 11 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
> > > index d5585695c64d..b776185e5cb5 100644
> > > --- a/drivers/gpu/drm/vkms/vkms_composer.c
> > > +++ b/drivers/gpu/drm/vkms/vkms_composer.c
> > > @@ -75,6 +75,9 @@ static void blend(void *vaddr_dst, void *vaddr_src,
> > >  	int y_limit = y_src + h_dst;
> > >  	int x_limit = x_src + w_dst;
> > >  
> > > +	u8 *src, *dst;
> > > +	u32 alpha, inv_alpha;
> > 
> > These could all live in a tighter scope.
> 
> Hi, Ville.
> 
> Thank you for reviewing my patch.
> I think that's good idea and I'll do that in next version.
> I found some patch in mailing list that is similar with this patch.
> So should I drop this patch and find other thing?

Probably best if you discuss that with whoever sent that other patch.

> 
> Sidong.
> 
> > 
> > Apart from that lgtm
> > Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > > +
> > >  	for (i = y_src, i_dst = y_dst; i < y_limit; ++i) {
> > >  		for (j = x_src, j_dst = x_dst; j < x_limit; ++j) {
> > >  			offset_dst = dest_composer->offset
> > > @@ -84,8 +87,14 @@ static void blend(void *vaddr_dst, void *vaddr_src,
> > >  				     + (i * src_composer->pitch)
> > >  				     + (j * src_composer->cpp);
> > >  
> > > -			memcpy(vaddr_dst + offset_dst,
> > > -			       vaddr_src + offset_src, sizeof(u32));
> > > +			src = vaddr_src + offset_src;
> > > +			dst = vaddr_dst + offset_dst;
> > > +			alpha = src[3] + 1;
> > > +			inv_alpha = 256 - src[3];
> > > +			dst[0] = (alpha * src[0] + inv_alpha * dst[0]) >> 8;
> > > +			dst[1] = (alpha * src[1] + inv_alpha * dst[1]) >> 8;
> > > +			dst[2] = (alpha * src[2] + inv_alpha * dst[2]) >> 8;
> > > +			dst[3] = 0xff;
> > >  		}
> > >  		i_dst++;
> > >  	}
> > > -- 
> > > 2.20.1
> > > 
> > > _______________________________________________
> > > dri-devel mailing list
> > > dri-devel@lists.freedesktop.org
> > > https://lists.freedesktop.org/mailman/listinfo/dri-devel
> > 
> > -- 
> > Ville Syrjälä
> > Intel
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
index d5585695c64d..b776185e5cb5 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -75,6 +75,9 @@  static void blend(void *vaddr_dst, void *vaddr_src,
 	int y_limit = y_src + h_dst;
 	int x_limit = x_src + w_dst;
 
+	u8 *src, *dst;
+	u32 alpha, inv_alpha;
+
 	for (i = y_src, i_dst = y_dst; i < y_limit; ++i) {
 		for (j = x_src, j_dst = x_dst; j < x_limit; ++j) {
 			offset_dst = dest_composer->offset
@@ -84,8 +87,14 @@  static void blend(void *vaddr_dst, void *vaddr_src,
 				     + (i * src_composer->pitch)
 				     + (j * src_composer->cpp);
 
-			memcpy(vaddr_dst + offset_dst,
-			       vaddr_src + offset_src, sizeof(u32));
+			src = vaddr_src + offset_src;
+			dst = vaddr_dst + offset_dst;
+			alpha = src[3] + 1;
+			inv_alpha = 256 - src[3];
+			dst[0] = (alpha * src[0] + inv_alpha * dst[0]) >> 8;
+			dst[1] = (alpha * src[1] + inv_alpha * dst[1]) >> 8;
+			dst[2] = (alpha * src[2] + inv_alpha * dst[2]) >> 8;
+			dst[3] = 0xff;
 		}
 		i_dst++;
 	}