From: "Màxim Pedraza Padilla" <maximpedraza@gmail.com>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Ard Biesheuvel <ardb@kernel.org>,
Jonathan Corbet <corbet@lwn.net>
Cc: Francesco Valla <francesco@valla.it>,
Mario Limonciello <mario.limonciello@amd.com>,
Javier Martinez Canillas <javierm@redhat.com>,
Jocelyn Falempe <jfalempe@redhat.com>,
Sam Ravnborg <sam@ravnborg.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
linux-efi@vger.kernel.org, linux-doc@vger.kernel.org,
linux-embedded@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH RFC v4 09/13] drm/client: splash: turn the device tree image as it asks
Date: Thu, 1 Oct 2026 21:58:43 +0200 [thread overview]
Message-ID: <20261001195847.141192-10-maximpedraza@gmail.com> (raw)
In-Reply-To: <20261001195847.141192-1-maximpedraza@gmail.com>
The same board is often fitted with the same panel mounted in more than
one orientation. Let the device tree node ask for the image to be turned,
with a "rotation" property counting degrees counter clockwise, as panels
already do and as DRM_MODE_ROTATE_* count, which is what it is kept as.
The rotation turns the image and not the screen: "logo-position" and
"logo-offset" stay in screen pixels, and a quarter turn only swaps how
much room the image takes up. Placing it in a frame that turned with it
would make the same pair of coordinates mean different places on the
same panel, decided by a property that describes the image.
The three blitters, one per destination pixel size, become one that
reads the source pixel through the rotation and writes it according to
the pixel size. Each source pixel is read as three bytes rather than as
an unaligned u32: a BMP row is only padded as a whole, so with 3 * width
already a multiple of four the last pixel of the image was read one byte
past its end. An upright image going to an RGB888 buffer is still copied
a row at a time.
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Màxim Pedraza Padilla <maximpedraza@gmail.com>
---
drivers/gpu/drm/clients/drm_splash.c | 206 ++++++++++++++-------------
1 file changed, 110 insertions(+), 96 deletions(-)
diff --git a/drivers/gpu/drm/clients/drm_splash.c b/drivers/gpu/drm/clients/drm_splash.c
index 349f68d392e5..924bc0032d1d 100644
--- a/drivers/gpu/drm/clients/drm_splash.c
+++ b/drivers/gpu/drm/clients/drm_splash.c
@@ -25,6 +25,7 @@
#include <drm/drm_drv.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_framebuffer.h>
+#include <drm/drm_mode.h>
#include <drm/drm_plane.h>
#include <drm/drm_print.h>
@@ -128,6 +129,8 @@ struct drm_splash {
*/
s32 pos_x, pos_y;
s32 off_x, off_y;
+ /* One of DRM_MODE_ROTATE_*: turns the image, not the screen */
+ unsigned int rotation;
};
static struct drm_splash *client_to_drm_splash(struct drm_client_dev *client)
@@ -275,6 +278,28 @@ static void drm_splash_dt_placement(struct drm_splash *splash,
splash->off_x = (s32)val[0];
splash->off_y = (s32)val[1];
}
+
+ /* Degrees counter clockwise, as for panels, and as DRM counts them */
+ if (!of_property_read_u32(np, "rotation", &val[0])) {
+ switch (val[0]) {
+ case 0:
+ splash->rotation = DRM_MODE_ROTATE_0;
+ break;
+ case 90:
+ splash->rotation = DRM_MODE_ROTATE_90;
+ break;
+ case 180:
+ splash->rotation = DRM_MODE_ROTATE_180;
+ break;
+ case 270:
+ splash->rotation = DRM_MODE_ROTATE_270;
+ break;
+ default:
+ drm_warn(splash->client.dev,
+ "splash: %pOF: unsupported rotation %u",
+ np, val[0]);
+ }
+ }
}
static int drm_splash_dt_load(struct drm_splash *splash, const u8 **data,
@@ -500,73 +525,68 @@ static unsigned int drm_splash_place_axis(s32 pos, s32 off, unsigned int span,
return clamp_t(s64, coord + off, 0, last);
}
-static void drm_splash_blit_pix16(struct iosys_map *map, unsigned int dpitch,
- unsigned int x_pad, unsigned int y_pad,
- const u8 *sbuf8, unsigned int spitch,
- unsigned int width, unsigned int height,
- bool invert_y, u32 format)
-{
- unsigned int x, y, src_offset, dst_offset;
- u32 scolor, dcolor, wr_off;
-
- for (y = 0; y < height; y++) {
- src_offset = (invert_y ? (height - y - 1) : y) * spitch;
- dst_offset = (y_pad + y) * dpitch;
-
- for (x = 0; x < width; x++) {
- scolor = *(const u32 *)(&sbuf8[src_offset + 3 * x]);
- dcolor = drm_draw_color_from_xrgb8888(scolor, format);
- wr_off = dst_offset + (x_pad + x) * sizeof(u16);
-
- iosys_map_wr(map, wr_off, u16, dcolor);
- }
- }
-}
-
-static void drm_splash_blit_pix24(struct iosys_map *map, unsigned int dpitch,
- unsigned int x_pad, unsigned int y_pad,
- const u8 *sbuf8, unsigned int spitch,
- unsigned int width, unsigned int height,
- bool invert_y, u32 format)
-{
- unsigned int x, y, src_offset, dst_offset;
- u32 scolor, dcolor, wr_off;
-
- for (y = 0; y < height; y++) {
- src_offset = (invert_y ? (height - y - 1) : y) * spitch;
- dst_offset = (y_pad + y) * dpitch;
-
- for (x = 0; x < width; x++) {
- scolor = *(const u32 *)(&sbuf8[src_offset + 3 * x]);
- dcolor = drm_draw_color_from_xrgb8888(scolor, format);
- wr_off = dst_offset + (x_pad + x) * 3;
-
- iosys_map_wr(map, wr_off, u8, (dcolor & 0x000000FF) >> 0);
- iosys_map_wr(map, wr_off + 1, u8, (dcolor & 0x0000FF00) >> 8);
- iosys_map_wr(map, wr_off + 2, u8, (dcolor & 0x00FF0000) >> 16);
- }
- }
-}
-
-static void drm_splash_blit_pix32(struct iosys_map *map, unsigned int dpitch,
- unsigned int x_pad, unsigned int y_pad,
- const u8 *sbuf8, unsigned int spitch,
- unsigned int width, unsigned int height,
- bool invert_y, u32 format)
+/*
+ * Copy the BMP pixels into the buffer, converted to its format and turned by
+ * @rotation, one of DRM_MODE_ROTATE_*, which count counter clockwise. The
+ * rotation turns the image, not the screen: a quarter turn swaps how much
+ * room the image takes up, and @x_pad and @y_pad place that room on screen.
+ *
+ * Each source pixel is three bytes read on their own, since a BMP row is
+ * only padded to four bytes as a whole and the image need not be aligned.
+ */
+static void drm_splash_blit(struct iosys_map *map, unsigned int dpitch,
+ u32 format, unsigned int cpp,
+ unsigned int x_pad, unsigned int y_pad,
+ const u8 *sbuf8, unsigned int spitch,
+ unsigned int width, unsigned int height,
+ bool invert_y, unsigned int rotation)
{
- unsigned int x, y, src_offset, dst_offset;
- u32 scolor, dcolor, wr_off;
-
- for (y = 0; y < height; y++) {
- src_offset = (invert_y ? (height - y - 1) : y) * spitch;
- dst_offset = (y_pad + y) * dpitch;
+ bool quarter = rotation & (DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270);
+ unsigned int dw = quarter ? height : width;
+ unsigned int dh = quarter ? width : height;
+ unsigned int x, y, sx, sy, row, off;
+ u32 scolor, dcolor;
+
+ for (y = 0; y < dh; y++) {
+ for (x = 0; x < dw; x++) {
+ switch (rotation) {
+ case DRM_MODE_ROTATE_90:
+ sx = width - 1 - y;
+ sy = x;
+ break;
+ case DRM_MODE_ROTATE_180:
+ sx = width - 1 - x;
+ sy = height - 1 - y;
+ break;
+ case DRM_MODE_ROTATE_270:
+ sx = y;
+ sy = height - 1 - x;
+ break;
+ default:
+ sx = x;
+ sy = y;
+ break;
+ }
- for (x = 0; x < width; x++) {
- scolor = *(const u32 *)(&sbuf8[src_offset + 3 * x]);
+ /* A positive BMP height stores the rows bottom up */
+ row = invert_y ? height - 1 - sy : sy;
+ scolor = get_unaligned_le24(&sbuf8[row * spitch + 3 * sx]);
dcolor = drm_draw_color_from_xrgb8888(scolor, format);
- wr_off = dst_offset + (x_pad + x) * sizeof(u32);
+ off = (y_pad + y) * dpitch + (x_pad + x) * cpp;
- iosys_map_wr(map, wr_off, u32, dcolor);
+ switch (cpp) {
+ case 2:
+ iosys_map_wr(map, off, u16, dcolor);
+ break;
+ case 3:
+ iosys_map_wr(map, off, u8, dcolor & 0xff);
+ iosys_map_wr(map, off + 1, u8, (dcolor >> 8) & 0xff);
+ iosys_map_wr(map, off + 2, u8, (dcolor >> 16) & 0xff);
+ break;
+ case 4:
+ iosys_map_wr(map, off, u32, dcolor);
+ break;
+ }
}
}
}
@@ -605,7 +625,7 @@ static int drm_splash_bmp_to_scanout(struct drm_splash *splash,
bool bmp_invert_y;
u32 bitmap_offset;
size_t row_len, pixels_len, end;
- unsigned int x_pad, y_pad;
+ unsigned int x_pad, y_pad, img_w, img_h;
const u8 *image_data;
struct iosys_map map;
struct drm_rect r;
@@ -665,7 +685,16 @@ static int drm_splash_bmp_to_scanout(struct drm_splash *splash,
}
bmp_pitch = row_len & ~(size_t)3;
- if (bmp_width > scanout->width || bmp_height > scanout->height) {
+ /* The room the image takes up on screen, once turned */
+ if (splash->rotation & (DRM_MODE_ROTATE_90 | DRM_MODE_ROTATE_270)) {
+ img_w = bmp_height;
+ img_h = bmp_width;
+ } else {
+ img_w = bmp_width;
+ img_h = bmp_height;
+ }
+
+ if (img_w > scanout->width || img_h > scanout->height) {
drm_err(client->dev, "splash: BMP image is too big for the screen");
return -EINVAL;
}
@@ -699,9 +728,9 @@ static int drm_splash_bmp_to_scanout(struct drm_splash *splash,
#endif
} else {
x_pad = drm_splash_place_axis(splash->pos_x, splash->off_x,
- scanout->width, bmp_width);
+ scanout->width, img_w);
y_pad = drm_splash_place_axis(splash->pos_y, splash->off_y,
- scanout->height, bmp_height);
+ scanout->height, img_h);
}
image_data = data + bitmap_offset;
@@ -712,40 +741,24 @@ static int drm_splash_bmp_to_scanout(struct drm_splash *splash,
return ret;
}
- r = DRM_RECT_INIT(x_pad, y_pad, bmp_width, bmp_height);
+ r = DRM_RECT_INIT(x_pad, y_pad, img_w, img_h);
- /* In case the target format is RGB888, source data can be copied to
- * the video buffer line by line, avoiding some overhead.
+ /*
+ * An unturned image going to an RGB888 buffer has the same byte order
+ * as the BMP, so it is copied a row at a time.
*/
- if (scanout->format == DRM_FORMAT_RGB888) {
+ if (scanout->format == DRM_FORMAT_RGB888 &&
+ splash->rotation == DRM_MODE_ROTATE_0) {
drm_splash_blit_rgb888(&map, fb->pitches[0], x_pad, y_pad,
image_data, bmp_pitch, bmp_width,
bmp_height, bmp_invert_y);
+ } else if (px_width >= 2 && px_width <= 4) {
+ drm_splash_blit(&map, fb->pitches[0], scanout->format, px_width,
+ x_pad, y_pad, image_data, bmp_pitch, bmp_width,
+ bmp_height, bmp_invert_y, splash->rotation);
} else {
- switch (px_width) {
- case 2:
- drm_splash_blit_pix16(&map, fb->pitches[0], x_pad,
- y_pad, image_data, bmp_pitch,
- bmp_width, bmp_height,
- bmp_invert_y, scanout->format);
- break;
- case 3:
- drm_splash_blit_pix24(&map, fb->pitches[0], x_pad,
- y_pad, image_data, bmp_pitch,
- bmp_width, bmp_height,
- bmp_invert_y, scanout->format);
- break;
- case 4:
- drm_splash_blit_pix32(&map, fb->pitches[0], x_pad,
- y_pad, image_data, bmp_pitch,
- bmp_width, bmp_height,
- bmp_invert_y, scanout->format);
- break;
- default:
- drm_warn_once(client->dev,
- "splash: can't blit with pixel width %d",
- px_width);
- }
+ drm_warn_once(client->dev, "splash: can't blit with pixel width %d",
+ px_width);
}
drm_client_buffer_vunmap_local(buffer);
@@ -1190,9 +1203,10 @@ void drm_splash_register(struct drm_device *dev,
spin_lock_init(&splash->fw_lock);
init_completion(&splash->fw_done);
- /* Centred unless the image source asks otherwise */
+ /* Centred and upright unless the image source asks otherwise */
splash->pos_x = -1;
splash->pos_y = -1;
+ splash->rotation = DRM_MODE_ROTATE_0;
if (format && format->num_planes == 1)
splash->preferred_format = format->format;
--
2.39.5
next prev parent reply other threads:[~2026-10-01 19:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 19:58 [PATCH RFC v4 00/13] Add splash DRM client Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 01/13] drm/clients: Kconfig: indent DRM_CLIENT_DEFAULT with tabs Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 02/13] efi: bgrt: export the BGRT table and image size Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 03/13] drm: client: add splash client Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 04/13] MAINTAINERS: add entry for DRM " Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 05/13] drm: docs: remove bootsplash from TODO Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 06/13] dt-bindings: display: add a boot logo node under /chosen Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 07/13] drm/client: splash: add a device tree image source Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 08/13] drm/client: splash: place the device tree image where it asks Màxim Pedraza Padilla
2026-10-01 19:58 ` Màxim Pedraza Padilla [this message]
2026-10-01 19:58 ` [PATCH RFC v4 10/13] drm/client: splash: take the background colour from the image source Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 11/13] drm/client: splash: turn the BGRT image on panels mounted turned Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 12/13] drm/client: splash: prefer what the command line asks for Màxim Pedraza Padilla
2026-10-01 19:58 ` [PATCH RFC v4 13/13] drm/client: splash: document the image sources and parameters Màxim Pedraza Padilla
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=20261001195847.141192-10-maximpedraza@gmail.com \
--to=maximpedraza@gmail.com \
--cc=airlied@gmail.com \
--cc=ardb@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=francesco@valla.it \
--cc=ilias.apalodimas@linaro.org \
--cc=javierm@redhat.com \
--cc=jfalempe@redhat.com \
--cc=krzk+dt@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-embedded@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mario.limonciello@amd.com \
--cc=mripard@kernel.org \
--cc=rdunlap@infradead.org \
--cc=robh@kernel.org \
--cc=sam@ravnborg.org \
--cc=simona@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=tzimmermann@suse.de \
/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
all inboxes | Powered by JetHome®