Skip to contentSkip to conversation

sdl rendering

PATCH In review Stefano Stabellini 1 participant 3 messages Mar 17, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sdl rendering

Hi all,
I am attaching a patch that adds opengl support for rendering the guest framebuffer in the SDL window. SDL is needed anyway to open the window and handle the events.
Opengl rendering is optional and can be turned off at both compile time and in the vm configuration file. Some of the benefits of using opengl are:

-faster rendering, less CPU intensive, especially with good graphic cards;

-makes the window resizing possible and hardware accelerated, thus very efficient and smooth;

-allows other optimizations like sharing directly a buffer in vram with the guest (not yet implemented).

Regards,

Stefano Stabellini

tools/examples/xmexample.hvm +5 -0
diff -r f33328217eee tools/examples/xmexample.hvm
@@ -135,6 +135,11 @@ sdl=0
 sdl=0
 
 #----------------------------------------------------------------------------
+# enable OpenGL for texture rendering inside the SDL window, default = 1
+# valid only if sdl is enabled.
+opengl=1
+
+#----------------------------------------------------------------------------
 # enable VNC library for graphics, default = 1
 vnc=1
 
tools/ioemu/configure +32 -0
diff -r f33328217eee tools/ioemu/configure
@@ -189,6 +189,8 @@ for opt do
   --static) static="yes"
   ;;
   --disable-sdl) sdl="no"
+  ;;
+  --disable-opengl) opengl="no"
   ;;
   --enable-coreaudio) coreaudio="yes"
   ;;
@@ -539,6 +541,26 @@ fi # -z $sdl
 fi # -z $sdl
 
 ##########################################
+# OpenGL test
+
+if test -z "$opengl" && test "$sdl" = "yes"
+then
+cat > $TMPC << EOF
+#include <GL/gl.h>
+#ifndef GL_TEXTURE_RECTANGLE_ARB
+#error "Opengl doesn't support GL_TEXTURE_RECTANGLE_ARB"
+#endif
+int main( void ) { return (int) glGetString(GL_EXTENSIONS); }
+EOF
+if $cc -o $TMPE $TMPC -lGL 2> /dev/null
+then
+opengl="yes"
+else
+opengl="no"
+fi
+fi
+
+##########################################
 # alsa sound support libraries
 
 if test "$alsa" = "yes" ; then
@@ -612,6 +634,7 @@ if test "$sdl" != "no" ; then
 if test "$sdl" != "no" ; then
     echo "SDL static link   $sdl_static"
 fi
+echo "OpenGL support    $opengl"
 echo "mingw32 support   $mingw32"
 echo "Adlib support     $adlib"
 echo "CoreAudio support $coreaudio"
@@ -995,6 +1018,15 @@ if test "$target_user_only" = "no"; then
     fi
 fi
 
+if test $opengl = "yes"
+then
+    echo "#define CONFIG_OPENGL 1" >> $config_h
+    echo "CONFIG_OPENGL=yes" >> $config_mak
+    echo "SDL_CFLAGS+=-I/usr/include/GL" >> $config_mak
+    echo "SDL_LIBS+=-lXext" >> $config_mak
+    echo "SDL_LIBS+=-lGL" >> $config_mak
+fi
+
 if test "$cocoa" = "yes" ; then
     echo "#define CONFIG_COCOA 1" >> $config_h
     echo "CONFIG_COCOA=yes" >> $config_mak
tools/ioemu/sdl.c +156 -10

241 lines not on this page · raw message

tools/ioemu/vl.c +14 -1
diff -r f33328217eee tools/ioemu/vl.c
@@ -174,6 +174,11 @@ int graphic_height = 600;
 #endif
 int graphic_depth = 15;
 int full_screen = 0;
+#ifdef CONFIG_OPENGL
+int opengl_enabled = 1;
+#else
+int opengl_enabled = 0;
+#endif
 int no_quit = 0;
 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
@@ -6482,6 +6487,9 @@ void help(void)
 #ifdef CONFIG_SDL
            "-no-quit        disable SDL window close capability\n"
 #endif
+#ifdef CONFIG_OPENGL
+           "-disable-opengl disable OpenGL rendering, using SDL"
+#endif
 #ifdef TARGET_I386
            "-no-fd-bootchk  disable boot signature checking for floppy disks\n"
 #endif
