hw/display/sm501: Add fallbacks to pixman routines

Pixman may return false if it does not have a suitable implementation.
Add fallbacks to handle such cases.

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
Reported-by: Rene Engel <ReneEngel80@emailn.de>
Tested-by: Rene Engel <ReneEngel80@emailn.de>
Message-Id: <20ed9442a0146238254ccc340c0d1efa226c6356.1677445307.git.balaton@eik.bme.hu>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
This commit is contained in:
BALATON Zoltan 2023-02-25 22:35:28 +01:00 committed by Philippe Mathieu-Daudé
parent 8b0ce7f7c8
commit c09b5158e1
1 changed files with 52 additions and 23 deletions

View File

@ -692,7 +692,7 @@ static void sm501_2d_operation(SM501State *s)
unsigned int dst_pitch = (s->twoD_pitch >> 16) & 0x1FFF; unsigned int dst_pitch = (s->twoD_pitch >> 16) & 0x1FFF;
int crt = (s->dc_crt_control & SM501_DC_CRT_CONTROL_SEL) ? 1 : 0; int crt = (s->dc_crt_control & SM501_DC_CRT_CONTROL_SEL) ? 1 : 0;
int fb_len = get_width(s, crt) * get_height(s, crt) * get_bpp(s, crt); int fb_len = get_width(s, crt) * get_height(s, crt) * get_bpp(s, crt);
bool overlap = false; bool overlap = false, fallback = false;
if ((s->twoD_stretch >> 16) & 0xF) { if ((s->twoD_stretch >> 16) & 0xF) {
qemu_log_mask(LOG_UNIMP, "sm501: only XY addressing is supported.\n"); qemu_log_mask(LOG_UNIMP, "sm501: only XY addressing is supported.\n");
@ -835,25 +835,48 @@ static void sm501_2d_operation(SM501State *s)
if (tmp_stride * sizeof(uint32_t) * height > sizeof(tmp_buf)) { if (tmp_stride * sizeof(uint32_t) * height > sizeof(tmp_buf)) {
tmp = g_malloc(tmp_stride * sizeof(uint32_t) * height); tmp = g_malloc(tmp_stride * sizeof(uint32_t) * height);
} }
pixman_blt((uint32_t *)&s->local_mem[src_base], tmp, fallback = !pixman_blt((uint32_t *)&s->local_mem[src_base],
src_pitch * bypp / sizeof(uint32_t), tmp,
tmp_stride, 8 * bypp, 8 * bypp, src_pitch * bypp / sizeof(uint32_t),
src_x, src_y, 0, 0, width, height); tmp_stride,
pixman_blt(tmp, (uint32_t *)&s->local_mem[dst_base], 8 * bypp, 8 * bypp,
tmp_stride, src_x, src_y, 0, 0, width, height);
dst_pitch * bypp / sizeof(uint32_t), if (!fallback) {
8 * bypp, 8 * bypp, fallback = !pixman_blt(tmp,
0, 0, dst_x, dst_y, width, height); (uint32_t *)&s->local_mem[dst_base],
tmp_stride,
dst_pitch * bypp / sizeof(uint32_t),
8 * bypp, 8 * bypp,
0, 0, dst_x, dst_y, width, height);
}
if (tmp != tmp_buf) { if (tmp != tmp_buf) {
g_free(tmp); g_free(tmp);
} }
} else { } else {
pixman_blt((uint32_t *)&s->local_mem[src_base], fallback = !pixman_blt((uint32_t *)&s->local_mem[src_base],
(uint32_t *)&s->local_mem[dst_base], (uint32_t *)&s->local_mem[dst_base],
src_pitch * bypp / sizeof(uint32_t), src_pitch * bypp / sizeof(uint32_t),
dst_pitch * bypp / sizeof(uint32_t), dst_pitch * bypp / sizeof(uint32_t),
8 * bypp, 8 * bypp, 8 * bypp, 8 * bypp, src_x, src_y,
src_x, src_y, dst_x, dst_y, width, height); dst_x, dst_y, width, height);
}
if (fallback) {
uint8_t *sp = s->local_mem + src_base;
uint8_t *d = s->local_mem + dst_base;
unsigned int y, i, j;
for (y = 0; y < height; y++) {
if (overlap) { /* overlap also means rtl */
i = (dst_y + height - 1 - y) * dst_pitch;
i = (dst_x + i) * bypp;
j = (src_y + height - 1 - y) * src_pitch;
j = (src_x + j) * bypp;
memmove(&d[i], &sp[j], width * bypp);
} else {
i = (dst_x + (dst_y + y) * dst_pitch) * bypp;
j = (src_x + (src_y + y) * src_pitch) * bypp;
memcpy(&d[i], &sp[j], width * bypp);
}
}
} }
} }
break; break;
@ -868,13 +891,19 @@ static void sm501_2d_operation(SM501State *s)
color = cpu_to_le16(color); color = cpu_to_le16(color);
} }
if (width == 1 && height == 1) { if ((width == 1 && height == 1) ||
unsigned int i = (dst_x + dst_y * dst_pitch) * bypp; !pixman_fill((uint32_t *)&s->local_mem[dst_base],
stn_he_p(&s->local_mem[dst_base + i], bypp, color); dst_pitch * bypp / sizeof(uint32_t), 8 * bypp,
} else { dst_x, dst_y, width, height, color)) {
pixman_fill((uint32_t *)&s->local_mem[dst_base], /* fallback when pixman failed or we don't want to call it */
dst_pitch * bypp / sizeof(uint32_t), uint8_t *d = s->local_mem + dst_base;
8 * bypp, dst_x, dst_y, width, height, color); unsigned int x, y, i;
for (y = 0; y < height; y++, i += dst_pitch * bypp) {
i = (dst_x + (dst_y + y) * dst_pitch) * bypp;
for (x = 0; x < width; x++, i += bypp) {
stn_he_p(&d[i], bypp, color);
}
}
} }
break; break;
} }