linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Noralf Trønnes" <noralf@tronnes.org>
To: Thomas Zimmermann <tzimmermann@suse.de>,
	daniel@ffwll.ch, airlied@linux.ie, mripard@kernel.org,
	maarten.lankhorst@linux.intel.com, drawat.floss@gmail.com,
	airlied@redhat.com, kraxel@redhat.com, david@lechnology.com,
	sam@ravnborg.org, javierm@redhat.com, kernel@amanoeldawod.com,
	dirty.ice.hu@gmail.com, michael+lkml@stapelberg.ch, aros@gmx.com,
	joshua@stroblindustries.com, arnd@arndb.de
Cc: dri-devel@lists.freedesktop.org, linux-hyperv@vger.kernel.org,
	virtualization@lists.linux-foundation.org
Subject: Re: [PATCH 4/9] drm/format-helper: Rework format-helper conversion functions
Date: Sun, 24 Oct 2021 13:32:07 +0200	[thread overview]
Message-ID: <34b8daf3-b6b4-02fb-9e10-ef11c0848572@tronnes.org> (raw)
In-Reply-To: <20211022132829.7697-5-tzimmermann@suse.de>



Den 22.10.2021 15.28, skrev Thomas Zimmermann:
> Move destination-buffer clipping from all format-helper conversion
> functions into callers. Support destination-buffer pitch. Only
> distinguish between system and I/O memory, but use same logic
> everywhere.
> 
> Simply harmonize the interface and semantics of the existing code.
> Not all conversion helpers support all combinations of parameters.
> We have to add additional features when we need them.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> ---

>  /**
>   * drm_fb_xrgb8888_to_gray8 - Convert XRGB8888 to grayscale
>   * @dst: 8-bit grayscale destination buffer
> + * @dst_pitch: Number of bytes between two consecutive scanlines within dst
>   * @vaddr: XRGB8888 source buffer
>   * @fb: DRM framebuffer
>   * @clip: Clip rectangle area to copy
> @@ -415,16 +417,21 @@ EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_dstclip);
>   *
>   * ITU BT.601 is used for the RGB -> luma (brightness) conversion.
>   */
> -void drm_fb_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
> -			       struct drm_rect *clip)
> +void drm_fb_xrgb8888_to_gray8(void *dst, unsigned int dst_pitch, const void *vaddr,
> +			      const struct drm_framebuffer *fb, const struct drm_rect *clip)
>  {
>  	unsigned int len = (clip->x2 - clip->x1) * sizeof(u32);
>  	unsigned int x, y;
>  	void *buf;
> -	u32 *src;
> +	u8 *dst8;
> +	u32 *src32;
>  
>  	if (WARN_ON(fb->format->format != DRM_FORMAT_XRGB8888))
>  		return;
> +
> +	if (!dst_pitch)

len is source length (should really have been named src_len) which
results in a kernel crash:

> +		dst_pitch = len;

This works:

		dst_pitch = drm_rect_width(clip);

With that fixed:

Tested-by: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Noralf Trønnes <noralf@tronnes.org>

> +
>  	/*
>  	 * The cma memory is write-combined so reads are uncached.
>  	 * Speed up by fetching one line at a time.
> @@ -433,20 +440,22 @@ void drm_fb_xrgb8888_to_gray8(u8 *dst, void *vaddr, struct drm_framebuffer *fb,
>  	if (!buf)
>  		return;
>  
> +	vaddr += clip_offset(clip, fb->pitches[0], sizeof(u32));
>  	for (y = clip->y1; y < clip->y2; y++) {
> -		src = vaddr + (y * fb->pitches[0]);
> -		src += clip->x1;
> -		memcpy(buf, src, len);
> -		src = buf;
> +		dst8 = dst;
> +		src32 = memcpy(buf, vaddr, len);
>  		for (x = clip->x1; x < clip->x2; x++) {
> -			u8 r = (*src & 0x00ff0000) >> 16;
> -			u8 g = (*src & 0x0000ff00) >> 8;
> -			u8 b =  *src & 0x000000ff;
> +			u8 r = (*src32 & 0x00ff0000) >> 16;
> +			u8 g = (*src32 & 0x0000ff00) >> 8;
> +			u8 b =  *src32 & 0x000000ff;
>  
>  			/* ITU BT.601: Y = 0.299 R + 0.587 G + 0.114 B */
> -			*dst++ = (3 * r + 6 * g + b) / 10;
> -			src++;
> +			*dst8++ = (3 * r + 6 * g + b) / 10;
> +			src32++;
>  		}
> +
> +		vaddr += fb->pitches[0];
> +		dst += dst_pitch;
>  	}
>  
>  	kfree(buf);

  reply	other threads:[~2021-10-24 11:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22 13:28 [PATCH 0/9] drm/simpledrm: Enable damage clips and virtual screens Thomas Zimmermann
2021-10-22 13:28 ` [PATCH 1/9] drm/format-helper: Export drm_fb_clip_offset() Thomas Zimmermann
2021-10-24  8:25   ` Noralf Trønnes
     [not found]   ` <YXO+bGIW9sn9Rcfw@ravnborg.org>
2021-11-01  8:43     ` Thomas Zimmermann
2021-10-22 13:28 ` [PATCH 2/9] drm/format-helper: Rework format-helper memcpy functions Thomas Zimmermann
2021-10-24  8:25   ` Noralf Trønnes
2021-10-22 13:28 ` [PATCH 3/9] drm/format-helper: Add destination-buffer pitch to drm_fb_swab() Thomas Zimmermann
2021-10-24  8:33   ` Noralf Trønnes
2021-10-22 13:28 ` [PATCH 4/9] drm/format-helper: Rework format-helper conversion functions Thomas Zimmermann
2021-10-24 11:32   ` Noralf Trønnes [this message]
2021-11-01 13:38     ` Thomas Zimmermann
2021-10-22 13:28 ` [PATCH 5/9] drm/format-helper: Streamline blit-helper interface Thomas Zimmermann
2021-10-24 14:59   ` Noralf Trønnes
2021-10-22 13:28 ` [PATCH 6/9] drm/fb-helper: Allocate shadow buffer of surface height Thomas Zimmermann
2021-10-24 15:10   ` Noralf Trønnes
2021-10-22 13:28 ` [PATCH 7/9] drm/simpledrm: Enable FB_DAMAGE_CLIPS property Thomas Zimmermann
2021-10-24 15:20   ` Noralf Trønnes
2021-11-01  8:56     ` Thomas Zimmermann
2021-10-22 13:28 ` [PATCH 8/9] drm/simpledrm: Support virtual screen sizes Thomas Zimmermann
2021-10-22 13:28 ` [PATCH 9/9] drm: Clarify semantics of struct drm_mode_config.{min,max}_{width,height} Thomas Zimmermann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=34b8daf3-b6b4-02fb-9e10-ef11c0848572@tronnes.org \
    --to=noralf@tronnes.org \
    --cc=airlied@linux.ie \
    --cc=airlied@redhat.com \
    --cc=arnd@arndb.de \
    --cc=aros@gmx.com \
    --cc=daniel@ffwll.ch \
    --cc=david@lechnology.com \
    --cc=dirty.ice.hu@gmail.com \
    --cc=drawat.floss@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=javierm@redhat.com \
    --cc=joshua@stroblindustries.com \
    --cc=kernel@amanoeldawod.com \
    --cc=kraxel@redhat.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=michael+lkml@stapelberg.ch \
    --cc=mripard@kernel.org \
    --cc=sam@ravnborg.org \
    --cc=tzimmermann@suse.de \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).