Changeset
include/ui/sdl2.h |  1 +
qapi/ui.json      | 20 +++++++++++++++++++-
qemu-options.hx   |  2 +-
ui/sdl2-gl.c      | 19 +++++++++++++++++--
ui/sdl2.c         | 10 +++++-----
vl.c              | 14 +++++++++-----
6 files changed, 52 insertions(+), 14 deletions(-)
Git apply log
Switched to a new branch '20180413135842.21325-1-tournier.elie@gmail.com'
Applying: qapi: Parameter gl of DisplayType now accept an enum
Applying: sdl: Move DisplayOptions global to sdl2_console
Applying: sdl: Allow OpenGL ES context creation
To https://github.com/patchew-project/qemu
 * [new tag]         patchew/20180413135842.21325-1-tournier.elie@gmail.com -> patchew/20180413135842.21325-1-tournier.elie@gmail.com
Test failed: checkpatch

loading

Test passed: docker-mingw@fedora

loading

Test passed: docker-build@min-glib

loading

Test passed: s390x

loading

[Qemu-devel] [PATCH v3 0/3] Use SDL to create an OpenGL ES context for virglrenderer.
Posted by Elie Tournier, 13 weeks ago
Hi,

v2: Rebase on top of master
v3: Fix the json format (Eric Blake)
    Move DisplayOptions from ui/sdl2.c to include/ui/sdl2.h (Gerd Hoffmann)
    Fix a comparison issue (Gerd Hoffmann)

Currently, virglrenderer [1] support OpenGL ES 2.0 on the guest side
and OpenGL ES 3.0 on the host side.
Thanks to this work, we are able to run QEMU on system that only support OpenGL ES.

The support of OpenGL ES 3.0 on the guest is limited.
We are working on it, so stay tune!
For the most curious of you, the development branch is available on
our gitlab instance [2].

In order to use this feature in QEMU, we need to create an OpenGL ES context.
This is possible thanks to the following option `-display sdl,gl=es`.

Have a nice day,
Elie

[1] https://cgit.freedesktop.org/virglrenderer
[2] https://gitlab.collabora.com/virgl-es/virglrenderer-gles/tree/hacks

Elie Tournier (3):
  qapi: Parameter gl of DisplayType now accept an enum
  sdl: Move DisplayOptions global to sdl2_console
  sdl: Allow OpenGL ES context creation

 include/ui/sdl2.h |  1 +
 qapi/ui.json      | 20 +++++++++++++++++++-
 qemu-options.hx   |  2 +-
 ui/sdl2-gl.c      | 19 +++++++++++++++++--
 ui/sdl2.c         | 10 +++++-----
 vl.c              | 14 +++++++++-----
 6 files changed, 52 insertions(+), 14 deletions(-)

-- 
2.17.0


Re: [Qemu-devel] [PATCH v3 0/3] Use SDL to create an OpenGL ES context for virglrenderer.
Posted by Elie Tournier, 12 weeks ago
On Fri, Apr 13, 2018 at 02:58:39PM +0100, Elie Tournier wrote:
> Hi,
> 
Hello,

Humble ping.
This series is unreviewed.

BR,
Elie

