qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 08/18] gl: bind GL api before context creation


From: Marc-André Lureau
Subject: [Qemu-devel] [PATCH 08/18] gl: bind GL api before context creation
Date: Mon, 5 Sep 2016 02:20:29 +0400

EGL API binding is per-thread. Make sure an API is bound when creating a
context, creating one from a new thread will not fail for missing API.

virgl requires opengl, and qemu has no complete gles support so far it
seems, so take it by default.

While at it, fix indentation to please check-patch.

Signed-off-by: Marc-André Lureau <address@hidden>
---
 hw/display/virtio-gpu-3d.c |  8 ++++----
 ui/egl-context.c           | 27 ++++++++++++++++-----------
 include/ui/console.h       |  1 +
 3 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/hw/display/virtio-gpu-3d.c b/hw/display/virtio-gpu-3d.c
index 8f068b5..e7115bf 100644
--- a/hw/display/virtio-gpu-3d.c
+++ b/hw/display/virtio-gpu-3d.c
@@ -542,12 +542,12 @@ virgl_create_context(void *opaque, int scanout_idx,
 {
     VirtIOGPU *g = opaque;
     QEMUGLContext ctx;
-    QEMUGLParams qparams;
+    QEMUGLParams qparams = {
+        .major_ver = params->major_ver,
+        .minor_ver = params->minor_ver
+    };
     bool make_current = true;
 
-    qparams.major_ver = params->major_ver;
-    qparams.minor_ver = params->minor_ver;
-
     if (g->thread_ctx) {
         dpy_gl_ctx_make_current(g->scanout[scanout_idx].con, g->thread_ctx);
         make_current = false;
diff --git a/ui/egl-context.c b/ui/egl-context.c
index 3a02b68..70530fb 100644
--- a/ui/egl-context.c
+++ b/ui/egl-context.c
@@ -5,16 +5,21 @@
 QEMUGLContext qemu_egl_create_context(DisplayChangeListener *dcl,
                                       QEMUGLParams *params)
 {
-   EGLContext ctx;
-   EGLint ctx_att[] = {
-      EGL_CONTEXT_CLIENT_VERSION, params->major_ver,
-      EGL_CONTEXT_MINOR_VERSION_KHR, params->minor_ver,
-      EGL_NONE
-   };
+    EGLContext ctx;
+    EGLint ctx_att[] = {
+        EGL_CONTEXT_CLIENT_VERSION, params->major_ver,
+        EGL_CONTEXT_MINOR_VERSION_KHR, params->minor_ver,
+        EGL_NONE
+    };
+    EGLenum api = params->gles ? EGL_OPENGL_ES_API : EGL_OPENGL_API;
 
-   ctx = eglCreateContext(qemu_egl_display, qemu_egl_config,
-                          eglGetCurrentContext(), ctx_att);
-   return ctx;
+    if (!eglBindAPI(api)) {
+        return NULL;
+    }
+
+    ctx = eglCreateContext(qemu_egl_display, qemu_egl_config,
+                           eglGetCurrentContext(), ctx_att);
+    return ctx;
 }
 
 void qemu_egl_destroy_context(DisplayChangeListener *dcl, QEMUGLContext ctx)
@@ -25,8 +30,8 @@ void qemu_egl_destroy_context(DisplayChangeListener *dcl, 
QEMUGLContext ctx)
 int qemu_egl_make_context_current(DisplayChangeListener *dcl,
                                   QEMUGLContext ctx)
 {
-   return eglMakeCurrent(qemu_egl_display,
-                         EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
+    return eglMakeCurrent(qemu_egl_display,
+                          EGL_NO_SURFACE, EGL_NO_SURFACE, ctx);
 }
 
 QEMUGLContext qemu_egl_get_current_context(DisplayChangeListener *dcl)
diff --git a/include/ui/console.h b/include/ui/console.h
index a1891b7..a076b0f 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -178,6 +178,7 @@ typedef struct QEMUGLParams QEMUGLParams;
 struct QEMUGLParams {
     int major_ver;
     int minor_ver;
+    int gles;
 };
 
 typedef struct DisplayChangeListenerOps {
-- 
2.9.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]