Re: [Qemu-devel] [PATCH v3 0/3] Use SDL to create an OpenGL ES context for virglrenderer.

2018-04-20 Thread Elie Tournier
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
> 



Re: [Qemu-devel] [PATCH v3 0/3] Use SDL to create an OpenGL ES context for virglrenderer.

2018-04-20 Thread Elie Tournier
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
> 



[Qemu-devel] [PATCH v3 1/3] qapi: Parameter gl of DisplayType now accept an enum

2018-04-13 Thread Elie Tournier
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.tourn...@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", )) {
-dpy.gl = true;
+dpy.gl = DISPLAYGL_MODE_ON;
 } else if (strstart(opts, "off", )) {
-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", )) {
-dpy.gl = true;
+dpy.gl = DISPLAYGL_MODE_ON;
 } else if (strstart(opts, "off", )) {
-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();
 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 0/3] Use SDL to create an OpenGL ES context for virglrenderer.

2018-04-13 Thread Elie Tournier
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




[Qemu-devel] [PATCH v3 3/3] sdl: Allow OpenGL ES context creation

2018-04-13 Thread Elie Tournier
Signed-off-by: Elie Tournier <elie.tourn...@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=[,]\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", )) {
 dpy.gl = DISPLAYGL_MODE_ON;
+} else if (strstart(opts, "core", )) {
+dpy.gl = DISPLAYGL_MODE_CORE;
+} else if (strstart(opts, "es", )) {
+dpy.gl = DISPLAYGL_MODE_ES;
 } else if (strstart(opts, "off", )) {
 dpy.gl = DISPLAYGL_MODE_OFF;
 } else {
-- 
2.17.0




[Qemu-devel] [PATCH v3 2/3] sdl: Move DisplayOptions global to sdl2_console

2018-04-13 Thread Elie Tournier
Suggested-by: Gerd Hoffmann <kra...@redhat.com>
Signed-off-by: Elie Tournier <elie.tourn...@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




Re: [Qemu-devel] [PATCH v2 1/2 for-2.12?] qapi: Parameter gl of DisplayType now accept an enum

2018-04-13 Thread Elie Tournier
On Fri, Apr 13, 2018 at 08:15:29AM +0200, Gerd Hoffmann wrote:
> On Thu, Apr 12, 2018 at 03:11:53PM +0100, Elie Tournier wrote:
> > Hello,
> > 
> > On Tue, Apr 10, 2018 at 03:33:35PM +0200, Gerd Hoffmann wrote:
> > > > # @off: Disable OpenGL (default).
> > 
> > Just to be sure, I have to add @ in front of all parameter, right?
> > 
> > > > 
> > > > > + # 'on'Use OpenGL, pick context type automatically.
> > > > > + # Would better be named 'auto' but is called 'on' for 
> > > > > backward
> > > > > + # compatibility with bool type.
> > > > 
> > > > See below...
> > > 
> > > > DisplayOptions was added in 2.12.  This is a backwards-incompatible
> > > > change in QMP (you CANNOT change 'bool' to 'DisplayGLMode' across
> > > > releases, because the on-the-wire representation differs; pre-patch it
> > > > would be "gl":true, post-patch it is "gl":"on").  So if it affects QMP,
> > > > and we want it, this patch either HAS to go in 2.12, or we have to have
> > > > more finesse (perhaps by using an 'alternate' type in the QAPI) so that
> > > > it remains backwards-compatible.
> > > > 
> > > > /me goes and looks at introspection output...
> > > > 
> > > > You may be in luck - there is no instance of 'window-close' in the
> > > > introspection output, which means 'DisplayType' exists only for ease of
> > > > command-line parsing and is not currently used by QMP, so tweaks here
> > > > are not affecting the command line.
> > > 
> > > Yes, right now the struct is only used to store the parsed command line
> > > opts, so no effect on QMP.
> > > 
> > > Plan for the future is to also parse command line options with generic
> > > qapi/json code instead of the home-grown parser, but that switch didn't
> > > happen yet.
> > > 
> > > > That said, you can STILL name the enum value something smarter than 'on'
> > > > IF you make the change now, for 2.12, given that the QAPI type was only
> > > > introduced in 2.12 (you only have to worry about backwards compatibility
> > > > if 2.11 already parsed gl=on).
> > > 
> > > gl=on is older, so that must continue to work.  Making both "on" and
> > > "auto" work isn't a problem for our home-grown parser (aka
> > > parse_display() in vl.c).  But having quirks like this makes the switch
> > > to generic parser code more difficuilt, so I'd prefer to avoid that ...
> > 
> > Is it possible to upstream this change before 2.12 release?
> 
> No need to hurry with this.  QMP doesn't see the structs, so no
> compatibility problem here.  gl=on cmd line option was present in 2.11 +
> older already, so that must continue to work no matter whenever this
> makes 2.12 or not.