> v2: Rebase on top of master
> v3: Fix the json format (Eric Blake)
>     Move DisplayOptions from ui/sdl2.c to include/ui/sdl2.h (Gerd Hoffmann)
>     Fix a comparison issue (Gerd Hoffmann)
> 
> Currently, virglrenderer [1] support OpenGL ES 2.0 on the guest side
> and OpenGL ES 3.0 on the host side.
> Thanks to this work, we are able to run QEMU on system that only support OpenGL ES.
> 
> The support of OpenGL ES 3.0 on the guest is limited.
> We are working on it, so stay tune!
> For the most curious of you, the development branch is available on
> our gitlab instance [2].
> 
> In order to use this feature in QEMU, we need to create an OpenGL ES context.
> This is possible thanks to the following option `-display sdl,gl=es`.
> 
> Have a nice day,
> Elie
> 
> [1] https://cgit.freedesktop.org/virglrenderer
> [2] https://gitlab.collabora.com/virgl-es/virglrenderer-gles/tree/hacks
> 
> Elie Tournier (3):
>   qapi: Parameter gl of DisplayType now accept an enum
>   sdl: Move DisplayOptions global to sdl2_console
>   sdl: Allow OpenGL ES context creation
> 
>  include/ui/sdl2.h |  1 +
>  qapi/ui.json      | 20 +++++++++++++++++++-
>  qemu-options.hx   |  2 +-
>  ui/sdl2-gl.c      | 19 +++++++++++++++++--
>  ui/sdl2.c         | 10 +++++-----
>  vl.c              | 14 +++++++++-----
>  6 files changed, 52 insertions(+), 14 deletions(-)
> 
> -- 
> 2.17.0
> 

Re: [Qemu-devel] [PATCH v3 0/3] Use SDL to create an OpenGL ES context for virglrenderer.
Posted by Gerd Hoffmann, 12 weeks ago
On Fri, Apr 20, 2018 at 10:32:53AM +0100, Elie Tournier wrote:
> On Fri, Apr 13, 2018 at 02:58:39PM +0100, Elie Tournier wrote:
> > Hi,
> > 
> Hello,
> 
> Humble ping.
> This series is unreviewed.

Looks sane.  Plan to include it in the next pull request (unless
something shows up in testing).  Waiting for 2.12 being released and
master branch opening up for new development.

cheers,
  Gerd


Re: [Qemu-devel] [PATCH v3 0/3] Use SDL to create an OpenGL ES context for virglrenderer.
Posted by Elie Tournier, 12 weeks ago
On Fri, Apr 20, 2018 at 12:44:44PM +0200, Gerd Hoffmann wrote:
> On Fri, Apr 20, 2018 at 10:32:53AM +0100, Elie Tournier wrote:
> > On Fri, Apr 13, 2018 at 02:58:39PM +0100, Elie Tournier wrote:
> > > Hi,
> > > 
> > Hello,
> > 
> > Humble ping.
> > This series is unreviewed.
> 
> Looks sane.  Plan to include it in the next pull request (unless
> something shows up in testing).  Waiting for 2.12 being released and
> master branch opening up for new development.

Nice.
Thank you very much.
> 
> cheers,
>   Gerd
> 

[Qemu-devel] [PATCH v3 1/3] qapi: Parameter gl of DisplayType now accept an enum
Posted by Elie Tournier, 13 weeks ago
v2: Rebase on top of master
v3: Fix the json format (Eric Blake)
    Fix a comparison issue (Gerd Hoffmann)

Signed-off-by: Elie Tournier <elie.tournier@collabora.com>
---
 qapi/ui.json | 20 +++++++++++++++++++-
 vl.c         | 10 +++++-----
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/qapi/ui.json b/qapi/ui.json
index 5d01ad4304..3ad7835992 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1019,6 +1019,24 @@
 { 'struct'  : 'DisplayGTK',
   'data'    : { '*grab-on-hover' : 'bool' } }
 
+ ##
+ # @DisplayGLMode:
+ #
+ # Display OpenGL mode.
+ #
+ # @off: Disable OpenGL (default).
+ # @on: Use OpenGL, pick context type automatically.
+ #      Would better be named 'auto' but is called 'on' for backward
+ #      compatibility with bool type.
+ # @core: Use OpenGL with Core (desktop) Context.
+ # @es: Use OpenGL with ES (embedded systems) Context.
+ #
+ # Since: 2.13
+ #
+ ##
+ { 'enum'    : 'DisplayGLMode',
+   'data'    : [ 'off', 'on', 'core', 'es' ] }
+
 ##
 # @DisplayType:
 #
