Selaa lähdekoodia

egl-headless: Allow to test with Mesa on macOS

Signed-off-by: Akihiko Odaki <akihiko.odaki@gmail.com>
Akihiko Odaki 4 vuotta sitten
vanhempi
commit
edba23a4d4
4 muutettua tiedostoa jossa 90 lisäystä ja 28 poistoa
  1. 1 0
      include/ui/egl-helpers.h
  2. 25 0
      ui/egl-headless.c
  3. 62 26
      ui/egl-helpers.c
  4. 2 2
      ui/meson.build

+ 1 - 0
include/ui/egl-helpers.h

@@ -51,6 +51,7 @@ void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf);
 EGLSurface qemu_egl_init_surface(EGLContext ectx, EGLNativeWindowType win);
 
 int qemu_egl_init_dpy_cocoa(DisplayGLMode mode);
+int qemu_egl_init_dpy_surfaceless(DisplayGLMode mode);
 
 #if defined(CONFIG_X11) || defined(CONFIG_GBM)
 

+ 25 - 0
ui/egl-headless.c

@@ -18,6 +18,10 @@ typedef struct egl_dpy {
     uint32_t pos_y;
 } egl_dpy;
 
+#ifndef CONFIG_GBM
+static EGLContext ctx;
+#endif
+
 /* ------------------------------------------------------------------ */
 
 static void egl_refresh(DisplayChangeListener *dcl)
@@ -41,8 +45,12 @@ static void egl_gfx_switch(DisplayChangeListener *dcl,
 static QEMUGLContext egl_create_context(void *dg,
                                         QEMUGLParams *params)
 {
+#ifdef CONFIG_GBM
     eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE,
                    qemu_egl_rn_ctx);
+#else
+    eglMakeCurrent(qemu_egl_display, EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
+#endif
     return qemu_egl_create_context(dg, params);
 }
 
@@ -98,6 +106,7 @@ static void egl_scanout_texture(void *dg,
     }
 }
 