Alright, thanks.
Well, to be fair, I just want to see this feature upstream, I don't really care
about the release number.

Just a question before I resend the series.
Should I note "Since 2.12" or "Since 2.13" in qapi/ui.json?

BR,
Elie

> 
> cheers,
>   Gerd
> 



Re: [Qemu-devel] [PATCH v2 1/2 for-2.12?] qapi: Parameter gl of DisplayType now accept an enum

2018-04-12 Thread Elie Tournier
Hello,

On Tue, Apr 10, 2018 at 03:33:35PM +0200, Gerd Hoffmann wrote:
> > # @off: Disable OpenGL (default).

Just to be sure, I have to add @ in front of all parameter, right?

> > 
> > > + # 'on'Use OpenGL, pick context type automatically.
> > > + # Would better be named 'auto' but is called 'on' for backward
> > > + # compatibility with bool type.
> > 
> > See below...
> 
> > DisplayOptions was added in 2.12.  This is a backwards-incompatible
> > change in QMP (you CANNOT change 'bool' to 'DisplayGLMode' across
> > releases, because the on-the-wire representation differs; pre-patch it
> > would be "gl":true, post-patch it is "gl":"on").  So if it affects QMP,
> > and we want it, this patch either HAS to go in 2.12, or we have to have
> > more finesse (perhaps by using an 'alternate' type in the QAPI) so that
> > it remains backwards-compatible.
> > 
> > /me goes and looks at introspection output...
> > 
> > You may be in luck - there is no instance of 'window-close' in the
> > introspection output, which means 'DisplayType' exists only for ease of
> > command-line parsing and is not currently used by QMP, so tweaks here
> > are not affecting the command line.
> 
> Yes, right now the struct is only used to store the parsed command line
> opts, so no effect on QMP.
> 
> Plan for the future is to also parse command line options with generic
> qapi/json code instead of the home-grown parser, but that switch didn't
> happen yet.
> 
> > That said, you can STILL name the enum value something smarter than 'on'
> > IF you make the change now, for 2.12, given that the QAPI type was only
> > introduced in 2.12 (you only have to worry about backwards compatibility
> > if 2.11 already parsed gl=on).
> 
> gl=on is older, so that must continue to work.  Making both "on" and
> "auto" work isn't a problem for our home-grown parser (aka
> parse_display() in vl.c).  But having quirks like this makes the switch
> to generic parser code more difficuilt, so I'd prefer to avoid that ...

Is it possible to upstream this change before 2.12 release?

> 
> cheers,
>   Gerd
> 



Re: [Qemu-devel] [PATCH v2 1/2 for-2.12?] qapi: Parameter gl of DisplayType now accept an enum

