Support for HID devices (mice and keyboards only for now) has been added
authorMike Gorchak <lestat@i.com.ua>
Tue, 28 Apr 2009 04:33:30 +0000
changeset 31097b3a09fb9c8b
parent 3108 aa1897bee1e9
child 3110 e6c21c14ce3a
Support for HID devices (mice and keyboards only for now) has been added
src/video/qnxgf/SDL_gf_input.c
src/video/qnxgf/SDL_gf_input.h
src/video/qnxgf/SDL_gf_opengles.c
src/video/qnxgf/SDL_gf_opengles.h
src/video/qnxgf/SDL_gf_render.c
src/video/qnxgf/SDL_hiddi_joystick.h
src/video/qnxgf/SDL_hiddi_keyboard.h
src/video/qnxgf/SDL_hiddi_mouse.h
src/video/qnxgf/SDL_qnxgf.c
src/video/qnxgf/SDL_qnxgf.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/qnxgf/SDL_gf_input.c	Tue Apr 28 04:33:30 2009 +0000
     1.3 @@ -0,0 +1,1187 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2009 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +
    1.25 +    QNX Graphics Framework SDL driver
    1.26 +    Copyright (C) 2009 Mike Gorchak
    1.27 +    (mike@malva.ua, lestat@i.com.ua)
    1.28 +*/
    1.29 +
    1.30 +#include "SDL_gf_input.h"
    1.31 +
    1.32 +#include "SDL_config.h"
    1.33 +#include "SDL_events.h"
    1.34 +#include "../../events/SDL_mouse_c.h"
    1.35 +#include "../../events/SDL_keyboard_c.h"
    1.36 +
    1.37 +/* Include QNX HIDDI definitions */
    1.38 +#include "SDL_hiddi_keyboard.h"
    1.39 +#include "SDL_hiddi_mouse.h"
    1.40 +#include "SDL_hiddi_joystick.h"
    1.41 +
    1.42 +/* Mouse related functions */
    1.43 +SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y);
    1.44 +int  gf_showcursor(SDL_Cursor* cursor);
    1.45 +void gf_movecursor(SDL_Cursor* cursor);
    1.46 +void gf_freecursor(SDL_Cursor* cursor);
    1.47 +void gf_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y);
    1.48 +void gf_freemouse(SDL_Mouse* mouse);
    1.49 +
    1.50 +/* HIDDI interacting functions */
    1.51 +static int32_t hiddi_connect_devices();
    1.52 +static int32_t hiddi_disconnect_devices();
    1.53 +
    1.54 +int32_t gf_addinputdevices(_THIS)
    1.55 +{
    1.56 +   SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata;
    1.57 +   SDL_DisplayData* didata;
    1.58 +   struct SDL_Mouse gf_mouse;
    1.59 +   SDL_Keyboard gf_keyboard;
    1.60 +   SDLKey keymap[SDL_NUM_SCANCODES];
    1.61 +   SDL_MouseData* mdata;
    1.62 +   uint32_t it;
    1.63 +
    1.64 +   for (it=0; it<_this->num_displays; it++)
    1.65 +   {
    1.66 +      /* Clear SDL mouse structure */
    1.67 +      SDL_memset(&gf_mouse, 0x00, sizeof(struct SDL_Mouse));
    1.68 +
    1.69 +      /* Allocate SDL_MouseData structure */
    1.70 +      mdata=(SDL_MouseData*)SDL_calloc(1, sizeof(SDL_MouseData));
    1.71 +      if (mdata==NULL)
    1.72 +      {
    1.73 +         SDL_OutOfMemory();
    1.74 +         return -1;
    1.75 +      }
    1.76 +
    1.77 +      /* Mark this mouse with ID 0 */
    1.78 +      gf_mouse.id=it;
    1.79 +      gf_mouse.driverdata=(void*)mdata;
    1.80 +      gf_mouse.CreateCursor=gf_createcursor;
    1.81 +      gf_mouse.ShowCursor=gf_showcursor;
    1.82 +      gf_mouse.MoveCursor=gf_movecursor;
    1.83 +      gf_mouse.FreeCursor=gf_freecursor;
    1.84 +      gf_mouse.WarpMouse=gf_warpmouse;
    1.85 +      gf_mouse.FreeMouse=gf_freemouse;
    1.86 +
    1.87 +      /* Get display data */
    1.88 +      didata=(SDL_DisplayData*)_this->displays[it].driverdata;
    1.89 +
    1.90 +      /* Store SDL_DisplayData pointer in the mouse driver internals */
    1.91 +      mdata->didata=didata;
    1.92 +
    1.93 +      /* Set cursor pos to 0,0 to avoid cursor disappearing in some drivers */
    1.94 +      gf_cursor_set_pos(didata->display, 0, 0, 0);
    1.95 +
    1.96 +      /* Register mouse cursor in SDL */
    1.97 +      SDL_AddMouse(&gf_mouse, "GF mouse cursor", 0, 0, 1);
    1.98 +   }
    1.99 +
   1.100 +   /* Keyboard could be one only */
   1.101 +   SDL_zero(gf_keyboard);
   1.102 +   SDL_AddKeyboard(&gf_keyboard, -1);
   1.103 +
   1.104 +   /* Add scancode to key mapping, HIDDI uses USB HID codes, so */
   1.105 +   /* map will be exact one-to-one */
   1.106 +   SDL_GetDefaultKeymap(keymap);
   1.107 +   SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
   1.108 +
   1.109 +   /* Connect to HID server and enumerate all input devices */
   1.110 +   hiddi_connect_devices();
   1.111 +
   1.112 +   return 0;
   1.113 +}
   1.114 +
   1.115 +int32_t gf_delinputdevices(_THIS)
   1.116 +{
   1.117 +   /* Disconnect from HID server and release input devices */
   1.118 +   hiddi_disconnect_devices();
   1.119 +
   1.120 +   /* Delete keyboard */
   1.121 +   SDL_KeyboardQuit();
   1.122 +
   1.123 +   /* Destroy all of the mice */
   1.124 +   SDL_MouseQuit();
   1.125 +}
   1.126 +
   1.127 +/*****************************************************************************/
   1.128 +/* GF Mouse related functions                                                */
   1.129 +/*****************************************************************************/
   1.130 +SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y)
   1.131 +{
   1.132 +   gf_cursor_t* internal_cursor;
   1.133 +   SDL_Cursor*  sdl_cursor;
   1.134 +   uint8_t*     image0=NULL;
   1.135 +   uint8_t*     image1=NULL;
   1.136 +   uint32_t     it;
   1.137 +   uint32_t     jt;
   1.138 +   uint32_t     shape_color;
   1.139 +
   1.140 +   /* SDL converts monochrome cursor shape to 32bpp cursor shape      */
   1.141 +   /* and we must convert it back to monochrome, this routine handles */
   1.142 +   /* 24/32bpp surfaces only                                          */
   1.143 +   if ((surface->format->BitsPerPixel!=32) && (surface->format->BitsPerPixel!=24))
   1.144 +   {
   1.145 +      SDL_SetError("GF: Cursor shape is not 24/32bpp.");
   1.146 +      return NULL;
   1.147 +   }
   1.148 +
   1.149 +   /* Since GF is not checking data, we must check */
   1.150 +   if ((surface->w==0) || (surface->h==0))
   1.151 +   {
   1.152 +      SDL_SetError("GF: Cursor shape dimensions are zero");
   1.153 +      return NULL;
   1.154 +   }
   1.155 +
   1.156 +   /* Allocate memory for the internal cursor format */
   1.157 +   internal_cursor=(gf_cursor_t*)SDL_calloc(1, sizeof(gf_cursor_t));
   1.158 +   if (internal_cursor==NULL)
   1.159 +   {
   1.160 +      SDL_OutOfMemory();
   1.161 +      return NULL;
   1.162 +   }
   1.163 +
   1.164 +   /* Allocate memory for the SDL cursor */
   1.165 +   sdl_cursor=(SDL_Cursor*)SDL_calloc(1, sizeof(SDL_Cursor));
   1.166 +   if (sdl_cursor==NULL)
   1.167 +   {
   1.168 +      SDL_free(internal_cursor);
   1.169 +      SDL_OutOfMemory();
   1.170 +      return NULL;
   1.171 +   }
   1.172 +
   1.173 +   /* Allocate two monochrome images */
   1.174 +   image0=(uint8_t*)SDL_calloc(1, ((surface->w+7)/8)*surface->h);
   1.175 +   if (image0==NULL)
   1.176 +   {
   1.177 +      SDL_free(sdl_cursor);
   1.178 +      SDL_free(internal_cursor);
   1.179 +      SDL_OutOfMemory();
   1.180 +      return NULL;
   1.181 +   }
   1.182 +   image1=(uint8_t*)SDL_calloc(1, ((surface->w+7)>>3)*surface->h);
   1.183 +   if (image1==NULL)
   1.184 +   {
   1.185 +      SDL_free(image0);
   1.186 +      SDL_free(sdl_cursor);
   1.187 +      SDL_free(internal_cursor);
   1.188 +      SDL_OutOfMemory();
   1.189 +      return NULL;
   1.190 +   }
   1.191 +
   1.192 +   /* Set driverdata as GF cursor format */
   1.193 +   sdl_cursor->driverdata=(void*)internal_cursor;
   1.194 +   internal_cursor->type=GF_CURSOR_BITMAP;
   1.195 +   internal_cursor->hotspot.x=hot_x;
   1.196 +   internal_cursor->hotspot.y=hot_y;
   1.197 +   internal_cursor->cursor.bitmap.w=surface->w;
   1.198 +   internal_cursor->cursor.bitmap.h=surface->h;
   1.199 +   internal_cursor->cursor.bitmap.color0=SDL_GF_MOUSE_COLOR_BLACK;
   1.200 +   internal_cursor->cursor.bitmap.color1=SDL_GF_MOUSE_COLOR_WHITE;
   1.201 +
   1.202 +   /* Setup cursor shape images */
   1.203 +   internal_cursor->cursor.bitmap.stride=((surface->w+7)>>3);
   1.204 +   internal_cursor->cursor.bitmap.image0=image0;
   1.205 +   internal_cursor->cursor.bitmap.image1=image1;
   1.206 +
   1.207 +   /* Convert cursor from 32 bpp */
   1.208 +   for (jt=0; jt<surface->h; jt++)
   1.209 +   {
   1.210 +      for (it=0; it<surface->w; it++)
   1.211 +      {
   1.212 +         shape_color=*((uint32_t*)((uint8_t*)surface->pixels+jt*surface->pitch+it*surface->format->BytesPerPixel));
   1.213 +         switch(shape_color)
   1.214 +         {
   1.215 +            case SDL_GF_MOUSE_COLOR_BLACK:
   1.216 +                 {
   1.217 +                    *(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))|=0x80>>(it%8);
   1.218 +                    *(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8));
   1.219 +                 }
   1.220 +                 break;
   1.221 +            case SDL_GF_MOUSE_COLOR_WHITE:
   1.222 +                 {
   1.223 +                    *(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8));
   1.224 +                    *(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))|=0x80>>(it%8);
   1.225 +                 }
   1.226 +                 break;
   1.227 +            case SDL_GF_MOUSE_COLOR_TRANS:
   1.228 +                 {
   1.229 +                    *(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8));
   1.230 +                    *(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8));
   1.231 +                 }
   1.232 +                 break;
   1.233 +            default:
   1.234 +                 {
   1.235 +                    /* The same as transparent color, must not happen */
   1.236 +                    *(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8));
   1.237 +                    *(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8));
   1.238 +                 }
   1.239 +                 break;
   1.240 +         }
   1.241 +      }
   1.242 +   }
   1.243 +
   1.244 +   return sdl_cursor;
   1.245 +}
   1.246 +
   1.247 +int gf_showcursor(SDL_Cursor* cursor)
   1.248 +{
   1.249 +   SDL_VideoDisplay* display;
   1.250 +   SDL_DisplayData*  didata;
   1.251 +   SDL_Window*  window;
   1.252 +   SDL_WindowID window_id;
   1.253 +   gf_cursor_t* internal_cursor;
   1.254 +   int32_t status;
   1.255 +
   1.256 +   /* Get current window id */
   1.257 +   window_id=SDL_GetFocusWindow();
   1.258 +   if (window_id<=0)
   1.259 +   {
   1.260 +      SDL_MouseData* mdata=NULL;
   1.261 +
   1.262 +      /* If there is no current window, then someone calls this function */
   1.263 +      /* to set global mouse settings during SDL initialization          */
   1.264 +      if (cursor!=NULL)
   1.265 +      {
   1.266 +         mdata=(SDL_MouseData*)cursor->mouse->driverdata;
   1.267 +         didata=(SDL_DisplayData*)mdata->didata;
   1.268 +      }
   1.269 +      else
   1.270 +      {
   1.271 +         /* We can't get SDL_DisplayData at this point, return fake success */
   1.272 +         return 0;
   1.273 +      }
   1.274 +   }
   1.275 +   else
   1.276 +   {
   1.277 +      /* Sanity checks */
   1.278 +      window=SDL_GetWindowFromID(window_id);
   1.279 +      if (window!=NULL)
   1.280 +      {
   1.281 +         display=SDL_GetDisplayFromWindow(window);
   1.282 +         if (display!=NULL)
   1.283 +         {
   1.284 +            didata=(SDL_DisplayData*)display->driverdata;
   1.285 +            if (didata==NULL)
   1.286 +            {
   1.287 +               return -1;
   1.288 +            }
   1.289 +         }
   1.290 +         else
   1.291 +         {
   1.292 +            return -1;
   1.293 +         }
   1.294 +      }
   1.295 +      else
   1.296 +      {
   1.297 +         return -1;
   1.298 +      }
   1.299 +   }
   1.300 +
   1.301 +   /* Check if we need to set new shape or disable cursor shape */
   1.302 +   if (cursor!=NULL)
   1.303 +   {
   1.304 +      /* Retrieve GF cursor shape */
   1.305 +      internal_cursor=(gf_cursor_t*)cursor->driverdata;
   1.306 +      if (internal_cursor==NULL)
   1.307 +      {
   1.308 +         SDL_SetError("GF: Internal cursor data is absent");
   1.309 +         return -1;
   1.310 +      }
   1.311 +      if ((internal_cursor->cursor.bitmap.image0==NULL) ||
   1.312 +          (internal_cursor->cursor.bitmap.image1==NULL))
   1.313 +      {
   1.314 +         SDL_SetError("GF: Cursor shape is absent");
   1.315 +         return -1;
   1.316 +      }
   1.317 +
   1.318 +      /* Store last shown cursor to display data */
   1.319 +      didata->cursor.type=internal_cursor->type;
   1.320 +      didata->cursor.hotspot.x=internal_cursor->hotspot.x;
   1.321 +      didata->cursor.hotspot.y=internal_cursor->hotspot.y;
   1.322 +      if (internal_cursor->cursor.bitmap.w>SDL_VIDEO_GF_MAX_CURSOR_SIZE)
   1.323 +      {
   1.324 +         didata->cursor.cursor.bitmap.w=SDL_VIDEO_GF_MAX_CURSOR_SIZE;
   1.325 +      }
   1.326 +      else
   1.327 +      {
   1.328 +         didata->cursor.cursor.bitmap.w=internal_cursor->cursor.bitmap.w;
   1.329 +      }
   1.330 +
   1.331 +      if (didata->cursor.cursor.bitmap.h>SDL_VIDEO_GF_MAX_CURSOR_SIZE)
   1.332 +      {
   1.333 +         didata->cursor.cursor.bitmap.h=SDL_VIDEO_GF_MAX_CURSOR_SIZE;
   1.334 +      }
   1.335 +      else
   1.336 +      {
   1.337 +         didata->cursor.cursor.bitmap.h=internal_cursor->cursor.bitmap.h;
   1.338 +      }
   1.339 +
   1.340 +      didata->cursor.cursor.bitmap.color0=internal_cursor->cursor.bitmap.color0;
   1.341 +      didata->cursor.cursor.bitmap.color1=internal_cursor->cursor.bitmap.color1;
   1.342 +      didata->cursor.cursor.bitmap.stride=internal_cursor->cursor.bitmap.stride;
   1.343 +      SDL_memcpy(didata->cursor.cursor.bitmap.image0,
   1.344 +                internal_cursor->cursor.bitmap.image0,
   1.345 +                ((internal_cursor->cursor.bitmap.w+7)/(sizeof(uint8_t)*8))*internal_cursor->cursor.bitmap.h);
   1.346 +      SDL_memcpy(didata->cursor.cursor.bitmap.image1,
   1.347 +                internal_cursor->cursor.bitmap.image1,
   1.348 +                ((internal_cursor->cursor.bitmap.w+7)/(sizeof(uint8_t)*8))*internal_cursor->cursor.bitmap.h);
   1.349 +
   1.350 +      /* Setup cursor shape */
   1.351 +      status=gf_cursor_set(didata->display, 0, internal_cursor);
   1.352 +      if (status!=GF_ERR_OK)
   1.353 +      {
   1.354 +         if (status!=GF_ERR_NOSUPPORT)
   1.355 +         {
   1.356 +            SDL_SetError("GF: Can't set hardware cursor shape");
   1.357 +            return -1;
   1.358 +         }
   1.359 +      }
   1.360 +
   1.361 +      /* Enable just set cursor */
   1.362 +      status=gf_cursor_enable(didata->display, 0);
   1.363 +      if (status!=GF_ERR_OK)
   1.364 +      {
   1.365 +         if (status!=GF_ERR_NOSUPPORT)
   1.366 +         {
   1.367 +            SDL_SetError("GF: Can't enable hardware cursor");
   1.368 +            return -1;
   1.369 +         }
   1.370 +      }
   1.371 +
   1.372 +      /* Set cursor visible */
   1.373 +      didata->cursor_visible=SDL_TRUE;
   1.374 +   }
   1.375 +   else
   1.376 +   {
   1.377 +      /* SDL requests to disable cursor */
   1.378 +      status=gf_cursor_disable(didata->display, 0);
   1.379 +      if (status!=GF_ERR_OK)
   1.380 +      {
   1.381 +         if (status!=GF_ERR_NOSUPPORT)
   1.382 +         {
   1.383 +            SDL_SetError("GF: Can't disable hardware cursor");
   1.384 +            return -1;
   1.385 +         }
   1.386 +      }
   1.387 +
   1.388 +      /* Set cursor invisible */
   1.389 +      didata->cursor_visible=SDL_FALSE;
   1.390 +   }
   1.391 +
   1.392 +   /* New cursor shape is set */
   1.393 +   return 0;
   1.394 +}
   1.395 +
   1.396 +void gf_movecursor(SDL_Cursor* cursor)
   1.397 +{
   1.398 +   SDL_VideoDisplay* display;
   1.399 +   SDL_DisplayData*  didata;
   1.400 +   SDL_Window*  window;
   1.401 +   SDL_WindowID window_id;
   1.402 +   int32_t status;
   1.403 +   uint32_t xmax;
   1.404 +   uint32_t ymax;
   1.405 +
   1.406 +   /* Get current window id */
   1.407 +   window_id=SDL_GetFocusWindow();
   1.408 +   if (window_id<=0)
   1.409 +   {
   1.410 +      didata=(SDL_DisplayData*)cursor->mouse->driverdata;
   1.411 +   }
   1.412 +   else
   1.413 +   {
   1.414 +      /* Sanity checks */
   1.415 +      window=SDL_GetWindowFromID(window_id);
   1.416 +      if (window!=NULL)
   1.417 +      {
   1.418 +         display=SDL_GetDisplayFromWindow(window);
   1.419 +         if (display!=NULL)
   1.420 +         {
   1.421 +            didata=(SDL_DisplayData*)display->driverdata;
   1.422 +            if (didata==NULL)
   1.423 +            {
   1.424 +               return;
   1.425 +            }
   1.426 +         }
   1.427 +         else
   1.428 +         {
   1.429 +            return;
   1.430 +         }
   1.431 +      }
   1.432 +      else
   1.433 +      {
   1.434 +         return;
   1.435 +      }
   1.436 +   }
   1.437 +
   1.438 +   /* Add checks for out of screen bounds position */
   1.439 +   if (cursor->mouse->x<0)
   1.440 +   {
   1.441 +      cursor->mouse->x=0;
   1.442 +   }
   1.443 +   if (cursor->mouse->y<0)
   1.444 +   {
   1.445 +      cursor->mouse->y=0;
   1.446 +   }
   1.447 +
   1.448 +   /* Get window size to clamp maximum coordinates */
   1.449 +   SDL_GetWindowSize(window_id, &xmax, &ymax);
   1.450 +   if (cursor->mouse->x>=xmax)
   1.451 +   {
   1.452 +      cursor->mouse->x=xmax-1;
   1.453 +   }
   1.454 +   if (cursor->mouse->y>=ymax)
   1.455 +   {
   1.456 +      cursor->mouse->y=ymax-1;
   1.457 +   }
   1.458 +
   1.459 +   status=gf_cursor_set_pos(didata->display, 0, cursor->mouse->x, cursor->mouse->y);
   1.460 +   if (status!=GF_ERR_OK)
   1.461 +   {
   1.462 +      if (status!=GF_ERR_NOSUPPORT)
   1.463 +      {
   1.464 +         SDL_SetError("GF: Can't set hardware cursor position");
   1.465 +         return;
   1.466 +      }
   1.467 +   }
   1.468 +}
   1.469 +
   1.470 +void gf_freecursor(SDL_Cursor* cursor)
   1.471 +{
   1.472 +   gf_cursor_t* internal_cursor;
   1.473 +
   1.474 +   if (cursor!=NULL)
   1.475 +   {
   1.476 +      internal_cursor=(gf_cursor_t*)cursor->driverdata;
   1.477 +      if (internal_cursor!=NULL)
   1.478 +      {
   1.479 +         if (internal_cursor->cursor.bitmap.image0!=NULL)
   1.480 +         {
   1.481 +            SDL_free((uint8_t*)internal_cursor->cursor.bitmap.image0);
   1.482 +         }
   1.483 +         if (internal_cursor->cursor.bitmap.image1!=NULL)
   1.484 +         {
   1.485 +            SDL_free((uint8_t*)internal_cursor->cursor.bitmap.image1);
   1.486 +         }
   1.487 +         SDL_free(internal_cursor);
   1.488 +      }
   1.489 +   }
   1.490 +}
   1.491 +
   1.492 +void gf_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y)
   1.493 +{
   1.494 +   SDL_VideoDisplay* display;
   1.495 +   SDL_DisplayData*  didata;
   1.496 +   SDL_Window* window;
   1.497 +   uint32_t xmax;
   1.498 +   uint32_t ymax;
   1.499 +   int32_t  status;
   1.500 +
   1.501 +   /* Sanity checks */
   1.502 +   window=SDL_GetWindowFromID(windowID);
   1.503 +   if (window!=NULL)
   1.504 +   {
   1.505 +      display=SDL_GetDisplayFromWindow(window);
   1.506 +      if (display!=NULL)
   1.507 +      {
   1.508 +         didata=(SDL_DisplayData*)display->driverdata;
   1.509 +         if (didata==NULL)
   1.510 +         {
   1.511 +            return;
   1.512 +         }
   1.513 +      }
   1.514 +      else
   1.515 +      {
   1.516 +         return;
   1.517 +      }
   1.518 +   }
   1.519 +   else
   1.520 +   {
   1.521 +      return;
   1.522 +   }
   1.523 +
   1.524 +   /* Add checks for out of screen bounds position */
   1.525 +   if (x<0)
   1.526 +   {
   1.527 +      x=0;
   1.528 +   }
   1.529 +   if (y<0)
   1.530 +   {
   1.531 +      y=0;
   1.532 +   }
   1.533 +
   1.534 +   /* Get window size to clamp maximum coordinates */
   1.535 +   SDL_GetWindowSize(windowID, &xmax, &ymax);
   1.536 +   if (x>=xmax)
   1.537 +   {
   1.538 +      x=xmax-1;
   1.539 +   }
   1.540 +   if (y>=ymax)
   1.541 +   {
   1.542 +      y=ymax-1;
   1.543 +   }
   1.544 +
   1.545 +   status=gf_cursor_set_pos(didata->display, 0, x, y);
   1.546 +   if (status!=GF_ERR_OK)
   1.547 +   {
   1.548 +      if (status!=GF_ERR_NOSUPPORT)
   1.549 +      {
   1.550 +         SDL_SetError("GF: Can't set hardware cursor position");
   1.551 +         return;
   1.552 +      }
   1.553 +   }
   1.554 +}
   1.555 +
   1.556 +void gf_freemouse(SDL_Mouse* mouse)
   1.557 +{
   1.558 +   if (mouse->driverdata==NULL)
   1.559 +   {
   1.560 +      return;
   1.561 +   }
   1.562 +
   1.563 +   /* Mouse framework doesn't deletes automatically our driverdata */
   1.564 +   SDL_free(mouse->driverdata);
   1.565 +   mouse->driverdata=NULL;
   1.566 +
   1.567 +   return;
   1.568 +}
   1.569 +
   1.570 +/*****************************************************************************/
   1.571 +/* HIDDI handlers code                                                       */
   1.572 +/*****************************************************************************/
   1.573 +static key_packet key_last_state[SDL_HIDDI_MAX_DEVICES];
   1.574 +
   1.575 +static void hiddi_keyboard_handler(uint32_t devno, uint8_t* report_data, uint32_t report_len)
   1.576 +{
   1.577 +   key_packet* packet;
   1.578 +   uint32_t    it;
   1.579 +   uint32_t    jt;
   1.580 +
   1.581 +   packet=(key_packet*)report_data;
   1.582 +
   1.583 +   /* Check for special states */
   1.584 +   switch (report_len)
   1.585 +   {
   1.586 +      case 8:   /* 8 bytes of report length */
   1.587 +           {
   1.588 +              for (it=0; it<6; it++)
   1.589 +              {
   1.590 +                 /* Check for keyboard overflow, when it can't handle */
   1.591 +                 /* many simultaneous pressed keys */
   1.592 +                 if (packet->codes[it]==HIDDI_KEY_OVERFLOW)
   1.593 +                 {
   1.594 +                    return;
   1.595 +                 }
   1.596 +              }
   1.597 +           }
   1.598 +           break;
   1.599 +      default:
   1.600 +           {
   1.601 +              /* Do not process unknown reports */
   1.602 +              return;
   1.603 +           }
   1.604 +           break;
   1.605 +   }
   1.606 +
   1.607 +   /* Check if modifier key was pressed */
   1.608 +   if (packet->modifiers!=key_last_state[devno].modifiers)
   1.609 +   {
   1.610 +      if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL)==HIDDI_MKEY_LEFT_CTRL) &&
   1.611 +         (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL)==0)
   1.612 +      {
   1.613 +         /* Left Ctrl key was pressed */
   1.614 +         SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LCTRL);
   1.615 +      }
   1.616 +      if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL)==0) &&
   1.617 +         (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL)==HIDDI_MKEY_LEFT_CTRL)
   1.618 +      {
   1.619 +         /* Left Ctrl key was released */
   1.620 +         SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LCTRL);
   1.621 +      }
   1.622 +      if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT)==HIDDI_MKEY_LEFT_SHIFT) &&
   1.623 +         (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT)==0)
   1.624 +      {
   1.625 +         /* Left Shift key was pressed */
   1.626 +         SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LSHIFT);
   1.627 +      }
   1.628 +      if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT)==0) &&
   1.629 +         (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT)==HIDDI_MKEY_LEFT_SHIFT)
   1.630 +      {
   1.631 +         /* Left Shift key was released */
   1.632 +         SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LSHIFT);
   1.633 +      }
   1.634 +      if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT)==HIDDI_MKEY_LEFT_ALT) &&
   1.635 +         (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT)==0)
   1.636 +      {
   1.637 +         /* Left Alt key was pressed */
   1.638 +         SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LALT);
   1.639 +      }
   1.640 +      if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT)==0) &&
   1.641 +         (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT)==HIDDI_MKEY_LEFT_ALT)
   1.642 +      {
   1.643 +         /* Left Alt key was released */
   1.644 +         SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LALT);
   1.645 +      }
   1.646 +      if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG)==HIDDI_MKEY_LEFT_WFLAG) &&
   1.647 +         (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG)==0)
   1.648 +      {
   1.649 +         /* Left Windows flag key was pressed */
   1.650 +         SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LGUI);
   1.651 +      }
   1.652 +      if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG)==0) &&
   1.653 +         (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG)==HIDDI_MKEY_LEFT_WFLAG)
   1.654 +      {
   1.655 +         /* Left Windows flag key was released */
   1.656 +         SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LGUI);
   1.657 +      }
   1.658 +      if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL)==HIDDI_MKEY_RIGHT_CTRL) &&
   1.659 +         (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL)==0)
   1.660 +      {
   1.661 +         /* Right Ctrl key was pressed */
   1.662 +         SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RCTRL);
   1.663 +      }
   1.664 +      if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL)==0) &&
   1.665 +         (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL)==HIDDI_MKEY_RIGHT_CTRL)
   1.666 +      {
   1.667 +         /* Right Ctrl key was released */
   1.668 +         SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RCTRL);
   1.669 +      }
   1.670 +      if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT)==HIDDI_MKEY_RIGHT_SHIFT) &&
   1.671 +         (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT)==0)
   1.672 +      {
   1.673 +         /* Right Shift key was pressed */
   1.674 +         SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RSHIFT);
   1.675 +      }
   1.676 +      if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT)==0) &&
   1.677 +         (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT)==HIDDI_MKEY_RIGHT_SHIFT)
   1.678 +      {
   1.679 +         /* Right Shift key was released */
   1.680 +         SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RSHIFT);
   1.681 +      }
   1.682 +      if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT)==HIDDI_MKEY_RIGHT_ALT) &&
   1.683 +         (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT)==0)
   1.684 +      {
   1.685 +         /* Right Alt key was pressed */
   1.686 +         SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RALT);
   1.687 +      }
   1.688 +      if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT)==0) &&
   1.689 +         (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT)==HIDDI_MKEY_RIGHT_ALT)
   1.690 +      {
   1.691 +         /* Right Alt key was released */
   1.692 +         SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RALT);
   1.693 +      }
   1.694 +      if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG)==HIDDI_MKEY_RIGHT_WFLAG) &&
   1.695 +         (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG)==0)
   1.696 +      {
   1.697 +         /* Right Windows flag key was pressed */
   1.698 +         SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RGUI);
   1.699 +      }
   1.700 +      if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG)==0) &&
   1.701 +         (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG)==HIDDI_MKEY_RIGHT_WFLAG)
   1.702 +      {
   1.703 +         /* Right Windows flag key was released */
   1.704 +         SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RGUI);
   1.705 +      }
   1.706 +   }
   1.707 +
   1.708 +   /* Check each key in the press/release buffer */
   1.709 +   switch (report_len)
   1.710 +   {
   1.711 +      case 8:   /* 8 bytes of report length */
   1.712 +           {
   1.713 +              /* Check if at least one key was unpressed */
   1.714 +              for (it=0; it<6; it++)
   1.715 +              {
   1.716 +                 if (key_last_state[devno].codes[it]==HIDDI_KEY_UNPRESSED)
   1.717 +                 {
   1.718 +                    /* if stored keycode is zero, find another */
   1.719 +                    continue;
   1.720 +                 }
   1.721 +                 for (jt=0; jt<6; jt++)
   1.722 +                 {
   1.723 +                    /* Find stored keycode in the current pressed codes */
   1.724 +                    if (packet->codes[jt]==key_last_state[devno].codes[it])
   1.725 +                    {
   1.726 +                       /* If found then particular key state is not changed */
   1.727 +                       break;
   1.728 +                    }
   1.729 +                 }
   1.730 +
   1.731 +                 /* Check if pressed key can't longer be found */
   1.732 +                 if (jt==6)
   1.733 +                 {
   1.734 +                    SDL_SendKeyboardKey(0, SDL_RELEASED, key_last_state[devno].codes[it]);
   1.735 +                 }
   1.736 +              }
   1.737 +
   1.738 +              /* Check if at least one new key was pressed */
   1.739 +              for (it=0; it<6; it++)
   1.740 +              {
   1.741 +                 if (packet->codes[it]==HIDDI_KEY_UNPRESSED)
   1.742 +                 {
   1.743 +                    continue;
   1.744 +                 }
   1.745 +                 for (jt=0; jt<6; jt++)
   1.746 +                 {
   1.747 +                    /* Find new keycode it the array of old pressed keys */
   1.748 +                    if (packet->codes[it]==key_last_state[devno].codes[jt])
   1.749 +                    {
   1.750 +                       break;
   1.751 +                    }
   1.752 +                 }
   1.753 +
   1.754 +                 /* Check if new key was pressed */
   1.755 +                 if (jt==6)
   1.756 +                 {
   1.757 +                    SDL_SendKeyboardKey(0, SDL_PRESSED, packet->codes[it]);
   1.758 +                 }
   1.759 +              }
   1.760 +           }
   1.761 +      default:  /* unknown keyboard report type */
   1.762 +           {
   1.763 +              /* Ignore all unknown reports */
   1.764 +           }
   1.765 +           break;
   1.766 +   }
   1.767 +
   1.768 +   /* Store last state */
   1.769 +   key_last_state[devno]=*packet;
   1.770 +}
   1.771 +
   1.772 +static uint32_t mouse_last_state_button[SDL_HIDDI_MAX_DEVICES];
   1.773 +static uint32_t collect_reports=0;
   1.774 +
   1.775 +static void hiddi_mouse_handler(uint32_t devno, uint8_t* report_data, uint32_t report_len)
   1.776 +{
   1.777 +   uint32_t it;
   1.778 +   uint32_t sdlbutton;
   1.779 +
   1.780 +   /* We do not want to collect stored events */
   1.781 +   if (collect_reports==0)
   1.782 +   {
   1.783 +      return;
   1.784 +   }
   1.785 +
   1.786 +   /* Check for special states */
   1.787 +   switch (report_len)
   1.788 +   {
   1.789 +      case 8:   /* 8 bytes of report length, usually multi-button USB mice */
   1.790 +           {
   1.791 +              mouse_packet8* packet;
   1.792 +              packet=(mouse_packet8*)report_data;
   1.793 +
   1.794 +              /* Send motion event if motion really was */
   1.795 +              if ((packet->horizontal_precision!=0) || (packet->vertical_precision!=0))
   1.796 +              {
   1.797 +                 SDL_SendMouseMotion(0, 1, packet->horizontal_precision, packet->vertical_precision, 0);
   1.798 +              }
   1.799 +
   1.800 +              /* Send mouse button press/release events */
   1.801 +              if (mouse_last_state_button[devno]!=packet->buttons)
   1.802 +              {
   1.803 +                 /* Cycle all buttons status */
   1.804 +                 for (it=0; it<8; it++)
   1.805 +                 {
   1.806 +                    /* convert hiddi button id to sdl button id */
   1.807 +                    switch(it)
   1.808 +                    {
   1.809 +                       case 0:
   1.810 +                            {
   1.811 +                               sdlbutton=SDL_BUTTON_LEFT;
   1.812 +                            }
   1.813 +                            break;
   1.814 +                       case 1:
   1.815 +                            {
   1.816 +                               sdlbutton=SDL_BUTTON_RIGHT;
   1.817 +                            }
   1.818 +                            break;
   1.819 +                       case 2:
   1.820 +                            {
   1.821 +                               sdlbutton=SDL_BUTTON_MIDDLE;
   1.822 +                            }
   1.823 +                            break;
   1.824 +                       default:
   1.825 +                            {
   1.826 +                               sdlbutton=it+1;
   1.827 +                            }
   1.828 +                            break;
   1.829 +                    }
   1.830 +
   1.831 +                    /* Button pressed */
   1.832 +                    if (((packet->buttons & (0x01<<it))==(0x01<<it)) &&
   1.833 +                        ((mouse_last_state_button[devno] & (0x01<<it))==0x00))
   1.834 +                    {
   1.835 +                       SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton);
   1.836 +                    }
   1.837 +                    /* Button released */
   1.838 +                    if (((packet->buttons & (0x01<<it))==0x00) &&
   1.839 +                        ((mouse_last_state_button[devno] & (0x01<<it))==(0x01<<it)))
   1.840 +                    {
   1.841 +                       SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
   1.842 +                    }
   1.843 +                 }
   1.844 +                 mouse_last_state_button[devno]=packet->buttons;
   1.845 +              }
   1.846 +
   1.847 +              /* Send mouse wheel events */
   1.848 +              if (packet->wheel!=0)
   1.849 +              {
   1.850 +                 /* Send vertical wheel event only */
   1.851 +                 SDL_SendMouseWheel(0, 0, packet->wheel);
   1.852 +              }
   1.853 +           }
   1.854 +           break;
   1.855 +      case 4:   /* 4 bytes of report length, usually PS/2 mice */
   1.856 +           {
   1.857 +              mouse_packet4* packet;
   1.858 +              packet=(mouse_packet4*)report_data;
   1.859 +
   1.860 +              /* Send motion event if motion really was */
   1.861 +              if ((packet->horizontal!=0) || (packet->vertical!=0))
   1.862 +              {
   1.863 +                 SDL_SendMouseMotion(0, 1, packet->horizontal, packet->vertical, 0);
   1.864 +              }
   1.865 +
   1.866 +              /* Send mouse button press/release events */
   1.867 +              if (mouse_last_state_button[devno]!=packet->buttons)
   1.868 +              {
   1.869 +                 /* Cycle all buttons status */
   1.870 +                 for (it=0; it<8; it++)
   1.871 +                 {
   1.872 +                    /* convert hiddi button id to sdl button id */
   1.873 +                    switch(it)
   1.874 +                    {
   1.875 +                       case 0:
   1.876 +                            {
   1.877 +                               sdlbutton=SDL_BUTTON_LEFT;
   1.878 +                            }
   1.879 +                            break;
   1.880 +                       case 1:
   1.881 +                            {
   1.882 +                               sdlbutton=SDL_BUTTON_RIGHT;
   1.883 +                            }
   1.884 +                            break;
   1.885 +                       case 2:
   1.886 +                            {
   1.887 +                               sdlbutton=SDL_BUTTON_MIDDLE;
   1.888 +                            }
   1.889 +                            break;
   1.890 +                       default:
   1.891 +                            {
   1.892 +                               sdlbutton=it+1;
   1.893 +                            }
   1.894 +                            break;
   1.895 +                    }
   1.896 +
   1.897 +                    /* Button pressed */
   1.898 +                    if (((packet->buttons & (0x01<<it))==(0x01<<it)) &&
   1.899 +                        ((mouse_last_state_button[devno] & (0x01<<it))==0x00))
   1.900 +                    {
   1.901 +                       SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton);
   1.902 +                    }
   1.903 +                    /* Button released */
   1.904 +                    if (((packet->buttons & (0x01<<it))==0x00) &&
   1.905 +                        ((mouse_last_state_button[devno] & (0x01<<it))==(0x01<<it)))
   1.906 +                    {
   1.907 +                       SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
   1.908 +                    }
   1.909 +                 }
   1.910 +                 mouse_last_state_button[devno]=packet->buttons;
   1.911 +              }
   1.912 +
   1.913 +              /* Send mouse wheel events */
   1.914 +              if (packet->wheel!=0)
   1.915 +              {
   1.916 +                 /* Send vertical wheel event only */
   1.917 +                 SDL_SendMouseWheel(0, 0, packet->wheel);
   1.918 +              }
   1.919 +           }
   1.920 +           break;
   1.921 +   }
   1.922 +}
   1.923 +
   1.924 +/*****************************************************************************/
   1.925 +/* HIDDI interacting code                                                    */
   1.926 +/*****************************************************************************/
   1.927 +static hidd_device_ident_t hiddevice=
   1.928 +{
   1.929 +   HIDD_CONNECT_WILDCARD,  /* vendor id:  any */
   1.930 +   HIDD_CONNECT_WILDCARD,  /* product id: any */
   1.931 +   HIDD_CONNECT_WILDCARD,  /* version:    any */
   1.932 +};
   1.933 +
   1.934 +static hidd_connect_parm_t hidparams={NULL, HID_VERSION, HIDD_VERSION, 0, 0, &hiddevice, NULL, 0};
   1.935 +
   1.936 +static void hiddi_insertion(struct hidd_connection* connection, hidd_device_instance_t* device_instance);
   1.937 +static void hiddi_removal(struct hidd_connection* connection, hidd_device_instance_t* instance);
   1.938 +static void hiddi_report(struct hidd_connection* connection, struct hidd_report* report, void* report_data, uint32_t report_len, uint32_t flags, void* user);
   1.939 +
   1.940 +static hidd_funcs_t hidfuncs={_HIDDI_NFUNCS, hiddi_insertion, hiddi_removal, hiddi_report, NULL};
   1.941 +
   1.942 +/* HID handle, singletone */
   1.943 +struct hidd_connection* connection=NULL;
   1.944 +
   1.945 +/* SDL detected input device types, singletone */
   1.946 +static uint32_t sdl_input_devices[SDL_HIDDI_MAX_DEVICES];
   1.947 +
   1.948 +static int hiddi_register_for_reports(struct hidd_collection* col, hidd_device_instance_t* device_instance)
   1.949 +{
   1.950 +   int it;
   1.951 +   uint16_t num_col;
   1.952 +   struct hidd_collection** hidd_collections;
   1.953 +   struct hidd_report_instance* report_instance;
   1.954 +   struct hidd_report* report;
   1.955 +   int status=0;
   1.956 +   hidview_device_t* device;
   1.957 +
   1.958 +   for (it=0 ; it<10 && !status; it++)
   1.959 +   {
   1.960 +      status=hidd_get_report_instance(col, it, HID_INPUT_REPORT, &report_instance);
   1.961 +      if (status==EOK)
   1.962 +      {
   1.963 +         status=hidd_report_attach(connection, device_instance, report_instance, 0, sizeof(hidview_device_t), &report);
   1.964 +         if (status==EOK)
   1.965 +         {
   1.966 +            device=hidd_report_extra(report);
   1.967 +            device->report=report;
   1.968 +            device->instance=report_instance;
   1.969 +         }
   1.970 +      }
   1.971 +   }
   1.972 +   hidd_get_collections(NULL, col, &hidd_collections, &num_col);
   1.973 +
   1.974 +   for (it=0; it<num_col; it++)
   1.975 +   {
   1.976 +      hiddi_register_for_reports(hidd_collections[it], device_instance);
   1.977 +   }
   1.978 +
   1.979 +   return EOK;
   1.980 +}
   1.981 +
   1.982 +static void hiddi_insertion(struct hidd_connection* connection, hidd_device_instance_t* device_instance)
   1.983 +{
   1.984 +   uint32_t it;
   1.985 +   struct hidd_collection** hidd_collections;
   1.986 +   uint16_t num_col;
   1.987 +
   1.988 +   /* get root level collections */
   1.989 +   hidd_get_collections(device_instance, NULL, &hidd_collections, &num_col);
   1.990 +   for (it=0; it<num_col; it++)
   1.991 +   {
   1.992 +      hiddi_register_for_reports(hidd_collections[it], device_instance);
   1.993 +   }
   1.994 +}
   1.995 +
   1.996 +static void hiddi_removal(struct hidd_connection* connection, hidd_device_instance_t* instance)
   1.997 +{
   1.998 +   hidd_reports_detach(connection, instance);
   1.999 +}
  1.1000 +
  1.1001 +static void hiddi_report(struct hidd_connection* connection, hidd_report_t* report, void* report_data, uint32_t report_len, uint32_t flags, void* user)
  1.1002 +{
  1.1003 +   if (report->dev_inst->devno>=SDL_HIDDI_MAX_DEVICES)
  1.1004 +   {
  1.1005 +      /* Unknown HID device, with devno number out of supported range */
  1.1006 +      return;
  1.1007 +   }
  1.1008 +
  1.1009 +   /* Check device type which generates event */
  1.1010 +   switch (sdl_input_devices[report->dev_inst->devno])
  1.1011 +   {
  1.1012 +      case SDL_GF_HIDDI_NONE:
  1.1013 +           {
  1.1014 +              /* We do not handle other devices type*/
  1.1015 +              return;
  1.1016 +           }
  1.1017 +           break;
  1.1018 +      case SDL_GF_HIDDI_MOUSE:
  1.1019 +           {
  1.1020 +              /* Call mouse handler */
  1.1021 +              hiddi_mouse_handler(report->dev_inst->devno, report_data, report_len);
  1.1022 +           }
  1.1023 +           break;
  1.1024 +      case SDL_GF_HIDDI_KEYBOARD:
  1.1025 +           {
  1.1026 +              /* Call keyboard handler */
  1.1027 +              hiddi_keyboard_handler(report->dev_inst->devno, report_data, report_len);
  1.1028 +           }
  1.1029 +           break;
  1.1030 +      case SDL_GF_HIDDI_JOYSTICK:
  1.1031 +           {
  1.1032 +              /* Call joystick handler */
  1.1033 +           }
  1.1034 +           break;
  1.1035 +   }
  1.1036 +}
  1.1037 +
  1.1038 +static hiddi_get_device_type(uint8_t* report_data, uint16_t report_length)
  1.1039 +{
  1.1040 +   hid_byte_t  byte;
  1.1041 +   uint16_t    usage_page=0;
  1.1042 +   uint16_t    usage=0;
  1.1043 +   uint16_t    data=0;
  1.1044 +
  1.1045 +   while (report_length && !(usage_page && usage))
  1.1046 +   {
  1.1047 +      if (hidp_analyse_byte(*report_data, &byte))
  1.1048 +      {
  1.1049 +         /* Error in parser, do nothing */
  1.1050 +      }
  1.1051 +      data=hidp_get_data((report_data+1), &byte);
  1.1052 +      switch (byte.HIDB_Type)
  1.1053 +      {
  1.1054 +         case HID_TYPE_GLOBAL:
  1.1055 +              if (!usage_page && byte.HIDB_Tag==HID_GLOBAL_USAGE_PAGE)
  1.1056 +              {
  1.1057 +                 usage_page=data;
  1.1058 +              }
  1.1059 +              break;
  1.1060 +         case HID_TYPE_LOCAL:
  1.1061 +              if (!usage && byte.HIDB_Tag==HID_LOCAL_USAGE)
  1.1062 +              {
  1.1063 +                 usage=data;
  1.1064 +              }
  1.1065 +              break;
  1.1066 +      }
  1.1067 +      report_data+=byte.HIDB_Length+1;
  1.1068 +      report_length-=byte.HIDB_Length+1;
  1.1069 +   }
  1.1070 +
  1.1071 +   switch (usage_page)
  1.1072 +   {
  1.1073 +      case HIDD_PAGE_DESKTOP:
  1.1074 +           {
  1.1075 +              switch (usage)
  1.1076 +              {
  1.1077 +                 case HIDD_USAGE_MOUSE:
  1.1078 +                      {
  1.1079 +                         return SDL_GF_HIDDI_MOUSE;
  1.1080 +                      }
  1.1081 +                      break;
  1.1082 +                 case HIDD_USAGE_JOYSTICK:
  1.1083 +                      {
  1.1084 +                         return SDL_GF_HIDDI_JOYSTICK;
  1.1085 +                      }
  1.1086 +                      break;
  1.1087 +                 case HIDD_USAGE_KEYBOARD:
  1.1088 +                      {
  1.1089 +                         return SDL_GF_HIDDI_KEYBOARD;
  1.1090 +                      }
  1.1091 +                      break;
  1.1092 +              }
  1.1093 +           }
  1.1094 +           break;
  1.1095 +      case HIDD_PAGE_DIGITIZER:
  1.1096 +           {
  1.1097 +              /* Do not handle digitizers */
  1.1098 +           }
  1.1099 +           break;
  1.1100 +      case HIDD_PAGE_CONSUMER:
  1.1101 +           {
  1.1102 +              /* Do not handle consumer input devices */
  1.1103 +           }
  1.1104 +           break;
  1.1105 +   }
  1.1106 +
  1.1107 +   return SDL_GF_HIDDI_NONE;
  1.1108 +}
  1.1109 +
  1.1110 +static int32_t hiddi_connect_devices()
  1.1111 +{
  1.1112 +   int32_t  status;
  1.1113 +   uint32_t it;
  1.1114 +   uint8_t* report_data;
  1.1115 +   uint16_t report_length;
  1.1116 +   hidd_device_instance_t instance;
  1.1117 +
  1.1118 +   /* Cleanup initial keys and mice state */
  1.1119 +   SDL_memset(key_last_state, 0x00, sizeof(key_packet)*SDL_HIDDI_MAX_DEVICES);
  1.1120 +   SDL_memset(mouse_last_state_button, 0x00, sizeof(uint32_t)*SDL_HIDDI_MAX_DEVICES);
  1.1121 +
  1.1122 +   status=hidd_connect(&hidparams, &connection);
  1.1123 +   if (status!=EOK)
  1.1124 +   {
  1.1125 +      return -1;
  1.1126 +   }
  1.1127 +
  1.1128 +   for (it=0; it<SDL_HIDDI_MAX_DEVICES; it++)
  1.1129 +   {
  1.1130 +      /* Get device instance */
  1.1131 +      status=hidd_get_device_instance(connection, it, &instance);
  1.1132 +      if (status!=EOK)
  1.1133 +      {
  1.1134 +         continue;
  1.1135 +      }
  1.1136 +
  1.1137 +      status=hidd_get_report_desc(connection, &instance, &report_data, &report_length);
  1.1138 +      if (status!=EOK)
  1.1139 +      {
  1.1140 +         continue;
  1.1141 +      }
  1.1142 +
  1.1143 +      status=hiddi_get_device_type(report_data, report_length);
  1.1144 +      sdl_input_devices[it]=status;
  1.1145 +
  1.1146 +      free(report_data);
  1.1147 +   }
  1.1148 +
  1.1149 +   /* Disconnect from HID server */
  1.1150 +   status=hidd_disconnect(connection);
  1.1151 +   if (status!=EOK)
  1.1152 +   {
  1.1153 +      return -1;
  1.1154 +   }
  1.1155 +
  1.1156 +   /* Add handlers for HID devices */
  1.1157 +   hidparams.funcs=&hidfuncs;
  1.1158 +
  1.1159 +   status=hidd_connect(&hidparams, &connection);
  1.1160 +   if (status!=EOK)
  1.1161 +   {
  1.1162 +      return -1;
  1.1163 +   }
  1.1164 +
  1.1165 +   return 0;
  1.1166 +}
  1.1167 +
  1.1168 +static int32_t hiddi_disconnect_devices()
  1.1169 +{
  1.1170 +   int32_t status;
  1.1171 +
  1.1172 +   hiddi_disable_mouse();
  1.1173 +
  1.1174 +   /* Disconnect from HID server */
  1.1175 +   status=hidd_disconnect(connection);
  1.1176 +   if (status!=EOK)
  1.1177 +   {
  1.1178 +      return -1;
  1.1179 +   }
  1.1180 +}
  1.1181 +
  1.1182 +void hiddi_enable_mouse()
  1.1183 +{
  1.1184 +   collect_reports=1;
  1.1185 +}
  1.1186 +
  1.1187 +void hiddi_disable_mouse()
  1.1188 +{
  1.1189 +   collect_reports=0;
  1.1190 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/video/qnxgf/SDL_gf_input.h	Tue Apr 28 04:33:30 2009 +0000
     2.3 @@ -0,0 +1,165 @@
     2.4 +/*
     2.5 +    SDL - Simple DirectMedia Layer
     2.6 +    Copyright (C) 1997-2009 Sam Lantinga
     2.7 +
     2.8 +    This library is free software; you can redistribute it and/or
     2.9 +    modify it under the terms of the GNU Lesser General Public
    2.10 +    License as published by the Free Software Foundation; either
    2.11 +    version 2.1 of the License, or (at your option) any later version.
    2.12 +
    2.13 +    This library is distributed in the hope that it will be useful,
    2.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 +    Lesser General Public License for more details.
    2.17 +
    2.18 +    You should have received a copy of the GNU Lesser General Public
    2.19 +    License along with this library; if not, write to the Free Software
    2.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    2.21 +
    2.22 +    Sam Lantinga
    2.23 +    slouken@libsdl.org
    2.24 +
    2.25 +    QNX Graphics Framework SDL driver
    2.26 +    Copyright (C) 2009 Mike Gorchak
    2.27 +    (mike@malva.ua, lestat@i.com.ua)
    2.28 +*/
    2.29 +
    2.30 +#ifndef __SDL_GF_INPUT_H__
    2.31 +#define __SDL_GF_INPUT_H__
    2.32 +
    2.33 +#include "SDL_config.h"
    2.34 +#include "SDL_video.h"
    2.35 +#include "../SDL_sysvideo.h"
    2.36 +
    2.37 +#include <errno.h>
    2.38 +
    2.39 +#include <gf/gf.h>
    2.40 +
    2.41 +#include <sys/hiddi.h>
    2.42 +#include <sys/hidut.h>
    2.43 +
    2.44 +#include "SDL_qnxgf.h"
    2.45 +
    2.46 +typedef struct SDL_MouseData
    2.47 +{
    2.48 +   SDL_DisplayData* didata;
    2.49 +} SDL_MouseData;
    2.50 +
    2.51 +int32_t gf_addinputdevices(_THIS);
    2.52 +int32_t gf_delinputdevices(_THIS);
    2.53 +
    2.54 +#define SDL_GF_MOUSE_COLOR_BLACK 0xFF000000
    2.55 +#define SDL_GF_MOUSE_COLOR_WHITE 0xFFFFFFFF
    2.56 +#define SDL_GF_MOUSE_COLOR_TRANS 0x00000000
    2.57 +
    2.58 +/*****************************************************************************/
    2.59 +/* This is HIDDI closed interface declarations                               */
    2.60 +/*****************************************************************************/
    2.61 +#define HID_TYPE_MAIN      0x0
    2.62 +#define HID_TYPE_GLOBAL    0x1
    2.63 +#define HID_TYPE_LOCAL     0x2
    2.64 +#define HID_TYPE_RESERVED  0x3
    2.65 +
    2.66 +#define HID_GLOBAL_USAGE_PAGE 0x0
    2.67 +#define HID_LOCAL_USAGE       0x0
    2.68 +
    2.69 +typedef struct _hid_byte
    2.70 +{
    2.71 +   uint8_t HIDB_Length;
    2.72 +   uint8_t HIDB_Type;
    2.73 +   uint8_t HIDB_Tag;
    2.74 +   uint8_t reserved[1];
    2.75 +} hid_byte_t;
    2.76 +
    2.77 +typedef struct _hidd_global_item
    2.78 +{
    2.79 +   uint16_t usage_page;
    2.80 +   uint16_t logical_min;
    2.81 +   uint16_t logical_max;
    2.82 +   uint16_t physical_min;
    2.83 +   uint16_t physical_max;
    2.84 +   uint16_t unit_expo;
    2.85 +   uint16_t unit;
    2.86 +   uint16_t report_size;
    2.87 +   uint16_t report_id;
    2.88 +   uint16_t report_count;
    2.89 +} hidd_global_item_t;
    2.90 +
    2.91 +typedef struct _hidd_local_item
    2.92 +{
    2.93 +   uint16_t type;
    2.94 +   uint8_t  reserved[2];
    2.95 +   uint32_t value;
    2.96 +   struct _hidd_local_item* next_local;
    2.97 +   struct _hidd_local_item* alt_local;
    2.98 +} hidd_local_item_t;
    2.99 +
   2.100 +typedef struct _hidd_local_table
   2.101 +{
   2.102 +   hidd_local_item_t* usage_info;
   2.103 +   hidd_local_item_t* designator_info;
   2.104 +   hidd_local_item_t* string_info;
   2.105 +   uint8_t delimiter;
   2.106 +   uint8_t reserved[3];
   2.107 +} hidd_local_table_t;
   2.108 +
   2.109 +typedef struct _hidd_field
   2.110 +{
   2.111 +   struct hidd_report_instance* report;
   2.112 +   struct hidd_collection* collection;
   2.113 +   uint16_t report_offset;
   2.114 +   uint16_t flags;
   2.115 +   hidd_global_item_t  gitem;
   2.116 +   hidd_local_table_t* ltable;
   2.117 +   struct _hidd_field* next_field;
   2.118 +   void* user;
   2.119 +} hidd_field_t;
   2.120 +
   2.121 +typedef struct hidd_report_instance
   2.122 +{
   2.123 +   uint8_t       report_id;
   2.124 +   uint8_t       reserved[1];
   2.125 +   uint16_t      report_type;
   2.126 +   hidd_field_t* field;
   2.127 +   uint16_t      num_field;
   2.128 +   uint16_t      byte_len;
   2.129 +   uint16_t      bit_len;
   2.130 +   uint8_t       reserved2[2];
   2.131 +   struct hidd_collection* collection;
   2.132 +   struct hidd_report_instance* next_col_report;
   2.133 +   struct hidd_report_instance* next_report;
   2.134 +} hidd_report_instance_t;
   2.135 +
   2.136 +typedef struct hidd_report
   2.137 +{
   2.138 +   TAILQ_ENTRY(hidd_report) link;
   2.139 +   hidd_report_instance_t* rinst;
   2.140 +   hidd_device_instance_t* dev_inst;
   2.141 +   uint32_t flags;
   2.142 +   struct hidd_connection* connection;
   2.143 +   void* user;
   2.144 +} hidd_report_t;
   2.145 +
   2.146 +typedef struct hidview_device
   2.147 +{
   2.148 +   struct hidd_report_instance* instance;
   2.149 +   struct hidd_report* report;
   2.150 +} hidview_device_t;
   2.151 +
   2.152 +/*****************************************************************************/
   2.153 +/* Closed HIDDI interface declarations end                                   */
   2.154 +/*****************************************************************************/
   2.155 +
   2.156 +/* Maximum devices and subdevices amount per host */
   2.157 +#define SDL_HIDDI_MAX_DEVICES 64
   2.158 +
   2.159 +/* Detected device/subdevice type for SDL */
   2.160 +#define SDL_GF_HIDDI_NONE     0x00000000
   2.161 +#define SDL_GF_HIDDI_MOUSE    0x00000001
   2.162 +#define SDL_GF_HIDDI_KEYBOARD 0x00000002
   2.163 +#define SDL_GF_HIDDI_JOYSTICK 0x00000003
   2.164 +
   2.165 +extern void hiddi_enable_mouse();
   2.166 +extern void hiddi_disable_mouse();
   2.167 +
   2.168 +#endif /* __SDL_GF_INPUT_H__ */
     3.1 --- a/src/video/qnxgf/SDL_gf_opengles.c	Tue Apr 28 04:30:52 2009 +0000
     3.2 +++ b/src/video/qnxgf/SDL_gf_opengles.c	Tue Apr 28 04:33:30 2009 +0000
     3.3 @@ -1,8 +1,3 @@
     3.4 -Date: Mon, 23 Mar 2009 09:17:24 +0200
     3.5 -From: "Mike Gorchak" <mike@malva.ua>
     3.6 -To: "Sam Lantinga" <slouken@devolution.com>
     3.7 -Subject: New QNX patches
     3.8 -
     3.9  /*
    3.10      SDL - Simple DirectMedia Layer
    3.11      Copyright (C) 1997-2009 Sam Lantinga
    3.12 @@ -53,4 +48,3 @@
    3.13     glColor4f(((GLfloat)red)/255.f, ((GLfloat)green)/255.f, ((GLfloat)blue)/255.f, ((GLfloat)alpha)/255.f);
    3.14     return;
    3.15  }
    3.16 -
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/video/qnxgf/SDL_gf_opengles.h	Tue Apr 28 04:33:30 2009 +0000
     4.3 @@ -0,0 +1,37 @@
     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 Graphics Framework 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_GF_OPENGLES_H__
    4.31 +#define __SDL_GF_OPENGLES_H__
    4.32 +
    4.33 +#include <GLES/gl.h>
    4.34 +#include <GLES/glext.h>
    4.35 +
    4.36 +GLAPI void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param);
    4.37 +GLAPI void APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint* params);
    4.38 +GLAPI void APIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
    4.39 +
    4.40 +#endif /* __SDL_GF_OPENGLES_H__ */
     5.1 --- a/src/video/qnxgf/SDL_gf_render.c	Tue Apr 28 04:30:52 2009 +0000
     5.2 +++ b/src/video/qnxgf/SDL_gf_render.c	Tue Apr 28 04:33:30 2009 +0000
     5.3 @@ -35,24 +35,24 @@
     5.4  #include "SDL_qnxgf.h"
     5.5  
     5.6  static SDL_Renderer* gf_createrenderer(SDL_Window* window, Uint32 flags);
     5.7 -static int gf_displaymodechanged(SDL_Renderer* renderer);
     5.8 -static int gf_activaterenderer(SDL_Renderer* renderer);
     5.9 -static int gf_createtexture(SDL_Renderer* renderer, SDL_Texture* texture);
    5.10 -static int gf_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch);
    5.11 -static int gf_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors);
    5.12 -static int gf_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors);
    5.13 -static int gf_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture);
    5.14 -static int gf_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture);
    5.15 -static int gf_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture);
    5.16 -static int gf_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture);
    5.17 -static int gf_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch);
    5.18 -static int gf_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch);
    5.19 +static int  gf_displaymodechanged(SDL_Renderer* renderer);
    5.20 +static int  gf_activaterenderer(SDL_Renderer* renderer);
    5.21 +static int  gf_createtexture(SDL_Renderer* renderer, SDL_Texture* texture);
    5.22 +static int  gf_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch);
    5.23 +static int  gf_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors);
    5.24 +static int  gf_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors);
    5.25 +static int  gf_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture);
    5.26 +static int  gf_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture);
    5.27 +static int  gf_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture);
    5.28 +static int  gf_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture);
    5.29 +static int  gf_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch);
    5.30 +static int  gf_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch);
    5.31  static void gf_unlocktexture(SDL_Renderer* renderer, SDL_Texture* texture);
    5.32  static void gf_dirtytexture(SDL_Renderer* renderer, SDL_Texture* texture, int numrects, const SDL_Rect* rects);
    5.33 -static int gf_renderpoint(SDL_Renderer* renderer, int x, int y);
    5.34 -static int gf_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2);
    5.35 -static int gf_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect);
    5.36 -static int gf_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect);
    5.37 +static int  gf_renderpoint(SDL_Renderer* renderer, int x, int y);
    5.38 +static int  gf_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2);
    5.39 +static int  gf_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect);
    5.40 +static int  gf_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect);
    5.41  static void gf_renderpresent(SDL_Renderer* renderer);
    5.42  static void gf_destroytexture(SDL_Renderer* renderer, SDL_Texture* texture);
    5.43  static void gf_destroyrenderer(SDL_Renderer* renderer);
    5.44 @@ -222,7 +222,6 @@
    5.45     for (it=0; it<rdata->surfaces_count; it++)
    5.46     {
    5.47        /* TODO: add palette creation */
    5.48 -      /*       do not waste surfaces when using GL ES */
    5.49  
    5.50        /* Create displayable surfaces */
    5.51        status=gf_surface_create_layer(&rdata->surface[it], &didata->layer, 1, 0,
    5.52 @@ -236,6 +235,7 @@
    5.53           for (jt=it-1; jt>0; jt--)
    5.54           {
    5.55              gf_surface_free(rdata->surface[jt]);
    5.56 +            rdata->surface[jt]=NULL;
    5.57           }
    5.58           SDL_free(rdata);
    5.59           SDL_free(renderer);
    5.60 @@ -288,10 +288,10 @@
    5.61     SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata;
    5.62  
    5.63     /* Setup current surface as visible */
    5.64 -   gf_layer_set_surfaces(didata->layer, &rdata->surface[rdata->surface_visible_idx], 1);
    5.65 +//   gf_layer_set_surfaces(didata->layer, &rdata->surface[rdata->surface_visible_idx], 1);
    5.66  
    5.67     /* Set visible surface when hardware in idle state */
    5.68 -   gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
    5.69 +//   gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
    5.70  
    5.71     return 0;
    5.72  }
    5.73 @@ -391,7 +391,10 @@
    5.74  
    5.75     for (it=0; it<rdata->surfaces_count; it++)
    5.76     {
    5.77 -      gf_surface_free(rdata->surface[it]);
    5.78 +      if (rdata->surface[it]!=NULL)
    5.79 +      {
    5.80 +         gf_surface_free(rdata->surface[it]);
    5.81 +      }
    5.82     }
    5.83  }
    5.84  
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/video/qnxgf/SDL_hiddi_joystick.h	Tue Apr 28 04:33:30 2009 +0000
     6.3 @@ -0,0 +1,34 @@
     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 Graphics Framework SDL driver
    6.26 +    Copyright (C) 2009 Mike Gorchak
    6.27 +    (mike@malva.ua, lestat@i.com.ua)
    6.28 +*/
    6.29 +
    6.30 +#ifndef __SDL_HIDDI_JOYSTICK_H__
    6.31 +#define __SDL_HIDDI_JOYSTICK_H__
    6.32 +
    6.33 +#include <inttypes.h>
    6.34 +
    6.35 +
    6.36 +
    6.37 +#endif /* __SDL_HIDDI_JOYSTICK_H__ */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/qnxgf/SDL_hiddi_keyboard.h	Tue Apr 28 04:33:30 2009 +0000
     7.3 @@ -0,0 +1,159 @@
     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 Graphics Framework SDL driver
    7.26 +    Copyright (C) 2009 Mike Gorchak
    7.27 +    (mike@malva.ua, lestat@i.com.ua)
    7.28 +*/
    7.29 +
    7.30 +#ifndef __SDL_HIDDI_KEYBOARD_H__
    7.31 +#define __SDL_HIDDI_KEYBOARD_H__
    7.32 +
    7.33 +#include <inttypes.h>
    7.34 +
    7.35 +/* PS/2 and USB keyboards are generating this packet */
    7.36 +typedef struct key_packet
    7.37 +{
    7.38 +   uint8_t modifiers;
    7.39 +   uint8_t data;
    7.40 +   uint8_t codes[6];
    7.41 +} key_packet;
    7.42 +
    7.43 +/* Key modifier codes */
    7.44 +#define HIDDI_MKEY_LEFT_CTRL            0x00000001
    7.45 +#define HIDDI_MKEY_LEFT_SHIFT           0x00000002
    7.46 +#define HIDDI_MKEY_LEFT_ALT             0x00000004
    7.47 +#define HIDDI_MKEY_LEFT_WFLAG           0x00000008
    7.48 +#define HIDDI_MKEY_RIGHT_CTRL           0x00000010
    7.49 +#define HIDDI_MKEY_RIGHT_SHIFT          0x00000020
    7.50 +#define HIDDI_MKEY_RIGHT_ALT            0x00000040
    7.51 +#define HIDDI_MKEY_RIGHT_WFLAG          0x00000080
    7.52 +
    7.53 +/* Key codes */
    7.54 +#define HIDDI_KEY_UNPRESSED             0x00000000
    7.55 +#define HIDDI_KEY_OVERFLOW              0x00000001
    7.56 +#define HIDDI_KEY_ESC                   0x00000029
    7.57 +#define HIDDI_KEY_F1                    0x0000003A
    7.58 +#define HIDDI_KEY_F2                    0x0000003B
    7.59 +#define HIDDI_KEY_F3                    0x0000003C
    7.60 +#define HIDDI_KEY_F4                    0x0000003D
    7.61 +#define HIDDI_KEY_F5                    0x0000003E
    7.62 +#define HIDDI_KEY_F6                    0x0000003F
    7.63 +#define HIDDI_KEY_F7                    0x00000040
    7.64 +#define HIDDI_KEY_F8                    0x00000041
    7.65 +#define HIDDI_KEY_F9                    0x00000042
    7.66 +#define HIDDI_KEY_F10                   0x00000043
    7.67 +#define HIDDI_KEY_F11                   0x00000044
    7.68 +#define HIDDI_KEY_F12                   0x00000045
    7.69 +
    7.70 +#define HIDDI_KEY_BACKQUOTE             0x00000035
    7.71 +#define HIDDI_KEY_1                     0x0000001E
    7.72 +#define HIDDI_KEY_2                     0x0000001F
    7.73 +#define HIDDI_KEY_3                     0x00000020
    7.74 +#define HIDDI_KEY_4                     0x00000021
    7.75 +#define HIDDI_KEY_5                     0x00000022
    7.76 +#define HIDDI_KEY_6                     0x00000023
    7.77 +#define HIDDI_KEY_7                     0x00000024
    7.78 +#define HIDDI_KEY_8                     0x00000025
    7.79 +#define HIDDI_KEY_9                     0x00000026
    7.80 +#define HIDDI_KEY_0                     0x00000027
    7.81 +#define HIDDI_KEY_MINUS                 0x0000002D
    7.82 +#define HIDDI_KEY_EQUAL                 0x0000002E
    7.83 +#define HIDDI_KEY_BACKSPACE             0x0000002A
    7.84 +
    7.85 +#define HIDDI_KEY_TAB                   0x0000002B
    7.86 +#define HIDDI_KEY_Q                     0x00000014
    7.87 +#define HIDDI_KEY_W                     0x0000001A
    7.88 +#define HIDDI_KEY_E                     0x00000008
    7.89 +#define HIDDI_KEY_R                     0x00000015
    7.90 +#define HIDDI_KEY_T                     0x00000017
    7.91 +#define HIDDI_KEY_Y                     0x0000001C
    7.92 +#define HIDDI_KEY_U                     0x00000018
    7.93 +#define HIDDI_KEY_I                     0x0000000C
    7.94 +#define HIDDI_KEY_O                     0x00000012
    7.95 +#define HIDDI_KEY_P                     0x00000013
    7.96 +#define HIDDI_KEY_LEFT_SQ_BRACKET       0x0000002F
    7.97 +#define HIDDI_KEY_RIGHT_SQ_BRACKET      0x00000030
    7.98 +#define HIDDI_KEY_BACKSLASH             0x00000031
    7.99 +
   7.100 +#define HIDDI_KEY_CAPSLOCK              0x00000039
   7.101 +#define HIDDI_KEY_A                     0x00000004
   7.102 +#define HIDDI_KEY_S                     0x00000016
   7.103 +#define HIDDI_KEY_D                     0x00000007
   7.104 +#define HIDDI_KEY_F                     0x00000009
   7.105 +#define HIDDI_KEY_G                     0x0000000A
   7.106 +#define HIDDI_KEY_H                     0x0000000B
   7.107 +#define HIDDI_KEY_J                     0x0000000D
   7.108 +#define HIDDI_KEY_K                     0x0000000E
   7.109 +#define HIDDI_KEY_L                     0x0000000F
   7.110 +#define HIDDI_KEY_SEMICOLON             0x00000033
   7.111 +#define HIDDI_KEY_QUOTE                 0x00000034
   7.112 +#define HIDDI_KEY_ENTER                 0x00000028
   7.113 +
   7.114 +#define HIDDI_KEY_Z                     0x0000001D
   7.115 +#define HIDDI_KEY_X                     0x0000001B
   7.116 +#define HIDDI_KEY_C                     0x00000006
   7.117 +#define HIDDI_KEY_V                     0x00000019
   7.118 +#define HIDDI_KEY_B                     0x00000005
   7.119 +#define HIDDI_KEY_N                     0x00000011
   7.120 +#define HIDDI_KEY_M                     0x00000010
   7.121 +#define HIDDI_KEY_COMMA                 0x00000036
   7.122 +#define HIDDI_KEY_POINT                 0x00000037
   7.123 +#define HIDDI_KEY_SLASH                 0x00000038
   7.124 +
   7.125 +#define HIDDI_KEY_SPACE                 0x0000002C
   7.126 +#define HIDDI_KEY_MENU                  0x00000065
   7.127 +
   7.128 +#define HIDDI_KEY_PRINTSCREEN           0x00000046
   7.129 +#define HIDDI_KEY_SCROLLLOCK            0x00000047
   7.130 +#define HIDDI_KEY_PAUSE                 0x00000048
   7.131 +
   7.132 +#define HIDDI_KEY_INSERT                0x00000049
   7.133 +#define HIDDI_KEY_HOME                  0x0000004A
   7.134 +#define HIDDI_KEY_PAGEUP                0x0000004B
   7.135 +#define HIDDI_KEY_DELETE                0x0000004C
   7.136 +#define HIDDI_KEY_END                   0x0000004D
   7.137 +#define HIDDI_KEY_PAGEDOWN              0x0000004E
   7.138 +
   7.139 +#define HIDDI_KEY_UP                    0x00000052
   7.140 +#define HIDDI_KEY_LEFT                  0x00000050
   7.141 +#define HIDDI_KEY_DOWN                  0x00000051
   7.142 +#define HIDDI_KEY_RIGHT                 0x0000004F
   7.143 +
   7.144 +#define HIDDI_KEY_NUMLOCK               0x00000053
   7.145 +#define HIDDI_KEY_GR_SLASH              0x00000054
   7.146 +#define HIDDI_KEY_GR_ASTERISK           0x00000055
   7.147 +#define HIDDI_KEY_GR_MINUS              0x00000056
   7.148 +#define HIDDI_KEY_GR_7                  0x0000005F
   7.149 +#define HIDDI_KEY_GR_8                  0x00000060
   7.150 +#define HIDDI_KEY_GR_9                  0x00000061
   7.151 +#define HIDDI_KEY_GR_PLUS               0x00000057
   7.152 +#define HIDDI_KEY_GR_4                  0x0000005C
   7.153 +#define HIDDI_KEY_GR_5                  0x0000005D
   7.154 +#define HIDDI_KEY_GR_6                  0x0000005E
   7.155 +#define HIDDI_KEY_GR_1                  0x00000059
   7.156 +#define HIDDI_KEY_GR_2                  0x0000005A
   7.157 +#define HIDDI_KEY_GR_3                  0x0000005B
   7.158 +#define HIDDI_KEY_GR_ENTER              0x00000058
   7.159 +#define HIDDI_KEY_GR_0                  0x00000062
   7.160 +#define HIDDI_KEY_GR_DELETE             0x00000063
   7.161 +
   7.162 +#endif /* __SDL_HIDDI_KEYBOARD_H__ */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/qnxgf/SDL_hiddi_mouse.h	Tue Apr 28 04:33:30 2009 +0000
     8.3 @@ -0,0 +1,69 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997-2009 Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Lesser General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2.1 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Lesser General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Lesser General Public
    8.19 +    License along with this library; if not, write to the Free Software
    8.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +
    8.25 +    QNX Graphics Framework SDL driver
    8.26 +    Copyright (C) 2009 Mike Gorchak
    8.27 +    (mike@malva.ua, lestat@i.com.ua)
    8.28 +*/
    8.29 +
    8.30 +#ifndef __SDL_HIDDI_MOUSE_H__
    8.31 +#define __SDL_HIDDI_MOUSE_H__
    8.32 +
    8.33 +#include <inttypes.h>
    8.34 +
    8.35 +/* USB keyboard multimedia keys are generating this packet */
    8.36 +typedef struct mouse_packet2
    8.37 +{
    8.38 +   uint8_t buttons;
    8.39 +   int8_t  wheel;
    8.40 +} mouse_packet2;
    8.41 +
    8.42 +/* PS/2 mice are generating this packet */
    8.43 +typedef struct mouse_packet4
    8.44 +{
    8.45 +   uint8_t buttons;
    8.46 +   int8_t  horizontal;
    8.47 +   int8_t  vertical;
    8.48 +   int8_t  wheel;
    8.49 +} mouse_packet4;
    8.50 +
    8.51 +/* USB keyboard with mice wheel onboard generating this packet */
    8.52 +typedef struct mouse_packet5
    8.53 +{
    8.54 +   uint8_t buttons;
    8.55 +   int8_t  horizontal;
    8.56 +   int8_t  vertical;
    8.57 +   int8_t  wheel;
    8.58 +   uint8_t state;
    8.59 +} mouse_packet5;
    8.60 +
    8.61 +/* USB multi-button mice are generating this packet */
    8.62 +typedef struct mouse_packet8
    8.63 +{
    8.64 +   uint8_t buttons;
    8.65 +   int8_t  horizontal;
    8.66 +   int8_t  vertical;
    8.67 +   int8_t  wheel;
    8.68 +   int16_t horizontal_precision;
    8.69 +   int16_t vertical_precision;
    8.70 +} mouse_packet8;
    8.71 +
    8.72 +#endif /* __SDL_HIDDI_MOUSE_H__ */
     9.1 --- a/src/video/qnxgf/SDL_qnxgf.c	Tue Apr 28 04:30:52 2009 +0000
     9.2 +++ b/src/video/qnxgf/SDL_qnxgf.c	Tue Apr 28 04:33:30 2009 +0000
     9.3 @@ -37,6 +37,8 @@
     9.4  #include "SDL_qnxgf.h"
     9.5  #include "SDL_gf_render.h"
     9.6  #include "SDL_gf_pixelfmt.h"
     9.7 +#include "SDL_gf_opengles.h"
     9.8 +#include "SDL_gf_input.h"
     9.9  
    9.10  /******************************************************************************/
    9.11  /* SDL Generic video modes, which could provide GF                            */
    9.12 @@ -248,6 +250,13 @@
    9.13        return NULL;
    9.14     }
    9.15  
    9.16 +   if (gfdata->gfdev_info.description==NULL)
    9.17 +   {
    9.18 +      gf_dev_detach(gfdata->gfdev);
    9.19 +      SDL_SetError("GF: Failed to initialize graphics driver");
    9.20 +      return NULL;
    9.21 +   }
    9.22 +
    9.23     /* Setup amount of available displays and current display */
    9.24     device->num_displays=0;
    9.25     device->current_display=0;
    9.26 @@ -312,6 +321,10 @@
    9.27     uint32_t it;
    9.28     uint32_t jt;
    9.29     char* override;
    9.30 +   int32_t status;
    9.31 +
    9.32 +   /* By default GF uses buffer swap on vsync */
    9.33 +   gfdata->swapinterval=1;
    9.34  
    9.35     /* Add each detected output to SDL */
    9.36     for (it=0; it<gfdata->gfdev_info.ndisplays; it++)
    9.37 @@ -319,7 +332,6 @@
    9.38        SDL_VideoDisplay  display;
    9.39        SDL_DisplayMode   current_mode;
    9.40        SDL_DisplayData*  didata;
    9.41 -      int status;
    9.42  
    9.43        didata=(SDL_DisplayData*)SDL_calloc(1, sizeof(SDL_DisplayData));
    9.44        if (didata==NULL)
    9.45 @@ -329,6 +341,36 @@
    9.46           return -1;
    9.47        }
    9.48  
    9.49 +      /* Set default cursor settings, maximum 128x128 cursor */
    9.50 +      didata->cursor_visible=SDL_FALSE;
    9.51 +      didata->cursor.type=GF_CURSOR_BITMAP;
    9.52 +      didata->cursor.hotspot.x=0;
    9.53 +      didata->cursor.hotspot.y=0;
    9.54 +      didata->cursor.cursor.bitmap.w=SDL_VIDEO_GF_MAX_CURSOR_SIZE;
    9.55 +      didata->cursor.cursor.bitmap.h=SDL_VIDEO_GF_MAX_CURSOR_SIZE;
    9.56 +      didata->cursor.cursor.bitmap.stride=(didata->cursor.cursor.bitmap.w+7)/
    9.57 +                                          (sizeof(uint8_t)*8);
    9.58 +      didata->cursor.cursor.bitmap.color0=0x00000000;
    9.59 +      didata->cursor.cursor.bitmap.color1=0x00000000;
    9.60 +      didata->cursor.cursor.bitmap.image0=SDL_calloc(sizeof(uint8_t), (didata->cursor.cursor.bitmap.w+7)*
    9.61 +                                          didata->cursor.cursor.bitmap.h/(sizeof(uint8_t)*8));
    9.62 +      if (didata->cursor.cursor.bitmap.image0==NULL)
    9.63 +      {
    9.64 +         SDL_free(didata);
    9.65 +         SDL_OutOfMemory();
    9.66 +         return -1;
    9.67 +      }
    9.68 +      didata->cursor.cursor.bitmap.image1=SDL_calloc(sizeof(uint8_t), (didata->cursor.cursor.bitmap.w+7)*
    9.69 +                                   didata->cursor.cursor.bitmap.h/(sizeof(uint8_t)*8));
    9.70 +      if (didata->cursor.cursor.bitmap.image1==NULL)
    9.71 +      {
    9.72 +         SDL_OutOfMemory();
    9.73 +         SDL_free((void*)didata->cursor.cursor.bitmap.image0);
    9.74 +         SDL_free(didata);
    9.75 +         return -1;
    9.76 +      }
    9.77 +
    9.78 +      /* Query current display settings */
    9.79        status=gf_display_query(gfdata->gfdev, it, &didata->display_info);
    9.80        if (status==GF_ERR_OK)
    9.81        {
    9.82 @@ -342,6 +384,8 @@
    9.83        else
    9.84        {
    9.85           /* video initialization problem */
    9.86 +         SDL_free((void*)didata->cursor.cursor.bitmap.image0);
    9.87 +         SDL_free((void*)didata->cursor.cursor.bitmap.image1);
    9.88           SDL_free(didata);
    9.89           SDL_SetError("GF: Display query failed");
    9.90           return -1;
    9.91 @@ -352,6 +396,8 @@
    9.92        if (status!=GF_ERR_OK)
    9.93        {
    9.94           /* video initialization problem */
    9.95 +         SDL_free((void*)didata->cursor.cursor.bitmap.image0);
    9.96 +         SDL_free((void*)didata->cursor.cursor.bitmap.image1);
    9.97           SDL_free(didata);
    9.98           SDL_SetError("GF: Couldn't attach to display");
    9.99           return -1;
   9.100 @@ -364,18 +410,64 @@
   9.101        status=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0);
   9.102        if (status!=GF_ERR_OK)
   9.103        {
   9.104 +         /* Failed to attach to main layer */
   9.105 +         SDL_free((void*)didata->cursor.cursor.bitmap.image0);
   9.106 +         SDL_free((void*)didata->cursor.cursor.bitmap.image1);
   9.107 +         SDL_free(didata);
   9.108           SDL_SetError("GF: Couldn't attach to main layer, it could be busy");
   9.109 +         return -1;
   9.110 +      }
   9.111 +
   9.112 +      /* Mark main display layer is attached */
   9.113 +      didata->layer_attached=SDL_TRUE;
   9.114 +
   9.115 +      /* Set layer source and destination viewport */
   9.116 +      gf_layer_set_src_viewport(didata->layer, 0, 0, current_mode.w-1, current_mode.h-1);
   9.117 +      gf_layer_set_dst_viewport(didata->layer, 0, 0, current_mode.w-1, current_mode.h-1);
   9.118  
   9.119 -         /* Failed to attach to main layer */
   9.120 +      /* Create main visible on display surface */
   9.121 +      status=gf_surface_create_layer(&didata->surface[0], &didata->layer,
   9.122 +             1, 0, current_mode.w, current_mode.h,
   9.123 +             qnxgf_sdl_to_gf_pixelformat(current_mode.format),
   9.124 +             NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
   9.125 +             GF_SURFACE_CREATE_SHAREABLE);
   9.126 +      if (status!=GF_ERR_OK)
   9.127 +      {
   9.128 +         gf_layer_disable(didata->layer);
   9.129 +         gf_layer_detach(didata->layer);
   9.130 +         didata->layer_attached=SDL_FALSE;
   9.131 +         SDL_free((void*)didata->cursor.cursor.bitmap.image0);
   9.132 +         SDL_free((void*)didata->cursor.cursor.bitmap.image1);
   9.133 +         SDL_free(didata);
   9.134 +         SDL_SetError("GF: Can't create main layer surface at init (%d)\n", status);
   9.135 +         return -1;
   9.136 +      }
   9.137 +
   9.138 +      /* Set just created surface as main visible on the layer */
   9.139 +//      gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1);
   9.140 +
   9.141 +      /* Update layer parameters */
   9.142 +      status=gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
   9.143 +      if (status!=GF_ERR_OK)
   9.144 +      {
   9.145 +         /* Free allocated surface */
   9.146 +         gf_surface_free(didata->surface[0]);
   9.147 +         didata->surface[0]=NULL;
   9.148 +
   9.149 +         /* Disable and detach from layer */
   9.150 +         gf_layer_disable(didata->layer);
   9.151 +         gf_layer_detach(didata->layer);
   9.152 +         didata->layer_attached=SDL_FALSE;
   9.153 +         SDL_free((void*)didata->cursor.cursor.bitmap.image0);
   9.154 +         SDL_free((void*)didata->cursor.cursor.bitmap.image1);
   9.155 +         SDL_free(didata);
   9.156 +         SDL_SetError("GF: Can't update layer parameters\n");
   9.157           return -1;
   9.158        }
   9.159  
   9.160        /* Enable layer in case if hardware supports layer enable/disable */
   9.161        gf_layer_enable(didata->layer);
   9.162  
   9.163 -      /* Mark main display layer is attached */
   9.164 -      didata->layer_attached=SDL_TRUE;
   9.165 -
   9.166        /* Copy device name for each display */
   9.167        SDL_strlcpy(didata->description, gfdata->gfdev_info.description, SDL_VIDEO_GF_DEVICENAME_MAX-1);
   9.168  
   9.169 @@ -395,9 +487,9 @@
   9.170  
   9.171        /* Initialize display structure */
   9.172        SDL_zero(display);
   9.173 -      display.desktop_mode = current_mode;
   9.174 -      display.current_mode = current_mode;
   9.175 -      display.driverdata = didata;
   9.176 +      display.desktop_mode=current_mode;
   9.177 +      display.current_mode=current_mode;
   9.178 +      display.driverdata=didata;
   9.179        didata->current_mode=current_mode;
   9.180        SDL_AddVideoDisplay(&display);
   9.181  
   9.182 @@ -411,11 +503,26 @@
   9.183              didata->custom_refresh=0;
   9.184           }
   9.185        }
   9.186 +
   9.187 +      /* Get all display modes for this display */
   9.188 +      _this->current_display=it;
   9.189 +      qnxgf_getdisplaymodes(_this);
   9.190     }
   9.191  
   9.192 +   /* Restore default display */
   9.193 +   _this->current_display=0;
   9.194 +
   9.195     /* Add GF renderer to SDL */
   9.196     gf_addrenderdriver(_this);
   9.197  
   9.198 +   /* Add GF input devices */
   9.199 +   status=gf_addinputdevices(_this);
   9.200 +   if (status!=0)
   9.201 +   {
   9.202 +      /* SDL error is set by gf_addinputdevices() function */
   9.203 +      return -1;
   9.204 +   }
   9.205 +
   9.206     /* video has been initialized successfully */
   9.207     return 1;
   9.208  }
   9.209 @@ -425,11 +532,58 @@
   9.210     SDL_DisplayData* didata;
   9.211     uint32_t it;
   9.212  
   9.213 -   /* SDL will restore our desktop mode on exit */
   9.214 +   /* Delete GF input devices */
   9.215 +   gf_delinputdevices(_this);
   9.216 +
   9.217 +   /* SDL will restore old desktop mode on exit */
   9.218     for(it=0; it<_this->num_displays; it++)
   9.219     {
   9.220        didata=_this->displays[it].driverdata;
   9.221  
   9.222 +      /* Free cursor image */
   9.223 +      if (didata->cursor.cursor.bitmap.image0!=NULL)
   9.224 +      {
   9.225 +         SDL_free((void*)didata->cursor.cursor.bitmap.image0);
   9.226 +      }
   9.227 +      if (didata->cursor.cursor.bitmap.image1!=NULL)
   9.228 +      {
   9.229 +         SDL_free((void*)didata->cursor.cursor.bitmap.image1);
   9.230 +      }
   9.231 +
   9.232 +      /* Free main surface */
   9.233 +      if (didata->surface[0]!=NULL)
   9.234 +      {
   9.235 +         gf_surface_free(didata->surface[0]);
   9.236 +         didata->surface[0]=NULL;
   9.237 +      }
   9.238 +
   9.239 +      /* Free back surface */
   9.240 +      if (didata->surface[1]!=NULL)
   9.241 +      {
   9.242 +         gf_surface_free(didata->surface[1]);
   9.243 +         didata->surface[1]=NULL;
   9.244 +      }
   9.245 +
   9.246 +      /* Free second back surface */
   9.247 +      if (didata->surface[2]!=NULL)
   9.248 +      {
   9.249 +         gf_surface_free(didata->surface[2]);
   9.250 +         didata->surface[2]=NULL;
   9.251 +      }
   9.252 +
   9.253 +      /* Detach layer before quit */
   9.254 +      if (didata->layer_attached==SDL_TRUE)
   9.255 +      {
   9.256 +         /* Disable layer if hardware supports this */
   9.257 +         gf_layer_disable(didata->layer);
   9.258 +
   9.259 +         /* Detach from layer, free it for others */
   9.260 +         gf_layer_detach(didata->layer);
   9.261 +
   9.262 +         /* Mark it as detached */
   9.263 +         didata->layer_attached=SDL_FALSE;
   9.264 +      }
   9.265 +
   9.266        /* Detach from selected display */
   9.267        gf_display_detach(didata->display);
   9.268     }
   9.269 @@ -523,7 +677,7 @@
   9.270  {
   9.271     SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
   9.272     uint32_t refresh_rate=0;
   9.273 -   int result;
   9.274 +   int status;
   9.275  
   9.276     /* Current display dimensions and bpp are no more valid */
   9.277     didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN;
   9.278 @@ -617,6 +771,27 @@
   9.279        }
   9.280     }
   9.281  
   9.282 +   /* Free main surface */
   9.283 +   if (didata->surface[0]!=NULL)
   9.284 +   {
   9.285 +      gf_surface_free(didata->surface[0]);
   9.286 +      didata->surface[0]=NULL;
   9.287 +   }
   9.288 +
   9.289 +   /* Free back surface */
   9.290 +   if (didata->surface[1]!=NULL)
   9.291 +   {
   9.292 +      gf_surface_free(didata->surface[1]);
   9.293 +      didata->surface[1]=NULL;
   9.294 +   }
   9.295 +
   9.296 +   /* Free second back surface */
   9.297 +   if (didata->surface[2]!=NULL)
   9.298 +   {
   9.299 +      gf_surface_free(didata->surface[2]);
   9.300 +      didata->surface[2]=NULL;
   9.301 +   }
   9.302 +
   9.303     /* Detach layer before switch to new graphics mode */
   9.304     if (didata->layer_attached==SDL_TRUE)
   9.305     {
   9.306 @@ -631,9 +806,9 @@
   9.307     }
   9.308  
   9.309     /* Set new display video mode */
   9.310 -   result=gf_display_set_mode(didata->display, mode->w, mode->h, refresh_rate,
   9.311 +   status=gf_display_set_mode(didata->display, mode->w, mode->h, refresh_rate,
   9.312                                qnxgf_sdl_to_gf_pixelformat(mode->format), 0);
   9.313 -   if (result!=GF_ERR_OK)
   9.314 +   if (status!=GF_ERR_OK)
   9.315     {
   9.316        /* Display mode/resolution switch has been failed */
   9.317        SDL_SetError("GF: Mode is not supported by graphics driver");
   9.318 @@ -646,8 +821,8 @@
   9.319     }
   9.320  
   9.321     /* Attach to main display layer */
   9.322 -   result=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0);
   9.323 -   if (result!=GF_ERR_OK)
   9.324 +   status=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0);
   9.325 +   if (status!=GF_ERR_OK)
   9.326     {
   9.327        SDL_SetError("GF: Couldn't attach to main layer, it could be busy");
   9.328  
   9.329 @@ -655,12 +830,56 @@
   9.330        return -1;
   9.331     }
   9.332  
   9.333 +   /* Mark main display layer is attached */
   9.334 +   didata->layer_attached=SDL_TRUE;
   9.335 +
   9.336 +   /* Set layer source and destination viewport */
   9.337 +   gf_layer_set_src_viewport(didata->layer, 0, 0, mode->w-1, mode->h-1);
   9.338 +   gf_layer_set_dst_viewport(didata->layer, 0, 0, mode->w-1, mode->h-1);
   9.339 +
   9.340 +   /* Create main visible on display surface */
   9.341 +   status=gf_surface_create_layer(&didata->surface[0], &didata->layer, 1, 0,
   9.342 +          mode->w, mode->h, qnxgf_sdl_to_gf_pixelformat(mode->format),
   9.343 +          NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
   9.344 +          GF_SURFACE_CREATE_SHAREABLE);
   9.345 +   if (status!=GF_ERR_OK)
   9.346 +   {
   9.347 +      gf_layer_disable(didata->layer);
   9.348 +      gf_layer_detach(didata->layer);
   9.349 +      didata->layer_attached=SDL_FALSE;
   9.350 +      SDL_SetError("GF: Can't create main layer surface at modeswitch (%d)\n", status);
   9.351 +      return -1;
   9.352 +   }
   9.353 +
   9.354 +   /* Set just created surface as main visible on the layer */
   9.355 +   gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1);
   9.356 +
   9.357 +   /* Update layer parameters */
   9.358 +   status=gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
   9.359 +   if (status!=GF_ERR_OK)
   9.360 +   {
   9.361 +      /* Free main surface */
   9.362 +      gf_surface_free(didata->surface[0]);
   9.363 +      didata->surface[0]=NULL;
   9.364 +
   9.365 +      /* Detach layer */
   9.366 +      gf_layer_disable(didata->layer);
   9.367 +      gf_layer_detach(didata->layer);
   9.368 +      didata->layer_attached=SDL_FALSE;
   9.369 +      SDL_SetError("GF: Can't update layer parameters\n");
   9.370 +      return -1;
   9.371 +   }
   9.372 +
   9.373 +   /* Restore cursor if it was visible */
   9.374 +   if (didata->cursor_visible==SDL_TRUE)
   9.375 +   {
   9.376 +      gf_cursor_set(didata->display, 0, &didata->cursor);
   9.377 +      gf_cursor_enable(didata->display, 0);
   9.378 +   }
   9.379 +
   9.380     /* Enable layer in case if hardware supports layer enable/disable */
   9.381     gf_layer_enable(didata->layer);
   9.382  
   9.383 -   /* Mark main display layer is attached */
   9.384 -   didata->layer_attached=SDL_TRUE;
   9.385 -
   9.386     return 0;
   9.387  }
   9.388  
   9.389 @@ -766,7 +985,7 @@
   9.390        }
   9.391     }
   9.392  
   9.393 -   /* Setup our own window decorations, which are depend on fullscreen mode */
   9.394 +   /* Setup our own window decorations and states, which are depend on fullscreen mode */
   9.395     window->flags|=SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS |
   9.396                    SDL_WINDOW_MAXIMIZED | SDL_WINDOW_INPUT_GRABBED |
   9.397                    SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS;
   9.398 @@ -823,6 +1042,13 @@
   9.399        #endif /* SDL_VIDEO_OPENGL_ES */
   9.400     }
   9.401  
   9.402 +   /* Enable mouse event collecting */
   9.403 +   hiddi_enable_mouse();
   9.404 +
   9.405 +   /* By default last created window got a input focus */
   9.406 +   SDL_SetKeyboardFocus(0, window->id);
   9.407 +   SDL_SetMouseFocus(0, window->id);
   9.408 +
   9.409     /* Window has been successfully created */
   9.410     return 0;
   9.411  }
   9.412 @@ -896,9 +1122,9 @@
   9.413           if (wdata->target_created==SDL_TRUE)
   9.414           {
   9.415              gf_3d_target_free(wdata->target);
   9.416 +            wdata->target_created==SDL_FALSE;
   9.417           }
   9.418  
   9.419 -
   9.420           gfdata->egl_refcount--;
   9.421           if (gfdata->egl_refcount==0)
   9.422           {
   9.423 @@ -1001,8 +1227,22 @@
   9.424           }
   9.425        }
   9.426  
   9.427 +      /* Add emulated OpenGL ES 1.1 functions */
   9.428 +      if (SDL_strcmp(proc, "glTexParameteri")==0)
   9.429 +      {
   9.430 +         return glTexParameteri;
   9.431 +      }
   9.432 +      if (SDL_strcmp(proc, "glTexParameteriv")==0)
   9.433 +      {
   9.434 +         return glTexParameteriv;
   9.435 +      }
   9.436 +      if (SDL_strcmp(proc, "glColor4ub")==0)
   9.437 +      {
   9.438 +         return glColor4ub;
   9.439 +      }
   9.440 +
   9.441        /* Failed to get GL ES function address pointer */
   9.442 -      SDL_SetError("GF: Cannot locate given function name");
   9.443 +      SDL_SetError("GF: Cannot locate OpenGL ES function name");
   9.444        return NULL;
   9.445     #else
   9.446        SDL_SetError("GF: OpenGL ES support is not compiled in");
   9.447 @@ -1036,6 +1276,125 @@
   9.448        EGLint           configs;
   9.449        uint32_t         surfaces;
   9.450        uint32_t         attr_pos;
   9.451 +      EGLint           attr_value;
   9.452 +      EGLint           cit;
   9.453 +
   9.454 +      /* Choose buffeingr scheme */
   9.455 +      if (!_this->gl_config.double_buffer)
   9.456 +      {
   9.457 +         surfaces=1;
   9.458 +      }
   9.459 +      else
   9.460 +      {
   9.461 +         surfaces=2;
   9.462 +      }
   9.463 +
   9.464 +      /* Free main surface */
   9.465 +      if (didata->surface[0]!=NULL)
   9.466 +      {
   9.467 +         gf_surface_free(didata->surface[0]);
   9.468 +         didata->surface[0]=NULL;
   9.469 +      }
   9.470 +
   9.471 +      /* Free back surface */
   9.472 +      if (didata->surface[1]!=NULL)
   9.473 +      {
   9.474 +         gf_surface_free(didata->surface[1]);
   9.475 +         didata->surface[1]=NULL;
   9.476 +      }
   9.477 +
   9.478 +      /* Free second back surface */
   9.479 +      if (didata->surface[2]!=NULL)
   9.480 +      {
   9.481 +         gf_surface_free(didata->surface[2]);
   9.482 +         didata->surface[2]=NULL;
   9.483 +      }
   9.484 +
   9.485 +      /* Detach layer before switch to new graphics mode */
   9.486 +      if (didata->layer_attached==SDL_TRUE)
   9.487 +      {
   9.488 +         /* Disable layer if hardware supports this */
   9.489 +         gf_layer_disable(didata->layer);
   9.490 +
   9.491 +         /* Detach from layer, free it for others */
   9.492 +         gf_layer_detach(didata->layer);
   9.493 +
   9.494 +         /* Mark it as detached */
   9.495 +         didata->layer_attached=SDL_FALSE;
   9.496 +      }
   9.497 +
   9.498 +      /* Attach to main display layer */
   9.499 +      gfstatus=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0);
   9.500 +      if (gfstatus!=GF_ERR_OK)
   9.501 +      {
   9.502 +         SDL_SetError("GF: Couldn't attach to main layer, it could be busy");
   9.503 +
   9.504 +         /* Failed to attach to main displayable layer */
   9.505 +         return NULL;
   9.506 +      }
   9.507 +
   9.508 +      /* Mark main display layer is attached */
   9.509 +      didata->layer_attached=SDL_TRUE;
   9.510 +
   9.511 +      /* Set layer source and destination viewport */
   9.512 +      gf_layer_set_src_viewport(didata->layer, 0, 0, didata->current_mode.w-1, didata->current_mode.h-1);
   9.513 +      gf_layer_set_dst_viewport(didata->layer, 0, 0, didata->current_mode.w-1, didata->current_mode.h-1);
   9.514 +
   9.515 +      /* Create main visible on display surface */
   9.516 +      gfstatus=gf_surface_create_layer(&didata->surface[0], &didata->layer, 1, 0,
   9.517 +               didata->current_mode.w, didata->current_mode.h, qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format),
   9.518 +               NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
   9.519 +               GF_SURFACE_CREATE_SHAREABLE);
   9.520 +      if (gfstatus!=GF_ERR_OK)
   9.521 +      {
   9.522 +         gf_layer_disable(didata->layer);
   9.523 +         gf_layer_detach(didata->layer);
   9.524 +         didata->layer_attached=SDL_FALSE;
   9.525 +         SDL_SetError("GF: Can't create main layer surface at glctx (%d)\n", gfstatus);
   9.526 +         return NULL;
   9.527 +      }
   9.528 +
   9.529 +      /* Set just created surface as main visible on the layer */
   9.530 +//      gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1);
   9.531 +
   9.532 +      if (surfaces>1)
   9.533 +      {
   9.534 +         /* Create back display surface */
   9.535 +         gfstatus=gf_surface_create_layer(&didata->surface[1], &didata->layer, 1, 0,
   9.536 +                  didata->current_mode.w, didata->current_mode.h, qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format),
   9.537 +                  NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
   9.538 +                  GF_SURFACE_CREATE_SHAREABLE);
   9.539 +         if (gfstatus!=GF_ERR_OK)
   9.540 +         {
   9.541 +            gf_surface_free(didata->surface[0]);
   9.542 +            gf_layer_disable(didata->layer);
   9.543 +            gf_layer_detach(didata->layer);
   9.544 +            didata->layer_attached=SDL_FALSE;
   9.545 +            SDL_SetError("GF: Can't create main layer surface at glctx (%d)\n", gfstatus);
   9.546 +            return NULL;
   9.547 +         }
   9.548 +      }
   9.549 +
   9.550 +      /* Update layer parameters */
   9.551 +      gfstatus=gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
   9.552 +      if (gfstatus!=GF_ERR_OK)
   9.553 +      {
   9.554 +         /* Free main and back surfaces */
   9.555 +         gf_surface_free(didata->surface[1]);
   9.556 +         didata->surface[1]=NULL;
   9.557 +         gf_surface_free(didata->surface[0]);
   9.558 +         didata->surface[0]=NULL;
   9.559 +
   9.560 +         /* Detach layer */
   9.561 +         gf_layer_disable(didata->layer);
   9.562 +         gf_layer_detach(didata->layer);
   9.563 +         didata->layer_attached=SDL_FALSE;
   9.564 +         SDL_SetError("GF: Can't update layer parameters\n");
   9.565 +         return NULL;
   9.566 +      }
   9.567 +
   9.568 +      /* Enable layer in case if hardware supports layer enable/disable */
   9.569 +      gf_layer_enable(didata->layer);
   9.570  
   9.571        /* Prepare attributes list to pass them to OpenGL ES */
   9.572        attr_pos=0;
   9.573 @@ -1069,19 +1428,6 @@
   9.574           wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
   9.575        }
   9.576  
   9.577 -      /* OpenGL ES 1.0 uses double buffer by default, so if application */
   9.578 -      /* do not requested double buffering, switch to single buffer     */
   9.579 -      if (!_this->gl_config.double_buffer)
   9.580 -      {
   9.581 -         wdata->gles_attributes[attr_pos++]=EGL_SINGLE_BUFFER;
   9.582 -         wdata->gles_attributes[attr_pos++]=EGL_TRUE;
   9.583 -         surfaces=1;
   9.584 -      }
   9.585 -      else
   9.586 -      {
   9.587 -         surfaces=2;
   9.588 -      }
   9.589 -
   9.590        /* Set number of samples in multisampling */
   9.591        if (_this->gl_config.multisamplesamples)
   9.592        {
   9.593 @@ -1100,15 +1446,161 @@
   9.594        wdata->gles_attributes[attr_pos]=EGL_NONE;
   9.595  
   9.596        /* Request first suitable framebuffer configuration */
   9.597 -      status=eglChooseConfig(gfdata->egldisplay, wdata->gles_attributes, &wdata->gles_config, 1, &configs);
   9.598 +      status=eglChooseConfig(gfdata->egldisplay, wdata->gles_attributes,
   9.599 +                             wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
   9.600        if (status!=EGL_TRUE)
   9.601        {
   9.602           SDL_SetError("GF: Can't find closest configuration for OpenGL ES");
   9.603           return NULL;
   9.604        }
   9.605  
   9.606 +      /* Check if nothing has been found, try "don't care" settings */
   9.607 +      if (configs==0)
   9.608 +      {
   9.609 +         int32_t it;
   9.610 +         int32_t jt;
   9.611 +         GLint   depthbits[4]={32, 24, 16, EGL_DONT_CARE};
   9.612 +
   9.613 +         for (it=0; it<4; it++)
   9.614 +         {
   9.615 +            for (jt=16; jt>=0; jt--)
   9.616 +            {
   9.617 +               /* Don't care about color buffer bits, use what exist */
   9.618 +               /* Replace previous data set with EGL_DONT_CARE       */
   9.619 +               attr_pos=0;
   9.620 +               wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID;
   9.621 +               wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
   9.622 +               wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE;
   9.623 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
   9.624 +               wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE;
   9.625 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
   9.626 +               wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE;
   9.627 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
   9.628 +               wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE;
   9.629 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
   9.630 +               wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
   9.631 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
   9.632 +
   9.633 +               /* Try to find requested or smallest depth */
   9.634 +               if (_this->gl_config.depth_size)
   9.635 +               {
   9.636 +                  wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
   9.637 +                  wdata->gles_attributes[attr_pos++]=depthbits[it];
   9.638 +               }
   9.639 +               else
   9.640 +               {
   9.641 +                  wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
   9.642 +                  wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
   9.643 +               }
   9.644 +
   9.645 +               if (_this->gl_config.stencil_size)
   9.646 +               {
   9.647 +                  wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
   9.648 +                  wdata->gles_attributes[attr_pos++]=jt;
   9.649 +               }
   9.650 +               else
   9.651 +               {
   9.652 +                  wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
   9.653 +                  wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
   9.654 +
   9.655 +                  /* exit from stencil loop */
   9.656 +                  jt=0;
   9.657 +               }
   9.658 +
   9.659 +               /* Don't care about antialiasing */
   9.660 +               wdata->gles_attributes[attr_pos++]=EGL_SAMPLES;
   9.661 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
   9.662 +               wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS;
   9.663 +               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
   9.664 +               wdata->gles_attributes[attr_pos]=EGL_NONE;
   9.665 +
   9.666 +               /* Request first suitable framebuffer configuration */
   9.667 +               status=eglChooseConfig(gfdata->egldisplay, wdata->gles_attributes,
   9.668 +                                      wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
   9.669 +               if (status!=EGL_TRUE)
   9.670 +               {
   9.671 +                  SDL_SetError("Photon: Can't find closest configuration for OpenGL ES");
   9.672 +                  return NULL;
   9.673 +               }
   9.674 +               if (configs!=0)
   9.675 +               {
   9.676 +                  break;
   9.677 +               }
   9.678 +            }
   9.679 +            if (configs!=0)
   9.680 +            {
   9.681 +               break;
   9.682 +            }
   9.683 +         }
   9.684 +
   9.685 +         /* No available configs */
   9.686 +         if (configs==0)
   9.687 +         {
   9.688 +            SDL_SetError("Photon: Can't find any configuration for OpenGL ES");
   9.689 +            return NULL;
   9.690 +         }
   9.691 +      }
   9.692 +
   9.693 +      /* Initialize config index */
   9.694 +      wdata->gles_config=0;
   9.695 +
   9.696 +      /* Now check each configuration to find out the best */
   9.697 +      for (cit=0; cit<configs; cit++)
   9.698 +      {
   9.699 +         uint32_t stencil_found;
   9.700 +         uint32_t depth_found;
   9.701 +
   9.702 +         stencil_found=0;
   9.703 +         depth_found=0;
   9.704 +
   9.705 +         if (_this->gl_config.stencil_size)
   9.706 +         {
   9.707 +            status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[cit], EGL_STENCIL_SIZE, &attr_value);
   9.708 +            if (status==EGL_TRUE)
   9.709 +            {
   9.710 +               if (attr_value!=0)
   9.711 +               {
   9.712 +                  stencil_found=1;
   9.713 +               }
   9.714 +            }
   9.715 +         }
   9.716 +         else
   9.717 +         {
   9.718 +            stencil_found=1;
   9.719 +         }
   9.720 +
   9.721 +         if (_this->gl_config.depth_size)
   9.722 +         {
   9.723 +            status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[cit], EGL_DEPTH_SIZE, &attr_value);
   9.724 +            if (status==EGL_TRUE)
   9.725 +            {
   9.726 +               if (attr_value!=0)
   9.727 +               {
   9.728 +                  depth_found=1;
   9.729 +               }
   9.730 +            }
   9.731 +         }
   9.732 +         else
   9.733 +         {
   9.734 +            depth_found=1;
   9.735 +         }
   9.736 +
   9.737 +         /* Exit from loop if found appropriate configuration */
   9.738 +         if ((depth_found!=0) && (stencil_found!=0))
   9.739 +         {
   9.740 +            break;
   9.741 +         }
   9.742 +      }
   9.743 +
   9.744 +      /* If best could not be found, use first */
   9.745 +      if (cit==configs)
   9.746 +      {
   9.747 +         cit=0;
   9.748 +      }
   9.749 +      wdata->gles_config=cit;
   9.750 +
   9.751        /* Create OpenGL ES context */
   9.752 -      wdata->gles_context=eglCreateContext(gfdata->egldisplay, wdata->gles_config, EGL_NO_CONTEXT, NULL);
   9.753 +      wdata->gles_context=eglCreateContext(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_NO_CONTEXT, NULL);
   9.754        if (wdata->gles_context==EGL_NO_CONTEXT)
   9.755        {
   9.756           SDL_SetError("GF: OpenGL ES context creation has been failed");
   9.757 @@ -1119,13 +1611,13 @@
   9.758        if (wdata->target_created==SDL_TRUE)
   9.759        {
   9.760           gf_3d_target_free(wdata->target);
   9.761 +         wdata->target_created==SDL_FALSE;
   9.762        }
   9.763  
   9.764        /* Create surface(s) target for OpenGL ES */
   9.765 -      gfstatus=gf_3d_target_create(&wdata->target, didata->layer, NULL,
   9.766 +      gfstatus=gf_3d_target_create(&wdata->target, didata->layer, &didata->surface[0],
   9.767                 surfaces, didata->current_mode.w, didata->current_mode.h,
   9.768                 qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format));
   9.769 -
   9.770        if (gfstatus!=GF_ERR_OK)
   9.771        {
   9.772           /* Destroy just created context */
   9.773 @@ -1143,7 +1635,7 @@
   9.774        }
   9.775  
   9.776        /* Create target rendering surface on whole screen */
   9.777 -      wdata->gles_surface=eglCreateWindowSurface(gfdata->egldisplay, wdata->gles_config, wdata->target, NULL);
   9.778 +      wdata->gles_surface=eglCreateWindowSurface(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], wdata->target, NULL);
   9.779        if (wdata->gles_surface==EGL_NO_SURFACE)
   9.780        {
   9.781           /* Destroy 3d target */
   9.782 @@ -1192,7 +1684,39 @@
   9.783        /* Always clear stereo enable, since OpenGL ES do not supports stereo */
   9.784        _this->gl_config.stereo=0;
   9.785  
   9.786 -      /* Failed to create GL ES context */
   9.787 +      /* Get back samples and samplebuffers configurations. Rest framebuffer */
   9.788 +      /* parameters could be obtained through the OpenGL ES API              */
   9.789 +      status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLES, &attr_value);
   9.790 +      if (status==EGL_TRUE)
   9.791 +      {
   9.792 +         _this->gl_config.multisamplesamples=attr_value;
   9.793 +      }
   9.794 +      status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLE_BUFFERS, &attr_value);
   9.795 +      if (status==EGL_TRUE)
   9.796 +      {
   9.797 +         _this->gl_config.multisamplebuffers=attr_value;
   9.798 +      }
   9.799 +
   9.800 +      /* Get back stencil and depth buffer sizes */
   9.801 +      status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_DEPTH_SIZE, &attr_value);
   9.802 +      if (status==EGL_TRUE)
   9.803 +      {
   9.804 +         _this->gl_config.depth_size=attr_value;
   9.805 +      }
   9.806 +      status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_STENCIL_SIZE, &attr_value);
   9.807 +      if (status==EGL_TRUE)
   9.808 +      {
   9.809 +         _this->gl_config.stencil_size=attr_value;
   9.810 +      }
   9.811 +
   9.812 +      /* Restore cursor if it was visible */
   9.813 +      if (didata->cursor_visible==SDL_TRUE)
   9.814 +      {
   9.815 +         gf_cursor_set(didata->display, 0, &didata->cursor);
   9.816 +         gf_cursor_enable(didata->display, 0);
   9.817 +      }
   9.818 +
   9.819 +      /* GL ES context was successfully created */
   9.820        return wdata->gles_context;
   9.821     #else
   9.822        SDL_SetError("GF: OpenGL ES support is not compiled in");
   9.823 @@ -1283,6 +1807,10 @@
   9.824        SDL_VideoData*   gfdata=(SDL_VideoData*)_this->driverdata;
   9.825        SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
   9.826  
   9.827 +      /* Finish all drawings */
   9.828 +      glFinish();
   9.829 +
   9.830 +      /* Swap buffers */
   9.831        eglSwapBuffers(gfdata->egldisplay, wdata->gles_surface);
   9.832     #else
   9.833        SDL_SetError("GF: OpenGL ES support is not compiled in");
    10.1 --- a/src/video/qnxgf/SDL_qnxgf.h	Tue Apr 28 04:30:52 2009 +0000
    10.2 +++ b/src/video/qnxgf/SDL_qnxgf.h	Tue Apr 28 04:33:30 2009 +0000
    10.3 @@ -48,7 +48,8 @@
    10.4     #endif /* SDL_VIDEO_OPENGL_ES */
    10.5  } SDL_VideoData;
    10.6  
    10.7 -#define SDL_VIDEO_GF_DEVICENAME_MAX 257
    10.8 +#define SDL_VIDEO_GF_DEVICENAME_MAX  257
    10.9 +#define SDL_VIDEO_GF_MAX_CURSOR_SIZE 128
   10.10  
   10.11  typedef struct SDL_DisplayData
   10.12  {
   10.13 @@ -61,15 +62,23 @@
   10.14     uint32_t          caps;             /* Device capabilities                */
   10.15     SDL_bool          layer_attached;   /* Layer attach status                */
   10.16     gf_layer_t        layer;            /* Graphics layer to which attached   */
   10.17 +   gf_surface_t      surface[3];       /* Visible surface on the display     */
   10.18 +   SDL_bool          cursor_visible;   /* SDL_TRUE if cursor visible         */
   10.19 +   gf_cursor_t       cursor;           /* Cursor shape which was set last    */
   10.20  } SDL_DisplayData;
   10.21  
   10.22 +/* Maximum amount of OpenGL ES framebuffer configurations */
   10.23 +#define SDL_VIDEO_GF_OPENGLES_CONFS 32
   10.24 +
   10.25  typedef struct SDL_WindowData
   10.26  {
   10.27     SDL_bool   uses_gles;               /* true if window support OpenGL ES   */
   10.28     #if defined(SDL_VIDEO_OPENGL_ES)
   10.29        gf_3d_target_t target;           /* OpenGL ES window target            */
   10.30        SDL_bool   target_created;       /* GF 3D target is created if true    */
   10.31 -      EGLConfig  gles_config;          /* OpenGL ES framebuffer configuration*/
   10.32 +      EGLConfig  gles_configs[SDL_VIDEO_GF_OPENGLES_CONFS];
   10.33 +                                       /* OpenGL ES framebuffer confs        */
   10.34 +      EGLint     gles_config;          /* Config index in the array of cfgs  */
   10.35        EGLContext gles_context;         /* OpenGL ES context                  */
   10.36        EGLint     gles_attributes[256]; /* OpenGL ES attributes for context   */
   10.37        EGLSurface gles_surface;         /* OpenGL ES target rendering surface */
   10.38 @@ -103,16 +112,16 @@
   10.39  /****************************************************************************/
   10.40  
   10.41  /* Display and window functions */
   10.42 -int qnxgf_videoinit(_THIS);
   10.43 +int  qnxgf_videoinit(_THIS);
   10.44  void qnxgf_videoquit(_THIS);
   10.45  void qnxgf_getdisplaymodes(_THIS);
   10.46 -int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode);
   10.47 -int qnxgf_setdisplaypalette(_THIS, SDL_Palette* palette);
   10.48 -int qnxgf_getdisplaypalette(_THIS, SDL_Palette* palette);
   10.49 -int qnxgf_setdisplaygammaramp(_THIS, Uint16* ramp);
   10.50 -int qnxgf_getdisplaygammaramp(_THIS, Uint16* ramp);
   10.51 -int qnxgf_createwindow(_THIS, SDL_Window* window);
   10.52 -int qnxgf_createwindowfrom(_THIS, SDL_Window* window, const void* data);
   10.53 +int  qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode);
   10.54 +int  qnxgf_setdisplaypalette(_THIS, SDL_Palette* palette);
   10.55 +int  qnxgf_getdisplaypalette(_THIS, SDL_Palette* palette);
   10.56 +int  qnxgf_setdisplaygammaramp(_THIS, Uint16* ramp);
   10.57 +int  qnxgf_getdisplaygammaramp(_THIS, Uint16* ramp);
   10.58 +int  qnxgf_createwindow(_THIS, SDL_Window* window);
   10.59 +int  qnxgf_createwindowfrom(_THIS, SDL_Window* window, const void* data);
   10.60  void qnxgf_setwindowtitle(_THIS, SDL_Window* window);
   10.61  void qnxgf_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon);
   10.62  void qnxgf_setwindowposition(_THIS, SDL_Window* window);