[cogl] Add support for the WebOS version of SDL



commit 3726c60deab2bd94617a562abb63f735627a25e4
Author: Neil Roberts <neil linux intel com>
Date:   Mon Dec 19 11:51:58 2011 +0000

    Add support for the WebOS version of SDL
    
    The stock 1.2.x version of SDL only supports regular OpenGL. The
    version on WebOS is specially patched to add some extra API to request
    a GLES1 or GLES2 context. This patch adds a configure check to detect
    when Cogl is being built with the patched version of SDL. In that case
    it will additionally allow the gles1 and gles2 drivers and set the
    right video mode attributes to get the corresponding context.
    
    Reviewed-by: Robert Bragg <robert linux intel com>

 cogl/winsys/cogl-winsys-sdl.c |   40 +++++++++++++++++++++++-
 configure.ac                  |   68 ++++++++++++++++++++++++++--------------
 2 files changed, 82 insertions(+), 26 deletions(-)
---
diff --git a/cogl/winsys/cogl-winsys-sdl.c b/cogl/winsys/cogl-winsys-sdl.c
index a8c3520..58c177a 100644
--- a/cogl/winsys/cogl-winsys-sdl.c
+++ b/cogl/winsys/cogl-winsys-sdl.c
@@ -47,12 +47,18 @@ typedef struct _CoglDisplaySdl
 {
   SDL_Surface *surface;
   CoglBool has_onscreen;
+  Uint32 video_mode_flags;
 } CoglDisplaySdl;
 
 static CoglFuncPtr
 _cogl_winsys_renderer_get_proc_address (CoglRenderer *renderer,
                                         const char *name)
 {
+#ifdef COGL_HAS_SDL_GLES_SUPPORT
+  if (renderer->driver != COGL_DRIVER_GL)
+    return SDL_GLES_GetProcAddress (name);
+#endif
+
   return SDL_GL_GetProcAddress (name);
 }
 
@@ -68,6 +74,7 @@ static CoglBool
 _cogl_winsys_renderer_connect (CoglRenderer *renderer,
                                GError **error)
 {
+#ifndef COGL_HAS_SDL_GLES_SUPPORT
   if (renderer->driver != COGL_DRIVER_GL)
     {
       g_set_error (error, COGL_WINSYS_ERROR,
@@ -75,6 +82,7 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
                    "The SDL winsys only supports the GL driver");
       return FALSE;
     }
+#endif /* COGL_HAS_SDL_GLES_SUPPORT */
 
   if (SDL_Init (SDL_INIT_VIDEO) == -1)
     {
@@ -134,11 +142,37 @@ _cogl_winsys_display_setup (CoglDisplay *display,
 
   set_gl_attribs_from_framebuffer_config (&display->onscreen_template->config);
 
+  switch (display->renderer->driver)
+    {
+    case COGL_DRIVER_GL:
+      sdl_display->video_mode_flags = SDL_OPENGL;
+      break;
+
+#ifdef COGL_HAS_SDL_GLES_SUPPORT
+    case COGL_DRIVER_GLES2:
+      sdl_display->video_mode_flags = SDL_OPENGLES;
+      SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+      SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 0);
+      break;
+
+    case COGL_DRIVER_GLES1:
+      sdl_display->video_mode_flags = SDL_OPENGLES;
+      SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 1);
+      SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 1);
+      break;
+#endif /* COGL_HAS_SDL_GLES_SUPPORT */
+
+    default:
+      g_assert_not_reached ();
+    }
+
   /* There's no way to know what size the application will need until
      it creates the first onscreen but we need to set the video mode
      now so that we can get a GL context. We'll have to just guess at
      a size an resize it later */
