All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/4] sdl2: add opengl rendering support
@ 2015-01-12 12:35 Gerd Hoffmann
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 1/4] configure: opengl overhaul Gerd Hoffmann
                   ` (3 more replies)
  0 siblings, 4 replies; 16+ messages in thread
From: Gerd Hoffmann @ 2015-01-12 12:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

Next round of the opengl rendering support patches.

Changes from RfC:
 * new patch #2, adding helper functions to render display surfaces
   as opengl texture.
 * sdl2 opengl code just carries the sdl2-specific bits and calls
   the opengl console helpers added by patch #2.
 * Addressing most (but not yet all) review comments from Max.
 * opengl support is runtime-switchable via '-display sdl,gl={on,off}'.
   Defaults to off atm.

please review,
  Gerd

Gerd Hoffmann (4):
  configure: opengl overhaul
  console: add opengl rendering helper functions
  sdl2: add support for display rendering using opengl.
  sdl2: move SDL_* includes to sdl2.h

 configure                        |  39 ++++++------
 default-configs/lm32-softmmu.mak |   2 +-
 hw/display/Makefile.objs         |   2 +-
 hw/lm32/milkymist-hw.h           |   4 +-
 include/sysemu/sysemu.h          |   1 +
 include/ui/console.h             |  24 ++++++++
 include/ui/sdl2.h                |  17 ++++++
 ui/Makefile.objs                 |   9 +++
 ui/console-gl.c                  | 127 +++++++++++++++++++++++++++++++++++++++
 ui/sdl.c                         |  11 ++++
 ui/sdl2-2d.c                     |  13 ++--
 ui/sdl2-gl.c                     | 107 +++++++++++++++++++++++++++++++++
 ui/sdl2-input.c                  |   6 --
 ui/sdl2.c                        |  73 ++++++++++++++++++----
 vl.c                             |  12 ++++
 15 files changed, 396 insertions(+), 51 deletions(-)
 create mode 100644 ui/console-gl.c
 create mode 100644 ui/sdl2-gl.c

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 1/4] configure: opengl overhaul
  2015-01-12 12:35 [Qemu-devel] [PATCH 0/4] sdl2: add opengl rendering support Gerd Hoffmann
@ 2015-01-12 12:35 ` Gerd Hoffmann
  2015-01-12 12:55   ` Paolo Bonzini
  2015-01-15 19:55   ` Max Reitz
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions Gerd Hoffmann
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 16+ messages in thread
From: Gerd Hoffmann @ 2015-01-12 12:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Michael Walle, Gerd Hoffmann, Anthony Liguori

Rename config option from "glx" to "opengl", glx will not be the only
option for opengl in near future.  Also switch over to pkg-config for
opengl support detection.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 configure                        | 39 +++++++++++++++++----------------------
 default-configs/lm32-softmmu.mak |  2 +-
 hw/display/Makefile.objs         |  2 +-
 hw/lm32/milkymist-hw.h           |  4 ++--
 include/sysemu/sysemu.h          |  1 +
 vl.c                             |  1 +
 6 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/configure b/configure
index cae588c..ee1693b 100755
--- a/configure
+++ b/configure
@@ -309,7 +309,7 @@ rbd=""
 smartcard_nss=""
 libusb=""
 usb_redir=""
-glx=""
+opengl=""
 zlib="yes"
 lzo=""
 snappy=""
@@ -1026,9 +1026,9 @@ for opt do
   ;;
   --enable-vhost-scsi) vhost_scsi="yes"
   ;;
-  --disable-glx) glx="no"
+  --disable-opengl) opengl="no"
   ;;
-  --enable-glx) glx="yes"
+  --enable-opengl) opengl="yes"
   ;;
   --disable-rbd) rbd="no"
   ;;
@@ -3056,23 +3056,18 @@ fi
 libs_softmmu="$libs_softmmu $fdt_libs"
 
 ##########################################
-# GLX probe, used by milkymist-tmu2
-if test "$glx" != "no" ; then
-  glx_libs="-lGL -lX11"
-  cat > $TMPC << EOF
-#include <X11/Xlib.h>
-#include <GL/gl.h>
-#include <GL/glx.h>
-int main(void) { glBegin(0); glXQueryVersion(0,0,0); return 0; }
-EOF
-  if compile_prog "" "-lGL -lX11" ; then
-    glx=yes
+# opengl probe, used by milkymist-tmu2
+if test "$opengl" != "no" ; then
+  opengl_pkgs="gl"
+  if $pkg_config $opengl_pkgs; then
+    opengl_libs="$($pkg_config --libs $opengl_pkgs) -lX11"
+    opengl=yes
   else
-    if test "$glx" = "yes" ; then
-      feature_not_found "glx" "Install GL devel (e.g. MESA)"
+    if test "$opengl" = "yes" ; then
+      feature_not_found "opengl" "Install GL devel (e.g. MESA)"
     fi
-    glx_libs=
-    glx=no
+    opengl_libs=""
+    opengl=no
   fi
 fi
 
@@ -4320,7 +4315,7 @@ echo "xfsctl support    $xfs"
 echo "nss used          $smartcard_nss"
 echo "libusb            $libusb"
 echo "usb net redir     $usb_redir"
-echo "GLX support       $glx"
+echo "OpenGL support    $opengl"
 echo "libiscsi support  $libiscsi"
 echo "libnfs support    $libnfs"
 echo "build guest agent $guest_agent"
@@ -4682,9 +4677,9 @@ if test "$usb_redir" = "yes" ; then
   echo "CONFIG_USB_REDIR=y" >> $config_host_mak
 fi
 
-if test "$glx" = "yes" ; then
-  echo "CONFIG_GLX=y" >> $config_host_mak
-  echo "GLX_LIBS=$glx_libs" >> $config_host_mak
+if test "$opengl" = "yes" ; then
+  echo "CONFIG_OPENGL=y" >> $config_host_mak
+  echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
 fi
 
 if test "$lzo" = "yes" ; then
diff --git a/default-configs/lm32-softmmu.mak b/default-configs/lm32-softmmu.mak
index 7df58c8..4889348 100644
--- a/default-configs/lm32-softmmu.mak
+++ b/default-configs/lm32-softmmu.mak
@@ -2,7 +2,7 @@
 
 CONFIG_LM32=y
 CONFIG_MILKYMIST=y
-CONFIG_MILKYMIST_TMU2=$(CONFIG_GLX)
+CONFIG_MILKYMIST_TMU2=$(CONFIG_OPENGL)
 CONFIG_FRAMEBUFFER=y
 CONFIG_PTIMER=y
 CONFIG_PFLASH_CFI01=y
diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
index 7ed76a9..e18ea57 100644
--- a/hw/display/Makefile.objs
+++ b/hw/display/Makefile.objs
@@ -20,7 +20,7 @@ common-obj-$(CONFIG_ZAURUS) += tc6393xb.o
 
 ifeq ($(CONFIG_MILKYMIST_TMU2),y)
 common-obj-y += milkymist-tmu2.o
-libs_softmmu += $(GLX_LIBS)
+libs_softmmu += $(OPENGL_LIBS)
 endif
 
 obj-$(CONFIG_OMAP) += omap_dss.o
diff --git a/hw/lm32/milkymist-hw.h b/hw/lm32/milkymist-hw.h
index 5317ce6..8d20cac 100644
--- a/hw/lm32/milkymist-hw.h
+++ b/hw/lm32/milkymist-hw.h
@@ -86,7 +86,7 @@ static inline DeviceState *milkymist_pfpu_create(hwaddr base,
     return dev;
 }
 
