KMS: rotate the cursor with the display
Deploy to the handset / build-and-deploy (push) Successful in 2m5s
CI / test (push) Failing after 2m48s

Only the cursor's position was rotated; the hardware cursor image and its
hotspot stayed in the panel's own orientation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Opus 5.5 committed 2026-11-29 20:53:23 -08:00
1 parent 30086562bc
commit 98a99aaa36
1 file changed
+28 -10
+28 -10
View File
@@ -269,29 +269,46 @@ static const char *ART_IBEAM[] = {
"XXXXXXX", "XooXooX", "XXXoXXX", "..XoX..", "..XoX..", "..XoX..", "..XoX..",
"..XoX..", "..XoX..", "..XoX..", "..XoX..", "XXXoXXX", "XooXooX", "XXXXXXX", NULL };
/* Draw the shape the way the output is rotated: the hardware cursor is scanned out unrotated, so
* the image turns with the frame and the hotspot turns with the image. */
static void cursor_draw(int shape) {
const char **art = ART_ARROW;
g_hotx = 0; g_hoty = 0;
if (shape == 4) { art = ART_HAND; g_hotx = 5; g_hoty = 0; }
else if (shape == 9) { art = ART_IBEAM; g_hotx = 3; g_hoty = 7; }
int hx = 0, hy = 0; /* hotspot, in art pixels */
if (shape == 4) { art = ART_HAND; hx = 5; hy = 0; }
else if (shape == 9) { art = ART_IBEAM; hx = 3; hy = 7; }
int sc = g_scale > 1 ? g_scale : 1;
if (sc > 3) sc = 3;
g_hotx *= sc;
g_hoty *= sc;
int aw = (int)strlen(art[0]), ah = 0;
while (art[ah]) ah++;
/* On a flipped axis the hotspot is its pixel's far edge, like the logical pixel it lies on
* (g_scale physical pixels wide, which cursor_apply addresses by its near edge). */
switch (g_rot) {
case 1: g_hotx = (ah - hy) * sc - g_scale; g_hoty = hx * sc; break;
case 2: g_hotx = (aw - hx) * sc - g_scale; g_hoty = (ah - hy) * sc - g_scale; break;
case 3: g_hotx = hy * sc; g_hoty = (aw - hx) * sc - g_scale; break;
default: g_hotx = hx * sc; g_hoty = hy * sc; break;
}
uint32_t *px = (uint32_t *)g_cur_buf.map;
memset(px, 0, (size_t)CUR * CUR * 4);
for (int y = 0; art[y]; y++) {
memset(px, 0, (size_t)CUR * g_cur_buf.pitch);
for (int y = 0; y < ah; y++) {
for (int x = 0; art[y][x]; x++) {
char ch = art[y][x];
if (ch != 'X' && ch != 'o') continue;
uint32_t col = ch == 'X' ? 0xFF000000u : 0xFFFFFFFFu;
int rx = x, ry = y; /* art pixel, rotated */
switch (g_rot) {
case 1: rx = ah - 1 - y; ry = x; break;
case 2: rx = aw - 1 - x; ry = ah - 1 - y; break;
case 3: rx = y; ry = aw - 1 - x; break;
default: break;
}
for (int sy = 0; sy < sc; sy++) {
int py = y * sc + sy;
int py = ry * sc + sy;
if (py >= CUR) break;
for (int sx = 0; sx < sc; sx++) {
int px_i = x * sc + sx;
int px_i = rx * sc + sx;
if (px_i >= CUR) break;
px[py * (g_cur_buf.pitch / 4) + px_i] = col;
px[py * (int)(g_cur_buf.pitch / 4) + px_i] = col;
}
}
}
@@ -670,6 +687,7 @@ int32_t mp_kms_set_rotation(int32_t rot) {
g_px = g_width / 2;
g_py = g_height / 2;
stale_add(0, 0, 1 << 16, 1 << 16);
if (g_cur_ready) cursor_draw(g_cur_shape);
cursor_apply();
fprintf(stderr, "kms: rotation %d deg -> logical %dx%d\n", g_rot * 90, g_width, g_height);
return ((g_width & 0xFFFF) << 16) | (g_height & 0xFFFF);