-  sdl_display->surface = SDL_SetVideoMode (640, 480, 0, SDL_OPENGL);
+  sdl_display->surface = SDL_SetVideoMode (640, 480, /* width/height */
+                                           0, /* bitsperpixel */
+                                           sdl_display->video_mode_flags);
 
   if (sdl_display->surface == NULL)
     {
@@ -213,7 +247,9 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
   if (width != sdl_display->surface->w ||
       height != sdl_display->surface->h)
     {
-      sdl_display->surface = SDL_SetVideoMode (width, height, 0, SDL_OPENGL);
+      sdl_display->surface = SDL_SetVideoMode (width, height,
+                                               0, /* bitsperpixel */
+                                               sdl_display->video_mode_flags);
 
       if (sdl_display->surface == NULL)
         {
diff --git a/configure.ac b/configure.ac
index 88ab27d..2ba1a7c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -447,7 +447,6 @@ AS_IF([test "x$enable_gles1" = "xyes"],
         PKG_CHECK_EXISTS([glesv1_cm],
           [COGL_PKG_REQUIRES_GL="$COGL_PKG_REQUIRES_GL glesv1_cm"
            COGL_GLES1_LIBNAME="libGLESv1_CM.so"
-           NEED_EGL=yes
           ],
           [
             # We have to check the two headers independently as GLES/glext.h
@@ -542,8 +541,6 @@ AS_IF([test "x$enable_gles2" = "xyes"],
 
             COGL_GLES2_LIBNAME="libGLESv2.so"
           ])
-
-        NEED_EGL=yes
       ])
 
 HAVE_GL=0
@@ -681,6 +678,46 @@ AS_IF([test "x$enable_wgl" = "xyes"],
       ])
 AM_CONDITIONAL(SUPPORT_WGL, [test "x$SUPPORT_WGL" = "xyes"])
 
+AC_ARG_ENABLE(
+  [sdl],
+  [AC_HELP_STRING([--enable-sdl=@<:@no/yes@:>@], [Enable support SDL @<:@default=no@:>@])],
+  [],
+  [enable_sdl=no])
+AS_IF([test "x$enable_sdl" = "xyes"],
+      [
+        PKG_CHECK_MODULES([SDL],
+                          [sdl],
+                          [],
+                          [AC_MSG_ERROR([SDL support requested but SDL not found])])
+
+        SUPPORT_SDL=yes
+        GL_WINSYS_APIS="$GL_WINSYS_APIS sdl"
+        COGL_PKG_REQUIRES="$COGL_PKG_REQUIRES sdl"
+
+        COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_SUPPORT"
+
+        dnl WebOS has a specially patched version of SDL to add
+        dnl support for creating a GLES1/2 context. This tries to
+        dnl detect that patch so we can use it if the GLES2 driver is
+        dnl selected.
+        cogl_save_CPPFLAGS="$CPPFLAGS"
+        CPPFLAGS="$CPPFLAGS $SDL_CFLAGS"
+        AC_CHECK_DECL([SDL_OPENGLES],
+                      [SUPPORT_SDL_GLES=yes],
+                      [SUPPORT_SDL_GLES=no],
+                      [#include <SDL.h>])
+        AC_CHECK_DECL([SDL_GL_CONTEXT_MAJOR_VERSION], [], [SUPPORT_SDL_GLES=no],
+                      [#include <SDL.h>])
+        AC_CHECK_DECL([SDL_GL_CONTEXT_MINOR_VERSION], [], [SUPPORT_SDL_GLES=no],
+                      [#include <SDL.h>])
+        CPPFLAGS="$cogl_save_CPPFLAGS"
+
+        AS_IF([test "x$SUPPORT_SDL_GLES" = "xyes"],
+              COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_GLES_SUPPORT")
+      ],
+      [SUPPORT_SDL=no])
+AM_CONDITIONAL(SUPPORT_SDL, [test "x$SUPPORT_SDL" = "xyes"])
+
 EGL_PLATFORM_COUNT=0
 
 AC_ARG_ENABLE(
@@ -823,7 +860,7 @@ AC_ARG_ENABLE(
   [xlib-egl-platform],
   [AC_HELP_STRING([--enable-xlib-egl-platform=@<:@no/yes@:>@], [Enable support for the Xlib egl platform @<:@default=auto@:>@])],
   [],
-  AS_IF([test "x$enable_gles1" = "xyes" -o "x$enable_gles2" = "xyes" && test $EGL_PLATFORM_COUNT -eq 0],
+  AS_IF([test "x$enable_gles1" = "xyes" -o "x$enable_gles2" = "xyes" && test "x$SUPPORT_SDL_GLES" != "xyes" && test $EGL_PLATFORM_COUNT -eq 0],
         [enable_xlib_egl_platform=yes], [enable_xlib_egl_platform=no])
 )
 AS_IF([test "x$enable_xlib_egl_platform" = "xyes"],
@@ -875,26 +912,6 @@ AS_IF([test "x$NEED_EGL" = "xyes"],
 
 AM_CONDITIONAL(SUPPORT_EGL, [test "x$SUPPORT_EGL" = "xyes"])
 
-AC_ARG_ENABLE(
-  [sdl],
-  [AC_HELP_STRING([--enable-sdl=@<:@no/yes@:>@], [Enable support SDL @<:@default=no@:>@])],
-  [],
-  [enable_sdl=no])
-AS_IF([test "x$enable_sdl" = "xyes"],
-      [
-        PKG_CHECK_EXISTS([sdl],
-                         [],
-                         [AC_MSG_ERROR([SDL support requested but SDL not found])])
-
-        SUPPORT_SDL=yes
-        GL_WINSYS_APIS="$GL_WINSYS_APIS sdl"
-        COGL_PKG_REQUIRES="$COGL_PKG_REQUIRES sdl"
-
-        COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_SDL_SUPPORT"
-      ],
-      [SUPPORT_SDL=no])
-AM_CONDITIONAL(SUPPORT_SDL, [test "x$SUPPORT_SDL" = "xyes"])
-
 dnl         ========================================================
 dnl         Check X11 dependencies if required
 dnl         ========================================================
@@ -1165,6 +1182,9 @@ if test "x$SUPPORT_EGL" = "xyes"; then
 echo "        EGL Platforms:${EGL_PLATFORMS}"
 echo "        Wayland compositor support: ${enable_wayland_egl_server}"
 fi
+if test "x$SUPPORT_SDL" = "xyes"; then
+echo "        Support GLES under SDL: ${SUPPORT_SDL_GLES}"
+fi
 echo "        Image backend: ${COGL_IMAGE_BACKEND}"
 echo "        Cogl Pango: ${enable_cogl_pango}"
 echo "        Profiling: ${enable_profile}"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]