@@ -1048,7 +1066,7 @@
   'base'    : { 'type'           : 'DisplayType',
                 '*full-screen'   : 'bool',
                 '*window-close'  : 'bool',
-                '*gl'            : 'bool' },
+                '*gl'            : 'DisplayGLMode' },
   'discriminator' : 'type',
   'data'    : { 'default'        : 'DisplayNoOpts',
                 'none'           : 'DisplayNoOpts',
diff --git a/vl.c b/vl.c
index fce1fd12d8..99284fd518 100644
--- a/vl.c
+++ b/vl.c
@@ -2142,9 +2142,9 @@ static void parse_display(const char *p)
                 opts = nextopt;
                 dpy.has_gl = true;
                 if (strstart(opts, "on", &nextopt)) {
-                    dpy.gl = true;
+                    dpy.gl = DISPLAYGL_MODE_ON;
                 } else if (strstart(opts, "off", &nextopt)) {
-                    dpy.gl = false;
+                    dpy.gl = DISPLAYGL_MODE_OFF;
                 } else {
                     goto invalid_sdl_args;
                 }
@@ -2185,9 +2185,9 @@ static void parse_display(const char *p)
                 opts = nextopt;
                 dpy.has_gl = true;
                 if (strstart(opts, "on", &nextopt)) {
-                    dpy.gl = true;
+                    dpy.gl = DISPLAYGL_MODE_ON;
                 } else if (strstart(opts, "off", &nextopt)) {
-                    dpy.gl = false;
+                    dpy.gl = DISPLAYGL_MODE_OFF;
                 } else {
                     goto invalid_gtk_args;
                 }
@@ -4343,7 +4343,7 @@ int main(int argc, char **argv, char **envp)
     qemu_display_early_init(&dpy);
     qemu_console_early_init();
 
-    if (dpy.has_gl && dpy.gl && display_opengl == 0) {
+    if (dpy.has_gl && dpy.gl != DISPLAYGL_MODE_OFF && display_opengl == 0) {
 #if defined(CONFIG_OPENGL)
         error_report("OpenGL is not supported by the display");
 #else
-- 
2.17.0


[Qemu-devel] [PATCH v3 2/3] sdl: Move DisplayOptions global to sdl2_console
Posted by Elie Tournier, 13 weeks ago
Suggested-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Elie Tournier <elie.tournier@collabora.com>
---
 include/ui/sdl2.h |  1 +
 ui/sdl2.c         | 10 +++++-----
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
index 51084e6320..f43eecdbd6 100644
--- a/include/ui/sdl2.h
+++ b/include/ui/sdl2.h
@@ -14,6 +14,7 @@
 struct sdl2_console {
     DisplayChangeListener dcl;
     DisplaySurface *surface;
+    DisplayOptions *opts;
     SDL_Texture *texture;
     SDL_Window *real_window;
     SDL_Renderer *real_renderer;
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 83b917fa37..da037248c2 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -32,7 +32,6 @@
 
 static int sdl2_num_outputs;
 static struct sdl2_console *sdl2_console;
-static DisplayOptions *opts;
 
 static SDL_Surface *guest_sprite_surface;
 static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
@@ -566,7 +565,7 @@ static void handle_windowevent(SDL_Event *ev)
         break;
     case SDL_WINDOWEVENT_CLOSE:
         if (qemu_console_is_graphic(scon->dcl.con)) {
-            if (opts->has_window_close && !opts->window_close) {
+            if (scon->opts->has_window_close && !scon->opts->window_close) {
                 allow_close = false;
             }
             if (allow_close) {
@@ -613,7 +612,7 @@ void sdl2_poll_events(struct sdl2_console *scon)
             handle_textinput(ev);
             break;
         case SDL_QUIT:
-            if (opts->has_window_close && !opts->window_close) {
+            if (scon->opts->has_window_close && !scon->opts->window_close) {
                 allow_close = false;
             }
             if (allow_close) {
@@ -770,7 +769,6 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
     SDL_SysWMinfo info;
 
     assert(o->type == DISPLAY_TYPE_SDL);
-    opts = o;
 
 #ifdef __linux__
     /* on Linux, SDL may use fbcon|directfb|svgalib when run without
@@ -806,6 +804,7 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
         return;
     }
     sdl2_console = g_new0(struct sdl2_console, sdl2_num_outputs);
+    sdl2_console->opts = o;
     for (i = 0; i < sdl2_num_outputs; i++) {
         QemuConsole *con = qemu_console_lookup_by_index(i);
         assert(con != NULL);
@@ -846,7 +845,8 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o)
         g_free(filename);
     }
 
-    if (opts->has_full_screen && opts->full_screen) {
+    if (sdl2_console->opts->has_full_screen &&
+        sdl2_console->opts->full_screen) {
         gui_fullscreen = 1;
         sdl_grab_start(0);
     }
-- 
2.17.0


[Qemu-devel] [PATCH v3 3/3] sdl: Allow OpenGL ES context creation
Posted by Elie Tournier, 13 weeks ago
Signed-off-by: Elie Tournier <elie.tournier@collabora.com>
---
 qemu-options.hx |  2 +-
 ui/sdl2-gl.c    | 19 +++++++++++++++++--
 vl.c            |  4 ++++
 3 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index ca4e412f2f..333dd1f1c8 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1240,7 +1240,7 @@ ETEXI
 
 DEF("display", HAS_ARG, QEMU_OPTION_display,
     "-display sdl[,frame=on|off][,alt_grab=on|off][,ctrl_grab=on|off]\n"
-    "            [,window_close=on|off][,gl=on|off]\n"
+    "            [,window_close=on|off][,gl=on|core|es|off]\n"
     "-display gtk[,grab_on_hover=on|off][,gl=on|off]|\n"
     "-display vnc=<display>[,<optargs>]\n"
     "-display curses\n"
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index c3683e6b65..a1200bfd20 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -140,12 +140,27 @@ QEMUGLContext sdl2_gl_create_context(DisplayChangeListener *dcl,
     SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
 
     SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
-    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
-                        SDL_GL_CONTEXT_PROFILE_CORE);
+    if (scon->opts->gl == DISPLAYGL_MODE_ON ||
+        scon->opts->gl == DISPLAYGL_MODE_CORE) {
+       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
+                           SDL_GL_CONTEXT_PROFILE_CORE);
+    } else if (scon->opts->gl == DISPLAYGL_MODE_ES) {
+       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
+                           SDL_GL_CONTEXT_PROFILE_ES);
+    }
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, params->major_ver);
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, params->minor_ver);
 
     ctx = SDL_GL_CreateContext(scon->real_window);
+
+    /* If SDL fail to create a GL context and we use the "on" flag,
+     * then try to fallback to GLES.
+     */
+    if (!ctx && scon->opts->gl == DISPLAYGL_MODE_ON) {
+       SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
+                           SDL_GL_CONTEXT_PROFILE_ES);
+       ctx = SDL_GL_CreateContext(scon->real_window);
+    }
     return (QEMUGLContext)ctx;
 }
 
diff --git a/vl.c b/vl.c
index 99284fd518..3bd3b902a0 100644
--- a/vl.c
+++ b/vl.c
@@ -2143,6 +2143,10 @@ static void parse_display(const char *p)
                 dpy.has_gl = true;
                 if (strstart(opts, "on", &nextopt)) {
                     dpy.gl = DISPLAYGL_MODE_ON;
+                } else if (strstart(opts, "core", &nextopt)) {
+                    dpy.gl = DISPLAYGL_MODE_CORE;
+                } else if (strstart(opts, "es", &nextopt)) {
+                    dpy.gl = DISPLAYGL_MODE_ES;
                 } else if (strstart(opts, "off", &nextopt)) {
                     dpy.gl = DISPLAYGL_MODE_OFF;
                 } else {
-- 
2.17.0