@@ -6660,6 +6668,7 @@ enum {
     QEMU_OPTION_loadvm,
     QEMU_OPTION_full_screen,
     QEMU_OPTION_no_quit,
+    QEMU_OPTION_disable_opengl,
     QEMU_OPTION_pidfile,
     QEMU_OPTION_no_kqemu,
     QEMU_OPTION_kernel_kqemu,
@@ -6757,6 +6766,7 @@ const QEMUOption qemu_options[] = {
 #ifdef CONFIG_SDL
     { "no-quit", 0, QEMU_OPTION_no_quit },
 #endif
+    { "disable-opengl", 0, QEMU_OPTION_disable_opengl },
     { "pidfile", HAS_ARG, QEMU_OPTION_pidfile },
     { "win2k-hack", 0, QEMU_OPTION_win2k_hack },
     { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
@@ -7528,6 +7538,9 @@ int main(int argc, char **argv)
                 no_quit = 1;
                 break;
 #endif
+            case QEMU_OPTION_disable_opengl:
+                opengl_enabled = 0;
+                break;
             case QEMU_OPTION_pidfile:
                 create_pidfile(optarg);
                 break;
@@ -7854,7 +7867,7 @@ int main(int argc, char **argv)
 	xenstore_write_vncport(vnc_display_port);
     } else {
 #if defined(CONFIG_SDL)
-        sdl_display_init(ds, full_screen);
+        sdl_display_init(ds, full_screen, opengl_enabled);
 #elif defined(CONFIG_COCOA)
         cocoa_display_init(ds, full_screen);
 #else
tools/ioemu/vl.h +1 -1
diff -r f33328217eee tools/ioemu/vl.h
@@ -982,7 +982,7 @@ void isa_cirrus_vga_init(DisplayState *d
                          unsigned long vga_ram_offset, int vga_ram_size);
 
 /* sdl.c */
-void sdl_display_init(DisplayState *ds, int full_screen);
+void sdl_display_init(DisplayState *ds, int full_screen, int opengl_enable);
 
 /* cocoa.m */
 void cocoa_display_init(DisplayState *ds, int full_screen);
tools/python/xen/xend/XendConfig.py +1 -1
diff -r f33328217eee tools/python/xen/xend/XendConfig.py
@@ -126,7 +126,7 @@ LEGACY_CFG_TO_XENAPI_CFG = reverse_dict(
 # Platform configuration keys.
 XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'boot', 'device_model', 'loader', 'display', 
                         'fda', 'fdb', 'keymap', 'isa', 'localtime', 'monitor', 
-                        'nographic', 'pae', 'rtc_timeoffset', 'serial', 'sdl',
+                        'nographic', 'pae', 'rtc_timeoffset', 'serial', 'sdl', 'opengl',
                         'soundhw','stdvga', 'usb', 'usbdevice', 'hpet', 'vnc',
                         'vncconsole', 'vncdisplay', 'vnclisten', 'timer_mode',
                         'vncpasswd', 'vncunused', 'xauthority', 'pci', 'vhpt',
tools/python/xen/xend/image.py +2 -1
diff -r f33328217eee tools/python/xen/xend/image.py
@@ -262,7 +262,8 @@ class ImageHandler:
 
         elif has_sdl:
             # SDL is default in QEMU.
-            pass
+            if int(vmConfig['platform'].get('opengl', 1)) != 1 :
+                ret.append('-disable-opengl')
         else:
             ret.append('-nographic')
 
tools/python/xen/xm/create.py +5 -1
diff -r f33328217eee tools/python/xen/xm/create.py
@@ -503,6 +503,10 @@ gopts.var('sdl', val='',
 gopts.var('sdl', val='',
           fn=set_value, default=None,
           use="""Should the device model use SDL?""")
+
+gopts.var('opengl', val='',
+          fn=set_value, default=None,
+          use="""Enable\Disable OpenGL""")
 
 gopts.var('display', val='DISPLAY',
           fn=set_value, default=None,
@@ -745,7 +749,7 @@ def configure_hvm(config_image, vals):
              'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
              'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',
              'acpi', 'apic', 'usb', 'usbdevice', 'keymap', 'pci', 'hpet',
-             'guest_os_type', 'hap']
+             'guest_os_type', 'hap', 'opengl']
 
     for a in args:
         if a in vals.__dict__ and vals.__dict__[a] is not None:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

sorry the topic should be "opengl rendering".

Quoted 20 lines · Stefano Stabellini

Hi all,
I am attaching a patch that adds opengl support for rendering the guest framebuffer in the SDL window. SDL is needed anyway to open the window and handle the events.
Opengl rendering is optional and can be turned off at both compile time and in the vm configuration file. Some of the benefits of using opengl are:

(quoted diff) +0 -2
-faster rendering, less CPU intensive, especially with good graphic cards;
 
-makes the window resizing possible and hardware accelerated, thus very 

efficient and smooth;

-allows other optimizations like sharing directly a buffer in vram with the guest (not yet implemented).

Regards,

Stefano Stabellini

#2 lore raw
In reply to Stefano Stabellini

Little correction: letting opengl decide the texture internal format.

Quoted 14 lines · Stefano Stabellini

Hi all,
I am attaching a patch that adds opengl support for rendering the guest framebuffer in the SDL window. SDL is needed anyway to open the window and handle the events.
Opengl rendering is optional and can be turned off at both compile time and in the vm configuration file. Some of the benefits of using opengl are:

(quoted diff) +0 -2
-faster rendering, less CPU intensive, especially with good graphic cards;
 
-makes the window resizing possible and hardware accelerated, thus very 

efficient and smooth;

-allows other optimizations like sharing directly a buffer in vram with the guest (not yet implemented).

Quoted 6 lines

Regards,

Stefano Stabellini

tools/examples/xmexample.hvm +5 -0
diff -r f33328217eee tools/examples/xmexample.hvm
@@ -135,6 +135,11 @@ sdl=0
 sdl=0
 
 #----------------------------------------------------------------------------
+# enable OpenGL for texture rendering inside the SDL window, default = 1
+# valid only if sdl is enabled.
+opengl=1
+
+#----------------------------------------------------------------------------
 # enable VNC library for graphics, default = 1
 vnc=1
 
tools/ioemu/configure +32 -0
diff -r f33328217eee tools/ioemu/configure
@@ -189,6 +189,8 @@ for opt do
   --static) static="yes"
   ;;
   --disable-sdl) sdl="no"
+  ;;
+  --disable-opengl) opengl="no"
   ;;
   --enable-coreaudio) coreaudio="yes"
   ;;
