All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH xf86-video-amdgpu] Apply gamma correction to HW cursor
@ 2017-05-02  3:16 Michel Dänzer
       [not found] ` <20170502031615.22988-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Michel Dänzer @ 2017-05-02  3:16 UTC (permalink / raw)
  To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

From: Michel Dänzer <michel.daenzer@amd.com>

The display hardware CLUT we're currently using for gamma correction
doesn't affect the HW cursor, so we have to apply it manually when
uploading the HW cursor data.

This currently only works in depth 24/32.

Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
---
 src/drmmode_display.c | 66 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 58 insertions(+), 8 deletions(-)

diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index 5e0c4133b..5b2431495 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -756,6 +756,17 @@ drmmode_crtc_scanout_update(xf86CrtcPtr crtc, DisplayModePtr mode,
 	}
 }
 
+static void
+drmmode_crtc_gamma_do_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t *green,
+			  uint16_t *blue, int size)
+{
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(crtc->scrn);
+
+	drmModeCrtcSetGamma(pAMDGPUEnt->fd, drmmode_crtc->mode_crtc->crtc_id,
+			    size, red, green, blue);
+}
+
 static Bool
 drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		       Rotation rotation, int x, int y)
@@ -820,8 +831,8 @@ drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
 		if (drmmode_crtc->tear_free)
 			scanout_id = drmmode_crtc->scanout_id;
 
-		crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc->gamma_green,
-				       crtc->gamma_blue, crtc->gamma_size);
+		drmmode_crtc_gamma_do_set(crtc, crtc->gamma_red, crtc->gamma_green,
+					  crtc->gamma_blue, crtc->gamma_size);
 
 		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
 
@@ -991,6 +1002,31 @@ drmmode_cursor_src_offset(Rotation rotation, int width, int height,
 
 #endif
 
+static uint32_t
+drmmode_cursor_gamma(xf86CrtcPtr crtc, uint32_t argb)
+{
+	uint32_t alpha = argb >> 24;
+	uint32_t rgb[3];
+	int i;
+
+	if (!alpha)
+		return 0;
+
+	if (crtc->scrn->depth != 24 && crtc->scrn->depth != 32)
+		return argb;
+
+	/* Un-premultiply alpha */
+	for (i = 0; i < 3; i++)
+		rgb[i] = ((argb >> (i * 8)) & 0xff) * 0xff / alpha;
+
+	/* Apply gamma correction and pre-multiply alpha */
+	rgb[0] = (crtc->gamma_blue[rgb[0]] >> 8) * alpha / 0xff;
+	rgb[1] = (crtc->gamma_green[rgb[1]] >> 8) * alpha / 0xff;
+	rgb[2] = (crtc->gamma_red[rgb[2]] >> 8) * alpha / 0xff;
+
+	return alpha << 24 | rgb[2] << 16 | rgb[1] << 8 | rgb[0];
+}
+
 static void drmmode_do_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image, uint32_t *ptr)
 {
 	ScrnInfoPtr pScrn = crtc->scrn;
@@ -1010,7 +1046,8 @@ static void drmmode_do_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image, uint32_
 								      dstx, dsty);
 
 				ptr[dsty * info->cursor_w + dstx] =
-					cpu_to_le32(image[srcoffset]);
+					cpu_to_le32(drmmode_cursor_gamma(crtc,
+									 image[srcoffset]));
 			}
 		}
 	} else
@@ -1020,7 +1057,7 @@ static void drmmode_do_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image, uint32_
 		int i;
 
 		for (i = 0; i < cursor_size; i++)
-			ptr[i] = cpu_to_le32(image[i]);
+			ptr[i] = cpu_to_le32(drmmode_cursor_gamma(crtc, image[i]));
 	}
 }
 
@@ -1176,11 +1213,24 @@ static void
 drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t * red, uint16_t * green,
 		       uint16_t * blue, int size)
 {
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(crtc->scrn);
+	ScrnInfoPtr scrn = crtc->scrn;
+	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
+	AMDGPUInfoPtr info = AMDGPUPTR(scrn);
+	int i;
 
-	drmModeCrtcSetGamma(pAMDGPUEnt->fd, drmmode_crtc->mode_crtc->crtc_id,
-			    size, red, green, blue);
+	drmmode_crtc_gamma_do_set(crtc, red, green, blue, size);
+
+	/* Compute index of this CRTC into xf86_config->crtc */
+	for (i = 0; xf86_config->crtc[i] != crtc; i++) {}
+
+	if (info->hwcursor_disabled & (1 << i))
+		return;
+
+#ifdef HAVE_XF86_CURSOR_RESET_CURSOR
+	xf86CursorResetCursor(scrn->pScreen);
+#else
+	xf86_reload_cursors(scrn->pScreen);
+#endif
 }
 
 #ifdef AMDGPU_PIXMAP_SHARING
-- 
2.11.0

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH xf86-video-amdgpu] Apply gamma correction to HW cursor
       [not found] ` <20170502031615.22988-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org>