2018-04-10 Thread Elie Tournier
On Tue, Apr 10, 2018 at 08:13:00AM -0500, Eric Blake wrote:
> On 04/10/2018 07:02 AM, Elie Tournier wrote:
> > Signed-off-by: Elie Tournier <elie.tourn...@collabora.com>
> > ---
> >  qapi/ui.json | 21 -
> >  vl.c | 10 +-
> >  2 files changed, 25 insertions(+), 6 deletions(-)
> > 
> > diff --git a/qapi/ui.json b/qapi/ui.json
> > index 5d01ad4304..c8005867e5 100644
> > --- a/qapi/ui.json
> > +++ b/qapi/ui.json
> > @@ -1019,6 +1019,25 @@
> >  { 'struct'  : 'DisplayGTK',
> >'data': { '*grab-on-hover' : 'bool' } }
> >  
> > + ##
> > + # @DisplayGLMode:
> > + #
> > + # Display OpenGL mode.
> > + #
> > + # 'off'   Disable OpenGL (default).
> 
> Wrong format; this should be:
> 
> # @off: Disable OpenGL (default).

Fix locally
> 
> > + # 'on'Use OpenGL, pick context type automatically.
> > + # Would better be named 'auto' but is called 'on' for backward
> > + # compatibility with bool type.
> 
> See below...
> 
> > + # '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 +1067,7 @@
> >'base': { 'type'   : 'DisplayType',
> >  '*full-screen'   : 'bool',
> >  '*window-close'  : 'bool',
> > -'*gl': 'bool' },
> > +'*gl': 'DisplayGLMode' },
> 
> DisplayOptions was added in 2.12.  This is a backwards-incompatible
> change in QMP (you CANNOT change 'bool' to 'DisplayGLMode' across
> releases, because the on-the-wire representation differs; pre-patch it
> would be "gl":true, post-patch it is "gl":"on").  So if it affects QMP,
> and we want it, this patch either HAS to go in 2.12, or we have to have
> more finesse (perhaps by using an 'alternate' type in the QAPI) so that
> it remains backwards-compatible.
> 
> /me goes and looks at introspection output...
> 
> You may be in luck - there is no instance of 'window-close' in the
> introspection output, which means 'DisplayType' exists only for ease of
> command-line parsing and is not currently used by QMP, so tweaks here
> are not affecting the command line.
> 
> That said, you can STILL name the enum value something smarter than 'on'
> IF you make the change now, for 2.12, given that the QAPI type was only
> introduced in 2.12 (you only have to worry about backwards compatibility
> if 2.11 already parsed gl=on).

It sounds like making the change now is the best option.
So, is 'auto' a better choice than 'on' in the enum?
> 
> -- 
> Eric Blake, Principal Software Engineer
> Red Hat, Inc.   +1-919-301-3266
> Virtualization:  qemu.org | libvirt.org
> 






[Qemu-devel] [PATCH v2 2/2] sdl: Allow OpenGL ES context creation

2018-04-10 Thread Elie Tournier
Signed-off-by: Elie Tournier <elie.tourn...@collabora.com>
---
 include/ui/sdl2.h |  1 +
 qemu-options.hx   |  2 +-
 ui/sdl2-gl.c  | 17 +++--
 ui/sdl2.c |  1 +
 vl.c  |  4 
 5 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