@@ -539,6 +541,26 @@ fi # -z $sdl
 fi # -z $sdl
 
 ##########################################
+# OpenGL test
+
+if test -z "$opengl" && test "$sdl" = "yes"
+then
+cat > $TMPC << EOF
+#include <GL/gl.h>
+#ifndef GL_TEXTURE_RECTANGLE_ARB
+#error "Opengl doesn't support GL_TEXTURE_RECTANGLE_ARB"
+#endif
+int main( void ) { return (int) glGetString(GL_EXTENSIONS); }
+EOF
+if $cc -o $TMPE $TMPC -lGL 2> /dev/null
+then
+opengl="yes"
+else
+opengl="no"
+fi
+fi
+
+##########################################
 # alsa sound support libraries
 
 if test "$alsa" = "yes" ; then
@@ -612,6 +634,7 @@ if test "$sdl" != "no" ; then
 if test "$sdl" != "no" ; then
     echo "SDL static link   $sdl_static"
 fi
+echo "OpenGL support    $opengl"
 echo "mingw32 support   $mingw32"
 echo "Adlib support     $adlib"
 echo "CoreAudio support $coreaudio"
@@ -995,6 +1018,15 @@ if test "$target_user_only" = "no"; then
     fi
 fi
 
+if test $opengl = "yes"
+then
+    echo "#define CONFIG_OPENGL 1" >> $config_h
+    echo "CONFIG_OPENGL=yes" >> $config_mak
+    echo "SDL_CFLAGS+=-I/usr/include/GL" >> $config_mak
+    echo "SDL_LIBS+=-lXext" >> $config_mak
+    echo "SDL_LIBS+=-lGL" >> $config_mak
+fi
+
 if test "$cocoa" = "yes" ; then
     echo "#define CONFIG_COCOA 1" >> $config_h
     echo "CONFIG_COCOA=yes" >> $config_mak
tools/ioemu/sdl.c +156 -10

241 lines not on this page · raw message

tools/ioemu/vl.c +14 -1
diff -r f33328217eee tools/ioemu/vl.c
@@ -174,6 +174,11 @@ int graphic_height = 600;
 #endif
 int graphic_depth = 15;
 int full_screen = 0;
+#ifdef CONFIG_OPENGL
+int opengl_enabled = 1;
+#else
+int opengl_enabled = 0;
+#endif
 int no_quit = 0;
 CharDriverState *serial_hds[MAX_SERIAL_PORTS];
 CharDriverState *parallel_hds[MAX_PARALLEL_PORTS];
@@ -6482,6 +6487,9 @@ void help(void)
 #ifdef CONFIG_SDL
            "-no-quit        disable SDL window close capability\n"
 #endif
+#ifdef CONFIG_OPENGL
+           "-disable-opengl disable OpenGL rendering, using SDL"
+#endif
 #ifdef TARGET_I386
            "-no-fd-bootchk  disable boot signature checking for floppy disks\n"
 #endif