@ 2017-05-02  3:38   ` Deucher, Alexander
       [not found]     ` <BN6PR12MB1652ADD5BD87F3BDAB1B0316F7170-/b2+HYfkarQqUD6E6FAiowdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Deucher, Alexander @ 2017-05-02  3:38 UTC (permalink / raw)
  To: 'Michel Dänzer', amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

> -----Original Message-----
> From: amd-gfx [mailto:amd-gfx-bounces@lists.freedesktop.org] On Behalf
> Of Michel Dänzer
> Sent: Monday, May 01, 2017 11:16 PM
> To: amd-gfx@lists.freedesktop.org
> Subject: [PATCH xf86-video-amdgpu] Apply gamma correction to HW cursor
> 
> From: Michel Dänzer <michel.daenzer@amd.com>
> 
> The display hardware CLUT we're currently using for gamma correction
> doesn't affect the HW cursor, so we have to apply it manually when
> uploading the HW cursor data.
> 
> This currently only works in depth 24/32.
> 
> Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>

Starting with DCE5, I vaguely remember there being some controls related to whether gamma correction should be applied to the cursor or not, but I'm not sure if it’s the legacy CLUT or the newer stuff.

Patch is:
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

> ---
>  src/drmmode_display.c | 66
> ++++++++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 58 insertions(+), 8 deletions(-)
> 
> diff --git a/src/drmmode_display.c b/src/drmmode_display.c
> index 5e0c4133b..5b2431495 100644
> --- a/src/drmmode_display.c
> +++ b/src/drmmode_display.c
> @@ -756,6 +756,17 @@ drmmode_crtc_scanout_update(xf86CrtcPtr crtc,
> DisplayModePtr mode,
>  	}
>  }
> 
> +static void
> +drmmode_crtc_gamma_do_set(xf86CrtcPtr crtc, uint16_t *red, uint16_t
> *green,
> +			  uint16_t *blue, int size)
> +{
> +	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
> +	AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(crtc->scrn);
> +
> +	drmModeCrtcSetGamma(pAMDGPUEnt->fd, drmmode_crtc-
> >mode_crtc->crtc_id,
> +			    size, red, green, blue);
> +}
> +
>  static Bool
>  drmmode_set_mode_major(xf86CrtcPtr crtc, DisplayModePtr mode,
>  		       Rotation rotation, int x, int y)
> @@ -820,8 +831,8 @@ drmmode_set_mode_major(xf86CrtcPtr crtc,
> DisplayModePtr mode,
>  		if (drmmode_crtc->tear_free)
>  			scanout_id = drmmode_crtc->scanout_id;
> 
> -		crtc->funcs->gamma_set(crtc, crtc->gamma_red, crtc-
> >gamma_green,
> -				       crtc->gamma_blue, crtc->gamma_size);
> +		drmmode_crtc_gamma_do_set(crtc, crtc->gamma_red, crtc-
> >gamma_green,
> +					  crtc->gamma_blue, crtc-
> >gamma_size);
> 
>  		drmmode_ConvertToKMode(crtc->scrn, &kmode, mode);
> 
> @@ -991,6 +1002,31 @@ drmmode_cursor_src_offset(Rotation rotation, int
> width, int height,
> 
>  #endif
> 
> +static uint32_t
> +drmmode_cursor_gamma(xf86CrtcPtr crtc, uint32_t argb)
> +{
> +	uint32_t alpha = argb >> 24;
> +	uint32_t rgb[3];
> +	int i;
> +
> +	if (!alpha)
> +		return 0;
> +
> +	if (crtc->scrn->depth != 24 && crtc->scrn->depth != 32)
> +		return argb;
> +
> +	/* Un-premultiply alpha */
> +	for (i = 0; i < 3; i++)
> +		rgb[i] = ((argb >> (i * 8)) & 0xff) * 0xff / alpha;
> +
> +	/* Apply gamma correction and pre-multiply alpha */
> +	rgb[0] = (crtc->gamma_blue[rgb[0]] >> 8) * alpha / 0xff;
> +	rgb[1] = (crtc->gamma_green[rgb[1]] >> 8) * alpha / 0xff;
> +	rgb[2] = (crtc->gamma_red[rgb[2]] >> 8) * alpha / 0xff;
> +
> +	return alpha << 24 | rgb[2] << 16 | rgb[1] << 8 | rgb[0];
> +}
> +
>  static void drmmode_do_load_cursor_argb(xf86CrtcPtr crtc, CARD32
> *image, uint32_t *ptr)
>  {
>  	ScrnInfoPtr pScrn = crtc->scrn;
> @@ -1010,7 +1046,8 @@ static void
> drmmode_do_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image, uint32_
>  								      dstx, dsty);
> 
>  				ptr[dsty * info->cursor_w + dstx] =
> -					cpu_to_le32(image[srcoffset]);
> +
> 	cpu_to_le32(drmmode_cursor_gamma(crtc,
> +
> image[srcoffset]));
>  			}
>  		}
>  	} else
> @@ -1020,7 +1057,7 @@ static void
> drmmode_do_load_cursor_argb(xf86CrtcPtr crtc, CARD32 *image, uint32_
>  		int i;
> 
>  		for (i = 0; i < cursor_size; i++)
> -			ptr[i] = cpu_to_le32(image[i]);
> +			ptr[i] = cpu_to_le32(drmmode_cursor_gamma(crtc,
> image[i]));
>  	}
>  }
> 
> @@ -1176,11 +1213,24 @@ static void
>  drmmode_crtc_gamma_set(xf86CrtcPtr crtc, uint16_t * red, uint16_t *
> green,
>  		       uint16_t * blue, int size)
>  {
> -	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
> -	AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(crtc->scrn);
> +	ScrnInfoPtr scrn = crtc->scrn;
> +	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(scrn);
> +	AMDGPUInfoPtr info = AMDGPUPTR(scrn);
> +	int i;
> 
> -	drmModeCrtcSetGamma(pAMDGPUEnt->fd, drmmode_crtc-
> >mode_crtc->crtc_id,
> -			    size, red, green, blue);
> +	drmmode_crtc_gamma_do_set(crtc, red, green, blue, size);
> +
> +	/* Compute index of this CRTC into xf86_config->crtc */
> +	for (i = 0; xf86_config->crtc[i] != crtc; i++) {}
> +
> +	if (info->hwcursor_disabled & (1 << i))
> +		return;
> +
> +#ifdef HAVE_XF86_CURSOR_RESET_CURSOR
> +	xf86CursorResetCursor(scrn->pScreen);
> +#else
> +	xf86_reload_cursors(scrn->pScreen);
> +#endif
>  }
> 
>  #ifdef AMDGPU_PIXMAP_SHARING
> --
> 2.11.0
> 
> _______________________________________________
> amd-gfx mailing list
> amd-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH xf86-video-amdgpu] Apply gamma correction to HW cursor
       [not found]     ` <BN6PR12MB1652ADD5BD87F3BDAB1B0316F7170-/b2+HYfkarQqUD6E6FAiowdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
@ 2017-05-02  4:01       ` Michel Dänzer
  0 siblings, 0 replies; 3+ messages in thread
