Re: [PATCH v4 1/4] drm/format-helper: Export line conversion helper for drm_panic

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

 



On 16/10/2023 12:47, Thomas Zimmermann wrote:
Hi

Am 03.10.23 um 16:22 schrieb Jocelyn Falempe:
drm_panic will need the low-level drm_fb_xxxx_line functions.

It seems like premature optimization to not use drm_fb_blit(); especially since drm_panic is not performance critical.

Also add drm_fb_r1_to_xrgb8888 to render the fonts.

I think we should provide a helper function that returns a pointer to the correct function for each supported case. Essentially, it would move that if-else branching from drm_fb_blit() into its own function.  It's not typical DRM style, but cleaner than retyping the if-elses in drm_panic.

Something like:

typedef int (*drm_format_conv_func)(/* args here */);

drm_format_conv_func  drm_format_conv(u32 dst_fourcc, u32 src_fourcc)
{
     // do if-else from drm_fb_blit here

     return <correct-format-conv-helper>
}
EXPORT_SYMBOL(drm_format_conv)

That would be callable from anywhere. You can integrate any helpers for _R1 here as well.

Regarding the color conversion approach, I think we don't need to convert the whole buffer, like drm_fb_blit() or the xxxx_line() do. Just converting the fg_color and bg_color is enough, and then only the pixel size matters, when converting from R1.

So instead of having plenty of conversion functions, I will only need
R1_to_8bit(), R1_to_16bit(), R1_to_24bit() and R1_to_32bit()

I can encapsulate this in a drm_blit_from_r1(), that will also take the fg_color and bg_color as parameter.

If you agree with that, I will do it for the v5.

--

Jocelyn



Best regards
Thomas


Signed-off-by: Jocelyn Falempe <jfalempe@xxxxxxxxxx>
---
  drivers/gpu/drm/drm_format_helper.c | 88 ++++++++++++++++++++++++++---
  include/drm/drm_format_helper.h     |  9 +++
  2 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
index f93a4efcee90..c238e5d84f1f 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -270,7 +270,30 @@ void drm_fb_swab(struct iosys_map *dst, const unsigned int *dst_pitch,       drm_fb_xfrm(dst, dst_pitch, &cpp, src, fb, clip, cached, swab_line);
  }
-EXPORT_SYMBOL(drm_fb_swab);
+
+/**
+ * drm_fb_r1_to_32bit_line - Convert one line from monochrome to any 32bit pixel format
+ * @dbuf: Pointer to the destination line (in any 32bit format)
+ * @sbuf: Pointer to the source line (in monochrome)
+ * @pixels: Number of pixels to convert.
+ * @fg_color: Foreground color, applied when R1 is 1
+ * @bg_color: Background color, applied when R1 is 0
+ *
+ * Convert monochrome to any format with 32bit pixel.
+ * There is a limitation, as sbuf is a pointer, it can only points to a multiple
+ * of 8 pixels in the source buffer.
+ */
+void drm_fb_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned int pixels,
+                u32 fg_color, u32 bg_color)
+{
+    unsigned int x;
+    const u8 *sbuf8 = sbuf;
+    u32 *dubf32 = dbuf;
+
+    for (x = 0; x < pixels; x++)
+        dubf32[x] = (sbuf8[x / 8] & (0x80 >> (x % 8))) ? fg_color : bg_color;
+}
+EXPORT_SYMBOL(drm_fb_r1_to_32bit_line);
  static void drm_fb_xrgb8888_to_rgb332_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