index 51084e6320..8495795e48 100644
--- a/include/ui/sdl2.h
+++ b/include/ui/sdl2.h
@@ -22,6 +22,7 @@ struct sdl2_console {
 int x, y, w, h;
 int hidden;
 int opengl;
+DisplayGLMode gl_mode;
 int updates;
 int idle_counter;
 int ignore_hotkeys;
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=[,]\n"
 "-display curses\n"
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index c3683e6b65..4755314afe 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -140,12 +140,25 @@ 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->gl_mode ==  DISPLAYGL_MODE_ON || scon->gl_mode == 
DISPLAYGL_MODE_CORE)
+   SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
+   SDL_GL_CONTEXT_PROFILE_CORE);
+else if (scon->gl_mode == 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->gl_mode == 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/ui/sdl2.c b/ui/sdl2.c
index 83b917fa37..29bf8e36ad 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -815,6 +815,7 @@ static void sdl2_display_init(DisplayState *ds, 
DisplayOptions *o)
 sdl2_console[i].idx = i;
 #ifdef CONFIG_OPENGL
 sdl2_console[i].opengl = display_opengl;
+sdl2_console[i].gl_mode = o->gl;
 sdl2_console[i].dcl.ops = display_opengl ? _gl_ops : _2d_ops;
 #else
 sdl2_console[i].opengl = 0;
diff --git a/vl.c b/vl.c
index 7809a15caf..5694c23742 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", )) {
 dpy.gl = DISPLAYGL_MODE_ON;
+} else if (strstart(opts, "core", )) {
+dpy.gl = DISPLAYGL_MODE_CORE;
+} else if (strstart(opts, "es", )) {
+dpy.gl = DISPLAYGL_MODE_ES;
 } else if (strstart(opts, "off", )) {
 dpy.gl = DISPLAYGL_MODE_OFF;
 } else {
-- 
2.17.0




[Qemu-devel] [PATCH v2 1/2] qapi: Parameter gl of DisplayType now accept an enum

2018-04-10 Thread Elie Tournier
Signed-off-by: Elie Tournier <elie.tourn...@collabora.com>
---
 qapi/ui.json | 21 -
 vl.c | 10 +-
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/qapi/ui.json b/qapi/ui.json
index 5d01ad4304..c8005867e5 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1019,6 +1019,25 @@
 { '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 +1067,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..7809a15caf 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", )) {
-dpy.gl = true;
+dpy.gl = DISPLAYGL_MODE_ON;
 } else if (strstart(opts, "off", )) {
-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", )) {
-dpy.gl = true;
+dpy.gl = DISPLAYGL_MODE_ON;
 } else if (strstart(opts, "off", )) {
-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();
 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 v2 0/2] Use SDL to create an OpenGL ES context for virglrenderer.

2018-04-10 Thread Elie Tournier
Hello everyone,

I submitted the v1 of this series before kraxel's display system rework.

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 (2):
  qapi: Parameter gl of DisplayType now accept an enum
  sdl: Allow OpenGL ES context creation

 include/ui/sdl2.h |  1 +
 qapi/ui.json  | 21 -
 qemu-options.hx   |  2 +-
 ui/sdl2-gl.c  | 17 +++--
 ui/sdl2.c |  1 +
 vl.c  | 14 +-
 6 files changed, 47 insertions(+), 9 deletions(-)

-- 
2.17.0




[Qemu-devel] [PATCH] sdl2: Remove unused epoxy include

2018-04-04 Thread Elie Tournier
Signed-off-by: Elie Tournier <elie.tourn...@collabora.com>
---
Can someone push this patch for me please.
I don't have commit access.

 ui/sdl2-gl.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index 5e1073a084..c3683e6b65 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -32,8 +32,6 @@
 #include "ui/sdl2.h"
 #include "sysemu/sysemu.h"
 
-#include 
-
 static void sdl2_set_scanout_mode(struct sdl2_console *scon, bool scanout)
 {
 if (scon->scanout_mode == scanout) {
-- 
2.16.3




Re: [Qemu-devel] [RFC 0/2] Use SDL to create an OpenGL ES context for virglrenderer.

2018-01-30 Thread Elie Tournier
On Tue, Jan 30, 2018 at 04:22:33PM +0100, Gerd Hoffmann wrote:
>   Hi,
> 
> > > Well, display configuration is going to be rewritten, and while that is
> > > in flight adding new config options isn't a good idea b/c things will
> > > conflict ...
> > I'm wondering how extensive this rewrite is going to be. Did you plan to 
> > modify the qemu interface?
> > If someone already start working on this task, can you send me the link to 
> > the repository?
> > I will be happy to help if needed.
> 
> https://www.kraxel.org/cgit/qemu/log/?h=sirius/display-cmdline
Awesome, thanks. I will definitely have a look to it.
> 
> > > Beside that:  Is a new config option actually needed in the first place?
> > > 
> > > Ideally qemu (or sdl) would figure on its own that a full core context
> > > isn't available and try fallback to gles then.
> > I'm fine with this idea.
> > However, I think we still need to add a way to the user to choose the 
> > backend he want.
> 
> Changing gl from bool to multiple choice looks more useful to me then,
> i.e. have "gl={on,core,gles,off}", where "on" automatically picks "core"
> or "gles" depending on what is available.
I like that solution. ;). I will implement it on top of your work.
> 
> What is the status of the virglrenderer patches btw?
We keep upstreaming no invasive patches.
But with upstream virglrenderer, you will not be able to use a gles backend.
If you want to know more about the current status of the project, you can have 
a look to our repo [1].

Currently, we are working through bugs, cleaning up the remaing patches.
Our short term goal is to pass the GLES2 CTS [2] in the guest side.

Regards,
Elie

[1] https://gitlab.collabora.com/jakob/virglrenderer-gles/tree/hacks
[2] https://github.com/KhronosGroup/VK-GL-CTS
> 
> cheers,
>   Gerd
> 



Re: [Qemu-devel] [RFC 0/2] Use SDL to create an OpenGL ES context for virglrenderer.

2018-01-30 Thread Elie Tournier
On Mon, Jan 29, 2018 at 07:08:30PM +0100, Gerd Hoffmann wrote:
Hello,

First, thanks for your reply.
I added some comments and questions below.

Cheers,
Elie

>   Hi,
> 
> > > In order to use this feature, we need to create a gles context.
> > > This series add an option (`-display sdl,gles=on`) in the SDL display to 
> > > create that context.
> > 
> > Humble ping.
> > I didn't get any comment on this series.
> 
> Well, display configuration is going to be rewritten, and while that is
> in flight adding new config options isn't a good idea b/c things will
> conflict ...
I'm wondering how extensive this rewrite is going to be. Did you plan to modify 
the qemu interface?
If someone already start working on this task, can you send me the link to the 
repository?
I will be happy to help if needed.
> 
> Beside that:  Is a new config option actually needed in the first place?
> 
> Ideally qemu (or sdl) would figure on its own that a full core context
> isn't available and try fallback to gles then.
I'm fine with this idea.
However, I think we still need to add a way to the user to choose the backend 
he want.
> 
> cheers,
>   Gerd
> 



Re: [Qemu-devel] [RFC 0/2] Use SDL to create an OpenGL ES context for virglrenderer.

2018-01-29 Thread Elie Tournier
On Wed, Jan 17, 2018 at 02:50:27PM +, Elie Tournier wrote:
> Hello everyone,
> 
> At Collabora, we are working on adding an OpenGL ES backend on virglrenderer 
> [1].
> I submit these patches as an RFC because our work didn't land in 
> virglrenderer yet.
> Currently, we support OpenGL ES 2.0 on the guest side and OpenGL ES 3.0 on 
> the host side.
> Our plan is to increase the guest support to OpenGL ES 3.0.
> Thanks to this work, we are able to run QEMU on system that only support 
> OpenGL ES.
> 
> In order to use this feature, we need to create a gles context.
> This series add an option (`-display sdl,gles=on`) in the SDL display to 
> create that context.
> 
> The source code is available on our gitlab instance.
> For virglrenderer [2] and qemu [3].
> 
> Feel free to review/comment the series.

Hello,

Humble ping.
I didn't get any comment on this series.
Are you interested by running QEMU on systems that only support OpenGL ES?
If yes, did I proceed correctly?

> 
> Have a nice day,
> Elie
> 
> [1] https://cgit.freedesktop.org/virglrenderer
> [2] https://gitlab.collabora.com/jakob/virglrenderer-gles/tree/hacks
> [3] https://gitlab.collabora.com/elie/qemu/tree/gles-option
> 
> Elie Tournier (2):
>   sdl2: Add gles options
>   sdl2: gles option will create a gles context
> 
>  include/sysemu/sysemu.h |  1 +
>  include/ui/sdl2.h   |  1 +
>  qemu-options.hx |  5 -
>  ui/sdl2-gl.c|  8 ++--
>  ui/sdl2.c   |  8 
>  vl.c| 12 +++-
>  6 files changed, 31 insertions(+), 4 deletions(-)
> 
> -- 
> 2.15.1
> 



[Qemu-devel] [RFC 1/2] sdl2: Add gles options

2018-01-17 Thread Elie Tournier
This commit add an option to the sdl display: `-display sdl,gles=on`
This will allow the user to create an OpenGL ES context.

Signed-off-by: Elie Tournier <elie.tourn...@collabora.com>
---
 qemu-options.hx |  5 -
 ui/sdl2.c   |  1 +
 vl.c| 11 ++-
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/qemu-options.hx b/qemu-options.hx
index 678181c599..18a616e339 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1257,7 +1257,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|off][,gles=on|off]\n"
 "-display gtk[,grab_on_hover=on|off][,gl=on|off]|\n"
 "-display vnc=[,]\n"
 "-display curses\n"
@@ -1492,6 +1492,9 @@ Enable/disable spice seamless migration. Default is off.
 @item gl=[on|off]
 Enable/disable OpenGL context. Default is off.
 
+@item gles=[on|off]
+Enable/disable OpenGL ES context. Default is off.
+
 @item rendernode=
 DRM render node for OpenGL rendering. If not specified, it will pick
 the first available. (Since 2.9)
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 89c6a2633c..e78cff1a6f 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -762,6 +762,7 @@ void sdl_display_early_init(int opengl)
 case 0:  /* off */
 break;
 case 1: /* on */
+case 2: /* gles = on */
 #ifdef CONFIG_OPENGL
 display_opengl = 1;
 #endif
diff --git a/vl.c b/vl.c
index 2586f25952..3fe325222e 100644
--- a/vl.c
+++ b/vl.c
@@ -2154,6 +2154,15 @@ static DisplayType select_display(const char *p)
 } else {
 goto invalid_sdl_args;
 }