From: Michel Dänzer @ 2017-05-02  4:01 UTC (permalink / raw)
  To: Deucher, Alexander; +Cc: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW

On 02/05/17 12:38 PM, Deucher, Alexander wrote:
>> -----Original Message-----
>> From: amd-gfx [mailto:amd-gfx-bounces@lists.freedesktop.org] On Behalf
>> Of Michel Dänzer
>> Sent: Monday, May 01, 2017 11:16 PM
>> To: amd-gfx@lists.freedesktop.org
>> Subject: [PATCH xf86-video-amdgpu] Apply gamma correction to HW cursor
>>
>> From: Michel Dänzer <michel.daenzer@amd.com>
>>
>> The display hardware CLUT we're currently using for gamma correction
>> doesn't affect the HW cursor, so we have to apply it manually when
>> uploading the HW cursor data.
>>
>> This currently only works in depth 24/32.
>>
>> Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
> 
> Starting with DCE5, I vaguely remember there being some controls
> related to whether gamma correction should be applied to the cursor or
> not, but I'm not sure if it’s the legacy CLUT or the newer stuff.

I talked to some DC guys about it, apparently only the newer stuff
applies to the cursor.


> Patch is:
> Reviewed-by: Alex Deucher <alexander.deucher@amd.com>

Thanks!


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-02  4:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-02  3:16 [PATCH xf86-video-amdgpu] Apply gamma correction to HW cursor Michel Dänzer
     [not found] ` <20170502031615.22988-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org>
2017-05-02  3:38   ` Deucher, Alexander
     [not found]     ` <BN6PR12MB1652ADD5BD87F3BDAB1B0316F7170-/b2+HYfkarQqUD6E6FAiowdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-05-02  4:01       ` Michel Dänzer

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.