@samitouri / QOSamiQemu / commits / 9aa7be3a7d

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>

Akihiko Odaki committed Mar 3, 2026 at 22:08 UTC 9aa7be3a7d7b834c02eb0f1750740533d36c5857
1 file changed +22 -21
ui/console-gl.c
+22 -21
@@ -31,19 +31,38 @@
31
32 /* ---------------------------------------------------------------------- */
33
34 -bool console_gl_check_format(DisplayChangeListener *dcl,
35 - pixman_format_code_t format)
34 +static bool map_format(pixman_format_code_t format,
35 + GLenum *glformat, GLenum *gltype)
36 {
37 switch (format) {
38 case PIXMAN_BE_b8g8r8x8:
39 case PIXMAN_BE_b8g8r8a8:
40 + *glformat = GL_BGRA_EXT;
41 + *gltype = GL_UNSIGNED_BYTE;
42 + return true;
43 + case PIXMAN_BE_x8r8g8b8:
44 + case PIXMAN_BE_a8r8g8b8:
45 + *glformat = GL_RGBA;
46 + *gltype = GL_UNSIGNED_BYTE;
47 + return true;
48 case PIXMAN_r5g6b5:
49 + *glformat = GL_RGB;
50 + *gltype = GL_UNSIGNED_SHORT_5_6_5;
51 return true;
52 default:
53 return false;
54 }
55 }
56
57 +bool console_gl_check_format(DisplayChangeListener *dcl,
58 + pixman_format_code_t format)
59 +{
60 + GLenum glformat;
61 + GLenum gltype;
62 +
63 + return map_format(format, &glformat, &gltype);
64 +}
65 +
66 void surface_gl_create_texture(QemuGLShader *gls,
67 DisplaySurface *surface)
68 {
@@ -54,25 +73,7 @@ void surface_gl_create_texture(QemuGLShader *gls,
73 return;
74 }
75
57 - switch (surface_format(surface)) {
58 - case PIXMAN_BE_b8g8r8x8:
59 - case PIXMAN_BE_b8g8r8a8:
60 - surface->glformat = GL_BGRA_EXT;
61 - surface->gltype = GL_UNSIGNED_BYTE;
62 - break;
63 - case PIXMAN_BE_x8r8g8b8:
64 - case PIXMAN_BE_a8r8g8b8:
65 - surface->glformat = GL_RGBA;
66 - surface->gltype = GL_UNSIGNED_BYTE;
67 - break;
68 - case PIXMAN_r5g6b5:
69 - surface->glformat = GL_RGB;
70 - surface->gltype = GL_UNSIGNED_SHORT_5_6_5;
71 - break;
72 - default:
73 - g_assert_not_reached();
74 - }
75 -
76 + assert(map_format(surface_format(surface), &surface->glformat, &surface->gltype));
77 glGenTextures(1, &surface->texture);
78 glEnable(GL_TEXTURE_2D);
79 glBindTexture(GL_TEXTURE_2D, surface->texture);