+} else if (strstart(opts, ",gles=", )) {
+opts = nextopt;
+if (strstart(opts, "on", )) {
+request_opengl = 2;
+} else if (strstart(opts, "off", )) {
+request_opengl = 0;
+} else {
+goto invalid_sdl_args;
+}
 } else if (strstart(opts, ",gl=", )) {
 opts = nextopt;
 if (strstart(opts, "on", )) {
@@ -4364,7 +4373,7 @@ int main(int argc, char **argv, char **envp)
 
 qemu_console_early_init();
 
-if (request_opengl == 1 && display_opengl == 0) {
+if ((request_opengl == 1 || request_opengl == 2) && display_opengl == 0) {
 #if defined(CONFIG_OPENGL)
 error_report("OpenGL is not supported by the display");
 #else
-- 
2.15.1




[Qemu-devel] [RFC 2/2] sdl2: gles option will create a gles context

2018-01-17 Thread Elie Tournier
Create an OpenGL ES context if the option `-display sdl,gles=on` is set.

Signed-off-by: Elie Tournier <elie.tourn...@collabora.com>
---
 include/sysemu/sysemu.h | 1 +
 include/ui/sdl2.h   | 1 +
 ui/sdl2-gl.c| 8 ++--
 ui/sdl2.c   | 7 +++
 vl.c| 1 +
 5 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 31612caf10..32f242c4c5 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -108,6 +108,7 @@ extern int graphic_width;
 extern int graphic_height;
 extern int graphic_depth;
 extern int display_opengl;
+extern bool use_opengl_es;
 extern const char *keyboard_layout;
 extern int win2k_install_hack;
 extern int alt_grab;
diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
index 51084e6320..2aaa203f51 100644
--- a/include/ui/sdl2.h
+++ b/include/ui/sdl2.h
@@ -26,6 +26,7 @@ struct sdl2_console {
 int idle_counter;
 int ignore_hotkeys;
 SDL_GLContext winctx;
+bool opengl_es;
 #ifdef CONFIG_OPENGL
 QemuGLShader *gls;
 egl_fb guest_fb;
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index 5e1073a084..4e620c5ff7 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -142,8 +142,12 @@ 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->opengl_es)
+SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
+SDL_GL_CONTEXT_PROFILE_ES);
+else
+SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
+SDL_GL_CONTEXT_PROFILE_CORE);
 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, params->major_ver);
 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, params->minor_ver);
 