+#ifdef CONFIG_GBM
 static void egl_scanout_dmabuf(void *dg, QemuDmaBuf *dmabuf)
 {
     egl_dmabuf_import_texture(dmabuf);
@@ -140,6 +149,7 @@ static void egl_release_dmabuf(void *dg, QemuDmaBuf *dmabuf)
 {
     egl_dmabuf_release_texture(dmabuf);
 }
+#endif
 
 static void egl_scanout_flush(DisplayChangeListener *dcl,
                               uint32_t x, uint32_t y,
@@ -176,10 +186,12 @@ static const DisplayGLOps dg_egl_ops = {
     .dpy_gl_scanout_get_enabled = egl_scanout_get_enabled,
     .dpy_gl_scanout_disable     = egl_scanout_disable,
     .dpy_gl_scanout_texture     = egl_scanout_texture,
+#ifdef CONFIG_GBM
     .dpy_gl_scanout_dmabuf      = egl_scanout_dmabuf,
     .dpy_gl_cursor_dmabuf       = egl_cursor_dmabuf,
     .dpy_gl_cursor_position     = egl_cursor_position,
     .dpy_gl_release_dmabuf      = egl_release_dmabuf,
+#endif
 };
 
 static const DisplayChangeListenerOps dcl_egl_ops = {
@@ -203,10 +215,23 @@ static void egl_headless_init(DisplayState *ds, DisplayOptions *opts)
     egl_dpy *edpy;
     int idx;
 
+#ifdef CONFIG_GBM
     if (egl_rendernode_init(opts->u.egl_headless.rendernode, mode) < 0) {
         error_report("egl: render node init failed");
         exit(1);
     }
+#else
+    if (qemu_egl_init_dpy_surfaceless(mode)) {
+        error_report("egl: display init failed");
+        exit(1);
+    }
+
+    ctx = qemu_egl_init_ctx();
+    if (!ctx) {
+        error_report("egl: egl_init_ctx failed");
+        exit(1);
+    }
+#endif
 
     register_displayglops(&dg_egl_ops);
 

+ 62 - 26
ui/egl-helpers.c

@@ -316,6 +316,31 @@ EGLSurface qemu_egl_init_surface(EGLContext ectx, EGLNativeWindowType win)
 /* ---------------------------------------------------------------------- */
 
 static int qemu_egl_init_dpy(EGLDisplay dpy, DisplayGLMode mode)
+{
+    EGLint major, minor;
+    EGLBoolean b;
+    bool gles = (mode == DISPLAYGL_MODE_ES);
+
+    qemu_egl_display = dpy;
+
+    b = eglInitialize(qemu_egl_display, &major, &minor);
+    if (b == EGL_FALSE) {
+        error_report("egl: eglInitialize failed");
+        return -1;
+    }
+
+    b = eglBindAPI(gles ?  EGL_OPENGL_ES_API : EGL_OPENGL_API);
+    if (b == EGL_FALSE) {
+        error_report("egl: eglBindAPI failed (%s mode)",
+                     gles ? "gles" : "core");
+        return -1;
+    }
+
+    qemu_egl_mode = gles ? DISPLAYGL_MODE_ES : DISPLAYGL_MODE_CORE;
+    return 0;
+}
+
+static int qemu_egl_config_dpy()
 {
     static const EGLint conf_att_core[] = {
         EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
@@ -335,25 +360,9 @@ static int qemu_egl_init_dpy(EGLDisplay dpy, DisplayGLMode mode)
         EGL_ALPHA_SIZE, 0,
         EGL_NONE,
     };
-    EGLint major, minor;
     EGLBoolean b;
     EGLint n;
-    bool gles = (mode == DISPLAYGL_MODE_ES);
-
-    qemu_egl_display = dpy;
-
-    b = eglInitialize(qemu_egl_display, &major, &minor);
-    if (b == EGL_FALSE) {
-        error_report("egl: eglInitialize failed");
-        return -1;
-    }
-
-    b = eglBindAPI(gles ?  EGL_OPENGL_ES_API : EGL_OPENGL_API);
-    if (b == EGL_FALSE) {
-        error_report("egl: eglBindAPI failed (%s mode)",
-                     gles ? "gles" : "core");
-        return -1;
-    }
+    bool gles = (qemu_egl_mode == DISPLAYGL_MODE_ES);
 
     b = eglChooseConfig(qemu_egl_display,
                         gles ? conf_att_gles : conf_att_core,
@@ -364,22 +373,26 @@ static int qemu_egl_init_dpy(EGLDisplay dpy, DisplayGLMode mode)
         return -1;
     }
 
-    qemu_egl_mode = gles ? DISPLAYGL_MODE_ES : DISPLAYGL_MODE_CORE;
     return 0;
 }
 
 int qemu_egl_init_dpy_cocoa(DisplayGLMode mode)
 {
+    int result;
+
     EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
     if (dpy == EGL_NO_DISPLAY) {
         error_report("egl: eglGetDisplay failed");
         return -1;
     }
 
-    return qemu_egl_init_dpy(dpy, mode);
-}
+    result = qemu_egl_init_dpy(dpy, mode);
+    if (!result) {
+        result = qemu_egl_config_dpy();
+    }
 
-#if defined(CONFIG_X11) || defined(CONFIG_GBM)
+    return result;
+}
 
 /*
  * Taken from glamor_egl.h from the Xorg xserver, which is MIT licensed
@@ -409,7 +422,7 @@ int qemu_egl_init_dpy_cocoa(DisplayGLMode mode)
  * platform extensions (EGL_KHR_platform_gbm and friends) yet it doesn't seem
  * like mesa will be able to advertise these (even though it can do EGL 1.5).
  */
-static int qemu_egl_init_dpy_platform(EGLNativeDisplayType native,
+static int qemu_egl_init_dpy_platform(void *native,
                                       EGLenum platform,
                                       DisplayGLMode mode)
 {
@@ -424,10 +437,12 @@ static int qemu_egl_init_dpy_platform(EGLNativeDisplayType native,
         }
     }
 
+#if defined(CONFIG_X11) || defined(CONFIG_GBM)
     if (dpy == EGL_NO_DISPLAY) {
         /* fallback */
         dpy = eglGetDisplay(native);
     }
+#endif
 
     if (dpy == EGL_NO_DISPLAY) {
         error_report("egl: eglGetDisplay failed");
@@ -437,22 +452,43 @@ static int qemu_egl_init_dpy_platform(EGLNativeDisplayType native,
     return qemu_egl_init_dpy(dpy, mode);
 }
 
+int qemu_egl_init_dpy_surfaceless(DisplayGLMode mode)
+{
+    return qemu_egl_init_dpy_platform(NULL, EGL_PLATFORM_SURFACELESS_MESA, mode);
+}
+
+#if defined(CONFIG_X11) || defined(CONFIG_GBM)
+
 int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy, DisplayGLMode mode)
 {
+    int result;
+
 #ifdef EGL_KHR_platform_x11
-    return qemu_egl_init_dpy_platform(dpy, EGL_PLATFORM_X11_KHR, mode);
+    result = qemu_egl_init_dpy_platform(dpy, EGL_PLATFORM_X11_KHR, mode);
 #else
-    return qemu_egl_init_dpy_platform(dpy, 0, mode);
+    result = qemu_egl_init_dpy_platform(dpy, 0, mode);
 #endif
+    if (!result) {
+        result = qemu_egl_config_dpy();
+    }
+
+    return result;
 }
 
 int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, DisplayGLMode mode)
 {
+    int result;
+
 #ifdef EGL_MESA_platform_gbm
-    return qemu_egl_init_dpy_platform(dpy, EGL_PLATFORM_GBM_MESA, mode);
+    result = qemu_egl_init_dpy_platform(dpy, EGL_PLATFORM_GBM_MESA, mode);
 #else
-    return qemu_egl_init_dpy_platform(dpy, 0, mode);
+    result = qemu_egl_init_dpy_platform(dpy, 0, mode);
 #endif
+    if (!result) {
+        result = qemu_egl_config_dpy();
+    }
+
+    return result;
 }
 
 #endif

+ 2 - 2
ui/meson.build

@@ -59,9 +59,9 @@ if config_host.has_key('CONFIG_OPENGL')
   ui_modules += {'opengl' : opengl_ss}
 endif
 
-if config_host.has_key('CONFIG_OPENGL') and gbm.found()
+if config_host.has_key('CONFIG_OPENGL')
   egl_headless_ss = ss.source_set()
-  egl_headless_ss.add(when: [opengl, gbm, pixman, 'CONFIG_OPENGL', 'CONFIG_EGL'],
+  egl_headless_ss.add(when: [opengl, pixman, 'CONFIG_OPENGL', 'CONFIG_EGL'],
                       if_true: files('egl-headless.c'))
   ui_modules += {'egl-headless' : egl_headless_ss}
 endif