OpenPandora support added by David Carré
authorSam Lantinga <slouken@libsdl.org>
Sun, 31 May 2009 11:53:12 +0000
changeset 3161494559cc723b
parent 3160 210e209b87cc
child 3162 dc1eb82ffdaa
OpenPandora support added by David Carré
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
     1.1 --- a/CREDITS	Thu May 28 09:39:14 2009 +0000
     1.2 +++ b/CREDITS	Sun May 31 11:53:12 2009 +0000
     1.3 @@ -44,10 +44,12 @@
     1.4  
     1.5  * Eric Wing, Max Horn, and Darrell Walisser for unflagging work on the Mac OS X port
     1.6  
     1.7 -* Couriersud for the DirectFB driver
     1.8 +* David Carr, for the Pandora port
     1.9  
    1.10  * Patrice Mandin, for the Atari port
    1.11  
    1.12 +* Couriersud for the DirectFB driver
    1.13 +
    1.14  * Jon Atkins for SDL_image, SDL_mixer and SDL_net documentation
    1.15  
    1.16  * Arne Claus, for the 2004 winning SDL logo,
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/Makefile.pandora	Sun May 31 11:53:12 2009 +0000
     2.3 @@ -0,0 +1,37 @@
     2.4 +# Makefile to build the pandora SDL library
     2.5 +
     2.6 +AR	= arm-none-linux-gnueabi-ar
     2.7 +RANLIB	= arm-none-linux-gnueabi-ranlib
     2.8 +CC = arm-none-linux-gnueabi-gcc
     2.9 +CXX = arm-none-linux-gnueabi-g++
    2.10 +STRIP = arm-none-linux-gnueabi-strip
    2.11 +
    2.12 +CFLAGS  = -O3 -march=armv7-a -mcpu=cortex-a8 -mtune=cortex-a8 -mfloat-abi=softfp \
    2.13 +	-mfpu=neon -ftree-vectorize -ffast-math -fomit-frame-pointer -fno-strict-aliasing -fsingle-precision-constant \
    2.14 +	-I./include -I$(PNDSDK)/usr/include
    2.15 +
    2.16 +TARGET  = libSDL.a
    2.17 +
    2.18 +SOURCES = ./src/*.c ./src/audio/*.c ./src/cdrom/*.c ./src/cpuinfo/*.c ./src/events/*.c \
    2.19 +	./src/file/*.c ./src/stdlib/*.c ./src/thread/*.c ./src/timer/*.c ./src/video/*.c \
    2.20 +	./src/joystick/*.c ./src/haptic/*.c ./src/video/dummy/*.c ./src/audio/disk/*.c \
    2.21 +	./src/audio/dummy/*.c ./src/loadso/dlopen/*.c ./src/audio/dsp/*.c ./src/audio/dma/*.c \
    2.22 +	./src/thread/pthread/SDL_systhread.c ./src/thread/pthread/SDL_syssem.c \
    2.23 +	./src/thread/pthread/SDL_sysmutex.c ./src/thread/pthread/SDL_syscond.c \
    2.24 +	./src/joystick/linux/*.c ./src/haptic/linux/*.c ./src/timer/unix/*.c ./src/cdrom/dummy/*.c \
    2.25 +	./src/video/pandora/SDL_pandora.o ./src/video/pandora/SDL_pandora_events.o ./src/video/x11/*.c
    2.26 +	
    2.27 +
    2.28 +OBJECTS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g')
    2.29 +
    2.30 +all: $(TARGET)
    2.31 +
    2.32 +$(TARGET): $(CONFIG_H) $(OBJECTS)
    2.33 +	$(AR) crv $@ $^
    2.34 +	$(RANLIB) $@
    2.35 +
    2.36 +$(CONFIG_H):
    2.37 +	cp include/SDL_config_pandora.h include/SDL_config.h
    2.38 +
    2.39 +clean:
    2.40 +	rm -f $(TARGET) $(OBJECTS)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/README.pandora	Sun May 31 11:53:12 2009 +0000
     3.3 @@ -0,0 +1,16 @@
     3.4 +SDL 1.3 with open pandora console support ( http://openpandora.org/ )
     3.5 +=====================================================================
     3.6 +
     3.7 +- A pandora specific video driver was writed to allow SDL 1.3 with OpenGL ES
     3.8 +support to work on the pandora under the framebuffer. This driver do not have
     3.9 +input support for now, so if you use it you will have to add your own control code.
    3.10 +The video driver name is "pandora" so if you have problem running it from
    3.11 +the framebuffer, try to set the following variable before starting your application :
    3.12 +"export SDL_VIDEODRIVER=pandora"
    3.13 +
    3.14 +- OpenGL ES support was added to the x11 driver, so it's working like the normal
    3.15 +x11 driver one with OpenGLX support, with SDL input event's etc..
    3.16 +
    3.17 +
    3.18 +David Carré (Cpasjuste)
    3.19 +cpasjuste@gmail.com
     4.1 --- a/src/video/SDL_renderer_gles.c	Thu May 28 09:39:14 2009 +0000
     4.2 +++ b/src/video/SDL_renderer_gles.c	Sun May 31 11:53:12 2009 +0000
     4.3 @@ -42,6 +42,14 @@
     4.4  
     4.5  #endif /* __QNXNTO__ */
     4.6  
     4.7 +#if SDL_VIDEO_DRIVER_PANDORA
     4.8 +GL_API void GL_APIENTRY
     4.9 +glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
    4.10 +{
    4.11 +    return;
    4.12 +}
    4.13 +#endif /* SDL_VIDEO_DRIVER_PANDORA */
    4.14 +
    4.15  /* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
    4.16  
    4.17  static const float inv255f = 1.0f / 255.0f;
    4.18 @@ -284,7 +292,10 @@
    4.19              renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
    4.20          }
    4.21      }
    4.22 -
    4.23 +#if SDL_VIDEO_DRIVER_PANDORA
    4.24 +    data->GL_OES_draw_texture_supported = SDL_FALSE;
    4.25 +    data->useDrawTexture = SDL_FALSE;
    4.26 +#else
    4.27      if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) {
    4.28          data->GL_OES_draw_texture_supported = SDL_TRUE;
    4.29          data->useDrawTexture = SDL_TRUE;
    4.30 @@ -292,6 +303,7 @@
    4.31          data->GL_OES_draw_texture_supported = SDL_FALSE;
    4.32          data->useDrawTexture = SDL_FALSE;
    4.33      }
    4.34 +#endif
    4.35  
    4.36      data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
    4.37      renderer->info.max_texture_width = value;
     5.1 --- a/src/video/SDL_sysvideo.h	Thu May 28 09:39:14 2009 +0000
     5.2 +++ b/src/video/SDL_sysvideo.h	Sun May 31 11:53:12 2009 +0000
     5.3 @@ -318,6 +318,10 @@
     5.4      void *driverdata;
     5.5      struct SDL_GLDriverData *gl_data;
     5.6  
     5.7 +#if SDL_VIDEO_DRIVER_PANDORA
     5.8 +    struct SDL_PrivateGLESData *gles_data;
     5.9 +#endif
    5.10 +
    5.11      /* * * */
    5.12      /* The function used to dispose of this structure */
    5.13      void (*free) (_THIS);
    5.14 @@ -403,6 +407,9 @@
    5.15  #if SDL_VIDEO_DRIVER_NDS
    5.16  extern VideoBootStrap NDS_bootstrap;
    5.17  #endif
    5.18 +#if SDL_VIDEO_DRIVER_PANDORA
    5.19 +extern VideoBootStrap PND_bootstrap;
    5.20 +#endif
    5.21  
    5.22  #define SDL_CurrentDisplay	(_this->displays[_this->current_display])
    5.23  
     6.1 --- a/src/video/SDL_video.c	Thu May 28 09:39:14 2009 +0000
     6.2 +++ b/src/video/SDL_video.c	Sun May 31 11:53:12 2009 +0000
     6.3 @@ -121,6 +121,9 @@
     6.4  #if SDL_VIDEO_DRIVER_DUMMY
     6.5      &DUMMY_bootstrap,
     6.6  #endif
     6.7 +#if SDL_VIDEO_DRIVER_PANDORA
     6.8 +    &PND_bootstrap,
     6.9 +#endif
    6.10      NULL
    6.11  };
    6.12  
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/pandora/SDL_pandora.c	Sun May 31 11:53:12 2009 +0000
     7.3 @@ -0,0 +1,858 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997-2009 Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Lesser General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2.1 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Lesser General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Lesser General Public
    7.19 +    License along with this library; if not, write to the Free Software
    7.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    slouken@libsdl.org
    7.24 +
    7.25 +    Open Pandora SDL driver
    7.26 +    Copyright (C) 2009 David Carré
    7.27 +    (cpasjuste@gmail.com)
    7.28 +*/
    7.29 +
    7.30 +/* SDL internals */
    7.31 +#include "SDL_config.h"
    7.32 +#include "../SDL_sysvideo.h"
    7.33 +#include "SDL_version.h"
    7.34 +#include "SDL_syswm.h"
    7.35 +#include "SDL_loadso.h"
    7.36 +#include "SDL_events.h"
    7.37 +#include "../../events/SDL_mouse_c.h"
    7.38 +#include "../../events/SDL_keyboard_c.h"
    7.39 +
    7.40 +/* PND declarations */
    7.41 +#include "SDL_pandora.h"
    7.42 +#include "SDL_pandora_events.h"
    7.43 +
    7.44 +static SDL_bool PND_initialized = SDL_FALSE;
    7.45 +
    7.46 +static int
    7.47 +PND_available(void)
    7.48 +{
    7.49 +    return 1;
    7.50 +}
    7.51 +
    7.52 +static void
    7.53 +PND_destroy(SDL_VideoDevice * device)
    7.54 +{
    7.55 +    SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata;
    7.56 +
    7.57 +    if (device->driverdata != NULL) {
    7.58 +        device->driverdata = NULL;
    7.59 +    }
    7.60 +}
    7.61 +
    7.62 +static SDL_VideoDevice *
    7.63 +PND_create()
    7.64 +{
    7.65 +    SDL_VideoDevice *device;
    7.66 +    SDL_VideoData *phdata;
    7.67 +    int status;
    7.68 +
    7.69 +    /* Check if pandora could be initialized */
    7.70 +    status = PND_available();
    7.71 +    if (status == 0) {
    7.72 +        /* PND could not be used */
    7.73 +        return NULL;
    7.74 +    }
    7.75 +
    7.76 +    /* Initialize SDL_VideoDevice structure */
    7.77 +    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
    7.78 +    if (device == NULL) {
    7.79 +        SDL_OutOfMemory();
    7.80 +        return NULL;
    7.81 +    }
    7.82 +
    7.83 +    /* Initialize internal Pandora specific data */
    7.84 +    phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
    7.85 +    if (phdata == NULL) {
    7.86 +        SDL_OutOfMemory();
    7.87 +        SDL_free(device);
    7.88 +        return NULL;
    7.89 +    }
    7.90 +
    7.91 +    device->driverdata = phdata;
    7.92 +
    7.93 +    phdata->egl_initialized = SDL_TRUE;
    7.94 +
    7.95 +
    7.96 +    /* Setup amount of available displays and current display */
    7.97 +    device->num_displays = 1;
    7.98 +    device->current_display = 1;
    7.99 +
   7.100 +    /* Set device free function */
   7.101 +    device->free = PND_destroy;
   7.102 +
   7.103 +    /* Setup all functions which we can handle */
   7.104 +    device->VideoInit = PND_videoinit;
   7.105 +    device->VideoQuit = PND_videoquit;
   7.106 +    device->GetDisplayModes = PND_getdisplaymodes;
   7.107 +    device->SetDisplayMode = PND_setdisplaymode;
   7.108 +    device->SetDisplayPalette = PND_setdisplaypalette;
   7.109 +    device->GetDisplayPalette = PND_getdisplaypalette;
   7.110 +    device->SetDisplayGammaRamp = PND_setdisplaygammaramp;
   7.111 +    device->GetDisplayGammaRamp = PND_getdisplaygammaramp;
   7.112 +    device->CreateWindow = PND_createwindow;
   7.113 +    device->CreateWindowFrom = PND_createwindowfrom;
   7.114 +    device->SetWindowTitle = PND_setwindowtitle;
   7.115 +    device->SetWindowIcon = PND_setwindowicon;
   7.116 +    device->SetWindowPosition = PND_setwindowposition;
   7.117 +    device->SetWindowSize = PND_setwindowsize;
   7.118 +    device->ShowWindow = PND_showwindow;
   7.119 +    device->HideWindow = PND_hidewindow;
   7.120 +    device->RaiseWindow = PND_raisewindow;
   7.121 +    device->MaximizeWindow = PND_maximizewindow;
   7.122 +    device->MinimizeWindow = PND_minimizewindow;
   7.123 +    device->RestoreWindow = PND_restorewindow;
   7.124 +    device->SetWindowGrab = PND_setwindowgrab;
   7.125 +    device->DestroyWindow = PND_destroywindow;
   7.126 +    device->GetWindowWMInfo = PND_getwindowwminfo;
   7.127 +    device->GL_LoadLibrary = PND_gl_loadlibrary;
   7.128 +    device->GL_GetProcAddress = PND_gl_getprocaddres;
   7.129 +    device->GL_UnloadLibrary = PND_gl_unloadlibrary;
   7.130 +    device->GL_CreateContext = PND_gl_createcontext;
   7.131 +    device->GL_MakeCurrent = PND_gl_makecurrent;
   7.132 +    device->GL_SetSwapInterval = PND_gl_setswapinterval;
   7.133 +    device->GL_GetSwapInterval = PND_gl_getswapinterval;
   7.134 +    device->GL_SwapWindow = PND_gl_swapwindow;
   7.135 +    device->GL_DeleteContext = PND_gl_deletecontext;
   7.136 +    device->PumpEvents = PND_PumpEvents;
   7.137 +
   7.138 +    return device;
   7.139 +}
   7.140 +
   7.141 +VideoBootStrap PND_bootstrap = {
   7.142 +    "pandora",
   7.143 +    "SDL Pandora Video Driver",
   7.144 +    PND_available,
   7.145 +    PND_create
   7.146 +};
   7.147 +
   7.148 +/*****************************************************************************/
   7.149 +/* SDL Video and Display initialization/handling functions                   */
   7.150 +/*****************************************************************************/
   7.151 +int
   7.152 +PND_videoinit(_THIS)
   7.153 +{
   7.154 +    SDL_VideoDisplay display;
   7.155 +    SDL_DisplayMode current_mode;
   7.156 +
   7.157 +    SDL_zero(current_mode);
   7.158 +    current_mode.w = 800;
   7.159 +    current_mode.h = 480;
   7.160 +    current_mode.refresh_rate = 60;
   7.161 +    current_mode.format = SDL_PIXELFORMAT_RGB565;
   7.162 +    current_mode.driverdata = NULL;
   7.163 +
   7.164 +    SDL_zero(display);
   7.165 +    display.desktop_mode = current_mode;
   7.166 +    display.current_mode = current_mode;
   7.167 +    display.driverdata = NULL;
   7.168 +
   7.169 +    SDL_AddVideoDisplay(&display);
   7.170 +
   7.171 +    return 1;
   7.172 +}
   7.173 +
   7.174 +void
   7.175 +PND_videoquit(_THIS)
   7.176 +{
   7.177 +
   7.178 +}
   7.179 +
   7.180 +void
   7.181 +PND_getdisplaymodes(_THIS)
   7.182 +{
   7.183 +
   7.184 +}
   7.185 +
   7.186 +int
   7.187 +PND_setdisplaymode(_THIS, SDL_DisplayMode * mode)
   7.188 +{
   7.189 +    return 0;
   7.190 +}
   7.191 +
   7.192 +int
   7.193 +PND_setdisplaypalette(_THIS, SDL_Palette * palette)
   7.194 +{
   7.195 +    SDL_DisplayData *didata =
   7.196 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
   7.197 +
   7.198 +    /* Setting display palette operation has been failed */
   7.199 +    return -1;
   7.200 +}
   7.201 +
   7.202 +int
   7.203 +PND_getdisplaypalette(_THIS, SDL_Palette * palette)
   7.204 +{
   7.205 +    SDL_DisplayData *didata =
   7.206 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
   7.207 +
   7.208 +    /* Getting display palette operation has been failed */
   7.209 +    return -1;
   7.210 +}
   7.211 +
   7.212 +int
   7.213 +PND_setdisplaygammaramp(_THIS, Uint16 * ramp)
   7.214 +{
   7.215 +    SDL_DisplayData *didata =
   7.216 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
   7.217 +
   7.218 +    /* Setting display gamma ramp operation has been failed */
   7.219 +    return -1;
   7.220 +}
   7.221 +
   7.222 +int
   7.223 +PND_getdisplaygammaramp(_THIS, Uint16 * ramp)
   7.224 +{
   7.225 +    /* Getting display gamma ramp operation has been failed */
   7.226 +    return -1;
   7.227 +}
   7.228 +
   7.229 +int
   7.230 +PND_createwindow(_THIS, SDL_Window * window)
   7.231 +{
   7.232 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   7.233 +
   7.234 +    SDL_WindowData *wdata;
   7.235 +
   7.236 +    uint32_t winargc = 0;
   7.237 +    int32_t status;
   7.238 +
   7.239 +
   7.240 +    /* Allocate window internal data */
   7.241 +    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
   7.242 +    if (wdata == NULL) {
   7.243 +        SDL_OutOfMemory();
   7.244 +        return -1;
   7.245 +    }
   7.246 +
   7.247 +    /* Setup driver data for this window */
   7.248 +    window->driverdata = wdata;
   7.249 +
   7.250 +    /* Check if window must support OpenGL ES rendering */
   7.251 +    if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
   7.252 +
   7.253 +        EGLBoolean initstatus;
   7.254 +
   7.255 +        /* Mark this window as OpenGL ES compatible */
   7.256 +        wdata->uses_gles = SDL_TRUE;
   7.257 +
   7.258 +        /* Create connection to OpenGL ES */
   7.259 +        if (phdata->egl_display == EGL_NO_DISPLAY) {
   7.260 +            phdata->egl_display = eglGetDisplay((NativeDisplayType) 0);
   7.261 +            if (phdata->egl_display == EGL_NO_DISPLAY) {
   7.262 +                SDL_SetError("PND: Can't get connection to OpenGL ES");
   7.263 +                return -1;
   7.264 +            }
   7.265 +
   7.266 +            initstatus = eglInitialize(phdata->egl_display, NULL, NULL);
   7.267 +            if (initstatus != EGL_TRUE) {
   7.268 +                SDL_SetError("PND: Can't init OpenGL ES library");
   7.269 +                return -1;
   7.270 +            }
   7.271 +        }
   7.272 +
   7.273 +        phdata->egl_refcount++;
   7.274 +    }
   7.275 +
   7.276 +    /* Window has been successfully created */
   7.277 +    return 0;
   7.278 +}
   7.279 +
   7.280 +int
   7.281 +PND_createwindowfrom(_THIS, SDL_Window * window, const void *data)
   7.282 +{
   7.283 +    return -1;
   7.284 +}
   7.285 +
   7.286 +void
   7.287 +PND_setwindowtitle(_THIS, SDL_Window * window)
   7.288 +{
   7.289 +}
   7.290 +void
   7.291 +PND_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon)
   7.292 +{
   7.293 +}
   7.294 +void
   7.295 +PND_setwindowposition(_THIS, SDL_Window * window)
   7.296 +{
   7.297 +}
   7.298 +void
   7.299 +PND_setwindowsize(_THIS, SDL_Window * window)
   7.300 +{
   7.301 +}
   7.302 +void
   7.303 +PND_showwindow(_THIS, SDL_Window * window)
   7.304 +{
   7.305 +}
   7.306 +void
   7.307 +PND_hidewindow(_THIS, SDL_Window * window)
   7.308 +{
   7.309 +}
   7.310 +void
   7.311 +PND_raisewindow(_THIS, SDL_Window * window)
   7.312 +{
   7.313 +}
   7.314 +void
   7.315 +PND_maximizewindow(_THIS, SDL_Window * window)
   7.316 +{
   7.317 +}
   7.318 +void
   7.319 +PND_minimizewindow(_THIS, SDL_Window * window)
   7.320 +{
   7.321 +}
   7.322 +void
   7.323 +PND_restorewindow(_THIS, SDL_Window * window)
   7.324 +{
   7.325 +}
   7.326 +void
   7.327 +PND_setwindowgrab(_THIS, SDL_Window * window)
   7.328 +{
   7.329 +}
   7.330 +void
   7.331 +PND_destroywindow(_THIS, SDL_Window * window)
   7.332 +{
   7.333 +}
   7.334 +
   7.335 +/*****************************************************************************/
   7.336 +/* SDL Window Manager function                                               */
   7.337 +/*****************************************************************************/
   7.338 +SDL_bool
   7.339 +PND_getwindowwminfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
   7.340 +{
   7.341 +    if (info->version.major <= SDL_MAJOR_VERSION) {
   7.342 +        return SDL_TRUE;
   7.343 +    } else {
   7.344 +        SDL_SetError("application not compiled with SDL %d.%d\n",
   7.345 +                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
   7.346 +        return SDL_FALSE;
   7.347 +    }
   7.348 +
   7.349 +    /* Failed to get window manager information */
   7.350 +    return SDL_FALSE;
   7.351 +}
   7.352 +
   7.353 +/*****************************************************************************/
   7.354 +/* SDL OpenGL/OpenGL ES functions                                            */
   7.355 +/*****************************************************************************/
   7.356 +int
   7.357 +PND_gl_loadlibrary(_THIS, const char *path)
   7.358 +{
   7.359 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   7.360 +
   7.361 +    /* Check if OpenGL ES library is specified for GF driver */
   7.362 +    if (path == NULL) {
   7.363 +        path = SDL_getenv("SDL_OPENGL_LIBRARY");
   7.364 +        if (path == NULL) {
   7.365 +            path = SDL_getenv("SDL_OPENGLES_LIBRARY");
   7.366 +        }
   7.367 +    }
   7.368 +
   7.369 +    /* Check if default library loading requested */
   7.370 +    if (path == NULL) {
   7.371 +        /* Already linked with GF library which provides egl* subset of  */
   7.372 +        /* functions, use Common profile of OpenGL ES library by default */
   7.373 +        path = "/usr/lib/libGLES_CM.so";
   7.374 +    }
   7.375 +
   7.376 +    /* Load dynamic library */
   7.377 +    _this->gl_config.dll_handle = SDL_LoadObject(path);
   7.378 +    if (!_this->gl_config.dll_handle) {
   7.379 +        /* Failed to load new GL ES library */
   7.380 +        SDL_SetError("PND: Failed to locate OpenGL ES library");
   7.381 +        return -1;
   7.382 +    }
   7.383 +
   7.384 +    /* Store OpenGL ES library path and name */
   7.385 +    SDL_strlcpy(_this->gl_config.driver_path, path,
   7.386 +                SDL_arraysize(_this->gl_config.driver_path));
   7.387 +
   7.388 +    /* New OpenGL ES library is loaded */
   7.389 +    return 0;
   7.390 +}
   7.391 +
   7.392 +void *
   7.393 +PND_gl_getprocaddres(_THIS, const char *proc)
   7.394 +{
   7.395 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   7.396 +    void *function_address;
   7.397 +
   7.398 +    /* Try to get function address through the egl interface */
   7.399 +    function_address = eglGetProcAddress(proc);
   7.400 +    if (function_address != NULL) {
   7.401 +        return function_address;
   7.402 +    }
   7.403 +
   7.404 +    /* Then try to get function in the OpenGL ES library */
   7.405 +    if (_this->gl_config.dll_handle) {
   7.406 +        function_address =
   7.407 +            SDL_LoadFunction(_this->gl_config.dll_handle, proc);
   7.408 +        if (function_address != NULL) {
   7.409 +            return function_address;
   7.410 +        }
   7.411 +    }
   7.412 +
   7.413 +    /* Failed to get GL ES function address pointer */
   7.414 +    SDL_SetError("PND: Cannot locate OpenGL ES function name");
   7.415 +    return NULL;
   7.416 +}
   7.417 +
   7.418 +void
   7.419 +PND_gl_unloadlibrary(_THIS)
   7.420 +{
   7.421 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   7.422 +
   7.423 +    if (phdata->egl_initialized == SDL_TRUE) {
   7.424 +        /* Unload OpenGL ES library */
   7.425 +        if (_this->gl_config.dll_handle) {
   7.426 +            SDL_UnloadObject(_this->gl_config.dll_handle);
   7.427 +            _this->gl_config.dll_handle = NULL;
   7.428 +        }
   7.429 +    } else {
   7.430 +        SDL_SetError("PND: GF initialization failed, no OpenGL ES support");
   7.431 +    }
   7.432 +}
   7.433 +
   7.434 +SDL_GLContext
   7.435 +PND_gl_createcontext(_THIS, SDL_Window * window)
   7.436 +{
   7.437 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   7.438 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
   7.439 +    SDL_DisplayData *didata =
   7.440 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
   7.441 +    EGLBoolean status;
   7.442 +    int32_t gfstatus;
   7.443 +    EGLint configs;
   7.444 +    uint32_t attr_pos;
   7.445 +    EGLint attr_value;
   7.446 +    EGLint cit;
   7.447 +
   7.448 +    /* Check if EGL was initialized */
   7.449 +    if (phdata->egl_initialized != SDL_TRUE) {
   7.450 +        SDL_SetError("PND: EGL initialization failed, no OpenGL ES support");
   7.451 +        return NULL;
   7.452 +    }
   7.453 +
   7.454 +    /* Prepare attributes list to pass them to OpenGL ES */
   7.455 +    attr_pos = 0;
   7.456 +    wdata->gles_attributes[attr_pos++] = EGL_SURFACE_TYPE;
   7.457 +    wdata->gles_attributes[attr_pos++] = EGL_WINDOW_BIT;
   7.458 +    wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
   7.459 +    wdata->gles_attributes[attr_pos++] = _this->gl_config.red_size;
   7.460 +    wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
   7.461 +    wdata->gles_attributes[attr_pos++] = _this->gl_config.green_size;
   7.462 +    wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
   7.463 +    wdata->gles_attributes[attr_pos++] = _this->gl_config.blue_size;
   7.464 +    wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
   7.465 +
   7.466 +    /* Setup alpha size in bits */
   7.467 +    if (_this->gl_config.alpha_size) {
   7.468 +        wdata->gles_attributes[attr_pos++] = _this->gl_config.alpha_size;
   7.469 +    } else {
   7.470 +        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.471 +    }
   7.472 +
   7.473 +    /* Setup color buffer size */
   7.474 +    if (_this->gl_config.buffer_size) {
   7.475 +        wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
   7.476 +        wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
   7.477 +    } else {
   7.478 +        wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
   7.479 +        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.480 +    }
   7.481 +
   7.482 +    /* Setup depth buffer bits */
   7.483 +    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
   7.484 +    wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size;
   7.485 +
   7.486 +    /* Setup stencil bits */
   7.487 +    if (_this->gl_config.stencil_size) {
   7.488 +        wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
   7.489 +        wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
   7.490 +    } else {
   7.491 +        wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
   7.492 +        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.493 +    }
   7.494 +
   7.495 +    /* Set number of samples in multisampling */
   7.496 +    if (_this->gl_config.multisamplesamples) {
   7.497 +        wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
   7.498 +        wdata->gles_attributes[attr_pos++] =
   7.499 +            _this->gl_config.multisamplesamples;
   7.500 +    }
   7.501 +
   7.502 +    /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
   7.503 +    if (_this->gl_config.multisamplebuffers) {
   7.504 +        wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
   7.505 +        wdata->gles_attributes[attr_pos++] =
   7.506 +            _this->gl_config.multisamplebuffers;
   7.507 +    }
   7.508 +
   7.509 +    /* Finish attributes list */
   7.510 +    wdata->gles_attributes[attr_pos] = EGL_NONE;
   7.511 +
   7.512 +    /* Request first suitable framebuffer configuration */
   7.513 +    status = eglChooseConfig(phdata->egl_display, wdata->gles_attributes,
   7.514 +                             wdata->gles_configs, 1, &configs);
   7.515 +    if (status != EGL_TRUE) {
   7.516 +        SDL_SetError("PND: Can't find closest configuration for OpenGL ES");
   7.517 +        return NULL;
   7.518 +    }
   7.519 +
   7.520 +    /* Check if nothing has been found, try "don't care" settings */
   7.521 +    if (configs == 0) {
   7.522 +        int32_t it;
   7.523 +        int32_t jt;
   7.524 +        GLint depthbits[4] = { 32, 24, 16, EGL_DONT_CARE };
   7.525 +
   7.526 +        for (it = 0; it < 4; it++) {
   7.527 +            for (jt = 16; jt >= 0; jt--) {
   7.528 +                /* Don't care about color buffer bits, use what exist */
   7.529 +                /* Replace previous set data with EGL_DONT_CARE       */
   7.530 +                attr_pos = 0;
   7.531 +                wdata->gles_attributes[attr_pos++] = EGL_SURFACE_TYPE;
   7.532 +                wdata->gles_attributes[attr_pos++] = EGL_WINDOW_BIT;
   7.533 +                wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
   7.534 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.535 +                wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
   7.536 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.537 +                wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
   7.538 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.539 +                wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
   7.540 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.541 +                wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
   7.542 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.543 +
   7.544 +                /* Try to find requested or smallest depth */
   7.545 +                if (_this->gl_config.depth_size) {
   7.546 +                    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
   7.547 +                    wdata->gles_attributes[attr_pos++] = depthbits[it];
   7.548 +                } else {
   7.549 +                    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
   7.550 +                    wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.551 +                }
   7.552 +
   7.553 +                if (_this->gl_config.stencil_size) {
   7.554 +                    wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
   7.555 +                    wdata->gles_attributes[attr_pos++] = jt;
   7.556 +                } else {
   7.557 +                    wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
   7.558 +                    wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.559 +                }
   7.560 +
   7.561 +                wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
   7.562 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.563 +                wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
   7.564 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
   7.565 +                wdata->gles_attributes[attr_pos] = EGL_NONE;
   7.566 +
   7.567 +                /* Request first suitable framebuffer configuration */
   7.568 +                status =
   7.569 +                    eglChooseConfig(phdata->egl_display,
   7.570 +                                    wdata->gles_attributes,
   7.571 +                                    wdata->gles_configs, 1, &configs);
   7.572 +
   7.573 +                if (status != EGL_TRUE) {
   7.574 +                    SDL_SetError
   7.575 +                        ("PND: Can't find closest configuration for OpenGL ES");
   7.576 +                    return NULL;
   7.577 +                }
   7.578 +                if (configs != 0) {
   7.579 +                    break;
   7.580 +                }
   7.581 +            }
   7.582 +            if (configs != 0) {
   7.583 +                break;
   7.584 +            }
   7.585 +        }
   7.586 +
   7.587 +        /* No available configs */
   7.588 +        if (configs == 0) {
   7.589 +            SDL_SetError("PND: Can't find any configuration for OpenGL ES");
   7.590 +            return NULL;
   7.591 +        }
   7.592 +    }
   7.593 +
   7.594 +    /* Initialize config index */
   7.595 +    wdata->gles_config = 0;
   7.596 +
   7.597 +    /* Now check each configuration to find out the best */
   7.598 +    for (cit = 0; cit < configs; cit++) {
   7.599 +        uint32_t stencil_found;
   7.600 +        uint32_t depth_found;
   7.601 +
   7.602 +        stencil_found = 0;
   7.603 +        depth_found = 0;
   7.604 +
   7.605 +        if (_this->gl_config.stencil_size) {
   7.606 +            status =
   7.607 +                eglGetConfigAttrib(phdata->egl_display,
   7.608 +                                   wdata->gles_configs[cit], EGL_STENCIL_SIZE,
   7.609 +                                   &attr_value);
   7.610 +            if (status == EGL_TRUE) {
   7.611 +                if (attr_value != 0) {
   7.612 +                    stencil_found = 1;
   7.613 +                }
   7.614 +            }
   7.615 +        } else {
   7.616 +            stencil_found = 1;
   7.617 +        }
   7.618 +
   7.619 +        if (_this->gl_config.depth_size) {
   7.620 +            status =
   7.621 +                eglGetConfigAttrib(phdata->egl_display,
   7.622 +                                   wdata->gles_configs[cit], EGL_DEPTH_SIZE,
   7.623 +                                   &attr_value);
   7.624 +            if (status == EGL_TRUE) {
   7.625 +                if (attr_value != 0) {
   7.626 +                    depth_found = 1;
   7.627 +                }
   7.628 +            }
   7.629 +        } else {
   7.630 +            depth_found = 1;
   7.631 +        }
   7.632 +
   7.633 +        /* Exit from loop if found appropriate configuration */
   7.634 +        if ((depth_found != 0) && (stencil_found != 0)) {
   7.635 +            break;
   7.636 +        }
   7.637 +    }
   7.638 +
   7.639 +    /* If best could not be found, use first */
   7.640 +    if (cit == configs) {
   7.641 +        cit = 0;
   7.642 +    }
   7.643 +    wdata->gles_config = cit;
   7.644 +
   7.645 +    /* Create OpenGL ES context */
   7.646 +    wdata->gles_context =
   7.647 +        eglCreateContext(phdata->egl_display,
   7.648 +                         wdata->gles_configs[wdata->gles_config], NULL, NULL);
   7.649 +    if (wdata->gles_context == EGL_NO_CONTEXT) {
   7.650 +        SDL_SetError("PND: OpenGL ES context creation has been failed");
   7.651 +        return NULL;
   7.652 +    }
   7.653 +
   7.654 +    wdata->gles_surface =
   7.655 +        eglCreateWindowSurface(phdata->egl_display,
   7.656 +                               wdata->gles_configs[wdata->gles_config],
   7.657 +                               (NativeWindowType) 0, NULL);
   7.658 +    if (wdata->gles_surface == 0) {
   7.659 +        SDL_SetError("Error : eglCreateWindowSurface failed;\n");
   7.660 +        return NULL;
   7.661 +    }
   7.662 +
   7.663 +    /* Make just created context current */
   7.664 +    status =
   7.665 +        eglMakeCurrent(phdata->egl_display, wdata->gles_surface,
   7.666 +                       wdata->gles_surface, wdata->gles_context);
   7.667 +    if (status != EGL_TRUE) {
   7.668 +        /* Destroy OpenGL ES surface */
   7.669 +        eglDestroySurface(phdata->egl_display, wdata->gles_surface);
   7.670 +        eglDestroyContext(phdata->egl_display, wdata->gles_context);
   7.671 +        wdata->gles_context = EGL_NO_CONTEXT;
   7.672 +        SDL_SetError("PND: Can't set OpenGL ES context on creation");
   7.673 +        return NULL;
   7.674 +    }
   7.675 +
   7.676 +    _this->gl_config.accelerated = 1;
   7.677 +
   7.678 +    /* Always clear stereo enable, since OpenGL ES do not supports stereo */
   7.679 +    _this->gl_config.stereo = 0;
   7.680 +
   7.681 +    /* Get back samples and samplebuffers configurations. Rest framebuffer */
   7.682 +    /* parameters could be obtained through the OpenGL ES API              */
   7.683 +    status =
   7.684 +        eglGetConfigAttrib(phdata->egl_display,
   7.685 +                           wdata->gles_configs[wdata->gles_config],
   7.686 +                           EGL_SAMPLES, &attr_value);
   7.687 +    if (status == EGL_TRUE) {
   7.688 +        _this->gl_config.multisamplesamples = attr_value;
   7.689 +    }
   7.690 +    status =
   7.691 +        eglGetConfigAttrib(phdata->egl_display,
   7.692 +                           wdata->gles_configs[wdata->gles_config],
   7.693 +                           EGL_SAMPLE_BUFFERS, &attr_value);
   7.694 +    if (status == EGL_TRUE) {
   7.695 +        _this->gl_config.multisamplebuffers = attr_value;
   7.696 +    }
   7.697 +
   7.698 +    /* Get back stencil and depth buffer sizes */
   7.699 +    status =
   7.700 +        eglGetConfigAttrib(phdata->egl_display,
   7.701 +                           wdata->gles_configs[wdata->gles_config],
   7.702 +                           EGL_DEPTH_SIZE, &attr_value);
   7.703 +    if (status == EGL_TRUE) {
   7.704 +        _this->gl_config.depth_size = attr_value;
   7.705 +    }
   7.706 +    status =
   7.707 +        eglGetConfigAttrib(phdata->egl_display,
   7.708 +                           wdata->gles_configs[wdata->gles_config],
   7.709 +                           EGL_STENCIL_SIZE, &attr_value);
   7.710 +    if (status == EGL_TRUE) {
   7.711 +        _this->gl_config.stencil_size = attr_value;
   7.712 +    }
   7.713 +
   7.714 +    /* Under PND OpenGL ES output can't be double buffered */
   7.715 +    _this->gl_config.double_buffer = 0;
   7.716 +
   7.717 +    /* GL ES context was successfully created */
   7.718 +    return wdata->gles_context;
   7.719 +}
   7.720 +
   7.721 +int
   7.722 +PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context)
   7.723 +{
   7.724 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   7.725 +    SDL_WindowData *wdata;
   7.726 +    EGLBoolean status;
   7.727 +
   7.728 +    if (phdata->egl_initialized != SDL_TRUE) {
   7.729 +        SDL_SetError("PND: GF initialization failed, no OpenGL ES support");
   7.730 +        return -1;
   7.731 +    }
   7.732 +
   7.733 +    if ((window == NULL) && (context == NULL)) {
   7.734 +        status =
   7.735 +            eglMakeCurrent(phdata->egl_display, EGL_NO_SURFACE,
   7.736 +                           EGL_NO_SURFACE, EGL_NO_CONTEXT);
   7.737 +        if (status != EGL_TRUE) {
   7.738 +            /* Failed to set current GL ES context */
   7.739 +            SDL_SetError("PND: Can't set OpenGL ES context");
   7.740 +            return -1;
   7.741 +        }
   7.742 +    } else {
   7.743 +        wdata = (SDL_WindowData *) window->driverdata;
   7.744 +        if (wdata->gles_surface == EGL_NO_SURFACE) {
   7.745 +            SDL_SetError
   7.746 +                ("PND: OpenGL ES surface is not initialized for this window");
   7.747 +            return -1;
   7.748 +        }
   7.749 +        if (wdata->gles_context == EGL_NO_CONTEXT) {
   7.750 +            SDL_SetError
   7.751 +                ("PND: OpenGL ES context is not initialized for this window");
   7.752 +            return -1;
   7.753 +        }
   7.754 +        if (wdata->gles_context != context) {
   7.755 +            SDL_SetError
   7.756 +                ("PND: OpenGL ES context is not belong to this window");
   7.757 +            return -1;
   7.758 +        }
   7.759 +        status =
   7.760 +            eglMakeCurrent(phdata->egl_display, wdata->gles_surface,
   7.761 +                           wdata->gles_surface, wdata->gles_context);
   7.762 +        if (status != EGL_TRUE) {
   7.763 +            /* Failed to set current GL ES context */
   7.764 +            SDL_SetError("PND: Can't set OpenGL ES context");
   7.765 +            return -1;
   7.766 +        }
   7.767 +    }
   7.768 +    return 0;
   7.769 +}
   7.770 +
   7.771 +int
   7.772 +PND_gl_setswapinterval(_THIS, int interval)
   7.773 +{
   7.774 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   7.775 +    EGLBoolean status;
   7.776 +
   7.777 +    if (phdata->egl_initialized != SDL_TRUE) {
   7.778 +        SDL_SetError("PND: EGL initialization failed, no OpenGL ES support");
   7.779 +        return -1;
   7.780 +    }
   7.781 +
   7.782 +    /* Check if OpenGL ES connection has been initialized */
   7.783 +    if (phdata->egl_display != EGL_NO_DISPLAY) {
   7.784 +        /* Set swap OpenGL ES interval */
   7.785 +        status = eglSwapInterval(phdata->egl_display, interval);
   7.786 +        if (status == EGL_TRUE) {
   7.787 +            /* Return success to upper level */
   7.788 +            phdata->swapinterval = interval;
   7.789 +            return 0;
   7.790 +        }
   7.791 +    }
   7.792 +
   7.793 +    /* Failed to set swap interval */
   7.794 +    SDL_SetError("PND: Cannot set swap interval");
   7.795 +    return -1;
   7.796 +}
   7.797 +
   7.798 +int
   7.799 +PND_gl_getswapinterval(_THIS)
   7.800 +{
   7.801 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   7.802 +
   7.803 +    if (phdata->egl_initialized != SDL_TRUE) {
   7.804 +        SDL_SetError("PND: GLES initialization failed, no OpenGL ES support");
   7.805 +        return -1;
   7.806 +    }
   7.807 +
   7.808 +    /* Return default swap interval value */
   7.809 +    return phdata->swapinterval;
   7.810 +}
   7.811 +
   7.812 +void
   7.813 +PND_gl_swapwindow(_THIS, SDL_Window * window)
   7.814 +{
   7.815 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   7.816 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
   7.817 +    SDL_DisplayData *didata =
   7.818 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
   7.819 +
   7.820 +
   7.821 +    if (phdata->egl_initialized != SDL_TRUE) {
   7.822 +        SDL_SetError("PND: GLES initialization failed, no OpenGL ES support");
   7.823 +        return;
   7.824 +    }
   7.825 +
   7.826 +    /* Many applications do not uses glFinish(), so we call it for them */
   7.827 +    glFinish();
   7.828 +
   7.829 +    /* Wait until OpenGL ES rendering is completed */
   7.830 +    eglWaitGL();
   7.831 +
   7.832 +    eglSwapBuffers(phdata->egl_display, wdata->gles_surface);
   7.833 +}
   7.834 +
   7.835 +void
   7.836 +PND_gl_deletecontext(_THIS, SDL_GLContext context)
   7.837 +{
   7.838 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   7.839 +    EGLBoolean status;
   7.840 +
   7.841 +    if (phdata->egl_initialized != SDL_TRUE) {
   7.842 +        SDL_SetError("PND: GLES initialization failed, no OpenGL ES support");
   7.843 +        return;
   7.844 +    }
   7.845 +
   7.846 +    /* Check if OpenGL ES connection has been initialized */
   7.847 +    if (phdata->egl_display != EGL_NO_DISPLAY) {
   7.848 +        if (context != EGL_NO_CONTEXT) {
   7.849 +            status = eglDestroyContext(phdata->egl_display, context);
   7.850 +            if (status != EGL_TRUE) {
   7.851 +                /* Error during OpenGL ES context destroying */
   7.852 +                SDL_SetError("PND: OpenGL ES context destroy error");
   7.853 +                return;
   7.854 +            }
   7.855 +        }
   7.856 +    }
   7.857 +
   7.858 +    return;
   7.859 +}
   7.860 +
   7.861 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/pandora/SDL_pandora.h	Sun May 31 11:53:12 2009 +0000
     8.3 @@ -0,0 +1,110 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997-2009 Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Lesser General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2.1 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Lesser General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Lesser General Public
    8.19 +    License along with this library; if not, write to the Free Software
    8.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +
    8.25 +    Open Pandora SDL driver
    8.26 +    Copyright (C) 2009 David Carré
    8.27 +    (cpasjuste@gmail.com)
    8.28 +*/
    8.29 +
    8.30 +#ifndef __SDL_PANDORA_H__
    8.31 +#define __SDL_PANDORA_H__
    8.32 +
    8.33 +#include <GLES/egl.h>
    8.34 +
    8.35 +#include "SDL_config.h"
    8.36 +#include "../SDL_sysvideo.h"
    8.37 +
    8.38 +typedef struct SDL_VideoData
    8.39 +{
    8.40 +    SDL_bool egl_initialized;   /* OpenGL ES device initialization status */
    8.41 +    EGLDisplay egl_display;     /* OpenGL ES display connection           */
    8.42 +    uint32_t egl_refcount;      /* OpenGL ES reference count              */
    8.43 +    uint32_t swapinterval;      /* OpenGL ES default swap interval        */
    8.44 +
    8.45 +} SDL_VideoData;
    8.46 +
    8.47 +
    8.48 +typedef struct SDL_DisplayData
    8.49 +{
    8.50 +
    8.51 +} SDL_DisplayData;
    8.52 +
    8.53 +
    8.54 +typedef struct SDL_WindowData
    8.55 +{
    8.56 +    SDL_bool uses_gles;         /* if true window must support OpenGL ES */
    8.57 +
    8.58 +    EGLConfig gles_configs[32];
    8.59 +    EGLint gles_config;         /* OpenGL ES configuration index      */
    8.60 +    EGLContext gles_context;    /* OpenGL ES context                  */
    8.61 +    EGLint gles_attributes[256];        /* OpenGL ES attributes for context   */
    8.62 +    EGLSurface gles_surface;    /* OpenGL ES target rendering surface */
    8.63 +
    8.64 +} SDL_WindowData;
    8.65 +
    8.66 +
    8.67 +/****************************************************************************/
    8.68 +/* SDL_VideoDevice functions declaration                                    */
    8.69 +/****************************************************************************/
    8.70 +
    8.71 +/* Display and window functions */
    8.72 +int PND_videoinit(_THIS);
    8.73 +void PND_videoquit(_THIS);
    8.74 +void PND_getdisplaymodes(_THIS);
    8.75 +int PND_setdisplaymode(_THIS, SDL_DisplayMode * mode);
    8.76 +int PND_setdisplaypalette(_THIS, SDL_Palette * palette);
    8.77 +int PND_getdisplaypalette(_THIS, SDL_Palette * palette);
    8.78 +int PND_setdisplaygammaramp(_THIS, Uint16 * ramp);
    8.79 +int PND_getdisplaygammaramp(_THIS, Uint16 * ramp);
    8.80 +int PND_createwindow(_THIS, SDL_Window * window);
    8.81 +int PND_createwindowfrom(_THIS, SDL_Window * window, const void *data);
    8.82 +void PND_setwindowtitle(_THIS, SDL_Window * window);
    8.83 +void PND_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon);
    8.84 +void PND_setwindowposition(_THIS, SDL_Window * window);
    8.85 +void PND_setwindowsize(_THIS, SDL_Window * window);
    8.86 +void PND_showwindow(_THIS, SDL_Window * window);
    8.87 +void PND_hidewindow(_THIS, SDL_Window * window);
    8.88 +void PND_raisewindow(_THIS, SDL_Window * window);
    8.89 +void PND_maximizewindow(_THIS, SDL_Window * window);
    8.90 +void PND_minimizewindow(_THIS, SDL_Window * window);
    8.91 +void PND_restorewindow(_THIS, SDL_Window * window);
    8.92 +void PND_setwindowgrab(_THIS, SDL_Window * window);
    8.93 +void PND_destroywindow(_THIS, SDL_Window * window);
    8.94 +
    8.95 +/* Window manager function */
    8.96 +SDL_bool PND_getwindowwminfo(_THIS, SDL_Window * window,
    8.97 +                             struct SDL_SysWMinfo *info);
    8.98 +
    8.99 +/* OpenGL/OpenGL ES functions */
   8.100 +int PND_gl_loadlibrary(_THIS, const char *path);
   8.101 +void *PND_gl_getprocaddres(_THIS, const char *proc);
   8.102 +void PND_gl_unloadlibrary(_THIS);
   8.103 +SDL_GLContext PND_gl_createcontext(_THIS, SDL_Window * window);
   8.104 +int PND_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context);
   8.105 +int PND_gl_setswapinterval(_THIS, int interval);
   8.106 +int PND_gl_getswapinterval(_THIS);
   8.107 +void PND_gl_swapwindow(_THIS, SDL_Window * window);
   8.108 +void PND_gl_deletecontext(_THIS, SDL_GLContext context);
   8.109 +
   8.110 +
   8.111 +#endif /* __SDL_PANDORA_H__ */
   8.112 +
   8.113 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/video/pandora/SDL_pandora_events.c	Sun May 31 11:53:12 2009 +0000
     9.3 @@ -0,0 +1,36 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997-2009 Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Lesser General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2.1 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Lesser General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Lesser General Public
    9.19 +    License along with this library; if not, write to the Free Software
    9.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@libsdl.org
    9.24 +*/
    9.25 +#include "SDL_config.h"
    9.26 +
    9.27 +/* Being a null driver, there's no event stream. We just define stubs for
    9.28 +   most of the API. */
    9.29 +
    9.30 +#include "../../events/SDL_sysevents.h"
    9.31 +#include "../../events/SDL_events_c.h"
    9.32 +
    9.33 +void
    9.34 +PND_PumpEvents(_THIS)
    9.35 +{
    9.36 +    /* Not implemented. */
    9.37 +}
    9.38 +
    9.39 +/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/video/pandora/SDL_pandora_events.h	Sun May 31 11:53:12 2009 +0000
    10.3 @@ -0,0 +1,26 @@
    10.4 +/*
    10.5 +    SDL - Simple DirectMedia Layer
    10.6 +    Copyright (C) 1997-2009 Sam Lantinga
    10.7 +
    10.8 +    This library is free software; you can redistribute it and/or
    10.9 +    modify it under the terms of the GNU Lesser General Public
   10.10 +    License as published by the Free Software Foundation; either
   10.11 +    version 2.1 of the License, or (at your option) any later version.
   10.12 +
   10.13 +    This library is distributed in the hope that it will be useful,
   10.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10.16 +    Lesser General Public License for more details.
   10.17 +
   10.18 +    You should have received a copy of the GNU Lesser General Public
   10.19 +    License along with this library; if not, write to the Free Software
   10.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   10.21 +
   10.22 +    Sam Lantinga
   10.23 +    slouken@libsdl.org
   10.24 +*/
   10.25 +#include "SDL_config.h"
   10.26 +
   10.27 +extern void PND_PumpEvents(_THIS);
   10.28 +
   10.29 +/* vi: set ts=4 sw=4 expandtab: */
    11.1 --- a/src/video/x11/SDL_x11window.c	Thu May 28 09:39:14 2009 +0000
    11.2 +++ b/src/video/x11/SDL_x11window.c	Sun May 31 11:53:12 2009 +0000
    11.3 @@ -31,6 +31,10 @@
    11.4  #include "SDL_x11gamma.h"
    11.5  #include "../Xext/extensions/StdCmap.h"
    11.6  
    11.7 +#ifdef SDL_VIDEO_DRIVER_PANDORA
    11.8 +#include "SDL_x11opengles.h"
    11.9 +#endif
   11.10 +
   11.11  #define _NET_WM_STATE_REMOVE    0l
   11.12  #define _NET_WM_STATE_ADD       1l
   11.13  #define _NET_WM_STATE_TOGGLE    2l
   11.14 @@ -241,6 +245,19 @@
   11.15          XFree(vinfo);
   11.16      } else
   11.17  #endif
   11.18 +#ifdef SDL_VIDEO_DRIVER_PANDORA
   11.19 +    if (window->flags & SDL_WINDOW_OPENGL) {
   11.20 +        XVisualInfo *vinfo;
   11.21 +
   11.22 +        vinfo = X11_GLES_GetVisual(_this, data->display, displaydata->screen);
   11.23 +        if (!vinfo) {
   11.24 +            return -1;
   11.25 +        }
   11.26 +        visual = vinfo->visual;
   11.27 +        depth = vinfo->depth;
   11.28 +        XFree(vinfo);
   11.29 +    } else
   11.30 +#endif
   11.31      {
   11.32          visual = displaydata->visual;
   11.33          depth = displaydata->depth;
   11.34 @@ -505,6 +522,19 @@
   11.35          SDL_SetError("Couldn't create window");
   11.36          return -1;
   11.37      }
   11.38 +#if SDL_VIDEO_DRIVER_PANDORA
   11.39 +    /* Create the GLES window surface */
   11.40 +    _this->gles_data->egl_surface =
   11.41 +        _this->gles_data->eglCreateWindowSurface(_this->gles_data->
   11.42 +                                                 egl_display,
   11.43 +                                                 _this->gles_data->egl_config,
   11.44 +                                                 (NativeWindowType) w, NULL);
   11.45 +
   11.46 +    if (_this->gles_data->egl_surface == EGL_NO_SURFACE) {
   11.47 +        SDL_SetError("Could not create GLES window surface");
   11.48 +        return -1;
   11.49 +    }
   11.50 +#endif
   11.51  
   11.52      sizehints = XAllocSizeHints();
   11.53      if (sizehints) {