-#ifdef CONFIG_GLX
+#ifdef CONFIG_OPENGL
 #include <X11/Xlib.h>
 #include <GL/glx.h>
 static const int glx_fbconfig_attr[] = {
@@ -100,7 +100,7 @@ static const int glx_fbconfig_attr[] = {
 static inline DeviceState *milkymist_tmu2_create(hwaddr base,
         qemu_irq irq)
 {
-#ifdef CONFIG_GLX
+#ifdef CONFIG_OPENGL
     DeviceState *dev;
     Display *d;
     GLXFBConfig *configs;
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 503e5a4..e5c91eb 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -117,6 +117,7 @@ extern int graphic_width;
 extern int graphic_height;
 extern int graphic_depth;
 extern DisplayType display_type;
+extern int display_opengl;
 extern const char *keyboard_layout;
 extern int win2k_install_hack;
 extern int alt_grab;
diff --git a/vl.c b/vl.c
index bea9656..06e8f44 100644
--- a/vl.c
+++ b/vl.c
@@ -129,6 +129,7 @@ static int data_dir_idx;
 const char *bios_name = NULL;
 enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
 DisplayType display_type = DT_DEFAULT;
+int display_opengl;
 static int display_remote;
 const char* keyboard_layout = NULL;
 ram_addr_t ram_size;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions
  2015-01-12 12:35 [Qemu-devel] [PATCH 0/4] sdl2: add opengl rendering support Gerd Hoffmann
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 1/4] configure: opengl overhaul Gerd Hoffmann
@ 2015-01-12 12:35 ` Gerd Hoffmann
  2015-01-12 13:04   ` Paolo Bonzini
  2015-01-15 20:46   ` Max Reitz
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 3/4] sdl2: add support for display rendering using opengl Gerd Hoffmann
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 4/4] sdl2: move SDL_* includes to sdl2.h Gerd Hoffmann
  3 siblings, 2 replies; 16+ messages in thread
From: Gerd Hoffmann @ 2015-01-12 12:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h |  23 ++++++++++
 ui/Makefile.objs     |   5 ++
 ui/console-gl.c      | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 155 insertions(+)
 create mode 100644 ui/console-gl.c

diff --git a/include/ui/console.h b/include/ui/console.h
index 22ef8ca..5cb169c 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -9,6 +9,11 @@
 #include "qapi-types.h"
 #include "qapi/error.h"
 
+#ifdef CONFIG_OPENGL
+#include <GL/gl.h>
+#include <GL/glext.h>
+#endif
+
 /* keyboard/mouse support */
 
 #define MOUSE_EVENT_LBUTTON 0x01
@@ -118,6 +123,11 @@ struct DisplaySurface {
     pixman_format_code_t format;
     pixman_image_t *image;
     uint8_t flags;
+#ifdef CONFIG_OPENGL
+    GLenum glformat;
+    GLenum gltype;
+    GLuint texture;
+#endif
 };
 
 typedef struct QemuUIInfo {
@@ -320,6 +330,19 @@ void qemu_console_copy(QemuConsole *con, int src_x, int src_y,
 DisplaySurface *qemu_console_surface(QemuConsole *con);
 DisplayState *qemu_console_displaystate(QemuConsole *console);
 
+#ifdef CONFIG_OPENGL
+/* console-gl.c */
+bool console_gl_check_format(DisplayChangeListener *dcl,
+                             pixman_format_code_t format);
+void surface_gl_create_texture(DisplaySurface *surface);
+void surface_gl_update_texture(DisplaySurface *surface,
+                               int x, int y, int w, int h);
+void surface_gl_render_texture(DisplaySurface *surface);
+void surface_gl_destroy_texture(DisplaySurface *surface);
+void surface_gl_setup_viewport(DisplaySurface *surface,
+                               int ww, int wh);
+#endif
+
 /* sdl.c */
 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
 
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index 13b5cfb..3173778 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -24,4 +24,9 @@ sdl.mo-objs := sdl2.o sdl2-input.o sdl2-2d.o
 endif
 sdl.mo-cflags := $(SDL_CFLAGS)
 
+ifeq ($(CONFIG_OPENGL),y)
+common-obj-y += console-gl.o
+libs_softmmu += $(OPENGL_LIBS)
+endif
+
 gtk.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS)
diff --git a/ui/console-gl.c b/ui/console-gl.c
new file mode 100644
index 0000000..470dd61
--- /dev/null
+++ b/ui/console-gl.c
@@ -0,0 +1,127 @@
+/*
+ * QEMU graphical console -- opengl helper bits
+ *
+ * Copyright (c) 2004 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#include "qemu-common.h"
+#include "ui/console.h"
+
+bool console_gl_check_format(DisplayChangeListener *dcl,
+                             pixman_format_code_t format)
+{
+    switch (format) {
+    case PIXMAN_x8r8g8b8:
+    case PIXMAN_a8r8g8b8:
+    case PIXMAN_r5g6b5:
+        return true;
+    default:
+        return false;
+    }
+}
+
+void surface_gl_create_texture(DisplaySurface *surface)
+{
+    switch (surface->format) {
+    case PIXMAN_x8r8g8b8:
+    case PIXMAN_a8r8g8b8:
+        surface->glformat = GL_BGRA;
+        surface->gltype = GL_UNSIGNED_BYTE;
+        break;
+    case PIXMAN_r5g6b5:
+        surface->glformat = GL_RGB;
+        surface->gltype = GL_UNSIGNED_SHORT_5_6_5;
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
+    glGenTextures(1, &surface->texture);
+    glEnable(GL_TEXTURE_2D);
+    glBindTexture(GL_TEXTURE_2D, surface->texture);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
+                 surface_width(surface),
+                 surface_height(surface),
+                 0, surface->glformat, surface->gltype,
+                 surface_data(surface));
+
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+}
+
+void surface_gl_update_texture(DisplaySurface *surface,
+                               int x, int y, int w, int h)
+{
+    uint8_t *data = (void *)surface_data(surface);
+
+    glTexSubImage2D(GL_TEXTURE_2D, 0,
+                    0, y,
+                    surface_width(surface), h,
+                    surface->glformat, surface->gltype,
+                    data + surface_stride(surface) * y);
+}
+
+void surface_gl_render_texture(DisplaySurface *surface)
+{
+    glClearColor(0.0, 0.0, 0.0, 0);
+    glClear(GL_COLOR_BUFFER_BIT);
+
+    glBegin(GL_QUADS);
+    glTexCoord2i(0, 1);  glVertex3i(-1, -1, 0);
+    glTexCoord2i(0, 0);  glVertex3i(-1, 1, 0);
+    glTexCoord2i(1, 0);  glVertex3i(1, 1, 0);
+    glTexCoord2i(1, 1);  glVertex3i(1, -1, 0);
+    glEnd();
+}
+
+void surface_gl_destroy_texture(DisplaySurface *surface)
+{
+    if (!surface || !surface->texture) {
+        return;
+    }
+    glDeleteTextures(1, &surface->texture);
+    surface->texture = 0;
+}
+
+void surface_gl_setup_viewport(DisplaySurface *surface,
+                               int ww, int wh)
+{
+    int gw, gh, stripe;
+    float sw, sh;
+
+    gw = surface_width(surface);
+    gh = surface_height(surface);
+
+    sw = (float)ww/gw;
+    sh = (float)wh/gh;
+    if (sw < sh) {
+        stripe = wh - wh*sw/sh;
+        glViewport(0, stripe / 2, ww, wh - stripe);
+    } else {
+        stripe = ww - ww*sh/sw;
+        glViewport(stripe / 2, 0, ww - stripe, wh);
+    }
+
+    glMatrixMode(GL_PROJECTION);
+    glLoadIdentity();
+
+    glMatrixMode(GL_MODELVIEW);
+    glLoadIdentity();
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 3/4] sdl2: add support for display rendering using opengl.
  2015-01-12 12:35 [Qemu-devel] [PATCH 0/4] sdl2: add opengl rendering support Gerd Hoffmann
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 1/4] configure: opengl overhaul Gerd Hoffmann
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions Gerd Hoffmann
@ 2015-01-12 12:35 ` Gerd Hoffmann
  2015-01-15 22:14   ` Max Reitz
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 4/4] sdl2: move SDL_* includes to sdl2.h Gerd Hoffmann
  3 siblings, 1 reply; 16+ messages in thread
From: Gerd Hoffmann @ 2015-01-12 12:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Gerd Hoffmann, Anthony Liguori

Add new sdl2-gl.c file, with display
rendering functions using opengl.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h |   1 +
 include/ui/sdl2.h    |  10 +++++
 ui/Makefile.objs     |   4 ++
 ui/sdl.c             |  11 +++++
 ui/sdl2-2d.c         |   7 ++++
 ui/sdl2-gl.c         | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/sdl2.c            |  67 ++++++++++++++++++++++++++----
 vl.c                 |  11 +++++
 8 files changed, 218 insertions(+), 7 deletions(-)
 create mode 100644 ui/sdl2-gl.c

diff --git a/include/ui/console.h b/include/ui/console.h
index 5cb169c..7496dee 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -344,6 +344,7 @@ void surface_gl_setup_viewport(DisplaySurface *surface,
 #endif
 
 /* sdl.c */
+void sdl_display_early_init(int opengl);
 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
 
 /* cocoa.m */
diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
index f56c596..5c962da 100644
--- a/include/ui/sdl2.h
+++ b/include/ui/sdl2.h
@@ -11,6 +11,9 @@ struct sdl2_console {
     int last_vm_running; /* per console for caption reasons */
     int x, y;
     int hidden;
+    int opengl;
+    int updates;
+    SDL_GLContext winctx;
 };
 
 void sdl2_window_create(struct sdl2_console *scon);
@@ -29,4 +32,11 @@ void sdl2_2d_switch(DisplayChangeListener *dcl,
 void sdl2_2d_refresh(DisplayChangeListener *dcl);
 void sdl2_2d_redraw(struct sdl2_console *scon);
 
+void sdl2_gl_update(DisplayChangeListener *dcl,
+                    int x, int y, int w, int h);
+void sdl2_gl_switch(DisplayChangeListener *dcl,
+                    DisplaySurface *new_surface);
+void sdl2_gl_refresh(DisplayChangeListener *dcl);
+void sdl2_gl_redraw(struct sdl2_console *scon);
+
 #endif /* SDL2_H */
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index 3173778..c1f4299 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -21,6 +21,10 @@ sdl.mo-objs := sdl.o sdl_zoom.o
 endif
 ifeq ($(CONFIG_SDLABI),2.0)
 sdl.mo-objs := sdl2.o sdl2-input.o sdl2-2d.o
+ifeq ($(CONFIG_OPENGL),y)
+sdl.mo-objs += sdl2-gl.o
+libs_softmmu += $(OPENGL_LIBS)
+endif
 endif
 sdl.mo-cflags := $(SDL_CFLAGS)
 
diff --git a/ui/sdl.c b/ui/sdl.c
index 3e9d810..1fe002d 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -873,6 +873,17 @@ static const DisplayChangeListenerOps dcl_ops = {
     .dpy_cursor_define = sdl_mouse_define,
 };
 
+void sdl_display_early_init(int opengl)
+{
+    if (opengl == 1 /* on */) {
+        fprintf(stderr,
+                "SDL1 display code has no opengl support.\n"
+                "Please recompile qemu with SDL2, using\n"
+                "./configure --enable-sdl --with-sdlabi=2.0\n");
+        exit(1);
+    }
+}
+
 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
 {
     int flags;
diff --git a/ui/sdl2-2d.c b/ui/sdl2-2d.c
index 9264817..85f1be4 100644
--- a/ui/sdl2-2d.c
+++ b/ui/sdl2-2d.c
@@ -42,6 +42,8 @@ void sdl2_2d_update(DisplayChangeListener *dcl,
     DisplaySurface *surf = qemu_console_surface(dcl->con);
     SDL_Rect rect;
 
+    assert(!scon->opengl);
+
     if (!surf) {
         return;
     }
@@ -67,6 +69,8 @@ void sdl2_2d_switch(DisplayChangeListener *dcl,
     DisplaySurface *old_surface = scon->surface;
     int format = 0;
 
+    assert(!scon->opengl);
+
     scon->surface = new_surface;
 
     if (scon->texture) {
@@ -107,12 +111,15 @@ void sdl2_2d_refresh(DisplayChangeListener *dcl)
 {
     struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
 
+    assert(!scon->opengl);
     graphic_hw_update(dcl->con);
     sdl2_poll_events(scon);
 }
 
 void sdl2_2d_redraw(struct sdl2_console *scon)
 {
+    assert(!scon->opengl);
+
     if (!scon->surface) {
         return;
     }
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
new file mode 100644
index 0000000..b8620ca
--- /dev/null
+++ b/ui/sdl2-gl.c
@@ -0,0 +1,114 @@
+/*
+ * QEMU SDL display driver
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+/* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
+
+/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
+#undef WIN32_LEAN_AND_MEAN
+
+#include <SDL.h>
+#include <SDL_syswm.h>
+#include <SDL_opengl.h>
+
+#include "qemu-common.h"
+#include "ui/console.h"
+#include "ui/input.h"
+#include "ui/sdl2.h"
+#include "sysemu/sysemu.h"
+
+static void sdl2_gl_render_surface(struct sdl2_console *scon)
+{
+    int ww, wh;
+
+    SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
+
+    SDL_GetWindowSize(scon->real_window, &ww, &wh);
+    surface_gl_setup_viewport(scon->surface, ww, wh);
+
+    surface_gl_render_texture(scon->surface);
+    SDL_GL_SwapWindow(scon->real_window);
+}
+
+void sdl2_gl_update(DisplayChangeListener *dcl,
+                    int x, int y, int w, int h)
+{
+    struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
+
+    assert(scon->opengl);
+
+    SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
+    surface_gl_update_texture(scon->surface, x, y, w, h);
+    scon->updates++;
+}
+
+void sdl2_gl_switch(DisplayChangeListener *dcl,
+                    DisplaySurface *new_surface)
+{
+    struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
+    DisplaySurface *old_surface = scon->surface;
+
+    assert(scon->opengl);
+
+    SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
+    surface_gl_destroy_texture(scon->surface);
+
+    scon->surface = new_surface;
+
+    if (!new_surface) {
+        sdl2_window_destroy(scon);
+        return;
+    }
+
+    if (!scon->real_window) {
+        sdl2_window_create(scon);
+    } else if (old_surface &&
+               ((surface_width(old_surface)  != surface_width(new_surface)) ||
+                (surface_height(old_surface) != surface_height(new_surface)))) {
+        sdl2_window_resize(scon);
+    }
+
+    surface_gl_create_texture(scon->surface);
+}
+
+void sdl2_gl_refresh(DisplayChangeListener *dcl)
+{
+    struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
+
+    assert(scon->opengl);
+
+    graphic_hw_update(dcl->con);
+    if (scon->updates && scon->surface) {
+        scon->updates = 0;
+        sdl2_gl_render_surface(scon);
+    }
+    sdl2_poll_events(scon);
+}
+
+void sdl2_gl_redraw(struct sdl2_console *scon)
+{
+    assert(scon->opengl);
+
+    if (scon->surface) {
+        sdl2_gl_render_surface(scon);
+    }
+}
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 1ae2781..7dd8a87 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -92,6 +92,9 @@ void sdl2_window_create(struct sdl2_console *scon)
                                          surface_height(scon->surface),
                                          flags);
     scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
+    if (scon->opengl) {
+        scon->winctx = SDL_GL_GetCurrentContext();
+    }
     sdl_update_caption(scon);
 }
 
@@ -118,6 +121,17 @@ void sdl2_window_resize(struct sdl2_console *scon)
                       surface_height(scon->surface));
 }
 
+static void sdl2_redraw(struct sdl2_console *scon)
+{
+    if (scon->opengl) {
+#ifdef CONFIG_OPENGL
+        sdl2_gl_redraw(scon);
+#endif
+    } else {
+        sdl2_2d_redraw(scon);
+    }
+}
+
 static void sdl_update_caption(struct sdl2_console *scon)
 {
     char win_title[1024];
@@ -316,7 +330,7 @@ static void toggle_full_screen(struct sdl2_console *scon)
         }
         SDL_SetWindowFullscreen(scon->real_window, 0);
     }
-    sdl2_2d_redraw(scon);
+    sdl2_redraw(scon);
 }
 
 static void handle_keydown(SDL_Event *ev)
@@ -364,8 +378,10 @@ static void handle_keydown(SDL_Event *ev)
         case SDL_SCANCODE_U:
             sdl2_window_destroy(scon);
             sdl2_window_create(scon);
-            /* re-create texture */
-            sdl2_2d_switch(&scon->dcl, scon->surface);
+            if (!scon->opengl) {
+                /* re-create scon->texture */
+                sdl2_2d_switch(&scon->dcl, scon->surface);
+            }
             gui_keysym = 1;
             break;
 #if 0
@@ -384,7 +400,7 @@ static void handle_keydown(SDL_Event *ev)
                 fprintf(stderr, "%s: scale to %dx%d\n",
                         __func__, width, height);
                 sdl_scale(scon, width, height);
-                sdl2_2d_redraw(scon);
+                sdl2_redraw(scon);
                 gui_keysym = 1;
             }
 #endif
@@ -520,10 +536,10 @@ static void handle_windowevent(SDL_Event *ev)
             info.height = ev->window.data2;
             dpy_set_ui_info(scon->dcl.con, &info);
         }
-        sdl2_2d_redraw(scon);
+        sdl2_redraw(scon);
         break;
     case SDL_WINDOWEVENT_EXPOSED:
-        sdl2_2d_redraw(scon);
+        sdl2_redraw(scon);
         break;
     case SDL_WINDOWEVENT_FOCUS_GAINED:
     case SDL_WINDOWEVENT_ENTER:
@@ -676,6 +692,37 @@ static const DisplayChangeListenerOps dcl_2d_ops = {
     .dpy_cursor_define = sdl_mouse_define,
 };
 
+#ifdef CONFIG_OPENGL
+static const DisplayChangeListenerOps dcl_gl_ops = {
+    .dpy_name          = "sdl2-gl",
+    .dpy_gfx_update    = sdl2_gl_update,
+    .dpy_gfx_switch    = sdl2_gl_switch,
+    .dpy_refresh       = sdl2_gl_refresh,
+    .dpy_mouse_set     = sdl_mouse_warp,
+    .dpy_cursor_define = sdl_mouse_define,
+};
+#endif
+
+void sdl_display_early_init(int opengl)
+{
+    switch (opengl) {
+    case -1: /* default */
+    case 0:  /* off */
+        break;
+    case 1: /* on */
+#ifdef CONFIG_OPENGL
+        display_opengl = 1;
+#else
+        fprintf(stderr, "SDL2 has been compiled without opengl support\n");
+        exit(1);
+#endif
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+}
+
 void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
 {
     int flags;
@@ -721,10 +768,16 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
         if (!qemu_console_is_graphic(con)) {
             sdl2_console[i].hidden = true;
         }
+        sdl2_console[i].idx = i;
+#ifdef CONFIG_OPENGL
+        sdl2_console[i].opengl = display_opengl;
+        sdl2_console[i].dcl.ops = display_opengl ? &dcl_gl_ops : &dcl_2d_ops;
+#else
+        sdl2_console[i].opengl = 0;
         sdl2_console[i].dcl.ops = &dcl_2d_ops;
+#endif
         sdl2_console[i].dcl.con = con;
         register_displaychangelistener(&sdl2_console[i].dcl);
-        sdl2_console[i].idx = i;
     }
 
     /* Load a 32x32x4 image. White pixels are transparent. */
diff --git a/vl.c b/vl.c
index 06e8f44..008e4bf 100644
--- a/vl.c
+++ b/vl.c
@@ -1939,6 +1939,7 @@ static DisplayType select_display(const char *p)
 {
     const char *opts;
     DisplayType display = DT_DEFAULT;
+    int opengl = -1;
 
     if (strstart(p, "sdl", &opts)) {
 #ifdef CONFIG_SDL
@@ -1982,6 +1983,15 @@ static DisplayType select_display(const char *p)
                 } else {
                     goto invalid_sdl_args;
                 }
+            } else if (strstart(opts, ",gl=", &nextopt)) {
+                opts = nextopt;
+                if (strstart(opts, "on", &nextopt)) {
+                    opengl = 1;
+                } else if (strstart(opts, "off", &nextopt)) {
+                    opengl = 0;
+                } else {
+                    goto invalid_sdl_args;
+                }
             } else {
             invalid_sdl_args:
                 fprintf(stderr, "Invalid SDL option string: %s\n", p);
@@ -1989,6 +1999,7 @@ static DisplayType select_display(const char *p)
             }
             opts = nextopt;
         }
+        sdl_display_early_init(opengl);
 #else
         fprintf(stderr, "SDL support is disabled\n");
         exit(1);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [Qemu-devel] [PATCH 4/4] sdl2: move SDL_* includes to sdl2.h
  2015-01-12 12:35 [Qemu-devel] [PATCH 0/4] sdl2: add opengl rendering support Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 3/4] sdl2: add support for display rendering using opengl Gerd Hoffmann
@ 2015-01-12 12:35 ` Gerd Hoffmann
  2015-01-15 22:21   ` Max Reitz
  3 siblings, 1 reply; 16+ messages in thread
From: Gerd Hoffmann @ 2015-01-12 12:35 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/sdl2.h | 7 +++++++
 ui/sdl2-2d.c      | 6 ------
 ui/sdl2-gl.c      | 7 -------
 ui/sdl2-input.c   | 6 ------
 ui/sdl2.c         | 6 ------
 5 files changed, 7 insertions(+), 25 deletions(-)

diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
index 5c962da..a80b3a1 100644
--- a/include/ui/sdl2.h
+++ b/include/ui/sdl2.h
@@ -1,6 +1,13 @@
 #ifndef SDL2_H
 #define SDL2_H
 
+/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
+#undef WIN32_LEAN_AND_MEAN
+
+#include <SDL.h>
+#include <SDL_syswm.h>
+#include <SDL_opengl.h>
+
 struct sdl2_console {
     DisplayChangeListener dcl;
     DisplaySurface *surface;
diff --git a/ui/sdl2-2d.c b/ui/sdl2-2d.c
index 85f1be4..f6cb438 100644
--- a/ui/sdl2-2d.c
+++ b/ui/sdl2-2d.c
@@ -23,12 +23,6 @@
  */
 /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
 
-/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
-#undef WIN32_LEAN_AND_MEAN
-
-#include <SDL.h>
-#include <SDL_syswm.h>
-
 #include "qemu-common.h"
 #include "ui/console.h"
 #include "ui/input.h"
diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
index b8620ca..6de01ad 100644
--- a/ui/sdl2-gl.c
+++ b/ui/sdl2-gl.c
@@ -23,13 +23,6 @@
  */
 /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
 
-/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
-#undef WIN32_LEAN_AND_MEAN
-
-#include <SDL.h>
-#include <SDL_syswm.h>
-#include <SDL_opengl.h>
-
 #include "qemu-common.h"
 #include "ui/console.h"
 #include "ui/input.h"
diff --git a/ui/sdl2-input.c b/ui/sdl2-input.c
index a1973fc..ac5dc94 100644
--- a/ui/sdl2-input.c
+++ b/ui/sdl2-input.c
@@ -23,12 +23,6 @@
  */
 /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
 
-/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
-#undef WIN32_LEAN_AND_MEAN
-
-#include <SDL.h>
-#include <SDL_syswm.h>
-
 #include "qemu-common.h"
 #include "ui/console.h"
 #include "ui/input.h"
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 7dd8a87..3be9de7 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -23,12 +23,6 @@
  */
 /* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
 
-/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
-#undef WIN32_LEAN_AND_MEAN
-
-#include <SDL.h>
-#include <SDL_syswm.h>
-
 #include "qemu-common.h"
 #include "ui/console.h"
 #include "ui/input.h"
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] configure: opengl overhaul
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 1/4] configure: opengl overhaul Gerd Hoffmann
@ 2015-01-12 12:55   ` Paolo Bonzini
  2015-01-12 13:11     ` Gerd Hoffmann
  2015-01-15 19:55   ` Max Reitz
  1 sibling, 1 reply; 16+ messages in thread
From: Paolo Bonzini @ 2015-01-12 12:55 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: Michael Walle, Anthony Liguori



On 12/01/2015 13:35, Gerd Hoffmann wrote:
> Rename config option from "glx" to "opengl", glx will not be the only
> option for opengl in near future.  Also switch over to pkg-config for
> opengl support detection.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

Gerd, since you're working in this area, can you pick up
http://article.gmane.org/gmane.comp.emulators.qemu/313402 as well?  I
had queued it for my next pull request, but it conflicts with your stuff.

Paolo

> ---
>  configure                        | 39 +++++++++++++++++----------------------
>  default-configs/lm32-softmmu.mak |  2 +-
>  hw/display/Makefile.objs         |  2 +-
>  hw/lm32/milkymist-hw.h           |  4 ++--
>  include/sysemu/sysemu.h          |  1 +
>  vl.c                             |  1 +
>  6 files changed, 23 insertions(+), 26 deletions(-)
> 
> diff --git a/configure b/configure
> index cae588c..ee1693b 100755
> --- a/configure
> +++ b/configure
> @@ -309,7 +309,7 @@ rbd=""
>  smartcard_nss=""
>  libusb=""
>  usb_redir=""
> -glx=""
> +opengl=""
>  zlib="yes"
>  lzo=""
>  snappy=""
> @@ -1026,9 +1026,9 @@ for opt do
>    ;;
>    --enable-vhost-scsi) vhost_scsi="yes"
>    ;;
> -  --disable-glx) glx="no"
> +  --disable-opengl) opengl="no"
>    ;;
> -  --enable-glx) glx="yes"
> +  --enable-opengl) opengl="yes"
>    ;;
>    --disable-rbd) rbd="no"
>    ;;
> @@ -3056,23 +3056,18 @@ fi
>  libs_softmmu="$libs_softmmu $fdt_libs"
>  
>  ##########################################
> -# GLX probe, used by milkymist-tmu2
> -if test "$glx" != "no" ; then
> -  glx_libs="-lGL -lX11"
> -  cat > $TMPC << EOF
> -#include <X11/Xlib.h>
> -#include <GL/gl.h>
> -#include <GL/glx.h>
> -int main(void) { glBegin(0); glXQueryVersion(0,0,0); return 0; }
> -EOF
> -  if compile_prog "" "-lGL -lX11" ; then
> -    glx=yes
> +# opengl probe, used by milkymist-tmu2
> +if test "$opengl" != "no" ; then
> +  opengl_pkgs="gl"
> +  if $pkg_config $opengl_pkgs; then
> +    opengl_libs="$($pkg_config --libs $opengl_pkgs) -lX11"
> +    opengl=yes
>    else
> -    if test "$glx" = "yes" ; then
> -      feature_not_found "glx" "Install GL devel (e.g. MESA)"
> +    if test "$opengl" = "yes" ; then
> +      feature_not_found "opengl" "Install GL devel (e.g. MESA)"
>      fi
> -    glx_libs=
> -    glx=no
> +    opengl_libs=""
> +    opengl=no
>    fi
>  fi
>  
> @@ -4320,7 +4315,7 @@ echo "xfsctl support    $xfs"
>  echo "nss used          $smartcard_nss"
>  echo "libusb            $libusb"
>  echo "usb net redir     $usb_redir"
> -echo "GLX support       $glx"
> +echo "OpenGL support    $opengl"
>  echo "libiscsi support  $libiscsi"
>  echo "libnfs support    $libnfs"
>  echo "build guest agent $guest_agent"
> @@ -4682,9 +4677,9 @@ if test "$usb_redir" = "yes" ; then
>    echo "CONFIG_USB_REDIR=y" >> $config_host_mak
>  fi
>  
> -if test "$glx" = "yes" ; then
> -  echo "CONFIG_GLX=y" >> $config_host_mak
> -  echo "GLX_LIBS=$glx_libs" >> $config_host_mak
> +if test "$opengl" = "yes" ; then
> +  echo "CONFIG_OPENGL=y" >> $config_host_mak
> +  echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
>  fi
>  
>  if test "$lzo" = "yes" ; then
> diff --git a/default-configs/lm32-softmmu.mak b/default-configs/lm32-softmmu.mak
> index 7df58c8..4889348 100644
> --- a/default-configs/lm32-softmmu.mak
> +++ b/default-configs/lm32-softmmu.mak
> @@ -2,7 +2,7 @@
>  
>  CONFIG_LM32=y
>  CONFIG_MILKYMIST=y
> -CONFIG_MILKYMIST_TMU2=$(CONFIG_GLX)
> +CONFIG_MILKYMIST_TMU2=$(CONFIG_OPENGL)
>  CONFIG_FRAMEBUFFER=y
>  CONFIG_PTIMER=y
>  CONFIG_PFLASH_CFI01=y
> diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
> index 7ed76a9..e18ea57 100644
> --- a/hw/display/Makefile.objs
> +++ b/hw/display/Makefile.objs
> @@ -20,7 +20,7 @@ common-obj-$(CONFIG_ZAURUS) += tc6393xb.o
>  
>  ifeq ($(CONFIG_MILKYMIST_TMU2),y)
>  common-obj-y += milkymist-tmu2.o
> -libs_softmmu += $(GLX_LIBS)
> +libs_softmmu += $(OPENGL_LIBS)
>  endif
>  
>  obj-$(CONFIG_OMAP) += omap_dss.o
> diff --git a/hw/lm32/milkymist-hw.h b/hw/lm32/milkymist-hw.h
> index 5317ce6..8d20cac 100644
> --- a/hw/lm32/milkymist-hw.h
> +++ b/hw/lm32/milkymist-hw.h
> @@ -86,7 +86,7 @@ static inline DeviceState *milkymist_pfpu_create(hwaddr base,
>      return dev;
>  }
>  
> -#ifdef CONFIG_GLX
> +#ifdef CONFIG_OPENGL
>  #include <X11/Xlib.h>
>  #include <GL/glx.h>
>  static const int glx_fbconfig_attr[] = {
> @@ -100,7 +100,7 @@ static const int glx_fbconfig_attr[] = {
>  static inline DeviceState *milkymist_tmu2_create(hwaddr base,
>          qemu_irq irq)
>  {
> -#ifdef CONFIG_GLX
> +#ifdef CONFIG_OPENGL
>      DeviceState *dev;
>      Display *d;
>      GLXFBConfig *configs;
> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
> index 503e5a4..e5c91eb 100644
> --- a/include/sysemu/sysemu.h
> +++ b/include/sysemu/sysemu.h
> @@ -117,6 +117,7 @@ extern int graphic_width;
>  extern int graphic_height;
>  extern int graphic_depth;
>  extern DisplayType display_type;
> +extern int display_opengl;
>  extern const char *keyboard_layout;
>  extern int win2k_install_hack;
>  extern int alt_grab;
> diff --git a/vl.c b/vl.c
> index bea9656..06e8f44 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -129,6 +129,7 @@ static int data_dir_idx;
>  const char *bios_name = NULL;
>  enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
>  DisplayType display_type = DT_DEFAULT;
> +int display_opengl;
>  static int display_remote;
>  const char* keyboard_layout = NULL;
>  ram_addr_t ram_size;
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions Gerd Hoffmann
@ 2015-01-12 13:04   ` Paolo Bonzini
  2015-01-12 13:13     ` Gerd Hoffmann
  2015-01-15 20:46   ` Max Reitz
  1 sibling, 1 reply; 16+ messages in thread
From: Paolo Bonzini @ 2015-01-12 13:04 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: Anthony Liguori



On 12/01/2015 13:35, Gerd Hoffmann wrote:
> +/*
> + * QEMU graphical console -- opengl helper bits
> + *
> + * Copyright (c) 2004 Fabrice Bellard
> + *

Copyright Red Hat / Author you?

Paolo

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] configure: opengl overhaul
  2015-01-12 12:55   ` Paolo Bonzini
@ 2015-01-12 13:11     ` Gerd Hoffmann
  0 siblings, 0 replies; 16+ messages in thread
From: Gerd Hoffmann @ 2015-01-12 13:11 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Jeremy White, Michael Walle, qemu-devel, Anthony Liguori

On Mo, 2015-01-12 at 13:55 +0100, Paolo Bonzini wrote:
> 
> On 12/01/2015 13:35, Gerd Hoffmann wrote:
> > Rename config option from "glx" to "opengl", glx will not be the only
> > option for opengl in near future.  Also switch over to pkg-config for
> > opengl support detection.
> > 
> > Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> 
> Gerd, since you're working in this area, can you pick up
> http://article.gmane.org/gmane.comp.emulators.qemu/313402 as well?  I
> had queued it for my next pull request, but it conflicts with your stuff.

Yep, the gl bits conflict, I'll pick it up and handle the conflicts.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions
  2015-01-12 13:04   ` Paolo Bonzini
@ 2015-01-12 13:13     ` Gerd Hoffmann
  0 siblings, 0 replies; 16+ messages in thread
From: Gerd Hoffmann @ 2015-01-12 13:13 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: qemu-devel, Anthony Liguori

On Mo, 2015-01-12 at 14:04 +0100, Paolo Bonzini wrote:
> 
> On 12/01/2015 13:35, Gerd Hoffmann wrote:
> > +/*
> > + * QEMU graphical console -- opengl helper bits
> > + *
> > + * Copyright (c) 2004 Fabrice Bellard
> > + *
> 
> Copyright Red Hat / Author you?

Ahem, yes.  Just carelessly moved over the comment from console.c, which
doesn't make much sense given this is all new code ...

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] configure: opengl overhaul
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 1/4] configure: opengl overhaul Gerd Hoffmann
  2015-01-12 12:55   ` Paolo Bonzini
@ 2015-01-15 19:55   ` Max Reitz
  2015-01-16  9:11     ` Gerd Hoffmann
  1 sibling, 1 reply; 16+ messages in thread
From: Max Reitz @ 2015-01-15 19:55 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: Paolo Bonzini, Michael Walle, Anthony Liguori

On 2015-01-12 at 07:35, Gerd Hoffmann wrote:
> Rename config option from "glx" to "opengl", glx will not be the only
> option for opengl in near future.  Also switch over to pkg-config for
> opengl support detection.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>   configure                        | 39 +++++++++++++++++----------------------
>   default-configs/lm32-softmmu.mak |  2 +-
>   hw/display/Makefile.objs         |  2 +-
>   hw/lm32/milkymist-hw.h           |  4 ++--
>   include/sysemu/sysemu.h          |  1 +
>   vl.c                             |  1 +
>   6 files changed, 23 insertions(+), 26 deletions(-)
>
> diff --git a/configure b/configure
> index cae588c..ee1693b 100755
> --- a/configure
> +++ b/configure
> @@ -309,7 +309,7 @@ rbd=""
>   smartcard_nss=""
>   libusb=""
>   usb_redir=""
> -glx=""
> +opengl=""
>   zlib="yes"
>   lzo=""
>   snappy=""
> @@ -1026,9 +1026,9 @@ for opt do
>     ;;
>     --enable-vhost-scsi) vhost_scsi="yes"
>     ;;
> -  --disable-glx) glx="no"
> +  --disable-opengl) opengl="no"
>     ;;
> -  --enable-glx) glx="yes"
> +  --enable-opengl) opengl="yes"
>     ;;
>     --disable-rbd) rbd="no"
>     ;;
> @@ -3056,23 +3056,18 @@ fi
>   libs_softmmu="$libs_softmmu $fdt_libs"
>   
>   ##########################################
> -# GLX probe, used by milkymist-tmu2
> -if test "$glx" != "no" ; then
> -  glx_libs="-lGL -lX11"
> -  cat > $TMPC << EOF
> -#include <X11/Xlib.h>
> -#include <GL/gl.h>
> -#include <GL/glx.h>
> -int main(void) { glBegin(0); glXQueryVersion(0,0,0); return 0; }
> -EOF
> -  if compile_prog "" "-lGL -lX11" ; then
> -    glx=yes
> +# opengl probe, used by milkymist-tmu2