@@ -320,7 +343,13 @@ void drm_fb_xrgb8888_to_rgb332(struct iosys_map *dst, const unsigned int *dst_pi
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb332);
-static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to RGB565
+ * @dbuf: Pointer to the destination line (in RGB565)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;
@@ -336,6 +365,7 @@ static void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigne
          dbuf16[x] = cpu_to_le16(val16);
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565_line);
  /* TODO: implement this helper as conversion to RGB565|BIG_ENDIAN */
  static void drm_fb_xrgb8888_to_rgb565_swab_line(void *dbuf, const void *sbuf, @@ -396,7 +426,13 @@ void drm_fb_xrgb8888_to_rgb565(struct iosys_map *dst, const unsigned int *dst_pi
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb565);
-static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to XRGB1555
+ * @dbuf: Pointer to the destination line (in XRGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;
@@ -412,6 +448,7 @@ static void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsig
          dbuf16[x] = cpu_to_le16(val16);
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555_line);
  /**
   * drm_fb_xrgb8888_to_xrgb1555 - Convert XRGB8888 to XRGB1555 clip buffer @@ -447,7 +484,13 @@ void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb1555);
-static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb565_line - Convert one line from XRGB8888 to ARGB1555
+ * @dbuf: Pointer to the destination line (in ARGB1555)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;
@@ -464,6 +507,7 @@ static void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsig
          dbuf16[x] = cpu_to_le16(val16);
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555_line);
  /**
   * drm_fb_xrgb8888_to_argb1555 - Convert XRGB8888 to ARGB1555 clip buffer @@ -499,7 +543,13 @@ void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb1555);
-static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgba5551_line - Convert one line from XRGB8888 to ARGB5551
+ * @dbuf: Pointer to the destination line (in ARGB5551)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le16 *dbuf16 = dbuf;
      const __le32 *sbuf32 = sbuf;
@@ -516,6 +566,7 @@ static void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsig
          dbuf16[x] = cpu_to_le16(val16);
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551_line);
  /**
   * drm_fb_xrgb8888_to_rgba5551 - Convert XRGB8888 to RGBA5551 clip buffer @@ -551,7 +602,13 @@ void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgba5551);
-static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to RGB888
+ * @dbuf: Pointer to the destination line (in RGB888)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      u8 *dbuf8 = dbuf;
      const __le32 *sbuf32 = sbuf;
@@ -566,6 +623,7 @@ static void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigne
          *dbuf8++ = (pix & 0x00FF0000) >> 16;
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_rgb888_line);
  /**
   * drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer
@@ -709,7 +767,13 @@ static void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned in
              drm_fb_xrgb8888_to_xbgr8888_line);
  }
-static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to XRGB2101010
+ * @dbuf: Pointer to the destination line (in XRGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le32 *dbuf32 = dbuf;
      const __le32 *sbuf32 = sbuf;
@@ -726,6 +790,7 @@ static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, un
          *dbuf32++ = cpu_to_le32(pix);
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010_line);
  /**
   * drm_fb_xrgb8888_to_xrgb2101010 - Convert XRGB8888 to XRGB2101010 clip buffer @@ -761,7 +826,13 @@ void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *d
  }
  EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010);
-static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
+/**
+ * drm_fb_xrgb8888_to_rgb888_line - Convert one line from XRGB8888 to ARGB2101010
+ * @dbuf: Pointer to the destination line (in ARGB2101010)
+ * @sbuf: Pointer to the source line (in XRGB8888)
+ * @pixels: Number of pixels to convert.
+ */
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
  {
      __le32 *dbuf32 = dbuf;
      const __le32 *sbuf32 = sbuf;
@@ -779,6 +850,7 @@ static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, un
          *dbuf32++ = cpu_to_le32(pix);
      }
  }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb2101010_line);
  /**
   * drm_fb_xrgb8888_to_argb2101010 - Convert XRGB8888 to ARGB2101010 clip buffer diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
index 291deb09475b..31ab699128d5 100644
--- a/include/drm/drm_format_helper.h
+++ b/include/drm/drm_format_helper.h
@@ -24,30 +24,39 @@ void drm_fb_memcpy(struct iosys_map *dst, const unsigned int *dst_pitch,
  void drm_fb_swab(struct iosys_map *dst, const unsigned int *dst_pitch,
           const struct iosys_map *src, const struct drm_framebuffer *fb,
           const struct drm_rect *clip, bool cached);
+void drm_fb_r1_to_32bit_line(void *dbuf, const void *sbuf, unsigned int pixels,
+                 u32 fg_color, u32 bg_color);
  void drm_fb_xrgb8888_to_rgb332(struct iosys_map *dst, const unsigned int *dst_pitch,                      const struct iosys_map *src, const struct drm_framebuffer *fb,
                     const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgb565_line(void *dbuf, const void *sbuf, unsigned int pixels);   void drm_fb_xrgb8888_to_rgb565(struct iosys_map *dst, const unsigned int *dst_pitch,                      const struct iosys_map *src, const struct drm_framebuffer *fb,
                     const struct drm_rect *clip, bool swab);
+void drm_fb_xrgb8888_to_xrgb1555_line(void *dbuf, const void *sbuf, unsigned int pixels);   void drm_fb_xrgb8888_to_xrgb1555(struct iosys_map *dst, const unsigned int *dst_pitch,                    const struct iosys_map *src, const struct drm_framebuffer *fb,
                   const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb1555_line(void *dbuf, const void *sbuf, unsigned int pixels);   void drm_fb_xrgb8888_to_argb1555(struct iosys_map *dst, const unsigned int *dst_pitch,                    const struct iosys_map *src, const struct drm_framebuffer *fb,
                   const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgba5551_line(void *dbuf, const void *sbuf, unsigned int pixels);   void drm_fb_xrgb8888_to_rgba5551(struct iosys_map *dst, const unsigned int *dst_pitch,                    const struct iosys_map *src, const struct drm_framebuffer *fb,
                   const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_rgb888_line(void *dbuf, const void *sbuf, unsigned int pixels);   void drm_fb_xrgb8888_to_rgb888(struct iosys_map *dst, const unsigned int *dst_pitch,                      const struct iosys_map *src, const struct drm_framebuffer *fb,
                     const struct drm_rect *clip);
  void drm_fb_xrgb8888_to_argb8888(struct iosys_map *dst, const unsigned int *dst_pitch,                    const struct iosys_map *src, const struct drm_framebuffer *fb,
                   const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels);   void drm_fb_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *dst_pitch,                       const struct iosys_map *src, const struct drm_framebuffer *fb,
                      const struct drm_rect *clip);
+void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels);   void drm_fb_xrgb8888_to_argb2101010(struct iosys_map *dst, const unsigned int *dst_pitch,                       const struct iosys_map *src, const struct drm_framebuffer *fb,
                      const struct drm_rect *clip);





[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux