Re: [PATCH 4/9] drm/format-helper: Rework format-helper conversion functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

Am 24.10.21 um 13:32 schrieb Noralf Trønnes:


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@xxxxxxx>
---

  /**
   * 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);

Fixed in the next revision. Thank you so much!

Best regards
Thomas


With that fixed:

Tested-by: Noralf Trønnes <noralf@xxxxxxxxxxx>
Reviewed-by: Noralf Trønnes <noralf@xxxxxxxxxxx>

+
  	/*
  	 * 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);

--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Ivo Totev

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux