[PATCH 1/3] ui/console: Unify pixman-OpenGL format mapping

Akihiko Odaki posted 3 patches 1 month, 1 week ago
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>
[PATCH 1/3] ui/console: Unify pixman-OpenGL format mapping
Posted by Akihiko Odaki 1 month, 1 week ago
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>
---
 ui/console-gl.c | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/ui/console-gl.c b/ui/console-gl.c
index 403fc36fbdf2..22e9787c4156 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);

-- 
2.53.0
Re: [PATCH 1/3] ui/console: Unify pixman-OpenGL format mapping
Posted by Marc-André Lureau 1 month, 1 week ago
On Tue, Mar 3, 2026 at 2:11 PM Akihiko Odaki
<odaki@rsg.ci.i.u-tokyo.ac.jp> wrote:
>
> 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>

It should be fine for dbus display as well.

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  ui/console-gl.c | 43 ++++++++++++++++++++++---------------------
>  1 file changed, 22 insertions(+), 21 deletions(-)
>
> diff --git a/ui/console-gl.c b/ui/console-gl.c
> index 403fc36fbdf2..22e9787c4156 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);
>
> --
> 2.53.0
>
>


-- 
Marc-André Lureau