diff --git a/ui/sdl2.c b/ui/sdl2.c
index e78cff1a6f..a1250a6902 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -762,9 +762,14 @@ void sdl_display_early_init(int opengl)
 case 0:  /* off */
 break;
 case 1: /* on */
+#ifdef CONFIG_OPENGL
+display_opengl = 1;
+#endif
+break;
 case 2: /* gles = on */
 #ifdef CONFIG_OPENGL
 display_opengl = 1;
+use_opengl_es = true;
 #endif
 break;
 default:
@@ -829,9 +834,11 @@ void sdl_display_init(DisplayState *ds, int full_screen, 
int no_frame)
 #ifdef CONFIG_OPENGL
 sdl2_console[i].opengl = display_opengl;
 sdl2_console[i].dcl.ops = display_opengl ? _gl_ops : _2d_ops;
+sdl2_console[i].opengl_es = use_opengl_es;
 #else
 sdl2_console[i].opengl = 0;
 sdl2_console[i].dcl.ops = _2d_ops;
+sdl2_console[i].opengl_es = false;
 #endif
 sdl2_console[i].dcl.con = con;
 register_displaychangelistener(_console[i].dcl);
diff --git a/vl.c b/vl.c
index 3fe325222e..a7bde1fa1e 100644
--- a/vl.c
+++ b/vl.c
@@ -137,6 +137,7 @@ const char *bios_name = NULL;
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
 int request_opengl = -1;
 int display_opengl;