Maybe remove this part of the comment about milkymist?

> +if test "$opengl" != "no" ; then
> +  opengl_pkgs="gl"
> +  if $pkg_config $opengl_pkgs; then
> +    opengl_libs="$($pkg_config --libs $opengl_pkgs) -lX11"
> +    opengl=yes

`pkg-config gl` might be successful even without X11 available. In this 
case, $opengl will be set to 'yes', but linking will probably fail.

Maybe we should keep GLX separated from OpenGL; for SDL we don't need 
X11, but for milkymist-tmu2 we apparently do.

Max

>     else
> -    if test "$glx" = "yes" ; then
> -      feature_not_found "glx" "Install GL devel (e.g. MESA)"
> +    if test "$opengl" = "yes" ; then
> +      feature_not_found "opengl" "Install GL devel (e.g. MESA)"
>       fi
> -    glx_libs=
> -    glx=no
> +    opengl_libs=""
> +    opengl=no
>     fi
>   fi
>   
> @@ -4320,7 +4315,7 @@ echo "xfsctl support    $xfs"
>   echo "nss used          $smartcard_nss"
>   echo "libusb            $libusb"
>   echo "usb net redir     $usb_redir"
> -echo "GLX support       $glx"
> +echo "OpenGL support    $opengl"
>   echo "libiscsi support  $libiscsi"
>   echo "libnfs support    $libnfs"
>   echo "build guest agent $guest_agent"
> @@ -4682,9 +4677,9 @@ if test "$usb_redir" = "yes" ; then
>     echo "CONFIG_USB_REDIR=y" >> $config_host_mak
>   fi
>   
> -if test "$glx" = "yes" ; then
> -  echo "CONFIG_GLX=y" >> $config_host_mak
> -  echo "GLX_LIBS=$glx_libs" >> $config_host_mak
> +if test "$opengl" = "yes" ; then
> +  echo "CONFIG_OPENGL=y" >> $config_host_mak
> +  echo "OPENGL_LIBS=$opengl_libs" >> $config_host_mak
>   fi
>   
>   if test "$lzo" = "yes" ; then
> diff --git a/default-configs/lm32-softmmu.mak b/default-configs/lm32-softmmu.mak
> index 7df58c8..4889348 100644
> --- a/default-configs/lm32-softmmu.mak
> +++ b/default-configs/lm32-softmmu.mak
> @@ -2,7 +2,7 @@
>   
>   CONFIG_LM32=y
>   CONFIG_MILKYMIST=y
> -CONFIG_MILKYMIST_TMU2=$(CONFIG_GLX)
> +CONFIG_MILKYMIST_TMU2=$(CONFIG_OPENGL)
>   CONFIG_FRAMEBUFFER=y
>   CONFIG_PTIMER=y
>   CONFIG_PFLASH_CFI01=y
> diff --git a/hw/display/Makefile.objs b/hw/display/Makefile.objs
> index 7ed76a9..e18ea57 100644
> --- a/hw/display/Makefile.objs
> +++ b/hw/display/Makefile.objs
> @@ -20,7 +20,7 @@ common-obj-$(CONFIG_ZAURUS) += tc6393xb.o
>   
>   ifeq ($(CONFIG_MILKYMIST_TMU2),y)
>   common-obj-y += milkymist-tmu2.o
> -libs_softmmu += $(GLX_LIBS)
> +libs_softmmu += $(OPENGL_LIBS)
>   endif
>   
>   obj-$(CONFIG_OMAP) += omap_dss.o
> diff --git a/hw/lm32/milkymist-hw.h b/hw/lm32/milkymist-hw.h
> index 5317ce6..8d20cac 100644
> --- a/hw/lm32/milkymist-hw.h
> +++ b/hw/lm32/milkymist-hw.h
> @@ -86,7 +86,7 @@ static inline DeviceState *milkymist_pfpu_create(hwaddr base,
>       return dev;
>   }
>   
> -#ifdef CONFIG_GLX
> +#ifdef CONFIG_OPENGL
>   #include <X11/Xlib.h>
>   #include <GL/glx.h>
>   static const int glx_fbconfig_attr[] = {
> @@ -100,7 +100,7 @@ static const int glx_fbconfig_attr[] = {
>   static inline DeviceState *milkymist_tmu2_create(hwaddr base,
>           qemu_irq irq)
>   {
> -#ifdef CONFIG_GLX
> +#ifdef CONFIG_OPENGL
>       DeviceState *dev;
>       Display *d;
>       GLXFBConfig *configs;
> diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
> index 503e5a4..e5c91eb 100644
> --- a/include/sysemu/sysemu.h
> +++ b/include/sysemu/sysemu.h
> @@ -117,6 +117,7 @@ extern int graphic_width;
>   extern int graphic_height;
>   extern int graphic_depth;
>   extern DisplayType display_type;
> +extern int display_opengl;
>   extern const char *keyboard_layout;
>   extern int win2k_install_hack;
>   extern int alt_grab;
> diff --git a/vl.c b/vl.c
> index bea9656..06e8f44 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -129,6 +129,7 @@ static int data_dir_idx;
>   const char *bios_name = NULL;
>   enum vga_retrace_method vga_retrace_method = VGA_RETRACE_DUMB;
>   DisplayType display_type = DT_DEFAULT;
> +int display_opengl;
>   static int display_remote;
>   const char* keyboard_layout = NULL;
>   ram_addr_t ram_size;

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions Gerd Hoffmann
  2015-01-12 13:04   ` Paolo Bonzini
@ 2015-01-15 20:46   ` Max Reitz
  2015-01-16  9:21     ` Gerd Hoffmann
  1 sibling, 1 reply; 16+ messages in thread
From: Max Reitz @ 2015-01-15 20:46 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: Anthony Liguori

On 2015-01-12 at 07:35, Gerd Hoffmann wrote:
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>   include/ui/console.h |  23 ++++++++++
>   ui/Makefile.objs     |   5 ++
>   ui/console-gl.c      | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   3 files changed, 155 insertions(+)
>   create mode 100644 ui/console-gl.c
>
> diff --git a/include/ui/console.h b/include/ui/console.h
> index 22ef8ca..5cb169c 100644
> --- a/include/ui/console.h
> +++ b/include/ui/console.h
> @@ -9,6 +9,11 @@
>   #include "qapi-types.h"
>   #include "qapi/error.h"
>   
> +#ifdef CONFIG_OPENGL
> +#include <GL/gl.h>
> +#include <GL/glext.h>
> +#endif
> +
>   /* keyboard/mouse support */
>   
>   #define MOUSE_EVENT_LBUTTON 0x01
> @@ -118,6 +123,11 @@ struct DisplaySurface {
>       pixman_format_code_t format;
>       pixman_image_t *image;
>       uint8_t flags;
> +#ifdef CONFIG_OPENGL
> +    GLenum glformat;
> +    GLenum gltype;
> +    GLuint texture;
> +#endif
>   };
>   
>   typedef struct QemuUIInfo {
> @@ -320,6 +330,19 @@ void qemu_console_copy(QemuConsole *con, int src_x, int src_y,
>   DisplaySurface *qemu_console_surface(QemuConsole *con);
>   DisplayState *qemu_console_displaystate(QemuConsole *console);
>   
> +#ifdef CONFIG_OPENGL
> +/* console-gl.c */
> +bool console_gl_check_format(DisplayChangeListener *dcl,
> +                             pixman_format_code_t format);
> +void surface_gl_create_texture(DisplaySurface *surface);
> +void surface_gl_update_texture(DisplaySurface *surface,
> +                               int x, int y, int w, int h);
> +void surface_gl_render_texture(DisplaySurface *surface);
> +void surface_gl_destroy_texture(DisplaySurface *surface);
> +void surface_gl_setup_viewport(DisplaySurface *surface,
> +                               int ww, int wh);
> +#endif
> +
>   /* sdl.c */
>   void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
>   
> diff --git a/ui/Makefile.objs b/ui/Makefile.objs
> index 13b5cfb..3173778 100644
> --- a/ui/Makefile.objs
> +++ b/ui/Makefile.objs
> @@ -24,4 +24,9 @@ sdl.mo-objs := sdl2.o sdl2-input.o sdl2-2d.o
>   endif
>   sdl.mo-cflags := $(SDL_CFLAGS)
>   
> +ifeq ($(CONFIG_OPENGL),y)
> +common-obj-y += console-gl.o
> +libs_softmmu += $(OPENGL_LIBS)
> +endif
> +
>   gtk.o-cflags := $(GTK_CFLAGS) $(VTE_CFLAGS)
> diff --git a/ui/console-gl.c b/ui/console-gl.c
> new file mode 100644
> index 0000000..470dd61
> --- /dev/null
> +++ b/ui/console-gl.c
> @@ -0,0 +1,127 @@
> +/*
> + * QEMU graphical console -- opengl helper bits
> + *
> + * Copyright (c) 2004 Fabrice Bellard
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +#include "qemu-common.h"
> +#include "ui/console.h"
> +
> +bool console_gl_check_format(DisplayChangeListener *dcl,
> +                             pixman_format_code_t format)
> +{
> +    switch (format) {
> +    case PIXMAN_x8r8g8b8:
> +    case PIXMAN_a8r8g8b8:
> +    case PIXMAN_r5g6b5:
> +        return true;
> +    default:
> +        return false;
> +    }
> +}

What is this function supposed to be used for?

> +
> +void surface_gl_create_texture(DisplaySurface *surface)
> +{
> +    switch (surface->format) {
> +    case PIXMAN_x8r8g8b8:
> +    case PIXMAN_a8r8g8b8:
> +        surface->glformat = GL_BGRA;

Why does the format code seem to imply ARGB order but you're using the 
exact opposite? I could imagine something like endianness being the 
reason, but you're using RGB below where the format code says exactly that.

> +        surface->gltype = GL_UNSIGNED_BYTE;
> +        break;
> +    case PIXMAN_r5g6b5:
> +        surface->glformat = GL_RGB;
> +        surface->gltype = GL_UNSIGNED_SHORT_5_6_5;
> +        break;
> +    default:
> +        g_assert_not_reached();
> +    }
> +
> +    glGenTextures(1, &surface->texture);
> +    glEnable(GL_TEXTURE_2D);
> +    glBindTexture(GL_TEXTURE_2D, surface->texture);
> +    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,

Discarding the alpha channel is intentional, I suppose?

> +                 surface_width(surface),
> +                 surface_height(surface),
> +                 0, surface->glformat, surface->gltype,
> +                 surface_data(surface));

Is surface_stride(surface) specified to be surface_width(surface) * 
bytes_per_pixel (I don't know pixman so I don't know)? If it isn't then 
this may not work.

> +
> +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
> +    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
> +}
> +
> +void surface_gl_update_texture(DisplaySurface *surface,
> +                               int x, int y, int w, int h)
> +{
> +    uint8_t *data = (void *)surface_data(surface);
> +
> +    glTexSubImage2D(GL_TEXTURE_2D, 0,
> +                    0, y,
> +                    surface_width(surface), h,
> +                    surface->glformat, surface->gltype,
> +                    data + surface_stride(surface) * y);
> +}
> +
> +void surface_gl_render_texture(DisplaySurface *surface)
> +{
> +    glClearColor(0.0, 0.0, 0.0, 0);

I still find this strange (the RGB values are doubles, the alpha channel 
is an integer; and actually all parameters are expected to be floats), 
but I can live with it.

> +    glClear(GL_COLOR_BUFFER_BIT);
> +
> +    glBegin(GL_QUADS);
> +    glTexCoord2i(0, 1);  glVertex3i(-1, -1, 0);
> +    glTexCoord2i(0, 0);  glVertex3i(-1, 1, 0);
> +    glTexCoord2i(1, 0);  glVertex3i(1, 1, 0);
> +    glTexCoord2i(1, 1);  glVertex3i(1, -1, 0);

I don't know whether I've said it before, but you can use glVertex2i() here.

> +    glEnd();
> +}
> +
> +void surface_gl_destroy_texture(DisplaySurface *surface)
> +{
> +    if (!surface || !surface->texture) {
> +        return;
> +    }
> +    glDeleteTextures(1, &surface->texture);
> +    surface->texture = 0;
> +}
> +
> +void surface_gl_setup_viewport(DisplaySurface *surface,
> +                               int ww, int wh)
> +{
> +    int gw, gh, stripe;
> +    float sw, sh;
> +
> +    gw = surface_width(surface);
> +    gh = surface_height(surface);
> +
> +    sw = (float)ww/gw;
> +    sh = (float)wh/gh;
> +    if (sw < sh) {
> +        stripe = wh - wh*sw/sh;
> +        glViewport(0, stripe / 2, ww, wh - stripe);
> +    } else {
> +        stripe = ww - ww*sh/sw;
> +        glViewport(stripe / 2, 0, ww - stripe, wh);
> +    }
> +
> +    glMatrixMode(GL_PROJECTION);
> +    glLoadIdentity();
> +
> +    glMatrixMode(GL_MODELVIEW);
> +    glLoadIdentity();
> +}

Looks fine to me in general.

Max

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 3/4] sdl2: add support for display rendering using opengl.
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 3/4] sdl2: add support for display rendering using opengl Gerd Hoffmann
@ 2015-01-15 22:14   ` Max Reitz
  0 siblings, 0 replies; 16+ messages in thread
From: Max Reitz @ 2015-01-15 22:14 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: Paolo Bonzini, Anthony Liguori

On 2015-01-12 at 07:35, Gerd Hoffmann wrote:
> Add new sdl2-gl.c file, with display
> rendering functions using opengl.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>   include/ui/console.h |   1 +
>   include/ui/sdl2.h    |  10 +++++
>   ui/Makefile.objs     |   4 ++
>   ui/sdl.c             |  11 +++++
>   ui/sdl2-2d.c         |   7 ++++
>   ui/sdl2-gl.c         | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++
>   ui/sdl2.c            |  67 ++++++++++++++++++++++++++----
>   vl.c                 |  11 +++++
>   8 files changed, 218 insertions(+), 7 deletions(-)
>   create mode 100644 ui/sdl2-gl.c
>
> diff --git a/include/ui/console.h b/include/ui/console.h
> index 5cb169c..7496dee 100644
> --- a/include/ui/console.h
> +++ b/include/ui/console.h
> @@ -344,6 +344,7 @@ void surface_gl_setup_viewport(DisplaySurface *surface,
>   #endif
>   
>   /* sdl.c */
> +void sdl_display_early_init(int opengl);
>   void sdl_display_init(DisplayState *ds, int full_screen, int no_frame);
>   
>   /* cocoa.m */
> diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h
> index f56c596..5c962da 100644
> --- a/include/ui/sdl2.h
> +++ b/include/ui/sdl2.h
> @@ -11,6 +11,9 @@ struct sdl2_console {
>       int last_vm_running; /* per console for caption reasons */
>       int x, y;
>       int hidden;
> +    int opengl;
> +    int updates;
> +    SDL_GLContext winctx;
>   };
>   
>   void sdl2_window_create(struct sdl2_console *scon);
> @@ -29,4 +32,11 @@ void sdl2_2d_switch(DisplayChangeListener *dcl,
>   void sdl2_2d_refresh(DisplayChangeListener *dcl);
>   void sdl2_2d_redraw(struct sdl2_console *scon);
>   
> +void sdl2_gl_update(DisplayChangeListener *dcl,
> +                    int x, int y, int w, int h);
> +void sdl2_gl_switch(DisplayChangeListener *dcl,
> +                    DisplaySurface *new_surface);
> +void sdl2_gl_refresh(DisplayChangeListener *dcl);
> +void sdl2_gl_redraw(struct sdl2_console *scon);
> +
>   #endif /* SDL2_H */
> diff --git a/ui/Makefile.objs b/ui/Makefile.objs
> index 3173778..c1f4299 100644
> --- a/ui/Makefile.objs
> +++ b/ui/Makefile.objs
> @@ -21,6 +21,10 @@ sdl.mo-objs := sdl.o sdl_zoom.o
>   endif
>   ifeq ($(CONFIG_SDLABI),2.0)
>   sdl.mo-objs := sdl2.o sdl2-input.o sdl2-2d.o
> +ifeq ($(CONFIG_OPENGL),y)
> +sdl.mo-objs += sdl2-gl.o
> +libs_softmmu += $(OPENGL_LIBS)
> +endif
>   endif
>   sdl.mo-cflags := $(SDL_CFLAGS)
>   
> diff --git a/ui/sdl.c b/ui/sdl.c
> index 3e9d810..1fe002d 100644
> --- a/ui/sdl.c
> +++ b/ui/sdl.c
> @@ -873,6 +873,17 @@ static const DisplayChangeListenerOps dcl_ops = {
>       .dpy_cursor_define = sdl_mouse_define,
>   };
>   
> +void sdl_display_early_init(int opengl)
> +{
> +    if (opengl == 1 /* on */) {
> +        fprintf(stderr,
> +                "SDL1 display code has no opengl support.\n"
> +                "Please recompile qemu with SDL2, using\n"
> +                "./configure --enable-sdl --with-sdlabi=2.0\n");
> +        exit(1);
> +    }
> +}
> +
>   void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
>   {
>       int flags;
> diff --git a/ui/sdl2-2d.c b/ui/sdl2-2d.c
> index 9264817..85f1be4 100644
> --- a/ui/sdl2-2d.c
> +++ b/ui/sdl2-2d.c
> @@ -42,6 +42,8 @@ void sdl2_2d_update(DisplayChangeListener *dcl,
>       DisplaySurface *surf = qemu_console_surface(dcl->con);
>       SDL_Rect rect;
>   
> +    assert(!scon->opengl);
> +
>       if (!surf) {
>           return;
>       }
> @@ -67,6 +69,8 @@ void sdl2_2d_switch(DisplayChangeListener *dcl,
>       DisplaySurface *old_surface = scon->surface;
>       int format = 0;
>   
> +    assert(!scon->opengl);
> +
>       scon->surface = new_surface;
>   
>       if (scon->texture) {
> @@ -107,12 +111,15 @@ void sdl2_2d_refresh(DisplayChangeListener *dcl)
>   {
>       struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
>   
> +    assert(!scon->opengl);
>       graphic_hw_update(dcl->con);
>       sdl2_poll_events(scon);
>   }
>   
>   void sdl2_2d_redraw(struct sdl2_console *scon)
>   {
> +    assert(!scon->opengl);
> +
>       if (!scon->surface) {
>           return;
>       }
> diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c
> new file mode 100644
> index 0000000..b8620ca
> --- /dev/null
> +++ b/ui/sdl2-gl.c
> @@ -0,0 +1,114 @@
> +/*
> + * QEMU SDL display driver
> + *
> + * Copyright (c) 2003 Fabrice Bellard

Just as mentioned by Paolo on patch 2, this may be supposed to mention 
you instead.

> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to deal
> + * in the Software without restriction, including without limitation the rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> + * THE SOFTWARE.
> + */
> +/* Ported SDL 1.2 code to 2.0 by Dave Airlie. */

And this line seems wrong.

> +
> +/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
> +#undef WIN32_LEAN_AND_MEAN
> +
> +#include <SDL.h>
> +#include <SDL_syswm.h>
> +#include <SDL_opengl.h>
> +
> +#include "qemu-common.h"
> +#include "ui/console.h"
> +#include "ui/input.h"
> +#include "ui/sdl2.h"
> +#include "sysemu/sysemu.h"
> +
> +static void sdl2_gl_render_surface(struct sdl2_console *scon)
> +{
> +    int ww, wh;
> +
> +    SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
> +
> +    SDL_GetWindowSize(scon->real_window, &ww, &wh);
> +    surface_gl_setup_viewport(scon->surface, ww, wh);
> +
> +    surface_gl_render_texture(scon->surface);
> +    SDL_GL_SwapWindow(scon->real_window);
> +}
> +
> +void sdl2_gl_update(DisplayChangeListener *dcl,
> +                    int x, int y, int w, int h)
> +{
> +    struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
> +
> +    assert(scon->opengl);
> +
> +    SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
> +    surface_gl_update_texture(scon->surface, x, y, w, h);
> +    scon->updates++;
> +}
> +
> +void sdl2_gl_switch(DisplayChangeListener *dcl,
> +                    DisplaySurface *new_surface)
> +{
> +    struct sdl2_console *scon = container_of(dcl, struct sdl2_console, dcl);
> +    DisplaySurface *old_surface = scon->surface;
> +
> +    assert(scon->opengl);
> +
> +    SDL_GL_MakeCurrent(scon->real_window, scon->winctx);
> +    surface_gl_destroy_texture(scon->surface);

Can a surface be in use by multiple DCLs? If so, this would probably 
need reference counting.

> +
> +    scon->surface = new_surface;
> +
> +    if (!new_surface) {
> +        sdl2_window_destroy(scon);
> +        return;
> +    }
> +
> +    if (!scon->real_window) {
> +        sdl2_window_create(scon);
> +    } else if (old_surface &&
> +               ((surface_width(old_surface)  != surface_width(new_surface)) ||
> +                (surface_height(old_surface) != surface_height(new_surface)))) {
> +        sdl2_window_resize(scon);

Hm, now that I think about it... If the window is scaled, this will 
reset the scaling to 100 %. Fine, why not. However, if the new surface 
has the same dimensions as the old surface, the window will not be 
scaled. That would seem strange to me.

Apart from this and the question about surfaces used by multiple DCLs at 
the same time, the patch looks good to me (the option parsing in 
select_display() in vl.c looks like nightmare fuel, but it's just in 
line with its environment).

Max

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 4/4] sdl2: move SDL_* includes to sdl2.h
  2015-01-12 12:35 ` [Qemu-devel] [PATCH 4/4] sdl2: move SDL_* includes to sdl2.h Gerd Hoffmann
@ 2015-01-15 22:21   ` Max Reitz
  0 siblings, 0 replies; 16+ messages in thread
From: Max Reitz @ 2015-01-15 22:21 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: Anthony Liguori

On 2015-01-12 at 07:35, Gerd Hoffmann wrote:
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>   include/ui/sdl2.h | 7 +++++++
>   ui/sdl2-2d.c      | 6 ------
>   ui/sdl2-gl.c      | 7 -------
>   ui/sdl2-input.c   | 6 ------
>   ui/sdl2.c         | 6 ------
>   5 files changed, 7 insertions(+), 25 deletions(-)

Reviewed-by: Max Reitz <mreitz@redhat.com>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 1/4] configure: opengl overhaul
  2015-01-15 19:55   ` Max Reitz
@ 2015-01-16  9:11     ` Gerd Hoffmann
  0 siblings, 0 replies; 16+ messages in thread
From: Gerd Hoffmann @ 2015-01-16  9:11 UTC (permalink / raw)
  To: Max Reitz; +Cc: Paolo Bonzini, Michael Walle, qemu-devel, Anthony Liguori

  Hi,

> > +# opengl probe, used by milkymist-tmu2
> 
> Maybe remove this part of the comment about milkymist?

Will do.

> > +if test "$opengl" != "no" ; then
> > +  opengl_pkgs="gl"
> > +  if $pkg_config $opengl_pkgs; then
> > +    opengl_libs="$($pkg_config --libs $opengl_pkgs) -lX11"
> > +    opengl=yes
> 
> `pkg-config gl` might be successful even without X11 available. In this 
> case, $opengl will be set to 'yes', but linking will probably fail.

Indeed.

> Maybe we should keep GLX separated from OpenGL; for SDL we don't need 
> X11, but for milkymist-tmu2 we apparently do.

That should be only temporary.  There will be infrastructure for device
emulations to ask the UI for a opengl context.  Once this is in place we
should be able to switch over milkymist-tmu2 to that so it doesn't has
to initialize opengl on its own.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions
  2015-01-15 20:46   ` Max Reitz
@ 2015-01-16  9:21     ` Gerd Hoffmann
  2015-01-16 15:05       ` Max Reitz
  0 siblings, 1 reply; 16+ messages in thread
From: Gerd Hoffmann @ 2015-01-16  9:21 UTC (permalink / raw)
  To: Max Reitz; +Cc: qemu-devel, Anthony Liguori

  Hi,

> > +bool console_gl_check_format(DisplayChangeListener *dcl,
> > +                             pixman_format_code_t format)
> > +{
> > +    switch (format) {
> > +    case PIXMAN_x8r8g8b8:
> > +    case PIXMAN_a8r8g8b8:
> > +    case PIXMAN_r5g6b5:
> > +        return true;
> > +    default:
> > +        return false;
> > +    }
> > +}
> 
> What is this function supposed to be used for?

Inflight change, there is a patch series on the list adding a
check_format callback to DisplayChangeListenerOps, for format
negotiation.

> > +
> > +void surface_gl_create_texture(DisplaySurface *surface)
> > +{
> > +    switch (surface->format) {
> > +    case PIXMAN_x8r8g8b8:
> > +    case PIXMAN_a8r8g8b8:
> > +        surface->glformat = GL_BGRA;
> 
> Why does the format code seem to imply ARGB order but you're using the 
> exact opposite? I could imagine something like endianness being the 
> reason, but you're using RGB below where the format code says exactly that.

endianness indeed.  pixman formats are native endian, so this actually
is bgra ordering in memory.  While looking at it:  I guess GL_BGRA is
fixed byte ordering?  So this probably needs fixing to work correctly on
bigendian machines ...

> Discarding the alpha channel is intentional, I suppose?

Yes.

> 
> > +                 surface_width(surface),
> > +                 surface_height(surface),
> > +                 0, surface->glformat, surface->gltype,
> > +                 surface_data(surface));
> 
> Is surface_stride(surface) specified to be surface_width(surface) * 
> bytes_per_pixel (I don't know pixman so I don't know)?

Usually this is the case, but there can be exceptions.  Hmm, can I
explicitly pass the stride?

thanks,
  Gerd

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions
  2015-01-16  9:21     ` Gerd Hoffmann
@ 2015-01-16 15:05       ` Max Reitz
  0 siblings, 0 replies; 16+ messages in thread
From: Max Reitz @ 2015-01-16 15:05 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: qemu-devel, Anthony Liguori

On 2015-01-16 at 04:21, Gerd Hoffmann wrote:
>    Hi,
>
>>> +bool console_gl_check_format(DisplayChangeListener *dcl,
>>> +                             pixman_format_code_t format)
>>> +{
>>> +    switch (format) {
>>> +    case PIXMAN_x8r8g8b8:
>>> +    case PIXMAN_a8r8g8b8:
>>> +    case PIXMAN_r5g6b5:
>>> +        return true;
>>> +    default:
>>> +        return false;
>>> +    }
>>> +}
>> What is this function supposed to be used for?
> Inflight change, there is a patch series on the list adding a
> check_format callback to DisplayChangeListenerOps, for format
> negotiation.

OK.

>>> +
>>> +void surface_gl_create_texture(DisplaySurface *surface)
>>> +{
>>> +    switch (surface->format) {
>>> +    case PIXMAN_x8r8g8b8:
>>> +    case PIXMAN_a8r8g8b8:
>>> +        surface->glformat = GL_BGRA;
>> Why does the format code seem to imply ARGB order but you're using the
>> exact opposite? I could imagine something like endianness being the
>> reason, but you're using RGB below where the format code says exactly that.
> endianness indeed.  pixman formats are native endian, so this actually
> is bgra ordering in memory.  While looking at it:  I guess GL_BGRA is
> fixed byte ordering?

Yes, I think so.

> So this probably needs fixing to work correctly on
> bigendian machines ...

Probably, right.

>> Discarding the alpha channel is intentional, I suppose?
> Yes.
>
>>> +                 surface_width(surface),
>>> +                 surface_height(surface),
>>> +                 0, surface->glformat, surface->gltype,
>>> +                 surface_data(surface));
>> Is surface_stride(surface) specified to be surface_width(surface) *
>> bytes_per_pixel (I don't know pixman so I don't know)?
> Usually this is the case, but there can be exceptions.  Hmm, can I
> explicitly pass the stride?

The internet™ tells me about glPixelStorei(GL_UNPACK_ROW_LENGTH, 
$pixels_per_row) and glPixelStorei(GL_UNPACK_ALIGNMENT, 
$row_alignment_in_bytes) (which need to be called before using 
glTexImage2D() or glTexSubImage2D()). You may want to use it for 
surface_gl_update_texture(), too (if that isn't too much work).

Max

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-01-16 15:05 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-12 12:35 [Qemu-devel] [PATCH 0/4] sdl2: add opengl rendering support Gerd Hoffmann
2015-01-12 12:35 ` [Qemu-devel] [PATCH 1/4] configure: opengl overhaul Gerd Hoffmann
2015-01-12 12:55   ` Paolo Bonzini
2015-01-12 13:11     ` Gerd Hoffmann
2015-01-15 19:55   ` Max Reitz
2015-01-16  9:11     ` Gerd Hoffmann
2015-01-12 12:35 ` [Qemu-devel] [PATCH 2/4] console: add opengl rendering helper functions Gerd Hoffmann
2015-01-12 13:04   ` Paolo Bonzini
2015-01-12 13:13     ` Gerd Hoffmann
2015-01-15 20:46   ` Max Reitz
2015-01-16  9:21     ` Gerd Hoffmann
2015-01-16 15:05       ` Max Reitz
2015-01-12 12:35 ` [Qemu-devel] [PATCH 3/4] sdl2: add support for display rendering using opengl Gerd Hoffmann
2015-01-15 22:14   ` Max Reitz
2015-01-12 12:35 ` [Qemu-devel] [PATCH 4/4] sdl2: move SDL_* includes to sdl2.h Gerd Hoffmann
2015-01-15 22:21   ` Max Reitz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.