[virglrenderer-devel] [PATCH 2/2] virgl/egl: Add option to use GLES

Tomeu Vizoso tomeu.vizoso at collabora.com
Mon Jul 30 13:56:46 UTC 2018


Adds a VIRGL_RENDERER_USE_GLES flag for specifying the API to request
when creating the EGL context.

Users can enable this flag when using vtest with the VTEST_USE_GLES
environment variable.

Signed-off-by: Tomeu Vizoso <tomeu.vizoso at collabora.com>
---
 src/virgl_egl.h         |  2 +-
 src/virgl_egl_context.c | 10 ++++++++--
 src/virglrenderer.c     |  3 ++-
 src/virglrenderer.h     |  1 +
 vtest/vtest_renderer.c  |  8 ++++++++
 5 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/virgl_egl.h b/src/virgl_egl.h
index fc69757700be..9a6369e5e2c8 100644
--- a/src/virgl_egl.h
+++ b/src/virgl_egl.h
@@ -27,7 +27,7 @@
 #include "vrend_renderer.h"
 struct virgl_egl;
 
-struct virgl_egl *virgl_egl_init(int fd, bool surfaceless);
+struct virgl_egl *virgl_egl_init(int fd, bool surfaceless, bool gles);
 void virgl_egl_destroy(struct virgl_egl *ve);
 
 virgl_renderer_gl_context virgl_egl_create_context(struct virgl_egl *ve, struct virgl_gl_ctx_param *vparams);
diff --git a/src/virgl_egl_context.c b/src/virgl_egl_context.c
index 3f00e25b9cf8..bcc7878c247c 100644
--- a/src/virgl_egl_context.c
+++ b/src/virgl_egl_context.c
@@ -123,7 +123,7 @@ static bool virgl_egl_has_extension_in_string(const char *haystack, const char *
    return false;
 }
 
-struct virgl_egl *virgl_egl_init(int fd, bool surfaceless)
+struct virgl_egl *virgl_egl_init(int fd, bool surfaceless, bool gles)
 {
    static EGLint conf_att[] = {
       EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
@@ -148,6 +148,9 @@ struct virgl_egl *virgl_egl_init(int fd, bool surfaceless)
    if (!d)
       return NULL;
 
+   if (gles)
+      conf_att[3] = EGL_OPENGL_ES_BIT;
+
    if (surfaceless) {
       conf_att[1] = EGL_PBUFFER_BIT;
       d->fd = -1;
@@ -230,7 +233,10 @@ struct virgl_egl *virgl_egl_init(int fd, bool surfaceless)
       goto fail;
    }
 
-   api = EGL_OPENGL_API;
+   if (gles)
+      api = EGL_OPENGL_ES_API;
+   else
+      api = EGL_OPENGL_API;
    b = eglBindAPI(api);
    if (!b)
       goto fail;
diff --git a/src/virglrenderer.c b/src/virglrenderer.c
index e77cfce9c3e4..9a81887d9088 100644
--- a/src/virglrenderer.c
+++ b/src/virglrenderer.c
@@ -315,7 +315,8 @@ int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks
       if (cbs->version >= 2 && cbs->get_drm_fd) {
          fd = cbs->get_drm_fd(cookie);
       }
-      egl_info = virgl_egl_init(fd, flags & VIRGL_RENDERER_USE_SURFACELESS);
+      egl_info = virgl_egl_init(fd, flags & VIRGL_RENDERER_USE_SURFACELESS,
+                                    flags & VIRGL_RENDERER_USE_GLES);
       if (!egl_info)
          return -1;
       use_context = CONTEXT_EGL;
diff --git a/src/virglrenderer.h b/src/virglrenderer.h
index 0371bee6b56c..bc7cedfeaa53 100644
--- a/src/virglrenderer.h
+++ b/src/virglrenderer.h
@@ -67,6 +67,7 @@ struct virgl_renderer_callbacks {
 #define VIRGL_RENDERER_THREAD_SYNC 2
 #define VIRGL_RENDERER_USE_GLX (1 << 2)
 #define VIRGL_RENDERER_USE_SURFACELESS (1 << 3)
+#define VIRGL_RENDERER_USE_GLES (1 << 4)
 
 VIRGL_EXPORT int virgl_renderer_init(void *cookie, int flags, struct virgl_renderer_callbacks *cb);
 VIRGL_EXPORT void virgl_renderer_poll(void); /* force fences */
diff --git a/vtest/vtest_renderer.c b/vtest/vtest_renderer.c
index f6f712a3020b..8f0262a83b20 100644
--- a/vtest/vtest_renderer.c
+++ b/vtest/vtest_renderer.c
@@ -130,6 +130,14 @@ int vtest_create_renderer(int in_fd, int out_fd, uint32_t length)
         ctx |= VIRGL_RENDERER_USE_SURFACELESS;
     }
 
+    if (getenv("VTEST_USE_GLES")) {
+        if (ctx & VIRGL_RENDERER_USE_GLX) {
+            fprintf(stderr, "Cannot use GLES with GLX.\n");
+            return -1;
+        }
+        ctx |= VIRGL_RENDERER_USE_GLES;
+    }
+
     ret = virgl_renderer_init(&renderer,
                               ctx | VIRGL_RENDERER_THREAD_SYNC, &vtest_cbs);
     if (ret) {
-- 
2.17.1



More information about the virglrenderer-devel mailing list