+bool use_opengl_es;
 const char* keyboard_layout = NULL;
 ram_addr_t ram_size;
 const char *mem_path = NULL;
-- 
2.15.1




[Qemu-devel] [RFC 0/2] Use SDL to create an OpenGL ES context for virglrenderer.

2018-01-17 Thread Elie Tournier
Hello everyone,

At Collabora, we are working on adding an OpenGL ES backend on virglrenderer 
[1].
I submit these patches as an RFC because our work didn't land in virglrenderer 
yet.
Currently, we support OpenGL ES 2.0 on the guest side and OpenGL ES 3.0 on the 
host side.
Our plan is to increase the guest support to OpenGL ES 3.0.
Thanks to this work, we are able to run QEMU on system that only support OpenGL 
ES.

In order to use this feature, we need to create a gles context.
This series add an option (`-display sdl,gles=on`) in the SDL display to create 
that context.

The source code is available on our gitlab instance.
For virglrenderer [2] and qemu [3].

Feel free to review/comment the series.

Have a nice day,
Elie

[1] https://cgit.freedesktop.org/virglrenderer
[2] https://gitlab.collabora.com/jakob/virglrenderer-gles/tree/hacks
[3] https://gitlab.collabora.com/elie/qemu/tree/gles-option

Elie Tournier (2):
  sdl2: Add gles options
  sdl2: gles option will create a gles context

 include/sysemu/sysemu.h |  1 +
 include/ui/sdl2.h   |  1 +
 qemu-options.hx |  5 -
 ui/sdl2-gl.c|  8 ++--
 ui/sdl2.c   |  8 
 vl.c| 12 +++-
 6 files changed, 31 insertions(+), 4 deletions(-)

-- 
2.15.1