Continue working on QNX Photon with OpenGL ES support
authorMike Gorchak <lestat@i.com.ua>
Tue, 28 Apr 2009 04:30:52 +0000
changeset 3108aa1897bee1e9
parent 3107 3cf236d3cd81
child 3109 7b3a09fb9c8b
Continue working on QNX Photon with OpenGL ES support
src/video/photon/SDL_photon.c
src/video/photon/SDL_photon.h
src/video/photon/SDL_photon_input.c
src/video/photon/SDL_photon_input.h
src/video/photon/SDL_photon_keycodes.h
src/video/photon/SDL_photon_pixelfmt.c
src/video/photon/SDL_photon_pixelfmt.h
src/video/photon/SDL_photon_render.c
     1.1 --- a/src/video/photon/SDL_photon.c	Fri Apr 24 03:46:54 2009 +0000
     1.2 +++ b/src/video/photon/SDL_photon.c	Tue Apr 28 04:30:52 2009 +0000
     1.3 @@ -24,15 +24,104 @@
     1.4      (mike@malva.ua, lestat@i.com.ua)
     1.5  */
     1.6  
     1.7 +/* SDL internals */
     1.8  #include "SDL_config.h"
     1.9 -
    1.10  #include "../SDL_sysvideo.h"
    1.11  #include "SDL_version.h"
    1.12  #include "SDL_syswm.h"
    1.13 +#include "SDL_loadso.h"
    1.14 +#include "SDL_events.h"
    1.15 +#include "../../events/SDL_mouse_c.h"
    1.16 +#include "../../events/SDL_keyboard_c.h"
    1.17  
    1.18 -#include "../SDL_sysvideo.h"
    1.19 +/* Photon declarations */
    1.20 +#include "SDL_photon.h"
    1.21 +
    1.22 +/* Pixel format conversion routines */
    1.23 +#include "SDL_photon_pixelfmt.h"
    1.24 +
    1.25 +/* Use GF's pixel format functions for OpenGL ES context creation */
    1.26 +#if defined(SDL_VIDEO_OPENGL_ES)
    1.27 +   #include "../qnxgf/SDL_gf_pixelfmt.h"
    1.28 +
    1.29 +   /* If GF driver is not compiled in, include some of usefull functions */
    1.30 +   #if !defined(SDL_VIDEO_DRIVER_QNXGF)
    1.31 +      #include "../qnxgf/SDL_gf_pixelfmt.c"
    1.32 +   #endif /* SDL_VIDEO_DRIVER_QNXGF */
    1.33 +#endif /* SDL_VIDEO_OPENGL_ES */
    1.34 +
    1.35 +/* Use GF's OpenGL ES 1.1 functions emulation */
    1.36 +#if defined(SDL_VIDEO_OPENGL_ES)
    1.37 +   #include "../qnxgf/SDL_gf_opengles.h"
    1.38 +
    1.39 +   /* If GF driver is not compiled in, include some of usefull functions */
    1.40 +   #if !defined(SDL_VIDEO_DRIVER_QNXGF)
    1.41 +      #include "../qnxgf/SDL_gf_opengles.c"
    1.42 +   #endif /* SDL_VIDEO_DRIVER_QNXGF */
    1.43 +#endif /* SDL_VIDEO_OPENGL_ES */
    1.44  
    1.45 -#include "SDL_photon.h"
    1.46 +/* Low level device graphics driver names, which they are reporting */
    1.47 +Photon_DeviceCaps photon_devicename[]=
    1.48 +{
    1.49 +   /* ATI Rage 128 graphics driver (devg-ati_rage128)      */
    1.50 +   {"ati_rage128", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.51 +   /* Fujitsu Carmine graphics driver (devg-carmine.so)    */
    1.52 +   {"carmine",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
    1.53 +   /* C&T graphics driver (devg-chips.so)                  */
    1.54 +   {"chips",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.55 +   /* Fujitsu Coral graphics driver (devg-coral.so)        */
    1.56 +   {"coral",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
    1.57 +   /* Intel integrated graphics driver (devg-extreme2.so)  */
    1.58 +   {"extreme2",    SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
    1.59 +   /* Unaccelerated FB driver (devg-flat.so)               */
    1.60 +   {"flat",        SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.61 +   /* NS Geode graphics driver (devg-geode.so)             */
    1.62 +   {"geode",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.63 +   /* Geode LX graphics driver (devg-geodelx.so)           */
    1.64 +   {"geodelx",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.65 +   /* Intel integrated graphics driver (devg-gma9xx.so)    */
    1.66 +   {"gma",         SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
    1.67 +   /* Intel integrated graphics driver (devg-i810.so)      */
    1.68 +   {"i810",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.69 +   /* Intel integrated graphics driver (devg-i830.so)      */
    1.70 +   {"i830",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.71 +   /* Geode LX graphics driver (devg-lx800.so)             */
    1.72 +   {"lx800",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.73 +   /* Matrox Gxx graphics driver (devg-matroxg.so)         */
    1.74 +   {"matroxg",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.75 +   /* Intel Poulsbo graphics driver (devg-poulsbo.so)      */
    1.76 +   {"poulsbo",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
    1.77 +   /* ATI Radeon driver (devg-radeon.so)                   */
    1.78 +   {"radeon",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.79 +   /* ATI Rage driver (devg-rage.so)                       */
    1.80 +   {"rage",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.81 +   /* S3 Savage graphics driver (devg-s3_savage.so)        */
    1.82 +   {"s3_savage",   SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.83 +   /* SiS630 integrated graphics driver (devg-sis630.so)   */
    1.84 +   {"sis630",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.85 +   /* PowerVR SGX 535 graphics driver (devg-poulsbo.so)    */
    1.86 +   {"sgx",         SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
    1.87 +   /* SM Voyager GX graphics driver (devg-smi5xx.so)       */
    1.88 +   {"smi5xx",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.89 +   /* Silicon Motion graphics driver (devg-smi7xx.so)      */
    1.90 +   {"smi7xx",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.91 +   /* SVGA unaccelerated gfx driver (devg-svga.so)         */
    1.92 +   {"svga",        SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.93 +   /* nVidia TNT graphics driver (devg-tnt.so)             */
    1.94 +   {"tnt",         SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.95 +   /* VIA integrated graphics driver (devg-tvia.so)        */
    1.96 +   {"tvia",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.97 +   /* VIA UniChrome graphics driver (devg-unichrome.so)    */
    1.98 +   {"unichrome",   SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
    1.99 +   /* VESA unaccelerated gfx driver (devg-vesa.so)         */
   1.100 +   {"vesa",        SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   1.101 +   /* VmWare graphics driver (devg-volari.so)              */
   1.102 +   {"vmware",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   1.103 +   /* XGI XP10 graphics driver (devg-volari.so), OpenGL 1.5*/
   1.104 +   {"volari",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   1.105 +   /* End of list */
   1.106 +   {NULL,          0x00000000}
   1.107 +};
   1.108  
   1.109  static SDL_bool photon_initialized=SDL_FALSE;
   1.110  
   1.111 @@ -62,13 +151,26 @@
   1.112  
   1.113  static void photon_destroy(SDL_VideoDevice* device)
   1.114  {
   1.115 +   SDL_VideoData* phdata=(SDL_VideoData*) device->driverdata;
   1.116 +
   1.117 +   #if defined(SDL_VIDEO_OPENGL_ES)
   1.118 +      if (phdata->gfinitialized!=SDL_FALSE)
   1.119 +      {
   1.120 +         gf_dev_detach(phdata->gfdev);
   1.121 +      }
   1.122 +   #endif /* SDL_VIDEO_OPENGL_ES */
   1.123 +
   1.124 +   if (device->driverdata!=NULL)
   1.125 +   {
   1.126 +      device->driverdata=NULL;
   1.127 +   }
   1.128  }
   1.129  
   1.130  static SDL_VideoDevice* photon_create(int devindex)
   1.131  {
   1.132 -   SDL_VideoDevice* device;
   1.133 -   SDL_VideoData*   phdata;
   1.134 -   int              status;
   1.135 +   SDL_VideoDevice*  device;
   1.136 +   SDL_VideoData*    phdata;
   1.137 +   int               status;
   1.138  
   1.139     /* Check if photon could be initialized */
   1.140     status=photon_available();
   1.141 @@ -78,6 +180,13 @@
   1.142        return NULL;
   1.143     }
   1.144  
   1.145 +   /* Photon agregates all video devices to one with multiple heads */
   1.146 +   if (devindex!=0)
   1.147 +   {
   1.148 +      /* devindex could be zero only in Photon SDL driver */
   1.149 +      return NULL;
   1.150 +   }
   1.151 +
   1.152     /* Initialize SDL_VideoDevice structure */
   1.153     device=(SDL_VideoDevice*)SDL_calloc(1, sizeof(SDL_VideoDevice));
   1.154     if (device==NULL)
   1.155 @@ -96,9 +205,85 @@
   1.156     }
   1.157     device->driverdata=phdata;
   1.158  
   1.159 +   /* Get all photon display devices */
   1.160 +   phdata->avail_rids=PdGetDevices(&phdata->rid[0], SDL_VIDEO_PHOTON_MAX_RIDS);
   1.161 +   if (phdata->avail_rids>SDL_VIDEO_PHOTON_MAX_RIDS)
   1.162 +   {
   1.163 +      phdata->avail_rids=SDL_VIDEO_PHOTON_MAX_RIDS;
   1.164 +   }
   1.165 +
   1.166 +   #if defined(SDL_VIDEO_OPENGL_ES)
   1.167 +      /* TODO: add real device detection versus multiple heads */
   1.168 +      status=gf_dev_attach(&phdata->gfdev, GF_DEVICE_INDEX(0), &phdata->gfdev_info);
   1.169 +      if (status!=GF_ERR_OK)
   1.170 +      {
   1.171 +         /* Do not fail right now, if GF can't be attached */
   1.172 +         phdata->gfinitialized=SDL_FALSE;
   1.173 +      }
   1.174 +      else
   1.175 +      {
   1.176 +         phdata->gfinitialized=SDL_TRUE;
   1.177 +      }
   1.178 +   #endif /* SDL_VIDEO_OPENGL_ES */
   1.179 +
   1.180 +   /* Set default target device */
   1.181 +   status=PdSetTargetDevice(NULL, phdata->rid[0]);
   1.182 +   if (status==-1)
   1.183 +   {
   1.184 +      SDL_SetError("Photon: Can't set default target device");
   1.185 +      #if defined(SDL_VIDEO_OPENGL_ES)
   1.186 +         gf_dev_detach(phdata->gfdev);
   1.187 +      #endif /* SDL_VIDEO_OPENGL_ES */
   1.188 +      SDL_free(phdata);
   1.189 +      SDL_free(device);
   1.190 +      return NULL;
   1.191 +   }
   1.192 +   phdata->current_device_id=0;
   1.193 +
   1.194     /* Setup amount of available displays and current display */
   1.195     device->num_displays=0;
   1.196     device->current_display=0;
   1.197 +
   1.198 +   /* Set device free function */
   1.199 +   device->free=photon_destroy;
   1.200 +
   1.201 +   /* Setup all functions which we can handle */
   1.202 +   device->VideoInit=photon_videoinit;
   1.203 +   device->VideoQuit=photon_videoquit;
   1.204 +   device->GetDisplayModes=photon_getdisplaymodes;
   1.205 +   device->SetDisplayMode=photon_setdisplaymode;
   1.206 +   device->SetDisplayPalette=photon_setdisplaypalette;
   1.207 +   device->GetDisplayPalette=photon_getdisplaypalette;
   1.208 +   device->SetDisplayGammaRamp=photon_setdisplaygammaramp;
   1.209 +   device->GetDisplayGammaRamp=photon_getdisplaygammaramp;
   1.210 +   device->CreateWindow=photon_createwindow;
   1.211 +   device->CreateWindowFrom=photon_createwindowfrom;
   1.212 +   device->SetWindowTitle=photon_setwindowtitle;
   1.213 +   device->SetWindowIcon=photon_setwindowicon;
   1.214 +   device->SetWindowPosition=photon_setwindowposition;
   1.215 +   device->SetWindowSize=photon_setwindowsize;
   1.216 +   device->ShowWindow=photon_showwindow;
   1.217 +   device->HideWindow=photon_hidewindow;
   1.218 +   device->RaiseWindow=photon_raisewindow;
   1.219 +   device->MaximizeWindow=photon_maximizewindow;
   1.220 +   device->MinimizeWindow=photon_minimizewindow;
   1.221 +   device->RestoreWindow=photon_restorewindow;
   1.222 +   device->SetWindowGrab=photon_setwindowgrab;
   1.223 +   device->DestroyWindow=photon_destroywindow;
   1.224 +   device->GetWindowWMInfo=photon_getwindowwminfo;
   1.225 +   device->GL_LoadLibrary=photon_gl_loadlibrary;
   1.226 +   device->GL_GetProcAddress=photon_gl_getprocaddres;
   1.227 +   device->GL_UnloadLibrary=photon_gl_unloadlibrary;
   1.228 +   device->GL_CreateContext=photon_gl_createcontext;
   1.229 +   device->GL_MakeCurrent=photon_gl_makecurrent;
   1.230 +   device->GL_SetSwapInterval=photon_gl_setswapinterval;
   1.231 +   device->GL_GetSwapInterval=photon_gl_getswapinterval;
   1.232 +   device->GL_SwapWindow=photon_gl_swapwindow;
   1.233 +   device->GL_DeleteContext=photon_gl_deletecontext;
   1.234 +   device->PumpEvents=photon_pumpevents;
   1.235 +   device->SuspendScreenSaver=photon_suspendscreensaver;
   1.236 +
   1.237 +   return device;
   1.238  }
   1.239  
   1.240  VideoBootStrap photon_bootstrap=
   1.241 @@ -114,18 +299,147 @@
   1.242  /*****************************************************************************/
   1.243  int photon_videoinit(_THIS)
   1.244  {
   1.245 -   SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
   1.246 +   SDL_VideoData*    phdata=(SDL_VideoData*)_this->driverdata;
   1.247 +   PgHWCaps_t        hwcaps;
   1.248 +   PgVideoModeInfo_t modeinfo;
   1.249 +   int32_t           status;
   1.250 +   SDL_VideoDisplay  display;
   1.251 +   SDL_DisplayMode   current_mode;
   1.252 +   SDL_DisplayData*  didata;
   1.253 +   uint32_t          it;
   1.254 +   uint32_t          jt;
   1.255 +   char*             override;
   1.256 +
   1.257 +   /* By default Photon do not uses swap on VSYNC */
   1.258 +   phdata->swapinterval=0;
   1.259 +
   1.260 +   for (it=0; it<phdata->avail_rids; it++)
   1.261 +   {
   1.262 +      didata=(SDL_DisplayData*)SDL_calloc(1, sizeof(SDL_DisplayData));
   1.263 +      if (didata==NULL)
   1.264 +      {
   1.265 +         /* memory allocation error */
   1.266 +         SDL_OutOfMemory();
   1.267 +         return -1;
   1.268 +      }
   1.269 +
   1.270 +      /* Allocate two cursors with SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE size */
   1.271 +      /* and 128 bytes of spare place                                    */
   1.272 +      didata->cursor_size=((SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE*4)>>3)+128;
   1.273 +      didata->cursor=(PhCursorDef_t*)SDL_calloc(1, didata->cursor_size);
   1.274 +      if (didata->cursor==NULL)
   1.275 +      {
   1.276 +         /* memory allocation error */
   1.277 +         SDL_OutOfMemory();
   1.278 +         SDL_free(didata);
   1.279 +         return -1;
   1.280 +      }
   1.281 +
   1.282 +      /* Initialize GF in case of OpenGL ES support is compiled in */
   1.283 +      #if defined(SDL_VIDEO_OPENGL_ES)
   1.284 +         /* TODO: add real device detection versus multiple heads */
   1.285 +         if (phdata->gfinitialized==SDL_TRUE)
   1.286 +         {
   1.287 +            status=gf_display_attach(&didata->display, phdata->gfdev, it, &didata->display_info);
   1.288 +            if (status!=GF_ERR_OK)
   1.289 +            {
   1.290 +               /* Just shutdown GF, do not fail */
   1.291 +               gf_dev_detach(phdata->gfdev);
   1.292 +               phdata->gfinitialized=SDL_FALSE;
   1.293 +            }
   1.294 +         }
   1.295 +      #endif /* SDL_VIDEO_OPENGL_ES */
   1.296 +
   1.297 +      /* Check if current device is not the same as target */
   1.298 +      if (phdata->current_device_id!=it)
   1.299 +      {
   1.300 +         /* Set target device as default for Pd and Pg functions */
   1.301 +         status=PdSetTargetDevice(NULL, phdata->rid[it]);
   1.302 +         if (status!=0)
   1.303 +         {
   1.304 +            SDL_SetError("Photon: Can't set default target device\n");
   1.305 +            SDL_free(didata->cursor);
   1.306 +            SDL_free(didata);
   1.307 +            return -1;
   1.308 +         }
   1.309 +         phdata->current_device_id=it;
   1.310 +      }
   1.311 +
   1.312 +      /* Store device id */
   1.313 +      didata->device_id=it;
   1.314  
   1.315 -   /* Check for environment variables which could override some SDL settings */
   1.316 -//   didata->custom_refresh=0;
   1.317 -//   override = SDL_getenv("SDL_VIDEO_PHOTON_REFRESH_RATE");
   1.318 -//   if (override!=NULL)
   1.319 -//   {
   1.320 -//      if (SDL_sscanf(override, "%u", &didata->custom_refresh)!=1)
   1.321 -//      {
   1.322 -//         didata->custom_refresh=0;
   1.323 -//      }
   1.324 -//   }
   1.325 +      /* Query photon about graphics hardware caps and current video mode */
   1.326 +      status=PgGetGraphicsHWCaps(&hwcaps);
   1.327 +      if (status!=0)
   1.328 +      {
   1.329 +         SDL_SetError("Photon: Can't get graphics capabilities");
   1.330 +         SDL_free(didata->cursor);
   1.331 +         SDL_free(didata);
   1.332 +         return -1;
   1.333 +      }
   1.334 +
   1.335 +      /* Get current video mode details */
   1.336 +      status=PgGetVideoModeInfo(hwcaps.current_video_mode, &modeinfo);
   1.337 +      if (status!=0)
   1.338 +      {
   1.339 +         SDL_SetError("Photon: Can't get current video mode information");
   1.340 +         SDL_free(didata->cursor);
   1.341 +         SDL_free(didata);
   1.342 +         return -1;
   1.343 +      }
   1.344 +
   1.345 +      /* Setup current desktop mode for SDL */
   1.346 +      SDL_zero(current_mode);
   1.347 +      current_mode.w=modeinfo.width;
   1.348 +      current_mode.h=modeinfo.height;
   1.349 +      current_mode.refresh_rate=hwcaps.current_rrate;
   1.350 +      current_mode.format=photon_image_to_sdl_pixelformat(modeinfo.type);
   1.351 +      current_mode.driverdata=NULL;
   1.352 +
   1.353 +      /* Copy device name */
   1.354 +      SDL_strlcpy(didata->description, hwcaps.chip_name, SDL_VIDEO_PHOTON_DEVICENAME_MAX-1);
   1.355 +
   1.356 +      /* Search device capabilities and possible workarounds */
   1.357 +      jt=0;
   1.358 +      do {
   1.359 +         if (photon_devicename[jt].name==NULL)
   1.360 +         {
   1.361 +            break;
   1.362 +         }
   1.363 +         if (SDL_strncmp(photon_devicename[jt].name, didata->description, SDL_strlen(photon_devicename[jt].name))==0)
   1.364 +         {
   1.365 +            didata->caps=photon_devicename[jt].caps;
   1.366 +         }
   1.367 +         jt++;
   1.368 +      } while(1);
   1.369 +
   1.370 +      /* Initialize display structure */
   1.371 +      SDL_zero(display);
   1.372 +      display.desktop_mode=current_mode;
   1.373 +      display.current_mode=current_mode;
   1.374 +      display.driverdata=didata;
   1.375 +      didata->current_mode=current_mode;
   1.376 +      SDL_AddVideoDisplay(&display);
   1.377 +
   1.378 +      /* Check for environment variables which could override some SDL settings */
   1.379 +      didata->custom_refresh=0;
   1.380 +      override=SDL_getenv("SDL_VIDEO_PHOTON_REFRESH_RATE");
   1.381 +      if (override!=NULL)
   1.382 +      {
   1.383 +         if (SDL_sscanf(override, "%u", &didata->custom_refresh)!=1)
   1.384 +         {
   1.385 +            didata->custom_refresh=0;
   1.386 +         }
   1.387 +      }
   1.388 +   }
   1.389 +
   1.390 +   /* Add photon input devices */
   1.391 +   status=photon_addinputdevices(_this);
   1.392 +   if (status!=0)
   1.393 +   {
   1.394 +      /* SDL error is set by photon_addinputdevices() function */
   1.395 +      return -1;
   1.396 +   }
   1.397  
   1.398     /* Add photon renderer to SDL */
   1.399     photon_addrenderdriver(_this);
   1.400 @@ -136,6 +450,7 @@
   1.401  
   1.402  void photon_videoquit(_THIS)
   1.403  {
   1.404 +   SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
   1.405     SDL_DisplayData* didata;
   1.406     uint32_t it;
   1.407  
   1.408 @@ -143,19 +458,270 @@
   1.409     for(it=0; it<_this->num_displays; it++)
   1.410     {
   1.411        didata=_this->displays[it].driverdata;
   1.412 +
   1.413 +      if (didata->cursor!=NULL)
   1.414 +      {
   1.415 +         SDL_free(didata->cursor);
   1.416 +      }
   1.417 +
   1.418 +      #if defined(SDL_VIDEO_OPENGL_ES)
   1.419 +         if (phdata->gfinitialized==SDL_TRUE)
   1.420 +         {
   1.421 +            /* Detach GF display */
   1.422 +            gf_display_detach(didata->display);
   1.423 +         }
   1.424 +      #endif /* SDL_VIDEO_OPENGL_ES */
   1.425     }
   1.426  }
   1.427  
   1.428  void photon_getdisplaymodes(_THIS)
   1.429  {
   1.430 -   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
   1.431 -   SDL_DisplayMode  mode;
   1.432 +   SDL_VideoData*    phdata=(SDL_VideoData*)_this->driverdata;
   1.433 +   SDL_DisplayData*  didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
   1.434 +   SDL_DisplayMode   mode;
   1.435 +   PgVideoModes_t    modes;
   1.436 +   PgVideoModeInfo_t modeinfo;
   1.437 +   int32_t           status;
   1.438 +   uint32_t          it;
   1.439 +   uint32_t          jt;
   1.440 +
   1.441 +   /* Check if current device is not the same as target */
   1.442 +   if (phdata->current_device_id!=didata->device_id)
   1.443 +   {
   1.444 +      /* Set target device as default for Pd and Pg functions */
   1.445 +      status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
   1.446 +      if (status!=0)
   1.447 +      {
   1.448 +         SDL_SetError("Photon: Can't set default target device\n");
   1.449 +         return;
   1.450 +      }
   1.451 +      phdata->current_device_id=didata->device_id;
   1.452 +   }
   1.453  
   1.454 +   /* Get array of available video modes */
   1.455 +   status=PgGetVideoModeList(&modes);
   1.456 +   if (status!=0)
   1.457 +   {
   1.458 +      SDL_SetError("Photon: Can't get video mode list");
   1.459 +      return;
   1.460 +   }
   1.461 +
   1.462 +   for (it=0; it<modes.num_modes; it++)
   1.463 +   {
   1.464 +      status=PgGetVideoModeInfo(modes.modes[it], &modeinfo);
   1.465 +      if (status!=0)
   1.466 +      {
   1.467 +         /* Maybe something wrong with this particular mode, skip it */
   1.468 +         continue;
   1.469 +      }
   1.470 +
   1.471 +      jt=0;
   1.472 +      do {
   1.473 +         if (modeinfo.refresh_rates[jt]!=0)
   1.474 +         {
   1.475 +            mode.w=modeinfo.width;
   1.476 +            mode.h=modeinfo.height;
   1.477 +            mode.refresh_rate=modeinfo.refresh_rates[jt];
   1.478 +            mode.format=photon_image_to_sdl_pixelformat(modeinfo.type);
   1.479 +            mode.driverdata=NULL;
   1.480 +            SDL_AddDisplayMode(_this->current_display, &mode);
   1.481 +            jt++;
   1.482 +         }
   1.483 +         else
   1.484 +         {
   1.485 +            break;
   1.486 +         }
   1.487 +      } while(1);
   1.488 +   }
   1.489  }
   1.490  
   1.491  int photon_setdisplaymode(_THIS, SDL_DisplayMode* mode)
   1.492  {
   1.493 -   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
   1.494 +   SDL_VideoData*      phdata=(SDL_VideoData*)_this->driverdata;
   1.495 +   SDL_DisplayData*    didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
   1.496 +   PgVideoModes_t      modes;
   1.497 +   PgVideoModeInfo_t   modeinfo;
   1.498 +   PgDisplaySettings_t modesettings;
   1.499 +   uint32_t refresh_rate=0;
   1.500 +   int32_t  status;
   1.501 +   uint32_t it;
   1.502 +
   1.503 +   /* Check if current device is not the same as target */
   1.504 +   if (phdata->current_device_id!=didata->device_id)
   1.505 +   {
   1.506 +      /* Set target device as default for Pd and Pg functions */
   1.507 +      status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
   1.508 +      if (status!=0)
   1.509 +      {
   1.510 +         SDL_SetError("Photon: Can't set default target device\n");
   1.511 +         return;
   1.512 +      }
   1.513 +      phdata->current_device_id=didata->device_id;
   1.514 +   }
   1.515 +
   1.516 +   /* Get array of available video modes */
   1.517 +   status=PgGetVideoModeList(&modes);
   1.518 +   if (status!=0)
   1.519 +   {
   1.520 +      SDL_SetError("Photon: Can't get video mode list");
   1.521 +      return;
   1.522 +   }
   1.523 +
   1.524 +   /* Current display dimensions and bpp are no more valid */
   1.525 +   didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN;
   1.526 +   didata->current_mode.w=0;
   1.527 +   didata->current_mode.h=0;
   1.528 +
   1.529 +   /* Check if custom refresh rate requested */
   1.530 +   if (didata->custom_refresh!=0)
   1.531 +   {
   1.532 +      refresh_rate=didata->custom_refresh;
   1.533 +   }
   1.534 +   else
   1.535 +   {
   1.536 +      refresh_rate=mode->refresh_rate;
   1.537 +   }
   1.538 +
   1.539 +   /* Check if SDL GF driver needs to find appropriate refresh rate itself */
   1.540 +   if (refresh_rate==0)
   1.541 +   {
   1.542 +      SDL_DisplayMode tempmode;
   1.543 +
   1.544 +      /* Clear display mode structure */
   1.545 +      SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
   1.546 +      tempmode.refresh_rate=0x0000FFFF;
   1.547 +
   1.548 +      /* Check if window width and height matches one of our modes */
   1.549 +      for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++)
   1.550 +      {
   1.551 +         if ((SDL_CurrentDisplay.display_modes[it].w==mode->w) &&
   1.552 +             (SDL_CurrentDisplay.display_modes[it].h==mode->h) &&
   1.553 +             (SDL_CurrentDisplay.display_modes[it].format==mode->format))
   1.554 +         {
   1.555 +            /* Find the lowest refresh rate available */
   1.556 +            if (tempmode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate)
   1.557 +            {
   1.558 +               tempmode=SDL_CurrentDisplay.display_modes[it];
   1.559 +            }
   1.560 +         }
   1.561 +      }
   1.562 +      if (tempmode.refresh_rate!=0x0000FFFF)
   1.563 +      {
   1.564 +         refresh_rate=tempmode.refresh_rate;
   1.565 +      }
   1.566 +      else
   1.567 +      {
   1.568 +         /* Let video driver decide what to do with this */
   1.569 +         refresh_rate=0;
   1.570 +      }
   1.571 +   }
   1.572 +
   1.573 +   /* Check if SDL GF driver needs to check custom refresh rate */
   1.574 +   if (didata->custom_refresh!=0)
   1.575 +   {
   1.576 +      SDL_DisplayMode tempmode;
   1.577 +
   1.578 +      /* Clear display mode structure */
   1.579 +      SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
   1.580 +      tempmode.refresh_rate=0x0000FFFF;
   1.581 +
   1.582 +      /* Check if window width and height matches one of our modes */
   1.583 +      for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++)
   1.584 +      {
   1.585 +         if ((SDL_CurrentDisplay.display_modes[it].w==mode->w) &&
   1.586 +             (SDL_CurrentDisplay.display_modes[it].h==mode->h) &&
   1.587 +             (SDL_CurrentDisplay.display_modes[it].format==mode->format))
   1.588 +         {
   1.589 +            /* Find the lowest refresh rate available */
   1.590 +            if (tempmode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate)
   1.591 +            {
   1.592 +               tempmode=SDL_CurrentDisplay.display_modes[it];
   1.593 +            }
   1.594 +
   1.595 +            /* Check if requested refresh rate found */
   1.596 +            if (refresh_rate==SDL_CurrentDisplay.display_modes[it].refresh_rate)
   1.597 +            {
   1.598 +               tempmode=SDL_CurrentDisplay.display_modes[it];
   1.599 +               break;
   1.600 +            }
   1.601 +         }
   1.602 +      }
   1.603 +      if (tempmode.refresh_rate!=0x0000FFFF)
   1.604 +      {
   1.605 +         refresh_rate=tempmode.refresh_rate;
   1.606 +      }
   1.607 +      else
   1.608 +      {
   1.609 +         /* Let video driver decide what to do with this */
   1.610 +         refresh_rate=0;
   1.611 +      }
   1.612 +   }
   1.613 +
   1.614 +   /* Find photon's video mode number */
   1.615 +   for (it=0; it<modes.num_modes; it++)
   1.616 +   {
   1.617 +      uint32_t jt;
   1.618 +      uint32_t foundrefresh;
   1.619 +
   1.620 +      /* Get current video mode details */
   1.621 +      status=PgGetVideoModeInfo(modes.modes[it], &modeinfo);
   1.622 +      if (status!=0)
   1.623 +      {
   1.624 +         /* Maybe something wrong with this particular mode, skip it */
   1.625 +         continue;
   1.626 +      }
   1.627 +      if ((modeinfo.width==mode->w) && (modeinfo.height==mode->h) &&
   1.628 +          (modeinfo.type==photon_sdl_to_image_pixelformat(mode->format)))
   1.629 +      {
   1.630 +         /* Mode is found, find requested refresh rate, this case is for */
   1.631 +         /* video drivers, which provide non-generic video modes.        */
   1.632 +         jt=0;
   1.633 +         foundrefresh=0;
   1.634 +         do {
   1.635 +            if (modeinfo.refresh_rates[jt]!=0)
   1.636 +            {
   1.637 +               if (modeinfo.refresh_rates[jt]==refresh_rate)
   1.638 +               {
   1.639 +                  foundrefresh=1;
   1.640 +                  break;
   1.641 +               }
   1.642 +               jt++;
   1.643 +            }
   1.644 +            else
   1.645 +            {
   1.646 +               break;
   1.647 +            }
   1.648 +         } while(1);
   1.649 +         if (foundrefresh!=0)
   1.650 +         {
   1.651 +            break;
   1.652 +         }
   1.653 +      }
   1.654 +   }
   1.655 +
   1.656 +   /* Check if video mode has not been found */
   1.657 +   if (it==modes.num_modes)
   1.658 +   {
   1.659 +      SDL_SetError("Photon: Can't find appropriate video mode");
   1.660 +      return -1;
   1.661 +   }
   1.662 +
   1.663 +   /* Fill mode settings */
   1.664 +   modesettings.flags=0x00000000;
   1.665 +   modesettings.mode=modes.modes[it];
   1.666 +   modesettings.refresh=refresh_rate;
   1.667 +
   1.668 +   /* Finally set new video mode */
   1.669 +   status=PgSetVideoMode(&modesettings);
   1.670 +   if (status!=0)
   1.671 +   {
   1.672 +      SDL_SetError("Photon: Can't set new video mode");
   1.673 +      return -1;
   1.674 +   }
   1.675 +
   1.676 +   /* Store new video mode parameters */
   1.677 +   didata->current_mode=*mode;
   1.678 +   didata->current_mode.refresh_rate=refresh_rate;
   1.679  
   1.680     return 0;
   1.681  }
   1.682 @@ -192,8 +758,15 @@
   1.683  
   1.684  int photon_createwindow(_THIS, SDL_Window* window)
   1.685  {
   1.686 +   SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
   1.687     SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
   1.688     SDL_WindowData*  wdata;
   1.689 +   PhDim_t          winsize;
   1.690 +   PhPoint_t        winpos;
   1.691 +   PtArg_t          winargs[32];
   1.692 +   uint32_t         winargc=0;
   1.693 +   int32_t          status;
   1.694 +   PhRegion_t       wregion;
   1.695  
   1.696     /* Allocate window internal data */
   1.697     wdata=(SDL_WindowData*)SDL_calloc(1, sizeof(SDL_WindowData));
   1.698 @@ -206,75 +779,490 @@
   1.699     /* Setup driver data for this window */
   1.700     window->driverdata=wdata;
   1.701  
   1.702 +   /* Set initial window title */
   1.703 +   if (window->title!=NULL)
   1.704 +   {
   1.705 +      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, window->title, 0);
   1.706 +   }
   1.707 +   else
   1.708 +   {
   1.709 +      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, "", 0);
   1.710 +   }
   1.711 +
   1.712 +   /* TODO: handle SDL_WINDOW_INPUT_GRABBED */
   1.713 +
   1.714 +   /* Disable default window filling on redraw */
   1.715 +   PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL);
   1.716 +
   1.717 +   /* Set default maximum and minimum window sizes */
   1.718 +   winsize.w=0;
   1.719 +   winsize.h=0;
   1.720 +   PtSetArg(&winargs[winargc++], Pt_ARG_MAX_HEIGHT, 0, 0);
   1.721 +   PtSetArg(&winargs[winargc++], Pt_ARG_MAX_WIDTH, 0, 0);
   1.722 +   PtSetArg(&winargs[winargc++], Pt_ARG_MIN_HEIGHT, 0, 0);
   1.723 +   PtSetArg(&winargs[winargc++], Pt_ARG_MIN_WIDTH, 0, 0);
   1.724 +   PtSetArg(&winargs[winargc++], Pt_ARG_MAXIMUM_DIM, &winsize, 0);
   1.725 +   PtSetArg(&winargs[winargc++], Pt_ARG_MINIMUM_DIM, &winsize, 0);
   1.726 +
   1.727 +   /* Reset default managed events to disable */
   1.728 +   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
   1.729 +            Ph_WM_APP_DEF_MANAGED);
   1.730 +   /* Set which events we will not handle, let WM to handle them */
   1.731 +   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
   1.732 +            Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT  |
   1.733 +            Ph_WM_FOCUS    | Ph_WM_HELP    | Ph_WM_HIDE     | Ph_WM_MAX     |
   1.734 +            Ph_WM_MENU     | Ph_WM_MOVE    | Ph_WM_RESIZE   | Ph_WM_RESTORE |
   1.735 +            Ph_WM_TASKBAR  | Ph_WM_TOBACK);
   1.736 +
   1.737 +   /* Reset default notify events to disable */
   1.738 +   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE,
   1.739 +            Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP);
   1.740 +   /* Set which events we will handle */
   1.741 +   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
   1.742 +            Ph_WM_CLOSE | Ph_WM_COLLAPSE | Ph_WM_FOCUS   | Ph_WM_MAX  |
   1.743 +            Ph_WM_MOVE  | Ph_WM_RESIZE   | Ph_WM_RESTORE | Ph_WM_HIDE);
   1.744 +
   1.745 +   /* Borderless window can't be resizeable */
   1.746 +   if ((window->flags & SDL_WINDOW_BORDERLESS)==SDL_WINDOW_BORDERLESS)
   1.747 +   {
   1.748 +      window->flags&=~(SDL_WINDOW_RESIZABLE);
   1.749 +   }
   1.750 +
   1.751 +   /* Reset all default decorations */
   1.752 +   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_APP_DEF_RENDER);
   1.753 +
   1.754 +   /* Fullscreen window has its own decorations */
   1.755 +   if ((window->flags & SDL_WINDOW_FULLSCREEN)==SDL_WINDOW_FULLSCREEN)
   1.756 +   {
   1.757 +      window->flags|=SDL_WINDOW_BORDERLESS;
   1.758 +      window->flags&=~(SDL_WINDOW_RESIZABLE);
   1.759 +      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
   1.760 +               Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_TITLE);
   1.761 +   }
   1.762 +   else
   1.763 +   {
   1.764 +      uint32_t decorations=Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN |
   1.765 +                           Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE;
   1.766 +
   1.767 +      if ((window->flags & SDL_WINDOW_RESIZABLE)==SDL_WINDOW_RESIZABLE)
   1.768 +      {
   1.769 +         decorations|=Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX;
   1.770 +      }
   1.771 +      if ((window->flags & SDL_WINDOW_BORDERLESS)!=SDL_WINDOW_BORDERLESS)
   1.772 +      {
   1.773 +         decorations|=Ph_WM_RENDER_BORDER;
   1.774 +      }
   1.775 +      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, decorations);
   1.776 +   }
   1.777 +
   1.778 +   /* Set initial window state */
   1.779 +   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFOCUS);
   1.780 +   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY);
   1.781 +
   1.782 +   /* Set window dimensions */
   1.783 +   winsize.w=window->w;
   1.784 +   winsize.h=window->h;
   1.785 +   PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0);
   1.786 +
   1.787 +   /* Check if upper level requests WM to position window */
   1.788 +   if ((window->x==SDL_WINDOWPOS_UNDEFINED) && (window->y==SDL_WINDOWPOS_UNDEFINED))
   1.789 +   {
   1.790 +      /* Do not set widget position, let WM to set it */
   1.791 +   }
   1.792 +   else
   1.793 +   {
   1.794 +      if (window->x==SDL_WINDOWPOS_UNDEFINED)
   1.795 +      {
   1.796 +         window->x=0;
   1.797 +      }
   1.798 +      if (window->y==SDL_WINDOWPOS_UNDEFINED)
   1.799 +      {
   1.800 +         window->y=0;
   1.801 +      }
   1.802 +      if (window->x==SDL_WINDOWPOS_CENTERED)
   1.803 +      {
   1.804 +         window->x=(didata->current_mode.w-window->w)/2;
   1.805 +      }
   1.806 +      if (window->y==SDL_WINDOWPOS_CENTERED)
   1.807 +      {
   1.808 +         window->y=(didata->current_mode.h-window->h)/2;
   1.809 +      }
   1.810 +
   1.811 +      /* Now set window position */
   1.812 +      winpos.x=window->x;
   1.813 +      winpos.y=window->y;
   1.814 +      PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0);
   1.815 +   }
   1.816 +
   1.817 +   /* Add SDL window id as user data */
   1.818 +   PtSetArg(&winargs[winargc++], Pt_ARG_POINTER, (void*)window->id, 0);
   1.819 +
   1.820     /* Check if window must support OpenGL ES rendering */
   1.821     if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL)
   1.822     {
   1.823 -      /* Mark this window as OpenGL ES compatible */
   1.824 -      wdata->uses_gles=SDL_TRUE;
   1.825 +      #if defined(SDL_VIDEO_OPENGL_ES)
   1.826 +         EGLBoolean initstatus;
   1.827 +
   1.828 +         /* Check if GF was initialized correctly */
   1.829 +         if (phdata->gfinitialized==SDL_FALSE)
   1.830 +         {
   1.831 +            SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
   1.832 +            return -1;
   1.833 +         }
   1.834 +
   1.835 +         /* Mark this window as OpenGL ES compatible */
   1.836 +         wdata->uses_gles=SDL_TRUE;
   1.837 +
   1.838 +         /* Create connection to OpenGL ES */
   1.839 +         if (phdata->egldisplay==EGL_NO_DISPLAY)
   1.840 +         {
   1.841 +            phdata->egldisplay=eglGetDisplay(phdata->gfdev);
   1.842 +            if (phdata->egldisplay==EGL_NO_DISPLAY)
   1.843 +            {
   1.844 +               SDL_SetError("Photon: Can't get connection to OpenGL ES");
   1.845 +               return -1;
   1.846 +            }
   1.847 +
   1.848 +            /* Initialize OpenGL ES library, ignore EGL version */
   1.849 +            initstatus=eglInitialize(phdata->egldisplay, NULL, NULL);
   1.850 +            if (initstatus!=EGL_TRUE)
   1.851 +            {
   1.852 +               SDL_SetError("Photon: Can't init OpenGL ES library");
   1.853 +               return -1;
   1.854 +            }
   1.855 +         }
   1.856 +
   1.857 +         /* Increment GL ES reference count usage */
   1.858 +         phdata->egl_refcount++;
   1.859 +      #else
   1.860 +         SDL_SetError("Photon: OpenGL ES support is not compiled in");
   1.861 +         return -1;
   1.862 +      #endif /* SDL_VIDEO_OPENGL_ES */
   1.863 +   }
   1.864 +
   1.865 +   /* Finally create the window */
   1.866 +   wdata->window=PtCreateWidget(PtWindow, Pt_NO_PARENT, winargc, winargs);
   1.867 +   if (wdata->window==NULL)
   1.868 +   {
   1.869 +      SDL_SetError("Photon: Can't create window widget");
   1.870 +      SDL_free(wdata);
   1.871 +      return -1;
   1.872     }
   1.873  
   1.874 +   /* Show widget */
   1.875 +   status=PtRealizeWidget(wdata->window);
   1.876 +   if (status!=0)
   1.877 +   {
   1.878 +      SDL_SetError("Photon: Can't realize window widget");
   1.879 +      PtDestroyWidget(wdata->window);
   1.880 +      SDL_free(wdata);
   1.881 +      return;
   1.882 +   }
   1.883 +
   1.884 +   /* Just created SDL window always gets focus */
   1.885 +   window->flags|=SDL_WINDOW_INPUT_FOCUS;
   1.886 +
   1.887 +   /* Create window-specific cursor after creation */
   1.888 +   if (didata->cursor_visible==SDL_TRUE)
   1.889 +   {
   1.890 +      /* Setup cursor type. shape and default color */
   1.891 +      PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR, 0);
   1.892 +      PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
   1.893 +      PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, didata->cursor, didata->cursor->hdr.len+sizeof(PhRegionDataHdr_t));
   1.894 +   }
   1.895 +   else
   1.896 +   {
   1.897 +      PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
   1.898 +   }
   1.899 +
   1.900 +   /* Set window region sensible to mouse motion events */
   1.901 +   status=PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
   1.902 +   if (status!=0)
   1.903 +   {
   1.904 +      SDL_SetError("Photon: Can't set region sensivity to mouse motion events");
   1.905 +      PtDestroyWidget(wdata->window);
   1.906 +      SDL_free(wdata);
   1.907 +      return -1;
   1.908 +   }
   1.909 +   wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
   1.910 +   status=PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
   1.911 +   if (status<0)
   1.912 +   {
   1.913 +      SDL_SetError("Photon: Can't change region sensivity");
   1.914 +      PtDestroyWidget(wdata->window);
   1.915 +      SDL_free(wdata);
   1.916 +      return -1;
   1.917 +   }
   1.918 +
   1.919 +   /* Flush all widget operations again */
   1.920 +   PtFlush();
   1.921 +
   1.922 +   /* By default last created window got a input focus */
   1.923 +   SDL_SetKeyboardFocus(0, window->id);
   1.924 +
   1.925     /* Window has been successfully created */
   1.926     return 0;
   1.927  }
   1.928  
   1.929  int photon_createwindowfrom(_THIS, SDL_Window* window, const void* data)
   1.930  {
   1.931 +   /* TODO: it is possible */
   1.932 +
   1.933     /* Failed to create window from another window */
   1.934     return -1;
   1.935  }
   1.936  
   1.937  void photon_setwindowtitle(_THIS, SDL_Window* window)
   1.938  {
   1.939 +   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
   1.940 +   int32_t status;
   1.941 +
   1.942 +   /* Set window title */
   1.943 +   if (window->title!=NULL)
   1.944 +   {
   1.945 +      status=PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, window->title, 0);
   1.946 +   }
   1.947 +   else
   1.948 +   {
   1.949 +      status=PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, "", 0);
   1.950 +   }
   1.951 +
   1.952 +   if (status!=0)
   1.953 +   {
   1.954 +      SDL_SetError("Photon: Can't set window title");
   1.955 +   }
   1.956 +
   1.957 +   /* Flush all widget operations */
   1.958 +   PtFlush();
   1.959  }
   1.960  
   1.961  void photon_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon)
   1.962  {
   1.963 +   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
   1.964 +   int32_t   status;
   1.965 +
   1.966 +   /* TODO: Use iconify ? */
   1.967 +
   1.968 +   /* Flush all widget operations */
   1.969 +   PtFlush();
   1.970  }
   1.971  
   1.972  void photon_setwindowposition(_THIS, SDL_Window* window)
   1.973  {
   1.974 +   SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
   1.975 +   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
   1.976 +   PhPoint_t winpos;
   1.977 +   int32_t   status;
   1.978 +
   1.979 +   /* Check if upper level requests WM to position window */
   1.980 +   if ((window->x==SDL_WINDOWPOS_UNDEFINED) && (window->y==SDL_WINDOWPOS_UNDEFINED))
   1.981 +   {
   1.982 +      /* Do not set widget position, let WM to set it */
   1.983 +   }
   1.984 +   else
   1.985 +   {
   1.986 +      if (window->x==SDL_WINDOWPOS_UNDEFINED)
   1.987 +      {
   1.988 +         window->x=0;
   1.989 +      }
   1.990 +      if (window->y==SDL_WINDOWPOS_UNDEFINED)
   1.991 +      {
   1.992 +         window->y=0;
   1.993 +      }
   1.994 +      if (window->x==SDL_WINDOWPOS_CENTERED)
   1.995 +      {
   1.996 +         window->x=(didata->current_mode.w-window->w)/2;
   1.997 +      }
   1.998 +      if (window->y==SDL_WINDOWPOS_CENTERED)
   1.999 +      {
  1.1000 +         window->y=(didata->current_mode.h-window->h)/2;
  1.1001 +      }
  1.1002 +
  1.1003 +      /* Now set window position */
  1.1004 +      winpos.x=window->x;
  1.1005 +      winpos.y=window->y;
  1.1006 +      status=PtSetResource(wdata->window, Pt_ARG_POS, &winpos, 0);
  1.1007 +      if (status!=0)
  1.1008 +      {
  1.1009 +         SDL_SetError("Photon: Can't set window position");
  1.1010 +      }
  1.1011 +   }
  1.1012 +
  1.1013 +   /* Flush all widget operations */
  1.1014 +   PtFlush();
  1.1015  }
  1.1016  
  1.1017  void photon_setwindowsize(_THIS, SDL_Window* window)
  1.1018  {
  1.1019 +   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
  1.1020 +   PhDim_t winsize;
  1.1021 +   int32_t status;
  1.1022 +
  1.1023 +   winsize.w=window->w;
  1.1024 +   winsize.h=window->h;
  1.1025 +
  1.1026 +   status=PtSetResource(wdata->window, Pt_ARG_DIM, &winsize, 0);
  1.1027 +   if (status!=0)
  1.1028 +   {
  1.1029 +      SDL_SetError("Photon: Can't set window size");
  1.1030 +   }
  1.1031 +
  1.1032 +   /* Flush all widget operations */
  1.1033 +   PtFlush();
  1.1034  }
  1.1035  
  1.1036  void photon_showwindow(_THIS, SDL_Window* window)
  1.1037  {
  1.1038 +   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
  1.1039 +   int32_t status;
  1.1040 +
  1.1041 +   /* Bring focus to window and put it in front of others */
  1.1042 +   PtWindowToFront(wdata->window);
  1.1043 +
  1.1044 +   /* Flush all widget operations */
  1.1045 +   PtFlush();
  1.1046  }
  1.1047  
  1.1048  void photon_hidewindow(_THIS, SDL_Window* window)
  1.1049  {
  1.1050 +   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
  1.1051 +   PhWindowEvent_t winevent;
  1.1052 +   int32_t status;
  1.1053 +
  1.1054 +   SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
  1.1055 +   winevent.event_f=Ph_WM_HIDE;
  1.1056 +   winevent.rid=PtWidgetRid(wdata->window);
  1.1057 +   winevent.event_state=Ph_WM_EVSTATE_HIDE;
  1.1058 +
  1.1059 +   status=PtForwardWindowEvent(&winevent);
  1.1060 +   if (status!=0)
  1.1061 +   {
  1.1062 +      SDL_SetError("Photon: Can't hide window");
  1.1063 +   }
  1.1064 +
  1.1065 +   /* Flush all widget operations */
  1.1066 +   PtFlush();
  1.1067  }
  1.1068  
  1.1069  void photon_raisewindow(_THIS, SDL_Window* window)
  1.1070  {
  1.1071 +   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
  1.1072 +   PhWindowEvent_t winevent;
  1.1073 +   int32_t status;
  1.1074 +
  1.1075 +   SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
  1.1076 +   winevent.event_f=Ph_WM_HIDE;
  1.1077 +   winevent.rid=PtWidgetRid(wdata->window);
  1.1078 +   winevent.event_state=Ph_WM_EVSTATE_UNHIDE;
  1.1079 +
  1.1080 +   status=PtForwardWindowEvent(&winevent);
  1.1081 +   if (status!=0)
  1.1082 +   {
  1.1083 +      SDL_SetError("Photon: Can't hide window");
  1.1084 +   }
  1.1085 +
  1.1086 +   /* Flush all widget operations */
  1.1087 +   PtFlush();
  1.1088  }
  1.1089  
  1.1090  void photon_maximizewindow(_THIS, SDL_Window* window)
  1.1091  {
  1.1092 +   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
  1.1093 +   PhWindowEvent_t winevent;
  1.1094 +   int32_t status;
  1.1095 +
  1.1096 +   /* Flush all widget operations */
  1.1097 +   PtFlush();
  1.1098  }
  1.1099  
  1.1100  void photon_minimizewindow(_THIS, SDL_Window* window)
  1.1101  {
  1.1102 +   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
  1.1103 +   PhWindowEvent_t winevent;
  1.1104 +   int32_t status;
  1.1105 +
  1.1106 +   SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
  1.1107 +   winevent.event_f=Ph_WM_HIDE;
  1.1108 +   winevent.rid=PtWidgetRid(wdata->window);
  1.1109 +   winevent.event_state=Ph_WM_EVSTATE_HIDE;
  1.1110 +
  1.1111 +   status=PtForwardWindowEvent(&winevent);
  1.1112 +   if (status!=0)
  1.1113 +   {
  1.1114 +      SDL_SetError("Photon: Can't hide window");
  1.1115 +   }
  1.1116 +
  1.1117 +   /* Flush all widget operations */
  1.1118 +   PtFlush();
  1.1119  }
  1.1120  
  1.1121  void photon_restorewindow(_THIS, SDL_Window* window)
  1.1122  {
  1.1123 +   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
  1.1124 +   PhWindowEvent_t winevent;
  1.1125 +   int32_t status;
  1.1126 +
  1.1127 +   /* Flush all widget operations */
  1.1128 +   PtFlush();
  1.1129  }
  1.1130  
  1.1131  void photon_setwindowgrab(_THIS, SDL_Window* window)
  1.1132  {
  1.1133 +   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
  1.1134 +   PhWindowEvent_t winevent;
  1.1135 +   int32_t status;
  1.1136 +
  1.1137 +   /* Flush all widget operations */
  1.1138 +   PtFlush();
  1.1139  }
  1.1140  
  1.1141  void photon_destroywindow(_THIS, SDL_Window* window)
  1.1142  {
  1.1143 +   SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
  1.1144     SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
  1.1145     SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
  1.1146 +   int32_t status;
  1.1147  
  1.1148     if (wdata!=NULL)
  1.1149     {
  1.1150 +      status=PtDestroyWidget(wdata->window);
  1.1151 +      if (status!=0)
  1.1152 +      {
  1.1153 +         SDL_SetError("Photon: Can't destroy window widget");
  1.1154 +      }
  1.1155 +      wdata->window=NULL;
  1.1156 +
  1.1157 +      #if defined(SDL_VIDEO_OPENGL_ES)
  1.1158 +         if (phdata->gfinitialized==SDL_TRUE)
  1.1159 +         {
  1.1160 +            /* Destroy OpenGL ES surface if it was created */
  1.1161 +            if (wdata->gles_surface!=EGL_NO_SURFACE)
  1.1162 +            {
  1.1163 +               eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
  1.1164 +            }
  1.1165 +
  1.1166 +            /* Free OpenGL ES target surface */
  1.1167 +            if (wdata->gfsurface!=NULL)
  1.1168 +            {
  1.1169 +               gf_surface_free(wdata->gfsurface);
  1.1170 +            }
  1.1171 +
  1.1172 +            phdata->egl_refcount--;
  1.1173 +            if (phdata->egl_refcount==0)
  1.1174 +            {
  1.1175 +               /* Terminate connection to OpenGL ES */
  1.1176 +               if (phdata->egldisplay!=EGL_NO_DISPLAY)
  1.1177 +               {
  1.1178 +                  eglTerminate(phdata->egldisplay);
  1.1179 +                  phdata->egldisplay=EGL_NO_DISPLAY;
  1.1180 +               }
  1.1181 +            }
  1.1182 +         }
  1.1183 +      #endif /* SDL_VIDEO_OPENGL_ES */
  1.1184     }
  1.1185 +
  1.1186 +   /* Flush all widget operations */
  1.1187 +   PtFlush();
  1.1188  }
  1.1189  
  1.1190  /*****************************************************************************/
  1.1191 @@ -301,50 +1289,691 @@
  1.1192  /*****************************************************************************/
  1.1193  int photon_gl_loadlibrary(_THIS, const char* path)
  1.1194  {
  1.1195 -   /* Failed to load new GL library */
  1.1196 -   return -1;
  1.1197 +   #if defined(SDL_VIDEO_OPENGL_ES)
  1.1198 +      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
  1.1199 +
  1.1200 +      if (phdata->gfinitialized!=SDL_TRUE)
  1.1201 +      {
  1.1202 +         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
  1.1203 +         return NULL;
  1.1204 +      }
  1.1205 +
  1.1206 +      /* Check if OpenGL ES library is specified for GF driver */
  1.1207 +      if (path==NULL)
  1.1208 +      {
  1.1209 +         path=SDL_getenv("SDL_OPENGL_LIBRARY");
  1.1210 +         if (path==NULL)
  1.1211 +         {
  1.1212 +            path=SDL_getenv("SDL_OPENGLES_LIBRARY");
  1.1213 +         }
  1.1214 +      }
  1.1215 +
  1.1216 +      /* Check if default library loading requested */
  1.1217 +      if (path==NULL)
  1.1218 +      {
  1.1219 +         /* Already linked with GF library which provides egl* subset of  */
  1.1220 +         /* functions, use Common profile of OpenGL ES library by default */
  1.1221 +         path="/usr/lib/libGLES_CM.so.1";
  1.1222 +      }
  1.1223 +
  1.1224 +      /* Load dynamic library */
  1.1225 +      _this->gl_config.dll_handle=SDL_LoadObject(path);
  1.1226 +      if (!_this->gl_config.dll_handle)
  1.1227 +      {
  1.1228 +         /* Failed to load new GL ES library */
  1.1229 +         SDL_SetError("Photon: Failed to locate OpenGL ES library");
  1.1230 +         return -1;
  1.1231 +      }
  1.1232 +
  1.1233 +      /* Store OpenGL ES library path and name */
  1.1234 +      SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path));
  1.1235 +
  1.1236 +      /* New OpenGL ES library is loaded */
  1.1237 +      return 0;
  1.1238 +   #else
  1.1239 +      SDL_SetError("Photon: OpenGL ES support is not compiled in");
  1.1240 +      return -1;
  1.1241 +   #endif /* SDL_VIDEO_OPENGL_ES */
  1.1242  }
  1.1243  
  1.1244  void* photon_gl_getprocaddres(_THIS, const char* proc)
  1.1245  {
  1.1246 -   /* Failed to get GL function address pointer */
  1.1247 -   return NULL;
  1.1248 +   #if defined(SDL_VIDEO_OPENGL_ES)
  1.1249 +      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
  1.1250 +      void* function_address;
  1.1251 +
  1.1252 +      if (phdata->gfinitialized!=SDL_TRUE)
  1.1253 +      {
  1.1254 +         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
  1.1255 +         return NULL;
  1.1256 +      }
  1.1257 +
  1.1258 +      /* Try to get function address through the egl interface */
  1.1259 +      function_address=eglGetProcAddress(proc);
  1.1260 +      if (function_address!=NULL)
  1.1261 +      {
  1.1262 +         return function_address;
  1.1263 +      }
  1.1264 +
  1.1265 +      /* Then try to get function in the OpenGL ES library */
  1.1266 +      if (_this->gl_config.dll_handle)
  1.1267 +      {
  1.1268 +         function_address=SDL_LoadFunction(_this->gl_config.dll_handle, proc);
  1.1269 +         if (function_address!=NULL)
  1.1270 +         {
  1.1271 +            return function_address;
  1.1272 +         }
  1.1273 +      }
  1.1274 +
  1.1275 +      /* Add emulated OpenGL ES 1.1 functions */
  1.1276 +      if (SDL_strcmp(proc, "glTexParameteri")==0)
  1.1277 +      {
  1.1278 +         return glTexParameteri;
  1.1279 +      }
  1.1280 +      if (SDL_strcmp(proc, "glTexParameteriv")==0)
  1.1281 +      {
  1.1282 +         return glTexParameteriv;
  1.1283 +      }
  1.1284 +      if (SDL_strcmp(proc, "glColor4ub")==0)
  1.1285 +      {
  1.1286 +         return glColor4ub;
  1.1287 +      }
  1.1288 +
  1.1289 +      /* Failed to get GL ES function address pointer */
  1.1290 +      SDL_SetError("Photon: Cannot locate OpenGL ES function name");
  1.1291 +      return NULL;
  1.1292 +   #else
  1.1293 +      SDL_SetError("Photon: OpenGL ES support is not compiled in");
  1.1294 +      return NULL;
  1.1295 +   #endif /* SDL_VIDEO_OPENGL_ES */
  1.1296  }
  1.1297  
  1.1298  void photon_gl_unloadlibrary(_THIS)
  1.1299  {
  1.1300 +   #if defined(SDL_VIDEO_OPENGL_ES)
  1.1301 +      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
  1.1302 +
  1.1303 +      if (phdata->gfinitialized==SDL_TRUE)
  1.1304 +      {
  1.1305 +         /* Unload OpenGL ES library */
  1.1306 +         if (_this->gl_config.dll_handle)
  1.1307 +         {
  1.1308 +            SDL_UnloadObject(_this->gl_config.dll_handle);
  1.1309 +            _this->gl_config.dll_handle=NULL;
  1.1310 +         }
  1.1311 +      }
  1.1312 +      else
  1.1313 +      {
  1.1314 +         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
  1.1315 +      }
  1.1316 +   #else
  1.1317 +      SDL_SetError("Photon: OpenGL ES support is not compiled in");
  1.1318 +      return;
  1.1319 +   #endif /* SDL_VIDEO_OPENGL_ES */
  1.1320  }
  1.1321  
  1.1322  SDL_GLContext photon_gl_createcontext(_THIS, SDL_Window* window)
  1.1323  {
  1.1324 -   /* Failed to create GL context */
  1.1325 -   return NULL;
  1.1326 +   #if defined(SDL_VIDEO_OPENGL_ES)
  1.1327 +      SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
  1.1328 +      SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
  1.1329 +      SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
  1.1330 +      EGLBoolean       status;
  1.1331 +      int32_t          gfstatus;
  1.1332 +      EGLint           configs;
  1.1333 +      uint32_t         attr_pos;
  1.1334 +      EGLint           attr_value;
  1.1335 +      EGLint           cit;
  1.1336 +
  1.1337 +      /* Check if GF was initialized */
  1.1338 +      if (phdata->gfinitialized!=SDL_TRUE)
  1.1339 +      {
  1.1340 +         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
  1.1341 +         return NULL;
  1.1342 +      }
  1.1343 +
  1.1344 +      /* Prepare attributes list to pass them to OpenGL ES */
  1.1345 +      attr_pos=0;
  1.1346 +      wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID;
  1.1347 +      wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
  1.1348 +      wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE;
  1.1349 +      wdata->gles_attributes[attr_pos++]=_this->gl_config.red_size;
  1.1350 +      wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE;
  1.1351 +      wdata->gles_attributes[attr_pos++]=_this->gl_config.green_size;
  1.1352 +      wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE;
  1.1353 +      wdata->gles_attributes[attr_pos++]=_this->gl_config.blue_size;
  1.1354 +      wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE;
  1.1355 +
  1.1356 +      /* Setup alpha size in bits */
  1.1357 +      if (_this->gl_config.alpha_size)
  1.1358 +      {
  1.1359 +         wdata->gles_attributes[attr_pos++]=_this->gl_config.alpha_size;
  1.1360 +      }
  1.1361 +      else
  1.1362 +      {
  1.1363 +         wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1364 +      }
  1.1365 +
  1.1366 +      /* Setup color buffer size */
  1.1367 +      if (_this->gl_config.buffer_size)
  1.1368 +      {
  1.1369 +         wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
  1.1370 +         wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
  1.1371 +      }
  1.1372 +      else
  1.1373 +      {
  1.1374 +         wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
  1.1375 +         wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1376 +      }
  1.1377 +
  1.1378 +      /* Setup depth buffer bits */
  1.1379 +      wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
  1.1380 +      wdata->gles_attributes[attr_pos++]=_this->gl_config.depth_size;
  1.1381 +
  1.1382 +      /* Setup stencil bits */
  1.1383 +      if (_this->gl_config.stencil_size)
  1.1384 +      {
  1.1385 +         wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
  1.1386 +         wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
  1.1387 +      }
  1.1388 +      else
  1.1389 +      {
  1.1390 +         wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
  1.1391 +         wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1392 +      }
  1.1393 +
  1.1394 +      /* Set number of samples in multisampling */
  1.1395 +      if (_this->gl_config.multisamplesamples)
  1.1396 +      {
  1.1397 +         wdata->gles_attributes[attr_pos++]=EGL_SAMPLES;
  1.1398 +         wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplesamples;
  1.1399 +      }
  1.1400 +
  1.1401 +      /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
  1.1402 +      if (_this->gl_config.multisamplebuffers)
  1.1403 +      {
  1.1404 +         wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS;
  1.1405 +         wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplebuffers;
  1.1406 +      }
  1.1407 +
  1.1408 +      /* Finish attributes list */
  1.1409 +      wdata->gles_attributes[attr_pos]=EGL_NONE;
  1.1410 +
  1.1411 +      /* Request first suitable framebuffer configuration */
  1.1412 +      status=eglChooseConfig(phdata->egldisplay, wdata->gles_attributes,
  1.1413 +                             wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
  1.1414 +      if (status!=EGL_TRUE)
  1.1415 +      {
  1.1416 +         SDL_SetError("Photon: Can't find closest configuration for OpenGL ES");
  1.1417 +         return NULL;
  1.1418 +      }
  1.1419 +
  1.1420 +      /* Check if nothing has been found, try "don't care" settings */
  1.1421 +      if (configs==0)
  1.1422 +      {
  1.1423 +         int32_t it;
  1.1424 +         int32_t jt;
  1.1425 +         GLint   depthbits[4]={32, 24, 16, EGL_DONT_CARE};
  1.1426 +
  1.1427 +         for (it=0; it<4; it++)
  1.1428 +         {
  1.1429 +            for (jt=16; jt>=0; jt--)
  1.1430 +            {
  1.1431 +               /* Don't care about color buffer bits, use what exist */
  1.1432 +               /* Replace previous set data with EGL_DONT_CARE       */
  1.1433 +               attr_pos=0;
  1.1434 +               wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID;
  1.1435 +               wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
  1.1436 +               wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE;
  1.1437 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1438 +               wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE;
  1.1439 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1440 +               wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE;
  1.1441 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1442 +               wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE;
  1.1443 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1444 +               wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
  1.1445 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1446 +
  1.1447 +               /* Try to find requested or smallest depth */
  1.1448 +               if (_this->gl_config.depth_size)
  1.1449 +               {
  1.1450 +                  wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
  1.1451 +                  wdata->gles_attributes[attr_pos++]=depthbits[it];
  1.1452 +               }
  1.1453 +               else
  1.1454 +               {
  1.1455 +                  wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
  1.1456 +                  wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1457 +               }
  1.1458 +
  1.1459 +               if (_this->gl_config.stencil_size)
  1.1460 +               {
  1.1461 +                  wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
  1.1462 +                  wdata->gles_attributes[attr_pos++]=jt;
  1.1463 +               }
  1.1464 +               else
  1.1465 +               {
  1.1466 +                  wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
  1.1467 +                  wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1468 +               }
  1.1469 +
  1.1470 +               wdata->gles_attributes[attr_pos++]=EGL_SAMPLES;
  1.1471 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1472 +               wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS;
  1.1473 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  1.1474 +               wdata->gles_attributes[attr_pos]=EGL_NONE;
  1.1475 +
  1.1476 +               /* Request first suitable framebuffer configuration */
  1.1477 +               status=eglChooseConfig(phdata->egldisplay, wdata->gles_attributes,
  1.1478 +                                      wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
  1.1479 +               if (status!=EGL_TRUE)
  1.1480 +               {
  1.1481 +                  SDL_SetError("Photon: Can't find closest configuration for OpenGL ES");
  1.1482 +                  return NULL;
  1.1483 +               }
  1.1484 +               if (configs!=0)
  1.1485 +               {
  1.1486 +                  break;
  1.1487 +               }
  1.1488 +            }
  1.1489 +            if (configs!=0)
  1.1490 +            {
  1.1491 +               break;
  1.1492 +            }
  1.1493 +         }
  1.1494 +
  1.1495 +         /* No available configs */
  1.1496 +         if (configs==0)
  1.1497 +         {
  1.1498 +            SDL_SetError("Photon: Can't find any configuration for OpenGL ES");
  1.1499 +            return NULL;
  1.1500 +         }
  1.1501 +      }
  1.1502 +
  1.1503 +      /* Initialize config index */
  1.1504 +      wdata->gles_config=0;
  1.1505 +
  1.1506 +      /* Now check each configuration to find out the best */
  1.1507 +      for (cit=0; cit<configs; cit++)
  1.1508 +      {
  1.1509 +         uint32_t stencil_found;
  1.1510 +         uint32_t depth_found;
  1.1511 +
  1.1512 +         stencil_found=0;
  1.1513 +         depth_found=0;
  1.1514 +
  1.1515 +         if (_this->gl_config.stencil_size)
  1.1516 +         {
  1.1517 +            status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[cit], EGL_STENCIL_SIZE, &attr_value);
  1.1518 +            if (status==EGL_TRUE)
  1.1519 +            {
  1.1520 +               if (attr_value!=0)
  1.1521 +               {
  1.1522 +                  stencil_found=1;
  1.1523 +               }
  1.1524 +            }
  1.1525 +         }
  1.1526 +         else
  1.1527 +         {
  1.1528 +            stencil_found=1;
  1.1529 +         }
  1.1530 +
  1.1531 +         if (_this->gl_config.depth_size)
  1.1532 +         {
  1.1533 +            status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[cit], EGL_DEPTH_SIZE, &attr_value);
  1.1534 +            if (status==EGL_TRUE)
  1.1535 +            {
  1.1536 +               if (attr_value!=0)
  1.1537 +               {
  1.1538 +                  depth_found=1;
  1.1539 +               }
  1.1540 +            }
  1.1541 +         }
  1.1542 +         else
  1.1543 +         {
  1.1544 +            depth_found=1;
  1.1545 +         }
  1.1546 +
  1.1547 +         /* Exit from loop if found appropriate configuration */
  1.1548 +         if ((depth_found!=0) && (stencil_found!=0))
  1.1549 +         {
  1.1550 +            break;
  1.1551 +         }
  1.1552 +      }
  1.1553 +
  1.1554 +      /* If best could not be found, use first */
  1.1555 +      if (cit==configs)
  1.1556 +      {
  1.1557 +         cit=0;
  1.1558 +      }
  1.1559 +      wdata->gles_config=cit;
  1.1560 +
  1.1561 +      /* Create OpenGL ES context */
  1.1562 +      wdata->gles_context=eglCreateContext(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_NO_CONTEXT, NULL);
  1.1563 +      if (wdata->gles_context==EGL_NO_CONTEXT)
  1.1564 +      {
  1.1565 +         SDL_SetError("Photon: OpenGL ES context creation has been failed");
  1.1566 +         return NULL;
  1.1567 +      }
  1.1568 +
  1.1569 +      /* Check if surface is exist */
  1.1570 +      if (wdata->gfsurface!=NULL)
  1.1571 +      {
  1.1572 +         gf_surface_free(wdata->gfsurface);
  1.1573 +         wdata->gfsurface=NULL;
  1.1574 +      }
  1.1575 +
  1.1576 +      /* Create GF surface */
  1.1577 +      gfstatus=gf_surface_create(&wdata->gfsurface, phdata->gfdev, window->w, window->h,
  1.1578 +               qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format), NULL,
  1.1579 +               GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
  1.1580 +               GF_SURFACE_CREATE_SHAREABLE);
  1.1581 +      if (gfstatus!=GF_ERR_OK)
  1.1582 +      {
  1.1583 +         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
  1.1584 +         wdata->gles_context=EGL_NO_CONTEXT;
  1.1585 +         SDL_SetError("Photon: Can't create GF 3D surface (%08X)", gfstatus);
  1.1586 +         return NULL;
  1.1587 +      }
  1.1588 +
  1.1589 +      /* Create pixmap 3D target surface */
  1.1590 +      wdata->gles_surface=eglCreatePixmapSurface(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], wdata->gfsurface, NULL);
  1.1591 +      if (wdata->gles_surface==EGL_NO_SURFACE)
  1.1592 +      {
  1.1593 +         gf_surface_free(wdata->gfsurface);
  1.1594 +         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
  1.1595 +         wdata->gles_context=EGL_NO_CONTEXT;
  1.1596 +         SDL_SetError("Photon: Can't create EGL pixmap surface");
  1.1597 +         return NULL;
  1.1598 +      }
  1.1599 +
  1.1600 +      /* Make just created context current */
  1.1601 +      status=eglMakeCurrent(phdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context);
  1.1602 +      if (status!=EGL_TRUE)
  1.1603 +      {
  1.1604 +         /* Destroy OpenGL ES surface */
  1.1605 +         eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
  1.1606 +         gf_surface_free(wdata->gfsurface);
  1.1607 +         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
  1.1608 +         wdata->gles_context=EGL_NO_CONTEXT;
  1.1609 +         SDL_SetError("Photon: Can't set OpenGL ES context on creation");
  1.1610 +         return NULL;
  1.1611 +      }
  1.1612 +
  1.1613 +      /* Setup into SDL internals state of OpenGL ES:  */
  1.1614 +      /* it is accelerated or not                      */
  1.1615 +      if ((didata->caps & SDL_PHOTON_ACCELERATED_3D)==SDL_PHOTON_ACCELERATED_3D)
  1.1616 +      {
  1.1617 +         _this->gl_config.accelerated=1;
  1.1618 +      }
  1.1619 +      else
  1.1620 +      {
  1.1621 +         _this->gl_config.accelerated=0;
  1.1622 +      }
  1.1623 +
  1.1624 +      /* Always clear stereo enable, since OpenGL ES do not supports stereo */
  1.1625 +      _this->gl_config.stereo=0;
  1.1626 +
  1.1627 +      /* Get back samples and samplebuffers configurations. Rest framebuffer */
  1.1628 +      /* parameters could be obtained through the OpenGL ES API              */
  1.1629 +      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLES, &attr_value);
  1.1630 +      if (status==EGL_TRUE)
  1.1631 +      {
  1.1632 +         _this->gl_config.multisamplesamples=attr_value;
  1.1633 +      }
  1.1634 +      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLE_BUFFERS, &attr_value);
  1.1635 +      if (status==EGL_TRUE)
  1.1636 +      {
  1.1637 +         _this->gl_config.multisamplebuffers=attr_value;
  1.1638 +      }
  1.1639 +
  1.1640 +      /* Get back stencil and depth buffer sizes */
  1.1641 +      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_DEPTH_SIZE, &attr_value);
  1.1642 +      if (status==EGL_TRUE)
  1.1643 +      {
  1.1644 +         _this->gl_config.depth_size=attr_value;
  1.1645 +      }
  1.1646 +      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_STENCIL_SIZE, &attr_value);
  1.1647 +      if (status==EGL_TRUE)
  1.1648 +      {
  1.1649 +         _this->gl_config.stencil_size=attr_value;
  1.1650 +      }
  1.1651 +
  1.1652 +      /* Under Photon OpenGL ES output can't be double buffered */
  1.1653 +      _this->gl_config.double_buffer=0;
  1.1654 +
  1.1655 +      /* Check if current device is not the same as target */
  1.1656 +      if (phdata->current_device_id!=didata->device_id)
  1.1657 +      {
  1.1658 +         /* Set target device as default for Pd and Pg functions */
  1.1659 +         status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
  1.1660 +         if (status!=0)
  1.1661 +         {
  1.1662 +            /* Destroy OpenGL ES surface */
  1.1663 +            eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
  1.1664 +            gf_surface_free(wdata->gfsurface);
  1.1665 +            eglDestroyContext(phdata->egldisplay, wdata->gles_context);
  1.1666 +            wdata->gles_context=EGL_NO_CONTEXT;
  1.1667 +            SDL_SetError("Photon: Can't set default target device\n");
  1.1668 +            return NULL;
  1.1669 +         }
  1.1670 +         phdata->current_device_id=didata->device_id;
  1.1671 +      }
  1.1672 +
  1.1673 +      wdata->phsurface=PdCreateOffscreenContextGF(wdata->gfsurface);
  1.1674 +      if (wdata->phsurface==NULL)
  1.1675 +      {
  1.1676 +         /* Destroy OpenGL ES surface */
  1.1677 +         eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
  1.1678 +         gf_surface_free(wdata->gfsurface);
  1.1679 +         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
  1.1680 +         wdata->gles_context=EGL_NO_CONTEXT;
  1.1681 +         SDL_SetError("Photon: Can't bind GF surface to Photon\n");
  1.1682 +         return NULL;
  1.1683 +      }
  1.1684 +
  1.1685 +      /* GL ES context was successfully created */
  1.1686 +      return wdata->gles_context;
  1.1687 +   #else
  1.1688 +      SDL_SetError("Photon: OpenGL ES support is not compiled in");
  1.1689 +      return NULL;
  1.1690 +   #endif /* SDL_VIDEO_OPENGL_ES */
  1.1691  }
  1.1692  
  1.1693  int photon_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context)
  1.1694  {
  1.1695 -   /* Failed to set current GL context */
  1.1696 -   return -1;
  1.1697 +   #if defined(SDL_VIDEO_OPENGL_ES)
  1.1698 +      SDL_VideoData*  phdata=(SDL_VideoData*)_this->driverdata;
  1.1699 +      SDL_WindowData* wdata;
  1.1700 +      EGLBoolean status;
  1.1701 +
  1.1702 +      if (phdata->gfinitialized!=SDL_TRUE)
  1.1703 +      {
  1.1704 +         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
  1.1705 +         return -1;
  1.1706 +      }
  1.1707 +
  1.1708 +      if ((window==NULL) && (context==NULL))
  1.1709 +      {
  1.1710 +         status=eglMakeCurrent(phdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  1.1711 +         if (status!=EGL_TRUE)
  1.1712 +         {
  1.1713 +            /* Failed to set current GL ES context */
  1.1714 +            SDL_SetError("Photon: Can't set OpenGL ES context");
  1.1715 +            return -1;
  1.1716 +         }
  1.1717 +      }
  1.1718 +      else
  1.1719 +      {
  1.1720 +         wdata=(SDL_WindowData*)window->driverdata;
  1.1721 +         if (wdata->gles_surface==EGL_NO_SURFACE)
  1.1722 +         {
  1.1723 +            SDL_SetError("Photon: OpenGL ES surface is not initialized for this window");
  1.1724 +            return -1;
  1.1725 +         }
  1.1726 +         if (wdata->gles_context==EGL_NO_CONTEXT)
  1.1727 +         {
  1.1728 +            SDL_SetError("Photon: OpenGL ES context is not initialized for this window");
  1.1729 +            return -1;
  1.1730 +         }
  1.1731 +         if (wdata->gles_context!=context)
  1.1732 +         {
  1.1733 +            SDL_SetError("Photon: OpenGL ES context is not belong to this window");
  1.1734 +            return -1;
  1.1735 +         }
  1.1736 +         status=eglMakeCurrent(phdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context);
  1.1737 +         if (status!=EGL_TRUE)
  1.1738 +         {
  1.1739 +            /* Failed to set current GL ES context */
  1.1740 +            SDL_SetError("Photon: Can't set OpenGL ES context");
  1.1741 +            return -1;
  1.1742 +         }
  1.1743 +      }
  1.1744 +
  1.1745 +      return 0;
  1.1746 +   #else
  1.1747 +      SDL_SetError("Photon: OpenGL ES support is not compiled in");
  1.1748 +      return -1;
  1.1749 +   #endif /* SDL_VIDEO_OPENGL_ES */
  1.1750  }
  1.1751  
  1.1752  int photon_gl_setswapinterval(_THIS, int interval)
  1.1753  {
  1.1754 -   /* Failed to set swap interval */
  1.1755 -   return -1;
  1.1756 +   #if defined(SDL_VIDEO_OPENGL_ES)
  1.1757 +      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
  1.1758 +      EGLBoolean     status;
  1.1759 +
  1.1760 +      if (phdata->gfinitialized!=SDL_TRUE)
  1.1761 +      {
  1.1762 +         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
  1.1763 +         return -1;
  1.1764 +      }
  1.1765 +
  1.1766 +      /* Check if OpenGL ES connection has been initialized */
  1.1767 +      if (phdata->egldisplay!=EGL_NO_DISPLAY)
  1.1768 +      {
  1.1769 +         /* Set swap OpenGL ES interval */
  1.1770 +         status=eglSwapInterval(phdata->egldisplay, interval);
  1.1771 +         if (status==EGL_TRUE)
  1.1772 +         {
  1.1773 +            /* Return success to upper level */
  1.1774 +            phdata->swapinterval=interval;
  1.1775 +            return 0;
  1.1776 +         }
  1.1777 +      }
  1.1778 +
  1.1779 +      /* Failed to set swap interval */
  1.1780 +      SDL_SetError("Photon: Cannot set swap interval");
  1.1781 +      return -1;
  1.1782 +   #else
  1.1783 +      SDL_SetError("Photon: OpenGL ES support is not compiled in");
  1.1784 +      return -1;
  1.1785 +   #endif /* SDL_VIDEO_OPENGL_ES */
  1.1786  }
  1.1787  
  1.1788  int photon_gl_getswapinterval(_THIS)
  1.1789  {
  1.1790 -   /* Failed to get default swap interval */
  1.1791 -   return -1;
  1.1792 +   #if defined(SDL_VIDEO_OPENGL_ES)
  1.1793 +      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
  1.1794 +
  1.1795 +      if (phdata->gfinitialized!=SDL_TRUE)
  1.1796 +      {
  1.1797 +         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
  1.1798 +         return -1;
  1.1799 +      }
  1.1800 +
  1.1801 +      /* Return default swap interval value */
  1.1802 +      return phdata->swapinterval;
  1.1803 +   #else
  1.1804 +      SDL_SetError("Photon: OpenGL ES support is not compiled in");
  1.1805 +      return -1;
  1.1806 +   #endif /* SDL_VIDEO_OPENGL_ES */
  1.1807  }
  1.1808  
  1.1809  void photon_gl_swapwindow(_THIS, SDL_Window* window)
  1.1810  {
  1.1811 +   #if defined(SDL_VIDEO_OPENGL_ES)
  1.1812 +      SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
  1.1813 +      SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
  1.1814 +      SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
  1.1815 +      PhRect_t*        dst_rect;
  1.1816 +      PhRect_t         src_rect;
  1.1817 +
  1.1818 +      if (phdata->gfinitialized!=SDL_TRUE)
  1.1819 +      {
  1.1820 +         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
  1.1821 +         return;
  1.1822 +      }
  1.1823 +
  1.1824 +      /* Many applications do not uses glFinish(), so we call it for them */
  1.1825 +      glFinish();
  1.1826 +
  1.1827 +      /* Wait until OpenGL ES rendering is completed */
  1.1828 +      eglWaitGL();
  1.1829 +
  1.1830 +      /* Wait for VSYNC manually, if it was enabled */
  1.1831 +      if (phdata->swapinterval!=0)
  1.1832 +      {
  1.1833 +         /* Wait for VSYNC, we use GF function, since Photon requires */
  1.1834 +         /* to enter to the Direct mode to call PgWaitVSync()         */
  1.1835 +         gf_display_wait_vsync(didata->display);
  1.1836 +      }
  1.1837 +
  1.1838 +      /* Set blit area */
  1.1839 +      dst_rect=PtGetCanvas(wdata->window);
  1.1840 +      src_rect.ul.x=0;
  1.1841 +      src_rect.ul.y=0;
  1.1842 +      src_rect.lr.x=window->w-1;
  1.1843 +      src_rect.lr.y=window->h-1;
  1.1844 +
  1.1845 +      /* Blit OpenGL ES pixmap surface directly to window region */
  1.1846 +      PgFFlush(Ph_START_DRAW);
  1.1847 +      PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
  1.1848 +      PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
  1.1849 +      PgContextBlit(wdata->phsurface, &src_rect, NULL, dst_rect);
  1.1850 +      PgFFlush(Ph_DONE_DRAW);
  1.1851 +      PgWaitHWIdle();
  1.1852 +
  1.1853 +      eglSwapBuffers(phdata->egldisplay, wdata->gles_surface);
  1.1854 +   #else
  1.1855 +      SDL_SetError("Photon: OpenGL ES support is not compiled in");
  1.1856 +      return;
  1.1857 +   #endif /* SDL_VIDEO_OPENGL_ES */
  1.1858  }
  1.1859  
  1.1860  void photon_gl_deletecontext(_THIS, SDL_GLContext context)
  1.1861  {
  1.1862 +   #if defined(SDL_VIDEO_OPENGL_ES)
  1.1863 +      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
  1.1864 +      EGLBoolean     status;
  1.1865 +
  1.1866 +      if (phdata->gfinitialized!=SDL_TRUE)
  1.1867 +      {
  1.1868 +         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
  1.1869 +         return;
  1.1870 +      }
  1.1871 +
  1.1872 +      /* Check if OpenGL ES connection has been initialized */
  1.1873 +      if (phdata->egldisplay!=EGL_NO_DISPLAY)
  1.1874 +      {
  1.1875 +         if (context!=EGL_NO_CONTEXT)
  1.1876 +         {
  1.1877 +            status=eglDestroyContext(phdata->egldisplay, context);
  1.1878 +            if (status!=EGL_TRUE)
  1.1879 +            {
  1.1880 +               /* Error during OpenGL ES context destroying */
  1.1881 +               SDL_SetError("Photon: OpenGL ES context destroy error");
  1.1882 +               return;
  1.1883 +            }
  1.1884 +         }
  1.1885 +      }
  1.1886 +
  1.1887 +      return;
  1.1888 +   #else
  1.1889 +      SDL_SetError("Photon: OpenGL ES support is not compiled in");
  1.1890 +      return;
  1.1891 +   #endif /* SDL_VIDEO_OPENGL_ES */
  1.1892  }
  1.1893  
  1.1894  /*****************************************************************************/
  1.1895 @@ -352,6 +1981,543 @@
  1.1896  /*****************************************************************************/
  1.1897  void photon_pumpevents(_THIS)
  1.1898  {
  1.1899 +   uint8_t    eventbuffer[SDL_VIDEO_PHOTON_EVENT_SIZE];
  1.1900 +   PhEvent_t* event=(PhEvent_t*)eventbuffer;
  1.1901 +   int32_t    status;
  1.1902 +   uint32_t   finish=0;
  1.1903 +   uint32_t   it;
  1.1904 +   SDL_Window* window;
  1.1905 +   SDL_WindowData* wdata;
  1.1906 +
  1.1907 +   do {
  1.1908 +      status=PhEventPeek(event, SDL_VIDEO_PHOTON_EVENT_SIZE);
  1.1909 +      switch (status)
  1.1910 +      {
  1.1911 +         case Ph_RESIZE_MSG:
  1.1912 +              {
  1.1913 +                 SDL_SetError("Photon: Event size too much for buffer");
  1.1914 +                 return;
  1.1915 +              }
  1.1916 +              break;
  1.1917 +         case Ph_EVENT_MSG:
  1.1918 +              {
  1.1919 +                 /* Find a window, to which this handle destinated */
  1.1920 +                 status=0;
  1.1921 +                 for (it=0; it<SDL_CurrentDisplay.num_windows; it++)
  1.1922 +                 {
  1.1923 +                    wdata=(SDL_WindowData*)SDL_CurrentDisplay.windows[it].driverdata;
  1.1924 +
  1.1925 +                    /* Find the proper window */
  1.1926 +                    if (wdata->window!=NULL)
  1.1927 +                    {
  1.1928 +                       if (PtWidgetRid(wdata->window)==event->collector.rid)
  1.1929 +                       {
  1.1930 +                          window=(SDL_Window*)&SDL_CurrentDisplay.windows[it];
  1.1931 +                          status=1;
  1.1932 +                          break;
  1.1933 +                       }
  1.1934 +                    }
  1.1935 +                    else
  1.1936 +                    {
  1.1937 +                       continue;
  1.1938 +                    }
  1.1939 +                 }
  1.1940 +                 if (status==0)
  1.1941 +                 {
  1.1942 +                    window=NULL;
  1.1943 +                 }
  1.1944 +
  1.1945 +                 /* Event is ready */
  1.1946 +                 switch(event->type)
  1.1947 +                 {
  1.1948 +                    case Ph_EV_BOUNDARY:
  1.1949 +                         {
  1.1950 +                            switch(event->subtype)
  1.1951 +                            {
  1.1952 +                               case Ph_EV_PTR_ENTER:
  1.1953 +                                    {
  1.1954 +                                       /* Mouse cursor over handled window */
  1.1955 +                                       if (window!=NULL)
  1.1956 +                                       {
  1.1957 +                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_ENTER, 0, 0);
  1.1958 +                                          SDL_SetMouseFocus(0, window->id);
  1.1959 +                                       }
  1.1960 +                                    }
  1.1961 +                                    break;
  1.1962 +                               case Ph_EV_PTR_LEAVE:
  1.1963 +                                    {
  1.1964 +                                       /* Mouse cursor out of handled window */
  1.1965 +                                       if (window!=NULL)
  1.1966 +                                       {
  1.1967 +                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_LEAVE, 0, 0);
  1.1968 +                                       }
  1.1969 +                                    }
  1.1970 +                                    break;
  1.1971 +                            }
  1.1972 +                         }
  1.1973 +                         break;
  1.1974 +                    case Ph_EV_PTR_MOTION_BUTTON:
  1.1975 +                    case Ph_EV_PTR_MOTION_NOBUTTON:
  1.1976 +                         {
  1.1977 +                            PhPointerEvent_t* pevent=NULL;
  1.1978 +                            PhRect_t* prects=NULL;
  1.1979 +
  1.1980 +                            /* Get event data */
  1.1981 +                            pevent=PhGetData(event);
  1.1982 +                            /* Get associated event rectangles */
  1.1983 +                            prects=PhGetRects(event);
  1.1984 +                            if ((pevent!=NULL) && (prects!=NULL))
  1.1985 +                            {
  1.1986 +                               SDL_SendMouseMotion(0, 0, prects->ul.x, prects->ul.y, 0);
  1.1987 +                            }
  1.1988 +                         }
  1.1989 +                         break;
  1.1990 +                    case Ph_EV_BUT_PRESS:
  1.1991 +                         {
  1.1992 +                            /* Button press event */
  1.1993 +                            PhPointerEvent_t* pevent=NULL;
  1.1994 +                            uint32_t sdlbutton=0x00000000;
  1.1995 +
  1.1996 +                            /* Get event data */
  1.1997 +                            pevent=PhGetData(event);
  1.1998 +                            if (pevent!=NULL)
  1.1999 +                            {
  1.2000 +                               for (it=0; it<sizeof(pevent->buttons)*8; it++)
  1.2001 +                               {
  1.2002 +                                  if ((pevent->buttons&(0x0001<<it))==(0x0001<<it))
  1.2003 +                                  {
  1.2004 +                                     switch (it)
  1.2005 +                                     {
  1.2006 +                                        case 0:
  1.2007 +                                             {
  1.2008 +                                                sdlbutton=SDL_BUTTON_RIGHT;
  1.2009 +                                             }
  1.2010 +                                             break;
  1.2011 +                                        case 1:
  1.2012 +                                             {
  1.2013 +                                                sdlbutton=SDL_BUTTON_MIDDLE;
  1.2014 +                                             }
  1.2015 +                                             break;
  1.2016 +                                        case 2:
  1.2017 +                                             {
  1.2018 +                                                sdlbutton=SDL_BUTTON_LEFT;
  1.2019 +                                             }
  1.2020 +                                             break;
  1.2021 +                                        default:
  1.2022 +                                             {
  1.2023 +                                                sdlbutton=it+1;
  1.2024 +                                             }
  1.2025 +                                             break;
  1.2026 +                                     }
  1.2027 +                                     SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton);
  1.2028 +                                  }
  1.2029 +                               }
  1.2030 +                            }
  1.2031 +                         }
  1.2032 +                         break;
  1.2033 +                    case Ph_EV_BUT_RELEASE:
  1.2034 +                         {
  1.2035 +                            /* Button press event */
  1.2036 +                            PhPointerEvent_t* pevent=NULL;
  1.2037 +                            uint32_t sdlbutton=0x00000000;
  1.2038 +
  1.2039 +                            /* Get event data */
  1.2040 +                            pevent=PhGetData(event);
  1.2041 +                            if (pevent!=NULL)
  1.2042 +                            {
  1.2043 +                               for (it=0; it<sizeof(pevent->buttons)*8; it++)
  1.2044 +                               {
  1.2045 +                                  if ((pevent->buttons&(0x0001<<it))==(0x0001<<it))
  1.2046 +                                  {
  1.2047 +                                     switch (it)
  1.2048 +                                     {
  1.2049 +                                        case 0:
  1.2050 +                                             {
  1.2051 +                                                sdlbutton=SDL_BUTTON_RIGHT;
  1.2052 +                                             }
  1.2053 +                                             break;
  1.2054 +                                        case 1:
  1.2055 +                                             {
  1.2056 +                                                sdlbutton=SDL_BUTTON_MIDDLE;
  1.2057 +                                             }
  1.2058 +                                             break;
  1.2059 +                                        case 2:
  1.2060 +                                             {
  1.2061 +                                                sdlbutton=SDL_BUTTON_LEFT;
  1.2062 +                                             }
  1.2063 +                                             break;
  1.2064 +                                        default:
  1.2065 +                                             {
  1.2066 +                                                sdlbutton=it+1;
  1.2067 +                                             }
  1.2068 +                                             break;
  1.2069 +                                     }
  1.2070 +                                  }
  1.2071 +                               }
  1.2072 +                            }
  1.2073 +
  1.2074 +                            switch(event->subtype)
  1.2075 +                            {
  1.2076 +                               case Ph_EV_RELEASE_REAL:
  1.2077 +                                    {
  1.2078 +                                       /* Real release button event */
  1.2079 +                                       SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
  1.2080 +                                    }
  1.2081 +                                    break;
  1.2082 +                               case Ph_EV_RELEASE_PHANTOM:
  1.2083 +                                    {
  1.2084 +                                       /* We will get phantom button release */
  1.2085 +                                       /* event in case if it was unpressed  */
  1.2086 +                                       /* outside of window                  */
  1.2087 +                                       if (window!=NULL)
  1.2088 +                                       {
  1.2089 +                                          if ((window->flags & SDL_WINDOW_MOUSE_FOCUS)!=SDL_WINDOW_MOUSE_FOCUS)
  1.2090 +                                          {
  1.2091 +                                             /* Send phantom button release */
  1.2092 +                                             SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
  1.2093 +                                          }
  1.2094 +                                       }
  1.2095 +                                    }
  1.2096 +                                    break;
  1.2097 +                            }
  1.2098 +                         }
  1.2099 +                         break;
  1.2100 +                    case Ph_EV_EXPOSE:
  1.2101 +                         {
  1.2102 +                            switch(event->subtype)
  1.2103 +                            {
  1.2104 +                               case Ph_NORMAL_EXPOSE:
  1.2105 +                                    {
  1.2106 +                                       PhRect_t* rects=NULL;
  1.2107 +
  1.2108 +                                       /* Get array of rectangles to be updated */
  1.2109 +                                       rects=PhGetRects(event);
  1.2110 +                                       if (rects==NULL)
  1.2111 +                                       {
  1.2112 +                                          break;
  1.2113 +                                       }
  1.2114 +
  1.2115 +                                       /* Cycle through each rectangle */
  1.2116 +                                       for (it=0; it<event->num_rects; it++)
  1.2117 +                                       {
  1.2118 +                                          /* TODO: update the damaged rectangles */
  1.2119 +                                       }
  1.2120 +
  1.2121 +                                       /* Flush all blittings */
  1.2122 +                                       PgFlush();
  1.2123 +                                    }
  1.2124 +                                    break;
  1.2125 +                               case Ph_CAPTURE_EXPOSE:
  1.2126 +                                    {
  1.2127 +                                       /* We need to redraw entire screen */
  1.2128 +                                       PgFFlush(Ph_START_DRAW);
  1.2129 +
  1.2130 +                                       /* TODO: redraw the whole screen */
  1.2131 +
  1.2132 +                                       PgFFlush(Ph_DONE_DRAW);
  1.2133 +                                    }
  1.2134 +                                    break;
  1.2135 +                               case Ph_GRAPHIC_EXPOSE:
  1.2136 +                                    {
  1.2137 +                                       /* TODO: What this event means ? */
  1.2138 +                                    }
  1.2139 +                                    break;
  1.2140 +                            }
  1.2141 +                         }
  1.2142 +                         break;
  1.2143 +                    case Ph_EV_INFO:
  1.2144 +                         {
  1.2145 +                         }
  1.2146 +                         break;
  1.2147 +                    case Ph_EV_KEY:
  1.2148 +                         {
  1.2149 +                            PhKeyEvent_t* keyevent=NULL;
  1.2150 +                            SDL_scancode scancode=SDL_SCANCODE_UNKNOWN;
  1.2151 +                            SDL_bool pressed=SDL_FALSE;
  1.2152 +
  1.2153 +                            keyevent=PhGetData(event);
  1.2154 +                            if (keyevent==NULL)
  1.2155 +                            {
  1.2156 +                               break;
  1.2157 +                            }
  1.2158 +
  1.2159 +                            /* Check if key is repeated */
  1.2160 +                            if ((keyevent->key_flags & Pk_KF_Key_Repeat)==Pk_KF_Key_Repeat)
  1.2161 +                            {
  1.2162 +                               /* Ignore such events */
  1.2163 +                               break;
  1.2164 +                            }
  1.2165 +
  1.2166 +                            /* Check if key has its own scancode */
  1.2167 +                            if ((keyevent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid)
  1.2168 +                            {
  1.2169 +                               if ((keyevent->key_flags & Pk_KF_Key_Down)==Pk_KF_Key_Down)
  1.2170 +                               {
  1.2171 +                                  pressed=SDL_TRUE;
  1.2172 +                               }
  1.2173 +                               else
  1.2174 +                               {
  1.2175 +                                  pressed=SDL_FALSE;
  1.2176 +                               }
  1.2177 +                               scancode=photon_to_sdl_keymap(keyevent->key_scan);
  1.2178 +
  1.2179 +                               /* Add details for the pressed key */
  1.2180 +                               if ((keyevent->key_flags & Pk_KF_Cap_Valid)==Pk_KF_Cap_Valid)
  1.2181 +                               {
  1.2182 +                                  switch(keyevent->key_cap)
  1.2183 +                                  {
  1.2184 +                                     case Pk_Hyper_R: /* Right windows flag key */
  1.2185 +                                          scancode=SDL_SCANCODE_RGUI;
  1.2186 +                                          break;
  1.2187 +                                     case Pk_Control_R: /* Right Ctrl key */
  1.2188 +                                          scancode=SDL_SCANCODE_RCTRL;
  1.2189 +                                          break;
  1.2190 +                                     case Pk_Alt_R: /* Right Alt key */
  1.2191 +                                          scancode=SDL_SCANCODE_RALT;
  1.2192 +                                          break;
  1.2193 +                                     case Pk_Up: /* Up key but with invalid scan */
  1.2194 +                                          if (scancode!=SDL_SCANCODE_UP)
  1.2195 +                                          {
  1.2196 +                                             /* This is a mouse wheel event */
  1.2197 +                                             SDL_SendMouseWheel(0, 0, 1);
  1.2198 +                                             return;
  1.2199 +                                          }
  1.2200 +                                          break;
  1.2201 +                                     case Pk_KP_8: /* Up arrow or 8 on keypad */
  1.2202 +                                          scancode=SDL_SCANCODE_KP_8;
  1.2203 +                                          break;
  1.2204 +                                     case Pk_Down: /* Down key but with invalid scan */
  1.2205 +                                          if (scancode!=SDL_SCANCODE_DOWN)
  1.2206 +                                          {
  1.2207 +                                             /* This is a mouse wheel event */
  1.2208 +                                             SDL_SendMouseWheel(0, 0, -1);
  1.2209 +                                             return;
  1.2210 +                                          }
  1.2211 +                                          break;
  1.2212 +                                     case Pk_KP_2: /* Down arrow or 2 on keypad */
  1.2213 +                                          scancode=SDL_SCANCODE_KP_2;
  1.2214 +                                          break;
  1.2215 +                                     case Pk_Left: /* Left arrow key */
  1.2216 +                                          scancode=SDL_SCANCODE_LEFT;
  1.2217 +                                          break;
  1.2218 +                                     case Pk_KP_4: /* Left arrow or 4 on keypad */
  1.2219 +                                          scancode=SDL_SCANCODE_KP_4;
  1.2220 +                                          break;
  1.2221 +                                     case Pk_Right: /* Right arrow key */
  1.2222 +                                          scancode=SDL_SCANCODE_RIGHT;
  1.2223 +                                          break;
  1.2224 +                                     case Pk_KP_6: /* Right arrow or 6 on keypad */
  1.2225 +                                          scancode=SDL_SCANCODE_KP_6;
  1.2226 +                                          break;
  1.2227 +                                     case Pk_Insert: /* Insert key */
  1.2228 +                                          scancode=SDL_SCANCODE_INSERT;
  1.2229 +                                          break;
  1.2230 +                                     case Pk_KP_0: /* Insert or 0 on keypad */
  1.2231 +                                          scancode=SDL_SCANCODE_KP_0;
  1.2232 +                                          break;
  1.2233 +                                     case Pk_Home: /* Home key */
  1.2234 +                                          scancode=SDL_SCANCODE_HOME;
  1.2235 +                                          break;
  1.2236 +                                     case Pk_KP_7: /* Home or 7 on keypad */
  1.2237 +                                          scancode=SDL_SCANCODE_KP_7;
  1.2238 +                                          break;
  1.2239 +                                     case Pk_Pg_Up: /* PageUp key */
  1.2240 +                                          scancode=SDL_SCANCODE_PAGEUP;
  1.2241 +                                          break;
  1.2242 +                                     case Pk_KP_9: /* PgUp or 9 on keypad */
  1.2243 +                                          scancode=SDL_SCANCODE_KP_9;
  1.2244 +                                          break;
  1.2245 +                                     case Pk_Delete: /* Delete key */
  1.2246 +                                          scancode=SDL_SCANCODE_DELETE;
  1.2247 +                                          break;
  1.2248 +                                     case Pk_KP_Decimal: /* Del or . on keypad */
  1.2249 +                                          scancode=SDL_SCANCODE_KP_PERIOD;
  1.2250 +                                          break;
  1.2251 +                                     case Pk_End: /* End key */
  1.2252 +                                          scancode=SDL_SCANCODE_END;
  1.2253 +                                          break;
  1.2254 +                                     case Pk_KP_1: /* End or 1 on keypad */
  1.2255 +                                          scancode=SDL_SCANCODE_KP_1;
  1.2256 +                                          break;
  1.2257 +                                     case Pk_Pg_Down: /* PageDown key */
  1.2258 +                                          scancode=SDL_SCANCODE_PAGEDOWN;
  1.2259 +                                          break;
  1.2260 +                                     case Pk_KP_3: /* PgDn or 3 on keypad */
  1.2261 +                                          scancode=SDL_SCANCODE_KP_3;
  1.2262 +                                          break;
  1.2263 +                                     case Pk_KP_5: /* 5 on keypad */
  1.2264 +                                          scancode=SDL_SCANCODE_KP_5;
  1.2265 +                                          break;
  1.2266 +                                     case Pk_KP_Enter:
  1.2267 +                                          scancode=SDL_SCANCODE_KP_ENTER;
  1.2268 +                                          break;
  1.2269 +                                     case Pk_KP_Add:
  1.2270 +                                          scancode=SDL_SCANCODE_KP_PLUS;
  1.2271 +                                          break;
  1.2272 +                                     case Pk_KP_Subtract:
  1.2273 +                                          scancode=SDL_SCANCODE_KP_MINUS;
  1.2274 +                                          break;
  1.2275 +                                     case Pk_KP_Multiply:
  1.2276 +                                          scancode=SDL_SCANCODE_KP_MULTIPLY;
  1.2277 +                                          break;
  1.2278 +                                     case Pk_KP_Divide:
  1.2279 +                                          scancode=SDL_SCANCODE_KP_DIVIDE;
  1.2280 +                                          break;
  1.2281 +                                     case Pk_Pause:
  1.2282 +                                          scancode=SDL_SCANCODE_PAUSE;
  1.2283 +                                          break;
  1.2284 +                                  }
  1.2285 +                               }
  1.2286 +
  1.2287 +                               /* Finally check if scancode has been decoded */
  1.2288 +                               if (scancode==SDL_SCANCODE_UNKNOWN)
  1.2289 +                               {
  1.2290 +                                  /* Something was pressed, which is not supported */
  1.2291 +                                  break;
  1.2292 +                               }
  1.2293 +
  1.2294 +                               /* Report pressed/released key to SDL */
  1.2295 +                               if (pressed==SDL_TRUE)
  1.2296 +                               {
  1.2297 +                                  SDL_SendKeyboardKey(0, SDL_PRESSED, scancode);
  1.2298 +                               }
  1.2299 +                               else
  1.2300 +                               {
  1.2301 +                                  SDL_SendKeyboardKey(0, SDL_RELEASED, scancode);
  1.2302 +                               }
  1.2303 +
  1.2304 +                               /* Photon doesn't send a release event for PrnScr key */
  1.2305 +                               if ((scancode==SDL_SCANCODE_PRINTSCREEN) && (pressed))
  1.2306 +                               {
  1.2307 +                                  SDL_SendKeyboardKey(0, SDL_RELEASED, scancode);
  1.2308 +                               }
  1.2309 +                            }
  1.2310 +                         }
  1.2311 +                         break;
  1.2312 +                    case Ph_EV_SERVICE:
  1.2313 +                         {
  1.2314 +                         }
  1.2315 +                         break;
  1.2316 +                    case Ph_EV_SYSTEM:
  1.2317 +                         {
  1.2318 +                         }
  1.2319 +                         break;
  1.2320 +                    case Ph_EV_WM:
  1.2321 +                         {
  1.2322 +                            PhWindowEvent_t* wmevent=NULL;
  1.2323 +
  1.2324 +                            /* Get associated event data */
  1.2325 +                            wmevent=PhGetData(event);
  1.2326 +                            if (wmevent==NULL)
  1.2327 +                            {
  1.2328 +                               break;
  1.2329 +                            }
  1.2330 +
  1.2331 +                            switch(wmevent->event_f)
  1.2332 +                            {
  1.2333 +                               case Ph_WM_CLOSE:
  1.2334 +                                    {
  1.2335 +                                       if (window!=NULL)
  1.2336 +                                       {
  1.2337 +                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
  1.2338 +                                       }
  1.2339 +                                    }
  1.2340 +                                    break;
  1.2341 +                               case Ph_WM_FOCUS:
  1.2342 +                                    {
  1.2343 +                                       if (wmevent->event_state==Ph_WM_EVSTATE_FOCUS)
  1.2344 +                                       {
  1.2345 +                                          if (window!=NULL)
  1.2346 +                                          {
  1.2347 +                                             PhRegion_t wregion;
  1.2348 +
  1.2349 +                                             SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
  1.2350 +                                             SDL_SetKeyboardFocus(0, window->id);
  1.2351 +
  1.2352 +                                             /* Set window region sensible to mouse motion events */
  1.2353 +                                             PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
  1.2354 +                                             wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
  1.2355 +                                             PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
  1.2356 +                                          }
  1.2357 +                                       }
  1.2358 +                                       if (wmevent->event_state==Ph_WM_EVSTATE_FOCUSLOST)
  1.2359 +                                       {
  1.2360 +                                          if (window!=NULL)
  1.2361 +                                          {
  1.2362 +                                             PhRegion_t wregion;
  1.2363 +
  1.2364 +                                             SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
  1.2365 +
  1.2366 +                                             /* Set window region ignore mouse motion events */
  1.2367 +                                             PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
  1.2368 +                                             wregion.events_sense&=~(Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON);
  1.2369 +                                             PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
  1.2370 +                                          }
  1.2371 +                                       }
  1.2372 +                                    }
  1.2373 +                                    break;
  1.2374 +                               case Ph_WM_MOVE:
  1.2375 +                                    {
  1.2376 +                                       if (window!=NULL)
  1.2377 +                                       {
  1.2378 +                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, wmevent->pos.x, wmevent->pos.y);
  1.2379 +                                       }
  1.2380 +                                    }
  1.2381 +                                    break;
  1.2382 +                               case Ph_WM_RESIZE:
  1.2383 +                                    {
  1.2384 +                                       if (window!=NULL)
  1.2385 +                                       {
  1.2386 +                                       }
  1.2387 +                                    }
  1.2388 +                                    break;
  1.2389 +                               case Ph_WM_HIDE:
  1.2390 +                                    {
  1.2391 +                                       if (window!=NULL)
  1.2392 +                                       {
  1.2393 +                                       }
  1.2394 +                                    }
  1.2395 +                                    break;
  1.2396 +                               case Ph_WM_MAX:
  1.2397 +                                    {
  1.2398 +                                       if (window!=NULL)
  1.2399 +                                       {
  1.2400 +                                       }
  1.2401 +                                    }
  1.2402 +                                    break;
  1.2403 +                               case Ph_WM_RESTORE:
  1.2404 +                                    {
  1.2405 +                                       if (window!=NULL)
  1.2406 +                                       {
  1.2407 +                                       }
  1.2408 +                                    }
  1.2409 +                                    break;
  1.2410 +                            }
  1.2411 +                         }
  1.2412 +                         break;
  1.2413 +                 }
  1.2414 +                 PtEventHandler(event);
  1.2415 +              }
  1.2416 +              break;
  1.2417 +         case 0:
  1.2418 +              {
  1.2419 +                 /* All events are read */
  1.2420 +                 finish=1;
  1.2421 +                 break;
  1.2422 +              }
  1.2423 +         case -1:
  1.2424 +              {
  1.2425 +                 /* Error occured in event reading */
  1.2426 +                 SDL_SetError("Photon: Can't read event");
  1.2427 +                 return;
  1.2428 +              }
  1.2429 +              break;
  1.2430 +      }
  1.2431 +      if (finish!=0)
  1.2432 +      {
  1.2433 +         break;
  1.2434 +      }
  1.2435 +   } while(1);
  1.2436  }
  1.2437  
  1.2438  /*****************************************************************************/
     2.1 --- a/src/video/photon/SDL_photon.h	Fri Apr 24 03:46:54 2009 +0000
     2.2 +++ b/src/video/photon/SDL_photon.h	Tue Apr 28 04:30:52 2009 +0000
     2.3 @@ -27,28 +27,78 @@
     2.4  #ifndef __SDL_PHOTON_H__
     2.5  #define __SDL_PHOTON_H__
     2.6  
     2.7 +/* GF headers must be included first for the Photon GF functions */
     2.8 +#if defined(SDL_VIDEO_OPENGL_ES)
     2.9 +   #include <gf/gf.h>
    2.10 +   #include <GLES/egl.h>
    2.11 +#endif /* SDL_VIDEO_OPENGL_ES */
    2.12 +
    2.13 +#include "SDL_config.h"
    2.14  #include "../SDL_sysvideo.h"
    2.15  
    2.16  #include <Ph.h>
    2.17 +#include <Pt.h>
    2.18 +#include <photon/PkKeyDef.h>
    2.19 +
    2.20 +/* Maximum display devices, which can handle SDL Photon driver */
    2.21 +#define SDL_VIDEO_PHOTON_MAX_RIDS 16
    2.22  
    2.23  typedef struct SDL_VideoData
    2.24  {
    2.25 +   PhRid_t  rid[SDL_VIDEO_PHOTON_MAX_RIDS];
    2.26 +   uint32_t avail_rids;
    2.27 +   uint32_t current_device_id;
    2.28 +   #if defined(SDL_VIDEO_OPENGL_ES)
    2.29 +      gf_dev_t      gfdev;           /* GF device handle                     */
    2.30 +      gf_dev_info_t gfdev_info;      /* GF device information                */
    2.31 +      SDL_bool      gfinitialized;   /* GF device initialization status      */
    2.32 +      EGLDisplay    egldisplay;      /* OpenGL ES display connection         */
    2.33 +      uint32_t      egl_refcount;    /* OpenGL ES reference count            */
    2.34 +      uint32_t      swapinterval;    /* OpenGL ES default swap interval      */
    2.35 +   #endif /* SDL_VIDEO_OPENGL_ES */
    2.36  } SDL_VideoData;
    2.37  
    2.38 -#define SDL_VIDEO_PHOTON_DEVICENAME_MAX 257
    2.39 +/* This is hardcoded value in photon/Pg.h */
    2.40 +#define SDL_VIDEO_PHOTON_DEVICENAME_MAX  41
    2.41 +#define SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE 128
    2.42 +
    2.43 +/* Maximum event message size with data payload */
    2.44 +#define SDL_VIDEO_PHOTON_EVENT_SIZE 8192
    2.45  
    2.46  typedef struct SDL_DisplayData
    2.47  {
    2.48 +   uint32_t          device_id;
    2.49     uint32_t          custom_refresh;   /* Custom refresh rate for all modes  */
    2.50     SDL_DisplayMode   current_mode;     /* Current video mode                 */
    2.51     uint8_t           description[SDL_VIDEO_PHOTON_DEVICENAME_MAX];
    2.52                                         /* Device description                 */
    2.53     uint32_t          caps;             /* Device capabilities                */
    2.54 +   PhCursorDef_t*    cursor;           /* Global cursor settings             */
    2.55 +   SDL_bool          cursor_visible;   /* SDL_TRUE if cursor visible         */
    2.56 +   uint32_t          cursor_size;      /* Cursor size in memory w/ structure */
    2.57 +   #if defined(SDL_VIDEO_OPENGL_ES)
    2.58 +      gf_display_t      display;       /* GF display handle                  */
    2.59 +      gf_display_info_t display_info;  /* GF display information             */
    2.60 +   #endif /* SDL_VIDEO_OPENGL_ES */
    2.61  } SDL_DisplayData;
    2.62  
    2.63 +/* Maximum amount of OpenGL ES framebuffer configurations */
    2.64 +#define SDL_VIDEO_GF_OPENGLES_CONFS 32
    2.65 +
    2.66  typedef struct SDL_WindowData
    2.67  {
    2.68 -   SDL_bool     uses_gles;           /* if true window must support OpenGL ES*/
    2.69 +   SDL_bool       uses_gles;           /* if true window must support OpenGL ES*/
    2.70 +   PtWidget_t*    window;              /* window handle                        */
    2.71 +   #if defined(SDL_VIDEO_OPENGL_ES)
    2.72 +      EGLConfig    gles_configs[SDL_VIDEO_GF_OPENGLES_CONFS];
    2.73 +                                         /* OpenGL ES framebuffer confs        */
    2.74 +      EGLint       gles_config;          /* OpenGL ES configuration index      */
    2.75 +      EGLContext   gles_context;         /* OpenGL ES context                  */
    2.76 +      EGLint       gles_attributes[256]; /* OpenGL ES attributes for context   */
    2.77 +      EGLSurface   gles_surface;         /* OpenGL ES target rendering surface */
    2.78 +      gf_surface_t gfsurface;            /* OpenGL ES GF's surface             */
    2.79 +      PdOffscreenContext_t* phsurface;   /* OpenGL ES Photon's surface         */
    2.80 +   #endif /* SDL_VIDEO_OPENGL_ES */
    2.81  } SDL_WindowData;
    2.82  
    2.83  /****************************************************************************/
    2.84 @@ -62,22 +112,24 @@
    2.85  
    2.86  #define SDL_PHOTON_UNACCELERATED         0x00000000
    2.87  #define SDL_PHOTON_ACCELERATED           0x00000001
    2.88 +#define SDL_PHOTON_UNACCELERATED_3D      0x00000000
    2.89 +#define SDL_PHOTON_ACCELERATED_3D        0x00000004
    2.90  
    2.91  /****************************************************************************/
    2.92  /* SDL_VideoDevice functions declaration                                    */
    2.93  /****************************************************************************/
    2.94  
    2.95  /* Display and window functions */
    2.96 -int photon_videoinit(_THIS);
    2.97 +int  photon_videoinit(_THIS);
    2.98  void photon_videoquit(_THIS);
    2.99  void photon_getdisplaymodes(_THIS);
   2.100 -int photon_setdisplaymode(_THIS, SDL_DisplayMode* mode);
   2.101 -int photon_setdisplaypalette(_THIS, SDL_Palette* palette);
   2.102 -int photon_getdisplaypalette(_THIS, SDL_Palette* palette);
   2.103 -int photon_setdisplaygammaramp(_THIS, Uint16* ramp);
   2.104 -int photon_getdisplaygammaramp(_THIS, Uint16* ramp);
   2.105 -int photon_createwindow(_THIS, SDL_Window* window);
   2.106 -int photon_createwindowfrom(_THIS, SDL_Window* window, const void* data);
   2.107 +int  photon_setdisplaymode(_THIS, SDL_DisplayMode* mode);
   2.108 +int  photon_setdisplaypalette(_THIS, SDL_Palette* palette);
   2.109 +int  photon_getdisplaypalette(_THIS, SDL_Palette* palette);
   2.110 +int  photon_setdisplaygammaramp(_THIS, Uint16* ramp);
   2.111 +int  photon_getdisplaygammaramp(_THIS, Uint16* ramp);
   2.112 +int  photon_createwindow(_THIS, SDL_Window* window);
   2.113 +int  photon_createwindowfrom(_THIS, SDL_Window* window, const void* data);
   2.114  void photon_setwindowtitle(_THIS, SDL_Window* window);
   2.115  void photon_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon);
   2.116  void photon_setwindowposition(_THIS, SDL_Window* window);
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/video/photon/SDL_photon_input.c	Tue Apr 28 04:30:52 2009 +0000
     3.3 @@ -0,0 +1,735 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997-2009 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +
    3.25 +    QNX Photon GUI SDL driver
    3.26 +    Copyright (C) 2009 Mike Gorchak
    3.27 +    (mike@malva.ua, lestat@i.com.ua)
    3.28 +*/
    3.29 +
    3.30 +#include "SDL_photon_input.h"
    3.31 +
    3.32 +#include "SDL_config.h"
    3.33 +#include "SDL_events.h"
    3.34 +#include "../../events/SDL_mouse_c.h"
    3.35 +#include "../../events/SDL_keyboard_c.h"
    3.36 +
    3.37 +#include "SDL_photon_keycodes.h"
    3.38 +
    3.39 +/* Mouse related functions */
    3.40 +SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y);
    3.41 +int  photon_showcursor(SDL_Cursor* cursor);
    3.42 +void photon_movecursor(SDL_Cursor* cursor);
    3.43 +void photon_freecursor(SDL_Cursor* cursor);
    3.44 +void photon_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y);
    3.45 +void photon_freemouse(SDL_Mouse* mouse);
    3.46 +
    3.47 +int32_t photon_addinputdevices(_THIS)
    3.48 +{
    3.49 +   SDL_VideoData*    phdata=(SDL_VideoData*)_this->driverdata;
    3.50 +   SDL_DisplayData*  didata=NULL;
    3.51 +   struct SDL_Mouse  photon_mouse;
    3.52 +   SDL_MouseData*    mdata=NULL;
    3.53 +   SDL_Keyboard      photon_keyboard;
    3.54 +   SDLKey   keymap[SDL_NUM_SCANCODES];
    3.55 +   uint32_t it;
    3.56 +
    3.57 +   for (it=0; it<_this->num_displays; it++)
    3.58 +   {
    3.59 +      /* Clear SDL mouse structure */
    3.60 +      SDL_memset(&photon_mouse, 0x00, sizeof(struct SDL_Mouse));
    3.61 +
    3.62 +      /* Allocate SDL_MouseData structure */
    3.63 +      mdata=(SDL_MouseData*)SDL_calloc(1, sizeof(SDL_MouseData));
    3.64 +      if (mdata==NULL)
    3.65 +      {
    3.66 +         SDL_OutOfMemory();
    3.67 +         return -1;
    3.68 +      }
    3.69 +
    3.70 +      /* Mark this mouse with ID 0 */
    3.71 +      photon_mouse.id=it;
    3.72 +      photon_mouse.driverdata=(void*)mdata;
    3.73 +      photon_mouse.CreateCursor=photon_createcursor;
    3.74 +      photon_mouse.ShowCursor=photon_showcursor;
    3.75 +      photon_mouse.MoveCursor=photon_movecursor;
    3.76 +      photon_mouse.FreeCursor=photon_freecursor;
    3.77 +      photon_mouse.WarpMouse=photon_warpmouse;
    3.78 +      photon_mouse.FreeMouse=photon_freemouse;
    3.79 +
    3.80 +      /* Get display data */
    3.81 +      didata=(SDL_DisplayData*)_this->displays[it].driverdata;
    3.82 +
    3.83 +      /* Store SDL_DisplayData pointer in the mouse driver internals */
    3.84 +      mdata->didata=didata;
    3.85 +
    3.86 +      /* Register mouse cursor in SDL */
    3.87 +      SDL_AddMouse(&photon_mouse, "Photon mouse cursor", 0, 0, 1);
    3.88 +   }
    3.89 +
    3.90 +   /* Photon maps all keyboards to one */
    3.91 +   SDL_zero(photon_keyboard);
    3.92 +   SDL_AddKeyboard(&photon_keyboard, -1);
    3.93 +
    3.94 +   /* Add default scancode to key mapping */
    3.95 +   SDL_GetDefaultKeymap(keymap);
    3.96 +   SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
    3.97 +
    3.98 +   return 0;
    3.99 +}
   3.100 +
   3.101 +int32_t photon_delinputdevices(_THIS)
   3.102 +{
   3.103 +   /* Destroy all of the mice */
   3.104 +   SDL_MouseQuit();
   3.105 +}
   3.106 +
   3.107 +/*****************************************************************************/
   3.108 +/* Photon mouse related functions                                            */
   3.109 +/*****************************************************************************/
   3.110 +SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y)
   3.111 +{
   3.112 +   PhCursorDef_t* internal_cursor;
   3.113 +   SDL_Cursor*    sdl_cursor;
   3.114 +   uint8_t*       image0=NULL;
   3.115 +   uint8_t*       image1=NULL;
   3.116 +   uint32_t       it;
   3.117 +   uint32_t       jt;
   3.118 +   uint32_t       shape_color;
   3.119 +
   3.120 +   /* SDL converts monochrome cursor shape to 32bpp cursor shape      */
   3.121 +   /* and we must convert it back to monochrome, this routine handles */
   3.122 +   /* 24/32bpp surfaces only                                          */
   3.123 +   if ((surface->format->BitsPerPixel!=32) && (surface->format->BitsPerPixel!=24))
   3.124 +   {
   3.125 +      SDL_SetError("Photon: Cursor shape is not 24/32bpp.");
   3.126 +      return NULL;
   3.127 +   }
   3.128 +
   3.129 +   /* Checking data parameters */
   3.130 +   if ((surface->w==0) || (surface->h==0))
   3.131 +   {
   3.132 +      SDL_SetError("Photon: Cursor shape dimensions are zero");
   3.133 +      return NULL;
   3.134 +   }
   3.135 +
   3.136 +   /* Allocate memory for the internal cursor format */
   3.137 +   internal_cursor=(PhCursorDef_t*)SDL_calloc(1, sizeof(PhCursorDef_t)+
   3.138 +      ((((surface->w+7)>>3)*surface->h)*2)-1);
   3.139 +   if (internal_cursor==NULL)
   3.140 +   {
   3.141 +      SDL_OutOfMemory();
   3.142 +      return NULL;
   3.143 +   }
   3.144 +
   3.145 +   /* Allocate memory for the SDL cursor */
   3.146 +   sdl_cursor=(SDL_Cursor*)SDL_calloc(1, sizeof(SDL_Cursor));
   3.147 +   if (sdl_cursor==NULL)
   3.148 +   {
   3.149 +      SDL_free(internal_cursor);
   3.150 +      SDL_OutOfMemory();
   3.151 +      return NULL;
   3.152 +   }
   3.153 +
   3.154 +   /* Set driverdata as photon cursor format */
   3.155 +   image0=(uint8_t*)internal_cursor;
   3.156 +   image0+=sizeof(PhCursorDef_t)-1;
   3.157 +   image1=image0;
   3.158 +   image1+=((surface->w+7)>>3)*surface->h;
   3.159 +   sdl_cursor->driverdata=(void*)internal_cursor;
   3.160 +   internal_cursor->hdr.len=(sizeof(PhCursorDef_t)-sizeof(PhRegionDataHdr_t))+
   3.161 +                            ((((surface->w+7)>>3)*surface->h)*2)-1;
   3.162 +   internal_cursor->hdr.type=Ph_RDATA_CURSOR;
   3.163 +   internal_cursor->size1.x=surface->w;
   3.164 +   internal_cursor->size1.y=surface->h;
   3.165 +   internal_cursor->size2.x=surface->w;
   3.166 +   internal_cursor->size2.y=surface->h;
   3.167 +   internal_cursor->offset1.x=hot_x;
   3.168 +   internal_cursor->offset1.y=hot_y;
   3.169 +   internal_cursor->offset2.x=hot_x;
   3.170 +   internal_cursor->offset2.y=hot_y;
   3.171 +   internal_cursor->bytesperline1=((surface->w+7)>>3);
   3.172 +   internal_cursor->bytesperline2=((surface->w+7)>>3);
   3.173 +   internal_cursor->color1=(SDL_PHOTON_MOUSE_COLOR_BLACK) & 0x00FFFFFF;
   3.174 +   internal_cursor->color2=(SDL_PHOTON_MOUSE_COLOR_WHITE) & 0x00FFFFFF;
   3.175 +
   3.176 +   /* Convert cursor from 32 bpp */
   3.177 +   for (jt=0; jt<surface->h; jt++)
   3.178 +   {
   3.179 +      for (it=0; it<surface->w; it++)
   3.180 +      {
   3.181 +         shape_color=*((uint32_t*)((uint8_t*)surface->pixels+jt*surface->pitch+it*surface->format->BytesPerPixel));
   3.182 +         switch(shape_color)
   3.183 +         {
   3.184 +            case SDL_PHOTON_MOUSE_COLOR_BLACK:
   3.185 +                 {
   3.186 +                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))|=0x80>>(it%8);
   3.187 +                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8));
   3.188 +                 }
   3.189 +                 break;
   3.190 +            case SDL_PHOTON_MOUSE_COLOR_WHITE:
   3.191 +                 {
   3.192 +                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8));
   3.193 +                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))|=0x80>>(it%8);
   3.194 +                 }
   3.195 +                 break;
   3.196 +            case SDL_PHOTON_MOUSE_COLOR_TRANS:
   3.197 +                 {
   3.198 +                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8));
   3.199 +                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8));
   3.200 +                 }
   3.201 +                 break;
   3.202 +            default:
   3.203 +                 {
   3.204 +                    /* The same as transparent color, must not happen */
   3.205 +                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8));
   3.206 +                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8));
   3.207 +                 }
   3.208 +                 break;
   3.209 +         }
   3.210 +      }
   3.211 +   }
   3.212 +
   3.213 +   return sdl_cursor;
   3.214 +}
   3.215 +
   3.216 +int photon_showcursor(SDL_Cursor* cursor)
   3.217 +{
   3.218 +   SDL_VideoDisplay* display;
   3.219 +   SDL_DisplayData*  didata;
   3.220 +   SDL_Window*       window;
   3.221 +   SDL_WindowData*   wdata;
   3.222 +   SDL_WindowID      window_id;
   3.223 +   PhCursorDef_t*    internal_cursor;
   3.224 +   int32_t status;
   3.225 +
   3.226 +   /* Get current window id */
   3.227 +   window_id=SDL_GetFocusWindow();
   3.228 +   if (window_id<=0)
   3.229 +   {
   3.230 +      SDL_MouseData* mdata=NULL;
   3.231 +
   3.232 +      /* If there is no current window, then someone calls this function */
   3.233 +      /* to set global mouse settings during SDL initialization          */
   3.234 +      if (cursor!=NULL)
   3.235 +      {
   3.236 +         /* Store cursor for future usage */
   3.237 +         mdata=(SDL_MouseData*)cursor->mouse->driverdata;
   3.238 +         didata=(SDL_DisplayData*)mdata->didata;
   3.239 +         internal_cursor=(PhCursorDef_t*)cursor->driverdata;
   3.240 +
   3.241 +         if (didata->cursor_size>=(internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t)))
   3.242 +         {
   3.243 +            SDL_memcpy(didata->cursor, internal_cursor, internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t));
   3.244 +         }
   3.245 +         else
   3.246 +         {
   3.247 +            /* Partitial cursor image */
   3.248 +            SDL_memcpy(didata->cursor, internal_cursor, didata->cursor_size);
   3.249 +         }
   3.250 +
   3.251 +         didata->cursor_visible=SDL_TRUE;
   3.252 +         return 0;
   3.253 +      }
   3.254 +      else
   3.255 +      {
   3.256 +         /* We can't get SDL_DisplayData at this point, return fake success */
   3.257 +         return 0;
   3.258 +      }
   3.259 +   }
   3.260 +   else
   3.261 +   {
   3.262 +      /* Sanity checks */
   3.263 +      window=SDL_GetWindowFromID(window_id);
   3.264 +      if (window!=NULL)
   3.265 +      {
   3.266 +         display=SDL_GetDisplayFromWindow(window);
   3.267 +         if (display!=NULL)
   3.268 +         {
   3.269 +            didata=(SDL_DisplayData*)display->driverdata;
   3.270 +            if (didata!=NULL)
   3.271 +            {
   3.272 +               wdata=(SDL_WindowData*)window->driverdata;
   3.273 +               if (wdata==NULL)
   3.274 +               {
   3.275 +                  return -1;
   3.276 +               }
   3.277 +            }
   3.278 +            else
   3.279 +            {
   3.280 +               return -1;
   3.281 +            }
   3.282 +         }
   3.283 +         else
   3.284 +         {
   3.285 +            return -1;
   3.286 +         }
   3.287 +      }
   3.288 +      else
   3.289 +      {
   3.290 +         return -1;
   3.291 +      }
   3.292 +   }
   3.293 +
   3.294 +   /* return if window widget has been destroyed already */
   3.295 +   if (wdata->window==NULL)
   3.296 +   {
   3.297 +      return;
   3.298 +   }
   3.299 +
   3.300 +   /* Check if we need to set new shape or disable cursor shape */
   3.301 +   if (cursor!=NULL)
   3.302 +   {
   3.303 +      /* Retrieve photon cursor shape */
   3.304 +      internal_cursor=(PhCursorDef_t*)cursor->driverdata;
   3.305 +      if (internal_cursor==NULL)
   3.306 +      {
   3.307 +         SDL_SetError("Photon: Internal cursor data is absent");
   3.308 +         return -1;
   3.309 +      }
   3.310 +
   3.311 +      /* Setup cursor type */
   3.312 +      status=PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
   3.313 +      if (status!=0)
   3.314 +      {
   3.315 +         SDL_SetError("Photon: Failed to set cursor type to bitmap");
   3.316 +         return -1;
   3.317 +      }
   3.318 +
   3.319 +      /* Setup cursor color to default */
   3.320 +      status=PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR, 0);
   3.321 +      if (status!=0)
   3.322 +      {
   3.323 +         SDL_SetError("Photon: Failed to set cursor color");
   3.324 +         return -1;
   3.325 +      }
   3.326 +
   3.327 +      /* Setup cursor shape */
   3.328 +      status=PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, internal_cursor,
   3.329 +                           internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t));
   3.330 +      if (status!=0)
   3.331 +      {
   3.332 +         SDL_SetError("Photon: Failed to set cursor color");
   3.333 +         return -1;
   3.334 +      }
   3.335 +
   3.336 +      /* Store current cursor for future usage */
   3.337 +      if (didata->cursor_size>=(internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t)))
   3.338 +      {
   3.339 +         SDL_memcpy(didata->cursor, internal_cursor, internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t));
   3.340 +      }
   3.341 +      else
   3.342 +      {
   3.343 +         /* Partitial cursor image */
   3.344 +         SDL_memcpy(didata->cursor, internal_cursor, didata->cursor_size);
   3.345 +      }
   3.346 +
   3.347 +      /* Set cursor visible */
   3.348 +      didata->cursor_visible=SDL_TRUE;
   3.349 +   }
   3.350 +   else
   3.351 +   {
   3.352 +      /* SDL requests to disable cursor */
   3.353 +      status=PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
   3.354 +      if (status!=0)
   3.355 +      {
   3.356 +         SDL_SetError("Photon: Can't disable cursor");
   3.357 +         return -1;
   3.358 +      }
   3.359 +
   3.360 +      /* Set cursor invisible */
   3.361 +      didata->cursor_visible=SDL_FALSE;
   3.362 +   }
   3.363 +
   3.364 +   /* Flush all pending widget data */
   3.365 +   PtFlush();
   3.366 +
   3.367 +   /* New cursor shape is set */
   3.368 +   return 0;
   3.369 +}
   3.370 +
   3.371 +void photon_movecursor(SDL_Cursor* cursor)
   3.372 +{
   3.373 +   SDL_VideoDisplay* display;
   3.374 +   SDL_DisplayData*  didata;
   3.375 +   SDL_Window*  window;
   3.376 +   SDL_WindowID window_id;
   3.377 +   int32_t status;
   3.378 +
   3.379 +   /* Get current window id */
   3.380 +   window_id=SDL_GetFocusWindow();
   3.381 +   if (window_id<=0)
   3.382 +   {
   3.383 +      didata=(SDL_DisplayData*)cursor->mouse->driverdata;
   3.384 +   }
   3.385 +   else
   3.386 +   {
   3.387 +      /* Sanity checks */
   3.388 +      window=SDL_GetWindowFromID(window_id);
   3.389 +      if (window!=NULL)
   3.390 +      {
   3.391 +         display=SDL_GetDisplayFromWindow(window);
   3.392 +         if (display!=NULL)
   3.393 +         {
   3.394 +            didata=(SDL_DisplayData*)display->driverdata;
   3.395 +            if (didata==NULL)
   3.396 +            {
   3.397 +               return;
   3.398 +            }
   3.399 +         }
   3.400 +         else
   3.401 +         {
   3.402 +            return;
   3.403 +         }
   3.404 +      }
   3.405 +      else
   3.406 +      {
   3.407 +         return;
   3.408 +      }
   3.409 +   }
   3.410 +
   3.411 +/*   cursor->mouse->x, cursor->mouse->y */
   3.412 +}
   3.413 +
   3.414 +void photon_freecursor(SDL_Cursor* cursor)
   3.415 +{
   3.416 +   PhCursorDef_t* internal_cursor=NULL;
   3.417 +
   3.418 +   if (cursor!=NULL)
   3.419 +   {
   3.420 +      internal_cursor=(PhCursorDef_t*)cursor->driverdata;
   3.421 +      if (internal_cursor!=NULL)
   3.422 +      {
   3.423 +         SDL_free(internal_cursor);
   3.424 +         cursor->driverdata=NULL;
   3.425 +      }
   3.426 +   }
   3.427 +}
   3.428 +
   3.429 +void photon_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y)
   3.430 +{
   3.431 +   SDL_VideoDisplay* display;
   3.432 +   SDL_DisplayData*  didata;
   3.433 +   SDL_Window* window;
   3.434 +   int32_t status;
   3.435 +
   3.436 +   /* Sanity checks */
   3.437 +   window=SDL_GetWindowFromID(windowID);
   3.438 +   if (window!=NULL)
   3.439 +   {
   3.440 +      display=SDL_GetDisplayFromWindow(window);
   3.441 +      if (display!=NULL)
   3.442 +      {
   3.443 +         didata=(SDL_DisplayData*)display->driverdata;
   3.444 +         if (didata==NULL)
   3.445 +         {
   3.446 +            return;
   3.447 +         }
   3.448 +      }
   3.449 +      else
   3.450 +      {
   3.451 +         return;
   3.452 +      }
   3.453 +   }
   3.454 +   else
   3.455 +   {
   3.456 +      return;
   3.457 +   }
   3.458 +
   3.459 +}
   3.460 +
   3.461 +void photon_freemouse(SDL_Mouse* mouse)
   3.462 +{
   3.463 +   if (mouse->driverdata==NULL)
   3.464 +   {
   3.465 +      return;
   3.466 +   }
   3.467 +
   3.468 +   /* Mouse framework doesn't deletes automatically our driverdata */
   3.469 +   SDL_free(mouse->driverdata);
   3.470 +   mouse->driverdata=NULL;
   3.471 +
   3.472 +   return;
   3.473 +}
   3.474 +
   3.475 +SDL_scancode photon_to_sdl_keymap(uint32_t key)
   3.476 +{
   3.477 +   SDL_scancode scancode=SDL_SCANCODE_UNKNOWN;
   3.478 +
   3.479 +   switch(key & 0x0000007F)
   3.480 +   {
   3.481 +      case PHOTON_SCANCODE_ESCAPE:
   3.482 +           scancode=SDL_SCANCODE_ESCAPE;
   3.483 +           break;
   3.484 +      case PHOTON_SCANCODE_F1:
   3.485 +           scancode=SDL_SCANCODE_F1;
   3.486 +           break;
   3.487 +      case PHOTON_SCANCODE_F2:
   3.488 +           scancode=SDL_SCANCODE_F2;
   3.489 +           break;
   3.490 +      case PHOTON_SCANCODE_F3:
   3.491 +           scancode=SDL_SCANCODE_F3;
   3.492 +           break;
   3.493 +      case PHOTON_SCANCODE_F4:
   3.494 +           scancode=SDL_SCANCODE_F4;
   3.495 +           break;
   3.496 +      case PHOTON_SCANCODE_F5:
   3.497 +           scancode=SDL_SCANCODE_F5;
   3.498 +           break;
   3.499 +      case PHOTON_SCANCODE_F6:
   3.500 +           scancode=SDL_SCANCODE_F6;
   3.501 +           break;
   3.502 +      case PHOTON_SCANCODE_F7:
   3.503 +           scancode=SDL_SCANCODE_F7;
   3.504 +           break;
   3.505 +      case PHOTON_SCANCODE_F8:
   3.506 +           scancode=SDL_SCANCODE_F8;
   3.507 +           break;
   3.508 +      case PHOTON_SCANCODE_F9:
   3.509 +           scancode=SDL_SCANCODE_F9;
   3.510 +           break;
   3.511 +      case PHOTON_SCANCODE_F10:
   3.512 +           scancode=SDL_SCANCODE_F10;
   3.513 +           break;
   3.514 +      case PHOTON_SCANCODE_F11:
   3.515 +           scancode=SDL_SCANCODE_F11;
   3.516 +           break;
   3.517 +      case PHOTON_SCANCODE_F12:
   3.518 +           scancode=SDL_SCANCODE_F12;
   3.519 +           break;
   3.520 +      case PHOTON_SCANCODE_BACKQOUTE:
   3.521 +           scancode=SDL_SCANCODE_GRAVE;
   3.522 +           break;
   3.523 +      case PHOTON_SCANCODE_1:
   3.524 +           scancode=SDL_SCANCODE_1;
   3.525 +           break;
   3.526 +      case PHOTON_SCANCODE_2:
   3.527 +           scancode=SDL_SCANCODE_2;
   3.528 +           break;
   3.529 +      case PHOTON_SCANCODE_3:
   3.530 +           scancode=SDL_SCANCODE_3;
   3.531 +           break;
   3.532 +      case PHOTON_SCANCODE_4:
   3.533 +           scancode=SDL_SCANCODE_4;
   3.534 +           break;
   3.535 +      case PHOTON_SCANCODE_5:
   3.536 +           scancode=SDL_SCANCODE_5;
   3.537 +           break;
   3.538 +      case PHOTON_SCANCODE_6:
   3.539 +           scancode=SDL_SCANCODE_6;
   3.540 +           break;
   3.541 +      case PHOTON_SCANCODE_7:
   3.542 +           scancode=SDL_SCANCODE_7;
   3.543 +           break;
   3.544 +      case PHOTON_SCANCODE_8:
   3.545 +           scancode=SDL_SCANCODE_8;
   3.546 +           break;
   3.547 +      case PHOTON_SCANCODE_9:
   3.548 +           scancode=SDL_SCANCODE_9;
   3.549 +           break;
   3.550 +      case PHOTON_SCANCODE_0:
   3.551 +           scancode=SDL_SCANCODE_0;
   3.552 +           break;
   3.553 +      case PHOTON_SCANCODE_MINUS:
   3.554 +           scancode=SDL_SCANCODE_MINUS;
   3.555 +           break;
   3.556 +      case PHOTON_SCANCODE_EQUAL:
   3.557 +           scancode=SDL_SCANCODE_EQUALS;
   3.558 +           break;
   3.559 +      case PHOTON_SCANCODE_BACKSPACE:
   3.560 +           scancode=SDL_SCANCODE_BACKSPACE;
   3.561 +           break;
   3.562 +      case PHOTON_SCANCODE_TAB:
   3.563 +           scancode=SDL_SCANCODE_TAB;
   3.564 +           break;
   3.565 +      case PHOTON_SCANCODE_Q:
   3.566 +           scancode=SDL_SCANCODE_Q;
   3.567 +           break;
   3.568 +      case PHOTON_SCANCODE_W:
   3.569 +           scancode=SDL_SCANCODE_W;
   3.570 +           break;
   3.571 +      case PHOTON_SCANCODE_E:
   3.572 +           scancode=SDL_SCANCODE_E;
   3.573 +           break;
   3.574 +      case PHOTON_SCANCODE_R:
   3.575 +           scancode=SDL_SCANCODE_R;
   3.576 +           break;
   3.577 +      case PHOTON_SCANCODE_T:
   3.578 +           scancode=SDL_SCANCODE_T;
   3.579 +           break;
   3.580 +      case PHOTON_SCANCODE_Y:
   3.581 +           scancode=SDL_SCANCODE_Y;
   3.582 +           break;
   3.583 +      case PHOTON_SCANCODE_U:
   3.584 +           scancode=SDL_SCANCODE_U;
   3.585 +           break;
   3.586 +      case PHOTON_SCANCODE_I:
   3.587 +           scancode=SDL_SCANCODE_I;
   3.588 +           break;
   3.589 +      case PHOTON_SCANCODE_O:
   3.590 +           scancode=SDL_SCANCODE_O;
   3.591 +           break;
   3.592 +      case PHOTON_SCANCODE_P:
   3.593 +           scancode=SDL_SCANCODE_P;
   3.594 +           break;
   3.595 +      case PHOTON_SCANCODE_LEFT_SQ_BR:
   3.596 +           scancode=SDL_SCANCODE_LEFTBRACKET;
   3.597 +           break;
   3.598 +      case PHOTON_SCANCODE_RIGHT_SQ_BR:
   3.599 +           scancode=SDL_SCANCODE_RIGHTBRACKET;
   3.600 +           break;
   3.601 +      case PHOTON_SCANCODE_ENTER:
   3.602 +           scancode=SDL_SCANCODE_RETURN;
   3.603 +           break;
   3.604 +      case PHOTON_SCANCODE_CAPSLOCK:
   3.605 +           scancode=SDL_SCANCODE_CAPSLOCK;
   3.606 +           break;
   3.607 +      case PHOTON_SCANCODE_A:
   3.608 +           scancode=SDL_SCANCODE_A;
   3.609 +           break;
   3.610 +      case PHOTON_SCANCODE_S:
   3.611 +           scancode=SDL_SCANCODE_S;
   3.612 +           break;
   3.613 +      case PHOTON_SCANCODE_D:
   3.614 +           scancode=SDL_SCANCODE_D;
   3.615 +           break;
   3.616 +      case PHOTON_SCANCODE_F:
   3.617 +           scancode=SDL_SCANCODE_F;
   3.618 +           break;
   3.619 +      case PHOTON_SCANCODE_G:
   3.620 +           scancode=SDL_SCANCODE_G;
   3.621 +           break;
   3.622 +      case PHOTON_SCANCODE_H:
   3.623 +           scancode=SDL_SCANCODE_H;
   3.624 +           break;
   3.625 +      case PHOTON_SCANCODE_J:
   3.626 +           scancode=SDL_SCANCODE_J;
   3.627 +           break;
   3.628 +      case PHOTON_SCANCODE_K:
   3.629 +           scancode=SDL_SCANCODE_K;
   3.630 +           break;
   3.631 +      case PHOTON_SCANCODE_L:
   3.632 +           scancode=SDL_SCANCODE_L;
   3.633 +           break;
   3.634 +      case PHOTON_SCANCODE_SEMICOLON:
   3.635 +           scancode=SDL_SCANCODE_SEMICOLON;
   3.636 +           break;
   3.637 +      case PHOTON_SCANCODE_QUOTE:
   3.638 +           scancode=SDL_SCANCODE_APOSTROPHE;
   3.639 +           break;
   3.640 +      case PHOTON_SCANCODE_BACKSLASH:
   3.641 +           scancode=SDL_SCANCODE_BACKSLASH;
   3.642 +           break;
   3.643 +      case PHOTON_SCANCODE_LEFT_SHIFT:
   3.644 +           scancode=SDL_SCANCODE_LSHIFT;
   3.645 +           break;
   3.646 +      case PHOTON_SCANCODE_Z:
   3.647 +           scancode=SDL_SCANCODE_Z;
   3.648 +           break;
   3.649 +      case PHOTON_SCANCODE_X:
   3.650 +           scancode=SDL_SCANCODE_X;
   3.651 +           break;
   3.652 +      case PHOTON_SCANCODE_C:
   3.653 +           scancode=SDL_SCANCODE_C;
   3.654 +           break;
   3.655 +      case PHOTON_SCANCODE_V:
   3.656 +           scancode=SDL_SCANCODE_V;
   3.657 +           break;
   3.658 +      case PHOTON_SCANCODE_B:
   3.659 +           scancode=SDL_SCANCODE_B;
   3.660 +           break;
   3.661 +      case PHOTON_SCANCODE_N:
   3.662 +           scancode=SDL_SCANCODE_N;
   3.663 +           break;
   3.664 +      case PHOTON_SCANCODE_M:
   3.665 +           scancode=SDL_SCANCODE_M;
   3.666 +           break;
   3.667 +      case PHOTON_SCANCODE_COMMA:
   3.668 +           scancode=SDL_SCANCODE_COMMA;
   3.669 +           break;
   3.670 +      case PHOTON_SCANCODE_POINT:
   3.671 +           scancode=SDL_SCANCODE_PERIOD;
   3.672 +           break;
   3.673 +      case PHOTON_SCANCODE_SLASH:
   3.674 +           scancode=SDL_SCANCODE_SLASH;
   3.675 +           break;
   3.676 +      case PHOTON_SCANCODE_RIGHT_SHIFT:
   3.677 +           scancode=SDL_SCANCODE_RSHIFT;
   3.678 +           break;
   3.679 +      case PHOTON_SCANCODE_CTRL:
   3.680 +           scancode=SDL_SCANCODE_LCTRL;
   3.681 +           break;
   3.682 +      case PHOTON_SCANCODE_WFLAG:
   3.683 +           scancode=SDL_SCANCODE_LGUI;
   3.684 +           break;
   3.685 +      case PHOTON_SCANCODE_ALT:
   3.686 +           scancode=SDL_SCANCODE_LALT;
   3.687 +           break;
   3.688 +      case PHOTON_SCANCODE_SPACE:
   3.689 +           scancode=SDL_SCANCODE_SPACE;
   3.690 +           break;
   3.691 +      case PHOTON_SCANCODE_MENU:
   3.692 +           scancode=SDL_SCANCODE_MENU;
   3.693 +           break;
   3.694 +      case PHOTON_SCANCODE_PRNSCR:
   3.695 +           scancode=SDL_SCANCODE_PRINTSCREEN;
   3.696 +           break;
   3.697 +      case PHOTON_SCANCODE_SCROLLLOCK:
   3.698 +           scancode=SDL_SCANCODE_SCROLLLOCK;
   3.699 +           break;
   3.700 +      case PHOTON_SCANCODE_INSERT:
   3.701 +           scancode=SDL_SCANCODE_INSERT;
   3.702 +           break;
   3.703 +      case PHOTON_SCANCODE_HOME:
   3.704 +           scancode=SDL_SCANCODE_HOME;
   3.705 +           break;
   3.706 +      case PHOTON_SCANCODE_PAGEUP:
   3.707 +           scancode=SDL_SCANCODE_PAGEUP;
   3.708 +           break;
   3.709 +      case PHOTON_SCANCODE_DELETE:
   3.710 +           scancode=SDL_SCANCODE_DELETE;
   3.711 +           break;
   3.712 +      case PHOTON_SCANCODE_END:
   3.713 +           scancode=SDL_SCANCODE_END;
   3.714 +           break;
   3.715 +      case PHOTON_SCANCODE_PAGEDOWN:
   3.716 +           scancode=SDL_SCANCODE_PAGEDOWN;
   3.717 +           break;
   3.718 +      case PHOTON_SCANCODE_UP:
   3.719 +           scancode=SDL_SCANCODE_UP;
   3.720 +           break;
   3.721 +      case PHOTON_SCANCODE_DOWN:
   3.722 +           scancode=SDL_SCANCODE_DOWN;
   3.723 +           break;
   3.724 +      case PHOTON_SCANCODE_LEFT:
   3.725 +           scancode=SDL_SCANCODE_LEFT;
   3.726 +           break;
   3.727 +      case PHOTON_SCANCODE_RIGHT:
   3.728 +           scancode=SDL_SCANCODE_RIGHT;
   3.729 +           break;
   3.730 +      case PHOTON_SCANCODE_NUMLOCK:
   3.731 +           scancode=SDL_SCANCODE_NUMLOCKCLEAR;
   3.732 +           break;
   3.733 +      default:
   3.734 +           break;
   3.735 +   }
   3.736 +
   3.737 +   return scancode;
   3.738 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/photon/SDL_photon_input.h	Tue Apr 28 04:30:52 2009 +0000
     4.3 @@ -0,0 +1,50 @@
     4.4 +/*
     4.5 +    SDL - Simple DirectMedia Layer
     4.6 +    Copyright (C) 1997-2009 Sam Lantinga
     4.7 +
     4.8 +    This library is free software; you can redistribute it and/or
     4.9 +    modify it under the terms of the GNU Lesser General Public
    4.10 +    License as published by the Free Software Foundation; either
    4.11 +    version 2.1 of the License, or (at your option) any later version.
    4.12 +
    4.13 +    This library is distributed in the hope that it will be useful,
    4.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 +    Lesser General Public License for more details.
    4.17 +
    4.18 +    You should have received a copy of the GNU Lesser General Public
    4.19 +    License along with this library; if not, write to the Free Software
    4.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    4.21 +
    4.22 +    Sam Lantinga
    4.23 +    slouken@libsdl.org
    4.24 +
    4.25 +    QNX Photon GUI SDL driver
    4.26 +    Copyright (C) 2009 Mike Gorchak
    4.27 +    (mike@malva.ua, lestat@i.com.ua)
    4.28 +*/
    4.29 +
    4.30 +#ifndef __SDL_PHOTON_INPUT_H__
    4.31 +#define __SDL_PHOTON_INPUT_H__
    4.32 +
    4.33 +#include "SDL_config.h"
    4.34 +#include "SDL_video.h"
    4.35 +#include "../SDL_sysvideo.h"
    4.36 +
    4.37 +#include "SDL_photon.h"
    4.38 +
    4.39 +typedef struct SDL_MouseData
    4.40 +{
    4.41 +   SDL_DisplayData* didata;
    4.42 +} SDL_MouseData;
    4.43 +
    4.44 +int32_t photon_addinputdevices(_THIS);
    4.45 +int32_t photon_delinputdevices(_THIS);
    4.46 +
    4.47 +#define SDL_PHOTON_MOUSE_COLOR_BLACK 0xFF000000
    4.48 +#define SDL_PHOTON_MOUSE_COLOR_WHITE 0xFFFFFFFF
    4.49 +#define SDL_PHOTON_MOUSE_COLOR_TRANS 0x00000000
    4.50 +
    4.51 +SDL_scancode photon_to_sdl_keymap(uint32_t key);
    4.52 +
    4.53 +#endif /* __SDL_GF_INPUT_H__ */
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/video/photon/SDL_photon_keycodes.h	Tue Apr 28 04:30:52 2009 +0000
     5.3 @@ -0,0 +1,123 @@
     5.4 +/*
     5.5 +    SDL - Simple DirectMedia Layer
     5.6 +    Copyright (C) 1997-2009 Sam Lantinga
     5.7 +
     5.8 +    This library is free software; you can redistribute it and/or
     5.9 +    modify it under the terms of the GNU Lesser General Public
    5.10 +    License as published by the Free Software Foundation; either
    5.11 +    version 2.1 of the License, or (at your option) any later version.
    5.12 +
    5.13 +    This library is distributed in the hope that it will be useful,
    5.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    5.16 +    Lesser General Public License for more details.
    5.17 +
    5.18 +    You should have received a copy of the GNU Lesser General Public
    5.19 +    License along with this library; if not, write to the Free Software
    5.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    5.21 +
    5.22 +    Sam Lantinga
    5.23 +    slouken@libsdl.org
    5.24 +
    5.25 +    QNX Photon GUI SDL driver
    5.26 +    Copyright (C) 2009 Mike Gorchak
    5.27 +    (mike@malva.ua, lestat@i.com.ua)
    5.28 +*/
    5.29 +
    5.30 +#ifndef __SDL_PHOTON_KEYCODES_H__
    5.31 +#define __SDL_PHOTON_KEYCODES_H__
    5.32 +
    5.33 +#define PHOTON_SCANCODE_ESCAPE      0x01
    5.34 +#define PHOTON_SCANCODE_F1          0x3B
    5.35 +#define PHOTON_SCANCODE_F2          0x3C
    5.36 +#define PHOTON_SCANCODE_F3          0x3D
    5.37 +#define PHOTON_SCANCODE_F4          0x3E
    5.38 +#define PHOTON_SCANCODE_F5          0x3F
    5.39 +#define PHOTON_SCANCODE_F6          0x40
    5.40 +#define PHOTON_SCANCODE_F7          0x41
    5.41 +#define PHOTON_SCANCODE_F8          0x42
    5.42 +#define PHOTON_SCANCODE_F9          0x43
    5.43 +#define PHOTON_SCANCODE_F10         0x44
    5.44 +#define PHOTON_SCANCODE_F11         0x57
    5.45 +#define PHOTON_SCANCODE_F12         0x58
    5.46 +
    5.47 +#define PHOTON_SCANCODE_BACKQOUTE   0x29
    5.48 +#define PHOTON_SCANCODE_1           0x02
    5.49 +#define PHOTON_SCANCODE_2           0x03
    5.50 +#define PHOTON_SCANCODE_3           0x04
    5.51 +#define PHOTON_SCANCODE_4           0x05
    5.52 +#define PHOTON_SCANCODE_5           0x06
    5.53 +#define PHOTON_SCANCODE_6           0x07
    5.54 +#define PHOTON_SCANCODE_7           0x08
    5.55 +#define PHOTON_SCANCODE_8           0x09
    5.56 +#define PHOTON_SCANCODE_9           0x0A
    5.57 +#define PHOTON_SCANCODE_0           0x0B
    5.58 +#define PHOTON_SCANCODE_MINUS       0x0C
    5.59 +#define PHOTON_SCANCODE_EQUAL       0x0D
    5.60 +#define PHOTON_SCANCODE_BACKSPACE   0x0E
    5.61 +
    5.62 +#define PHOTON_SCANCODE_TAB         0x0F
    5.63 +#define PHOTON_SCANCODE_Q           0x10
    5.64 +#define PHOTON_SCANCODE_W           0x11
    5.65 +#define PHOTON_SCANCODE_E           0x12
    5.66 +#define PHOTON_SCANCODE_R           0x13
    5.67 +#define PHOTON_SCANCODE_T           0x14
    5.68 +#define PHOTON_SCANCODE_Y           0x15
    5.69 +#define PHOTON_SCANCODE_U           0x16
    5.70 +#define PHOTON_SCANCODE_I           0x17
    5.71 +#define PHOTON_SCANCODE_O           0x18
    5.72 +#define PHOTON_SCANCODE_P           0x19
    5.73 +#define PHOTON_SCANCODE_LEFT_SQ_BR  0x1A
    5.74 +#define PHOTON_SCANCODE_RIGHT_SQ_BR 0x1B
    5.75 +#define PHOTON_SCANCODE_ENTER       0x1C
    5.76 +
    5.77 +#define PHOTON_SCANCODE_CAPSLOCK    0x3A
    5.78 +#define PHOTON_SCANCODE_A           0x1E
    5.79 +#define PHOTON_SCANCODE_S           0x1F
    5.80 +#define PHOTON_SCANCODE_D           0x20
    5.81 +#define PHOTON_SCANCODE_F           0x21
    5.82 +#define PHOTON_SCANCODE_G           0x22
    5.83 +#define PHOTON_SCANCODE_H           0x23
    5.84 +#define PHOTON_SCANCODE_J           0x24
    5.85 +#define PHOTON_SCANCODE_K           0x25
    5.86 +#define PHOTON_SCANCODE_L           0x26
    5.87 +#define PHOTON_SCANCODE_SEMICOLON   0x27
    5.88 +#define PHOTON_SCANCODE_QUOTE       0x28
    5.89 +#define PHOTON_SCANCODE_BACKSLASH   0x2B
    5.90 +
    5.91 +#define PHOTON_SCANCODE_LEFT_SHIFT  0x2A
    5.92 +#define PHOTON_SCANCODE_Z           0x2C
    5.93 +#define PHOTON_SCANCODE_X           0x2D
    5.94 +#define PHOTON_SCANCODE_C           0x2E
    5.95 +#define PHOTON_SCANCODE_V           0x2F
    5.96 +#define PHOTON_SCANCODE_B           0x30
    5.97 +#define PHOTON_SCANCODE_N           0x31
    5.98 +#define PHOTON_SCANCODE_M           0x32
    5.99 +#define PHOTON_SCANCODE_COMMA       0x33
   5.100 +#define PHOTON_SCANCODE_POINT       0x34
   5.101 +#define PHOTON_SCANCODE_SLASH       0x35
   5.102 +#define PHOTON_SCANCODE_RIGHT_SHIFT 0x36
   5.103 +
   5.104 +#define PHOTON_SCANCODE_CTRL        0x1D
   5.105 +#define PHOTON_SCANCODE_WFLAG       0x5B
   5.106 +#define PHOTON_SCANCODE_ALT         0x38
   5.107 +#define PHOTON_SCANCODE_SPACE       0x39
   5.108 +#define PHOTON_SCANCODE_MENU        0x5D
   5.109 +
   5.110 +#define PHOTON_SCANCODE_PRNSCR      0x54   /* only key pressed event, no release */
   5.111 +#define PHOTON_SCANCODE_SCROLLLOCK  0x46
   5.112 +/* #define PHOTON_SCANCODE_PAUSE 0x?? */   /* pause doesn't generates a scancode */
   5.113 +#define PHOTON_SCANCODE_INSERT      0x52
   5.114 +#define PHOTON_SCANCODE_HOME        0x47
   5.115 +#define PHOTON_SCANCODE_PAGEUP      0x49
   5.116 +#define PHOTON_SCANCODE_DELETE      0x53
   5.117 +#define PHOTON_SCANCODE_END         0x4F
   5.118 +#define PHOTON_SCANCODE_PAGEDOWN    0x51
   5.119 +#define PHOTON_SCANCODE_UP          0x48
   5.120 +#define PHOTON_SCANCODE_DOWN        0x50
   5.121 +#define PHOTON_SCANCODE_LEFT        0x4B
   5.122 +#define PHOTON_SCANCODE_RIGHT       0x4D
   5.123 +
   5.124 +#define PHOTON_SCANCODE_NUMLOCK     0x45
   5.125 +
   5.126 +#endif /* __SDL_PHOTON_KEYCODES_H__ */
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/video/photon/SDL_photon_pixelfmt.c	Tue Apr 28 04:30:52 2009 +0000
     6.3 @@ -0,0 +1,198 @@
     6.4 +/*
     6.5 +    SDL - Simple DirectMedia Layer
     6.6 +    Copyright (C) 1997-2009 Sam Lantinga
     6.7 +
     6.8 +    This library is free software; you can redistribute it and/or
     6.9 +    modify it under the terms of the GNU Lesser General Public
    6.10 +    License as published by the Free Software Foundation; either
    6.11 +    version 2.1 of the License, or (at your option) any later version.
    6.12 +
    6.13 +    This library is distributed in the hope that it will be useful,
    6.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 +    Lesser General Public License for more details.
    6.17 +
    6.18 +    You should have received a copy of the GNU Lesser General Public
    6.19 +    License along with this library; if not, write to the Free Software
    6.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    6.21 +
    6.22 +    Sam Lantinga
    6.23 +    slouken@libsdl.org
    6.24 +
    6.25 +    QNX Photon GUI SDL driver
    6.26 +    Copyright (C) 2009 Mike Gorchak
    6.27 +    (mike@malva.ua, lestat@i.com.ua)
    6.28 +*/
    6.29 +
    6.30 +#include "SDL_photon_pixelfmt.h"
    6.31 +
    6.32 +uint32_t photon_bits_to_sdl_pixelformat(uint32_t pixelfmt)
    6.33 +{
    6.34 +   switch(pixelfmt)
    6.35 +   {
    6.36 +      case 8:
    6.37 +           {
    6.38 +              return SDL_PIXELFORMAT_INDEX8;
    6.39 +           }
    6.40 +           break;
    6.41 +      case 15:
    6.42 +           {
    6.43 +              return SDL_PIXELFORMAT_ARGB1555;
    6.44 +           }
    6.45 +           break;
    6.46 +      case 16:
    6.47 +           {
    6.48 +              return SDL_PIXELFORMAT_RGB565;
    6.49 +           }
    6.50 +           break;
    6.51 +      case 24:
    6.52 +           {
    6.53 +              return SDL_PIXELFORMAT_RGB888;
    6.54 +           }
    6.55 +           break;
    6.56 +      case 32:
    6.57 +           {
    6.58 +              return SDL_PIXELFORMAT_ARGB8888;
    6.59 +           }
    6.60 +           break;
    6.61 +   }
    6.62 +}
    6.63 +
    6.64 +uint32_t photon_sdl_to_bits_pixelformat(uint32_t pixelfmt)
    6.65 +{
    6.66 +   switch(pixelfmt)
    6.67 +   {
    6.68 +      case SDL_PIXELFORMAT_INDEX8:
    6.69 +           {
    6.70 +              return 8;
    6.71 +           }
    6.72 +           break;
    6.73 +      case SDL_PIXELFORMAT_ARGB1555:
    6.74 +           {
    6.75 +              return 15;
    6.76 +           }
    6.77 +           break;
    6.78 +      case SDL_PIXELFORMAT_ABGR1555:
    6.79 +           {
    6.80 +              return 15;
    6.81 +           }
    6.82 +           break;
    6.83 +      case SDL_PIXELFORMAT_RGB565:
    6.84 +           {
    6.85 +              return 16;
    6.86 +           }
    6.87 +           break;
    6.88 +      case SDL_PIXELFORMAT_RGB888:
    6.89 +           {
    6.90 +              return 24;
    6.91 +           }
    6.92 +           break;
    6.93 +      case SDL_PIXELFORMAT_BGRA8888:
    6.94 +           {
    6.95 +              return 32;
    6.96 +           }
    6.97 +           break;
    6.98 +      case SDL_PIXELFORMAT_ARGB8888:
    6.99 +           {
   6.100 +              return 32;
   6.101 +           }
   6.102 +           break;
   6.103 +      case SDL_PIXELFORMAT_YV12:
   6.104 +           {
   6.105 +              return 8;
   6.106 +           }
   6.107 +           break;
   6.108 +      case SDL_PIXELFORMAT_YUY2:
   6.109 +           {
   6.110 +              return 16;
   6.111 +           }
   6.112 +           break;
   6.113 +      case SDL_PIXELFORMAT_UYVY:
   6.114 +           {
   6.115 +              return 16;
   6.116 +           }
   6.117 +           break;
   6.118 +      case SDL_PIXELFORMAT_YVYU:
   6.119 +           {
   6.120 +              return 16;
   6.121 +           }
   6.122 +           break;
   6.123 +   }
   6.124 +
   6.125 +   return 0;
   6.126 +}
   6.127 +
   6.128 +uint32_t photon_image_to_sdl_pixelformat(uint32_t pixelfmt)
   6.129 +{
   6.130 +   switch(pixelfmt)
   6.131 +   {
   6.132 +      case Pg_IMAGE_PALETTE_BYTE:
   6.133 +           {
   6.134 +              return SDL_PIXELFORMAT_INDEX8;
   6.135 +           }
   6.136 +           break;
   6.137 +      case Pg_IMAGE_DIRECT_8888:
   6.138 +           {
   6.139 +              return SDL_PIXELFORMAT_BGRA8888;
   6.140 +           }
   6.141 +           break;
   6.142 +      case Pg_IMAGE_DIRECT_888:
   6.143 +           {
   6.144 +              return SDL_PIXELFORMAT_RGB888;
   6.145 +           }
   6.146 +           break;
   6.147 +      case Pg_IMAGE_DIRECT_565:
   6.148 +           {
   6.149 +              return SDL_PIXELFORMAT_RGB565;
   6.150 +           }
   6.151 +           break;
   6.152 +      case Pg_IMAGE_DIRECT_555:
   6.153 +           {
   6.154 +              return SDL_PIXELFORMAT_RGB555;
   6.155 +           }
   6.156 +           break;
   6.157 +      case Pg_IMAGE_DIRECT_1555:
   6.158 +           {
   6.159 +              return SDL_PIXELFORMAT_ARGB1555;
   6.160 +           }
   6.161 +           break;
   6.162 +   }
   6.163 +
   6.164 +   return 0;
   6.165 +}
   6.166 +
   6.167 +uint32_t photon_sdl_to_image_pixelformat(uint32_t pixelfmt)
   6.168 +{
   6.169 +   switch(pixelfmt)
   6.170 +   {
   6.171 +      case SDL_PIXELFORMAT_INDEX8:
   6.172 +           {
   6.173 +              return Pg_IMAGE_PALETTE_BYTE;
   6.174 +           }
   6.175 +           break;
   6.176 +      case SDL_PIXELFORMAT_BGRA8888:
   6.177 +           {
   6.178 +              return Pg_IMAGE_DIRECT_8888;
   6.179 +           }
   6.180 +           break;
   6.181 +      case SDL_PIXELFORMAT_RGB888:
   6.182 +           {
   6.183 +              return Pg_IMAGE_DIRECT_888;
   6.184 +           }
   6.185 +           break;
   6.186 +      case SDL_PIXELFORMAT_RGB565:
   6.187 +           {
   6.188 +              return Pg_IMAGE_DIRECT_565;
   6.189 +           }
   6.190 +           break;
   6.191 +      case SDL_PIXELFORMAT_ARGB1555:
   6.192 +           {
   6.193 +              return Pg_IMAGE_DIRECT_1555;
   6.194 +           }
   6.195 +           break;
   6.196 +   }
   6.197 +
   6.198 +   return 0;
   6.199 +}
   6.200 +
   6.201 +/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/photon/SDL_photon_pixelfmt.h	Tue Apr 28 04:30:52 2009 +0000
     7.3 @@ -0,0 +1,42 @@
     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 +    QNX Photon GUI SDL driver
    7.26 +    Copyright (C) 2009 Mike Gorchak
    7.27 +    (mike@malva.ua, lestat@i.com.ua)
    7.28 +*/
    7.29 +
    7.30 +#include "SDL_config.h"
    7.31 +#include "../SDL_sysvideo.h"
    7.32 +
    7.33 +#include <Ph.h>
    7.34 +
    7.35 +#ifndef __SDL_PHOTON_PIXELFMT_H__
    7.36 +#define __SDL_PHOTON_PIXELFMT_H__
    7.37 +
    7.38 +uint32_t photon_bits_to_sdl_pixelformat(uint32_t pixelfmt);
    7.39 +uint32_t photon_sdl_to_bits_pixelformat(uint32_t pixelfmt);
    7.40 +uint32_t photon_image_to_sdl_pixelformat(uint32_t pixelfmt);
    7.41 +uint32_t photon_sdl_to_image_pixelformat(uint32_t pixelfmt);
    7.42 +
    7.43 +#endif /* __SDL_PHOTON_PIXELFMT_H__ */
    7.44 +
    7.45 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/video/photon/SDL_photon_render.c	Fri Apr 24 03:46:54 2009 +0000
     8.2 +++ b/src/video/photon/SDL_photon_render.c	Tue Apr 28 04:30:52 2009 +0000
     8.3 @@ -35,24 +35,24 @@
     8.4  #include "SDL_photon.h"
     8.5  
     8.6  static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags);
     8.7 -static int photon_displaymodechanged(SDL_Renderer* renderer);
     8.8 -static int photon_activaterenderer(SDL_Renderer* renderer);
     8.9 -static int photon_createtexture(SDL_Renderer* renderer, SDL_Texture* texture);
    8.10 -static int photon_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch);
    8.11 -static int photon_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors);
    8.12 -static int photon_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors);
    8.13 -static int photon_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture);
    8.14 -static int photon_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture);
    8.15 -static int photon_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture);
    8.16 -static int photon_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture);
    8.17 -static int photon_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch);
    8.18 -static int photon_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch);
    8.19 +static int  photon_displaymodechanged(SDL_Renderer* renderer);
    8.20 +static int  photon_activaterenderer(SDL_Renderer* renderer);
    8.21 +static int  photon_createtexture(SDL_Renderer* renderer, SDL_Texture* texture);
    8.22 +static int  photon_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch);
    8.23 +static int  photon_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors);
    8.24 +static int  photon_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors);
    8.25 +static int  photon_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture);
    8.26 +static int  photon_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture);
    8.27 +static int  photon_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture);
    8.28 +static int  photon_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture);
    8.29 +static int  photon_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch);
    8.30 +static int  photon_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch);
    8.31  static void photon_unlocktexture(SDL_Renderer* renderer, SDL_Texture* texture);
    8.32  static void photon_dirtytexture(SDL_Renderer* renderer, SDL_Texture* texture, int numrects, const SDL_Rect* rects);
    8.33 -static int photon_renderpoint(SDL_Renderer* renderer, int x, int y);
    8.34 -static int photon_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2);
    8.35 -static int photon_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect);
    8.36 -static int photon_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect);
    8.37 +static int  photon_renderpoint(SDL_Renderer* renderer, int x, int y);
    8.38 +static int  photon_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2);
    8.39 +static int  photon_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect);
    8.40 +static int  photon_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect);
    8.41  static void photon_renderpresent(SDL_Renderer* renderer);
    8.42  static void photon_destroytexture(SDL_Renderer* renderer, SDL_Texture* texture);
    8.43  static void photon_destroyrenderer(SDL_Renderer* renderer);