Commit 9aa7be3a7d for qemu.org
commit 9aa7be3a7d7b834c02eb0f1750740533d36c5857
Author: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Date: Tue Mar 3 22:08:54 2026 +0900
ui/console: Unify pixman-OpenGL format mapping
console_gl_check_format() was supposed to check if the pixman format is
supported by surface_gl_create_texture(), but it missed
PIXMAN_BE_x8r8g8b8 and PIXMAN_BE_a8r8g8b8, which are properly mapped to
OpenGL formats by surface_gl_create_texture().
Fix the discrepancy of the two functions by sharing the code to map
pixman formats to OpenGL ones.
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20260303-gl-v1-1-d90f0a237a52@rsg.ci.i.u-tokyo.ac.jp>
diff --git a/ui/console-gl.c b/ui/console-gl.c
index 403fc36fbd..22e9787c41 100644
--- a/ui/console-gl.c
+++ b/ui/console-gl.c
@@ -31,19 +31,38 @@
/* ---------------------------------------------------------------------- */
-bool console_gl_check_format(DisplayChangeListener *dcl,
- pixman_format_code_t format)
+static bool map_format(pixman_format_code_t format,
+ GLenum *glformat, GLenum *gltype)
{
switch (format) {
case PIXMAN_BE_b8g8r8x8:
case PIXMAN_BE_b8g8r8a8:
+ *glformat = GL_BGRA_EXT;
+ *gltype = GL_UNSIGNED_BYTE;
+ return true;
+ case PIXMAN_BE_x8r8g8b8:
+ case PIXMAN_BE_a8r8g8b8:
+ *glformat = GL_RGBA;
+ *gltype = GL_UNSIGNED_BYTE;
+ return true;
case PIXMAN_r5g6b5:
+ *glformat = GL_RGB;
+ *gltype = GL_UNSIGNED_SHORT_5_6_5;
return true;
default:
return false;
}
}
+bool console_gl_check_format(DisplayChangeListener *dcl,
+ pixman_format_code_t format)
+{
+ GLenum glformat;
+ GLenum gltype;
+
+ return map_format(format, &glformat, &gltype);
+}
+
void surface_gl_create_texture(QemuGLShader *gls,
DisplaySurface *surface)
{
@@ -54,25 +73,7 @@ void surface_gl_create_texture(QemuGLShader *gls,
return;
}
- switch (surface_format(surface)) {
- case PIXMAN_BE_b8g8r8x8:
- case PIXMAN_BE_b8g8r8a8:
- surface->glformat = GL_BGRA_EXT;
- surface->gltype = GL_UNSIGNED_BYTE;
- break;
- case PIXMAN_BE_x8r8g8b8:
- case PIXMAN_BE_a8r8g8b8:
- surface->glformat = GL_RGBA;
- surface->gltype = GL_UNSIGNED_BYTE;
- break;
- case PIXMAN_r5g6b5:
- surface->glformat = GL_RGB;
- surface->gltype = GL_UNSIGNED_SHORT_5_6_5;
- break;
- default:
- g_assert_not_reached();
- }
-
+ assert(map_format(surface_format(surface), &surface->glformat, &surface->gltype));
glGenTextures(1, &surface->texture);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, surface->texture);