@@ -6660,6 +6668,7 @@ enum {
     QEMU_OPTION_loadvm,
     QEMU_OPTION_full_screen,
     QEMU_OPTION_no_quit,
+    QEMU_OPTION_disable_opengl,
     QEMU_OPTION_pidfile,
     QEMU_OPTION_no_kqemu,
     QEMU_OPTION_kernel_kqemu,
@@ -6757,6 +6766,7 @@ const QEMUOption qemu_options[] = {
 #ifdef CONFIG_SDL
     { "no-quit", 0, QEMU_OPTION_no_quit },
 #endif
+    { "disable-opengl", 0, QEMU_OPTION_disable_opengl },
     { "pidfile", HAS_ARG, QEMU_OPTION_pidfile },
     { "win2k-hack", 0, QEMU_OPTION_win2k_hack },
     { "usbdevice", HAS_ARG, QEMU_OPTION_usbdevice },
@@ -7528,6 +7538,9 @@ int main(int argc, char **argv)
                 no_quit = 1;
                 break;
 #endif
+            case QEMU_OPTION_disable_opengl:
+                opengl_enabled = 0;
+                break;
             case QEMU_OPTION_pidfile:
                 create_pidfile(optarg);
                 break;
@@ -7854,7 +7867,7 @@ int main(int argc, char **argv)
 	xenstore_write_vncport(vnc_display_port);
     } else {
 #if defined(CONFIG_SDL)
-        sdl_display_init(ds, full_screen);
+        sdl_display_init(ds, full_screen, opengl_enabled);
 #elif defined(CONFIG_COCOA)
         cocoa_display_init(ds, full_screen);
 #else
tools/ioemu/vl.h +1 -1
diff -r f33328217eee tools/ioemu/vl.h
@@ -982,7 +982,7 @@ void isa_cirrus_vga_init(DisplayState *d
                          unsigned long vga_ram_offset, int vga_ram_size);
 
 /* sdl.c */
-void sdl_display_init(DisplayState *ds, int full_screen);
+void sdl_display_init(DisplayState *ds, int full_screen, int opengl_enable);
 
 /* cocoa.m */
 void cocoa_display_init(DisplayState *ds, int full_screen);
tools/python/xen/xend/XendConfig.py +1 -1
diff -r f33328217eee tools/python/xen/xend/XendConfig.py
@@ -126,7 +126,7 @@ LEGACY_CFG_TO_XENAPI_CFG = reverse_dict(
 # Platform configuration keys.
 XENAPI_PLATFORM_CFG = [ 'acpi', 'apic', 'boot', 'device_model', 'loader', 'display', 
                         'fda', 'fdb', 'keymap', 'isa', 'localtime', 'monitor', 
-                        'nographic', 'pae', 'rtc_timeoffset', 'serial', 'sdl',
+                        'nographic', 'pae', 'rtc_timeoffset', 'serial', 'sdl', 'opengl',
                         'soundhw','stdvga', 'usb', 'usbdevice', 'hpet', 'vnc',
                         'vncconsole', 'vncdisplay', 'vnclisten', 'timer_mode',
                         'vncpasswd', 'vncunused', 'xauthority', 'pci', 'vhpt',
tools/python/xen/xend/image.py +2 -1
diff -r f33328217eee tools/python/xen/xend/image.py
@@ -262,7 +262,8 @@ class ImageHandler:
 
         elif has_sdl:
             # SDL is default in QEMU.
-            pass
+            if int(vmConfig['platform'].get('opengl', 1)) != 1 :
+                ret.append('-disable-opengl')
         else:
             ret.append('-nographic')
 
tools/python/xen/xm/create.py +5 -1
diff -r f33328217eee tools/python/xen/xm/create.py
@@ -503,6 +503,10 @@ gopts.var('sdl', val='',
 gopts.var('sdl', val='',
           fn=set_value, default=None,
           use="""Should the device model use SDL?""")
+
+gopts.var('opengl', val='',
+          fn=set_value, default=None,
+          use="""Enable\Disable OpenGL""")
 
 gopts.var('display', val='DISPLAY',
           fn=set_value, default=None,
@@ -745,7 +749,7 @@ def configure_hvm(config_image, vals):
              'vnc', 'vncdisplay', 'vncunused', 'vncconsole', 'vnclisten',
              'sdl', 'display', 'xauthority', 'rtc_timeoffset', 'monitor',
              'acpi', 'apic', 'usb', 'usbdevice', 'keymap', 'pci', 'hpet',
-             'guest_os_type', 'hap']
+             'guest_os_type', 'hap', 'opengl']
 
     for a in args:
         if a in vals.__dict__ and vals.__dict__[a] is not None:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel