changeset 3161:494559cc723b

OpenPandora support added by David Carré
author Sam Lantinga <slouken@libsdl.org>
date Sun, 31 May 2009 11:53:12 +0000
parents 210e209b87cc
children dc1eb82ffdaa
files CREDITS Makefile.pandora README.pandora src/video/SDL_renderer_gles.c src/video/SDL_sysvideo.h src/video/SDL_video.c src/video/pandora/SDL_pandora.c src/video/pandora/SDL_pandora.h src/video/pandora/SDL_pandora_events.c src/video/pandora/SDL_pandora_events.h src/video/x11/SDL_x11window.c
diffstat 11 files changed, 1139 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/CREDITS	Thu May 28 09:39:14 2009 +0000
+++ b/CREDITS	Sun May 31 11:53:12 2009 +0000
@@ -44,10 +44,12 @@
 
 * Eric Wing, Max Horn, and Darrell Walisser for unflagging work on the Mac OS X port
 
-* Couriersud for the DirectFB driver
+* David Carré, for the Pandora port
 
 * Patrice Mandin, for the Atari port
 
+* Couriersud for the DirectFB driver
+
 * Jon Atkins for SDL_image, SDL_mixer and SDL_net documentation
 
 * Arne Claus, for the 2004 winning SDL logo,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile.pandora	Sun May 31 11:53:12 2009 +0000
@@ -0,0 +1,37 @@
+# Makefile to build the pandora SDL library
+
+AR	= arm-none-linux-gnueabi-ar
+RANLIB	= arm-none-linux-gnueabi-ranlib
+CC = arm-none-linux-gnueabi-gcc
+CXX = arm-none-linux-gnueabi-g++
+STRIP = arm-none-linux-gnueabi-strip
+
+CFLAGS  = -O3 -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfloat-abi=softfp \
+	-mfpu=neon -ftree-vectorize -ffast-math -fomit-frame-pointer -fno-strict-aliasing -fsingle-precision-constant \
+	-I./include -I$(PNDSDK)/usr/include
+
+TARGET  = libSDL.a
+
+SOURCES = ./src/*.c ./src/audio/*.c ./src/cdrom/*.c ./src/cpuinfo/*.c ./src/events/*.c \
+	./src/file/*.c ./src/stdlib/*.c ./src/thread/*.c ./src/timer/*.c ./src/video/*.c \
+	./src/joystick/*.c ./src/haptic/*.c ./src/video/dummy/*.c ./src/audio/disk/*.c \
+	./src/audio/dummy/*.c ./src/loadso/dlopen/*.c ./src/audio/dsp/*.c ./src/audio/dma/*.c \
+	./src/thread/pthread/SDL_systhread.c ./src/thread/pthread/SDL_syssem.c \
+	./src/thread/pthread/SDL_sysmutex.c ./src/thread/pthread/SDL_syscond.c \
+	./src/joystick/linux/*.c ./src/haptic/linux/*.c ./src/timer/unix/*.c ./src/cdrom/dummy/*.c \
+	./src/video/pandora/SDL_pandora.o ./src/video/pandora/SDL_pandora_events.o ./src/video/x11/*.c
+	
+
+OBJECTS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g')
+
+all: $(TARGET)
+
+$(TARGET): $(CONFIG_H) $(OBJECTS)
+	$(AR) crv $@ $^
+	$(RANLIB) $@
+
+$(CONFIG_H):
+	cp include/SDL_config_pandora.h include/SDL_config.h
+
+clean:
+	rm -f $(TARGET) $(OBJECTS)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.pandora	Sun May 31 11:53:12 2009 +0000
@@ -0,0 +1,16 @@
+SDL 1.3 with open pandora console support ( http://openpandora.org/ )
+=====================================================================
+
+- A pandora specific video driver was writed to allow SDL 1.3 with OpenGL ES
+support to work on the pandora under the framebuffer. This driver do not have
+input support for now, so if you use it you will have to add your own control code.
+The video driver name is "pandora" so if you have problem running it from
+the framebuffer, try to set the following variable before starting your application :
+"export SDL_VIDEODRIVER=pandora"
+
+- OpenGL ES support was added to the x11 driver, so it's working like the normal
+x11 driver one with OpenGLX support, with SDL input event's etc..
+
+
+David Carré (Cpasjuste)
+cpasjuste@gmail.com
--- a/src/video/SDL_renderer_gles.c	Thu May 28 09:39:14 2009 +0000
+++ b/src/video/SDL_renderer_gles.c	Sun May 31 11:53:12 2009 +0000
@@ -42,6 +42,14 @@
 
 #endif /* __QNXNTO__ */
 
+#if SDL_VIDEO_DRIVER_PANDORA
+GL_API void GL_APIENTRY
+glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
+{
+    return;
+}
+#endif /* SDL_VIDEO_DRIVER_PANDORA */
+
 /* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
 
 static const float inv255f = 1.0f / 255.0f;
@@ -284,7 +292,10 @@
             renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
         }
     }
-
+#if SDL_VIDEO_DRIVER_PANDORA
+    data->GL_OES_draw_texture_supported = SDL_FALSE;
+    data->useDrawTexture = SDL_FALSE;
+#else
     if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) {
         data->GL_OES_draw_texture_supported = SDL_TRUE;
         data->useDrawTexture = SDL_TRUE;
@@ -292,6 +303,7 @@
         data->GL_OES_draw_texture_supported = SDL_FALSE;
         data->useDrawTexture = SDL_FALSE;
     }
+#endif
 
     data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
     renderer->info.max_texture_width = value;
--- a/src/video/SDL_sysvideo.h	Thu May 28 09:39:14 2009 +0000
+++ b/src/video/SDL_sysvideo.h	Sun May 31 11:53:12 2009 +0000
@@ -318,6 +318,10 @@
     void *driverdata;
     struct SDL_GLDriverData *gl_data;
 
+#if SDL_VIDEO_DRIVER_PANDORA
+    struct SDL_PrivateGLESData *gles_data;
+#endif
+
     /* * * */
     /* The function used to dispose of this structure */
     void (*free) (_THIS);
@@ -403,6 +407,9 @@
 #if SDL_VIDEO_DRIVER_NDS
 extern VideoBootStrap NDS_bootstrap;
 #endif
+#if SDL_VIDEO_DRIVER_PANDORA
+extern VideoBootStrap PND_bootstrap;
+#endif
 
 #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
 
--- a/src/video/SDL_video.c	Thu May 28 09:39:14 2009 +0000
+++ b/src/video/SDL_video.c	Sun May 31 11:53:12 2009 +0000
@@ -121,6 +121,9 @@
 #if SDL_VIDEO_DRIVER_DUMMY
     &DUMMY_bootstrap,
 #endif
+#if SDL_VIDEO_DRIVER_PANDORA
+    &PND_bootstrap,
+#endif
     NULL
 };
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/pandora/SDL_pandora.c	Sun May 31 11:53:12 2009 +0000
@@ -0,0 +1,858 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2009 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+
+    Open Pandora SDL driver
+    Copyright (C) 2009 David Carré
+    (cpasjuste@gmail.com)
+*/
+
+/* SDL internals */
+#include "SDL_config.h"
+#include "../SDL_sysvideo.h"
+#include "SDL_version.h"
+#include "SDL_syswm.h"
+#include "SDL_loadso.h"
+#include "SDL_events.h"
+#include "../../events/SDL_mouse_c.h"
+#include "../../events/SDL_keyboard_c.h"
+
+/* PND declarations */
+#include "SDL_pandora.h"
+#include "SDL_pandora_events.h"
+
+static SDL_bool PND_initialized = SDL_FALSE;
+
+static int
+PND_available(void)
+{
+    return 1;
+}
+
+static void
+PND_destroy(SDL_VideoDevice * device)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata;
+
+    if (device->driverdata != NULL) {
+        device->driverdata = NULL;
+    }
+}
+
+static SDL_VideoDevice *
+PND_create()
+{
+    SDL_VideoDevice *device;
+    SDL_VideoData *phdata;
+    int status;
+
+    /* Check if pandora could be initialized */
+    status = PND_available();
+    if (status == 0) {
+        /* PND could not be used */
+        return NULL;
+    }
+
+    /* Initialize SDL_VideoDevice structure */
+    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
+    if (device == NULL) {
+        SDL_OutOfMemory();
+        return NULL;
+    }
+
+    /* Initialize internal Pandora specific data */
+    phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
+    if (phdata == NULL) {
+        SDL_OutOfMemory();
+        SDL_free(device);
+        return NULL;
+    }
+
+    device->driverdata = phdata;
+
+    phdata->egl_initialized = SDL_TRUE;
+
+
+    /* Setup amount of available displays and current display */
+    device->num_displays = 1;
+    device->current_display = 1;
+
+    /* Set device free function */
+    device->free = PND_destroy;
+
+    /* Setup all functions which we can handle */
+    device->VideoInit = PND_videoinit;
+    device->VideoQuit = PND_videoquit;
+    device->GetDisplayModes = PND_getdisplaymodes;
+    device->SetDisplayMode = PND_setdisplaymode;
+    device->SetDisplayPalette = PND_setdisplaypalette;
+    device->GetDisplayPalette = PND_getdisplaypalette;
+    device->SetDisplayGammaRamp = PND_setdisplaygammaramp;
+    device->GetDisplayGammaRamp = PND_getdisplaygammaramp;
+    device->CreateWindow = PND_createwindow;
+    device->CreateWindowFrom = PND_createwindowfrom;
+    device->SetWindowTitle = PND_setwindowtitle;
+    device->SetWindowIcon = PND_setwindowicon;
+    device->SetWindowPosition = PND_setwindowposition;
+    device->SetWindowSize = PND_setwindowsize;
+    device->ShowWindow = PND_showwindow;
+    device->HideWindow = PND_hidewindow;
+    device->RaiseWindow = PND_raisewindow;
+    device->MaximizeWindow = PND_maximizewindow;
+    device->MinimizeWindow = PND_minimizewindow;
+    device->RestoreWindow = PND_restorewindow;
+    device->SetWindowGrab = PND_setwindowgrab;
+    device->DestroyWindow = PND_destroywindow;
+    device->GetWindowWMInfo = PND_getwindowwminfo;
+    device->GL_LoadLibrary = PND_gl_loadlibrary;
+    device->GL_GetProcAddress = PND_gl_getprocaddres;
+    device->GL_UnloadLibrary = PND_gl_unloadlibrary;
+    device->GL_CreateContext = PND_gl_createcontext;
+    device->GL_MakeCurrent = PND_gl_makecurrent;
+    device->GL_SetSwapInterval = PND_gl_setswapinterval;
+    device->GL_GetSwapInterval = PND_gl_getswapinterval;
+    device->GL_SwapWindow = PND_gl_swapwindow;
+    device->GL_DeleteContext = PND_gl_deletecontext;
+    device->PumpEvents = PND_PumpEvents;
+
+    return device;
+}
+
+VideoBootStrap PND_bootstrap = {
+    "pandora",
+    "SDL Pandora Video Driver",
+    PND_available,
+    PND_create
+};
+
+/*****************************************************************************/
+/* SDL Video and Display initialization/handling functions                   */
+/*****************************************************************************/
+int
+PND_videoinit(_THIS)
+{
+    SDL_VideoDisplay display;
+    SDL_DisplayMode current_mode;
+
+    SDL_zero(current_mode);
+    current_mode.w = 800;
+    current_mode.h = 480;
+    current_mode.refresh_rate = 60;
+    current_mode.format = SDL_PIXELFORMAT_RGB565;
+    current_mode.driverdata = NULL;
+
+    SDL_zero(display);
+    display.desktop_mode = current_mode;
+    display.current_mode = current_mode;
+    display.driverdata = NULL;
+
+    SDL_AddVideoDisplay(&display);
+
+    return 1;
+}
+
+void
+PND_videoquit(_THIS)
+{
+
+}
+
+void
+PND_getdisplaymodes(_THIS)
+{
+
+}
+
+int
+PND_setdisplaymode(_THIS, SDL_DisplayMode * mode)
+{
+    return 0;
+}
+
+int
+PND_setdisplaypalette(_THIS, SDL_Palette * palette)
+{
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+
+    /* Setting display palette operation has been failed */
+    return -1;
+}
+
+int
+PND_getdisplaypalette(_THIS, SDL_Palette * palette)
+{
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+
+    /* Getting display palette operation has been failed */
+    return -1;
+}
+
+int
+PND_setdisplaygammaramp(_THIS, Uint16 * ramp)
+{
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+
+    /* Setting display gamma ramp operation has been failed */
+    return -1;
+}
+
+int
+PND_getdisplaygammaramp(_THIS, Uint16 * ramp)
+{
+    /* Getting display gamma ramp operation has been failed */
+    return -1;
+}
+
+int
+PND_createwindow(_THIS, SDL_Window * window)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+
+    SDL_WindowData *wdata;
+
+    uint32_t winargc = 0;
+    int32_t status;
+
+
+    /* Allocate window internal data */
+    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
+    if (wdata == NULL) {
+        SDL_OutOfMemory();
+        return -1;
+    }
+
+    /* Setup driver data for this window */
+    window->driverdata = wdata;
+
+    /* Check if window must support OpenGL ES rendering */
+    if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
+
+        EGLBoolean initstatus;
+
+        /* Mark this window as OpenGL ES compatible */
+        wdata->uses_gles = SDL_TRUE;
+
+        /* Create connection to OpenGL ES */
+        if (phdata->egl_display == EGL_NO_DISPLAY) {
+            phdata->egl_display = eglGetDisplay((NativeDisplayType) 0);
+            if (phdata->egl_display == EGL_NO_DISPLAY) {
+                SDL_SetError("PND: Can't get connection to OpenGL ES");
+                return -1;
+            }
+
+            initstatus = eglInitialize(phdata->egl_display, NULL, NULL);
+            if (initstatus != EGL_TRUE) {
+                SDL_SetError("PND: Can't init OpenGL ES library");
+                return -1;
+            }
+        }
+
+        phdata->egl_refcount++;
+    }
+
+    /* Window has been successfully created */
+    return 0;
+}
+
+int
+PND_createwindowfrom(_THIS, SDL_Window * window, const void *data)
+{
+    return -1;
+}
+
+void
+PND_setwindowtitle(_THIS, SDL_Window * window)
+{
+}
+void
+PND_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon)
+{
+}
+void
+PND_setwindowposition(_THIS, SDL_Window * window)
+{
+}
+void
+PND_setwindowsize(_THIS, SDL_Window * window)
+{
+}
+void
+PND_showwindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_hidewindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_raisewindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_maximizewindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_minimizewindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_restorewindow(_THIS, SDL_Window * window)
+{
+}
+void
+PND_setwindowgrab(_THIS, SDL_Window * window)
+{
+}
+void
+PND_destroywindow(_THIS, SDL_Window * window)
+{
+}
+
+/*****************************************************************************/
+/* SDL Window Manager function                                               */
+/*****************************************************************************/
+SDL_bool
+PND_getwindowwminfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
+{
+    if (info->version.major <= SDL_MAJOR_VERSION) {
+        return SDL_TRUE;
+    } else {
+        SDL_SetError("application not compiled with SDL %d.%d\n",
+                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+        return SDL_FALSE;
+    }
+
+    /* Failed to get window manager information */
+    return SDL_FALSE;
+}
+
+/*****************************************************************************/
+/* SDL OpenGL/OpenGL ES functions                                            */
+/*****************************************************************************/
+int
+PND_gl_loadlibrary(_THIS, const char *path)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+
+    /* Check if OpenGL ES library is specified for GF driver */
+    if (path == NULL) {
+        path = SDL_getenv("SDL_OPENGL_LIBRARY");
+        if (path == NULL) {
+            path = SDL_getenv("SDL_OPENGLES_LIBRARY");
+        }
+    }
+
+    /* Check if default library loading requested */
+    if (path == NULL) {
+        /* Already linked with GF library which provides egl* subset of  */
+        /* functions, use Common profile of OpenGL ES library by default */
+        path = "/usr/lib/libGLES_CM.so";
+    }
+
+    /* Load dynamic library */
+    _this->gl_config.dll_handle = SDL_LoadObject(path);
+    if (!_this->gl_config.dll_handle) {
+        /* Failed to load new GL ES library */
+        SDL_SetError("PND: Failed to locate OpenGL ES library");
+        return -1;
+    }
+
+    /* Store OpenGL ES library path and name */
+    SDL_strlcpy(_this->gl_config.driver_path, path,
+                SDL_arraysize(_this->gl_config.driver_path));
+
+    /* New OpenGL ES library is loaded */
+    return 0;
+}
+
+void *
+PND_gl_getprocaddres(_THIS, const char *proc)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    void *function_address;
+
+    /* Try to get function address through the egl interface */
+    function_address = eglGetProcAddress(proc);
+    if (function_address != NULL) {
+        return function_address;
+    }
+
+    /* Then try to get function in the OpenGL ES library */
+    if (_this->gl_config.dll_handle) {
+        function_address =
+            SDL_LoadFunction(_this->gl_config.dll_handle, proc);
+        if (function_address != NULL) {
+            return function_address;
+        }
+    }
+
+    /* Failed to get GL ES function address pointer */
+    SDL_SetError("PND: Cannot locate OpenGL ES function name");
+    return NULL;
+}
+
+void
+PND_gl_unloadlibrary(_THIS)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+
+    if (phdata->egl_initialized == SDL_TRUE) {
+        /* Unload OpenGL ES library */
+        if (_this->gl_config.dll_handle) {
+            SDL_UnloadObject(_this->gl_config.dll_handle);
+            _this->gl_config.dll_handle = NULL;
+        }
+    } else {
+        SDL_SetError("PND: GF initialization failed, no OpenGL ES support");
+    }
+}
+
+SDL_GLContext
+PND_gl_createcontext(_THIS, SDL_Window * window)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+    EGLBoolean status;
+    int32_t gfstatus;
+    EGLint configs;
+    uint32_t attr_pos;
+    EGLint attr_value;
+    EGLint cit;
+
+    /* Check if EGL was initialized */
+    if (phdata->egl_initialized != SDL_TRUE) {
+        SDL_SetError("PND: EGL initialization failed, no OpenGL ES support");
+        return NULL;
+    }
+
+    /* Prepare attributes list to pass them to OpenGL ES */
+    attr_pos = 0;
+    wdata->gles_attributes[attr_pos++] = EGL_SURFACE_TYPE;
+    wdata->gles_attributes[attr_pos++] = EGL_WINDOW_BIT;
+    wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
+    wdata->gles_attributes[attr_pos++] = _this->gl_config.red_size;
+    wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
+    wdata->gles_attributes[attr_pos++] = _this->gl_config.green_size;
+    wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
+    wdata->gles_attributes[attr_pos++] = _this->gl_config.blue_size;
+    wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
+
+    /* Setup alpha size in bits */
+    if (_this->gl_config.alpha_size) {
+        wdata->gles_attributes[attr_pos++] = _this->gl_config.alpha_size;
+    } else {
+        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+    }
+
+    /* Setup color buffer size */
+    if (_this->gl_config.buffer_size) {
+        wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
+        wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
+    } else {
+        wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
+        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+    }
+
+    /* Setup depth buffer bits */
+    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
+    wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size;
+
+    /* Setup stencil bits */
+    if (_this->gl_config.stencil_size) {
+        wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+        wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
+    } else {
+        wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+    }
+
+    /* Set number of samples in multisampling */
+    if (_this->gl_config.multisamplesamples) {
+        wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
+        wdata->gles_attributes[attr_pos++] =
+            _this->gl_config.multisamplesamples;
+    }
+
+    /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
+    if (_this->gl_config.multisamplebuffers) {
+        wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
+        wdata->gles_attributes[attr_pos++] =
+            _this->gl_config.multisamplebuffers;
+    }
+
+    /* Finish attributes list */
+    wdata->gles_attributes[attr_pos] = EGL_NONE;
+
+    /* Request first suitable framebuffer configuration */
+    status = eglChooseConfig(phdata->egl_display, wdata->gles_attributes,
+                             wdata->gles_configs, 1, &configs);
+    if (status != EGL_TRUE) {
+        SDL_SetError("PND: Can't find closest configuration for OpenGL ES");
+        return NULL;
+    }
+
+    /* Check if nothing has been found, try "don't care" settings */
+    if (configs == 0) {
+        int32_t it;
+        int32_t jt;
+        GLint depthbits[4] = { 32, 24, 16, EGL_DONT_CARE };
+
+        for (it = 0; it < 4; it++) {
+            for (jt = 16; jt >= 0; jt--) {
+                /* Don't care about color buffer bits, use what exist */
+                /* Replace previous set data with EGL_DONT_CARE       */
+                attr_pos = 0;
+                wdata->gles_attributes[attr_pos++] = EGL_SURFACE_TYPE;
+                wdata->gles_attributes[attr_pos++] = EGL_WINDOW_BIT;
+                wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+
+                /* Try to find requested or smallest depth */
+                if (_this->gl_config.depth_size) {
+                    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
+                    wdata->gles_attributes[attr_pos++] = depthbits[it];
+                } else {
+                    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
+                    wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                }
+
+                if (_this->gl_config.stencil_size) {
+                    wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+                    wdata->gles_attributes[attr_pos++] = jt;
+                } else {
+                    wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
+                    wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                }
+
+                wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
+                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
+                wdata->gles_attributes[attr_pos] = EGL_NONE;
+
+                /* Request first suitable framebuffer configuration */
+                status =
+                    eglChooseConfig(phdata->egl_display,
+                                    wdata->gles_attributes,
+                                    wdata->gles_configs, 1, &configs);
+
+                if (status != EGL_TRUE) {
+                    SDL_SetError
+                        ("PND: Can't find closest configuration for OpenGL ES");
+                    return NULL;
+                }
+                if (configs != 0) {
+                    break;
+                }
+            }
+            if (configs != 0) {
+                break;
+            }
+        }
+
+        /* No available configs */
+        if (configs == 0) {
+            SDL_SetError("PND: Can't find any configuration for OpenGL ES");
+            return NULL;
+        }
+    }
+
+    /* Initialize config index */
+    wdata->gles_config = 0;
+
+    /* Now check each configuration to find out the best */
+    for (cit = 0; cit < configs; cit++) {
+        uint32_t stencil_found;
+        uint32_t depth_found;
+
+        stencil_found = 0;
+        depth_found = 0;
+
+        if (_this->gl_config.stencil_size) {
+            status =
+                eglGetConfigAttrib(phdata->egl_display,
+                                   wdata->gles_configs[cit], EGL_STENCIL_SIZE,
+                                   &attr_value);
+            if (status == EGL_TRUE) {
+                if (attr_value != 0) {
+                    stencil_found = 1;
+                }
+            }
+        } else {
+            stencil_found = 1;
+        }
+
+        if (_this->gl_config.depth_size) {
+            status =
+                eglGetConfigAttrib(phdata->egl_display,
+                                   wdata->gles_configs[cit], EGL_DEPTH_SIZE,
+                                   &attr_value);
+            if (status == EGL_TRUE) {
+                if (attr_value != 0) {
+                    depth_found = 1;
+                }
+            }
+        } else {
+            depth_found = 1;
+        }
+
+        /* Exit from loop if found appropriate configuration */
+        if ((depth_found != 0) && (stencil_found != 0)) {
+            break;
+        }
+    }
+
+    /* If best could not be found, use first */
+    if (cit == configs) {
+        cit = 0;
+    }
+    wdata->gles_config = cit;
+
+    /* Create OpenGL ES context */
+    wdata->gles_context =
+        eglCreateContext(phdata->egl_display,
+                         wdata->gles_configs[wdata->gles_config], NULL, NULL);
+    if (wdata->gles_context == EGL_NO_CONTEXT) {
+        SDL_SetError("PND: OpenGL ES context creation has been failed");
+        return NULL;
+    }
+
+    wdata->gles_surface =
+        eglCreateWindowSurface(phdata->egl_display,
+                               wdata->gles_configs[wdata->gles_config],
+                               (NativeWindowType) 0, NULL);
+    if (wdata->gles_surface == 0) {
+        SDL_SetError("Error : eglCreateWindowSurface failed;\n");
+        return NULL;
+    }
+
+    /* Make just created context current */
+    status =
+        eglMakeCurrent(phdata->egl_display, wdata->gles_surface,
+                       wdata->gles_surface, wdata->gles_context);
+    if (status != EGL_TRUE) {
+        /* Destroy OpenGL ES surface */
+        eglDestroySurface(phdata->egl_display, wdata->gles_surface);
+        eglDestroyContext(phdata->egl_display, wdata->gles_context);
+        wdata->gles_context = EGL_NO_CONTEXT;
+        SDL_SetError("PND: Can't set OpenGL ES context on creation");
+        return NULL;
+    }
+
+    _this->gl_config.accelerated = 1;
+
+    /* Always clear stereo enable, since OpenGL ES do not supports stereo */
+    _this->gl_config.stereo = 0;
+
+    /* Get back samples and samplebuffers configurations. Rest framebuffer */
+    /* parameters could be obtained through the OpenGL ES API              */
+    status =
+        eglGetConfigAttrib(phdata->egl_display,
+                           wdata->gles_configs[wdata->gles_config],
+                           EGL_SAMPLES, &attr_value);
+    if (status == EGL_TRUE) {
+        _this->gl_config.multisamplesamples = attr_value;
+    }
+    status =
+        eglGetConfigAttrib(phdata->egl_display,
+                           wdata->gles_configs[wdata->gles_config],
+                           EGL_SAMPLE_BUFFERS, &attr_value);
+    if (status == EGL_TRUE) {
+        _this->gl_config.multisamplebuffers = attr_value;
+    }
+
+    /* Get back stencil and depth buffer sizes */
+    status =
+        eglGetConfigAttrib(phdata->egl_display,
+                           wdata->gles_configs[wdata->gles_config],
+                           EGL_DEPTH_SIZE, &attr_value);
+    if (status == EGL_TRUE) {
+        _this->gl_config.depth_size = attr_value;
+    }
+    status =
+        eglGetConfigAttrib(phdata->egl_display,
+                           wdata->gles_configs[wdata->gles_config],
+                           EGL_STENCIL_SIZE, &attr_value);
+    if (status == EGL_TRUE) {
+        _this->gl_config.stencil_size = attr_value;
+    }
+
+    /* Under PND OpenGL ES output can't be double buffered */
+    _this->gl_config.double_buffer = 0;
+
+    /* GL ES context was successfully created */
+    return wdata->gles_context;
+}
+
+int
+PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_WindowData *wdata;
+    EGLBoolean status;
+
+    if (phdata->egl_initialized != SDL_TRUE) {
+        SDL_SetError("PND: GF initialization failed, no OpenGL ES support");
+        return -1;
+    }
+
+    if ((window == NULL) && (context == NULL)) {
+        status =
+            eglMakeCurrent(phdata->egl_display, EGL_NO_SURFACE,
+                           EGL_NO_SURFACE, EGL_NO_CONTEXT);
+        if (status != EGL_TRUE) {
+            /* Failed to set current GL ES context */
+            SDL_SetError("PND: Can't set OpenGL ES context");
+            return -1;
+        }
+    } else {
+        wdata = (SDL_WindowData *) window->driverdata;
+        if (wdata->gles_surface == EGL_NO_SURFACE) {
+            SDL_SetError
+                ("PND: OpenGL ES surface is not initialized for this window");
+            return -1;
+        }
+        if (wdata->gles_context == EGL_NO_CONTEXT) {
+            SDL_SetError
+                ("PND: OpenGL ES context is not initialized for this window");
+            return -1;
+        }
+        if (wdata->gles_context != context) {
+            SDL_SetError
+                ("PND: OpenGL ES context is not belong to this window");
+            return -1;
+        }
+        status =
+            eglMakeCurrent(phdata->egl_display, wdata->gles_surface,
+                           wdata->gles_surface, wdata->gles_context);
+        if (status != EGL_TRUE) {
+            /* Failed to set current GL ES context */
+            SDL_SetError("PND: Can't set OpenGL ES context");
+            return -1;
+        }
+    }
+    return 0;
+}
+
+int
+PND_gl_setswapinterval(_THIS, int interval)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    EGLBoolean status;
+
+    if (phdata->egl_initialized != SDL_TRUE) {
+        SDL_SetError("PND: EGL initialization failed, no OpenGL ES support");
+        return -1;
+    }
+
+    /* Check if OpenGL ES connection has been initialized */
+    if (phdata->egl_display != EGL_NO_DISPLAY) {
+        /* Set swap OpenGL ES interval */
+        status = eglSwapInterval(phdata->egl_display, interval);
+        if (status == EGL_TRUE) {
+            /* Return success to upper level */
+            phdata->swapinterval = interval;
+            return 0;
+        }
+    }
+
+    /* Failed to set swap interval */
+    SDL_SetError("PND: Cannot set swap interval");
+    return -1;
+}
+
+int
+PND_gl_getswapinterval(_THIS)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+
+    if (phdata->egl_initialized != SDL_TRUE) {
+        SDL_SetError("PND: GLES initialization failed, no OpenGL ES support");
+        return -1;
+    }
+
+    /* Return default swap interval value */
+    return phdata->swapinterval;
+}
+
+void
+PND_gl_swapwindow(_THIS, SDL_Window * window)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
+    SDL_DisplayData *didata =
+        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
+
+
+    if (phdata->egl_initialized != SDL_TRUE) {
+        SDL_SetError("PND: GLES initialization failed, no OpenGL ES support");
+        return;
+    }
+
+    /* Many applications do not uses glFinish(), so we call it for them */
+    glFinish();
+
+    /* Wait until OpenGL ES rendering is completed */
+    eglWaitGL();
+
+    eglSwapBuffers(phdata->egl_display, wdata->gles_surface);
+}
+
+void
+PND_gl_deletecontext(_THIS, SDL_GLContext context)
+{
+    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
+    EGLBoolean status;
+
+    if (phdata->egl_initialized != SDL_TRUE) {
+        SDL_SetError("PND: GLES initialization failed, no OpenGL ES support");
+        return;
+    }
+
+    /* Check if OpenGL ES connection has been initialized */
+    if (phdata->egl_display != EGL_NO_DISPLAY) {
+        if (context != EGL_NO_CONTEXT) {
+            status = eglDestroyContext(phdata->egl_display, context);
+            if (status != EGL_TRUE) {
+                /* Error during OpenGL ES context destroying */
+                SDL_SetError("PND: OpenGL ES context destroy error");
+                return;
+            }
+        }
+    }
+
+    return;
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/pandora/SDL_pandora.h	Sun May 31 11:53:12 2009 +0000
@@ -0,0 +1,110 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2009 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+
+    Open Pandora SDL driver
+    Copyright (C) 2009 David Carré
+    (cpasjuste@gmail.com)
+*/
+
+#ifndef __SDL_PANDORA_H__
+#define __SDL_PANDORA_H__
+
+#include <GLES/egl.h>
+
+#include "SDL_config.h"
+#include "../SDL_sysvideo.h"
+
+typedef struct SDL_VideoData
+{
+    SDL_bool egl_initialized;   /* OpenGL ES device initialization status */
+    EGLDisplay egl_display;     /* OpenGL ES display connection           */
+    uint32_t egl_refcount;      /* OpenGL ES reference count              */
+    uint32_t swapinterval;      /* OpenGL ES default swap interval        */
+
+} SDL_VideoData;
+
+
+typedef struct SDL_DisplayData
+{
+
+} SDL_DisplayData;
+
+
+typedef struct SDL_WindowData
+{
+    SDL_bool uses_gles;         /* if true window must support OpenGL ES */
+
+    EGLConfig gles_configs[32];
+    EGLint gles_config;         /* OpenGL ES configuration index      */
+    EGLContext gles_context;    /* OpenGL ES context                  */
+    EGLint gles_attributes[256];        /* OpenGL ES attributes for context   */
+    EGLSurface gles_surface;    /* OpenGL ES target rendering surface */
+
+} SDL_WindowData;
+
+
+/****************************************************************************/
+/* SDL_VideoDevice functions declaration                                    */
+/****************************************************************************/
+
+/* Display and window functions */
+int PND_videoinit(_THIS);
+void PND_videoquit(_THIS);
+void PND_getdisplaymodes(_THIS);
+int PND_setdisplaymode(_THIS, SDL_DisplayMode * mode);
+int PND_setdisplaypalette(_THIS, SDL_Palette * palette);
+int PND_getdisplaypalette(_THIS, SDL_Palette * palette);
+int PND_setdisplaygammaramp(_THIS, Uint16 * ramp);
+int PND_getdisplaygammaramp(_THIS, Uint16 * ramp);
+int PND_createwindow(_THIS, SDL_Window * window);
+int PND_createwindowfrom(_THIS, SDL_Window * window, const void *data);
+void PND_setwindowtitle(_THIS, SDL_Window * window);
+void PND_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon);
+void PND_setwindowposition(_THIS, SDL_Window * window);
+void PND_setwindowsize(_THIS, SDL_Window * window);
+void PND_showwindow(_THIS, SDL_Window * window);
+void PND_hidewindow(_THIS, SDL_Window * window);
+void PND_raisewindow(_THIS, SDL_Window * window);
+void PND_maximizewindow(_THIS, SDL_Window * window);
+void PND_minimizewindow(_THIS, SDL_Window * window);
+void PND_restorewindow(_THIS, SDL_Window * window);
+void PND_setwindowgrab(_THIS, SDL_Window * window);
+void PND_destroywindow(_THIS, SDL_Window * window);
+
+/* Window manager function */
+SDL_bool PND_getwindowwminfo(_THIS, SDL_Window * window,
+                             struct SDL_SysWMinfo *info);
+
+/* OpenGL/OpenGL ES functions */
+int PND_gl_loadlibrary(_THIS, const char *path);
+void *PND_gl_getprocaddres(_THIS, const char *proc);
+void PND_gl_unloadlibrary(_THIS);
+SDL_GLContext PND_gl_createcontext(_THIS, SDL_Window * window);
+int PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+int PND_gl_setswapinterval(_THIS, int interval);
+int PND_gl_getswapinterval(_THIS);
+void PND_gl_swapwindow(_THIS, SDL_Window * window);
+void PND_gl_deletecontext(_THIS, SDL_GLContext context);
+
+
+#endif /* __SDL_PANDORA_H__ */
+
+/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/pandora/SDL_pandora_events.c	Sun May 31 11:53:12 2009 +0000
@@ -0,0 +1,36 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2009 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+#include "SDL_config.h"
+
+/* Being a null driver, there's no event stream. We just define stubs for
+   most of the API. */
+
+#include "../../events/SDL_sysevents.h"
+#include "../../events/SDL_events_c.h"
+
+void
+PND_PumpEvents(_THIS)
+{
+    /* Not implemented. */
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/pandora/SDL_pandora_events.h	Sun May 31 11:53:12 2009 +0000
@@ -0,0 +1,26 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2009 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+#include "SDL_config.h"
+
+extern void PND_PumpEvents(_THIS);
+
+/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/x11/SDL_x11window.c	Thu May 28 09:39:14 2009 +0000
+++ b/src/video/x11/SDL_x11window.c	Sun May 31 11:53:12 2009 +0000
@@ -31,6 +31,10 @@
 #include "SDL_x11gamma.h"
 #include "../Xext/extensions/StdCmap.h"
 
+#ifdef SDL_VIDEO_DRIVER_PANDORA
+#include "SDL_x11opengles.h"
+#endif
+
 #define _NET_WM_STATE_REMOVE    0l
 #define _NET_WM_STATE_ADD       1l
 #define _NET_WM_STATE_TOGGLE    2l
@@ -241,6 +245,19 @@
         XFree(vinfo);
     } else
 #endif
+#ifdef SDL_VIDEO_DRIVER_PANDORA
+    if (window->flags & SDL_WINDOW_OPENGL) {
+        XVisualInfo *vinfo;
+
+        vinfo = X11_GLES_GetVisual(_this, data->display, displaydata->screen);
+        if (!vinfo) {
+            return -1;
+        }
+        visual = vinfo->visual;
+        depth = vinfo->depth;
+        XFree(vinfo);
+    } else
+#endif
     {
         visual = displaydata->visual;
         depth = displaydata->depth;
@@ -505,6 +522,19 @@
         SDL_SetError("Couldn't create window");
         return -1;
     }
+#if SDL_VIDEO_DRIVER_PANDORA
+    /* Create the GLES window surface */
+    _this->gles_data->egl_surface =
+        _this->gles_data->eglCreateWindowSurface(_this->gles_data->
+                                                 egl_display,
+                                                 _this->gles_data->egl_config,
+                                                 (NativeWindowType) w, NULL);
+
+    if (_this->gles_data->egl_surface == EGL_NO_SURFACE) {
+        SDL_SetError("Could not create GLES window surface");
+        return -1;
+    }
+#endif
 
     sizehints = XAllocSizeHints();
     if (sizehints) {