indent
authorSam Lantinga <slouken@libsdl.org>
Sat, 23 May 2009 22:41:08 +0000
changeset 31397f684f249ec9
parent 3125 d71d8ceda8b3
child 3140 9ef99b844c60
child 3160 210e209b87cc
child 3710 8600c345cd77
indent
XCodeiPhoneOS/Demos/src/keyboard.c
XCodeiPhoneOS/Demos/src/mixer.c
include/SDL_opengles.h
include/SDL_video.h
src/SDL_compat.c
src/audio/SDL_audio.c
src/audio/qsa/SDL_qsa_audio.c
src/audio/qsa/SDL_qsa_audio.h
src/video/SDL_renderer_gles.c
src/video/SDL_video.c
src/video/nds/SDL_ndsrender.c
src/video/photon/SDL_photon.c
src/video/photon/SDL_photon.h
src/video/photon/SDL_photon_input.c
src/video/photon/SDL_photon_input.h
src/video/photon/SDL_photon_keycodes.h
src/video/photon/SDL_photon_pixelfmt.c
src/video/photon/SDL_photon_render.c
src/video/photon/SDL_photon_render.h
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_pixelfmt.c
src/video/qnxgf/SDL_gf_pixelfmt.h
src/video/qnxgf/SDL_gf_render.c
src/video/qnxgf/SDL_gf_render.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
src/video/win32/SDL_gdirender.c
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32gamma.c
src/video/win32/SDL_win32modes.c
src/video/win32/SDL_win32opengl.c
src/video/win32/SDL_win32window.c
src/video/x11/SDL_x11opengl.c
test/testdyngles.c
test/testgl2.c
test/testgles.c
     1.1 --- a/XCodeiPhoneOS/Demos/src/keyboard.c	Fri May 15 15:47:37 2009 +0000
     1.2 +++ b/XCodeiPhoneOS/Demos/src/keyboard.c	Sat May 23 22:41:08 2009 +0000
     1.3 @@ -174,7 +174,8 @@
     1.4  drawBlank(int x, int y)
     1.5  {
     1.6      SDL_Rect rect = { x, y, GLYPH_SIZE_SCREEN, GLYPH_SIZE_SCREEN };
     1.7 -    SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b, bg_color.unused);
     1.8 +    SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b,
     1.9 +                           bg_color.unused);
    1.10      SDL_RenderFill(&rect);
    1.11  }
    1.12  
    1.13 @@ -254,7 +255,8 @@
    1.14      loadFont();
    1.15  
    1.16      /* draw the background, we'll just paint over it */
    1.17 -    SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b, bg_color.unused);
    1.18 +    SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b,
    1.19 +                           bg_color.unused);
    1.20      SDL_RenderFill(NULL);
    1.21      SDL_RenderPresent();
    1.22  
     2.1 --- a/XCodeiPhoneOS/Demos/src/mixer.c	Fri May 15 15:47:37 2009 +0000
     2.2 +++ b/XCodeiPhoneOS/Demos/src/mixer.c	Sat May 23 22:41:08 2009 +0000
     2.3 @@ -168,7 +168,7 @@
     2.4  {
     2.5      int i;
     2.6      SDL_SetRenderDrawColor(50, 50, 50, 255);
     2.7 -    SDL_RenderFill(NULL);      /* draw background (gray) */
     2.8 +    SDL_RenderFill(NULL);       /* draw background (gray) */
     2.9      /* draw the drum buttons */
    2.10      for (i = 0; i < NUM_DRUMS; i++) {
    2.11          SDL_Color color =
     3.1 --- a/include/SDL_opengles.h	Fri May 15 15:47:37 2009 +0000
     3.2 +++ b/include/SDL_opengles.h	Sat May 23 22:41:08 2009 +0000
     3.3 @@ -50,7 +50,7 @@
     3.4  
     3.5  #ifndef GL_API
     3.6  #define GL_API
     3.7 -#endif /* GL_API */
     3.8 +#endif                          /* GL_API */
     3.9  
    3.10  /*
    3.11  ** License Applicability. Except to the extent portions of this file are
    3.12 @@ -347,10 +347,10 @@
    3.13  /* OpenGL ES 1.0 defines, they gone in 1.1 and 2.0 */
    3.14  #ifndef GL_MAX_ELEMENTS_VERTICES
    3.15  #define GL_MAX_ELEMENTS_VERTICES          0x80E8
    3.16 -#endif /* GL_MAX_ELEMENTS_VERTICES */
    3.17 +#endif                          /* GL_MAX_ELEMENTS_VERTICES */
    3.18  #ifndef GL_MAX_ELEMENTS_INDICES
    3.19  #define GL_MAX_ELEMENTS_INDICES           0x80E9
    3.20 -#endif /* GL_MAX_ELEMENTS_INDICES */
    3.21 +#endif                          /* GL_MAX_ELEMENTS_INDICES */
    3.22  
    3.23  /* GetTextureParameter */
    3.24  /*      GL_TEXTURE_MAG_FILTER */
    3.25 @@ -669,7 +669,7 @@
    3.26  /* GL_OES_draw_texture */
    3.27  #ifndef GL_OES_draw_texture
    3.28  #define GL_TEXTURE_CROP_RECT_OES                                0x8B9D
    3.29 -#endif /* GL_OES_draw_texture */
    3.30 +#endif                          /* GL_OES_draw_texture */
    3.31  
    3.32  /*  GL_OES_vertex_buffer_object */
    3.33  #ifndef GL_OES_vertex_buffer_object
    3.34 @@ -687,7 +687,7 @@
    3.35  #define GL_BUFFER_SIZE_OES                                      0x8764
    3.36  #define GL_BUFFER_USAGE_OES                                     0x8765
    3.37  #define GL_BUFFER_ACCESS_OES                                    0x88BB
    3.38 -#endif /* GL_OES_vertex_buffer_object */
    3.39 +#endif                          /* GL_OES_vertex_buffer_object */
    3.40  
    3.41  /*************************************************************/
    3.42  
    3.43 @@ -973,8 +973,9 @@
    3.44  /* GL_OES_query_matrix */
    3.45  #ifndef GL_OES_query_matrix
    3.46  #define GL_OES_query_matrix 1
    3.47 -    GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16]);
    3.48 -#endif /* GL_OES_query_matrix */
    3.49 +    GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES(GLfixed mantissa[16],
    3.50 +                                                    GLint exponent[16]);
    3.51 +#endif                          /* GL_OES_query_matrix */
    3.52  
    3.53  /* GL_OES_point_sprite */
    3.54  #ifndef GL_OES_point_sprite
    3.55 @@ -984,26 +985,35 @@
    3.56  /* GL_OES_draw_texture */
    3.57  #ifndef GL_OES_draw_texture
    3.58  #define GL_OES_draw_texture 1
    3.59 -    GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height);
    3.60 -    GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height);
    3.61 -    GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height);
    3.62 -    GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort *coords);
    3.63 -    GL_API void GL_APIENTRY glDrawTexivOES (const GLint *coords);
    3.64 -    GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed *coords);
    3.65 -    GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height);
    3.66 -    GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat *coords);
    3.67 -#endif /* GL_OES_draw_texture */
    3.68 +    GL_API void GL_APIENTRY glDrawTexsOES(GLshort x, GLshort y, GLshort z,
    3.69 +                                          GLshort width, GLshort height);
    3.70 +    GL_API void GL_APIENTRY glDrawTexiOES(GLint x, GLint y, GLint z,
    3.71 +                                          GLint width, GLint height);
    3.72 +    GL_API void GL_APIENTRY glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z,
    3.73 +                                          GLfixed width, GLfixed height);
    3.74 +    GL_API void GL_APIENTRY glDrawTexsvOES(const GLshort * coords);
    3.75 +    GL_API void GL_APIENTRY glDrawTexivOES(const GLint * coords);
    3.76 +    GL_API void GL_APIENTRY glDrawTexxvOES(const GLfixed * coords);
    3.77 +    GL_API void GL_APIENTRY glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z,
    3.78 +                                          GLfloat width, GLfloat height);
    3.79 +    GL_API void GL_APIENTRY glDrawTexfvOES(const GLfloat * coords);
    3.80 +#endif                          /* GL_OES_draw_texture */
    3.81  
    3.82  /* GL_OES_single_precision */
    3.83  #ifndef GL_OES_single_precision
    3.84  #define GL_OES_single_precision 1
    3.85 -    GL_API void GL_APIENTRY glDepthRangefOES (GLclampf zNear, GLclampf zFar);
    3.86 -    GL_API void GL_APIENTRY glFrustumfOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
    3.87 -    GL_API void GL_APIENTRY glOrthofOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar);
    3.88 -    GL_API void GL_APIENTRY glClipPlanefOES (GLenum plane, const GLfloat *equation);
    3.89 -    GL_API void GL_APIENTRY glGetClipPlanefOES (GLenum pname, GLfloat eqn[4]);
    3.90 -    GL_API void GL_APIENTRY glClearDepthfOES (GLclampf depth);
    3.91 -#endif /* GL_OES_single_precision */
    3.92 +    GL_API void GL_APIENTRY glDepthRangefOES(GLclampf zNear, GLclampf zFar);
    3.93 +    GL_API void GL_APIENTRY glFrustumfOES(GLfloat left, GLfloat right,
    3.94 +                                          GLfloat bottom, GLfloat top,
    3.95 +                                          GLfloat zNear, GLfloat zFar);
    3.96 +    GL_API void GL_APIENTRY glOrthofOES(GLfloat left, GLfloat right,
    3.97 +                                        GLfloat bottom, GLfloat top,
    3.98 +                                        GLfloat zNear, GLfloat zFar);
    3.99 +    GL_API void GL_APIENTRY glClipPlanefOES(GLenum plane,
   3.100 +                                            const GLfloat * equation);
   3.101 +    GL_API void GL_APIENTRY glGetClipPlanefOES(GLenum pname, GLfloat eqn[4]);
   3.102 +    GL_API void GL_APIENTRY glClearDepthfOES(GLclampf depth);
   3.103 +#endif                          /* GL_OES_single_precision */
   3.104  
   3.105  /* GL_OES_vertex_buffer_object */
   3.106  #ifndef GL_OES_vertex_buffer_object
   3.107 @@ -1012,10 +1022,12 @@
   3.108      GL_API void APIENTRY glDeleteBuffersOES(GLsizei, const GLuint *);
   3.109      GL_API void APIENTRY glGenBuffersOES(GLsizei, GLuint *);
   3.110      GL_API GLboolean APIENTRY glIsBufferOES(GLuint);
   3.111 -    GL_API void APIENTRY glBufferDataOES(GLenum, GLsizeiptr, const GLvoid *, GLenum);
   3.112 -    GL_API void APIENTRY glBufferSubDataOES(GLenum, GLintptr, GLsizeiptr, const GLvoid *);
   3.113 +    GL_API void APIENTRY glBufferDataOES(GLenum, GLsizeiptr, const GLvoid *,
   3.114 +                                         GLenum);
   3.115 +    GL_API void APIENTRY glBufferSubDataOES(GLenum, GLintptr, GLsizeiptr,
   3.116 +                                            const GLvoid *);
   3.117      GL_API void APIENTRY glGetBufferParameterivOES(GLenum, GLenum, GLint *);
   3.118 -#endif /* GL_OES_vertex_buffer_object */
   3.119 +#endif                          /* GL_OES_vertex_buffer_object */
   3.120  
   3.121  #ifdef __cplusplus
   3.122  }
     4.1 --- a/include/SDL_video.h	Fri May 15 15:47:37 2009 +0000
     4.2 +++ b/include/SDL_video.h	Sat May 23 22:41:08 2009 +0000
     4.3 @@ -271,8 +271,8 @@
     4.4      SDL_GL_MULTISAMPLESAMPLES,
     4.5      SDL_GL_ACCELERATED_VISUAL,
     4.6      SDL_GL_RETAINED_BACKING,
     4.7 -	SDL_GL_CONTEXT_MAJOR_VERSION,
     4.8 -	SDL_GL_CONTEXT_MINOR_VERSION
     4.9 +    SDL_GL_CONTEXT_MAJOR_VERSION,
    4.10 +    SDL_GL_CONTEXT_MINOR_VERSION
    4.11  } SDL_GLattr;
    4.12  
    4.13  
     5.1 --- a/src/SDL_compat.c	Fri May 15 15:47:37 2009 +0000
     5.2 +++ b/src/SDL_compat.c	Sat May 23 22:41:08 2009 +0000
     5.3 @@ -494,7 +494,7 @@
     5.4              return NULL;
     5.5          }
     5.6      }
     5.7 -    
     5.8 +
     5.9      SDL_GetDesktopDisplayMode(&desktop_mode);
    5.10  
    5.11      if (width == 0) {
     6.1 --- a/src/audio/SDL_audio.c	Fri May 15 15:47:37 2009 +0000
     6.2 +++ b/src/audio/SDL_audio.c	Sat May 23 22:41:08 2009 +0000
     6.3 @@ -477,7 +477,8 @@
     6.4                      /* Wait for an audio buffer to become available */
     6.5                      current_audio.impl.WaitDevice(device);
     6.6                  } else {
     6.7 -                    SDL_Delay((device->spec.samples * 1000) / device->spec.freq);
     6.8 +                    SDL_Delay((device->spec.samples * 1000) /
     6.9 +                              device->spec.freq);
    6.10                  }
    6.11              }
    6.12  
    6.13 @@ -525,7 +526,7 @@
    6.14                  /* Wait for an audio buffer to become available */
    6.15                  current_audio.impl.WaitDevice(device);
    6.16              } else {
    6.17 -            	SDL_Delay((device->spec.samples * 1000) / device->spec.freq);
    6.18 +                SDL_Delay((device->spec.samples * 1000) / device->spec.freq);
    6.19              }
    6.20          }
    6.21      }
     7.1 --- a/src/audio/qsa/SDL_qsa_audio.c	Fri May 15 15:47:37 2009 +0000
     7.2 +++ b/src/audio/qsa/SDL_qsa_audio.c	Sat May 23 22:41:08 2009 +0000
     7.3 @@ -59,888 +59,840 @@
     7.4  
     7.5  struct BuggyCards
     7.6  {
     7.7 -    char* cardname;
     7.8 +    char *cardname;
     7.9      unsigned long bugtype;
    7.10  };
    7.11  
    7.12  #define QSA_WA_CARDS             3
    7.13  #define QSA_MAX_CARD_NAME_LENGTH 33
    7.14  
    7.15 -struct BuggyCards buggycards[QSA_WA_CARDS]=
    7.16 -{
    7.17 -   {"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
    7.18 -   {"Vortex 8820", QSA_MMAP_WORKAROUND},
    7.19 -   {"Vortex 8830", QSA_MMAP_WORKAROUND},
    7.20 +struct BuggyCards buggycards[QSA_WA_CARDS] = {
    7.21 +    {"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
    7.22 +    {"Vortex 8820", QSA_MMAP_WORKAROUND},
    7.23 +    {"Vortex 8830", QSA_MMAP_WORKAROUND},
    7.24  };
    7.25  
    7.26  /* List of found devices */
    7.27  #define QSA_MAX_DEVICES       32
    7.28 -#define QSA_MAX_NAME_LENGTH   81+16 /* Hardcoded in QSA, can't be changed */
    7.29 +#define QSA_MAX_NAME_LENGTH   81+16     /* Hardcoded in QSA, can't be changed */
    7.30  
    7.31  typedef struct _QSA_Device
    7.32  {
    7.33 -   char  name[QSA_MAX_NAME_LENGTH];   /* Long audio device name for SDL  */
    7.34 -   int   cardno;
    7.35 -   int   deviceno;
    7.36 +    char name[QSA_MAX_NAME_LENGTH];     /* Long audio device name for SDL  */
    7.37 +    int cardno;
    7.38 +    int deviceno;
    7.39  } QSA_Device;
    7.40  
    7.41  QSA_Device qsa_playback_device[QSA_MAX_DEVICES];
    7.42 -uint32_t   qsa_playback_devices;
    7.43 +uint32_t qsa_playback_devices;
    7.44  
    7.45  QSA_Device qsa_capture_device[QSA_MAX_DEVICES];
    7.46 -uint32_t   qsa_capture_devices;
    7.47 +uint32_t qsa_capture_devices;
    7.48  
    7.49 -static inline void QSA_SetError(const char* fn, int status)
    7.50 +static inline void
    7.51 +QSA_SetError(const char *fn, int status)
    7.52  {
    7.53 -   SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status));
    7.54 +    SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status));
    7.55  }
    7.56  
    7.57  /* card names check to apply the workarounds */
    7.58 -static int QSA_CheckBuggyCards(_THIS, unsigned long checkfor)
    7.59 +static int
    7.60 +QSA_CheckBuggyCards(_THIS, unsigned long checkfor)
    7.61  {
    7.62 -   char scardname[QSA_MAX_CARD_NAME_LENGTH];
    7.63 -   int it;
    7.64 +    char scardname[QSA_MAX_CARD_NAME_LENGTH];
    7.65 +    int it;
    7.66  
    7.67 -   if (snd_card_get_name(this->hidden->cardno, scardname, QSA_MAX_CARD_NAME_LENGTH-1)<0)
    7.68 -   {
    7.69 -      return 0;
    7.70 -   }
    7.71 +    if (snd_card_get_name
    7.72 +        (this->hidden->cardno, scardname, QSA_MAX_CARD_NAME_LENGTH - 1) < 0) {
    7.73 +        return 0;
    7.74 +    }
    7.75  
    7.76 -   for (it=0; it<QSA_WA_CARDS; it++)
    7.77 -   {
    7.78 -      if (SDL_strcmp(buggycards[it].cardname, scardname)==0)
    7.79 -      {
    7.80 -         if (buggycards[it].bugtype==checkfor)
    7.81 -         {
    7.82 -            return 1;
    7.83 -         }
    7.84 -      }
    7.85 -   }
    7.86 +    for (it = 0; it < QSA_WA_CARDS; it++) {
    7.87 +        if (SDL_strcmp(buggycards[it].cardname, scardname) == 0) {
    7.88 +            if (buggycards[it].bugtype == checkfor) {
    7.89 +                return 1;
    7.90 +            }
    7.91 +        }
    7.92 +    }
    7.93  
    7.94 -   return 0;
    7.95 +    return 0;
    7.96  }
    7.97  
    7.98 -static void QSA_ThreadInit(_THIS)
    7.99 +static void
   7.100 +QSA_ThreadInit(_THIS)
   7.101  {
   7.102 -   struct sched_param param;
   7.103 -   int status;
   7.104 +    struct sched_param param;
   7.105 +    int status;
   7.106  
   7.107 -   /* Increase default 10 priority to 25 to avoid jerky sound */
   7.108 -   status=SchedGet(0, 0, &param);
   7.109 -   param.sched_priority=param.sched_curpriority + 15;
   7.110 -   status=SchedSet(0, 0, SCHED_NOCHANGE, &param);
   7.111 +    /* Increase default 10 priority to 25 to avoid jerky sound */
   7.112 +    status = SchedGet(0, 0, &param);
   7.113 +    param.sched_priority = param.sched_curpriority + 15;
   7.114 +    status = SchedSet(0, 0, SCHED_NOCHANGE, &param);
   7.115  }
   7.116  
   7.117  /* PCM channel parameters initialize function */
   7.118 -static void QSA_InitAudioParams(snd_pcm_channel_params_t* cpars)
   7.119 +static void
   7.120 +QSA_InitAudioParams(snd_pcm_channel_params_t * cpars)
   7.121  {
   7.122 -   SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
   7.123 +    SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
   7.124  
   7.125 -   cpars->channel=SND_PCM_CHANNEL_PLAYBACK;
   7.126 -   cpars->mode=SND_PCM_MODE_BLOCK;
   7.127 -   cpars->start_mode=SND_PCM_START_DATA;
   7.128 -   cpars->stop_mode=SND_PCM_STOP_STOP;
   7.129 -   cpars->format.format=SND_PCM_SFMT_S16_LE;
   7.130 -   cpars->format.interleave=1;
   7.131 -   cpars->format.rate=DEFAULT_CPARAMS_RATE;
   7.132 -   cpars->format.voices=DEFAULT_CPARAMS_VOICES;
   7.133 -   cpars->buf.block.frag_size=DEFAULT_CPARAMS_FRAG_SIZE;
   7.134 -   cpars->buf.block.frags_min=DEFAULT_CPARAMS_FRAGS_MIN;
   7.135 -   cpars->buf.block.frags_max=DEFAULT_CPARAMS_FRAGS_MAX;
   7.136 +    cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
   7.137 +    cpars->mode = SND_PCM_MODE_BLOCK;
   7.138 +    cpars->start_mode = SND_PCM_START_DATA;
   7.139 +    cpars->stop_mode = SND_PCM_STOP_STOP;
   7.140 +    cpars->format.format = SND_PCM_SFMT_S16_LE;
   7.141 +    cpars->format.interleave = 1;
   7.142 +    cpars->format.rate = DEFAULT_CPARAMS_RATE;
   7.143 +    cpars->format.voices = DEFAULT_CPARAMS_VOICES;
   7.144 +    cpars->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
   7.145 +    cpars->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
   7.146 +    cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
   7.147  }
   7.148  
   7.149  /* This function waits until it is possible to write a full sound buffer */
   7.150 -static void QSA_WaitDevice(_THIS)
   7.151 +static void
   7.152 +QSA_WaitDevice(_THIS)
   7.153  {
   7.154 -   fd_set wfds;
   7.155 -   fd_set rfds;
   7.156 -   int selectret;
   7.157 -   struct timeval timeout;
   7.158 +    fd_set wfds;
   7.159 +    fd_set rfds;
   7.160 +    int selectret;
   7.161 +    struct timeval timeout;
   7.162  
   7.163 -   if (!this->hidden->iscapture)
   7.164 -   {
   7.165 -      FD_ZERO(&wfds);
   7.166 -      FD_SET(this->hidden->audio_fd, &wfds);
   7.167 -   }
   7.168 -   else
   7.169 -   {
   7.170 -      FD_ZERO(&rfds);
   7.171 -      FD_SET(this->hidden->audio_fd, &rfds);
   7.172 -   }
   7.173 +    if (!this->hidden->iscapture) {
   7.174 +        FD_ZERO(&wfds);
   7.175 +        FD_SET(this->hidden->audio_fd, &wfds);
   7.176 +    } else {
   7.177 +        FD_ZERO(&rfds);
   7.178 +        FD_SET(this->hidden->audio_fd, &rfds);
   7.179 +    }
   7.180  
   7.181 -   do {
   7.182 -      /* Setup timeout for playing one fragment equal to 2 seconds          */
   7.183 -      /* If timeout occured than something wrong with hardware or driver    */
   7.184 -      /* For example, Vortex 8820 audio driver stucks on second DAC because */
   7.185 -      /* it doesn't exist !                                                 */
   7.186 -      timeout.tv_sec=2;
   7.187 -      timeout.tv_usec=0;
   7.188 -      this->hidden->timeout_on_wait=0;
   7.189 +    do {
   7.190 +        /* Setup timeout for playing one fragment equal to 2 seconds          */
   7.191 +        /* If timeout occured than something wrong with hardware or driver    */
   7.192 +        /* For example, Vortex 8820 audio driver stucks on second DAC because */
   7.193 +        /* it doesn't exist !                                                 */
   7.194 +        timeout.tv_sec = 2;
   7.195 +        timeout.tv_usec = 0;
   7.196 +        this->hidden->timeout_on_wait = 0;
   7.197  
   7.198 -      if (!this->hidden->iscapture)
   7.199 -      {
   7.200 -         selectret=select(this->hidden->audio_fd+1, NULL, &wfds, NULL, &timeout);
   7.201 -      }
   7.202 -      else
   7.203 -      {
   7.204 -         selectret=select(this->hidden->audio_fd+1, &rfds, NULL, NULL, &timeout);
   7.205 -      }
   7.206 +        if (!this->hidden->iscapture) {
   7.207 +            selectret =
   7.208 +                select(this->hidden->audio_fd + 1, NULL, &wfds, NULL,
   7.209 +                       &timeout);
   7.210 +        } else {
   7.211 +            selectret =
   7.212 +                select(this->hidden->audio_fd + 1, &rfds, NULL, NULL,
   7.213 +                       &timeout);
   7.214 +        }
   7.215  
   7.216 -      switch(selectret)
   7.217 -      {
   7.218 -         case -1:
   7.219 -              {
   7.220 -                 SDL_SetError("QSA: select() failed: %s\n", strerror(errno));
   7.221 -                 return;
   7.222 -              }
   7.223 -              break;
   7.224 -         case 0:
   7.225 -              {
   7.226 -                 SDL_SetError("QSA: timeout on buffer waiting occured\n");
   7.227 -                 this->hidden->timeout_on_wait=1;
   7.228 -                 return;
   7.229 -              }
   7.230 -              break;
   7.231 -         default:
   7.232 -              {
   7.233 -                 if (!this->hidden->iscapture)
   7.234 -                 {
   7.235 -                    if (FD_ISSET(this->hidden->audio_fd, &wfds))
   7.236 -                    {
   7.237 -                       return;
   7.238 +        switch (selectret) {
   7.239 +        case -1:
   7.240 +            {
   7.241 +                SDL_SetError("QSA: select() failed: %s\n", strerror(errno));
   7.242 +                return;
   7.243 +            }
   7.244 +            break;
   7.245 +        case 0:
   7.246 +            {
   7.247 +                SDL_SetError("QSA: timeout on buffer waiting occured\n");
   7.248 +                this->hidden->timeout_on_wait = 1;
   7.249 +                return;
   7.250 +            }
   7.251 +            break;
   7.252 +        default:
   7.253 +            {
   7.254 +                if (!this->hidden->iscapture) {
   7.255 +                    if (FD_ISSET(this->hidden->audio_fd, &wfds)) {
   7.256 +                        return;
   7.257                      }
   7.258 -                 }
   7.259 -                 else
   7.260 -                 {
   7.261 -                    if (FD_ISSET(this->hidden->audio_fd, &rfds))
   7.262 -                    {
   7.263 -                       return;
   7.264 +                } else {
   7.265 +                    if (FD_ISSET(this->hidden->audio_fd, &rfds)) {
   7.266 +                        return;
   7.267                      }
   7.268 -                 }
   7.269 -              }
   7.270 -              break;
   7.271 -      }
   7.272 -   } while (1);
   7.273 +                }
   7.274 +            }
   7.275 +            break;
   7.276 +        }
   7.277 +    } while (1);
   7.278  }
   7.279  
   7.280 -static void QSA_PlayDevice(_THIS)
   7.281 +static void
   7.282 +QSA_PlayDevice(_THIS)
   7.283  {
   7.284 -   snd_pcm_channel_status_t cstatus;
   7.285 -   int   written;
   7.286 -   int   status;
   7.287 -   int   towrite;
   7.288 -   void* pcmbuffer;
   7.289 +    snd_pcm_channel_status_t cstatus;
   7.290 +    int written;
   7.291 +    int status;
   7.292 +    int towrite;
   7.293 +    void *pcmbuffer;
   7.294  
   7.295 -   if ((!this->enabled) || (!this->hidden))
   7.296 -   {
   7.297 -      return;
   7.298 -   }
   7.299 +    if ((!this->enabled) || (!this->hidden)) {
   7.300 +        return;
   7.301 +    }
   7.302  
   7.303 -   towrite = this->spec.size;
   7.304 -   pcmbuffer = this->hidden->pcm_buf;
   7.305 +    towrite = this->spec.size;
   7.306 +    pcmbuffer = this->hidden->pcm_buf;
   7.307  
   7.308 -   /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
   7.309 -   do {
   7.310 -      written=snd_pcm_plugin_write(this->hidden->audio_handle, pcmbuffer, towrite);
   7.311 -      if (written!=towrite)
   7.312 -      {
   7.313 -         /* Check if samples playback got stuck somewhere in hardware or in */
   7.314 -         /* the audio device driver */
   7.315 -         if ((errno==EAGAIN) && (written==0))
   7.316 -         {
   7.317 -            if (this->hidden->timeout_on_wait!=0)
   7.318 -            {
   7.319 -               SDL_SetError("QSA: buffer playback timeout\n");
   7.320 -               return;
   7.321 +    /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
   7.322 +    do {
   7.323 +        written =
   7.324 +            snd_pcm_plugin_write(this->hidden->audio_handle, pcmbuffer,
   7.325 +                                 towrite);
   7.326 +        if (written != towrite) {
   7.327 +            /* Check if samples playback got stuck somewhere in hardware or in */
   7.328 +            /* the audio device driver */
   7.329 +            if ((errno == EAGAIN) && (written == 0)) {
   7.330 +                if (this->hidden->timeout_on_wait != 0) {
   7.331 +                    SDL_SetError("QSA: buffer playback timeout\n");
   7.332 +                    return;
   7.333 +                }
   7.334              }
   7.335 -         }
   7.336  
   7.337 -         /* Check for errors or conditions */
   7.338 -         if ((errno==EAGAIN)||(errno==EWOULDBLOCK))
   7.339 -         {
   7.340 -            /* Let a little CPU time go by and try to write again */
   7.341 -            SDL_Delay(1);
   7.342 +            /* Check for errors or conditions */
   7.343 +            if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
   7.344 +                /* Let a little CPU time go by and try to write again */
   7.345 +                SDL_Delay(1);
   7.346  
   7.347 -            /* if we wrote some data */
   7.348 -            towrite-=written;
   7.349 -            pcmbuffer+=written*this->spec.channels;
   7.350 -            continue;
   7.351 -         }
   7.352 -         else
   7.353 -         {
   7.354 -            if ((errno==EINVAL)||(errno==EIO))
   7.355 -            {
   7.356 -               SDL_memset(&cstatus, 0, sizeof(cstatus));
   7.357 -               if (!this->hidden->iscapture)
   7.358 -               {
   7.359 -                  cstatus.channel=SND_PCM_CHANNEL_PLAYBACK;
   7.360 -               }
   7.361 -               else
   7.362 -               {
   7.363 -                  cstatus.channel=SND_PCM_CHANNEL_CAPTURE;
   7.364 -               }
   7.365 +                /* if we wrote some data */
   7.366 +                towrite -= written;
   7.367 +                pcmbuffer += written * this->spec.channels;
   7.368 +                continue;
   7.369 +            } else {
   7.370 +                if ((errno == EINVAL) || (errno == EIO)) {
   7.371 +                    SDL_memset(&cstatus, 0, sizeof(cstatus));
   7.372 +                    if (!this->hidden->iscapture) {
   7.373 +                        cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
   7.374 +                    } else {
   7.375 +                        cstatus.channel = SND_PCM_CHANNEL_CAPTURE;
   7.376 +                    }
   7.377  
   7.378 -               status=snd_pcm_plugin_status(this->hidden->audio_handle, &cstatus);
   7.379 -               if (status<0)
   7.380 -               {
   7.381 -                  QSA_SetError("snd_pcm_plugin_status", status);
   7.382 -                  return;
   7.383 -               }
   7.384 +                    status =
   7.385 +                        snd_pcm_plugin_status(this->hidden->audio_handle,
   7.386 +                                              &cstatus);
   7.387 +                    if (status < 0) {
   7.388 +                        QSA_SetError("snd_pcm_plugin_status", status);
   7.389 +                        return;
   7.390 +                    }
   7.391  
   7.392 -               if ((cstatus.status==SND_PCM_STATUS_UNDERRUN) ||
   7.393 -                   (cstatus.status==SND_PCM_STATUS_READY))
   7.394 -               {
   7.395 -                  if (!this->hidden->iscapture)
   7.396 -                  {
   7.397 -                     status=snd_pcm_plugin_prepare(this->hidden->audio_handle,
   7.398 -                                                   SND_PCM_CHANNEL_PLAYBACK);
   7.399 -                  }
   7.400 -                  else
   7.401 -                  {
   7.402 -                     status=snd_pcm_plugin_prepare(this->hidden->audio_handle,
   7.403 -                                                   SND_PCM_CHANNEL_CAPTURE);
   7.404 -                  }
   7.405 -                  if (status<0)
   7.406 -                  {
   7.407 -                     QSA_SetError("snd_pcm_plugin_prepare", status);
   7.408 -                     return;
   7.409 -                  }
   7.410 -               }
   7.411 -               continue;
   7.412 +                    if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) ||
   7.413 +                        (cstatus.status == SND_PCM_STATUS_READY)) {
   7.414 +                        if (!this->hidden->iscapture) {
   7.415 +                            status =
   7.416 +                                snd_pcm_plugin_prepare(this->hidden->
   7.417 +                                                       audio_handle,
   7.418 +                                                       SND_PCM_CHANNEL_PLAYBACK);
   7.419 +                        } else {
   7.420 +                            status =
   7.421 +                                snd_pcm_plugin_prepare(this->hidden->
   7.422 +                                                       audio_handle,
   7.423 +                                                       SND_PCM_CHANNEL_CAPTURE);
   7.424 +                        }
   7.425 +                        if (status < 0) {
   7.426 +                            QSA_SetError("snd_pcm_plugin_prepare", status);
   7.427 +                            return;
   7.428 +                        }
   7.429 +                    }
   7.430 +                    continue;
   7.431 +                } else {
   7.432 +                    return;
   7.433 +                }
   7.434              }
   7.435 -            else
   7.436 -            {
   7.437 -                return;
   7.438 -            }
   7.439 -         }
   7.440 -      }
   7.441 -      else
   7.442 -      {
   7.443 -         /* we wrote all remaining data */
   7.444 -         towrite -= written;
   7.445 -         pcmbuffer += written * this->spec.channels;
   7.446 -      }
   7.447 -   } while ((towrite>0) && (this->enabled));
   7.448 +        } else {
   7.449 +            /* we wrote all remaining data */
   7.450 +            towrite -= written;
   7.451 +            pcmbuffer += written * this->spec.channels;
   7.452 +        }
   7.453 +    } while ((towrite > 0) && (this->enabled));
   7.454  
   7.455 -   /* If we couldn't write, assume fatal error for now */
   7.456 -   if (towrite!=0)
   7.457 -   {
   7.458 -      this->enabled=0;
   7.459 -   }
   7.460 +    /* If we couldn't write, assume fatal error for now */
   7.461 +    if (towrite != 0) {
   7.462 +        this->enabled = 0;
   7.463 +    }
   7.464  }
   7.465  
   7.466 -static Uint8* QSA_GetDeviceBuf(_THIS)
   7.467 +static Uint8 *
   7.468 +QSA_GetDeviceBuf(_THIS)
   7.469  {
   7.470 -   return this->hidden->pcm_buf;
   7.471 +    return this->hidden->pcm_buf;
   7.472  }
   7.473  
   7.474 -static void QSA_CloseDevice(_THIS)
   7.475 +static void
   7.476 +QSA_CloseDevice(_THIS)
   7.477  {
   7.478 -   if (this->hidden!=NULL)
   7.479 -   {
   7.480 -      if (this->hidden->audio_handle!=NULL)
   7.481 -      {
   7.482 -         if (!this->hidden->iscapture)
   7.483 -         {
   7.484 -            /* Finish playing available samples */
   7.485 -            snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK);
   7.486 -         }
   7.487 -         else
   7.488 -         {
   7.489 -            /* Cancel unread samples during capture */
   7.490 -            snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE);
   7.491 -         }
   7.492 -         snd_pcm_close(this->hidden->audio_handle);
   7.493 -         this->hidden->audio_handle=NULL;
   7.494 -      }
   7.495 +    if (this->hidden != NULL) {
   7.496 +        if (this->hidden->audio_handle != NULL) {
   7.497 +            if (!this->hidden->iscapture) {
   7.498 +                /* Finish playing available samples */
   7.499 +                snd_pcm_plugin_flush(this->hidden->audio_handle,
   7.500 +                                     SND_PCM_CHANNEL_PLAYBACK);
   7.501 +            } else {
   7.502 +                /* Cancel unread samples during capture */
   7.503 +                snd_pcm_plugin_flush(this->hidden->audio_handle,
   7.504 +                                     SND_PCM_CHANNEL_CAPTURE);
   7.505 +            }
   7.506 +            snd_pcm_close(this->hidden->audio_handle);
   7.507 +            this->hidden->audio_handle = NULL;
   7.508 +        }
   7.509  
   7.510 -      if (this->hidden->pcm_buf!=NULL)
   7.511 -      {
   7.512 -         SDL_FreeAudioMem(this->hidden->pcm_buf);
   7.513 -         this->hidden->pcm_buf=NULL;
   7.514 -      }
   7.515 +        if (this->hidden->pcm_buf != NULL) {
   7.516 +            SDL_FreeAudioMem(this->hidden->pcm_buf);
   7.517 +            this->hidden->pcm_buf = NULL;
   7.518 +        }
   7.519  
   7.520 -      SDL_free(this->hidden);
   7.521 -      this->hidden=NULL;
   7.522 -   }
   7.523 +        SDL_free(this->hidden);
   7.524 +        this->hidden = NULL;
   7.525 +    }
   7.526  }
   7.527  
   7.528 -static int QSA_OpenDevice(_THIS, const char* devname, int iscapture)
   7.529 +static int
   7.530 +QSA_OpenDevice(_THIS, const char *devname, int iscapture)
   7.531  {
   7.532 -   int status=0;
   7.533 -   int format=0;
   7.534 -   SDL_AudioFormat test_format=0;
   7.535 -   int found=0;
   7.536 -   snd_pcm_channel_setup_t  csetup;
   7.537 -   snd_pcm_channel_params_t cparams;
   7.538 +    int status = 0;
   7.539 +    int format = 0;
   7.540 +    SDL_AudioFormat test_format = 0;
   7.541 +    int found = 0;
   7.542 +    snd_pcm_channel_setup_t csetup;
   7.543 +    snd_pcm_channel_params_t cparams;
   7.544  
   7.545 -   /* Initialize all variables that we clean on shutdown */
   7.546 -   this->hidden=(struct SDL_PrivateAudioData*)SDL_calloc(1, (sizeof(struct SDL_PrivateAudioData)));
   7.547 -   if (this->hidden==NULL)
   7.548 -   {
   7.549 -      SDL_OutOfMemory();
   7.550 -      return 0;
   7.551 -   }
   7.552 -   SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
   7.553 +    /* Initialize all variables that we clean on shutdown */
   7.554 +    this->hidden =
   7.555 +        (struct SDL_PrivateAudioData *) SDL_calloc(1,
   7.556 +                                                   (sizeof
   7.557 +                                                    (struct
   7.558 +                                                     SDL_PrivateAudioData)));
   7.559 +    if (this->hidden == NULL) {
   7.560 +        SDL_OutOfMemory();
   7.561 +        return 0;
   7.562 +    }
   7.563 +    SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
   7.564  
   7.565 -   /* Initialize channel transfer parameters to default */
   7.566 -   QSA_InitAudioParams(&cparams);
   7.567 +    /* Initialize channel transfer parameters to default */
   7.568 +    QSA_InitAudioParams(&cparams);
   7.569  
   7.570 -   /* Initialize channel direction: capture or playback */
   7.571 -   this->hidden->iscapture=iscapture;
   7.572 +    /* Initialize channel direction: capture or playback */
   7.573 +    this->hidden->iscapture = iscapture;
   7.574  
   7.575 -   /* Find deviceid and cardid by device name for playback */
   7.576 -   if ((!this->hidden->iscapture) && (devname!=NULL))
   7.577 -   {
   7.578 -      uint32_t device;
   7.579 -      int32_t  status;
   7.580 +    /* Find deviceid and cardid by device name for playback */
   7.581 +    if ((!this->hidden->iscapture) && (devname != NULL)) {
   7.582 +        uint32_t device;
   7.583 +        int32_t status;
   7.584  
   7.585 -      /* Search in the playback devices */
   7.586 -      device=0;
   7.587 -      do {
   7.588 -         status=SDL_strcmp(qsa_playback_device[device].name, devname);
   7.589 -         if (status==0)
   7.590 -         {
   7.591 -            /* Found requested device */
   7.592 -            this->hidden->deviceno=qsa_playback_device[device].deviceno;
   7.593 -            this->hidden->cardno=qsa_playback_device[device].cardno;
   7.594 +        /* Search in the playback devices */
   7.595 +        device = 0;
   7.596 +        do {
   7.597 +            status = SDL_strcmp(qsa_playback_device[device].name, devname);
   7.598 +            if (status == 0) {
   7.599 +                /* Found requested device */
   7.600 +                this->hidden->deviceno = qsa_playback_device[device].deviceno;
   7.601 +                this->hidden->cardno = qsa_playback_device[device].cardno;
   7.602 +                break;
   7.603 +            }
   7.604 +            device++;
   7.605 +            if (device >= qsa_playback_devices) {
   7.606 +                QSA_CloseDevice(this);
   7.607 +                SDL_SetError("No such playback device");
   7.608 +                return 0;
   7.609 +            }
   7.610 +        } while (1);
   7.611 +    }
   7.612 +
   7.613 +    /* Find deviceid and cardid by device name for capture */
   7.614 +    if ((this->hidden->iscapture) && (devname != NULL)) {
   7.615 +        /* Search in the capture devices */
   7.616 +        uint32_t device;
   7.617 +        int32_t status;
   7.618 +
   7.619 +        /* Searching in the playback devices */
   7.620 +        device = 0;
   7.621 +        do {
   7.622 +            status = SDL_strcmp(qsa_capture_device[device].name, devname);
   7.623 +            if (status == 0) {
   7.624 +                /* Found requested device */
   7.625 +                this->hidden->deviceno = qsa_capture_device[device].deviceno;
   7.626 +                this->hidden->cardno = qsa_capture_device[device].cardno;
   7.627 +                break;
   7.628 +            }
   7.629 +            device++;
   7.630 +            if (device >= qsa_capture_devices) {
   7.631 +                QSA_CloseDevice(this);
   7.632 +                SDL_SetError("No such capture device");
   7.633 +                return 0;
   7.634 +            }
   7.635 +        } while (1);
   7.636 +    }
   7.637 +
   7.638 +    /* Check if SDL requested default audio device */
   7.639 +    if (devname == NULL) {
   7.640 +        /* Open system default audio device */
   7.641 +        if (!this->hidden->iscapture) {
   7.642 +            status = snd_pcm_open_preferred(&this->hidden->audio_handle,
   7.643 +                                            &this->hidden->cardno,
   7.644 +                                            &this->hidden->deviceno,
   7.645 +                                            SND_PCM_OPEN_PLAYBACK);
   7.646 +        } else {
   7.647 +            status = snd_pcm_open_preferred(&this->hidden->audio_handle,
   7.648 +                                            &this->hidden->cardno,
   7.649 +                                            &this->hidden->deviceno,
   7.650 +                                            SND_PCM_OPEN_CAPTURE);
   7.651 +        }
   7.652 +    } else {
   7.653 +        /* Open requested audio device */
   7.654 +        if (!this->hidden->iscapture) {
   7.655 +            status =
   7.656 +                snd_pcm_open(&this->hidden->audio_handle,
   7.657 +                             this->hidden->cardno, this->hidden->deviceno,
   7.658 +                             SND_PCM_OPEN_PLAYBACK);
   7.659 +        } else {
   7.660 +            status =
   7.661 +                snd_pcm_open(&this->hidden->audio_handle,
   7.662 +                             this->hidden->cardno, this->hidden->deviceno,
   7.663 +                             SND_PCM_OPEN_CAPTURE);
   7.664 +        }
   7.665 +    }
   7.666 +
   7.667 +    /* Check if requested device is opened */
   7.668 +    if (status < 0) {
   7.669 +        this->hidden->audio_handle = NULL;
   7.670 +        QSA_CloseDevice(this);
   7.671 +        QSA_SetError("snd_pcm_open", status);
   7.672 +        return 0;
   7.673 +    }
   7.674 +
   7.675 +    if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) {
   7.676 +        /* Disable QSA MMAP plugin for buggy audio drivers */
   7.677 +        status =
   7.678 +            snd_pcm_plugin_set_disable(this->hidden->audio_handle,
   7.679 +                                       PLUGIN_DISABLE_MMAP);
   7.680 +        if (status < 0) {
   7.681 +            QSA_CloseDevice(this);
   7.682 +            QSA_SetError("snd_pcm_plugin_set_disable", status);
   7.683 +            return 0;
   7.684 +        }
   7.685 +    }
   7.686 +
   7.687 +    /* Try for a closest match on audio format */
   7.688 +    format = 0;
   7.689 +    /* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */
   7.690 +    found = 0;
   7.691 +
   7.692 +    for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;) {
   7.693 +        /* if match found set format to equivalent QSA format */
   7.694 +        switch (test_format) {
   7.695 +        case AUDIO_U8:
   7.696 +            {
   7.697 +                format = SND_PCM_SFMT_U8;
   7.698 +                found = 1;
   7.699 +            }
   7.700              break;
   7.701 -         }
   7.702 -         device++;
   7.703 -         if (device>=qsa_playback_devices)
   7.704 -         {
   7.705 -            QSA_CloseDevice(this);
   7.706 -            SDL_SetError("No such playback device");
   7.707 -            return 0;
   7.708 -         }
   7.709 -      } while(1);
   7.710 -   }
   7.711 +        case AUDIO_S8:
   7.712 +            {
   7.713 +                format = SND_PCM_SFMT_S8;
   7.714 +                found = 1;
   7.715 +            }
   7.716 +            break;
   7.717 +        case AUDIO_S16LSB:
   7.718 +            {
   7.719 +                format = SND_PCM_SFMT_S16_LE;
   7.720 +                found = 1;
   7.721 +            }
   7.722 +            break;
   7.723 +        case AUDIO_S16MSB:
   7.724 +            {
   7.725 +                format = SND_PCM_SFMT_S16_BE;
   7.726 +                found = 1;
   7.727 +            }
   7.728 +            break;
   7.729 +        case AUDIO_U16LSB:
   7.730 +            {
   7.731 +                format = SND_PCM_SFMT_U16_LE;
   7.732 +                found = 1;
   7.733 +            }
   7.734 +            break;
   7.735 +        case AUDIO_U16MSB:
   7.736 +            {
   7.737 +                format = SND_PCM_SFMT_U16_BE;
   7.738 +                found = 1;
   7.739 +            }
   7.740 +            break;
   7.741 +        case AUDIO_S32LSB:
   7.742 +            {
   7.743 +                format = SND_PCM_SFMT_S32_LE;
   7.744 +                found = 1;
   7.745 +            }
   7.746 +            break;
   7.747 +        case AUDIO_S32MSB:
   7.748 +            {
   7.749 +                format = SND_PCM_SFMT_S32_BE;
   7.750 +                found = 1;
   7.751 +            }
   7.752 +            break;
   7.753 +        case AUDIO_F32LSB:
   7.754 +            {
   7.755 +                format = SND_PCM_SFMT_FLOAT_LE;
   7.756 +                found = 1;
   7.757 +            }
   7.758 +            break;
   7.759 +        case AUDIO_F32MSB:
   7.760 +            {
   7.761 +                format = SND_PCM_SFMT_FLOAT_BE;
   7.762 +                found = 1;
   7.763 +            }
   7.764 +            break;
   7.765 +        default:
   7.766 +            {
   7.767 +                break;
   7.768 +            }
   7.769 +        }
   7.770  
   7.771 -   /* Find deviceid and cardid by device name for capture */
   7.772 -   if ((this->hidden->iscapture) && (devname!=NULL))
   7.773 -   {
   7.774 -      /* Search in the capture devices */
   7.775 -      uint32_t device;
   7.776 -      int32_t  status;
   7.777 +        if (!found) {
   7.778 +            test_format = SDL_NextAudioFormat();
   7.779 +        }
   7.780 +    }
   7.781  
   7.782 -      /* Searching in the playback devices */
   7.783 -      device=0;
   7.784 -      do {
   7.785 -         status=SDL_strcmp(qsa_capture_device[device].name, devname);
   7.786 -         if (status==0)
   7.787 -         {
   7.788 -            /* Found requested device */
   7.789 -            this->hidden->deviceno=qsa_capture_device[device].deviceno;
   7.790 -            this->hidden->cardno=qsa_capture_device[device].cardno;
   7.791 -            break;
   7.792 -         }
   7.793 -         device++;
   7.794 -         if (device>=qsa_capture_devices)
   7.795 -         {
   7.796 -            QSA_CloseDevice(this);
   7.797 -            SDL_SetError("No such capture device");
   7.798 -            return 0;
   7.799 -         }
   7.800 -      } while(1);
   7.801 -   }
   7.802 +    /* assumes test_format not 0 on success */
   7.803 +    if (test_format == 0) {
   7.804 +        QSA_CloseDevice(this);
   7.805 +        SDL_SetError("QSA: Couldn't find any hardware audio formats");
   7.806 +        return 0;
   7.807 +    }
   7.808  
   7.809 -   /* Check if SDL requested default audio device */
   7.810 -   if (devname==NULL)
   7.811 -   {
   7.812 -      /* Open system default audio device */
   7.813 -      if (!this->hidden->iscapture)
   7.814 -      {
   7.815 -         status=snd_pcm_open_preferred(&this->hidden->audio_handle,
   7.816 -                                       &this->hidden->cardno,
   7.817 -                                       &this->hidden->deviceno, SND_PCM_OPEN_PLAYBACK);
   7.818 -      }
   7.819 -      else
   7.820 -      {
   7.821 -         status=snd_pcm_open_preferred(&this->hidden->audio_handle,
   7.822 -                                       &this->hidden->cardno,
   7.823 -                                       &this->hidden->deviceno, SND_PCM_OPEN_CAPTURE);
   7.824 -      }
   7.825 -   }
   7.826 -   else
   7.827 -   {
   7.828 -      /* Open requested audio device */
   7.829 -      if (!this->hidden->iscapture)
   7.830 -      {
   7.831 -         status=snd_pcm_open(&this->hidden->audio_handle, this->hidden->cardno,
   7.832 -                              this->hidden->deviceno, SND_PCM_OPEN_PLAYBACK);
   7.833 -      }
   7.834 -      else
   7.835 -      {
   7.836 -         status=snd_pcm_open(&this->hidden->audio_handle, this->hidden->cardno,
   7.837 -                              this->hidden->deviceno, SND_PCM_OPEN_CAPTURE);
   7.838 -      }
   7.839 -   }
   7.840 +    this->spec.format = test_format;
   7.841  
   7.842 -   /* Check if requested device is opened */
   7.843 -   if (status<0)
   7.844 -   {
   7.845 -      this->hidden->audio_handle=NULL;
   7.846 -      QSA_CloseDevice(this);
   7.847 -      QSA_SetError("snd_pcm_open", status);
   7.848 -      return 0;
   7.849 -   }
   7.850 +    /* Set the audio format */
   7.851 +    cparams.format.format = format;
   7.852  
   7.853 -   if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND))
   7.854 -   {
   7.855 -      /* Disable QSA MMAP plugin for buggy audio drivers */
   7.856 -      status=snd_pcm_plugin_set_disable(this->hidden->audio_handle, PLUGIN_DISABLE_MMAP);
   7.857 -      if (status<0)
   7.858 -      {
   7.859 -         QSA_CloseDevice(this);
   7.860 -         QSA_SetError("snd_pcm_plugin_set_disable", status);
   7.861 -         return 0;
   7.862 -      }
   7.863 -   }
   7.864 +    /* Set mono/stereo/4ch/6ch/8ch audio */
   7.865 +    cparams.format.voices = this->spec.channels;
   7.866  
   7.867 -   /* Try for a closest match on audio format */
   7.868 -   format = 0;
   7.869 -   /* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */
   7.870 -   found = 0;
   7.871 +    /* Set rate */
   7.872 +    cparams.format.rate = this->spec.freq;
   7.873  
   7.874 -   for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;)
   7.875 -   {
   7.876 -      /* if match found set format to equivalent QSA format */
   7.877 -      switch (test_format)
   7.878 -      {
   7.879 -         case AUDIO_U8:
   7.880 -              {
   7.881 -                 format=SND_PCM_SFMT_U8;
   7.882 -                 found=1;
   7.883 -              }
   7.884 -              break;
   7.885 -         case AUDIO_S8:
   7.886 -              {
   7.887 -                 format=SND_PCM_SFMT_S8;
   7.888 -                 found=1;
   7.889 -              }
   7.890 -              break;
   7.891 -         case AUDIO_S16LSB:
   7.892 -              {
   7.893 -                 format=SND_PCM_SFMT_S16_LE;
   7.894 -                 found=1;
   7.895 -              }
   7.896 -              break;
   7.897 -         case AUDIO_S16MSB:
   7.898 -              {
   7.899 -                 format=SND_PCM_SFMT_S16_BE;
   7.900 -                 found=1;
   7.901 -              }
   7.902 -              break;
   7.903 -         case AUDIO_U16LSB:
   7.904 -              {
   7.905 -                 format=SND_PCM_SFMT_U16_LE;
   7.906 -                 found=1;
   7.907 -              }
   7.908 -              break;
   7.909 -         case AUDIO_U16MSB:
   7.910 -              {
   7.911 -                 format=SND_PCM_SFMT_U16_BE;
   7.912 -                 found=1;
   7.913 -              }
   7.914 -              break;
   7.915 -         case AUDIO_S32LSB:
   7.916 -              {
   7.917 -                 format=SND_PCM_SFMT_S32_LE;
   7.918 -                 found=1;
   7.919 -              }
   7.920 -              break;
   7.921 -         case AUDIO_S32MSB:
   7.922 -              {
   7.923 -                 format=SND_PCM_SFMT_S32_BE;
   7.924 -                 found=1;
   7.925 -              }
   7.926 -              break;
   7.927 -         case AUDIO_F32LSB:
   7.928 -              {
   7.929 -                 format=SND_PCM_SFMT_FLOAT_LE;
   7.930 -                 found=1;
   7.931 -              }
   7.932 -              break;
   7.933 -         case AUDIO_F32MSB:
   7.934 -              {
   7.935 -                 format=SND_PCM_SFMT_FLOAT_BE;
   7.936 -                 found=1;
   7.937 -              }
   7.938 -              break;
   7.939 -         default:
   7.940 -              {
   7.941 -                 break;
   7.942 -              }
   7.943 -      }
   7.944 +    /* Setup the transfer parameters according to cparams */
   7.945 +    status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
   7.946 +    if (status < 0) {
   7.947 +        QSA_CloseDevice(this);
   7.948 +        QSA_SetError("snd_pcm_channel_params", status);
   7.949 +        return 0;
   7.950 +    }
   7.951  
   7.952 -      if (!found)
   7.953 -      {
   7.954 -         test_format = SDL_NextAudioFormat();
   7.955 -      }
   7.956 -   }
   7.957 +    /* Make sure channel is setup right one last time */
   7.958 +    SDL_memset(&csetup, '\0', sizeof(csetup));
   7.959 +    if (!this->hidden->iscapture) {
   7.960 +        csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
   7.961 +    } else {
   7.962 +        csetup.channel = SND_PCM_CHANNEL_CAPTURE;
   7.963 +    }
   7.964  
   7.965 -   /* assumes test_format not 0 on success */
   7.966 -   if (test_format==0)
   7.967 -   {
   7.968 -      QSA_CloseDevice(this);
   7.969 -      SDL_SetError("QSA: Couldn't find any hardware audio formats");
   7.970 -      return 0;
   7.971 -   }
   7.972 +    /* Setup an audio channel */
   7.973 +    if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
   7.974 +        QSA_CloseDevice(this);
   7.975 +        SDL_SetError("QSA: Unable to setup channel\n");
   7.976 +        return 0;
   7.977 +    }
   7.978  
   7.979 -   this->spec.format=test_format;
   7.980 +    /* Calculate the final parameters for this audio specification */
   7.981 +    SDL_CalculateAudioSpec(&this->spec);
   7.982  
   7.983 -   /* Set the audio format */
   7.984 -   cparams.format.format=format;
   7.985 +    this->hidden->pcm_len = this->spec.size;
   7.986  
   7.987 -   /* Set mono/stereo/4ch/6ch/8ch audio */
   7.988 -   cparams.format.voices=this->spec.channels;
   7.989 +    if (this->hidden->pcm_len == 0) {
   7.990 +        this->hidden->pcm_len =
   7.991 +            csetup.buf.block.frag_size * this->spec.channels *
   7.992 +            (snd_pcm_format_width(format) / 8);
   7.993 +    }
   7.994  
   7.995 -   /* Set rate */
   7.996 -   cparams.format.rate=this->spec.freq;
   7.997 +    /*
   7.998 +     * Allocate memory to the audio buffer and initialize with silence
   7.999 +     *  (Note that buffer size must be a multiple of fragment size, so find
  7.1000 +     *  closest multiple)
  7.1001 +     */
  7.1002 +    this->hidden->pcm_buf =
  7.1003 +        (Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len);
  7.1004 +    if (this->hidden->pcm_buf == NULL) {
  7.1005 +        QSA_CloseDevice(this);
  7.1006 +        SDL_OutOfMemory();
  7.1007 +        return 0;
  7.1008 +    }
  7.1009 +    SDL_memset(this->hidden->pcm_buf, this->spec.silence,
  7.1010 +               this->hidden->pcm_len);
  7.1011  
  7.1012 -   /* Setup the transfer parameters according to cparams */
  7.1013 -   status=snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
  7.1014 -   if (status<0)
  7.1015 -   {
  7.1016 -      QSA_CloseDevice(this);
  7.1017 -      QSA_SetError("snd_pcm_channel_params", status);
  7.1018 -      return 0;
  7.1019 -   }
  7.1020 +    /* get the file descriptor */
  7.1021 +    if (!this->hidden->iscapture) {
  7.1022 +        this->hidden->audio_fd =
  7.1023 +            snd_pcm_file_descriptor(this->hidden->audio_handle,
  7.1024 +                                    SND_PCM_CHANNEL_PLAYBACK);
  7.1025 +    } else {
  7.1026 +        this->hidden->audio_fd =
  7.1027 +            snd_pcm_file_descriptor(this->hidden->audio_handle,
  7.1028 +                                    SND_PCM_CHANNEL_CAPTURE);
  7.1029 +    }
  7.1030  
  7.1031 -   /* Make sure channel is setup right one last time */
  7.1032 -   SDL_memset(&csetup, '\0', sizeof(csetup));
  7.1033 -   if (!this->hidden->iscapture)
  7.1034 -   {
  7.1035 -      csetup.channel=SND_PCM_CHANNEL_PLAYBACK;
  7.1036 -   }
  7.1037 -   else
  7.1038 -   {
  7.1039 -      csetup.channel=SND_PCM_CHANNEL_CAPTURE;
  7.1040 -   }
  7.1041 +    if (this->hidden->audio_fd < 0) {
  7.1042 +        QSA_CloseDevice(this);
  7.1043 +        QSA_SetError("snd_pcm_file_descriptor", status);
  7.1044 +        return 0;
  7.1045 +    }
  7.1046  
  7.1047 -   /* Setup an audio channel */
  7.1048 -   if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0)
  7.1049 -   {
  7.1050 -      QSA_CloseDevice(this);
  7.1051 -      SDL_SetError("QSA: Unable to setup channel\n");
  7.1052 -      return 0;
  7.1053 -   }
  7.1054 +    /* Prepare an audio channel */
  7.1055 +    if (!this->hidden->iscapture) {
  7.1056 +        /* Prepare audio playback */
  7.1057 +        status =
  7.1058 +            snd_pcm_plugin_prepare(this->hidden->audio_handle,
  7.1059 +                                   SND_PCM_CHANNEL_PLAYBACK);
  7.1060 +    } else {
  7.1061 +        /* Prepare audio capture */
  7.1062 +        status =
  7.1063 +            snd_pcm_plugin_prepare(this->hidden->audio_handle,
  7.1064 +                                   SND_PCM_CHANNEL_CAPTURE);
  7.1065 +    }
  7.1066  
  7.1067 -   /* Calculate the final parameters for this audio specification */
  7.1068 -   SDL_CalculateAudioSpec(&this->spec);
  7.1069 +    if (status < 0) {
  7.1070 +        QSA_CloseDevice(this);
  7.1071 +        QSA_SetError("snd_pcm_plugin_prepare", status);
  7.1072 +        return 0;
  7.1073 +    }
  7.1074  
  7.1075 -   this->hidden->pcm_len = this->spec.size;
  7.1076 -
  7.1077 -   if (this->hidden->pcm_len==0)
  7.1078 -   {
  7.1079 -      this->hidden->pcm_len=csetup.buf.block.frag_size * this->spec.channels *
  7.1080 -                           (snd_pcm_format_width(format) / 8);
  7.1081 -   }
  7.1082 -
  7.1083 -   /*
  7.1084 -    * Allocate memory to the audio buffer and initialize with silence
  7.1085 -    *  (Note that buffer size must be a multiple of fragment size, so find
  7.1086 -    *  closest multiple)
  7.1087 -    */
  7.1088 -   this->hidden->pcm_buf=(Uint8*)SDL_AllocAudioMem(this->hidden->pcm_len);
  7.1089 -   if (this->hidden->pcm_buf==NULL)
  7.1090 -   {
  7.1091 -      QSA_CloseDevice(this);
  7.1092 -      SDL_OutOfMemory();
  7.1093 -      return 0;
  7.1094 -   }
  7.1095 -   SDL_memset(this->hidden->pcm_buf, this->spec.silence, this->hidden->pcm_len);
  7.1096 -
  7.1097 -   /* get the file descriptor */
  7.1098 -   if (!this->hidden->iscapture)
  7.1099 -   {
  7.1100 -      this->hidden->audio_fd=snd_pcm_file_descriptor(this->hidden->audio_handle,
  7.1101 -                                                     SND_PCM_CHANNEL_PLAYBACK);
  7.1102 -   }
  7.1103 -   else
  7.1104 -   {
  7.1105 -      this->hidden->audio_fd=snd_pcm_file_descriptor(this->hidden->audio_handle,
  7.1106 -                                                     SND_PCM_CHANNEL_CAPTURE);
  7.1107 -   }
  7.1108 -
  7.1109 -   if (this->hidden->audio_fd<0)
  7.1110 -   {
  7.1111 -      QSA_CloseDevice(this);
  7.1112 -      QSA_SetError("snd_pcm_file_descriptor", status);
  7.1113 -      return 0;
  7.1114 -   }
  7.1115 -
  7.1116 -   /* Prepare an audio channel */
  7.1117 -   if (!this->hidden->iscapture)
  7.1118 -   {
  7.1119 -      /* Prepare audio playback */
  7.1120 -      status=snd_pcm_plugin_prepare(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK);
  7.1121 -   }
  7.1122 -   else
  7.1123 -   {
  7.1124 -      /* Prepare audio capture */
  7.1125 -      status=snd_pcm_plugin_prepare(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE);
  7.1126 -   }
  7.1127 -
  7.1128 -   if (status<0)
  7.1129 -   {
  7.1130 -      QSA_CloseDevice(this);
  7.1131 -      QSA_SetError("snd_pcm_plugin_prepare", status);
  7.1132 -      return 0;
  7.1133 -   }
  7.1134 -
  7.1135 -   /* We're really ready to rock and roll. :-) */
  7.1136 -   return 1;
  7.1137 +    /* We're really ready to rock and roll. :-) */
  7.1138 +    return 1;
  7.1139  }
  7.1140  
  7.1141 -int QSA_DetectDevices(int iscapture)
  7.1142 +int
  7.1143 +QSA_DetectDevices(int iscapture)
  7.1144  {
  7.1145 -   uint32_t it;
  7.1146 -   uint32_t cards;
  7.1147 -   uint32_t devices;
  7.1148 -   int32_t  status;
  7.1149 +    uint32_t it;
  7.1150 +    uint32_t cards;
  7.1151 +    uint32_t devices;
  7.1152 +    int32_t status;
  7.1153  
  7.1154 -   /* Detect amount of available devices       */
  7.1155 -   /* this value can be changed in the runtime */
  7.1156 -   cards=snd_cards();
  7.1157 +    /* Detect amount of available devices       */
  7.1158 +    /* this value can be changed in the runtime */
  7.1159 +    cards = snd_cards();
  7.1160  
  7.1161 -   /* If io-audio manager is not running we will get 0 as number */
  7.1162 -   /* of available audio devices                                 */
  7.1163 -   if (cards==0)
  7.1164 -   {
  7.1165 -      /* We have no any available audio devices */
  7.1166 -      return 0;
  7.1167 -   }
  7.1168 +    /* If io-audio manager is not running we will get 0 as number */
  7.1169 +    /* of available audio devices                                 */
  7.1170 +    if (cards == 0) {
  7.1171 +        /* We have no any available audio devices */
  7.1172 +        return 0;
  7.1173 +    }
  7.1174  
  7.1175 -   /* Find requested devices by type */
  7.1176 -   if (!iscapture)
  7.1177 -   {
  7.1178 -      /* Playback devices enumeration requested */
  7.1179 -      for(it=0; it<cards; it++)
  7.1180 -      {
  7.1181 -         devices=0;
  7.1182 -         do {
  7.1183 -            status=snd_card_get_longname(it, qsa_playback_device[qsa_playback_devices].name, QSA_MAX_NAME_LENGTH);
  7.1184 -            if (status==EOK)
  7.1185 -            {
  7.1186 -               snd_pcm_t* handle;
  7.1187 +    /* Find requested devices by type */
  7.1188 +    if (!iscapture) {
  7.1189 +        /* Playback devices enumeration requested */
  7.1190 +        for (it = 0; it < cards; it++) {
  7.1191 +            devices = 0;
  7.1192 +            do {
  7.1193 +                status =
  7.1194 +                    snd_card_get_longname(it,
  7.1195 +                                          qsa_playback_device
  7.1196 +                                          [qsa_playback_devices].name,
  7.1197 +                                          QSA_MAX_NAME_LENGTH);
  7.1198 +                if (status == EOK) {
  7.1199 +                    snd_pcm_t *handle;
  7.1200  
  7.1201 -               /* Add device number to device name */
  7.1202 -               sprintf(qsa_playback_device[qsa_playback_devices].name + SDL_strlen(qsa_playback_device[qsa_playback_devices].name), " d%d", devices);
  7.1203 +                    /* Add device number to device name */
  7.1204 +                    sprintf(qsa_playback_device[qsa_playback_devices].name +
  7.1205 +                            SDL_strlen(qsa_playback_device
  7.1206 +                                       [qsa_playback_devices].name), " d%d",
  7.1207 +                            devices);
  7.1208  
  7.1209 -               /* Store associated card number id */
  7.1210 -               qsa_playback_device[qsa_playback_devices].cardno=it;
  7.1211 +                    /* Store associated card number id */
  7.1212 +                    qsa_playback_device[qsa_playback_devices].cardno = it;
  7.1213  
  7.1214 -               /* Check if this device id could play anything */
  7.1215 -               status=snd_pcm_open(&handle, it, devices, SND_PCM_OPEN_PLAYBACK);
  7.1216 -               if (status==EOK)
  7.1217 -               {
  7.1218 -                  qsa_playback_device[qsa_playback_devices].deviceno=devices;
  7.1219 -                  status=snd_pcm_close(handle);
  7.1220 -                  if (status==EOK)
  7.1221 -                  {
  7.1222 -                     qsa_playback_devices++;
  7.1223 -                  }
  7.1224 -               }
  7.1225 -               else
  7.1226 -               {
  7.1227 -                  /* Check if we got end of devices list */
  7.1228 -                  if (status==-ENOENT)
  7.1229 -                  {
  7.1230 -                     break;
  7.1231 -                  }
  7.1232 -               }
  7.1233 -            }
  7.1234 -            else
  7.1235 -            {
  7.1236 -               break;
  7.1237 -            }
  7.1238 +                    /* Check if this device id could play anything */
  7.1239 +                    status =
  7.1240 +                        snd_pcm_open(&handle, it, devices,
  7.1241 +                                     SND_PCM_OPEN_PLAYBACK);
  7.1242 +                    if (status == EOK) {
  7.1243 +                        qsa_playback_device[qsa_playback_devices].deviceno =
  7.1244 +                            devices;
  7.1245 +                        status = snd_pcm_close(handle);
  7.1246 +                        if (status == EOK) {
  7.1247 +                            qsa_playback_devices++;
  7.1248 +                        }
  7.1249 +                    } else {
  7.1250 +                        /* Check if we got end of devices list */
  7.1251 +                        if (status == -ENOENT) {
  7.1252 +                            break;
  7.1253 +                        }
  7.1254 +                    }
  7.1255 +                } else {
  7.1256 +                    break;
  7.1257 +                }
  7.1258 +
  7.1259 +                /* Check if we reached maximum devices count */
  7.1260 +                if (qsa_playback_devices >= QSA_MAX_DEVICES) {
  7.1261 +                    break;
  7.1262 +                }
  7.1263 +                devices++;
  7.1264 +            } while (1);
  7.1265  
  7.1266              /* Check if we reached maximum devices count */
  7.1267 -            if (qsa_playback_devices>=QSA_MAX_DEVICES)
  7.1268 -            {
  7.1269 -               break;
  7.1270 +            if (qsa_playback_devices >= QSA_MAX_DEVICES) {
  7.1271 +                break;
  7.1272              }
  7.1273 -            devices++;
  7.1274 -         } while(1);
  7.1275 +        }
  7.1276 +    } else {
  7.1277 +        /* Capture devices enumeration requested */
  7.1278 +        for (it = 0; it < cards; it++) {
  7.1279 +            devices = 0;
  7.1280 +            do {
  7.1281 +                status =
  7.1282 +                    snd_card_get_longname(it,
  7.1283 +                                          qsa_capture_device
  7.1284 +                                          [qsa_capture_devices].name,
  7.1285 +                                          QSA_MAX_NAME_LENGTH);
  7.1286 +                if (status == EOK) {
  7.1287 +                    snd_pcm_t *handle;
  7.1288  
  7.1289 -         /* Check if we reached maximum devices count */
  7.1290 -         if (qsa_playback_devices>=QSA_MAX_DEVICES)
  7.1291 -         {
  7.1292 -            break;
  7.1293 -         }
  7.1294 -      }
  7.1295 -   }
  7.1296 -   else
  7.1297 -   {
  7.1298 -      /* Capture devices enumeration requested */
  7.1299 -      for(it=0; it<cards; it++)
  7.1300 -      {
  7.1301 -         devices=0;
  7.1302 -         do {
  7.1303 -            status=snd_card_get_longname(it, qsa_capture_device[qsa_capture_devices].name, QSA_MAX_NAME_LENGTH);
  7.1304 -            if (status==EOK)
  7.1305 -            {
  7.1306 -               snd_pcm_t* handle;
  7.1307 +                    /* Add device number to device name */
  7.1308 +                    sprintf(qsa_capture_device[qsa_capture_devices].name +
  7.1309 +                            SDL_strlen(qsa_capture_device
  7.1310 +                                       [qsa_capture_devices].name), " d%d",
  7.1311 +                            devices);
  7.1312  
  7.1313 -               /* Add device number to device name */
  7.1314 -               sprintf(qsa_capture_device[qsa_capture_devices].name + SDL_strlen(qsa_capture_device[qsa_capture_devices].name), " d%d", devices);
  7.1315 +                    /* Store associated card number id */
  7.1316 +                    qsa_capture_device[qsa_capture_devices].cardno = it;
  7.1317  
  7.1318 -               /* Store associated card number id */
  7.1319 -               qsa_capture_device[qsa_capture_devices].cardno=it;
  7.1320 +                    /* Check if this device id could play anything */
  7.1321 +                    status =
  7.1322 +                        snd_pcm_open(&handle, it, devices,
  7.1323 +                                     SND_PCM_OPEN_CAPTURE);
  7.1324 +                    if (status == EOK) {
  7.1325 +                        qsa_capture_device[qsa_capture_devices].deviceno =
  7.1326 +                            devices;
  7.1327 +                        status = snd_pcm_close(handle);
  7.1328 +                        if (status == EOK) {
  7.1329 +                            qsa_capture_devices++;
  7.1330 +                        }
  7.1331 +                    } else {
  7.1332 +                        /* Check if we got end of devices list */
  7.1333 +                        if (status == -ENOENT) {
  7.1334 +                            break;
  7.1335 +                        }
  7.1336 +                    }
  7.1337  
  7.1338 -               /* Check if this device id could play anything */
  7.1339 -               status=snd_pcm_open(&handle, it, devices, SND_PCM_OPEN_CAPTURE);
  7.1340 -               if (status==EOK)
  7.1341 -               {
  7.1342 -                  qsa_capture_device[qsa_capture_devices].deviceno=devices;
  7.1343 -                  status=snd_pcm_close(handle);
  7.1344 -                  if (status==EOK)
  7.1345 -                  {
  7.1346 -                     qsa_capture_devices++;
  7.1347 -                  }
  7.1348 -               }
  7.1349 -               else
  7.1350 -               {
  7.1351 -                  /* Check if we got end of devices list */
  7.1352 -                  if (status==-ENOENT)
  7.1353 -                  {
  7.1354 -                     break;
  7.1355 -                  }
  7.1356 -               }
  7.1357 +                    /* Check if we reached maximum devices count */
  7.1358 +                    if (qsa_capture_devices >= QSA_MAX_DEVICES) {
  7.1359 +                        break;
  7.1360 +                    }
  7.1361 +                } else {
  7.1362 +                    break;
  7.1363 +                }
  7.1364 +                devices++;
  7.1365 +            } while (1);
  7.1366  
  7.1367 -               /* Check if we reached maximum devices count */
  7.1368 -               if (qsa_capture_devices>=QSA_MAX_DEVICES)
  7.1369 -               {
  7.1370 -                  break;
  7.1371 -               }
  7.1372 +            /* Check if we reached maximum devices count */
  7.1373 +            if (qsa_capture_devices >= QSA_MAX_DEVICES) {
  7.1374 +                break;
  7.1375              }
  7.1376 -            else
  7.1377 -            {
  7.1378 -               break;
  7.1379 -            }
  7.1380 -            devices++;
  7.1381 -         } while(1);
  7.1382 +        }
  7.1383 +    }
  7.1384  
  7.1385 -         /* Check if we reached maximum devices count */
  7.1386 -         if (qsa_capture_devices>=QSA_MAX_DEVICES)
  7.1387 -         {
  7.1388 -            break;
  7.1389 -         }
  7.1390 -      }
  7.1391 -   }
  7.1392 -
  7.1393 -   /* Return amount of available playback or capture devices */
  7.1394 -   if (!iscapture)
  7.1395 -   {
  7.1396 -      return qsa_playback_devices;
  7.1397 -   }
  7.1398 -   else
  7.1399 -   {
  7.1400 -      return qsa_capture_devices;
  7.1401 -   }
  7.1402 +    /* Return amount of available playback or capture devices */
  7.1403 +    if (!iscapture) {
  7.1404 +        return qsa_playback_devices;
  7.1405 +    } else {
  7.1406 +        return qsa_capture_devices;
  7.1407 +    }
  7.1408  }
  7.1409  
  7.1410 -const char* QSA_GetDeviceName(int index, int iscapture)
  7.1411 +const char *
  7.1412 +QSA_GetDeviceName(int index, int iscapture)
  7.1413  {
  7.1414 -   if (!iscapture)
  7.1415 -   {
  7.1416 -      if (index>=qsa_playback_devices)
  7.1417 -      {
  7.1418 -         return "No such playback device";
  7.1419 -      }
  7.1420 +    if (!iscapture) {
  7.1421 +        if (index >= qsa_playback_devices) {
  7.1422 +            return "No such playback device";
  7.1423 +        }
  7.1424  
  7.1425 -      return qsa_playback_device[index].name;
  7.1426 -   }
  7.1427 -   else
  7.1428 -   {
  7.1429 -      if (index>=qsa_capture_devices)
  7.1430 -      {
  7.1431 -         return "No such capture device";
  7.1432 -      }
  7.1433 +        return qsa_playback_device[index].name;
  7.1434 +    } else {
  7.1435 +        if (index >= qsa_capture_devices) {
  7.1436 +            return "No such capture device";
  7.1437 +        }
  7.1438  
  7.1439 -      return qsa_capture_device[index].name;
  7.1440 -   }
  7.1441 +        return qsa_capture_device[index].name;
  7.1442 +    }
  7.1443  }
  7.1444  
  7.1445 -void QSA_WaitDone(_THIS)
  7.1446 +void
  7.1447 +QSA_WaitDone(_THIS)
  7.1448  {
  7.1449 -   if (!this->hidden->iscapture)
  7.1450 -   {
  7.1451 -      if (this->hidden->audio_handle!=NULL)
  7.1452 -      {
  7.1453 -         /* Wait till last fragment is played and stop channel */
  7.1454 -         snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK);
  7.1455 -      }
  7.1456 -   }
  7.1457 -   else
  7.1458 -   {
  7.1459 -      if (this->hidden->audio_handle!=NULL)
  7.1460 -      {
  7.1461 -         /* Discard all unread data and stop channel */
  7.1462 -         snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE);
  7.1463 -      }
  7.1464 -   }
  7.1465 +    if (!this->hidden->iscapture) {
  7.1466 +        if (this->hidden->audio_handle != NULL) {
  7.1467 +            /* Wait till last fragment is played and stop channel */
  7.1468 +            snd_pcm_plugin_flush(this->hidden->audio_handle,
  7.1469 +                                 SND_PCM_CHANNEL_PLAYBACK);
  7.1470 +        }
  7.1471 +    } else {
  7.1472 +        if (this->hidden->audio_handle != NULL) {
  7.1473 +            /* Discard all unread data and stop channel */
  7.1474 +            snd_pcm_plugin_flush(this->hidden->audio_handle,
  7.1475 +                                 SND_PCM_CHANNEL_CAPTURE);
  7.1476 +        }
  7.1477 +    }
  7.1478  }
  7.1479  
  7.1480 -void QSA_Deinitialize(void)
  7.1481 +void
  7.1482 +QSA_Deinitialize(void)
  7.1483  {
  7.1484 -   /* Clear devices array on shutdown */
  7.1485 -   SDL_memset(qsa_playback_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
  7.1486 -   SDL_memset(qsa_capture_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
  7.1487 -   qsa_playback_devices=0;
  7.1488 -   qsa_capture_devices=0;
  7.1489 +    /* Clear devices array on shutdown */
  7.1490 +    SDL_memset(qsa_playback_device, 0x00,
  7.1491 +               sizeof(QSA_Device) * QSA_MAX_DEVICES);
  7.1492 +    SDL_memset(qsa_capture_device, 0x00,
  7.1493 +               sizeof(QSA_Device) * QSA_MAX_DEVICES);
  7.1494 +    qsa_playback_devices = 0;
  7.1495 +    qsa_capture_devices = 0;
  7.1496  }
  7.1497  
  7.1498 -static int QSA_Init(SDL_AudioDriverImpl* impl)
  7.1499 +static int
  7.1500 +QSA_Init(SDL_AudioDriverImpl * impl)
  7.1501  {
  7.1502 -   snd_pcm_t* handle=NULL;
  7.1503 -   int32_t    status=0;
  7.1504 +    snd_pcm_t *handle = NULL;
  7.1505 +    int32_t status = 0;
  7.1506  
  7.1507 -   /* Clear devices array */
  7.1508 -   SDL_memset(qsa_playback_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
  7.1509 -   SDL_memset(qsa_capture_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
  7.1510 -   qsa_playback_devices=0;
  7.1511 -   qsa_capture_devices=0;
  7.1512 +    /* Clear devices array */
  7.1513 +    SDL_memset(qsa_playback_device, 0x00,
  7.1514 +               sizeof(QSA_Device) * QSA_MAX_DEVICES);
  7.1515 +    SDL_memset(qsa_capture_device, 0x00,
  7.1516 +               sizeof(QSA_Device) * QSA_MAX_DEVICES);
  7.1517 +    qsa_playback_devices = 0;
  7.1518 +    qsa_capture_devices = 0;
  7.1519  
  7.1520 -   /* Set function pointers                                     */
  7.1521 -   /* DeviceLock and DeviceUnlock functions are used default,   */
  7.1522 -   /* provided by SDL, which uses pthread_mutex for lock/unlock */
  7.1523 -   impl->DetectDevices=QSA_DetectDevices;
  7.1524 -   impl->GetDeviceName=QSA_GetDeviceName;
  7.1525 -   impl->OpenDevice=QSA_OpenDevice;
  7.1526 -   impl->ThreadInit=QSA_ThreadInit;
  7.1527 -   impl->WaitDevice=QSA_WaitDevice;
  7.1528 -   impl->PlayDevice=QSA_PlayDevice;
  7.1529 -   impl->GetDeviceBuf=QSA_GetDeviceBuf;
  7.1530 -   impl->CloseDevice=QSA_CloseDevice;
  7.1531 -   impl->WaitDone=QSA_WaitDone;
  7.1532 -   impl->Deinitialize=QSA_Deinitialize;
  7.1533 -   impl->LockDevice=NULL;
  7.1534 -   impl->UnlockDevice=NULL;
  7.1535 +    /* Set function pointers                                     */
  7.1536 +    /* DeviceLock and DeviceUnlock functions are used default,   */
  7.1537 +    /* provided by SDL, which uses pthread_mutex for lock/unlock */
  7.1538 +    impl->DetectDevices = QSA_DetectDevices;
  7.1539 +    impl->GetDeviceName = QSA_GetDeviceName;
  7.1540 +    impl->OpenDevice = QSA_OpenDevice;
  7.1541 +    impl->ThreadInit = QSA_ThreadInit;
  7.1542 +    impl->WaitDevice = QSA_WaitDevice;
  7.1543 +    impl->PlayDevice = QSA_PlayDevice;
  7.1544 +    impl->GetDeviceBuf = QSA_GetDeviceBuf;
  7.1545 +    impl->CloseDevice = QSA_CloseDevice;
  7.1546 +    impl->WaitDone = QSA_WaitDone;
  7.1547 +    impl->Deinitialize = QSA_Deinitialize;
  7.1548 +    impl->LockDevice = NULL;
  7.1549 +    impl->UnlockDevice = NULL;
  7.1550  
  7.1551 -   impl->OnlyHasDefaultOutputDevice=0;
  7.1552 -   impl->ProvidesOwnCallbackThread=0;
  7.1553 -   impl->SkipMixerLock=0;
  7.1554 -   impl->HasCaptureSupport=1;
  7.1555 -   impl->OnlyHasDefaultOutputDevice=0;
  7.1556 -   impl->OnlyHasDefaultInputDevice=0;
  7.1557 +    impl->OnlyHasDefaultOutputDevice = 0;
  7.1558 +    impl->ProvidesOwnCallbackThread = 0;
  7.1559 +    impl->SkipMixerLock = 0;
  7.1560 +    impl->HasCaptureSupport = 1;
  7.1561 +    impl->OnlyHasDefaultOutputDevice = 0;
  7.1562 +    impl->OnlyHasDefaultInputDevice = 0;
  7.1563  
  7.1564 -   /* Check if io-audio manager is running or not */
  7.1565 -   status=snd_cards();
  7.1566 -   if (status==0)
  7.1567 -   {
  7.1568 -      /* if no, return immediately */
  7.1569 -      return 1;
  7.1570 -   }
  7.1571 +    /* Check if io-audio manager is running or not */
  7.1572 +    status = snd_cards();
  7.1573 +    if (status == 0) {
  7.1574 +        /* if no, return immediately */
  7.1575 +        return 1;
  7.1576 +    }
  7.1577  
  7.1578 -   /* At this point we are definitely has an audio device */
  7.1579 -   return 2;
  7.1580 +    /* At this point we are definitely has an audio device */
  7.1581 +    return 2;
  7.1582  }
  7.1583  
  7.1584 -AudioBootStrap QSAAUDIO_bootstrap=
  7.1585 -{
  7.1586 -   DRIVER_NAME, "QNX QSA Audio", QSA_Init, 0
  7.1587 +AudioBootStrap QSAAUDIO_bootstrap = {
  7.1588 +    DRIVER_NAME, "QNX QSA Audio", QSA_Init, 0
  7.1589  };
  7.1590  
  7.1591  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/audio/qsa/SDL_qsa_audio.h	Fri May 15 15:47:37 2009 +0000
     8.2 +++ b/src/audio/qsa/SDL_qsa_audio.h	Sat May 23 22:41:08 2009 +0000
     8.3 @@ -44,7 +44,7 @@
     8.4      /* The audio device handle */
     8.5      int cardno;
     8.6      int deviceno;
     8.7 -    snd_pcm_t* audio_handle;
     8.8 +    snd_pcm_t *audio_handle;
     8.9  
    8.10      /* The audio file descriptor */
    8.11      int audio_fd;
    8.12 @@ -53,7 +53,7 @@
    8.13      uint32_t timeout_on_wait;
    8.14  
    8.15      /* Raw mixing buffer */
    8.16 -    Uint8* pcm_buf;
    8.17 +    Uint8 *pcm_buf;
    8.18      Uint32 pcm_len;
    8.19  };
    8.20  
     9.1 --- a/src/video/SDL_renderer_gles.c	Fri May 15 15:47:37 2009 +0000
     9.2 +++ b/src/video/SDL_renderer_gles.c	Sat May 23 22:41:08 2009 +0000
     9.3 @@ -34,9 +34,10 @@
     9.4  
     9.5  /* Empty function stub to get OpenGL ES 1.0 support without  */
     9.6  /* OpenGL ES extension GL_OES_draw_texture_supported         */
     9.7 -GL_API void GL_APIENTRY glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
     9.8 +GL_API void GL_APIENTRY
     9.9 +glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
    9.10  {
    9.11 -   return;
    9.12 +    return;
    9.13  }
    9.14  
    9.15  #endif /* __QNXNTO__ */
    9.16 @@ -105,8 +106,7 @@
    9.17       {
    9.18        /* OpenGL ES 1.x supported formats list */
    9.19        SDL_PIXELFORMAT_BGR24,
    9.20 -      SDL_PIXELFORMAT_ABGR8888
    9.21 -     },
    9.22 +      SDL_PIXELFORMAT_ABGR8888},
    9.23       0,
    9.24       0}
    9.25  };
    9.26 @@ -351,7 +351,7 @@
    9.27  }
    9.28  
    9.29  static int
    9.30 -GLES_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
    9.31 +GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
    9.32  {
    9.33      GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
    9.34      SDL_Window *window = SDL_GetWindowFromID(renderer->window);
    9.35 @@ -363,15 +363,15 @@
    9.36  
    9.37      switch (texture->format) {
    9.38      case SDL_PIXELFORMAT_BGR24:
    9.39 -         internalFormat = GL_RGB;
    9.40 -         format = GL_RGB;
    9.41 -         type = GL_UNSIGNED_BYTE;
    9.42 -         break;
    9.43 +        internalFormat = GL_RGB;
    9.44 +        format = GL_RGB;
    9.45 +        type = GL_UNSIGNED_BYTE;
    9.46 +        break;
    9.47      case SDL_PIXELFORMAT_ABGR8888:
    9.48 -         internalFormat = GL_RGBA;
    9.49 -         format = GL_RGBA;
    9.50 -         type = GL_UNSIGNED_BYTE;
    9.51 -         break;
    9.52 +        internalFormat = GL_RGBA;
    9.53 +        format = GL_RGBA;
    9.54 +        type = GL_UNSIGNED_BYTE;
    9.55 +        break;
    9.56          /*
    9.57             These formats would be supported if SDL had the necessary pixel formats
    9.58             case SDL_PIXELFORMAT_BGR565:
    9.59 @@ -389,7 +389,7 @@
    9.60             format = GL_RGBA;
    9.61             type = GL_UNSIGNED_SHORT_4_4_4_4;
    9.62             break;
    9.63 -        */
    9.64 +         */
    9.65      default:
    9.66          SDL_SetError("Unsupported texture format");
    9.67          return -1;
    9.68 @@ -533,8 +533,8 @@
    9.69  }
    9.70  
    9.71  static int
    9.72 -GLES_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
    9.73 -                   const SDL_Rect *rect, const void *pixels, int pitch)
    9.74 +GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    9.75 +                   const SDL_Rect * rect, const void *pixels, int pitch)
    9.76  {
    9.77      GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
    9.78      GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
    9.79 @@ -858,7 +858,7 @@
    9.80  }
    9.81  
    9.82  static void
    9.83 -GLES_RenderPresent(SDL_Renderer *renderer)
    9.84 +GLES_RenderPresent(SDL_Renderer * renderer)
    9.85  {
    9.86      SDL_GL_SwapWindow(renderer->window);
    9.87  }
    10.1 --- a/src/video/SDL_video.c	Fri May 15 15:47:37 2009 +0000
    10.2 +++ b/src/video/SDL_video.c	Sat May 23 22:41:08 2009 +0000
    10.3 @@ -1496,10 +1496,9 @@
    10.4      window->renderer = SDL_CurrentDisplay.render_drivers[index]
    10.5          .CreateRenderer(window, flags);
    10.6  
    10.7 -    if (window->renderer==NULL)
    10.8 -    {
    10.9 -       /* Assuming renderer set its error */
   10.10 -       return -1;
   10.11 +    if (window->renderer == NULL) {
   10.12 +        /* Assuming renderer set its error */
   10.13 +        return -1;
   10.14      }
   10.15  
   10.16      SDL_SelectRenderer(window->id);
   10.17 @@ -2719,7 +2718,7 @@
   10.18  {
   10.19  #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
   10.20      void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
   10.21 -    GLenum (APIENTRY * glGetErrorFunc) (void);
   10.22 +    GLenum(APIENTRY * glGetErrorFunc) (void);
   10.23      GLenum attrib = 0;
   10.24      GLenum error = 0;
   10.25  
   10.26 @@ -2734,7 +2733,7 @@
   10.27      }
   10.28  
   10.29      /* Clear value in any case */
   10.30 -    *value=0;
   10.31 +    *value = 0;
   10.32  
   10.33      switch (attr) {
   10.34      case SDL_GL_RETAINED_BACKING:
   10.35 @@ -2842,28 +2841,26 @@
   10.36      }
   10.37  
   10.38      glGetIntegervFunc(attrib, (GLint *) value);
   10.39 -    error=glGetErrorFunc();
   10.40 -    if (error!=GL_NO_ERROR)
   10.41 -    {
   10.42 -       switch (error)
   10.43 -       {
   10.44 -          case GL_INVALID_ENUM:
   10.45 -               {
   10.46 -                  SDL_SetError("OpenGL error: GL_INVALID_ENUM");
   10.47 -               }
   10.48 -               break;
   10.49 -          case GL_INVALID_VALUE:
   10.50 -               {
   10.51 -                  SDL_SetError("OpenGL error: GL_INVALID_VALUE");
   10.52 -               }
   10.53 -               break;
   10.54 -          default:
   10.55 -               {
   10.56 -                  SDL_SetError("OpenGL error: %08X", error);
   10.57 -               }
   10.58 -               break;
   10.59 -       }
   10.60 -       return -1;
   10.61 +    error = glGetErrorFunc();
   10.62 +    if (error != GL_NO_ERROR) {
   10.63 +        switch (error) {
   10.64 +        case GL_INVALID_ENUM:
   10.65 +            {
   10.66 +                SDL_SetError("OpenGL error: GL_INVALID_ENUM");
   10.67 +            }
   10.68 +            break;
   10.69 +        case GL_INVALID_VALUE:
   10.70 +            {
   10.71 +                SDL_SetError("OpenGL error: GL_INVALID_VALUE");
   10.72 +            }
   10.73 +            break;
   10.74 +        default:
   10.75 +            {
   10.76 +                SDL_SetError("OpenGL error: %08X", error);
   10.77 +            }
   10.78 +            break;
   10.79 +        }
   10.80 +        return -1;
   10.81      }
   10.82      return 0;
   10.83  #else
    11.1 --- a/src/video/nds/SDL_ndsrender.c	Fri May 15 15:47:37 2009 +0000
    11.2 +++ b/src/video/nds/SDL_ndsrender.c	Sat May 23 22:41:08 2009 +0000
    11.3 @@ -88,7 +88,7 @@
    11.4        SDL_PIXELFORMAT_INDEX8,
    11.5        SDL_PIXELFORMAT_ABGR1555,
    11.6        SDL_PIXELFORMAT_BGR555,
    11.7 -     },                         /* u32 texture_formats[20] */
    11.8 +      },                        /* u32 texture_formats[20] */
    11.9       (256),                     /* int max_texture_width */
   11.10       (256),                     /* int max_texture_height */
   11.11       }
   11.12 @@ -107,8 +107,14 @@
   11.13      { NDSTX_BG, NDSTX_SPR } type;       /* represented in a bg or sprite. */
   11.14      int hw_index;               /* index of sprite in OAM or bg from libnds */
   11.15      int pitch, bpp;             /* useful information about the texture */
   11.16 -    struct { int x,y; } scale;  /* x/y stretch (24.8 fixed point) */
   11.17 -    struct { int x,y; } scroll; /* x/y offset */
   11.18 +    struct
   11.19 +    {
   11.20 +        int x, y;
   11.21 +    } scale;                    /* x/y stretch (24.8 fixed point) */
   11.22 +    struct
   11.23 +    {
   11.24 +        int x, y;
   11.25 +    } scroll;                   /* x/y offset */
   11.26      int rotate;                 /* -32768 to 32767, texture rotation */
   11.27      u16 *vram_pixels;           /* where the pixel data is stored (a pointer into VRAM) */
   11.28      u16 *vram_palette;          /* where the palette data is stored if it's indexed. */
   11.29 @@ -197,9 +203,9 @@
   11.30      renderer->info.max_texture_height =
   11.31          NDS_RenderDriver.info.max_texture_height;
   11.32  
   11.33 -    data->sub = 0;           /* TODO: this is hard-coded to the "main" screen.
   11.34 -                                figure out how to detect whether to set it to
   11.35 -                                "sub" screen.  window->id, perhaps? */
   11.36 +    data->sub = 0;              /* TODO: this is hard-coded to the "main" screen.
   11.37 +                                   figure out how to detect whether to set it to
   11.38 +                                   "sub" screen.  window->id, perhaps? */
   11.39      data->bg_taken[2] = data->bg_taken[3] = 0;
   11.40  
   11.41      return renderer;
   11.42 @@ -310,9 +316,10 @@
   11.43              txdat->dim.vdy = 0x100;
   11.44              txdat->dim.pitch = pitch;
   11.45              txdat->dim.bpp = bpp;
   11.46 -            txdat->vram_pixels = (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX);
   11.47 +            txdat->vram_pixels =
   11.48 +                (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX);
   11.49              /* FIXME: use tileIdx*boundary
   11.50 -                      to point to proper location */
   11.51 +               to point to proper location */
   11.52          } else {
   11.53              SDL_SetError("Out of NDS sprites.");
   11.54          }
   11.55 @@ -332,20 +339,26 @@
   11.56                  SDL_OutOfMemory();
   11.57                  return -1;
   11.58              }
   11.59 -
   11.60  // hard-coded for 256x256 for now...
   11.61  // TODO: a series of if-elseif-else's to find the closest but larger size.
   11.62 -            if(!data->sub) {
   11.63 -                if(bpp==8) {
   11.64 -                    txdat->hw_index = bgInit(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
   11.65 +            if (!data->sub) {
   11.66 +                if (bpp == 8) {
   11.67 +                    txdat->hw_index =
   11.68 +                        bgInit(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
   11.69                  } else {
   11.70 -                    txdat->hw_index = bgInit(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
   11.71 +                    txdat->hw_index =
   11.72 +                        bgInit(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0,
   11.73 +                               0);
   11.74                  }
   11.75              } else {
   11.76 -                if(bpp==8) {
   11.77 -                    txdat->hw_index = bgInitSub(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
   11.78 +                if (bpp == 8) {
   11.79 +                    txdat->hw_index =
   11.80 +                        bgInitSub(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0,
   11.81 +                                  0);
   11.82                  } else {
   11.83 -                    txdat->hw_index = bgInitSub(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
   11.84 +                    txdat->hw_index =
   11.85 +                        bgInitSub(whichbg, BgType_Bmp16, BgSize_B16_256x256,
   11.86 +                                  0, 0);
   11.87                  }
   11.88              }
   11.89  
   11.90 @@ -357,14 +370,14 @@
   11.91  		bgUpdate(bg3);
   11.92  */
   11.93              txdat->type = NDSTX_BG;
   11.94 -            txdat->pitch = (texture->w)*(bpp/8);
   11.95 +            txdat->pitch = (texture->w) * (bpp / 8);
   11.96              txdat->bpp = bpp;
   11.97              txdat->rotate = 0;
   11.98              txdat->scale.x = 0x100;
   11.99              txdat->scale.y = 0x100;
  11.100              txdat->scroll.x = 0;
  11.101              txdat->scroll.y = 0;
  11.102 -            txdat->vram_pixels = (u16*)bgGetGfxPtr(txdat->hw_index);
  11.103 +            txdat->vram_pixels = (u16 *) bgGetGfxPtr(txdat->hw_index);
  11.104  
  11.105              bgSetCenter(txdat->hw_index, 0, 0);
  11.106              bgSetRotateScale(txdat->hw_index, txdat->rotate, txdat->scale.x,
  11.107 @@ -458,7 +471,7 @@
  11.108      int i, j;
  11.109  
  11.110      printf("NDS_RenderFill: stub\n");
  11.111 -    color = RGB8(r, g, b);  /* macro in libnds that makes an ARGB1555 pixel */
  11.112 +    color = RGB8(r, g, b);      /* macro in libnds that makes an ARGB1555 pixel */
  11.113      /* TODO: make a single-color sprite and stretch it.
  11.114         calculate the "HDX" width modifier of the sprite by:
  11.115         let S be the actual sprite's width (like, 32 pixels for example)
    12.1 --- a/src/video/photon/SDL_photon.c	Fri May 15 15:47:37 2009 +0000
    12.2 +++ b/src/video/photon/SDL_photon.c	Sat May 23 22:41:08 2009 +0000
    12.3 @@ -42,2541 +42,2509 @@
    12.4  
    12.5  /* Use GF's pixel format functions for OpenGL ES context creation */
    12.6  #if defined(SDL_VIDEO_OPENGL_ES)
    12.7 -   #include "../qnxgf/SDL_gf_pixelfmt.h"
    12.8 +#include "../qnxgf/SDL_gf_pixelfmt.h"
    12.9  
   12.10     /* If GF driver is not compiled in, include some of usefull functions */
   12.11 -   #if !defined(SDL_VIDEO_DRIVER_QNXGF)
   12.12 -      #include "../qnxgf/SDL_gf_pixelfmt.c"
   12.13 -   #endif /* SDL_VIDEO_DRIVER_QNXGF */
   12.14 +#if !defined(SDL_VIDEO_DRIVER_QNXGF)
   12.15 +#include "../qnxgf/SDL_gf_pixelfmt.c"
   12.16 +#endif /* SDL_VIDEO_DRIVER_QNXGF */
   12.17  #endif /* SDL_VIDEO_OPENGL_ES */
   12.18  
   12.19  /* Use GF's OpenGL ES 1.1 functions emulation */
   12.20  #if defined(SDL_VIDEO_OPENGL_ES)
   12.21 -   #include "../qnxgf/SDL_gf_opengles.h"
   12.22 +#include "../qnxgf/SDL_gf_opengles.h"
   12.23  
   12.24     /* If GF driver is not compiled in, include some of usefull functions */
   12.25 -   #if !defined(SDL_VIDEO_DRIVER_QNXGF)
   12.26 -      #include "../qnxgf/SDL_gf_opengles.c"
   12.27 -   #endif /* SDL_VIDEO_DRIVER_QNXGF */
   12.28 +#if !defined(SDL_VIDEO_DRIVER_QNXGF)
   12.29 +#include "../qnxgf/SDL_gf_opengles.c"
   12.30 +#endif /* SDL_VIDEO_DRIVER_QNXGF */
   12.31  #endif /* SDL_VIDEO_OPENGL_ES */
   12.32  
   12.33  /* Low level device graphics driver names, which they are reporting */
   12.34 -Photon_DeviceCaps photon_devicename[]=
   12.35 -{
   12.36 -   /* ATI Rage 128 graphics driver (devg-ati_rage128)      */
   12.37 -   {"ati_rage128", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.38 -   /* Fujitsu Carmine graphics driver (devg-carmine.so)    */
   12.39 -   {"carmine",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
   12.40 -   /* C&T graphics driver (devg-chips.so)                  */
   12.41 -   {"chips",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.42 -   /* Fujitsu Coral graphics driver (devg-coral.so)        */
   12.43 -   {"coral",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
   12.44 -   /* Intel integrated graphics driver (devg-extreme2.so)  */
   12.45 -   {"extreme2",    SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
   12.46 -   /* Unaccelerated FB driver (devg-flat.so)               */
   12.47 -   {"flat",        SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.48 -   /* NS Geode graphics driver (devg-geode.so)             */
   12.49 -   {"geode",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.50 -   /* Geode LX graphics driver (devg-geodelx.so)           */
   12.51 -   {"geodelx",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.52 -   /* Intel integrated graphics driver (devg-gma9xx.so)    */
   12.53 -   {"gma",         SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
   12.54 -   /* Intel integrated graphics driver (devg-i810.so)      */
   12.55 -   {"i810",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.56 -   /* Intel integrated graphics driver (devg-i830.so)      */
   12.57 -   {"i830",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.58 -   /* Geode LX graphics driver (devg-lx800.so)             */
   12.59 -   {"lx800",       SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.60 -   /* Matrox Gxx graphics driver (devg-matroxg.so)         */
   12.61 -   {"matroxg",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.62 -   /* Intel Poulsbo graphics driver (devg-poulsbo.so)      */
   12.63 -   {"poulsbo",     SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
   12.64 -   /* ATI Radeon driver (devg-radeon.so)                   */
   12.65 -   {"radeon",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.66 -   /* ATI Rage driver (devg-rage.so)                       */
   12.67 -   {"rage",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.68 -   /* S3 Savage graphics driver (devg-s3_savage.so)        */
   12.69 -   {"s3_savage",   SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.70 -   /* SiS630 integrated graphics driver (devg-sis630.so)   */
   12.71 -   {"sis630",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.72 -   /* PowerVR SGX 535 graphics driver (devg-poulsbo.so)    */
   12.73 -   {"sgx",         SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D},
   12.74 -   /* SM Voyager GX graphics driver (devg-smi5xx.so)       */
   12.75 -   {"smi5xx",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.76 -   /* Silicon Motion graphics driver (devg-smi7xx.so)      */
   12.77 -   {"smi7xx",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.78 -   /* SVGA unaccelerated gfx driver (devg-svga.so)         */
   12.79 -   {"svga",        SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.80 -   /* nVidia TNT graphics driver (devg-tnt.so)             */
   12.81 -   {"tnt",         SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.82 -   /* VIA integrated graphics driver (devg-tvia.so)        */
   12.83 -   {"tvia",        SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.84 -   /* VIA UniChrome graphics driver (devg-unichrome.so)    */
   12.85 -   {"unichrome",   SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.86 -   /* VESA unaccelerated gfx driver (devg-vesa.so)         */
   12.87 -   {"vesa",        SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.88 -   /* VmWare graphics driver (devg-volari.so)              */
   12.89 -   {"vmware",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.90 -   /* XGI XP10 graphics driver (devg-volari.so), OpenGL 1.5*/
   12.91 -   {"volari",      SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D},
   12.92 -   /* End of list */
   12.93 -   {NULL,          0x00000000}
   12.94 +Photon_DeviceCaps photon_devicename[] = {
   12.95 +    /* ATI Rage 128 graphics driver (devg-ati_rage128)      */
   12.96 +    {"ati_rage128", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
   12.97 +    ,
   12.98 +    /* Fujitsu Carmine graphics driver (devg-carmine.so)    */
   12.99 +    {"carmine", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
  12.100 +    ,
  12.101 +    /* C&T graphics driver (devg-chips.so)                  */
  12.102 +    {"chips", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.103 +    ,
  12.104 +    /* Fujitsu Coral graphics driver (devg-coral.so)        */
  12.105 +    {"coral", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
  12.106 +    ,
  12.107 +    /* Intel integrated graphics driver (devg-extreme2.so)  */
  12.108 +    {"extreme2", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
  12.109 +    ,
  12.110 +    /* Unaccelerated FB driver (devg-flat.so)               */
  12.111 +    {"flat", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.112 +    ,
  12.113 +    /* NS Geode graphics driver (devg-geode.so)             */
  12.114 +    {"geode", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.115 +    ,
  12.116 +    /* Geode LX graphics driver (devg-geodelx.so)           */
  12.117 +    {"geodelx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.118 +    ,
  12.119 +    /* Intel integrated graphics driver (devg-gma9xx.so)    */
  12.120 +    {"gma", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
  12.121 +    ,
  12.122 +    /* Intel integrated graphics driver (devg-i810.so)      */
  12.123 +    {"i810", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.124 +    ,
  12.125 +    /* Intel integrated graphics driver (devg-i830.so)      */
  12.126 +    {"i830", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.127 +    ,
  12.128 +    /* Geode LX graphics driver (devg-lx800.so)             */
  12.129 +    {"lx800", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.130 +    ,
  12.131 +    /* Matrox Gxx graphics driver (devg-matroxg.so)         */
  12.132 +    {"matroxg", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.133 +    ,
  12.134 +    /* Intel Poulsbo graphics driver (devg-poulsbo.so)      */
  12.135 +    {"poulsbo", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
  12.136 +    ,
  12.137 +    /* ATI Radeon driver (devg-radeon.so)                   */
  12.138 +    {"radeon", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.139 +    ,
  12.140 +    /* ATI Rage driver (devg-rage.so)                       */
  12.141 +    {"rage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.142 +    ,
  12.143 +    /* S3 Savage graphics driver (devg-s3_savage.so)        */
  12.144 +    {"s3_savage", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.145 +    ,
  12.146 +    /* SiS630 integrated graphics driver (devg-sis630.so)   */
  12.147 +    {"sis630", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.148 +    ,
  12.149 +    /* PowerVR SGX 535 graphics driver (devg-poulsbo.so)    */
  12.150 +    {"sgx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_ACCELERATED_3D}
  12.151 +    ,
  12.152 +    /* SM Voyager GX graphics driver (devg-smi5xx.so)       */
  12.153 +    {"smi5xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.154 +    ,
  12.155 +    /* Silicon Motion graphics driver (devg-smi7xx.so)      */
  12.156 +    {"smi7xx", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.157 +    ,
  12.158 +    /* SVGA unaccelerated gfx driver (devg-svga.so)         */
  12.159 +    {"svga", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.160 +    ,
  12.161 +    /* nVidia TNT graphics driver (devg-tnt.so)             */
  12.162 +    {"tnt", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.163 +    ,
  12.164 +    /* VIA integrated graphics driver (devg-tvia.so)        */
  12.165 +    {"tvia", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.166 +    ,
  12.167 +    /* VIA UniChrome graphics driver (devg-unichrome.so)    */
  12.168 +    {"unichrome", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.169 +    ,
  12.170 +    /* VESA unaccelerated gfx driver (devg-vesa.so)         */
  12.171 +    {"vesa", SDL_PHOTON_UNACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.172 +    ,
  12.173 +    /* VmWare graphics driver (devg-volari.so)              */
  12.174 +    {"vmware", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.175 +    ,
  12.176 +    /* XGI XP10 graphics driver (devg-volari.so), OpenGL 1.5 */
  12.177 +    {"volari", SDL_PHOTON_ACCELERATED | SDL_PHOTON_UNACCELERATED_3D}
  12.178 +    ,
  12.179 +    /* End of list */
  12.180 +    {NULL, 0x00000000}
  12.181  };
  12.182  
  12.183 -static SDL_bool photon_initialized=SDL_FALSE;
  12.184 +static SDL_bool photon_initialized = SDL_FALSE;
  12.185  
  12.186 -static int photon_available(void)
  12.187 +static int
  12.188 +photon_available(void)
  12.189  {
  12.190 -   int status;
  12.191 +    int status;
  12.192  
  12.193 -   /* Check if Photon was initialized before */
  12.194 -   if (photon_initialized==SDL_FALSE)
  12.195 -   {
  12.196 -      /* Initialize Photon widget library and open channel to Photon */
  12.197 -      status=PtInit(NULL);
  12.198 -      if (status==0)
  12.199 -      {
  12.200 -         photon_initialized=SDL_TRUE;
  12.201 -         return 1;
  12.202 -      }
  12.203 -      else
  12.204 -      {
  12.205 -         photon_initialized=SDL_FALSE;
  12.206 -         return 0;
  12.207 -      }
  12.208 -   }
  12.209 +    /* Check if Photon was initialized before */
  12.210 +    if (photon_initialized == SDL_FALSE) {
  12.211 +        /* Initialize Photon widget library and open channel to Photon */
  12.212 +        status = PtInit(NULL);
  12.213 +        if (status == 0) {
  12.214 +            photon_initialized = SDL_TRUE;
  12.215 +            return 1;
  12.216 +        } else {
  12.217 +            photon_initialized = SDL_FALSE;
  12.218 +            return 0;
  12.219 +        }
  12.220 +    }
  12.221  
  12.222 -   return 1;
  12.223 +    return 1;
  12.224  }
  12.225  
  12.226 -static void photon_destroy(SDL_VideoDevice* device)
  12.227 +static void
  12.228 +photon_destroy(SDL_VideoDevice * device)
  12.229  {
  12.230 -   SDL_VideoData* phdata=(SDL_VideoData*) device->driverdata;
  12.231 +    SDL_VideoData *phdata = (SDL_VideoData *) device->driverdata;
  12.232  
  12.233 -   #if defined(SDL_VIDEO_OPENGL_ES)
  12.234 -      if (phdata->gfinitialized!=SDL_FALSE)
  12.235 -      {
  12.236 -         gf_dev_detach(phdata->gfdev);
  12.237 -      }
  12.238 -   #endif /* SDL_VIDEO_OPENGL_ES */
  12.239 +#if defined(SDL_VIDEO_OPENGL_ES)
  12.240 +    if (phdata->gfinitialized != SDL_FALSE) {
  12.241 +        gf_dev_detach(phdata->gfdev);
  12.242 +    }
  12.243 +#endif /* SDL_VIDEO_OPENGL_ES */
  12.244  
  12.245 -   if (device->driverdata!=NULL)
  12.246 -   {
  12.247 -      device->driverdata=NULL;
  12.248 -   }
  12.249 +    if (device->driverdata != NULL) {
  12.250 +        device->driverdata = NULL;
  12.251 +    }
  12.252  }
  12.253  
  12.254 -static SDL_VideoDevice* photon_create(int devindex)
  12.255 +static SDL_VideoDevice *
  12.256 +photon_create(int devindex)
  12.257  {
  12.258 -   SDL_VideoDevice*  device;
  12.259 -   SDL_VideoData*    phdata;
  12.260 -   int               status;
  12.261 +    SDL_VideoDevice *device;
  12.262 +    SDL_VideoData *phdata;
  12.263 +    int status;
  12.264  
  12.265 -   /* Check if photon could be initialized */
  12.266 -   status=photon_available();
  12.267 -   if (status==0)
  12.268 -   {
  12.269 -      /* Photon could not be used */
  12.270 -      return NULL;
  12.271 -   }
  12.272 +    /* Check if photon could be initialized */
  12.273 +    status = photon_available();
  12.274 +    if (status == 0) {
  12.275 +        /* Photon could not be used */
  12.276 +        return NULL;
  12.277 +    }
  12.278  
  12.279 -   /* Photon agregates all video devices to one with multiple heads */
  12.280 -   if (devindex!=0)
  12.281 -   {
  12.282 -      /* devindex could be zero only in Photon SDL driver */
  12.283 -      return NULL;
  12.284 -   }
  12.285 +    /* Photon agregates all video devices to one with multiple heads */
  12.286 +    if (devindex != 0) {
  12.287 +        /* devindex could be zero only in Photon SDL driver */
  12.288 +        return NULL;
  12.289 +    }
  12.290  
  12.291 -   /* Initialize SDL_VideoDevice structure */
  12.292 -   device=(SDL_VideoDevice*)SDL_calloc(1, sizeof(SDL_VideoDevice));
  12.293 -   if (device==NULL)
  12.294 -   {
  12.295 -      SDL_OutOfMemory();
  12.296 -      return NULL;
  12.297 -   }
  12.298 +    /* Initialize SDL_VideoDevice structure */
  12.299 +    device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
  12.300 +    if (device == NULL) {
  12.301 +        SDL_OutOfMemory();
  12.302 +        return NULL;
  12.303 +    }
  12.304  
  12.305 -   /* Initialize internal photon specific data */
  12.306 -   phdata=(SDL_VideoData*)SDL_calloc(1, sizeof(SDL_VideoData));
  12.307 -   if (phdata==NULL)
  12.308 -   {
  12.309 -      SDL_OutOfMemory();
  12.310 -      SDL_free(device);
  12.311 -      return NULL;
  12.312 -   }
  12.313 -   device->driverdata=phdata;
  12.314 +    /* Initialize internal photon specific data */
  12.315 +    phdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
  12.316 +    if (phdata == NULL) {
  12.317 +        SDL_OutOfMemory();
  12.318 +        SDL_free(device);
  12.319 +        return NULL;
  12.320 +    }
  12.321 +    device->driverdata = phdata;
  12.322  
  12.323 -   /* Get all photon display devices */
  12.324 -   phdata->avail_rids=PdGetDevices(&phdata->rid[0], SDL_VIDEO_PHOTON_MAX_RIDS);
  12.325 -   if (phdata->avail_rids>SDL_VIDEO_PHOTON_MAX_RIDS)
  12.326 -   {
  12.327 -      phdata->avail_rids=SDL_VIDEO_PHOTON_MAX_RIDS;
  12.328 -   }
  12.329 +    /* Get all photon display devices */
  12.330 +    phdata->avail_rids =
  12.331 +        PdGetDevices(&phdata->rid[0], SDL_VIDEO_PHOTON_MAX_RIDS);
  12.332 +    if (phdata->avail_rids > SDL_VIDEO_PHOTON_MAX_RIDS) {
  12.333 +        phdata->avail_rids = SDL_VIDEO_PHOTON_MAX_RIDS;
  12.334 +    }
  12.335 +#if defined(SDL_VIDEO_OPENGL_ES)
  12.336 +    /* TODO: add real device detection versus multiple heads */
  12.337 +    status =
  12.338 +        gf_dev_attach(&phdata->gfdev, GF_DEVICE_INDEX(0),
  12.339 +                      &phdata->gfdev_info);
  12.340 +    if (status != GF_ERR_OK) {
  12.341 +        /* Do not fail right now, if GF can't be attached */
  12.342 +        phdata->gfinitialized = SDL_FALSE;
  12.343 +    } else {
  12.344 +        phdata->gfinitialized = SDL_TRUE;
  12.345 +    }
  12.346 +#endif /* SDL_VIDEO_OPENGL_ES */
  12.347  
  12.348 -   #if defined(SDL_VIDEO_OPENGL_ES)
  12.349 -      /* TODO: add real device detection versus multiple heads */
  12.350 -      status=gf_dev_attach(&phdata->gfdev, GF_DEVICE_INDEX(0), &phdata->gfdev_info);
  12.351 -      if (status!=GF_ERR_OK)
  12.352 -      {
  12.353 -         /* Do not fail right now, if GF can't be attached */
  12.354 -         phdata->gfinitialized=SDL_FALSE;
  12.355 -      }
  12.356 -      else
  12.357 -      {
  12.358 -         phdata->gfinitialized=SDL_TRUE;
  12.359 -      }
  12.360 -   #endif /* SDL_VIDEO_OPENGL_ES */
  12.361 +    /* Set default target device */
  12.362 +    status = PdSetTargetDevice(NULL, phdata->rid[0]);
  12.363 +    if (status == -1) {
  12.364 +        SDL_SetError("Photon: Can't set default target device");
  12.365 +#if defined(SDL_VIDEO_OPENGL_ES)
  12.366 +        gf_dev_detach(phdata->gfdev);
  12.367 +#endif /* SDL_VIDEO_OPENGL_ES */
  12.368 +        SDL_free(phdata);
  12.369 +        SDL_free(device);
  12.370 +        return NULL;
  12.371 +    }
  12.372 +    phdata->current_device_id = 0;
  12.373  
  12.374 -   /* Set default target device */
  12.375 -   status=PdSetTargetDevice(NULL, phdata->rid[0]);
  12.376 -   if (status==-1)
  12.377 -   {
  12.378 -      SDL_SetError("Photon: Can't set default target device");
  12.379 -      #if defined(SDL_VIDEO_OPENGL_ES)
  12.380 -         gf_dev_detach(phdata->gfdev);
  12.381 -      #endif /* SDL_VIDEO_OPENGL_ES */
  12.382 -      SDL_free(phdata);
  12.383 -      SDL_free(device);
  12.384 -      return NULL;
  12.385 -   }
  12.386 -   phdata->current_device_id=0;
  12.387 +    /* Setup amount of available displays and current display */
  12.388 +    device->num_displays = 0;
  12.389 +    device->current_display = 0;
  12.390  
  12.391 -   /* Setup amount of available displays and current display */
  12.392 -   device->num_displays=0;
  12.393 -   device->current_display=0;
  12.394 +    /* Set device free function */
  12.395 +    device->free = photon_destroy;
  12.396  
  12.397 -   /* Set device free function */
  12.398 -   device->free=photon_destroy;
  12.399 +    /* Setup all functions which we can handle */
  12.400 +    device->VideoInit = photon_videoinit;
  12.401 +    device->VideoQuit = photon_videoquit;
  12.402 +    device->GetDisplayModes = photon_getdisplaymodes;
  12.403 +    device->SetDisplayMode = photon_setdisplaymode;
  12.404 +    device->SetDisplayPalette = photon_setdisplaypalette;
  12.405 +    device->GetDisplayPalette = photon_getdisplaypalette;
  12.406 +    device->SetDisplayGammaRamp = photon_setdisplaygammaramp;
  12.407 +    device->GetDisplayGammaRamp = photon_getdisplaygammaramp;
  12.408 +    device->CreateWindow = photon_createwindow;
  12.409 +    device->CreateWindowFrom = photon_createwindowfrom;
  12.410 +    device->SetWindowTitle = photon_setwindowtitle;
  12.411 +    device->SetWindowIcon = photon_setwindowicon;
  12.412 +    device->SetWindowPosition = photon_setwindowposition;
  12.413 +    device->SetWindowSize = photon_setwindowsize;
  12.414 +    device->ShowWindow = photon_showwindow;
  12.415 +    device->HideWindow = photon_hidewindow;
  12.416 +    device->RaiseWindow = photon_raisewindow;
  12.417 +    device->MaximizeWindow = photon_maximizewindow;
  12.418 +    device->MinimizeWindow = photon_minimizewindow;
  12.419 +    device->RestoreWindow = photon_restorewindow;
  12.420 +    device->SetWindowGrab = photon_setwindowgrab;
  12.421 +    device->DestroyWindow = photon_destroywindow;
  12.422 +    device->GetWindowWMInfo = photon_getwindowwminfo;
  12.423 +    device->GL_LoadLibrary = photon_gl_loadlibrary;
  12.424 +    device->GL_GetProcAddress = photon_gl_getprocaddres;
  12.425 +    device->GL_UnloadLibrary = photon_gl_unloadlibrary;
  12.426 +    device->GL_CreateContext = photon_gl_createcontext;
  12.427 +    device->GL_MakeCurrent = photon_gl_makecurrent;
  12.428 +    device->GL_SetSwapInterval = photon_gl_setswapinterval;
  12.429 +    device->GL_GetSwapInterval = photon_gl_getswapinterval;
  12.430 +    device->GL_SwapWindow = photon_gl_swapwindow;
  12.431 +    device->GL_DeleteContext = photon_gl_deletecontext;
  12.432 +    device->PumpEvents = photon_pumpevents;
  12.433 +    device->SuspendScreenSaver = photon_suspendscreensaver;
  12.434  
  12.435 -   /* Setup all functions which we can handle */
  12.436 -   device->VideoInit=photon_videoinit;
  12.437 -   device->VideoQuit=photon_videoquit;
  12.438 -   device->GetDisplayModes=photon_getdisplaymodes;
  12.439 -   device->SetDisplayMode=photon_setdisplaymode;
  12.440 -   device->SetDisplayPalette=photon_setdisplaypalette;
  12.441 -   device->GetDisplayPalette=photon_getdisplaypalette;
  12.442 -   device->SetDisplayGammaRamp=photon_setdisplaygammaramp;
  12.443 -   device->GetDisplayGammaRamp=photon_getdisplaygammaramp;
  12.444 -   device->CreateWindow=photon_createwindow;
  12.445 -   device->CreateWindowFrom=photon_createwindowfrom;
  12.446 -   device->SetWindowTitle=photon_setwindowtitle;
  12.447 -   device->SetWindowIcon=photon_setwindowicon;
  12.448 -   device->SetWindowPosition=photon_setwindowposition;
  12.449 -   device->SetWindowSize=photon_setwindowsize;
  12.450 -   device->ShowWindow=photon_showwindow;
  12.451 -   device->HideWindow=photon_hidewindow;
  12.452 -   device->RaiseWindow=photon_raisewindow;
  12.453 -   device->MaximizeWindow=photon_maximizewindow;
  12.454 -   device->MinimizeWindow=photon_minimizewindow;
  12.455 -   device->RestoreWindow=photon_restorewindow;
  12.456 -   device->SetWindowGrab=photon_setwindowgrab;
  12.457 -   device->DestroyWindow=photon_destroywindow;
  12.458 -   device->GetWindowWMInfo=photon_getwindowwminfo;
  12.459 -   device->GL_LoadLibrary=photon_gl_loadlibrary;
  12.460 -   device->GL_GetProcAddress=photon_gl_getprocaddres;
  12.461 -   device->GL_UnloadLibrary=photon_gl_unloadlibrary;
  12.462 -   device->GL_CreateContext=photon_gl_createcontext;
  12.463 -   device->GL_MakeCurrent=photon_gl_makecurrent;
  12.464 -   device->GL_SetSwapInterval=photon_gl_setswapinterval;
  12.465 -   device->GL_GetSwapInterval=photon_gl_getswapinterval;
  12.466 -   device->GL_SwapWindow=photon_gl_swapwindow;
  12.467 -   device->GL_DeleteContext=photon_gl_deletecontext;
  12.468 -   device->PumpEvents=photon_pumpevents;
  12.469 -   device->SuspendScreenSaver=photon_suspendscreensaver;
  12.470 -
  12.471 -   return device;
  12.472 +    return device;
  12.473  }
  12.474  
  12.475 -VideoBootStrap photon_bootstrap=
  12.476 -{
  12.477 -   "photon",
  12.478 -   "SDL QNX Photon video driver",
  12.479 -   photon_available,
  12.480 -   photon_create
  12.481 +VideoBootStrap photon_bootstrap = {
  12.482 +    "photon",
  12.483 +    "SDL QNX Photon video driver",
  12.484 +    photon_available,
  12.485 +    photon_create
  12.486  };
  12.487  
  12.488  /*****************************************************************************/
  12.489  /* SDL Video and Display initialization/handling functions                   */
  12.490  /*****************************************************************************/
  12.491 -int photon_videoinit(_THIS)
  12.492 +int
  12.493 +photon_videoinit(_THIS)
  12.494  {
  12.495 -   SDL_VideoData*    phdata=(SDL_VideoData*)_this->driverdata;
  12.496 -   PgHWCaps_t        hwcaps;
  12.497 -   PgVideoModeInfo_t modeinfo;
  12.498 -   int32_t           status;
  12.499 -   SDL_VideoDisplay  display;
  12.500 -   SDL_DisplayMode   current_mode;
  12.501 -   SDL_DisplayData*  didata;
  12.502 -   uint32_t          it;
  12.503 -   uint32_t          jt;
  12.504 -   char*             override;
  12.505 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
  12.506 +    PgHWCaps_t hwcaps;
  12.507 +    PgVideoModeInfo_t modeinfo;
  12.508 +    int32_t status;
  12.509 +    SDL_VideoDisplay display;
  12.510 +    SDL_DisplayMode current_mode;
  12.511 +    SDL_DisplayData *didata;
  12.512 +    uint32_t it;
  12.513 +    uint32_t jt;
  12.514 +    char *override;
  12.515  
  12.516 -   /* By default Photon do not uses swap on VSYNC */
  12.517 -   phdata->swapinterval=0;
  12.518 +    /* By default Photon do not uses swap on VSYNC */
  12.519 +    phdata->swapinterval = 0;
  12.520  
  12.521 -   for (it=0; it<phdata->avail_rids; it++)
  12.522 -   {
  12.523 -      didata=(SDL_DisplayData*)SDL_calloc(1, sizeof(SDL_DisplayData));
  12.524 -      if (didata==NULL)
  12.525 -      {
  12.526 -         /* memory allocation error */
  12.527 -         SDL_OutOfMemory();
  12.528 -         return -1;
  12.529 -      }
  12.530 +    for (it = 0; it < phdata->avail_rids; it++) {
  12.531 +        didata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
  12.532 +        if (didata == NULL) {
  12.533 +            /* memory allocation error */
  12.534 +            SDL_OutOfMemory();
  12.535 +            return -1;
  12.536 +        }
  12.537  
  12.538 -      /* Allocate two cursors with SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE size */
  12.539 -      /* and 128 bytes of spare place                                    */
  12.540 -      didata->cursor_size=((SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE*4)>>3)+128;
  12.541 -      didata->cursor=(PhCursorDef_t*)SDL_calloc(1, didata->cursor_size);
  12.542 -      if (didata->cursor==NULL)
  12.543 -      {
  12.544 -         /* memory allocation error */
  12.545 -         SDL_OutOfMemory();
  12.546 -         SDL_free(didata);
  12.547 -         return -1;
  12.548 -      }
  12.549 +        /* Allocate two cursors with SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE size */
  12.550 +        /* and 128 bytes of spare place                                    */
  12.551 +        didata->cursor_size =
  12.552 +            ((SDL_VIDEO_PHOTON_MAX_CURSOR_SIZE * 4) >> 3) + 128;
  12.553 +        didata->cursor = (PhCursorDef_t *) SDL_calloc(1, didata->cursor_size);
  12.554 +        if (didata->cursor == NULL) {
  12.555 +            /* memory allocation error */
  12.556 +            SDL_OutOfMemory();
  12.557 +            SDL_free(didata);
  12.558 +            return -1;
  12.559 +        }
  12.560  
  12.561 -      /* Initialize GF in case of OpenGL ES support is compiled in */
  12.562 -      #if defined(SDL_VIDEO_OPENGL_ES)
  12.563 -         /* TODO: add real device detection versus multiple heads */
  12.564 -         if (phdata->gfinitialized==SDL_TRUE)
  12.565 -         {
  12.566 -            status=gf_display_attach(&didata->display, phdata->gfdev, it, &didata->display_info);
  12.567 -            if (status!=GF_ERR_OK)
  12.568 -            {
  12.569 -               /* Just shutdown GF, do not fail */
  12.570 -               gf_dev_detach(phdata->gfdev);
  12.571 -               phdata->gfinitialized=SDL_FALSE;
  12.572 +        /* Initialize GF in case of OpenGL ES support is compiled in */
  12.573 +#if defined(SDL_VIDEO_OPENGL_ES)
  12.574 +        /* TODO: add real device detection versus multiple heads */
  12.575 +        if (phdata->gfinitialized == SDL_TRUE) {
  12.576 +            status =
  12.577 +                gf_display_attach(&didata->display, phdata->gfdev, it,
  12.578 +                                  &didata->display_info);
  12.579 +            if (status != GF_ERR_OK) {
  12.580 +                /* Just shutdown GF, do not fail */
  12.581 +                gf_dev_detach(phdata->gfdev);
  12.582 +                phdata->gfinitialized = SDL_FALSE;
  12.583              }
  12.584 -         }
  12.585 -      #endif /* SDL_VIDEO_OPENGL_ES */
  12.586 +        }
  12.587 +#endif /* SDL_VIDEO_OPENGL_ES */
  12.588  
  12.589 -      /* Check if current device is not the same as target */
  12.590 -      if (phdata->current_device_id!=it)
  12.591 -      {
  12.592 -         /* Set target device as default for Pd and Pg functions */
  12.593 -         status=PdSetTargetDevice(NULL, phdata->rid[it]);
  12.594 -         if (status!=0)
  12.595 -         {
  12.596 -            SDL_SetError("Photon: Can't set default target device\n");
  12.597 +        /* Check if current device is not the same as target */
  12.598 +        if (phdata->current_device_id != it) {
  12.599 +            /* Set target device as default for Pd and Pg functions */
  12.600 +            status = PdSetTargetDevice(NULL, phdata->rid[it]);
  12.601 +            if (status != 0) {
  12.602 +                SDL_SetError("Photon: Can't set default target device\n");
  12.603 +                SDL_free(didata->cursor);
  12.604 +                SDL_free(didata);
  12.605 +                return -1;
  12.606 +            }
  12.607 +            phdata->current_device_id = it;
  12.608 +        }
  12.609 +
  12.610 +        /* Store device id */
  12.611 +        didata->device_id = it;
  12.612 +
  12.613 +        /* Query photon about graphics hardware caps and current video mode */
  12.614 +        status = PgGetGraphicsHWCaps(&hwcaps);
  12.615 +        if (status != 0) {
  12.616 +            SDL_SetError("Photon: Can't get graphics capabilities");
  12.617              SDL_free(didata->cursor);
  12.618              SDL_free(didata);
  12.619              return -1;
  12.620 -         }
  12.621 -         phdata->current_device_id=it;
  12.622 -      }
  12.623 +        }
  12.624  
  12.625 -      /* Store device id */
  12.626 -      didata->device_id=it;
  12.627 +        /* Get current video mode details */
  12.628 +        status = PgGetVideoModeInfo(hwcaps.current_video_mode, &modeinfo);
  12.629 +        if (status != 0) {
  12.630 +            SDL_SetError("Photon: Can't get current video mode information");
  12.631 +            SDL_free(didata->cursor);
  12.632 +            SDL_free(didata);
  12.633 +            return -1;
  12.634 +        }
  12.635  
  12.636 -      /* Query photon about graphics hardware caps and current video mode */
  12.637 -      status=PgGetGraphicsHWCaps(&hwcaps);
  12.638 -      if (status!=0)
  12.639 -      {
  12.640 -         SDL_SetError("Photon: Can't get graphics capabilities");
  12.641 -         SDL_free(didata->cursor);
  12.642 -         SDL_free(didata);
  12.643 -         return -1;
  12.644 -      }
  12.645 +        /* Setup current desktop mode for SDL */
  12.646 +        SDL_zero(current_mode);
  12.647 +        current_mode.w = modeinfo.width;
  12.648 +        current_mode.h = modeinfo.height;
  12.649 +        current_mode.refresh_rate = hwcaps.current_rrate;
  12.650 +        current_mode.format = photon_image_to_sdl_pixelformat(modeinfo.type);
  12.651 +        current_mode.driverdata = NULL;
  12.652  
  12.653 -      /* Get current video mode details */
  12.654 -      status=PgGetVideoModeInfo(hwcaps.current_video_mode, &modeinfo);
  12.655 -      if (status!=0)
  12.656 -      {
  12.657 -         SDL_SetError("Photon: Can't get current video mode information");
  12.658 -         SDL_free(didata->cursor);
  12.659 -         SDL_free(didata);
  12.660 -         return -1;
  12.661 -      }
  12.662 +        /* Copy device name */
  12.663 +        SDL_strlcpy(didata->description, hwcaps.chip_name,
  12.664 +                    SDL_VIDEO_PHOTON_DEVICENAME_MAX - 1);
  12.665  
  12.666 -      /* Setup current desktop mode for SDL */
  12.667 -      SDL_zero(current_mode);
  12.668 -      current_mode.w=modeinfo.width;
  12.669 -      current_mode.h=modeinfo.height;
  12.670 -      current_mode.refresh_rate=hwcaps.current_rrate;
  12.671 -      current_mode.format=photon_image_to_sdl_pixelformat(modeinfo.type);
  12.672 -      current_mode.driverdata=NULL;
  12.673 +        /* Search device capabilities and possible workarounds */
  12.674 +        jt = 0;
  12.675 +        do {
  12.676 +            if (photon_devicename[jt].name == NULL) {
  12.677 +                break;
  12.678 +            }
  12.679 +            if (SDL_strncmp
  12.680 +                (photon_devicename[jt].name, didata->description,
  12.681 +                 SDL_strlen(photon_devicename[jt].name)) == 0) {
  12.682 +                didata->caps = photon_devicename[jt].caps;
  12.683 +            }
  12.684 +            jt++;
  12.685 +        } while (1);
  12.686  
  12.687 -      /* Copy device name */
  12.688 -      SDL_strlcpy(didata->description, hwcaps.chip_name, SDL_VIDEO_PHOTON_DEVICENAME_MAX-1);
  12.689 +        /* Initialize display structure */
  12.690 +        SDL_zero(display);
  12.691 +        display.desktop_mode = current_mode;
  12.692 +        display.current_mode = current_mode;
  12.693 +        display.driverdata = didata;
  12.694 +        didata->current_mode = current_mode;
  12.695 +        SDL_AddVideoDisplay(&display);
  12.696  
  12.697 -      /* Search device capabilities and possible workarounds */
  12.698 -      jt=0;
  12.699 -      do {
  12.700 -         if (photon_devicename[jt].name==NULL)
  12.701 -         {
  12.702 -            break;
  12.703 -         }
  12.704 -         if (SDL_strncmp(photon_devicename[jt].name, didata->description, SDL_strlen(photon_devicename[jt].name))==0)
  12.705 -         {
  12.706 -            didata->caps=photon_devicename[jt].caps;
  12.707 -         }
  12.708 -         jt++;
  12.709 -      } while(1);
  12.710 +        /* Check for environment variables which could override some SDL settings */
  12.711 +        didata->custom_refresh = 0;
  12.712 +        override = SDL_getenv("SDL_VIDEO_PHOTON_REFRESH_RATE");
  12.713 +        if (override != NULL) {
  12.714 +            if (SDL_sscanf(override, "%u", &didata->custom_refresh) != 1) {
  12.715 +                didata->custom_refresh = 0;
  12.716 +            }
  12.717 +        }
  12.718 +    }
  12.719  
  12.720 -      /* Initialize display structure */
  12.721 -      SDL_zero(display);
  12.722 -      display.desktop_mode=current_mode;
  12.723 -      display.current_mode=current_mode;
  12.724 -      display.driverdata=didata;
  12.725 -      didata->current_mode=current_mode;
  12.726 -      SDL_AddVideoDisplay(&display);
  12.727 +    /* Add photon input devices */
  12.728 +    status = photon_addinputdevices(_this);
  12.729 +    if (status != 0) {
  12.730 +        /* SDL error is set by photon_addinputdevices() function */
  12.731 +        return -1;
  12.732 +    }
  12.733  
  12.734 -      /* Check for environment variables which could override some SDL settings */
  12.735 -      didata->custom_refresh=0;
  12.736 -      override=SDL_getenv("SDL_VIDEO_PHOTON_REFRESH_RATE");
  12.737 -      if (override!=NULL)
  12.738 -      {
  12.739 -         if (SDL_sscanf(override, "%u", &didata->custom_refresh)!=1)
  12.740 -         {
  12.741 -            didata->custom_refresh=0;
  12.742 -         }
  12.743 -      }
  12.744 -   }
  12.745 +    /* Add photon renderer to SDL */
  12.746 +    photon_addrenderdriver(_this);
  12.747  
  12.748 -   /* Add photon input devices */
  12.749 -   status=photon_addinputdevices(_this);
  12.750 -   if (status!=0)
  12.751 -   {
  12.752 -      /* SDL error is set by photon_addinputdevices() function */
  12.753 -      return -1;
  12.754 -   }
  12.755 -
  12.756 -   /* Add photon renderer to SDL */
  12.757 -   photon_addrenderdriver(_this);
  12.758 -
  12.759 -   /* video has been initialized successfully */
  12.760 -   return 1;
  12.761 +    /* video has been initialized successfully */
  12.762 +    return 1;
  12.763  }
  12.764  
  12.765 -void photon_videoquit(_THIS)
  12.766 +void
  12.767 +photon_videoquit(_THIS)
  12.768  {
  12.769 -   SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
  12.770 -   SDL_DisplayData* didata;
  12.771 -   uint32_t it;
  12.772 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
  12.773 +    SDL_DisplayData *didata;
  12.774 +    uint32_t it;
  12.775  
  12.776 -   /* SDL will restore our desktop mode on exit */
  12.777 -   for(it=0; it<_this->num_displays; it++)
  12.778 -   {
  12.779 -      didata=_this->displays[it].driverdata;
  12.780 +    /* SDL will restore our desktop mode on exit */
  12.781 +    for (it = 0; it < _this->num_displays; it++) {
  12.782 +        didata = _this->displays[it].driverdata;
  12.783  
  12.784 -      if (didata->cursor!=NULL)
  12.785 -      {
  12.786 -         SDL_free(didata->cursor);
  12.787 -      }
  12.788 -
  12.789 -      #if defined(SDL_VIDEO_OPENGL_ES)
  12.790 -         if (phdata->gfinitialized==SDL_TRUE)
  12.791 -         {
  12.792 +        if (didata->cursor != NULL) {
  12.793 +            SDL_free(didata->cursor);
  12.794 +        }
  12.795 +#if defined(SDL_VIDEO_OPENGL_ES)
  12.796 +        if (phdata->gfinitialized == SDL_TRUE) {
  12.797              /* Detach GF display */
  12.798              gf_display_detach(didata->display);
  12.799 -         }
  12.800 -      #endif /* SDL_VIDEO_OPENGL_ES */
  12.801 -   }
  12.802 +        }
  12.803 +#endif /* SDL_VIDEO_OPENGL_ES */
  12.804 +    }
  12.805  }
  12.806  
  12.807 -void photon_getdisplaymodes(_THIS)
  12.808 +void
  12.809 +photon_getdisplaymodes(_THIS)
  12.810  {
  12.811 -   SDL_VideoData*    phdata=(SDL_VideoData*)_this->driverdata;
  12.812 -   SDL_DisplayData*  didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
  12.813 -   SDL_DisplayMode   mode;
  12.814 -   PgVideoModes_t    modes;
  12.815 -   PgVideoModeInfo_t modeinfo;
  12.816 -   int32_t           status;
  12.817 -   uint32_t          it;
  12.818 -   uint32_t          jt;
  12.819 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
  12.820 +    SDL_DisplayData *didata =
  12.821 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
  12.822 +    SDL_DisplayMode mode;
  12.823 +    PgVideoModes_t modes;
  12.824 +    PgVideoModeInfo_t modeinfo;
  12.825 +    int32_t status;
  12.826 +    uint32_t it;
  12.827 +    uint32_t jt;
  12.828  
  12.829 -   /* Check if current device is not the same as target */
  12.830 -   if (phdata->current_device_id!=didata->device_id)
  12.831 -   {
  12.832 -      /* Set target device as default for Pd and Pg functions */
  12.833 -      status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
  12.834 -      if (status!=0)
  12.835 -      {
  12.836 -         SDL_SetError("Photon: Can't set default target device\n");
  12.837 -         return;
  12.838 -      }
  12.839 -      phdata->current_device_id=didata->device_id;
  12.840 -   }
  12.841 +    /* Check if current device is not the same as target */
  12.842 +    if (phdata->current_device_id != didata->device_id) {
  12.843 +        /* Set target device as default for Pd and Pg functions */
  12.844 +        status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
  12.845 +        if (status != 0) {
  12.846 +            SDL_SetError("Photon: Can't set default target device\n");
  12.847 +            return;
  12.848 +        }
  12.849 +        phdata->current_device_id = didata->device_id;
  12.850 +    }
  12.851  
  12.852 -   /* Get array of available video modes */
  12.853 -   status=PgGetVideoModeList(&modes);
  12.854 -   if (status!=0)
  12.855 -   {
  12.856 -      SDL_SetError("Photon: Can't get video mode list");
  12.857 -      return;
  12.858 -   }
  12.859 +    /* Get array of available video modes */
  12.860 +    status = PgGetVideoModeList(&modes);
  12.861 +    if (status != 0) {
  12.862 +        SDL_SetError("Photon: Can't get video mode list");
  12.863 +        return;
  12.864 +    }
  12.865  
  12.866 -   for (it=0; it<modes.num_modes; it++)
  12.867 -   {
  12.868 -      status=PgGetVideoModeInfo(modes.modes[it], &modeinfo);
  12.869 -      if (status!=0)
  12.870 -      {
  12.871 -         /* Maybe something wrong with this particular mode, skip it */
  12.872 -         continue;
  12.873 -      }
  12.874 +    for (it = 0; it < modes.num_modes; it++) {
  12.875 +        status = PgGetVideoModeInfo(modes.modes[it], &modeinfo);
  12.876 +        if (status != 0) {
  12.877 +            /* Maybe something wrong with this particular mode, skip it */
  12.878 +            continue;
  12.879 +        }
  12.880  
  12.881 -      jt=0;
  12.882 -      do {
  12.883 -         if (modeinfo.refresh_rates[jt]!=0)
  12.884 -         {
  12.885 -            mode.w=modeinfo.width;
  12.886 -            mode.h=modeinfo.height;
  12.887 -            mode.refresh_rate=modeinfo.refresh_rates[jt];
  12.888 -            mode.format=photon_image_to_sdl_pixelformat(modeinfo.type);
  12.889 -            mode.driverdata=NULL;
  12.890 -            SDL_AddDisplayMode(_this->current_display, &mode);
  12.891 -            jt++;
  12.892 -         }
  12.893 -         else
  12.894 -         {
  12.895 -            break;
  12.896 -         }
  12.897 -      } while(1);
  12.898 -   }
  12.899 +        jt = 0;
  12.900 +        do {
  12.901 +            if (modeinfo.refresh_rates[jt] != 0) {
  12.902 +                mode.w = modeinfo.width;
  12.903 +                mode.h = modeinfo.height;
  12.904 +                mode.refresh_rate = modeinfo.refresh_rates[jt];
  12.905 +                mode.format = photon_image_to_sdl_pixelformat(modeinfo.type);
  12.906 +                mode.driverdata = NULL;
  12.907 +                SDL_AddDisplayMode(_this->current_display, &mode);
  12.908 +                jt++;
  12.909 +            } else {
  12.910 +                break;
  12.911 +            }
  12.912 +        } while (1);
  12.913 +    }
  12.914  }
  12.915  
  12.916 -int photon_setdisplaymode(_THIS, SDL_DisplayMode* mode)
  12.917 +int
  12.918 +photon_setdisplaymode(_THIS, SDL_DisplayMode * mode)
  12.919  {
  12.920 -   SDL_VideoData*      phdata=(SDL_VideoData*)_this->driverdata;
  12.921 -   SDL_DisplayData*    didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
  12.922 -   PgVideoModes_t      modes;
  12.923 -   PgVideoModeInfo_t   modeinfo;
  12.924 -   PgDisplaySettings_t modesettings;
  12.925 -   uint32_t refresh_rate=0;
  12.926 -   int32_t  status;
  12.927 -   uint32_t it;
  12.928 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
  12.929 +    SDL_DisplayData *didata =
  12.930 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
  12.931 +    PgVideoModes_t modes;
  12.932 +    PgVideoModeInfo_t modeinfo;
  12.933 +    PgDisplaySettings_t modesettings;
  12.934 +    uint32_t refresh_rate = 0;
  12.935 +    int32_t status;
  12.936 +    uint32_t it;
  12.937  
  12.938 -   /* Check if current device is not the same as target */
  12.939 -   if (phdata->current_device_id!=didata->device_id)
  12.940 -   {
  12.941 -      /* Set target device as default for Pd and Pg functions */
  12.942 -      status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
  12.943 -      if (status!=0)
  12.944 -      {
  12.945 -         SDL_SetError("Photon: Can't set default target device\n");
  12.946 -         return;
  12.947 -      }
  12.948 -      phdata->current_device_id=didata->device_id;
  12.949 -   }
  12.950 +    /* Check if current device is not the same as target */
  12.951 +    if (phdata->current_device_id != didata->device_id) {
  12.952 +        /* Set target device as default for Pd and Pg functions */
  12.953 +        status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
  12.954 +        if (status != 0) {
  12.955 +            SDL_SetError("Photon: Can't set default target device\n");
  12.956 +            return;
  12.957 +        }
  12.958 +        phdata->current_device_id = didata->device_id;
  12.959 +    }
  12.960  
  12.961 -   /* Get array of available video modes */
  12.962 -   status=PgGetVideoModeList(&modes);
  12.963 -   if (status!=0)
  12.964 -   {
  12.965 -      SDL_SetError("Photon: Can't get video mode list");
  12.966 -      return;
  12.967 -   }
  12.968 +    /* Get array of available video modes */
  12.969 +    status = PgGetVideoModeList(&modes);
  12.970 +    if (status != 0) {
  12.971 +        SDL_SetError("Photon: Can't get video mode list");
  12.972 +        return;
  12.973 +    }
  12.974  
  12.975 -   /* Current display dimension and bpp are no more valid */
  12.976 -   didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN;
  12.977 -   didata->current_mode.w=0;
  12.978 -   didata->current_mode.h=0;
  12.979 +    /* Current display dimension and bpp are no more valid */
  12.980 +    didata->current_mode.format = SDL_PIXELFORMAT_UNKNOWN;
  12.981 +    didata->current_mode.w = 0;
  12.982 +    didata->current_mode.h = 0;
  12.983  
  12.984 -   /* Check if custom refresh rate requested */
  12.985 -   if (didata->custom_refresh!=0)
  12.986 -   {
  12.987 -      refresh_rate=didata->custom_refresh;
  12.988 -   }
  12.989 -   else
  12.990 -   {
  12.991 -      refresh_rate=mode->refresh_rate;
  12.992 -   }
  12.993 +    /* Check if custom refresh rate requested */
  12.994 +    if (didata->custom_refresh != 0) {
  12.995 +        refresh_rate = didata->custom_refresh;
  12.996 +    } else {
  12.997 +        refresh_rate = mode->refresh_rate;
  12.998 +    }
  12.999  
 12.1000 -   /* Check if SDL GF driver needs to find appropriate refresh rate itself */
 12.1001 -   if (refresh_rate==0)
 12.1002 -   {
 12.1003 -      SDL_DisplayMode tempmode;
 12.1004 +    /* Check if SDL GF driver needs to find appropriate refresh rate itself */
 12.1005 +    if (refresh_rate == 0) {
 12.1006 +        SDL_DisplayMode tempmode;
 12.1007  
 12.1008 -      /* Clear display mode structure */
 12.1009 -      SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
 12.1010 -      tempmode.refresh_rate=0x0000FFFF;
 12.1011 +        /* Clear display mode structure */
 12.1012 +        SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
 12.1013 +        tempmode.refresh_rate = 0x0000FFFF;
 12.1014  
 12.1015 -      /* Check if window width and height matches one of our modes */
 12.1016 -      for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++)
 12.1017 -      {
 12.1018 -         if ((SDL_CurrentDisplay.display_modes[it].w==mode->w) &&
 12.1019 -             (SDL_CurrentDisplay.display_modes[it].h==mode->h) &&
 12.1020 -             (SDL_CurrentDisplay.display_modes[it].format==mode->format))
 12.1021 -         {
 12.1022 -            /* Find the lowest refresh rate available */
 12.1023 -            if (tempmode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate)
 12.1024 +        /* Check if window width and height matches one of our modes */
 12.1025 +        for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) {
 12.1026 +            if ((SDL_CurrentDisplay.display_modes[it].w == mode->w) &&
 12.1027 +                (SDL_CurrentDisplay.display_modes[it].h == mode->h) &&
 12.1028 +                (SDL_CurrentDisplay.display_modes[it].format == mode->format))
 12.1029              {
 12.1030 -               tempmode=SDL_CurrentDisplay.display_modes[it];
 12.1031 +                /* Find the lowest refresh rate available */
 12.1032 +                if (tempmode.refresh_rate >
 12.1033 +                    SDL_CurrentDisplay.display_modes[it].refresh_rate) {
 12.1034 +                    tempmode = SDL_CurrentDisplay.display_modes[it];
 12.1035 +                }
 12.1036              }
 12.1037 -         }
 12.1038 -      }
 12.1039 -      if (tempmode.refresh_rate!=0x0000FFFF)
 12.1040 -      {
 12.1041 -         refresh_rate=tempmode.refresh_rate;
 12.1042 -      }
 12.1043 -      else
 12.1044 -      {
 12.1045 -         /* Let video driver decide what to do with this */
 12.1046 -         refresh_rate=0;
 12.1047 -      }
 12.1048 -   }
 12.1049 +        }
 12.1050 +        if (tempmode.refresh_rate != 0x0000FFFF) {
 12.1051 +            refresh_rate = tempmode.refresh_rate;
 12.1052 +        } else {
 12.1053 +            /* Let video driver decide what to do with this */
 12.1054 +            refresh_rate = 0;
 12.1055 +        }
 12.1056 +    }
 12.1057  
 12.1058 -   /* Check if SDL GF driver needs to check custom refresh rate */
 12.1059 -   if (didata->custom_refresh!=0)
 12.1060 -   {
 12.1061 -      SDL_DisplayMode tempmode;
 12.1062 +    /* Check if SDL GF driver needs to check custom refresh rate */
 12.1063 +    if (didata->custom_refresh != 0) {
 12.1064 +        SDL_DisplayMode tempmode;
 12.1065  
 12.1066 -      /* Clear display mode structure */
 12.1067 -      SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
 12.1068 -      tempmode.refresh_rate=0x0000FFFF;
 12.1069 +        /* Clear display mode structure */
 12.1070 +        SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
 12.1071 +        tempmode.refresh_rate = 0x0000FFFF;
 12.1072  
 12.1073 -      /* Check if window width and height matches one of our modes */
 12.1074 -      for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++)
 12.1075 -      {
 12.1076 -         if ((SDL_CurrentDisplay.display_modes[it].w==mode->w) &&
 12.1077 -             (SDL_CurrentDisplay.display_modes[it].h==mode->h) &&
 12.1078 -             (SDL_CurrentDisplay.display_modes[it].format==mode->format))
 12.1079 -         {
 12.1080 -            /* Find the lowest refresh rate available */
 12.1081 -            if (tempmode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate)
 12.1082 +        /* Check if window width and height matches one of our modes */
 12.1083 +        for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) {
 12.1084 +            if ((SDL_CurrentDisplay.display_modes[it].w == mode->w) &&
 12.1085 +                (SDL_CurrentDisplay.display_modes[it].h == mode->h) &&
 12.1086 +                (SDL_CurrentDisplay.display_modes[it].format == mode->format))
 12.1087              {
 12.1088 -               tempmode=SDL_CurrentDisplay.display_modes[it];
 12.1089 +                /* Find the lowest refresh rate available */
 12.1090 +                if (tempmode.refresh_rate >
 12.1091 +                    SDL_CurrentDisplay.display_modes[it].refresh_rate) {
 12.1092 +                    tempmode = SDL_CurrentDisplay.display_modes[it];
 12.1093 +                }
 12.1094 +
 12.1095 +                /* Check if requested refresh rate found */
 12.1096 +                if (refresh_rate ==
 12.1097 +                    SDL_CurrentDisplay.display_modes[it].refresh_rate) {
 12.1098 +                    tempmode = SDL_CurrentDisplay.display_modes[it];
 12.1099 +                    break;
 12.1100 +                }
 12.1101              }
 12.1102 +        }
 12.1103 +        if (tempmode.refresh_rate != 0x0000FFFF) {
 12.1104 +            refresh_rate = tempmode.refresh_rate;
 12.1105 +        } else {
 12.1106 +            /* Let video driver decide what to do with this */
 12.1107 +            refresh_rate = 0;
 12.1108 +        }
 12.1109 +    }
 12.1110  
 12.1111 -            /* Check if requested refresh rate found */
 12.1112 -            if (refresh_rate==SDL_CurrentDisplay.display_modes[it].refresh_rate)
 12.1113 -            {
 12.1114 -               tempmode=SDL_CurrentDisplay.display_modes[it];
 12.1115 -               break;
 12.1116 +    /* Find photon's video mode number */
 12.1117 +    for (it = 0; it < modes.num_modes; it++) {
 12.1118 +        uint32_t jt;
 12.1119 +        uint32_t foundrefresh;
 12.1120 +
 12.1121 +        /* Get current video mode details */
 12.1122 +        status = PgGetVideoModeInfo(modes.modes[it], &modeinfo);
 12.1123 +        if (status != 0) {
 12.1124 +            /* Maybe something wrong with this particular mode, skip it */
 12.1125 +            continue;
 12.1126 +        }
 12.1127 +        if ((modeinfo.width == mode->w) && (modeinfo.height == mode->h) &&
 12.1128 +            (modeinfo.type == photon_sdl_to_image_pixelformat(mode->format)))
 12.1129 +        {
 12.1130 +            /* Mode is found, find requested refresh rate, this case is for */
 12.1131 +            /* video drivers, which provide non-generic video modes.        */
 12.1132 +            jt = 0;
 12.1133 +            foundrefresh = 0;
 12.1134 +            do {
 12.1135 +                if (modeinfo.refresh_rates[jt] != 0) {
 12.1136 +                    if (modeinfo.refresh_rates[jt] == refresh_rate) {
 12.1137 +                        foundrefresh = 1;
 12.1138 +                        break;
 12.1139 +                    }
 12.1140 +                    jt++;
 12.1141 +                } else {
 12.1142 +                    break;
 12.1143 +                }
 12.1144 +            } while (1);
 12.1145 +            if (foundrefresh != 0) {
 12.1146 +                break;
 12.1147              }
 12.1148 -         }
 12.1149 -      }
 12.1150 -      if (tempmode.refresh_rate!=0x0000FFFF)
 12.1151 -      {
 12.1152 -         refresh_rate=tempmode.refresh_rate;
 12.1153 -      }
 12.1154 -      else
 12.1155 -      {
 12.1156 -         /* Let video driver decide what to do with this */
 12.1157 -         refresh_rate=0;
 12.1158 -      }
 12.1159 -   }
 12.1160 +        }
 12.1161 +    }
 12.1162  
 12.1163 -   /* Find photon's video mode number */
 12.1164 -   for (it=0; it<modes.num_modes; it++)
 12.1165 -   {
 12.1166 -      uint32_t jt;
 12.1167 -      uint32_t foundrefresh;
 12.1168 +    /* Check if video mode has not been found */
 12.1169 +    if (it == modes.num_modes) {
 12.1170 +        SDL_SetError("Photon: Can't find appropriate video mode");
 12.1171 +        return -1;
 12.1172 +    }
 12.1173  
 12.1174 -      /* Get current video mode details */
 12.1175 -      status=PgGetVideoModeInfo(modes.modes[it], &modeinfo);
 12.1176 -      if (status!=0)
 12.1177 -      {
 12.1178 -         /* Maybe something wrong with this particular mode, skip it */
 12.1179 -         continue;
 12.1180 -      }
 12.1181 -      if ((modeinfo.width==mode->w) && (modeinfo.height==mode->h) &&
 12.1182 -          (modeinfo.type==photon_sdl_to_image_pixelformat(mode->format)))
 12.1183 -      {
 12.1184 -         /* Mode is found, find requested refresh rate, this case is for */
 12.1185 -         /* video drivers, which provide non-generic video modes.        */
 12.1186 -         jt=0;
 12.1187 -         foundrefresh=0;
 12.1188 -         do {
 12.1189 -            if (modeinfo.refresh_rates[jt]!=0)
 12.1190 -            {
 12.1191 -               if (modeinfo.refresh_rates[jt]==refresh_rate)
 12.1192 -               {
 12.1193 -                  foundrefresh=1;
 12.1194 -                  break;
 12.1195 -               }
 12.1196 -               jt++;
 12.1197 -            }
 12.1198 -            else
 12.1199 -            {
 12.1200 -               break;
 12.1201 -            }
 12.1202 -         } while(1);
 12.1203 -         if (foundrefresh!=0)
 12.1204 -         {
 12.1205 -            break;
 12.1206 -         }
 12.1207 -      }
 12.1208 -   }
 12.1209 +    /* Fill mode settings */
 12.1210 +    modesettings.flags = 0x00000000;
 12.1211 +    modesettings.mode = modes.modes[it];
 12.1212 +    modesettings.refresh = refresh_rate;
 12.1213  
 12.1214 -   /* Check if video mode has not been found */
 12.1215 -   if (it==modes.num_modes)
 12.1216 -   {
 12.1217 -      SDL_SetError("Photon: Can't find appropriate video mode");
 12.1218 -      return -1;
 12.1219 -   }
 12.1220 +    /* Finally set new video mode */
 12.1221 +    status = PgSetVideoMode(&modesettings);
 12.1222 +    if (status != 0) {
 12.1223 +        SDL_SetError("Photon: Can't set new video mode");
 12.1224 +        return -1;
 12.1225 +    }
 12.1226  
 12.1227 -   /* Fill mode settings */
 12.1228 -   modesettings.flags=0x00000000;
 12.1229 -   modesettings.mode=modes.modes[it];
 12.1230 -   modesettings.refresh=refresh_rate;
 12.1231 +    /* Store new video mode parameters */
 12.1232 +    didata->current_mode = *mode;
 12.1233 +    didata->current_mode.refresh_rate = refresh_rate;
 12.1234  
 12.1235 -   /* Finally set new video mode */
 12.1236 -   status=PgSetVideoMode(&modesettings);
 12.1237 -   if (status!=0)
 12.1238 -   {
 12.1239 -      SDL_SetError("Photon: Can't set new video mode");
 12.1240 -      return -1;
 12.1241 -   }
 12.1242 -
 12.1243 -   /* Store new video mode parameters */
 12.1244 -   didata->current_mode=*mode;
 12.1245 -   didata->current_mode.refresh_rate=refresh_rate;
 12.1246 -
 12.1247 -   return 0;
 12.1248 +    return 0;
 12.1249  }
 12.1250  
 12.1251 -int photon_setdisplaypalette(_THIS, SDL_Palette* palette)
 12.1252 +int
 12.1253 +photon_setdisplaypalette(_THIS, SDL_Palette * palette)
 12.1254  {
 12.1255 -   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
 12.1256 +    SDL_DisplayData *didata =
 12.1257 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 12.1258  
 12.1259 -   /* Setting display palette operation has been failed */
 12.1260 -   return -1;
 12.1261 +    /* Setting display palette operation has been failed */
 12.1262 +    return -1;
 12.1263  }
 12.1264  
 12.1265 -int photon_getdisplaypalette(_THIS, SDL_Palette* palette)
 12.1266 +int
 12.1267 +photon_getdisplaypalette(_THIS, SDL_Palette * palette)
 12.1268  {
 12.1269 -   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
 12.1270 +    SDL_DisplayData *didata =
 12.1271 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 12.1272  
 12.1273 -   /* Getting display palette operation has been failed */
 12.1274 -   return -1;
 12.1275 +    /* Getting display palette operation has been failed */
 12.1276 +    return -1;
 12.1277  }
 12.1278  
 12.1279 -int photon_setdisplaygammaramp(_THIS, Uint16* ramp)
 12.1280 +int
 12.1281 +photon_setdisplaygammaramp(_THIS, Uint16 * ramp)
 12.1282  {
 12.1283 -   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
 12.1284 +    SDL_DisplayData *didata =
 12.1285 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 12.1286  
 12.1287 -   /* Setting display gamma ramp operation has been failed */
 12.1288 -   return -1;
 12.1289 +    /* Setting display gamma ramp operation has been failed */
 12.1290 +    return -1;
 12.1291  }
 12.1292  
 12.1293 -int photon_getdisplaygammaramp(_THIS, Uint16* ramp)
 12.1294 +int
 12.1295 +photon_getdisplaygammaramp(_THIS, Uint16 * ramp)
 12.1296  {
 12.1297 -   /* Getting display gamma ramp operation has been failed */
 12.1298 -   return -1;
 12.1299 +    /* Getting display gamma ramp operation has been failed */
 12.1300 +    return -1;
 12.1301  }
 12.1302  
 12.1303 -int photon_createwindow(_THIS, SDL_Window* window)
 12.1304 +int
 12.1305 +photon_createwindow(_THIS, SDL_Window * window)
 12.1306  {
 12.1307 -   SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
 12.1308 -   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
 12.1309 -   SDL_WindowData*  wdata;
 12.1310 -   PhDim_t          winsize;
 12.1311 -   PhPoint_t        winpos;
 12.1312 -   PtArg_t          winargs[32];
 12.1313 -   uint32_t         winargc=0;
 12.1314 -   int32_t          status;
 12.1315 -   PhRegion_t       wregion;
 12.1316 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.1317 +    SDL_DisplayData *didata =
 12.1318 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 12.1319 +    SDL_WindowData *wdata;
 12.1320 +    PhDim_t winsize;
 12.1321 +    PhPoint_t winpos;
 12.1322 +    PtArg_t winargs[32];
 12.1323 +    uint32_t winargc = 0;
 12.1324 +    int32_t status;
 12.1325 +    PhRegion_t wregion;
 12.1326  
 12.1327 -   /* Allocate window internal data */
 12.1328 -   wdata=(SDL_WindowData*)SDL_calloc(1, sizeof(SDL_WindowData));
 12.1329 -   if (wdata==NULL)
 12.1330 -   {
 12.1331 -      SDL_OutOfMemory();
 12.1332 -      return -1;
 12.1333 -   }
 12.1334 +    /* Allocate window internal data */
 12.1335 +    wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
 12.1336 +    if (wdata == NULL) {
 12.1337 +        SDL_OutOfMemory();
 12.1338 +        return -1;
 12.1339 +    }
 12.1340  
 12.1341 -   /* Setup driver data for this window */
 12.1342 -   window->driverdata=wdata;
 12.1343 +    /* Setup driver data for this window */
 12.1344 +    window->driverdata = wdata;
 12.1345  
 12.1346 -   /* Set initial window title */
 12.1347 -   if (window->title!=NULL)
 12.1348 -   {
 12.1349 -      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, window->title, 0);
 12.1350 -   }
 12.1351 -   else
 12.1352 -   {
 12.1353 -      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, "", 0);
 12.1354 -   }
 12.1355 +    /* Set initial window title */
 12.1356 +    if (window->title != NULL) {
 12.1357 +        PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, window->title, 0);
 12.1358 +    } else {
 12.1359 +        PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_TITLE, "", 0);
 12.1360 +    }
 12.1361  
 12.1362 -   /* TODO: handle SDL_WINDOW_INPUT_GRABBED */
 12.1363 +    /* TODO: handle SDL_WINDOW_INPUT_GRABBED */
 12.1364  
 12.1365 -   /* Disable default window filling on redraw */
 12.1366 -   PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE, Pt_BASIC_PREVENT_FILL);
 12.1367 +    /* Disable default window filling on redraw */
 12.1368 +    PtSetArg(&winargs[winargc++], Pt_ARG_BASIC_FLAGS, Pt_TRUE,
 12.1369 +             Pt_BASIC_PREVENT_FILL);
 12.1370  
 12.1371 -   /* Reset default managed flags to disabled state */
 12.1372 -   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
 12.1373 -            Ph_WM_APP_DEF_MANAGED);
 12.1374 -   /* Set which events we will not handle, let WM to handle them */
 12.1375 -   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
 12.1376 -            Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT  |
 12.1377 -            Ph_WM_FOCUS    | Ph_WM_HELP    | Ph_WM_HIDE     | Ph_WM_MAX     |
 12.1378 -            Ph_WM_MENU     | Ph_WM_MOVE    | Ph_WM_RESTORE  | Ph_WM_TASKBAR |
 12.1379 -            Ph_WM_TOBACK   | Ph_WM_RESIZE);
 12.1380 +    /* Reset default managed flags to disabled state */
 12.1381 +    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_FALSE,
 12.1382 +             Ph_WM_APP_DEF_MANAGED);
 12.1383 +    /* Set which events we will not handle, let WM to handle them */
 12.1384 +    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_MANAGED_FLAGS, Pt_TRUE,
 12.1385 +             Ph_WM_BACKDROP | Ph_WM_TOFRONT | Ph_WM_COLLAPSE | Ph_WM_FFRONT |
 12.1386 +             Ph_WM_FOCUS | Ph_WM_HELP | Ph_WM_HIDE | Ph_WM_MAX |
 12.1387 +             Ph_WM_MENU | Ph_WM_MOVE | Ph_WM_RESTORE | Ph_WM_TASKBAR |
 12.1388 +             Ph_WM_TOBACK | Ph_WM_RESIZE);
 12.1389  
 12.1390 -   /* Reset default notify events to disable */
 12.1391 -   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE,
 12.1392 -            Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP);
 12.1393 -   /* Set which events we will handle */
 12.1394 -   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
 12.1395 -            Ph_WM_CLOSE | Ph_WM_COLLAPSE | Ph_WM_FOCUS   | Ph_WM_MAX  |
 12.1396 -            Ph_WM_MOVE  | Ph_WM_RESIZE   | Ph_WM_RESTORE | Ph_WM_HIDE);
 12.1397 +    /* Reset default notify events to disable */
 12.1398 +    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_FALSE,
 12.1399 +             Ph_WM_RESIZE | Ph_WM_CLOSE | Ph_WM_HELP);
 12.1400 +    /* Set which events we will handle */
 12.1401 +    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_NOTIFY_FLAGS, Pt_TRUE,
 12.1402 +             Ph_WM_CLOSE | Ph_WM_COLLAPSE | Ph_WM_FOCUS | Ph_WM_MAX |
 12.1403 +             Ph_WM_MOVE | Ph_WM_RESIZE | Ph_WM_RESTORE | Ph_WM_HIDE);
 12.1404  
 12.1405 -   /* Borderless window can't be resizeable */
 12.1406 -   if ((window->flags & SDL_WINDOW_BORDERLESS)==SDL_WINDOW_BORDERLESS)
 12.1407 -   {
 12.1408 -      window->flags&=~(SDL_WINDOW_RESIZABLE);
 12.1409 -   }
 12.1410 +    /* Borderless window can't be resizeable */
 12.1411 +    if ((window->flags & SDL_WINDOW_BORDERLESS) == SDL_WINDOW_BORDERLESS) {
 12.1412 +        window->flags &= ~(SDL_WINDOW_RESIZABLE);
 12.1413 +    }
 12.1414  
 12.1415 -   /* Reset all default decorations */
 12.1416 -   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_APP_DEF_RENDER);
 12.1417 +    /* Reset all default decorations */
 12.1418 +    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE,
 12.1419 +             Ph_WM_APP_DEF_RENDER);
 12.1420  
 12.1421 -   /* Fullscreen window has its own decorations */
 12.1422 -   if ((window->flags & SDL_WINDOW_FULLSCREEN)==SDL_WINDOW_FULLSCREEN)
 12.1423 -   {
 12.1424 -      window->flags|=SDL_WINDOW_BORDERLESS;
 12.1425 -      window->flags&=~(SDL_WINDOW_RESIZABLE);
 12.1426 -      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
 12.1427 -               Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_TITLE);
 12.1428 -   }
 12.1429 -   else
 12.1430 -   {
 12.1431 -      uint32_t decorations=Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN |
 12.1432 -                           Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE;
 12.1433 +    /* Fullscreen window has its own decorations */
 12.1434 +    if ((window->flags & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN) {
 12.1435 +        window->flags |= SDL_WINDOW_BORDERLESS;
 12.1436 +        window->flags &= ~(SDL_WINDOW_RESIZABLE);
 12.1437 +        PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
 12.1438 +                 Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_TITLE);
 12.1439 +    } else {
 12.1440 +        uint32_t decorations =
 12.1441 +            Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MENU | Ph_WM_RENDER_MIN |
 12.1442 +            Ph_WM_RENDER_TITLE | Ph_WM_RENDER_MOVE;
 12.1443  
 12.1444 -      if ((window->flags & SDL_WINDOW_RESIZABLE)==SDL_WINDOW_RESIZABLE)
 12.1445 -      {
 12.1446 -         decorations|=Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX;
 12.1447 -         PtSetArg(&winargs[winargc++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED);
 12.1448 -      }
 12.1449 -      if ((window->flags & SDL_WINDOW_BORDERLESS)!=SDL_WINDOW_BORDERLESS)
 12.1450 -      {
 12.1451 -         decorations|=Ph_WM_RENDER_BORDER;
 12.1452 -      }
 12.1453 -      PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE, decorations);
 12.1454 -   }
 12.1455 +        if ((window->flags & SDL_WINDOW_RESIZABLE) == SDL_WINDOW_RESIZABLE) {
 12.1456 +            decorations |=
 12.1457 +                Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | Ph_WM_RENDER_MAX;
 12.1458 +            PtSetArg(&winargs[winargc++], Pt_ARG_RESIZE_FLAGS, Pt_TRUE,
 12.1459 +                     Pt_RESIZE_XY_AS_REQUIRED);
 12.1460 +        }
 12.1461 +        if ((window->flags & SDL_WINDOW_BORDERLESS) != SDL_WINDOW_BORDERLESS) {
 12.1462 +            decorations |= Ph_WM_RENDER_BORDER;
 12.1463 +        }
 12.1464 +        PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_TRUE,
 12.1465 +                 decorations);
 12.1466 +    }
 12.1467  
 12.1468 -   /* Set initial window state */
 12.1469 -   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE, Ph_WM_STATE_ISFOCUS);
 12.1470 -   PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISALTKEY);
 12.1471 +    /* Set initial window state */
 12.1472 +    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_FALSE,
 12.1473 +             Ph_WM_STATE_ISFOCUS);
 12.1474 +    PtSetArg(&winargs[winargc++], Pt_ARG_WINDOW_STATE, Pt_TRUE,
 12.1475 +             Ph_WM_STATE_ISALTKEY);
 12.1476  
 12.1477 -   /* Set window dimension */
 12.1478 -   winsize.w=window->w;
 12.1479 -   winsize.h=window->h;
 12.1480 -   PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0);
 12.1481 +    /* Set window dimension */
 12.1482 +    winsize.w = window->w;
 12.1483 +    winsize.h = window->h;
 12.1484 +    PtSetArg(&winargs[winargc++], Pt_ARG_DIM, &winsize, 0);
 12.1485  
 12.1486 -   /* Check if upper level requests WM to position window */
 12.1487 -   if ((window->x==SDL_WINDOWPOS_UNDEFINED) && (window->y==SDL_WINDOWPOS_UNDEFINED))
 12.1488 -   {
 12.1489 -      /* Do not set widget position, let WM to set it */
 12.1490 -   }
 12.1491 -   else
 12.1492 -   {
 12.1493 -      if (window->x==SDL_WINDOWPOS_UNDEFINED)
 12.1494 -      {
 12.1495 -         window->x=0;
 12.1496 -      }
 12.1497 -      if (window->y==SDL_WINDOWPOS_UNDEFINED)
 12.1498 -      {
 12.1499 -         window->y=0;
 12.1500 -      }
 12.1501 -      if (window->x==SDL_WINDOWPOS_CENTERED)
 12.1502 -      {
 12.1503 -         window->x=(didata->current_mode.w-window->w)/2;
 12.1504 -      }
 12.1505 -      if (window->y==SDL_WINDOWPOS_CENTERED)
 12.1506 -      {
 12.1507 -         window->y=(didata->current_mode.h-window->h)/2;
 12.1508 -      }
 12.1509 +    /* Check if upper level requests WM to position window */
 12.1510 +    if ((window->x == SDL_WINDOWPOS_UNDEFINED)
 12.1511 +        && (window->y == SDL_WINDOWPOS_UNDEFINED)) {
 12.1512 +        /* Do not set widget position, let WM to set it */
 12.1513 +    } else {
 12.1514 +        if (window->x == SDL_WINDOWPOS_UNDEFINED) {
 12.1515 +            window->x = 0;
 12.1516 +        }
 12.1517 +        if (window->y == SDL_WINDOWPOS_UNDEFINED) {
 12.1518 +            window->y = 0;
 12.1519 +        }
 12.1520 +        if (window->x == SDL_WINDOWPOS_CENTERED) {
 12.1521 +            window->x = (didata->current_mode.w - window->w) / 2;
 12.1522 +        }
 12.1523 +        if (window->y == SDL_WINDOWPOS_CENTERED) {
 12.1524 +            window->y = (didata->current_mode.h - window->h) / 2;
 12.1525 +        }
 12.1526  
 12.1527 -      /* Now set window position */
 12.1528 -      winpos.x=window->x;
 12.1529 -      winpos.y=window->y;
 12.1530 -      PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0);
 12.1531 -   }
 12.1532 +        /* Now set window position */
 12.1533 +        winpos.x = window->x;
 12.1534 +        winpos.y = window->y;
 12.1535 +        PtSetArg(&winargs[winargc++], Pt_ARG_POS, &winpos, 0);
 12.1536 +    }
 12.1537  
 12.1538 -   /* Check if window must support OpenGL ES rendering */
 12.1539 -   if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL)
 12.1540 -   {
 12.1541 -      #if defined(SDL_VIDEO_OPENGL_ES)
 12.1542 -         EGLBoolean initstatus;
 12.1543 +    /* Check if window must support OpenGL ES rendering */
 12.1544 +    if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
 12.1545 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.1546 +        EGLBoolean initstatus;
 12.1547  
 12.1548 -         /* Check if GF was initialized correctly */
 12.1549 -         if (phdata->gfinitialized==SDL_FALSE)
 12.1550 -         {
 12.1551 -            SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
 12.1552 +        /* Check if GF was initialized correctly */
 12.1553 +        if (phdata->gfinitialized == SDL_FALSE) {
 12.1554 +            SDL_SetError
 12.1555 +                ("Photon: GF initialization failed, no OpenGL ES support");
 12.1556              return -1;
 12.1557 -         }
 12.1558 +        }
 12.1559  
 12.1560 -         /* Mark this window as OpenGL ES compatible */
 12.1561 -         wdata->uses_gles=SDL_TRUE;
 12.1562 +        /* Mark this window as OpenGL ES compatible */
 12.1563 +        wdata->uses_gles = SDL_TRUE;
 12.1564  
 12.1565 -         /* Create connection to OpenGL ES */
 12.1566 -         if (phdata->egldisplay==EGL_NO_DISPLAY)
 12.1567 -         {
 12.1568 -            phdata->egldisplay=eglGetDisplay(phdata->gfdev);
 12.1569 -            if (phdata->egldisplay==EGL_NO_DISPLAY)
 12.1570 -            {
 12.1571 -               SDL_SetError("Photon: Can't get connection to OpenGL ES");
 12.1572 -               return -1;
 12.1573 +        /* Create connection to OpenGL ES */
 12.1574 +        if (phdata->egldisplay == EGL_NO_DISPLAY) {
 12.1575 +            phdata->egldisplay = eglGetDisplay(phdata->gfdev);
 12.1576 +            if (phdata->egldisplay == EGL_NO_DISPLAY) {
 12.1577 +                SDL_SetError("Photon: Can't get connection to OpenGL ES");
 12.1578 +                return -1;
 12.1579              }
 12.1580  
 12.1581              /* Initialize OpenGL ES library, ignore EGL version */
 12.1582 -            initstatus=eglInitialize(phdata->egldisplay, NULL, NULL);
 12.1583 -            if (initstatus!=EGL_TRUE)
 12.1584 -            {
 12.1585 -               SDL_SetError("Photon: Can't init OpenGL ES library");
 12.1586 -               return -1;
 12.1587 +            initstatus = eglInitialize(phdata->egldisplay, NULL, NULL);
 12.1588 +            if (initstatus != EGL_TRUE) {
 12.1589 +                SDL_SetError("Photon: Can't init OpenGL ES library");
 12.1590 +                return -1;
 12.1591              }
 12.1592 -         }
 12.1593 +        }
 12.1594  
 12.1595 -         /* Increment GL ES reference count usage */
 12.1596 -         phdata->egl_refcount++;
 12.1597 -      #else
 12.1598 -         SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.1599 -         return -1;
 12.1600 -      #endif /* SDL_VIDEO_OPENGL_ES */
 12.1601 -   }
 12.1602 +        /* Increment GL ES reference count usage */
 12.1603 +        phdata->egl_refcount++;
 12.1604 +#else
 12.1605 +        SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.1606 +        return -1;
 12.1607 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.1608 +    }
 12.1609  
 12.1610 -   /* Finally create the window */
 12.1611 -   wdata->window=PtCreateWidget(PtWindow, Pt_NO_PARENT, winargc, winargs);
 12.1612 -   if (wdata->window==NULL)
 12.1613 -   {
 12.1614 -      SDL_SetError("Photon: Can't create window widget");
 12.1615 -      SDL_free(wdata);
 12.1616 -      return -1;
 12.1617 -   }
 12.1618 +    /* Finally create the window */
 12.1619 +    wdata->window = PtCreateWidget(PtWindow, Pt_NO_PARENT, winargc, winargs);
 12.1620 +    if (wdata->window == NULL) {
 12.1621 +        SDL_SetError("Photon: Can't create window widget");
 12.1622 +        SDL_free(wdata);
 12.1623 +        return -1;
 12.1624 +    }
 12.1625  
 12.1626 -   /* Show widget */
 12.1627 -   status=PtRealizeWidget(wdata->window);
 12.1628 -   if (status!=0)
 12.1629 -   {
 12.1630 -      SDL_SetError("Photon: Can't realize window widget");
 12.1631 -      PtDestroyWidget(wdata->window);
 12.1632 -      SDL_free(wdata);
 12.1633 -      return;
 12.1634 -   }
 12.1635 +    /* Show widget */
 12.1636 +    status = PtRealizeWidget(wdata->window);
 12.1637 +    if (status != 0) {
 12.1638 +        SDL_SetError("Photon: Can't realize window widget");
 12.1639 +        PtDestroyWidget(wdata->window);
 12.1640 +        SDL_free(wdata);
 12.1641 +        return;
 12.1642 +    }
 12.1643  
 12.1644 -   /* Just created SDL window always gets focus */
 12.1645 -   window->flags|=SDL_WINDOW_INPUT_FOCUS;
 12.1646 +    /* Just created SDL window always gets focus */
 12.1647 +    window->flags |= SDL_WINDOW_INPUT_FOCUS;
 12.1648  
 12.1649 -   /* Create window-specific cursor after creation */
 12.1650 -   if (didata->cursor_visible==SDL_TRUE)
 12.1651 -   {
 12.1652 -      /* Setup cursor type. shape and default color */
 12.1653 -      PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR, 0);
 12.1654 -      PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
 12.1655 -      PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, didata->cursor, didata->cursor->hdr.len+sizeof(PhRegionDataHdr_t));
 12.1656 -   }
 12.1657 -   else
 12.1658 -   {
 12.1659 -      PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
 12.1660 -   }
 12.1661 +    /* Create window-specific cursor after creation */
 12.1662 +    if (didata->cursor_visible == SDL_TRUE) {
 12.1663 +        /* Setup cursor type. shape and default color */
 12.1664 +        PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR,
 12.1665 +                      Ph_CURSOR_DEFAULT_COLOR, 0);
 12.1666 +        PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
 12.1667 +        PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, didata->cursor,
 12.1668 +                      didata->cursor->hdr.len + sizeof(PhRegionDataHdr_t));
 12.1669 +    } else {
 12.1670 +        PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
 12.1671 +    }
 12.1672  
 12.1673 -   /* Set window region sensible to mouse motion events */
 12.1674 -   status=PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
 12.1675 -   if (status!=0)
 12.1676 -   {
 12.1677 -      SDL_SetError("Photon: Can't set region sensivity to mouse motion events");
 12.1678 -      PtDestroyWidget(wdata->window);
 12.1679 -      SDL_free(wdata);
 12.1680 -      return -1;
 12.1681 -   }
 12.1682 -   wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
 12.1683 -   status=PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
 12.1684 -   if (status<0)
 12.1685 -   {
 12.1686 -      SDL_SetError("Photon: Can't change region sensivity");
 12.1687 -      PtDestroyWidget(wdata->window);
 12.1688 -      SDL_free(wdata);
 12.1689 -      return -1;
 12.1690 -   }
 12.1691 +    /* Set window region sensible to mouse motion events */
 12.1692 +    status =
 12.1693 +        PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
 12.1694 +    if (status != 0) {
 12.1695 +        SDL_SetError
 12.1696 +            ("Photon: Can't set region sensivity to mouse motion events");
 12.1697 +        PtDestroyWidget(wdata->window);
 12.1698 +        SDL_free(wdata);
 12.1699 +        return -1;
 12.1700 +    }
 12.1701 +    wregion.events_sense |=
 12.1702 +        Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
 12.1703 +    status = PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
 12.1704 +    if (status < 0) {
 12.1705 +        SDL_SetError("Photon: Can't change region sensivity");
 12.1706 +        PtDestroyWidget(wdata->window);
 12.1707 +        SDL_free(wdata);
 12.1708 +        return -1;
 12.1709 +    }
 12.1710  
 12.1711 -   /* Flush all widget operations again */
 12.1712 -   PtFlush();
 12.1713 +    /* Flush all widget operations again */
 12.1714 +    PtFlush();
 12.1715  
 12.1716 -   /* By default last created window got a input focus */
 12.1717 -   SDL_SetKeyboardFocus(0, window->id);
 12.1718 +    /* By default last created window got a input focus */
 12.1719 +    SDL_SetKeyboardFocus(0, window->id);
 12.1720  
 12.1721 -   /* Window has been successfully created */
 12.1722 -   return 0;
 12.1723 +    /* Window has been successfully created */
 12.1724 +    return 0;
 12.1725  }
 12.1726  
 12.1727 -int photon_createwindowfrom(_THIS, SDL_Window* window, const void* data)
 12.1728 +int
 12.1729 +photon_createwindowfrom(_THIS, SDL_Window * window, const void *data)
 12.1730  {
 12.1731 -   /* TODO: it is possible */
 12.1732 +    /* TODO: it is possible */
 12.1733  
 12.1734 -   /* Failed to create window from another window */
 12.1735 -   return -1;
 12.1736 +    /* Failed to create window from another window */
 12.1737 +    return -1;
 12.1738  }
 12.1739  
 12.1740 -void photon_setwindowtitle(_THIS, SDL_Window* window)
 12.1741 +void
 12.1742 +photon_setwindowtitle(_THIS, SDL_Window * window)
 12.1743  {
 12.1744 -   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
 12.1745 -   int32_t status;
 12.1746 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.1747 +    int32_t status;
 12.1748  
 12.1749 -   /* Set window title */
 12.1750 -   if (window->title!=NULL)
 12.1751 -   {
 12.1752 -      status=PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, window->title, 0);
 12.1753 -   }
 12.1754 -   else
 12.1755 -   {
 12.1756 -      status=PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, "", 0);
 12.1757 -   }
 12.1758 +    /* Set window title */
 12.1759 +    if (window->title != NULL) {
 12.1760 +        status =
 12.1761 +            PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, window->title,
 12.1762 +                          0);
 12.1763 +    } else {
 12.1764 +        status = PtSetResource(wdata->window, Pt_ARG_WINDOW_TITLE, "", 0);
 12.1765 +    }
 12.1766  
 12.1767 -   if (status!=0)
 12.1768 -   {
 12.1769 -      SDL_SetError("Photon: Can't set window title");
 12.1770 -   }
 12.1771 +    if (status != 0) {
 12.1772 +        SDL_SetError("Photon: Can't set window title");
 12.1773 +    }
 12.1774  
 12.1775 -   /* Flush all widget operations */
 12.1776 -   PtFlush();
 12.1777 +    /* Flush all widget operations */
 12.1778 +    PtFlush();
 12.1779  }
 12.1780  
 12.1781 -void photon_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon)
 12.1782 +void
 12.1783 +photon_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon)
 12.1784  {
 12.1785 -   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
 12.1786 -   int32_t   status;
 12.1787 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.1788 +    int32_t status;
 12.1789  
 12.1790 -   /* TODO: Use iconify ? */
 12.1791 +    /* TODO: Use iconify ? */
 12.1792  
 12.1793 -   /* Flush all widget operations */
 12.1794 -   PtFlush();
 12.1795 +    /* Flush all widget operations */
 12.1796 +    PtFlush();
 12.1797  }
 12.1798  
 12.1799 -void photon_setwindowposition(_THIS, SDL_Window* window)
 12.1800 +void
 12.1801 +photon_setwindowposition(_THIS, SDL_Window * window)
 12.1802  {
 12.1803 -   SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
 12.1804 -   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
 12.1805 -   PhPoint_t winpos;
 12.1806 -   int32_t   status;
 12.1807 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.1808 +    SDL_DisplayData *didata =
 12.1809 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 12.1810 +    PhPoint_t winpos;
 12.1811 +    int32_t status;
 12.1812  
 12.1813 -   /* Check if upper level requests WM to position window */
 12.1814 -   if ((window->x==SDL_WINDOWPOS_UNDEFINED) && (window->y==SDL_WINDOWPOS_UNDEFINED))
 12.1815 -   {
 12.1816 -      /* Do not set widget position, let WM to set it */
 12.1817 -   }
 12.1818 -   else
 12.1819 -   {
 12.1820 -      if (window->x==SDL_WINDOWPOS_UNDEFINED)
 12.1821 -      {
 12.1822 -         window->x=0;
 12.1823 -      }
 12.1824 -      if (window->y==SDL_WINDOWPOS_UNDEFINED)
 12.1825 -      {
 12.1826 -         window->y=0;
 12.1827 -      }
 12.1828 -      if (window->x==SDL_WINDOWPOS_CENTERED)
 12.1829 -      {
 12.1830 -         window->x=(didata->current_mode.w-window->w)/2;
 12.1831 -      }
 12.1832 -      if (window->y==SDL_WINDOWPOS_CENTERED)
 12.1833 -      {
 12.1834 -         window->y=(didata->current_mode.h-window->h)/2;
 12.1835 -      }
 12.1836 +    /* Check if upper level requests WM to position window */
 12.1837 +    if ((window->x == SDL_WINDOWPOS_UNDEFINED)
 12.1838 +        && (window->y == SDL_WINDOWPOS_UNDEFINED)) {
 12.1839 +        /* Do not set widget position, let WM to set it */
 12.1840 +    } else {
 12.1841 +        if (window->x == SDL_WINDOWPOS_UNDEFINED) {
 12.1842 +            window->x = 0;
 12.1843 +        }
 12.1844 +        if (window->y == SDL_WINDOWPOS_UNDEFINED) {
 12.1845 +            window->y = 0;
 12.1846 +        }
 12.1847 +        if (window->x == SDL_WINDOWPOS_CENTERED) {
 12.1848 +            window->x = (didata->current_mode.w - window->w) / 2;
 12.1849 +        }
 12.1850 +        if (window->y == SDL_WINDOWPOS_CENTERED) {
 12.1851 +            window->y = (didata->current_mode.h - window->h) / 2;
 12.1852 +        }
 12.1853  
 12.1854 -      /* Now set window position */
 12.1855 -      winpos.x=window->x;
 12.1856 -      winpos.y=window->y;
 12.1857 -      status=PtSetResource(wdata->window, Pt_ARG_POS, &winpos, 0);
 12.1858 -      if (status!=0)
 12.1859 -      {
 12.1860 -         SDL_SetError("Photon: Can't set window position");
 12.1861 -      }
 12.1862 -   }
 12.1863 +        /* Now set window position */
 12.1864 +        winpos.x = window->x;
 12.1865 +        winpos.y = window->y;
 12.1866 +        status = PtSetResource(wdata->window, Pt_ARG_POS, &winpos, 0);
 12.1867 +        if (status != 0) {
 12.1868 +            SDL_SetError("Photon: Can't set window position");
 12.1869 +        }
 12.1870 +    }
 12.1871  
 12.1872 -   /* Flush all widget operations */
 12.1873 -   PtFlush();
 12.1874 +    /* Flush all widget operations */
 12.1875 +    PtFlush();
 12.1876  }
 12.1877  
 12.1878 -void photon_setwindowsize(_THIS, SDL_Window* window)
 12.1879 +void
 12.1880 +photon_setwindowsize(_THIS, SDL_Window * window)
 12.1881  {
 12.1882 -   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
 12.1883 -   PhDim_t winsize;
 12.1884 -   int32_t status;
 12.1885 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.1886 +    PhDim_t winsize;
 12.1887 +    int32_t status;
 12.1888  
 12.1889 -   winsize.w=window->w;
 12.1890 -   winsize.h=window->h;
 12.1891 +    winsize.w = window->w;
 12.1892 +    winsize.h = window->h;
 12.1893  
 12.1894 -   status=PtSetResource(wdata->window, Pt_ARG_DIM, &winsize, 0);
 12.1895 -   if (status!=0)
 12.1896 -   {
 12.1897 -      SDL_SetError("Photon: Can't set window size");
 12.1898 -   }
 12.1899 +    status = PtSetResource(wdata->window, Pt_ARG_DIM, &winsize, 0);
 12.1900 +    if (status != 0) {
 12.1901 +        SDL_SetError("Photon: Can't set window size");
 12.1902 +    }
 12.1903  
 12.1904 -   /* Flush all widget operations */
 12.1905 -   PtFlush();
 12.1906 +    /* Flush all widget operations */
 12.1907 +    PtFlush();
 12.1908  }
 12.1909  
 12.1910 -void photon_showwindow(_THIS, SDL_Window* window)
 12.1911 +void
 12.1912 +photon_showwindow(_THIS, SDL_Window * window)
 12.1913  {
 12.1914 -   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
 12.1915 -   int32_t status;
 12.1916 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.1917 +    int32_t status;
 12.1918  
 12.1919 -   /* Bring focus to window and put it in front of others */
 12.1920 -   PtWindowToFront(wdata->window);
 12.1921 +    /* Bring focus to window and put it in front of others */
 12.1922 +    PtWindowToFront(wdata->window);
 12.1923  
 12.1924 -   /* Flush all widget operations */
 12.1925 -   PtFlush();
 12.1926 +    /* Flush all widget operations */
 12.1927 +    PtFlush();
 12.1928  }
 12.1929  
 12.1930 -void photon_hidewindow(_THIS, SDL_Window* window)
 12.1931 +void
 12.1932 +photon_hidewindow(_THIS, SDL_Window * window)
 12.1933  {
 12.1934 -   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
 12.1935 -   PhWindowEvent_t winevent;
 12.1936 -   int32_t status;
 12.1937 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.1938 +    PhWindowEvent_t winevent;
 12.1939 +    int32_t status;
 12.1940  
 12.1941 -   SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
 12.1942 -   winevent.event_f=Ph_WM_HIDE;
 12.1943 -   winevent.rid=PtWidgetRid(wdata->window);
 12.1944 -   winevent.event_state=Ph_WM_EVSTATE_HIDE;
 12.1945 +    SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
 12.1946 +    winevent.event_f = Ph_WM_HIDE;
 12.1947 +    winevent.rid = PtWidgetRid(wdata->window);
 12.1948 +    winevent.event_state = Ph_WM_EVSTATE_HIDE;
 12.1949  
 12.1950 -   status=PtForwardWindowEvent(&winevent);
 12.1951 -   if (status!=0)
 12.1952 -   {
 12.1953 -      SDL_SetError("Photon: Can't hide window");
 12.1954 -   }
 12.1955 +    status = PtForwardWindowEvent(&winevent);
 12.1956 +    if (status != 0) {
 12.1957 +        SDL_SetError("Photon: Can't hide window");
 12.1958 +    }
 12.1959  
 12.1960 -   /* Flush all widget operations */
 12.1961 -   PtFlush();
 12.1962 +    /* Flush all widget operations */
 12.1963 +    PtFlush();
 12.1964  }
 12.1965  
 12.1966 -void photon_raisewindow(_THIS, SDL_Window* window)
 12.1967 +void
 12.1968 +photon_raisewindow(_THIS, SDL_Window * window)
 12.1969  {
 12.1970 -   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
 12.1971 -   PhWindowEvent_t winevent;
 12.1972 -   int32_t status;
 12.1973 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.1974 +    PhWindowEvent_t winevent;
 12.1975 +    int32_t status;
 12.1976  
 12.1977 -   SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
 12.1978 -   winevent.event_f=Ph_WM_HIDE;
 12.1979 -   winevent.rid=PtWidgetRid(wdata->window);
 12.1980 -   winevent.event_state=Ph_WM_EVSTATE_UNHIDE;
 12.1981 +    SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
 12.1982 +    winevent.event_f = Ph_WM_HIDE;
 12.1983 +    winevent.rid = PtWidgetRid(wdata->window);
 12.1984 +    winevent.event_state = Ph_WM_EVSTATE_UNHIDE;
 12.1985  
 12.1986 -   status=PtForwardWindowEvent(&winevent);
 12.1987 -   if (status!=0)
 12.1988 -   {
 12.1989 -      SDL_SetError("Photon: Can't hide window");
 12.1990 -   }
 12.1991 +    status = PtForwardWindowEvent(&winevent);
 12.1992 +    if (status != 0) {
 12.1993 +        SDL_SetError("Photon: Can't hide window");
 12.1994 +    }
 12.1995  
 12.1996 -   /* Flush all widget operations */
 12.1997 -   PtFlush();
 12.1998 +    /* Flush all widget operations */
 12.1999 +    PtFlush();
 12.2000  }
 12.2001  
 12.2002 -void photon_maximizewindow(_THIS, SDL_Window* window)
 12.2003 +void
 12.2004 +photon_maximizewindow(_THIS, SDL_Window * window)
 12.2005  {
 12.2006 -   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
 12.2007 -   PhWindowEvent_t winevent;
 12.2008 -   int32_t status;
 12.2009 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.2010 +    PhWindowEvent_t winevent;
 12.2011 +    int32_t status;
 12.2012  
 12.2013 -   /* Flush all widget operations */
 12.2014 -   PtFlush();
 12.2015 +    /* Flush all widget operations */
 12.2016 +    PtFlush();
 12.2017  }
 12.2018  
 12.2019 -void photon_minimizewindow(_THIS, SDL_Window* window)
 12.2020 +void
 12.2021 +photon_minimizewindow(_THIS, SDL_Window * window)
 12.2022  {
 12.2023 -   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
 12.2024 -   PhWindowEvent_t winevent;
 12.2025 -   int32_t status;
 12.2026 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.2027 +    PhWindowEvent_t winevent;
 12.2028 +    int32_t status;
 12.2029  
 12.2030 -   SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
 12.2031 -   winevent.event_f=Ph_WM_HIDE;
 12.2032 -   winevent.rid=PtWidgetRid(wdata->window);
 12.2033 -   winevent.event_state=Ph_WM_EVSTATE_HIDE;
 12.2034 +    SDL_memset(&winevent, 0x00, sizeof(PhWindowEvent_t));
 12.2035 +    winevent.event_f = Ph_WM_HIDE;
 12.2036 +    winevent.rid = PtWidgetRid(wdata->window);
 12.2037 +    winevent.event_state = Ph_WM_EVSTATE_HIDE;
 12.2038  
 12.2039 -   status=PtForwardWindowEvent(&winevent);
 12.2040 -   if (status!=0)
 12.2041 -   {
 12.2042 -      SDL_SetError("Photon: Can't hide window");
 12.2043 -   }
 12.2044 +    status = PtForwardWindowEvent(&winevent);
 12.2045 +    if (status != 0) {
 12.2046 +        SDL_SetError("Photon: Can't hide window");
 12.2047 +    }
 12.2048  
 12.2049 -   /* Flush all widget operations */
 12.2050 -   PtFlush();
 12.2051 +    /* Flush all widget operations */
 12.2052 +    PtFlush();
 12.2053  }
 12.2054  
 12.2055 -void photon_restorewindow(_THIS, SDL_Window* window)
 12.2056 +void
 12.2057 +photon_restorewindow(_THIS, SDL_Window * window)
 12.2058  {
 12.2059 -   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
 12.2060 -   PhWindowEvent_t winevent;
 12.2061 -   int32_t status;
 12.2062 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.2063 +    PhWindowEvent_t winevent;
 12.2064 +    int32_t status;
 12.2065  
 12.2066 -   /* Flush all widget operations */
 12.2067 -   PtFlush();
 12.2068 +    /* Flush all widget operations */
 12.2069 +    PtFlush();
 12.2070  }
 12.2071  
 12.2072 -void photon_setwindowgrab(_THIS, SDL_Window* window)
 12.2073 +void
 12.2074 +photon_setwindowgrab(_THIS, SDL_Window * window)
 12.2075  {
 12.2076 -   SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata;
 12.2077 -   PhWindowEvent_t winevent;
 12.2078 -   int32_t status;
 12.2079 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.2080 +    PhWindowEvent_t winevent;
 12.2081 +    int32_t status;
 12.2082  
 12.2083 -   /* Flush all widget operations */
 12.2084 -   PtFlush();
 12.2085 +    /* Flush all widget operations */
 12.2086 +    PtFlush();
 12.2087  }
 12.2088  
 12.2089 -void photon_destroywindow(_THIS, SDL_Window* window)
 12.2090 +void
 12.2091 +photon_destroywindow(_THIS, SDL_Window * window)
 12.2092  {
 12.2093 -   SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
 12.2094 -   SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
 12.2095 -   SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
 12.2096 -   int32_t status;
 12.2097 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.2098 +    SDL_DisplayData *didata =
 12.2099 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 12.2100 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.2101 +    int32_t status;
 12.2102  
 12.2103 -   if (wdata!=NULL)
 12.2104 -   {
 12.2105 -      status=PtDestroyWidget(wdata->window);
 12.2106 -      if (status!=0)
 12.2107 -      {
 12.2108 -         SDL_SetError("Photon: Can't destroy window widget");
 12.2109 -      }
 12.2110 -      wdata->window=NULL;
 12.2111 +    if (wdata != NULL) {
 12.2112 +        status = PtDestroyWidget(wdata->window);
 12.2113 +        if (status != 0) {
 12.2114 +            SDL_SetError("Photon: Can't destroy window widget");
 12.2115 +        }
 12.2116 +        wdata->window = NULL;
 12.2117  
 12.2118 -      #if defined(SDL_VIDEO_OPENGL_ES)
 12.2119 -         if (phdata->gfinitialized==SDL_TRUE)
 12.2120 -         {
 12.2121 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.2122 +        if (phdata->gfinitialized == SDL_TRUE) {
 12.2123              /* Destroy OpenGL ES surface if it was created */
 12.2124 -            if (wdata->gles_surface!=EGL_NO_SURFACE)
 12.2125 -            {
 12.2126 -               eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
 12.2127 +            if (wdata->gles_surface != EGL_NO_SURFACE) {
 12.2128 +                eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
 12.2129              }
 12.2130  
 12.2131              /* Free OpenGL ES target surface */
 12.2132 -            if (wdata->gfsurface!=NULL)
 12.2133 -            {
 12.2134 -               gf_surface_free(wdata->gfsurface);
 12.2135 +            if (wdata->gfsurface != NULL) {
 12.2136 +                gf_surface_free(wdata->gfsurface);
 12.2137              }
 12.2138  
 12.2139              phdata->egl_refcount--;
 12.2140 -            if (phdata->egl_refcount==0)
 12.2141 -            {
 12.2142 -               /* Terminate connection to OpenGL ES */
 12.2143 -               if (phdata->egldisplay!=EGL_NO_DISPLAY)
 12.2144 -               {
 12.2145 -                  eglTerminate(phdata->egldisplay);
 12.2146 -                  phdata->egldisplay=EGL_NO_DISPLAY;
 12.2147 -               }
 12.2148 +            if (phdata->egl_refcount == 0) {
 12.2149 +                /* Terminate connection to OpenGL ES */
 12.2150 +                if (phdata->egldisplay != EGL_NO_DISPLAY) {
 12.2151 +                    eglTerminate(phdata->egldisplay);
 12.2152 +                    phdata->egldisplay = EGL_NO_DISPLAY;
 12.2153 +                }
 12.2154              }
 12.2155 -         }
 12.2156 -      #endif /* SDL_VIDEO_OPENGL_ES */
 12.2157 -   }
 12.2158 +        }
 12.2159 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.2160 +    }
 12.2161  
 12.2162 -   /* Flush all widget operations */
 12.2163 -   PtFlush();
 12.2164 +    /* Flush all widget operations */
 12.2165 +    PtFlush();
 12.2166  }
 12.2167  
 12.2168  /*****************************************************************************/
 12.2169  /* SDL Window Manager function                                               */
 12.2170  /*****************************************************************************/
 12.2171 -SDL_bool photon_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo* info)
 12.2172 +SDL_bool
 12.2173 +photon_getwindowwminfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
 12.2174  {
 12.2175 -   if (info->version.major<=SDL_MAJOR_VERSION)
 12.2176 -   {
 12.2177 -      return SDL_TRUE;
 12.2178 -   }
 12.2179 -   else
 12.2180 -   {
 12.2181 -      SDL_SetError("application not compiled with SDL %d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
 12.2182 -      return SDL_FALSE;
 12.2183 -   }
 12.2184 +    if (info->version.major <= SDL_MAJOR_VERSION) {
 12.2185 +        return SDL_TRUE;
 12.2186 +    } else {
 12.2187 +        SDL_SetError("application not compiled with SDL %d.%d\n",
 12.2188 +                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
 12.2189 +        return SDL_FALSE;
 12.2190 +    }
 12.2191  
 12.2192 -   /* Failed to get window manager information */
 12.2193 -   return SDL_FALSE;
 12.2194 +    /* Failed to get window manager information */
 12.2195 +    return SDL_FALSE;
 12.2196  }
 12.2197  
 12.2198  /*****************************************************************************/
 12.2199  /* SDL OpenGL/OpenGL ES functions                                            */
 12.2200  /*****************************************************************************/
 12.2201 -int photon_gl_loadlibrary(_THIS, const char* path)
 12.2202 +int
 12.2203 +photon_gl_loadlibrary(_THIS, const char *path)
 12.2204  {
 12.2205 -   #if defined(SDL_VIDEO_OPENGL_ES)
 12.2206 -      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
 12.2207 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.2208 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.2209  
 12.2210 -      if (phdata->gfinitialized!=SDL_TRUE)
 12.2211 -      {
 12.2212 -         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
 12.2213 -         return NULL;
 12.2214 -      }
 12.2215 +    if (phdata->gfinitialized != SDL_TRUE) {
 12.2216 +        SDL_SetError
 12.2217 +            ("Photon: GF initialization failed, no OpenGL ES support");
 12.2218 +        return NULL;
 12.2219 +    }
 12.2220  
 12.2221 -      /* Check if OpenGL ES library is specified for GF driver */
 12.2222 -      if (path==NULL)
 12.2223 -      {
 12.2224 -         path=SDL_getenv("SDL_OPENGL_LIBRARY");
 12.2225 -         if (path==NULL)
 12.2226 -         {
 12.2227 -            path=SDL_getenv("SDL_OPENGLES_LIBRARY");
 12.2228 -         }
 12.2229 -      }
 12.2230 +    /* Check if OpenGL ES library is specified for GF driver */
 12.2231 +    if (path == NULL) {
 12.2232 +        path = SDL_getenv("SDL_OPENGL_LIBRARY");
 12.2233 +        if (path == NULL) {
 12.2234 +            path = SDL_getenv("SDL_OPENGLES_LIBRARY");
 12.2235 +        }
 12.2236 +    }
 12.2237  
 12.2238 -      /* Check if default library loading requested */
 12.2239 -      if (path==NULL)
 12.2240 -      {
 12.2241 -         /* Already linked with GF library which provides egl* subset of  */
 12.2242 -         /* functions, use Common profile of OpenGL ES library by default */
 12.2243 -         path="/usr/lib/libGLES_CM.so.1";
 12.2244 -      }
 12.2245 +    /* Check if default library loading requested */
 12.2246 +    if (path == NULL) {
 12.2247 +        /* Already linked with GF library which provides egl* subset of  */
 12.2248 +        /* functions, use Common profile of OpenGL ES library by default */
 12.2249 +        path = "/usr/lib/libGLES_CM.so.1";
 12.2250 +    }
 12.2251  
 12.2252 -      /* Load dynamic library */
 12.2253 -      _this->gl_config.dll_handle=SDL_LoadObject(path);
 12.2254 -      if (!_this->gl_config.dll_handle)
 12.2255 -      {
 12.2256 -         /* Failed to load new GL ES library */
 12.2257 -         SDL_SetError("Photon: Failed to locate OpenGL ES library");
 12.2258 -         return -1;
 12.2259 -      }
 12.2260 +    /* Load dynamic library */
 12.2261 +    _this->gl_config.dll_handle = SDL_LoadObject(path);
 12.2262 +    if (!_this->gl_config.dll_handle) {
 12.2263 +        /* Failed to load new GL ES library */
 12.2264 +        SDL_SetError("Photon: Failed to locate OpenGL ES library");
 12.2265 +        return -1;
 12.2266 +    }
 12.2267  
 12.2268 -      /* Store OpenGL ES library path and name */
 12.2269 -      SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path));
 12.2270 +    /* Store OpenGL ES library path and name */
 12.2271 +    SDL_strlcpy(_this->gl_config.driver_path, path,
 12.2272 +                SDL_arraysize(_this->gl_config.driver_path));
 12.2273  
 12.2274 -      /* New OpenGL ES library is loaded */
 12.2275 -      return 0;
 12.2276 -   #else
 12.2277 -      SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.2278 -      return -1;
 12.2279 -   #endif /* SDL_VIDEO_OPENGL_ES */
 12.2280 +    /* New OpenGL ES library is loaded */
 12.2281 +    return 0;
 12.2282 +#else
 12.2283 +    SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.2284 +    return -1;
 12.2285 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.2286  }
 12.2287  
 12.2288 -void* photon_gl_getprocaddres(_THIS, const char* proc)
 12.2289 +void *
 12.2290 +photon_gl_getprocaddres(_THIS, const char *proc)
 12.2291  {
 12.2292 -   #if defined(SDL_VIDEO_OPENGL_ES)
 12.2293 -      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
 12.2294 -      void* function_address;
 12.2295 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.2296 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.2297 +    void *function_address;
 12.2298  
 12.2299 -      if (phdata->gfinitialized!=SDL_TRUE)
 12.2300 -      {
 12.2301 -         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
 12.2302 -         return NULL;
 12.2303 -      }
 12.2304 +    if (phdata->gfinitialized != SDL_TRUE) {
 12.2305 +        SDL_SetError
 12.2306 +            ("Photon: GF initialization failed, no OpenGL ES support");
 12.2307 +        return NULL;
 12.2308 +    }
 12.2309  
 12.2310 -      /* Try to get function address through the egl interface */
 12.2311 -      function_address=eglGetProcAddress(proc);
 12.2312 -      if (function_address!=NULL)
 12.2313 -      {
 12.2314 -         return function_address;
 12.2315 -      }
 12.2316 +    /* Try to get function address through the egl interface */
 12.2317 +    function_address = eglGetProcAddress(proc);
 12.2318 +    if (function_address != NULL) {
 12.2319 +        return function_address;
 12.2320 +    }
 12.2321  
 12.2322 -      /* Then try to get function in the OpenGL ES library */
 12.2323 -      if (_this->gl_config.dll_handle)
 12.2324 -      {
 12.2325 -         function_address=SDL_LoadFunction(_this->gl_config.dll_handle, proc);
 12.2326 -         if (function_address!=NULL)
 12.2327 -         {
 12.2328 +    /* Then try to get function in the OpenGL ES library */
 12.2329 +    if (_this->gl_config.dll_handle) {
 12.2330 +        function_address =
 12.2331 +            SDL_LoadFunction(_this->gl_config.dll_handle, proc);
 12.2332 +        if (function_address != NULL) {
 12.2333              return function_address;
 12.2334 -         }
 12.2335 -      }
 12.2336 +        }
 12.2337 +    }
 12.2338  
 12.2339 -      /* Add emulated OpenGL ES 1.1 functions */
 12.2340 -      if (SDL_strcmp(proc, "glTexParameteri")==0)
 12.2341 -      {
 12.2342 -         return glTexParameteri;
 12.2343 -      }
 12.2344 -      if (SDL_strcmp(proc, "glTexParameteriv")==0)
 12.2345 -      {
 12.2346 -         return glTexParameteriv;
 12.2347 -      }
 12.2348 -      if (SDL_strcmp(proc, "glColor4ub")==0)
 12.2349 -      {
 12.2350 -         return glColor4ub;
 12.2351 -      }
 12.2352 +    /* Add emulated OpenGL ES 1.1 functions */
 12.2353 +    if (SDL_strcmp(proc, "glTexParameteri") == 0) {
 12.2354 +        return glTexParameteri;
 12.2355 +    }
 12.2356 +    if (SDL_strcmp(proc, "glTexParameteriv") == 0) {
 12.2357 +        return glTexParameteriv;
 12.2358 +    }
 12.2359 +    if (SDL_strcmp(proc, "glColor4ub") == 0) {
 12.2360 +        return glColor4ub;
 12.2361 +    }
 12.2362  
 12.2363 -      /* Failed to get GL ES function address pointer */
 12.2364 -      SDL_SetError("Photon: Cannot locate OpenGL ES function name");
 12.2365 -      return NULL;
 12.2366 -   #else
 12.2367 -      SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.2368 -      return NULL;
 12.2369 -   #endif /* SDL_VIDEO_OPENGL_ES */
 12.2370 +    /* Failed to get GL ES function address pointer */
 12.2371 +    SDL_SetError("Photon: Cannot locate OpenGL ES function name");
 12.2372 +    return NULL;
 12.2373 +#else
 12.2374 +    SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.2375 +    return NULL;
 12.2376 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.2377  }
 12.2378  
 12.2379 -void photon_gl_unloadlibrary(_THIS)
 12.2380 +void
 12.2381 +photon_gl_unloadlibrary(_THIS)
 12.2382  {
 12.2383 -   #if defined(SDL_VIDEO_OPENGL_ES)
 12.2384 -      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
 12.2385 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.2386 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.2387  
 12.2388 -      if (phdata->gfinitialized==SDL_TRUE)
 12.2389 -      {
 12.2390 -         /* Unload OpenGL ES library */
 12.2391 -         if (_this->gl_config.dll_handle)
 12.2392 -         {
 12.2393 +    if (phdata->gfinitialized == SDL_TRUE) {
 12.2394 +        /* Unload OpenGL ES library */
 12.2395 +        if (_this->gl_config.dll_handle) {
 12.2396              SDL_UnloadObject(_this->gl_config.dll_handle);
 12.2397 -            _this->gl_config.dll_handle=NULL;
 12.2398 -         }
 12.2399 -      }
 12.2400 -      else
 12.2401 -      {
 12.2402 -         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
 12.2403 -      }
 12.2404 -   #else
 12.2405 -      SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.2406 -      return;
 12.2407 -   #endif /* SDL_VIDEO_OPENGL_ES */
 12.2408 +            _this->gl_config.dll_handle = NULL;
 12.2409 +        }
 12.2410 +    } else {
 12.2411 +        SDL_SetError
 12.2412 +            ("Photon: GF initialization failed, no OpenGL ES support");
 12.2413 +    }
 12.2414 +#else
 12.2415 +    SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.2416 +    return;
 12.2417 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.2418  }
 12.2419  
 12.2420 -SDL_GLContext photon_gl_createcontext(_THIS, SDL_Window* window)
 12.2421 +SDL_GLContext
 12.2422 +photon_gl_createcontext(_THIS, SDL_Window * window)
 12.2423  {
 12.2424 -   #if defined(SDL_VIDEO_OPENGL_ES)
 12.2425 -      SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
 12.2426 -      SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
 12.2427 -      SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
 12.2428 -      EGLBoolean       status;
 12.2429 -      int32_t          gfstatus;
 12.2430 -      EGLint           configs;
 12.2431 -      uint32_t         attr_pos;
 12.2432 -      EGLint           attr_value;
 12.2433 -      EGLint           cit;
 12.2434 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.2435 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.2436 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.2437 +    SDL_DisplayData *didata =
 12.2438 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 12.2439 +    EGLBoolean status;
 12.2440 +    int32_t gfstatus;
 12.2441 +    EGLint configs;
 12.2442 +    uint32_t attr_pos;
 12.2443 +    EGLint attr_value;
 12.2444 +    EGLint cit;
 12.2445  
 12.2446 -      /* Check if GF was initialized */
 12.2447 -      if (phdata->gfinitialized!=SDL_TRUE)
 12.2448 -      {
 12.2449 -         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
 12.2450 -         return NULL;
 12.2451 -      }
 12.2452 +    /* Check if GF was initialized */
 12.2453 +    if (phdata->gfinitialized != SDL_TRUE) {
 12.2454 +        SDL_SetError
 12.2455 +            ("Photon: GF initialization failed, no OpenGL ES support");
 12.2456 +        return NULL;
 12.2457 +    }
 12.2458  
 12.2459 -      /* Prepare attributes list to pass them to OpenGL ES */
 12.2460 -      attr_pos=0;
 12.2461 -      wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID;
 12.2462 -      wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
 12.2463 -      wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE;
 12.2464 -      wdata->gles_attributes[attr_pos++]=_this->gl_config.red_size;
 12.2465 -      wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE;
 12.2466 -      wdata->gles_attributes[attr_pos++]=_this->gl_config.green_size;
 12.2467 -      wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE;
 12.2468 -      wdata->gles_attributes[attr_pos++]=_this->gl_config.blue_size;
 12.2469 -      wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE;
 12.2470 +    /* Prepare attributes list to pass them to OpenGL ES */
 12.2471 +    attr_pos = 0;
 12.2472 +    wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID;
 12.2473 +    wdata->gles_attributes[attr_pos++] =
 12.2474 +        qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
 12.2475 +    wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
 12.2476 +    wdata->gles_attributes[attr_pos++] = _this->gl_config.red_size;
 12.2477 +    wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
 12.2478 +    wdata->gles_attributes[attr_pos++] = _this->gl_config.green_size;
 12.2479 +    wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
 12.2480 +    wdata->gles_attributes[attr_pos++] = _this->gl_config.blue_size;
 12.2481 +    wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
 12.2482  
 12.2483 -      /* Setup alpha size in bits */
 12.2484 -      if (_this->gl_config.alpha_size)
 12.2485 -      {
 12.2486 -         wdata->gles_attributes[attr_pos++]=_this->gl_config.alpha_size;
 12.2487 -      }
 12.2488 -      else
 12.2489 -      {
 12.2490 -         wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2491 -      }
 12.2492 +    /* Setup alpha size in bits */
 12.2493 +    if (_this->gl_config.alpha_size) {
 12.2494 +        wdata->gles_attributes[attr_pos++] = _this->gl_config.alpha_size;
 12.2495 +    } else {
 12.2496 +        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2497 +    }
 12.2498  
 12.2499 -      /* Setup color buffer size */
 12.2500 -      if (_this->gl_config.buffer_size)
 12.2501 -      {
 12.2502 -         wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
 12.2503 -         wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
 12.2504 -      }
 12.2505 -      else
 12.2506 -      {
 12.2507 -         wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
 12.2508 -         wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2509 -      }
 12.2510 +    /* Setup color buffer size */
 12.2511 +    if (_this->gl_config.buffer_size) {
 12.2512 +        wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
 12.2513 +        wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
 12.2514 +    } else {
 12.2515 +        wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
 12.2516 +        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2517 +    }
 12.2518  
 12.2519 -      /* Setup depth buffer bits */
 12.2520 -      wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
 12.2521 -      wdata->gles_attributes[attr_pos++]=_this->gl_config.depth_size;
 12.2522 +    /* Setup depth buffer bits */
 12.2523 +    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
 12.2524 +    wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size;
 12.2525  
 12.2526 -      /* Setup stencil bits */
 12.2527 -      if (_this->gl_config.stencil_size)
 12.2528 -      {
 12.2529 -         wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
 12.2530 -         wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
 12.2531 -      }
 12.2532 -      else
 12.2533 -      {
 12.2534 -         wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
 12.2535 -         wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2536 -      }
 12.2537 +    /* Setup stencil bits */
 12.2538 +    if (_this->gl_config.stencil_size) {
 12.2539 +        wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
 12.2540 +        wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
 12.2541 +    } else {
 12.2542 +        wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
 12.2543 +        wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2544 +    }
 12.2545  
 12.2546 -      /* Set number of samples in multisampling */
 12.2547 -      if (_this->gl_config.multisamplesamples)
 12.2548 -      {
 12.2549 -         wdata->gles_attributes[attr_pos++]=EGL_SAMPLES;
 12.2550 -         wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplesamples;
 12.2551 -      }
 12.2552 +    /* Set number of samples in multisampling */
 12.2553 +    if (_this->gl_config.multisamplesamples) {
 12.2554 +        wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
 12.2555 +        wdata->gles_attributes[attr_pos++] =
 12.2556 +            _this->gl_config.multisamplesamples;
 12.2557 +    }
 12.2558  
 12.2559 -      /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
 12.2560 -      if (_this->gl_config.multisamplebuffers)
 12.2561 -      {
 12.2562 -         wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS;
 12.2563 -         wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplebuffers;
 12.2564 -      }
 12.2565 +    /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
 12.2566 +    if (_this->gl_config.multisamplebuffers) {
 12.2567 +        wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
 12.2568 +        wdata->gles_attributes[attr_pos++] =
 12.2569 +            _this->gl_config.multisamplebuffers;
 12.2570 +    }
 12.2571  
 12.2572 -      /* Finish attributes list */
 12.2573 -      wdata->gles_attributes[attr_pos]=EGL_NONE;
 12.2574 +    /* Finish attributes list */
 12.2575 +    wdata->gles_attributes[attr_pos] = EGL_NONE;
 12.2576  
 12.2577 -      /* Request first suitable framebuffer configuration */
 12.2578 -      status=eglChooseConfig(phdata->egldisplay, wdata->gles_attributes,
 12.2579 -                             wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
 12.2580 -      if (status!=EGL_TRUE)
 12.2581 -      {
 12.2582 -         SDL_SetError("Photon: Can't find closest configuration for OpenGL ES");
 12.2583 -         return NULL;
 12.2584 -      }
 12.2585 +    /* Request first suitable framebuffer configuration */
 12.2586 +    status = eglChooseConfig(phdata->egldisplay, wdata->gles_attributes,
 12.2587 +                             wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS,
 12.2588 +                             &configs);
 12.2589 +    if (status != EGL_TRUE) {
 12.2590 +        SDL_SetError
 12.2591 +            ("Photon: Can't find closest configuration for OpenGL ES");
 12.2592 +        return NULL;
 12.2593 +    }
 12.2594  
 12.2595 -      /* Check if nothing has been found, try "don't care" settings */
 12.2596 -      if (configs==0)
 12.2597 -      {
 12.2598 -         int32_t it;
 12.2599 -         int32_t jt;
 12.2600 -         GLint   depthbits[4]={32, 24, 16, EGL_DONT_CARE};
 12.2601 +    /* Check if nothing has been found, try "don't care" settings */
 12.2602 +    if (configs == 0) {
 12.2603 +        int32_t it;
 12.2604 +        int32_t jt;
 12.2605 +        GLint depthbits[4] = { 32, 24, 16, EGL_DONT_CARE };
 12.2606  
 12.2607 -         for (it=0; it<4; it++)
 12.2608 -         {
 12.2609 -            for (jt=16; jt>=0; jt--)
 12.2610 -            {
 12.2611 -               /* Don't care about color buffer bits, use what exist */
 12.2612 -               /* Replace previous set data with EGL_DONT_CARE       */
 12.2613 -               attr_pos=0;
 12.2614 -               wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID;
 12.2615 -               wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
 12.2616 -               wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE;
 12.2617 -               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2618 -               wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE;
 12.2619 -               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2620 -               wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE;
 12.2621 -               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2622 -               wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE;
 12.2623 -               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2624 -               wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
 12.2625 -               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2626 +        for (it = 0; it < 4; it++) {
 12.2627 +            for (jt = 16; jt >= 0; jt--) {
 12.2628 +                /* Don't care about color buffer bits, use what exist */
 12.2629 +                /* Replace previous set data with EGL_DONT_CARE       */
 12.2630 +                attr_pos = 0;
 12.2631 +                wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID;
 12.2632 +                wdata->gles_attributes[attr_pos++] =
 12.2633 +                    qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
 12.2634 +                wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
 12.2635 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2636 +                wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
 12.2637 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2638 +                wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
 12.2639 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2640 +                wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
 12.2641 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2642 +                wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
 12.2643 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2644  
 12.2645 -               /* Try to find requested or smallest depth */
 12.2646 -               if (_this->gl_config.depth_size)
 12.2647 -               {
 12.2648 -                  wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
 12.2649 -                  wdata->gles_attributes[attr_pos++]=depthbits[it];
 12.2650 -               }
 12.2651 -               else
 12.2652 -               {
 12.2653 -                  wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
 12.2654 -                  wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2655 -               }
 12.2656 +                /* Try to find requested or smallest depth */
 12.2657 +                if (_this->gl_config.depth_size) {
 12.2658 +                    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
 12.2659 +                    wdata->gles_attributes[attr_pos++] = depthbits[it];
 12.2660 +                } else {
 12.2661 +                    wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
 12.2662 +                    wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2663 +                }
 12.2664  
 12.2665 -               if (_this->gl_config.stencil_size)
 12.2666 -               {
 12.2667 -                  wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
 12.2668 -                  wdata->gles_attributes[attr_pos++]=jt;
 12.2669 -               }
 12.2670 -               else
 12.2671 -               {
 12.2672 -                  wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
 12.2673 -                  wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2674 -               }
 12.2675 +                if (_this->gl_config.stencil_size) {
 12.2676 +                    wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
 12.2677 +                    wdata->gles_attributes[attr_pos++] = jt;
 12.2678 +                } else {
 12.2679 +                    wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
 12.2680 +                    wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2681 +                }
 12.2682  
 12.2683 -               wdata->gles_attributes[attr_pos++]=EGL_SAMPLES;
 12.2684 -               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2685 -               wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS;
 12.2686 -               wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
 12.2687 -               wdata->gles_attributes[attr_pos]=EGL_NONE;
 12.2688 +                wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
 12.2689 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2690 +                wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
 12.2691 +                wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
 12.2692 +                wdata->gles_attributes[attr_pos] = EGL_NONE;
 12.2693  
 12.2694 -               /* Request first suitable framebuffer configuration */
 12.2695 -               status=eglChooseConfig(phdata->egldisplay, wdata->gles_attributes,
 12.2696 -                                      wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
 12.2697 -               if (status!=EGL_TRUE)
 12.2698 -               {
 12.2699 -                  SDL_SetError("Photon: Can't find closest configuration for OpenGL ES");
 12.2700 -                  return NULL;
 12.2701 -               }
 12.2702 -               if (configs!=0)
 12.2703 -               {
 12.2704 -                  break;
 12.2705 -               }
 12.2706 +                /* Request first suitable framebuffer configuration */
 12.2707 +                status =
 12.2708 +                    eglChooseConfig(phdata->egldisplay,
 12.2709 +                                    wdata->gles_attributes,
 12.2710 +                                    wdata->gles_configs,
 12.2711 +                                    SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
 12.2712 +                if (status != EGL_TRUE) {
 12.2713 +                    SDL_SetError
 12.2714 +                        ("Photon: Can't find closest configuration for OpenGL ES");
 12.2715 +                    return NULL;
 12.2716 +                }
 12.2717 +                if (configs != 0) {
 12.2718 +                    break;
 12.2719 +                }
 12.2720              }
 12.2721 -            if (configs!=0)
 12.2722 -            {
 12.2723 -               break;
 12.2724 +            if (configs != 0) {
 12.2725 +                break;
 12.2726              }
 12.2727 -         }
 12.2728 +        }
 12.2729  
 12.2730 -         /* No available configs */
 12.2731 -         if (configs==0)
 12.2732 -         {
 12.2733 -            SDL_SetError("Photon: Can't find any configuration for OpenGL ES");
 12.2734 +        /* No available configs */
 12.2735 +        if (configs == 0) {
 12.2736 +            SDL_SetError
 12.2737 +                ("Photon: Can't find any configuration for OpenGL ES");
 12.2738              return NULL;
 12.2739 -         }
 12.2740 -      }
 12.2741 +        }
 12.2742 +    }
 12.2743  
 12.2744 -      /* Initialize config index */
 12.2745 -      wdata->gles_config=0;
 12.2746 +    /* Initialize config index */
 12.2747 +    wdata->gles_config = 0;
 12.2748  
 12.2749 -      /* Now check each configuration to find out the best */
 12.2750 -      for (cit=0; cit<configs; cit++)
 12.2751 -      {
 12.2752 -         uint32_t stencil_found;
 12.2753 -         uint32_t depth_found;
 12.2754 +    /* Now check each configuration to find out the best */
 12.2755 +    for (cit = 0; cit < configs; cit++) {
 12.2756 +        uint32_t stencil_found;
 12.2757 +        uint32_t depth_found;
 12.2758  
 12.2759 -         stencil_found=0;
 12.2760 -         depth_found=0;
 12.2761 +        stencil_found = 0;
 12.2762 +        depth_found = 0;
 12.2763  
 12.2764 -         if (_this->gl_config.stencil_size)
 12.2765 -         {
 12.2766 -            status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[cit], EGL_STENCIL_SIZE, &attr_value);
 12.2767 -            if (status==EGL_TRUE)
 12.2768 -            {
 12.2769 -               if (attr_value!=0)
 12.2770 -               {
 12.2771 -                  stencil_found=1;
 12.2772 -               }
 12.2773 +        if (_this->gl_config.stencil_size) {
 12.2774 +            status =
 12.2775 +                eglGetConfigAttrib(phdata->egldisplay,
 12.2776 +                                   wdata->gles_configs[cit], EGL_STENCIL_SIZE,
 12.2777 +                                   &attr_value);
 12.2778 +            if (status == EGL_TRUE) {
 12.2779 +                if (attr_value != 0) {
 12.2780 +                    stencil_found = 1;
 12.2781 +                }
 12.2782              }
 12.2783 -         }
 12.2784 -         else
 12.2785 -         {
 12.2786 -            stencil_found=1;
 12.2787 -         }
 12.2788 +        } else {
 12.2789 +            stencil_found = 1;
 12.2790 +        }
 12.2791  
 12.2792 -         if (_this->gl_config.depth_size)
 12.2793 -         {
 12.2794 -            status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[cit], EGL_DEPTH_SIZE, &attr_value);
 12.2795 -            if (status==EGL_TRUE)
 12.2796 -            {
 12.2797 -               if (attr_value!=0)
 12.2798 -               {
 12.2799 -                  depth_found=1;
 12.2800 -               }
 12.2801 +        if (_this->gl_config.depth_size) {
 12.2802 +            status =
 12.2803 +                eglGetConfigAttrib(phdata->egldisplay,
 12.2804 +                                   wdata->gles_configs[cit], EGL_DEPTH_SIZE,
 12.2805 +                                   &attr_value);
 12.2806 +            if (status == EGL_TRUE) {
 12.2807 +                if (attr_value != 0) {
 12.2808 +                    depth_found = 1;
 12.2809 +                }
 12.2810              }
 12.2811 -         }
 12.2812 -         else
 12.2813 -         {
 12.2814 -            depth_found=1;
 12.2815 -         }
 12.2816 +        } else {
 12.2817 +            depth_found = 1;
 12.2818 +        }
 12.2819  
 12.2820 -         /* Exit from loop if found appropriate configuration */
 12.2821 -         if ((depth_found!=0) && (stencil_found!=0))
 12.2822 -         {
 12.2823 +        /* Exit from loop if found appropriate configuration */
 12.2824 +        if ((depth_found != 0) && (stencil_found != 0)) {
 12.2825              break;
 12.2826 -         }
 12.2827 -      }
 12.2828 +        }
 12.2829 +    }
 12.2830  
 12.2831 -      /* If best could not be found, use first */
 12.2832 -      if (cit==configs)
 12.2833 -      {
 12.2834 -         cit=0;
 12.2835 -      }
 12.2836 -      wdata->gles_config=cit;
 12.2837 +    /* If best could not be found, use first */
 12.2838 +    if (cit == configs) {
 12.2839 +        cit = 0;
 12.2840 +    }
 12.2841 +    wdata->gles_config = cit;
 12.2842  
 12.2843 -      /* Create OpenGL ES context */
 12.2844 -      wdata->gles_context=eglCreateContext(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_NO_CONTEXT, NULL);
 12.2845 -      if (wdata->gles_context==EGL_NO_CONTEXT)
 12.2846 -      {
 12.2847 -         SDL_SetError("Photon: OpenGL ES context creation has been failed");
 12.2848 -         return NULL;
 12.2849 -      }
 12.2850 +    /* Create OpenGL ES context */
 12.2851 +    wdata->gles_context =
 12.2852 +        eglCreateContext(phdata->egldisplay,
 12.2853 +                         wdata->gles_configs[wdata->gles_config],
 12.2854 +                         EGL_NO_CONTEXT, NULL);
 12.2855 +    if (wdata->gles_context == EGL_NO_CONTEXT) {
 12.2856 +        SDL_SetError("Photon: OpenGL ES context creation has been failed");
 12.2857 +        return NULL;
 12.2858 +    }
 12.2859  
 12.2860 -      /* Check if surface is exist */
 12.2861 -      if (wdata->gfsurface!=NULL)
 12.2862 -      {
 12.2863 -         gf_surface_free(wdata->gfsurface);
 12.2864 -         wdata->gfsurface=NULL;
 12.2865 -      }
 12.2866 +    /* Check if surface is exist */
 12.2867 +    if (wdata->gfsurface != NULL) {
 12.2868 +        gf_surface_free(wdata->gfsurface);
 12.2869 +        wdata->gfsurface = NULL;
 12.2870 +    }
 12.2871  
 12.2872 -      /* Create GF surface */
 12.2873 -      gfstatus=gf_surface_create(&wdata->gfsurface, phdata->gfdev, window->w, window->h,
 12.2874 -               qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format), NULL,
 12.2875 -               GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE |
 12.2876 -               GF_SURFACE_CREATE_SHAREABLE);
 12.2877 -      if (gfstatus!=GF_ERR_OK)
 12.2878 -      {
 12.2879 -         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
 12.2880 -         wdata->gles_context=EGL_NO_CONTEXT;
 12.2881 -         SDL_SetError("Photon: Can't create GF 3D surface (%08X)", gfstatus);
 12.2882 -         return NULL;
 12.2883 -      }
 12.2884 +    /* Create GF surface */
 12.2885 +    gfstatus =
 12.2886 +        gf_surface_create(&wdata->gfsurface, phdata->gfdev, window->w,
 12.2887 +                          window->h,
 12.2888 +                          qnxgf_sdl_to_gf_pixelformat(didata->current_mode.
 12.2889 +                                                      format), NULL,
 12.2890 +                          GF_SURFACE_CREATE_2D_ACCESSIBLE |
 12.2891 +                          GF_SURFACE_CREATE_3D_ACCESSIBLE |
 12.2892 +                          GF_SURFACE_CREATE_SHAREABLE);
 12.2893 +    if (gfstatus != GF_ERR_OK) {
 12.2894 +        eglDestroyContext(phdata->egldisplay, wdata->gles_context);
 12.2895 +        wdata->gles_context = EGL_NO_CONTEXT;
 12.2896 +        SDL_SetError("Photon: Can't create GF 3D surface (%08X)", gfstatus);
 12.2897 +        return NULL;
 12.2898 +    }
 12.2899  
 12.2900 -      /* Create pixmap 3D target surface */
 12.2901 -      wdata->gles_surface=eglCreatePixmapSurface(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], wdata->gfsurface, NULL);
 12.2902 -      if (wdata->gles_surface==EGL_NO_SURFACE)
 12.2903 -      {
 12.2904 -         gf_surface_free(wdata->gfsurface);
 12.2905 -         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
 12.2906 -         wdata->gles_context=EGL_NO_CONTEXT;
 12.2907 -         SDL_SetError("Photon: Can't create EGL pixmap surface");
 12.2908 -         return NULL;
 12.2909 -      }
 12.2910 +    /* Create pixmap 3D target surface */
 12.2911 +    wdata->gles_surface =
 12.2912 +        eglCreatePixmapSurface(phdata->egldisplay,
 12.2913 +                               wdata->gles_configs[wdata->gles_config],
 12.2914 +                               wdata->gfsurface, NULL);
 12.2915 +    if (wdata->gles_surface == EGL_NO_SURFACE) {
 12.2916 +        gf_surface_free(wdata->gfsurface);
 12.2917 +        eglDestroyContext(phdata->egldisplay, wdata->gles_context);
 12.2918 +        wdata->gles_context = EGL_NO_CONTEXT;
 12.2919 +        SDL_SetError("Photon: Can't create EGL pixmap surface");
 12.2920 +        return NULL;
 12.2921 +    }
 12.2922  
 12.2923 -      /* Make just created context current */
 12.2924 -      status=eglMakeCurrent(phdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context);
 12.2925 -      if (status!=EGL_TRUE)
 12.2926 -      {
 12.2927 -         /* Destroy OpenGL ES surface */
 12.2928 -         eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
 12.2929 -         gf_surface_free(wdata->gfsurface);
 12.2930 -         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
 12.2931 -         wdata->gles_context=EGL_NO_CONTEXT;
 12.2932 -         SDL_SetError("Photon: Can't set OpenGL ES context on creation");
 12.2933 -         return NULL;
 12.2934 -      }
 12.2935 +    /* Make just created context current */
 12.2936 +    status =
 12.2937 +        eglMakeCurrent(phdata->egldisplay, wdata->gles_surface,
 12.2938 +                       wdata->gles_surface, wdata->gles_context);
 12.2939 +    if (status != EGL_TRUE) {
 12.2940 +        /* Destroy OpenGL ES surface */
 12.2941 +        eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
 12.2942 +        gf_surface_free(wdata->gfsurface);
 12.2943 +        eglDestroyContext(phdata->egldisplay, wdata->gles_context);
 12.2944 +        wdata->gles_context = EGL_NO_CONTEXT;
 12.2945 +        SDL_SetError("Photon: Can't set OpenGL ES context on creation");
 12.2946 +        return NULL;
 12.2947 +    }
 12.2948  
 12.2949 -      /* Setup into SDL internals state of OpenGL ES:  */
 12.2950 -      /* it is accelerated or not                      */
 12.2951 -      if ((didata->caps & SDL_PHOTON_ACCELERATED_3D)==SDL_PHOTON_ACCELERATED_3D)
 12.2952 -      {
 12.2953 -         _this->gl_config.accelerated=1;
 12.2954 -      }
 12.2955 -      else
 12.2956 -      {
 12.2957 -         _this->gl_config.accelerated=0;
 12.2958 -      }
 12.2959 +    /* Setup into SDL internals state of OpenGL ES:  */
 12.2960 +    /* it is accelerated or not                      */
 12.2961 +    if ((didata->caps & SDL_PHOTON_ACCELERATED_3D) ==
 12.2962 +        SDL_PHOTON_ACCELERATED_3D) {
 12.2963 +        _this->gl_config.accelerated = 1;
 12.2964 +    } else {
 12.2965 +        _this->gl_config.accelerated = 0;
 12.2966 +    }
 12.2967  
 12.2968 -      /* Always clear stereo enable, since OpenGL ES do not supports stereo */
 12.2969 -      _this->gl_config.stereo=0;
 12.2970 +    /* Always clear stereo enable, since OpenGL ES do not supports stereo */
 12.2971 +    _this->gl_config.stereo = 0;
 12.2972  
 12.2973 -      /* Get back samples and samplebuffers configurations. Rest framebuffer */
 12.2974 -      /* parameters could be obtained through the OpenGL ES API              */
 12.2975 -      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLES, &attr_value);
 12.2976 -      if (status==EGL_TRUE)
 12.2977 -      {
 12.2978 -         _this->gl_config.multisamplesamples=attr_value;
 12.2979 -      }
 12.2980 -      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLE_BUFFERS, &attr_value);
 12.2981 -      if (status==EGL_TRUE)
 12.2982 -      {
 12.2983 -         _this->gl_config.multisamplebuffers=attr_value;
 12.2984 -      }
 12.2985 +    /* Get back samples and samplebuffers configurations. Rest framebuffer */
 12.2986 +    /* parameters could be obtained through the OpenGL ES API              */
 12.2987 +    status =
 12.2988 +        eglGetConfigAttrib(phdata->egldisplay,
 12.2989 +                           wdata->gles_configs[wdata->gles_config],
 12.2990 +                           EGL_SAMPLES, &attr_value);
 12.2991 +    if (status == EGL_TRUE) {
 12.2992 +        _this->gl_config.multisamplesamples = attr_value;
 12.2993 +    }
 12.2994 +    status =
 12.2995 +        eglGetConfigAttrib(phdata->egldisplay,
 12.2996 +                           wdata->gles_configs[wdata->gles_config],
 12.2997 +                           EGL_SAMPLE_BUFFERS, &attr_value);
 12.2998 +    if (status == EGL_TRUE) {
 12.2999 +        _this->gl_config.multisamplebuffers = attr_value;
 12.3000 +    }
 12.3001  
 12.3002 -      /* Get back stencil and depth buffer sizes */
 12.3003 -      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_DEPTH_SIZE, &attr_value);
 12.3004 -      if (status==EGL_TRUE)
 12.3005 -      {
 12.3006 -         _this->gl_config.depth_size=attr_value;
 12.3007 -      }
 12.3008 -      status=eglGetConfigAttrib(phdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_STENCIL_SIZE, &attr_value);
 12.3009 -      if (status==EGL_TRUE)
 12.3010 -      {
 12.3011 -         _this->gl_config.stencil_size=attr_value;
 12.3012 -      }
 12.3013 +    /* Get back stencil and depth buffer sizes */
 12.3014 +    status =
 12.3015 +        eglGetConfigAttrib(phdata->egldisplay,
 12.3016 +                           wdata->gles_configs[wdata->gles_config],
 12.3017 +                           EGL_DEPTH_SIZE, &attr_value);
 12.3018 +    if (status == EGL_TRUE) {
 12.3019 +        _this->gl_config.depth_size = attr_value;
 12.3020 +    }
 12.3021 +    status =
 12.3022 +        eglGetConfigAttrib(phdata->egldisplay,
 12.3023 +                           wdata->gles_configs[wdata->gles_config],
 12.3024 +                           EGL_STENCIL_SIZE, &attr_value);
 12.3025 +    if (status == EGL_TRUE) {
 12.3026 +        _this->gl_config.stencil_size = attr_value;
 12.3027 +    }
 12.3028  
 12.3029 -      /* Under Photon OpenGL ES output can't be double buffered */
 12.3030 -      _this->gl_config.double_buffer=0;
 12.3031 +    /* Under Photon OpenGL ES output can't be double buffered */
 12.3032 +    _this->gl_config.double_buffer = 0;
 12.3033  
 12.3034 -      /* Check if current device is not the same as target */
 12.3035 -      if (phdata->current_device_id!=didata->device_id)
 12.3036 -      {
 12.3037 -         /* Set target device as default for Pd and Pg functions */
 12.3038 -         status=PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
 12.3039 -         if (status!=0)
 12.3040 -         {
 12.3041 +    /* Check if current device is not the same as target */
 12.3042 +    if (phdata->current_device_id != didata->device_id) {
 12.3043 +        /* Set target device as default for Pd and Pg functions */
 12.3044 +        status = PdSetTargetDevice(NULL, phdata->rid[didata->device_id]);
 12.3045 +        if (status != 0) {
 12.3046              /* Destroy OpenGL ES surface */
 12.3047              eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
 12.3048              gf_surface_free(wdata->gfsurface);
 12.3049              eglDestroyContext(phdata->egldisplay, wdata->gles_context);
 12.3050 -            wdata->gles_context=EGL_NO_CONTEXT;
 12.3051 +            wdata->gles_context = EGL_NO_CONTEXT;
 12.3052              SDL_SetError("Photon: Can't set default target device\n");
 12.3053              return NULL;
 12.3054 -         }
 12.3055 -         phdata->current_device_id=didata->device_id;
 12.3056 -      }
 12.3057 +        }
 12.3058 +        phdata->current_device_id = didata->device_id;
 12.3059 +    }
 12.3060  
 12.3061 -      wdata->phsurface=PdCreateOffscreenContextGF(wdata->gfsurface);
 12.3062 -      if (wdata->phsurface==NULL)
 12.3063 -      {
 12.3064 -         /* Destroy OpenGL ES surface */
 12.3065 -         eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
 12.3066 -         gf_surface_free(wdata->gfsurface);
 12.3067 -         eglDestroyContext(phdata->egldisplay, wdata->gles_context);
 12.3068 -         wdata->gles_context=EGL_NO_CONTEXT;
 12.3069 -         SDL_SetError("Photon: Can't bind GF surface to Photon\n");
 12.3070 -         return NULL;
 12.3071 -      }
 12.3072 +    wdata->phsurface = PdCreateOffscreenContextGF(wdata->gfsurface);
 12.3073 +    if (wdata->phsurface == NULL) {
 12.3074 +        /* Destroy OpenGL ES surface */
 12.3075 +        eglDestroySurface(phdata->egldisplay, wdata->gles_surface);
 12.3076 +        gf_surface_free(wdata->gfsurface);
 12.3077 +        eglDestroyContext(phdata->egldisplay, wdata->gles_context);
 12.3078 +        wdata->gles_context = EGL_NO_CONTEXT;
 12.3079 +        SDL_SetError("Photon: Can't bind GF surface to Photon\n");
 12.3080 +        return NULL;
 12.3081 +    }
 12.3082  
 12.3083 -      /* GL ES context was successfully created */
 12.3084 -      return wdata->gles_context;
 12.3085 -   #else
 12.3086 -      SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3087 -      return NULL;
 12.3088 -   #endif /* SDL_VIDEO_OPENGL_ES */
 12.3089 +    /* GL ES context was successfully created */
 12.3090 +    return wdata->gles_context;
 12.3091 +#else
 12.3092 +    SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3093 +    return NULL;
 12.3094 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.3095  }
 12.3096  
 12.3097 -int photon_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context)
 12.3098 +int
 12.3099 +photon_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context)
 12.3100  {
 12.3101 -   #if defined(SDL_VIDEO_OPENGL_ES)
 12.3102 -      SDL_VideoData*  phdata=(SDL_VideoData*)_this->driverdata;
 12.3103 -      SDL_WindowData* wdata;
 12.3104 -      EGLBoolean status;
 12.3105 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.3106 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.3107 +    SDL_WindowData *wdata;
 12.3108 +    EGLBoolean status;
 12.3109  
 12.3110 -      if (phdata->gfinitialized!=SDL_TRUE)
 12.3111 -      {
 12.3112 -         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
 12.3113 -         return -1;
 12.3114 -      }
 12.3115 +    if (phdata->gfinitialized != SDL_TRUE) {
 12.3116 +        SDL_SetError
 12.3117 +            ("Photon: GF initialization failed, no OpenGL ES support");
 12.3118 +        return -1;
 12.3119 +    }
 12.3120  
 12.3121 -      if ((window==NULL) && (context==NULL))
 12.3122 -      {
 12.3123 -         status=eglMakeCurrent(phdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
 12.3124 -         if (status!=EGL_TRUE)
 12.3125 -         {
 12.3126 +    if ((window == NULL) && (context == NULL)) {
 12.3127 +        status =
 12.3128 +            eglMakeCurrent(phdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
 12.3129 +                           EGL_NO_CONTEXT);
 12.3130 +        if (status != EGL_TRUE) {
 12.3131              /* Failed to set current GL ES context */
 12.3132              SDL_SetError("Photon: Can't set OpenGL ES context");
 12.3133              return -1;
 12.3134 -         }
 12.3135 -      }
 12.3136 -      else
 12.3137 -      {
 12.3138 -         wdata=(SDL_WindowData*)window->driverdata;
 12.3139 -         if (wdata->gles_surface==EGL_NO_SURFACE)
 12.3140 -         {
 12.3141 -            SDL_SetError("Photon: OpenGL ES surface is not initialized for this window");
 12.3142 +        }
 12.3143 +    } else {
 12.3144 +        wdata = (SDL_WindowData *) window->driverdata;
 12.3145 +        if (wdata->gles_surface == EGL_NO_SURFACE) {
 12.3146 +            SDL_SetError
 12.3147 +                ("Photon: OpenGL ES surface is not initialized for this window");
 12.3148              return -1;
 12.3149 -         }
 12.3150 -         if (wdata->gles_context==EGL_NO_CONTEXT)
 12.3151 -         {
 12.3152 -            SDL_SetError("Photon: OpenGL ES context is not initialized for this window");
 12.3153 +        }
 12.3154 +        if (wdata->gles_context == EGL_NO_CONTEXT) {
 12.3155 +            SDL_SetError
 12.3156 +                ("Photon: OpenGL ES context is not initialized for this window");
 12.3157              return -1;
 12.3158 -         }
 12.3159 -         if (wdata->gles_context!=context)
 12.3160 -         {
 12.3161 -            SDL_SetError("Photon: OpenGL ES context is not belong to this window");
 12.3162 +        }
 12.3163 +        if (wdata->gles_context != context) {
 12.3164 +            SDL_SetError
 12.3165 +                ("Photon: OpenGL ES context is not belong to this window");
 12.3166              return -1;
 12.3167 -         }
 12.3168 -         status=eglMakeCurrent(phdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context);
 12.3169 -         if (status!=EGL_TRUE)
 12.3170 -         {
 12.3171 +        }
 12.3172 +        status =
 12.3173 +            eglMakeCurrent(phdata->egldisplay, wdata->gles_surface,
 12.3174 +                           wdata->gles_surface, wdata->gles_context);
 12.3175 +        if (status != EGL_TRUE) {
 12.3176              /* Failed to set current GL ES context */
 12.3177              SDL_SetError("Photon: Can't set OpenGL ES context");
 12.3178              return -1;
 12.3179 -         }
 12.3180 -      }
 12.3181 +        }
 12.3182 +    }
 12.3183  
 12.3184 -      return 0;
 12.3185 -   #else
 12.3186 -      SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3187 -      return -1;
 12.3188 -   #endif /* SDL_VIDEO_OPENGL_ES */
 12.3189 +    return 0;
 12.3190 +#else
 12.3191 +    SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3192 +    return -1;
 12.3193 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.3194  }
 12.3195  
 12.3196 -int photon_gl_setswapinterval(_THIS, int interval)
 12.3197 +int
 12.3198 +photon_gl_setswapinterval(_THIS, int interval)
 12.3199  {
 12.3200 -   #if defined(SDL_VIDEO_OPENGL_ES)
 12.3201 -      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
 12.3202 -      EGLBoolean     status;
 12.3203 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.3204 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.3205 +    EGLBoolean status;
 12.3206  
 12.3207 -      if (phdata->gfinitialized!=SDL_TRUE)
 12.3208 -      {
 12.3209 -         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
 12.3210 -         return -1;
 12.3211 -      }
 12.3212 +    if (phdata->gfinitialized != SDL_TRUE) {
 12.3213 +        SDL_SetError
 12.3214 +            ("Photon: GF initialization failed, no OpenGL ES support");
 12.3215 +        return -1;
 12.3216 +    }
 12.3217  
 12.3218 -      /* Check if OpenGL ES connection has been initialized */
 12.3219 -      if (phdata->egldisplay!=EGL_NO_DISPLAY)
 12.3220 -      {
 12.3221 -         /* Set swap OpenGL ES interval */
 12.3222 -         status=eglSwapInterval(phdata->egldisplay, interval);
 12.3223 -         if (status==EGL_TRUE)
 12.3224 -         {
 12.3225 +    /* Check if OpenGL ES connection has been initialized */
 12.3226 +    if (phdata->egldisplay != EGL_NO_DISPLAY) {
 12.3227 +        /* Set swap OpenGL ES interval */
 12.3228 +        status = eglSwapInterval(phdata->egldisplay, interval);
 12.3229 +        if (status == EGL_TRUE) {
 12.3230              /* Return success to upper level */
 12.3231 -            phdata->swapinterval=interval;
 12.3232 +            phdata->swapinterval = interval;
 12.3233              return 0;
 12.3234 -         }
 12.3235 -      }
 12.3236 +        }
 12.3237 +    }
 12.3238  
 12.3239 -      /* Failed to set swap interval */
 12.3240 -      SDL_SetError("Photon: Cannot set swap interval");
 12.3241 -      return -1;
 12.3242 -   #else
 12.3243 -      SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3244 -      return -1;
 12.3245 -   #endif /* SDL_VIDEO_OPENGL_ES */
 12.3246 +    /* Failed to set swap interval */
 12.3247 +    SDL_SetError("Photon: Cannot set swap interval");
 12.3248 +    return -1;
 12.3249 +#else
 12.3250 +    SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3251 +    return -1;
 12.3252 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.3253  }
 12.3254  
 12.3255 -int photon_gl_getswapinterval(_THIS)
 12.3256 +int
 12.3257 +photon_gl_getswapinterval(_THIS)
 12.3258  {
 12.3259 -   #if defined(SDL_VIDEO_OPENGL_ES)
 12.3260 -      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
 12.3261 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.3262 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.3263  
 12.3264 -      if (phdata->gfinitialized!=SDL_TRUE)
 12.3265 -      {
 12.3266 -         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
 12.3267 -         return -1;
 12.3268 -      }
 12.3269 +    if (phdata->gfinitialized != SDL_TRUE) {
 12.3270 +        SDL_SetError
 12.3271 +            ("Photon: GF initialization failed, no OpenGL ES support");
 12.3272 +        return -1;
 12.3273 +    }
 12.3274  
 12.3275 -      /* Return default swap interval value */
 12.3276 -      return phdata->swapinterval;
 12.3277 -   #else
 12.3278 -      SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3279 -      return -1;
 12.3280 -   #endif /* SDL_VIDEO_OPENGL_ES */
 12.3281 +    /* Return default swap interval value */
 12.3282 +    return phdata->swapinterval;
 12.3283 +#else
 12.3284 +    SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3285 +    return -1;
 12.3286 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.3287  }
 12.3288  
 12.3289 -void photon_gl_swapwindow(_THIS, SDL_Window* window)
 12.3290 +void
 12.3291 +photon_gl_swapwindow(_THIS, SDL_Window * window)
 12.3292  {
 12.3293 -   #if defined(SDL_VIDEO_OPENGL_ES)
 12.3294 -      SDL_VideoData*   phdata=(SDL_VideoData*)_this->driverdata;
 12.3295 -      SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
 12.3296 -      SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
 12.3297 -      PhRect_t         dst_rect;
 12.3298 -      PhRect_t         src_rect;
 12.3299 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.3300 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.3301 +    SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
 12.3302 +    SDL_DisplayData *didata =
 12.3303 +        (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
 12.3304 +    PhRect_t dst_rect;
 12.3305 +    PhRect_t src_rect;
 12.3306  
 12.3307 -      if (phdata->gfinitialized!=SDL_TRUE)
 12.3308 -      {
 12.3309 -         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
 12.3310 -         return;
 12.3311 -      }
 12.3312 +    if (phdata->gfinitialized != SDL_TRUE) {
 12.3313 +        SDL_SetError
 12.3314 +            ("Photon: GF initialization failed, no OpenGL ES support");
 12.3315 +        return;
 12.3316 +    }
 12.3317  
 12.3318 -      /* Many applications do not uses glFinish(), so we call it for them */
 12.3319 -      glFinish();
 12.3320 +    /* Many applications do not uses glFinish(), so we call it for them */
 12.3321 +    glFinish();
 12.3322  
 12.3323 -      /* Wait until OpenGL ES rendering is completed */
 12.3324 -      eglWaitGL();
 12.3325 +    /* Wait until OpenGL ES rendering is completed */
 12.3326 +    eglWaitGL();
 12.3327  
 12.3328 -      /* Wait for VSYNC manually, if it was enabled */
 12.3329 -      if (phdata->swapinterval!=0)
 12.3330 -      {
 12.3331 -         /* Wait for VSYNC, we use GF function, since Photon requires */
 12.3332 -         /* to enter to the Direct mode to call PgWaitVSync()         */
 12.3333 -         gf_display_wait_vsync(didata->display);
 12.3334 -      }
 12.3335 +    /* Wait for VSYNC manually, if it was enabled */
 12.3336 +    if (phdata->swapinterval != 0) {
 12.3337 +        /* Wait for VSYNC, we use GF function, since Photon requires */
 12.3338 +        /* to enter to the Direct mode to call PgWaitVSync()         */
 12.3339 +        gf_display_wait_vsync(didata->display);
 12.3340 +    }
 12.3341  
 12.3342 -      /* Set blit area */
 12.3343 -      dst_rect=*PtGetCanvas(wdata->window);
 12.3344 -      src_rect.ul.x=0;
 12.3345 -      src_rect.ul.y=0;
 12.3346 -      src_rect.lr.x=window->w-1;
 12.3347 -      src_rect.lr.y=window->h-1;
 12.3348 +    /* Set blit area */
 12.3349 +    dst_rect = *PtGetCanvas(wdata->window);
 12.3350 +    src_rect.ul.x = 0;
 12.3351 +    src_rect.ul.y = 0;
 12.3352 +    src_rect.lr.x = window->w - 1;
 12.3353 +    src_rect.lr.y = window->h - 1;
 12.3354  
 12.3355 -      /* Blit OpenGL ES pixmap surface directly to window region */
 12.3356 -      PgFFlush(Ph_START_DRAW);
 12.3357 -      PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
 12.3358 -      PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
 12.3359 -      PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
 12.3360 -      PgFFlush(Ph_DONE_DRAW);
 12.3361 -      PgWaitHWIdle();
 12.3362 +    /* Blit OpenGL ES pixmap surface directly to window region */
 12.3363 +    PgFFlush(Ph_START_DRAW);
 12.3364 +    PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
 12.3365 +    PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
 12.3366 +    PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
 12.3367 +    PgFFlush(Ph_DONE_DRAW);
 12.3368 +    PgWaitHWIdle();
 12.3369  
 12.3370 -      eglSwapBuffers(phdata->egldisplay, wdata->gles_surface);
 12.3371 -   #else
 12.3372 -      SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3373 -      return;
 12.3374 -   #endif /* SDL_VIDEO_OPENGL_ES */
 12.3375 +    eglSwapBuffers(phdata->egldisplay, wdata->gles_surface);
 12.3376 +#else
 12.3377 +    SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3378 +    return;
 12.3379 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.3380  }
 12.3381  
 12.3382 -void photon_gl_deletecontext(_THIS, SDL_GLContext context)
 12.3383 +void
 12.3384 +photon_gl_deletecontext(_THIS, SDL_GLContext context)
 12.3385  {
 12.3386 -   #if defined(SDL_VIDEO_OPENGL_ES)
 12.3387 -      SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata;
 12.3388 -      EGLBoolean     status;
 12.3389 +#if defined(SDL_VIDEO_OPENGL_ES)
 12.3390 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
 12.3391 +    EGLBoolean status;
 12.3392  
 12.3393 -      if (phdata->gfinitialized!=SDL_TRUE)
 12.3394 -      {
 12.3395 -         SDL_SetError("Photon: GF initialization failed, no OpenGL ES support");
 12.3396 -         return;
 12.3397 -      }
 12.3398 +    if (phdata->gfinitialized != SDL_TRUE) {
 12.3399 +        SDL_SetError
 12.3400 +            ("Photon: GF initialization failed, no OpenGL ES support");
 12.3401 +        return;
 12.3402 +    }
 12.3403  
 12.3404 -      /* Check if OpenGL ES connection has been initialized */
 12.3405 -      if (phdata->egldisplay!=EGL_NO_DISPLAY)
 12.3406 -      {
 12.3407 -         if (context!=EGL_NO_CONTEXT)
 12.3408 -         {
 12.3409 -            status=eglDestroyContext(phdata->egldisplay, context);
 12.3410 -            if (status!=EGL_TRUE)
 12.3411 -            {
 12.3412 -               /* Error during OpenGL ES context destroying */
 12.3413 -               SDL_SetError("Photon: OpenGL ES context destroy error");
 12.3414 -               return;
 12.3415 +    /* Check if OpenGL ES connection has been initialized */
 12.3416 +    if (phdata->egldisplay != EGL_NO_DISPLAY) {
 12.3417 +        if (context != EGL_NO_CONTEXT) {
 12.3418 +            status = eglDestroyContext(phdata->egldisplay, context);
 12.3419 +            if (status != EGL_TRUE) {
 12.3420 +                /* Error during OpenGL ES context destroying */
 12.3421 +                SDL_SetError("Photon: OpenGL ES context destroy error");
 12.3422 +                return;
 12.3423              }
 12.3424 -         }
 12.3425 -      }
 12.3426 +        }
 12.3427 +    }
 12.3428  
 12.3429 -      return;
 12.3430 -   #else
 12.3431 -      SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3432 -      return;
 12.3433 -   #endif /* SDL_VIDEO_OPENGL_ES */
 12.3434 +    return;
 12.3435 +#else
 12.3436 +    SDL_SetError("Photon: OpenGL ES support is not compiled in");
 12.3437 +    return;
 12.3438 +#endif /* SDL_VIDEO_OPENGL_ES */
 12.3439  }
 12.3440  
 12.3441  /*****************************************************************************/
 12.3442  /* SDL Event handling function                                               */
 12.3443  /*****************************************************************************/
 12.3444 -void photon_pumpevents(_THIS)
 12.3445 +void
 12.3446 +photon_pumpevents(_THIS)
 12.3447  {
 12.3448 -   uint8_t    eventbuffer[SDL_VIDEO_PHOTON_EVENT_SIZE];
 12.3449 -   PhEvent_t* event=(PhEvent_t*)eventbuffer;
 12.3450 -   int32_t    status;
 12.3451 -   uint32_t   finish=0;
 12.3452 -   uint32_t   it;
 12.3453 -   SDL_Window* window;
 12.3454 -   SDL_WindowData* wdata;
 12.3455 +    uint8_t eventbuffer[SDL_VIDEO_PHOTON_EVENT_SIZE];
 12.3456 +    PhEvent_t *event = (PhEvent_t *) eventbuffer;
 12.3457 +    int32_t status;
 12.3458 +    uint32_t finish = 0;
 12.3459 +    uint32_t it;
 12.3460 +    SDL_Window *window;
 12.3461 +    SDL_WindowData *wdata;
 12.3462  
 12.3463 -   do {
 12.3464 -      status=PhEventPeek(event, SDL_VIDEO_PHOTON_EVENT_SIZE);
 12.3465 -      switch (status)
 12.3466 -      {
 12.3467 -         case Ph_RESIZE_MSG:
 12.3468 -              {
 12.3469 -                 SDL_SetError("Photon: Event size too much for buffer");
 12.3470 -                 return;
 12.3471 -              }
 12.3472 -              break;
 12.3473 -         case Ph_EVENT_MSG:
 12.3474 -              {
 12.3475 -                 /* Find a window, to which this handle destinated */
 12.3476 -                 status=0;
 12.3477 -                 for (it=0; it<SDL_CurrentDisplay.num_windows; it++)
 12.3478 -                 {
 12.3479 -                    wdata=(SDL_WindowData*)SDL_CurrentDisplay.windows[it].driverdata;
 12.3480 +    do {
 12.3481 +        status = PhEventPeek(event, SDL_VIDEO_PHOTON_EVENT_SIZE);
 12.3482 +        switch (status) {
 12.3483 +        case Ph_RESIZE_MSG:
 12.3484 +            {
 12.3485 +                SDL_SetError("Photon: Event size too much for buffer");
 12.3486 +                return;
 12.3487 +            }
 12.3488 +            break;
 12.3489 +        case Ph_EVENT_MSG:
 12.3490 +            {
 12.3491 +                /* Find a window, to which this handle destinated */
 12.3492 +                status = 0;
 12.3493 +                for (it = 0; it < SDL_CurrentDisplay.num_windows; it++) {
 12.3494 +                    wdata =
 12.3495 +                        (SDL_WindowData *) SDL_CurrentDisplay.windows[it].
 12.3496 +                        driverdata;
 12.3497  
 12.3498                      /* Find the proper window */
 12.3499 -                    if (wdata->window!=NULL)
 12.3500 +                    if (wdata->window != NULL) {
 12.3501 +                        if (PtWidgetRid(wdata->window) ==
 12.3502 +                            event->collector.rid) {
 12.3503 +                            window =
 12.3504 +                                (SDL_Window *) & SDL_CurrentDisplay.
 12.3505 +                                windows[it];
 12.3506 +                            status = 1;
 12.3507 +                            break;
 12.3508 +                        }
 12.3509 +                    } else {
 12.3510 +                        continue;
 12.3511 +                    }
 12.3512 +                }
 12.3513 +                if (status == 0) {
 12.3514 +                    window = NULL;
 12.3515 +                    wdata = NULL;
 12.3516 +                }
 12.3517 +
 12.3518 +                /* Event is ready */
 12.3519 +                switch (event->type) {
 12.3520 +                case Ph_EV_BOUNDARY:
 12.3521                      {
 12.3522 -                       if (PtWidgetRid(wdata->window)==event->collector.rid)
 12.3523 -                       {
 12.3524 -                          window=(SDL_Window*)&SDL_CurrentDisplay.windows[it];
 12.3525 -                          status=1;
 12.3526 -                          break;
 12.3527 -                       }
 12.3528 +                        switch (event->subtype) {
 12.3529 +                        case Ph_EV_PTR_ENTER:
 12.3530 +                            {
 12.3531 +                                /* Mouse cursor over handled window */
 12.3532 +                                if (window != NULL) {
 12.3533 +                                    SDL_SendWindowEvent(window->id,
 12.3534 +                                                        SDL_WINDOWEVENT_ENTER,
 12.3535 +                                                        0, 0);
 12.3536 +                                    SDL_SetMouseFocus(0, window->id);
 12.3537 +                                }
 12.3538 +                            }
 12.3539 +                            break;
 12.3540 +                        case Ph_EV_PTR_LEAVE:
 12.3541 +                            {
 12.3542 +                                /* Mouse cursor out of handled window */
 12.3543 +                                if (window != NULL) {
 12.3544 +                                    SDL_SendWindowEvent(window->id,
 12.3545 +                                                        SDL_WINDOWEVENT_LEAVE,
 12.3546 +                                                        0, 0);
 12.3547 +                                }
 12.3548 +                            }
 12.3549 +                            break;
 12.3550 +                        }
 12.3551                      }
 12.3552 -                    else
 12.3553 +                    break;
 12.3554 +                case Ph_EV_PTR_MOTION_BUTTON:
 12.3555 +                case Ph_EV_PTR_MOTION_NOBUTTON:
 12.3556                      {
 12.3557 -                       continue;
 12.3558 +                        PhPointerEvent_t *pevent = NULL;
 12.3559 +                        PhRect_t *prects = NULL;
 12.3560 +
 12.3561 +                        /* Get event data */
 12.3562 +                        pevent = PhGetData(event);
 12.3563 +                        /* Get associated event rectangles */
 12.3564 +                        prects = PhGetRects(event);
 12.3565 +                        if ((pevent != NULL) && (prects != NULL)) {
 12.3566 +                            SDL_SendMouseMotion(0, 0, prects->ul.x,
 12.3567 +                                                prects->ul.y, 0);
 12.3568 +                        }
 12.3569                      }
 12.3570 -                 }
 12.3571 -                 if (status==0)
 12.3572 -                 {
 12.3573 -                    window=NULL;
 12.3574 -                    wdata=NULL;
 12.3575 -                 }
 12.3576 +                    break;
 12.3577 +                case Ph_EV_BUT_PRESS:
 12.3578 +                    {
 12.3579 +                        /* Button press event */
 12.3580 +                        PhPointerEvent_t *pevent = NULL;
 12.3581 +                        uint32_t sdlbutton = 0x00000000;
 12.3582  
 12.3583 -                 /* Event is ready */
 12.3584 -                 switch(event->type)
 12.3585 -                 {
 12.3586 -                    case Ph_EV_BOUNDARY:
 12.3587 -                         {
 12.3588 -                            switch(event->subtype)
 12.3589 +                        /* Get event data */
 12.3590 +                        pevent = PhGetData(event);
 12.3591 +                        if (pevent != NULL) {
 12.3592 +                            for (it = 0; it < sizeof(pevent->buttons) * 8;
 12.3593 +                                 it++) {
 12.3594 +                                if ((pevent->buttons & (0x0001 << it)) ==
 12.3595 +                                    (0x0001 << it)) {
 12.3596 +                                    switch (it) {
 12.3597 +                                    case 0:
 12.3598 +                                        {
 12.3599 +                                            sdlbutton = SDL_BUTTON_RIGHT;
 12.3600 +                                        }
 12.3601 +                                        break;
 12.3602 +                                    case 1:
 12.3603 +                                        {
 12.3604 +                                            sdlbutton = SDL_BUTTON_MIDDLE;
 12.3605 +                                        }
 12.3606 +                                        break;
 12.3607 +                                    case 2:
 12.3608 +                                        {
 12.3609 +                                            sdlbutton = SDL_BUTTON_LEFT;
 12.3610 +                                        }
 12.3611 +                                        break;
 12.3612 +                                    default:
 12.3613 +                                        {
 12.3614 +                                            sdlbutton = it + 1;
 12.3615 +                                        }
 12.3616 +                                        break;
 12.3617 +                                    }
 12.3618 +                                    SDL_SendMouseButton(0, SDL_PRESSED,
 12.3619 +                                                        sdlbutton);
 12.3620 +                                }
 12.3621 +                            }
 12.3622 +                        }
 12.3623 +                    }
 12.3624 +                    break;
 12.3625 +                case Ph_EV_BUT_RELEASE:
 12.3626 +                    {
 12.3627 +                        /* Button press event */
 12.3628 +                        PhPointerEvent_t *pevent = NULL;
 12.3629 +                        uint32_t sdlbutton = 0x00000000;
 12.3630 +
 12.3631 +                        /* Get event data */
 12.3632 +                        pevent = PhGetData(event);
 12.3633 +                        if (pevent != NULL) {
 12.3634 +                            for (it = 0; it < sizeof(pevent->buttons) * 8;
 12.3635 +                                 it++) {
 12.3636 +                                if ((pevent->buttons & (0x0001 << it)) ==
 12.3637 +                                    (0x0001 << it)) {
 12.3638 +                                    switch (it) {
 12.3639 +                                    case 0:
 12.3640 +                                        {
 12.3641 +                                            sdlbutton = SDL_BUTTON_RIGHT;
 12.3642 +                                        }
 12.3643 +                                        break;
 12.3644 +                                    case 1:
 12.3645 +                                        {
 12.3646 +                                            sdlbutton = SDL_BUTTON_MIDDLE;
 12.3647 +                                        }
 12.3648 +                                        break;
 12.3649 +                                    case 2:
 12.3650 +                                        {
 12.3651 +                                            sdlbutton = SDL_BUTTON_LEFT;
 12.3652 +                                        }
 12.3653 +                                        break;
 12.3654 +                                    default:
 12.3655 +                                        {
 12.3656 +                                            sdlbutton = it + 1;
 12.3657 +                                        }
 12.3658 +                                        break;
 12.3659 +                                    }
 12.3660 +                                }
 12.3661 +                            }
 12.3662 +                        }
 12.3663 +
 12.3664 +                        switch (event->subtype) {
 12.3665 +                        case Ph_EV_RELEASE_REAL:
 12.3666                              {
 12.3667 -                               case Ph_EV_PTR_ENTER:
 12.3668 -                                    {
 12.3669 -                                       /* Mouse cursor over handled window */
 12.3670 -                                       if (window!=NULL)
 12.3671 -                                       {
 12.3672 -                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_ENTER, 0, 0);
 12.3673 -                                          SDL_SetMouseFocus(0, window->id);
 12.3674 -                                       }
 12.3675 +                                /* Real release button event */
 12.3676 +                                SDL_SendMouseButton(0, SDL_RELEASED,
 12.3677 +                                                    sdlbutton);
 12.3678 +                            }
 12.3679 +                            break;
 12.3680 +                        case Ph_EV_RELEASE_PHANTOM:
 12.3681 +                            {
 12.3682 +                                /* We will get phantom button release */
 12.3683 +                                /* event in case if it was unpressed  */
 12.3684 +                                /* outside of window                  */
 12.3685 +                                if (window != NULL) {
 12.3686 +                                    if ((window->
 12.3687 +                                         flags & SDL_WINDOW_MOUSE_FOCUS) !=
 12.3688 +                                        SDL_WINDOW_MOUSE_FOCUS) {
 12.3689 +                                        /* Send phantom button release */
 12.3690 +                                        SDL_SendMouseButton(0, SDL_RELEASED,
 12.3691 +                                                            sdlbutton);
 12.3692 +                                    }
 12.3693 +                                }
 12.3694 +                            }
 12.3695 +                            break;
 12.3696 +                        }
 12.3697 +                    }
 12.3698 +                    break;
 12.3699 +                case Ph_EV_EXPOSE:
 12.3700 +                    {
 12.3701 +                        switch (event->subtype) {
 12.3702 +                        case Ph_NORMAL_EXPOSE:
 12.3703 +                            {
 12.3704 +                                PhRect_t *rects = NULL;
 12.3705 +
 12.3706 +                                /* Get array of rectangles to be updated */
 12.3707 +                                rects = PhGetRects(event);
 12.3708 +                                if (rects == NULL) {
 12.3709 +                                    break;
 12.3710 +                                }
 12.3711 +
 12.3712 +                                /* Check if expose come to one of the our windows */
 12.3713 +                                if ((wdata != NULL) && (window != NULL)) {
 12.3714 +                                    /* Check if window uses OpenGL ES */
 12.3715 +                                    if (wdata->uses_gles == SDL_TRUE) {
 12.3716 +                                        PhRect_t dst_rect;
 12.3717 +                                        PhRect_t src_rect;
 12.3718 +
 12.3719 +                                        /* Cycle through each rectangle */
 12.3720 +                                        for (it = 0; it < event->num_rects;
 12.3721 +                                             it++) {
 12.3722 +                                            /* Blit OpenGL ES pixmap surface directly to window region */
 12.3723 +                                            PgFFlush(Ph_START_DRAW);
 12.3724 +                                            PgSetRegionCx(PhDCGetCurrent(),
 12.3725 +                                                          PtWidgetRid(wdata->
 12.3726 +                                                                      window));
 12.3727 +                                            PgClearTranslationCx(PgGetGCCx
 12.3728 +                                                                 (PhDCGetCurrent
 12.3729 +                                                                  ()));
 12.3730 +                                            PgContextBlit(wdata->phsurface,
 12.3731 +                                                          &rects[it], NULL,
 12.3732 +                                                          &rects[it]);
 12.3733 +                                            PgFFlush(Ph_DONE_DRAW);
 12.3734 +                                            PgWaitHWIdle();
 12.3735 +                                        }
 12.3736 +                                    } else {
 12.3737 +                                        /* Normal window */
 12.3738 +                                        /* TODO: update the damaged rectangles */
 12.3739 +                                    }
 12.3740 +                                }
 12.3741 +
 12.3742 +                                /* Flush all blittings */
 12.3743 +                                PgFlush();
 12.3744 +                            }
 12.3745 +                            break;
 12.3746 +                        case Ph_CAPTURE_EXPOSE:
 12.3747 +                            {
 12.3748 +                                /* Check if expose come to one of the our windows */
 12.3749 +                                if ((wdata != NULL) && (window != NULL)) {
 12.3750 +                                    /* Check if window uses OpenGL ES */
 12.3751 +                                    if (wdata->uses_gles == SDL_TRUE) {
 12.3752 +                                        PhRect_t dst_rect;
 12.3753 +                                        PhRect_t src_rect;
 12.3754 +
 12.3755 +                                        /* Set blit area */
 12.3756 +                                        dst_rect =
 12.3757 +                                            *PtGetCanvas(wdata->window);
 12.3758 +                                        src_rect.ul.x = 0;
 12.3759 +                                        src_rect.ul.y = 0;
 12.3760 +                                        src_rect.lr.x = window->w - 1;
 12.3761 +                                        src_rect.lr.y = window->h - 1;
 12.3762 +
 12.3763 +                                        /* We need to redraw entire window */
 12.3764 +                                        PgFFlush(Ph_START_DRAW);
 12.3765 +                                        PgSetRegionCx(PhDCGetCurrent(),
 12.3766 +                                                      PtWidgetRid(wdata->
 12.3767 +                                                                  window));
 12.3768 +                                        PgClearTranslationCx(PgGetGCCx
 12.3769 +                                                             (PhDCGetCurrent
 12.3770 +                                                              ()));
 12.3771 +                                        PgContextBlit(wdata->phsurface,
 12.3772 +                                                      &src_rect, NULL,
 12.3773 +                                                      &dst_rect);
 12.3774 +                                        PgFFlush(Ph_DONE_DRAW);
 12.3775 +                                        PgWaitHWIdle();
 12.3776 +                                    } else {
 12.3777 +                                        /* Normal window */
 12.3778 +                                        /* TODO: update the damaged rectangles */
 12.3779 +
 12.3780 +                                        /* We need to redraw entire window */
 12.3781 +                                    }
 12.3782 +                                }
 12.3783 +                            }
 12.3784 +                            break;
 12.3785 +                        case Ph_GRAPHIC_EXPOSE:
 12.3786 +                            {
 12.3787 +                                /* TODO: What this event means ? */
 12.3788 +                            }
 12.3789 +                            break;
 12.3790 +                        }
 12.3791 +                    }
 12.3792 +                    break;
 12.3793 +                case Ph_EV_INFO:
 12.3794 +                    {
 12.3795 +                    }
 12.3796 +                    break;
 12.3797 +                case Ph_EV_KEY:
 12.3798 +                    {
 12.3799 +                        PhKeyEvent_t *keyevent = NULL;
 12.3800 +                        SDL_scancode scancode = SDL_SCANCODE_UNKNOWN;
 12.3801 +                        SDL_bool pressed = SDL_FALSE;
 12.3802 +
 12.3803 +                        keyevent = PhGetData(event);
 12.3804 +                        if (keyevent == NULL) {
 12.3805 +                            break;
 12.3806 +                        }
 12.3807 +
 12.3808 +                        /* Check if key is repeated */
 12.3809 +                        if ((keyevent->key_flags & Pk_KF_Key_Repeat) ==
 12.3810 +                            Pk_KF_Key_Repeat) {
 12.3811 +                            /* Ignore such events */
 12.3812 +                            break;
 12.3813 +                        }
 12.3814 +
 12.3815 +                        /* Check if key has its own scancode */
 12.3816 +                        if ((keyevent->key_flags & Pk_KF_Scan_Valid) ==
 12.3817 +                            Pk_KF_Scan_Valid) {
 12.3818 +                            if ((keyevent->key_flags & Pk_KF_Key_Down) ==
 12.3819 +                                Pk_KF_Key_Down) {
 12.3820 +                                pressed = SDL_TRUE;
 12.3821 +                            } else {
 12.3822 +                                pressed = SDL_FALSE;
 12.3823 +                            }
 12.3824 +                            scancode =
 12.3825 +                                photon_to_sdl_keymap(keyevent->key_scan);
 12.3826 +
 12.3827 +                            /* Add details for the pressed key */
 12.3828 +                            if ((keyevent->key_flags & Pk_KF_Cap_Valid) ==
 12.3829 +                                Pk_KF_Cap_Valid) {
 12.3830 +                                switch (keyevent->key_cap) {
 12.3831 +                                case Pk_Hyper_R:       /* Right windows flag key */
 12.3832 +                                    scancode = SDL_SCANCODE_RGUI;
 12.3833 +                                    break;
 12.3834 +                                case Pk_Control_R:     /* Right Ctrl key */
 12.3835 +                                    scancode = SDL_SCANCODE_RCTRL;
 12.3836 +                                    break;
 12.3837 +                                case Pk_Alt_R: /* Right Alt key */
 12.3838 +                                    scancode = SDL_SCANCODE_RALT;
 12.3839 +                                    break;
 12.3840 +                                case Pk_Up:    /* Up key but with invalid scan */
 12.3841 +                                    if (scancode != SDL_SCANCODE_UP) {
 12.3842 +                                        /* This is a mouse wheel event */
 12.3843 +                                        SDL_SendMouseWheel(0, 0, 1);
 12.3844 +                                        return;
 12.3845                                      }
 12.3846                                      break;
 12.3847 -                               case Ph_EV_PTR_LEAVE:
 12.3848 -                                    {
 12.3849 -                                       /* Mouse cursor out of handled window */
 12.3850 -                                       if (window!=NULL)
 12.3851 -                                       {
 12.3852 -                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_LEAVE, 0, 0);
 12.3853 -                                       }
 12.3854 +                                case Pk_KP_8:  /* Up arrow or 8 on keypad */
 12.3855 +                                    scancode = SDL_SCANCODE_KP_8;
 12.3856 +                                    break;
 12.3857 +                                case Pk_Down:  /* Down key but with invalid scan */
 12.3858 +                                    if (scancode != SDL_SCANCODE_DOWN) {
 12.3859 +                                        /* This is a mouse wheel event */
 12.3860 +                                        SDL_SendMouseWheel(0, 0, -1);
 12.3861 +                                        return;
 12.3862                                      }
 12.3863                                      break;
 12.3864 -                            }
 12.3865 -                         }
 12.3866 -                         break;
 12.3867 -                    case Ph_EV_PTR_MOTION_BUTTON:
 12.3868 -                    case Ph_EV_PTR_MOTION_NOBUTTON:
 12.3869 -                         {
 12.3870 -                            PhPointerEvent_t* pevent=NULL;
 12.3871 -                            PhRect_t* prects=NULL;
 12.3872 -
 12.3873 -                            /* Get event data */
 12.3874 -                            pevent=PhGetData(event);
 12.3875 -                            /* Get associated event rectangles */
 12.3876 -                            prects=PhGetRects(event);
 12.3877 -                            if ((pevent!=NULL) && (prects!=NULL))
 12.3878 -                            {
 12.3879 -                               SDL_SendMouseMotion(0, 0, prects->ul.x, prects->ul.y, 0);
 12.3880 -                            }
 12.3881 -                         }
 12.3882 -                         break;
 12.3883 -                    case Ph_EV_BUT_PRESS:
 12.3884 -                         {
 12.3885 -                            /* Button press event */
 12.3886 -                            PhPointerEvent_t* pevent=NULL;
 12.3887 -                            uint32_t sdlbutton=0x00000000;
 12.3888 -
 12.3889 -                            /* Get event data */
 12.3890 -                            pevent=PhGetData(event);
 12.3891 -                            if (pevent!=NULL)
 12.3892 -                            {
 12.3893 -                               for (it=0; it<sizeof(pevent->buttons)*8; it++)
 12.3894 -                               {
 12.3895 -                                  if ((pevent->buttons&(0x0001<<it))==(0x0001<<it))
 12.3896 -                                  {
 12.3897 -                                     switch (it)
 12.3898 -                                     {
 12.3899 -                                        case 0:
 12.3900 -                                             {
 12.3901 -                                                sdlbutton=SDL_BUTTON_RIGHT;
 12.3902 -                                             }
 12.3903 -                                             break;
 12.3904 -                                        case 1:
 12.3905 -                                             {
 12.3906 -                                                sdlbutton=SDL_BUTTON_MIDDLE;
 12.3907 -                                             }
 12.3908 -                                             break;
 12.3909 -                                        case 2:
 12.3910 -                                             {
 12.3911 -                                                sdlbutton=SDL_BUTTON_LEFT;
 12.3912 -                                             }
 12.3913 -                                             break;
 12.3914 -                                        default:
 12.3915 -                                             {
 12.3916 -                                                sdlbutton=it+1;
 12.3917 -                                             }
 12.3918 -                                             break;
 12.3919 -                                     }
 12.3920 -                                     SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton);
 12.3921 -                                  }
 12.3922 -                               }
 12.3923 -                            }
 12.3924 -                         }
 12.3925 -                         break;
 12.3926 -                    case Ph_EV_BUT_RELEASE:
 12.3927 -                         {
 12.3928 -                            /* Button press event */
 12.3929 -                            PhPointerEvent_t* pevent=NULL;
 12.3930 -                            uint32_t sdlbutton=0x00000000;
 12.3931 -
 12.3932 -                            /* Get event data */
 12.3933 -                            pevent=PhGetData(event);
 12.3934 -                            if (pevent!=NULL)
 12.3935 -                            {
 12.3936 -                               for (it=0; it<sizeof(pevent->buttons)*8; it++)
 12.3937 -                               {
 12.3938 -                                  if ((pevent->buttons&(0x0001<<it))==(0x0001<<it))
 12.3939 -                                  {
 12.3940 -                                     switch (it)
 12.3941 -                                     {
 12.3942 -                                        case 0:
 12.3943 -                                             {
 12.3944 -                                                sdlbutton=SDL_BUTTON_RIGHT;
 12.3945 -                                             }
 12.3946 -                                             break;
 12.3947 -                                        case 1:
 12.3948 -                                             {
 12.3949 -                                                sdlbutton=SDL_BUTTON_MIDDLE;
 12.3950 -                                             }
 12.3951 -                                             break;
 12.3952 -                                        case 2:
 12.3953 -                                             {
 12.3954 -                                                sdlbutton=SDL_BUTTON_LEFT;
 12.3955 -                                             }
 12.3956 -                                             break;
 12.3957 -                                        default:
 12.3958 -                                             {
 12.3959 -                                                sdlbutton=it+1;
 12.3960 -                                             }
 12.3961 -                                             break;
 12.3962 -                                     }
 12.3963 -                                  }
 12.3964 -                               }
 12.3965 +                                case Pk_KP_2:  /* Down arrow or 2 on keypad */
 12.3966 +                                    scancode = SDL_SCANCODE_KP_2;
 12.3967 +                                    break;
 12.3968 +                                case Pk_Left:  /* Left arrow key */
 12.3969 +                                    scancode = SDL_SCANCODE_LEFT;
 12.3970 +                                    break;
 12.3971 +                                case Pk_KP_4:  /* Left arrow or 4 on keypad */
 12.3972 +                                    scancode = SDL_SCANCODE_KP_4;
 12.3973 +                                    break;
 12.3974 +                                case Pk_Right: /* Right arrow key */
 12.3975 +                                    scancode = SDL_SCANCODE_RIGHT;
 12.3976 +                                    break;
 12.3977 +                                case Pk_KP_6:  /* Right arrow or 6 on keypad */
 12.3978 +                                    scancode = SDL_SCANCODE_KP_6;
 12.3979 +                                    break;
 12.3980 +                                case Pk_Insert:        /* Insert key */
 12.3981 +                                    scancode = SDL_SCANCODE_INSERT;
 12.3982 +                                    break;
 12.3983 +                                case Pk_KP_0:  /* Insert or 0 on keypad */
 12.3984 +                                    scancode = SDL_SCANCODE_KP_0;
 12.3985 +                                    break;
 12.3986 +                                case Pk_Home:  /* Home key */
 12.3987 +                                    scancode = SDL_SCANCODE_HOME;
 12.3988 +                                    break;
 12.3989 +                                case Pk_KP_7:  /* Home or 7 on keypad */
 12.3990 +                                    scancode = SDL_SCANCODE_KP_7;
 12.3991 +                                    break;
 12.3992 +                                case Pk_Pg_Up: /* PageUp key */
 12.3993 +                                    scancode = SDL_SCANCODE_PAGEUP;
 12.3994 +                                    break;
 12.3995 +                                case Pk_KP_9:  /* PgUp or 9 on keypad */
 12.3996 +                                    scancode = SDL_SCANCODE_KP_9;
 12.3997 +                                    break;
 12.3998 +                                case Pk_Delete:        /* Delete key */
 12.3999 +                                    scancode = SDL_SCANCODE_DELETE;
 12.4000 +                                    break;
 12.4001 +                                case Pk_KP_Decimal:    /* Del or . on keypad */
 12.4002 +                                    scancode = SDL_SCANCODE_KP_PERIOD;
 12.4003 +                                    break;
 12.4004 +                                case Pk_End:   /* End key */
 12.4005 +                                    scancode = SDL_SCANCODE_END;
 12.4006 +                                    break;
 12.4007 +                                case Pk_KP_1:  /* End or 1 on keypad */
 12.4008 +                                    scancode = SDL_SCANCODE_KP_1;
 12.4009 +                                    break;
 12.4010 +                                case Pk_Pg_Down:       /* PageDown key */
 12.4011 +                                    scancode = SDL_SCANCODE_PAGEDOWN;
 12.4012 +                                    break;
 12.4013 +                                case Pk_KP_3:  /* PgDn or 3 on keypad */
 12.4014 +                                    scancode = SDL_SCANCODE_KP_3;
 12.4015 +                                    break;
 12.4016 +                                case Pk_KP_5:  /* 5 on keypad */
 12.4017 +                                    scancode = SDL_SCANCODE_KP_5;
 12.4018 +                                    break;
 12.4019 +                                case Pk_KP_Enter:
 12.4020 +                                    scancode = SDL_SCANCODE_KP_ENTER;
 12.4021 +                                    break;
 12.4022 +                                case Pk_KP_Add:
 12.4023 +                                    scancode = SDL_SCANCODE_KP_PLUS;
 12.4024 +                                    break;
 12.4025 +                                case Pk_KP_Subtract:
 12.4026 +                                    scancode = SDL_SCANCODE_KP_MINUS;
 12.4027 +                                    break;
 12.4028 +                                case Pk_KP_Multiply:
 12.4029 +                                    scancode = SDL_SCANCODE_KP_MULTIPLY;
 12.4030 +                                    break;
 12.4031 +                                case Pk_KP_Divide:
 12.4032 +                                    scancode = SDL_SCANCODE_KP_DIVIDE;
 12.4033 +                                    break;
 12.4034 +                                case Pk_Pause:
 12.4035 +                                    scancode = SDL_SCANCODE_PAUSE;
 12.4036 +                                    break;
 12.4037 +                                }
 12.4038                              }
 12.4039  
 12.4040 -                            switch(event->subtype)
 12.4041 -                            {
 12.4042 -                               case Ph_EV_RELEASE_REAL:
 12.4043 -                                    {
 12.4044 -                                       /* Real release button event */
 12.4045 -                                       SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
 12.4046 -                                    }
 12.4047 -                                    break;
 12.4048 -                               case Ph_EV_RELEASE_PHANTOM:
 12.4049 -                                    {
 12.4050 -                                       /* We will get phantom button release */
 12.4051 -                                       /* event in case if it was unpressed  */
 12.4052 -                                       /* outside of window                  */
 12.4053 -                                       if (window!=NULL)
 12.4054 -                                       {
 12.4055 -                                          if ((window->flags & SDL_WINDOW_MOUSE_FOCUS)!=SDL_WINDOW_MOUSE_FOCUS)
 12.4056 -                                          {
 12.4057 -                                             /* Send phantom button release */
 12.4058 -                                             SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
 12.4059 -                                          }
 12.4060 -                                       }
 12.4061 -                                    }
 12.4062 -                                    break;
 12.4063 -                            }
 12.4064 -                         }
 12.4065 -                         break;
 12.4066 -                    case Ph_EV_EXPOSE:
 12.4067 -                         {
 12.4068 -                            switch(event->subtype)
 12.4069 -                            {
 12.4070 -                               case Ph_NORMAL_EXPOSE:
 12.4071 -                                    {
 12.4072 -                                       PhRect_t* rects=NULL;
 12.4073 -
 12.4074 -                                       /* Get array of rectangles to be updated */
 12.4075 -                                       rects=PhGetRects(event);
 12.4076 -                                       if (rects==NULL)
 12.4077 -                                       {
 12.4078 -                                          break;
 12.4079 -                                       }
 12.4080 -
 12.4081 -                                       /* Check if expose come to one of the our windows */
 12.4082 -                                       if ((wdata!=NULL) && (window!=NULL))
 12.4083 -                                       {
 12.4084 -                                          /* Check if window uses OpenGL ES */
 12.4085 -                                          if (wdata->uses_gles==SDL_TRUE)
 12.4086 -                                          {
 12.4087 -                                             PhRect_t dst_rect;
 12.4088 -                                             PhRect_t src_rect;
 12.4089 -
 12.4090 -                                             /* Cycle through each rectangle */
 12.4091 -                                             for (it=0; it<event->num_rects; it++)
 12.4092 -                                             {
 12.4093 -                                                /* Blit OpenGL ES pixmap surface directly to window region */
 12.4094 -                                                PgFFlush(Ph_START_DRAW);
 12.4095 -                                                PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
 12.4096 -                                                PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
 12.4097 -                                                PgContextBlit(wdata->phsurface, &rects[it], NULL, &rects[it]);
 12.4098 -                                                PgFFlush(Ph_DONE_DRAW);
 12.4099 -                                                PgWaitHWIdle();
 12.4100 -                                             }
 12.4101 -                                          }
 12.4102 -                                          else
 12.4103 -                                          {
 12.4104 -                                             /* Normal window */
 12.4105 -                                             /* TODO: update the damaged rectangles */
 12.4106 -                                          }
 12.4107 -                                       }
 12.4108 -
 12.4109 -                                       /* Flush all blittings */
 12.4110 -                                       PgFlush();
 12.4111 -                                    }
 12.4112 -                                    break;
 12.4113 -                               case Ph_CAPTURE_EXPOSE:
 12.4114 -                                    {
 12.4115 -                                       /* Check if expose come to one of the our windows */
 12.4116 -                                       if ((wdata!=NULL) && (window!=NULL))
 12.4117 -                                       {
 12.4118 -                                          /* Check if window uses OpenGL ES */
 12.4119 -                                          if (wdata->uses_gles==SDL_TRUE)
 12.4120 -                                          {
 12.4121 -                                             PhRect_t dst_rect;
 12.4122 -                                             PhRect_t src_rect;
 12.4123 -
 12.4124 -                                             /* Set blit area */
 12.4125 -                                             dst_rect=*PtGetCanvas(wdata->window);
 12.4126 -                                             src_rect.ul.x=0;
 12.4127 -                                             src_rect.ul.y=0;
 12.4128 -                                             src_rect.lr.x=window->w-1;
 12.4129 -                                             src_rect.lr.y=window->h-1;
 12.4130 -
 12.4131 -                                             /* We need to redraw entire window */
 12.4132 -                                             PgFFlush(Ph_START_DRAW);
 12.4133 -                                             PgSetRegionCx(PhDCGetCurrent(), PtWidgetRid(wdata->window));
 12.4134 -                                             PgClearTranslationCx(PgGetGCCx(PhDCGetCurrent()));
 12.4135 -                                             PgContextBlit(wdata->phsurface, &src_rect, NULL, &dst_rect);
 12.4136 -                                             PgFFlush(Ph_DONE_DRAW);
 12.4137 -                                             PgWaitHWIdle();
 12.4138 -                                          }
 12.4139 -                                          else
 12.4140 -                                          {
 12.4141 -                                             /* Normal window */
 12.4142 -                                             /* TODO: update the damaged rectangles */
 12.4143 -
 12.4144 -                                             /* We need to redraw entire window */
 12.4145 -                                          }
 12.4146 -                                       }
 12.4147 -                                    }
 12.4148 -                                    break;
 12.4149 -                               case Ph_GRAPHIC_EXPOSE:
 12.4150 -                                    {
 12.4151 -                                       /* TODO: What this event means ? */
 12.4152 -                                    }
 12.4153 -                                    break;
 12.4154 -                            }
 12.4155 -                         }
 12.4156 -                         break;
 12.4157 -                    case Ph_EV_INFO:
 12.4158 -                         {
 12.4159 -                         }
 12.4160 -                         break;
 12.4161 -                    case Ph_EV_KEY:
 12.4162 -                         {
 12.4163 -                            PhKeyEvent_t* keyevent=NULL;
 12.4164 -                            SDL_scancode scancode=SDL_SCANCODE_UNKNOWN;
 12.4165 -                            SDL_bool pressed=SDL_FALSE;
 12.4166 -
 12.4167 -                            keyevent=PhGetData(event);
 12.4168 -                            if (keyevent==NULL)
 12.4169 -                            {
 12.4170 -                               break;
 12.4171 +                            /* Finally check if scancode has been decoded */
 12.4172 +                            if (scancode == SDL_SCANCODE_UNKNOWN) {
 12.4173 +                                /* Something was pressed, which is not supported */
 12.4174 +                                break;
 12.4175                              }
 12.4176  
 12.4177 -                            /* Check if key is repeated */
 12.4178 -                            if ((keyevent->key_flags & Pk_KF_Key_Repeat)==Pk_KF_Key_Repeat)
 12.4179 -                            {
 12.4180 -                               /* Ignore such events */
 12.4181 -                               break;
 12.4182 +                            /* Report pressed/released key to SDL */
 12.4183 +                            if (pressed == SDL_TRUE) {
 12.4184 +                                SDL_SendKeyboardKey(0, SDL_PRESSED, scancode);
 12.4185 +                            } else {
 12.4186 +                                SDL_SendKeyboardKey(0, SDL_RELEASED,
 12.4187 +                                                    scancode);
 12.4188                              }
 12.4189  
 12.4190 -                            /* Check if key has its own scancode */
 12.4191 -                            if ((keyevent->key_flags & Pk_KF_Scan_Valid)==Pk_KF_Scan_Valid)
 12.4192 +                            /* Photon doesn't send a release event for PrnScr key */
 12.4193 +                            if ((scancode == SDL_SCANCODE_PRINTSCREEN)
 12.4194 +                                && (pressed)) {
 12.4195 +                                SDL_SendKeyboardKey(0, SDL_RELEASED,
 12.4196 +                                                    scancode);
 12.4197 +                            }
 12.4198 +                        }
 12.4199 +                    }
 12.4200 +                    break;
 12.4201 +                case Ph_EV_SERVICE:
 12.4202 +                    {
 12.4203 +                    }
 12.4204 +                    break;
 12.4205 +                case Ph_EV_SYSTEM:
 12.4206 +                    {
 12.4207 +                    }
 12.4208 +                    break;
 12.4209 +                case Ph_EV_WM:
 12.4210 +                    {
 12.4211 +                        PhWindowEvent_t *wmevent = NULL;
 12.4212 +
 12.4213 +                        /* Get associated event data */
 12.4214 +                        wmevent = PhGetData(event);
 12.4215 +                        if (wmevent == NULL) {
 12.4216 +                            break;
 12.4217 +                        }
 12.4218 +
 12.4219 +                        switch (wmevent->event_f) {
 12.4220 +                        case Ph_WM_CLOSE:
 12.4221                              {
 12.4222 -                               if ((keyevent->key_flags & Pk_KF_Key_Down)==Pk_KF_Key_Down)
 12.4223 -                               {
 12.4224 -                                  pressed=SDL_TRUE;
 12.4225 -                               }
 12.4226 -                               else
 12.4227 -                               {
 12.4228 -                                  pressed=SDL_FALSE;
 12.4229 -                               }
 12.4230 -                               scancode=photon_to_sdl_keymap(keyevent->key_scan);
 12.4231 +                                if (window != NULL) {
 12.4232 +                                    SDL_SendWindowEvent(window->id,
 12.4233 +                                                        SDL_WINDOWEVENT_CLOSE,
 12.4234 +                                                        0, 0);
 12.4235 +                                }
 12.4236 +                            }
 12.4237 +                            break;
 12.4238 +                        case Ph_WM_FOCUS:
 12.4239 +                            {
 12.4240 +                                if (wmevent->event_state ==
 12.4241 +                                    Ph_WM_EVSTATE_FOCUS) {
 12.4242 +                                    if (window != NULL) {
 12.4243 +                                        PhRegion_t wregion;
 12.4244  
 12.4245 -                               /* Add details for the pressed key */
 12.4246 -                               if ((keyevent->key_flags & Pk_KF_Cap_Valid)==Pk_KF_Cap_Valid)
 12.4247 -                               {
 12.4248 -                                  switch(keyevent->key_cap)
 12.4249 -                                  {
 12.4250 -                                     case Pk_Hyper_R: /* Right windows flag key */
 12.4251 -                                          scancode=SDL_SCANCODE_RGUI;
 12.4252 -                                          break;
 12.4253 -                                     case Pk_Control_R: /* Right Ctrl key */
 12.4254 -                                          scancode=SDL_SCANCODE_RCTRL;
 12.4255 -                                          break;
 12.4256 -                                     case Pk_Alt_R: /* Right Alt key */
 12.4257 -                                          scancode=SDL_SCANCODE_RALT;
 12.4258 -                                          break;
 12.4259 -                                     case Pk_Up: /* Up key but with invalid scan */
 12.4260 -                                          if (scancode!=SDL_SCANCODE_UP)
 12.4261 -                                          {
 12.4262 -                                             /* This is a mouse wheel event */
 12.4263 -                                             SDL_SendMouseWheel(0, 0, 1);
 12.4264 -                                             return;
 12.4265 -                                          }
 12.4266 -                                          break;
 12.4267 -                                     case Pk_KP_8: /* Up arrow or 8 on keypad */
 12.4268 -                                          scancode=SDL_SCANCODE_KP_8;
 12.4269 -                                          break;
 12.4270 -                                     case Pk_Down: /* Down key but with invalid scan */
 12.4271 -                                          if (scancode!=SDL_SCANCODE_DOWN)
 12.4272 -                                          {
 12.4273 -                                             /* This is a mouse wheel event */
 12.4274 -                                             SDL_SendMouseWheel(0, 0, -1);
 12.4275 -                                             return;
 12.4276 -                                          }
 12.4277 -                                          break;
 12.4278 -                                     case Pk_KP_2: /* Down arrow or 2 on keypad */
 12.4279 -                                          scancode=SDL_SCANCODE_KP_2;
 12.4280 -                                          break;
 12.4281 -                                     case Pk_Left: /* Left arrow key */
 12.4282 -                                          scancode=SDL_SCANCODE_LEFT;
 12.4283 -                                          break;
 12.4284 -                                     case Pk_KP_4: /* Left arrow or 4 on keypad */
 12.4285 -                                          scancode=SDL_SCANCODE_KP_4;
 12.4286 -                                          break;
 12.4287 -                                     case Pk_Right: /* Right arrow key */
 12.4288 -                                          scancode=SDL_SCANCODE_RIGHT;
 12.4289 -                                          break;
 12.4290 -                                     case Pk_KP_6: /* Right arrow or 6 on keypad */
 12.4291 -                                          scancode=SDL_SCANCODE_KP_6;
 12.4292 -                                          break;
 12.4293 -                                     case Pk_Insert: /* Insert key */
 12.4294 -                                          scancode=SDL_SCANCODE_INSERT;
 12.4295 -                                          break;
 12.4296 -                                     case Pk_KP_0: /* Insert or 0 on keypad */
 12.4297 -                                          scancode=SDL_SCANCODE_KP_0;
 12.4298 -                                          break;
 12.4299 -                                     case Pk_Home: /* Home key */
 12.4300 -                                          scancode=SDL_SCANCODE_HOME;
 12.4301 -                                          break;
 12.4302 -                                     case Pk_KP_7: /* Home or 7 on keypad */
 12.4303 -                                          scancode=SDL_SCANCODE_KP_7;
 12.4304 -                                          break;
 12.4305 -                                     case Pk_Pg_Up: /* PageUp key */
 12.4306 -                                          scancode=SDL_SCANCODE_PAGEUP;
 12.4307 -                                          break;
 12.4308 -                                     case Pk_KP_9: /* PgUp or 9 on keypad */
 12.4309 -                                          scancode=SDL_SCANCODE_KP_9;
 12.4310 -                                          break;
 12.4311 -                                     case Pk_Delete: /* Delete key */
 12.4312 -                                          scancode=SDL_SCANCODE_DELETE;
 12.4313 -                                          break;
 12.4314 -                                     case Pk_KP_Decimal: /* Del or . on keypad */
 12.4315 -                                          scancode=SDL_SCANCODE_KP_PERIOD;
 12.4316 -                                          break;
 12.4317 -                                     case Pk_End: /* End key */
 12.4318 -                                          scancode=SDL_SCANCODE_END;
 12.4319 -                                          break;
 12.4320 -                                     case Pk_KP_1: /* End or 1 on keypad */
 12.4321 -                                          scancode=SDL_SCANCODE_KP_1;
 12.4322 -                                          break;
 12.4323 -                                     case Pk_Pg_Down: /* PageDown key */
 12.4324 -                                          scancode=SDL_SCANCODE_PAGEDOWN;
 12.4325 -                                          break;
 12.4326 -                                     case Pk_KP_3: /* PgDn or 3 on keypad */
 12.4327 -                                          scancode=SDL_SCANCODE_KP_3;
 12.4328 -                                          break;
 12.4329 -                                     case Pk_KP_5: /* 5 on keypad */
 12.4330 -                                          scancode=SDL_SCANCODE_KP_5;
 12.4331 -                                          break;
 12.4332 -                                     case Pk_KP_Enter:
 12.4333 -                                          scancode=SDL_SCANCODE_KP_ENTER;
 12.4334 -                                          break;
 12.4335 -                                     case Pk_KP_Add:
 12.4336 -                                          scancode=SDL_SCANCODE_KP_PLUS;
 12.4337 -                                          break;
 12.4338 -                                     case Pk_KP_Subtract:
 12.4339 -                                          scancode=SDL_SCANCODE_KP_MINUS;
 12.4340 -                                          break;
 12.4341 -                                     case Pk_KP_Multiply:
 12.4342 -                                          scancode=SDL_SCANCODE_KP_MULTIPLY;
 12.4343 -                                          break;
 12.4344 -                                     case Pk_KP_Divide:
 12.4345 -                                          scancode=SDL_SCANCODE_KP_DIVIDE;
 12.4346 -                                          break;
 12.4347 -                                     case Pk_Pause:
 12.4348 -                                          scancode=SDL_SCANCODE_PAUSE;
 12.4349 -                                          break;
 12.4350 -                                  }
 12.4351 -                               }
 12.4352 +                                        SDL_SendWindowEvent(window->id,
 12.4353 +                                                            SDL_WINDOWEVENT_FOCUS_GAINED,
 12.4354 +                                                            0, 0);
 12.4355 +                                        SDL_SetKeyboardFocus(0, window->id);
 12.4356  
 12.4357 -                               /* Finally check if scancode has been decoded */
 12.4358 -                               if (scancode==SDL_SCANCODE_UNKNOWN)
 12.4359 -                               {
 12.4360 -                                  /* Something was pressed, which is not supported */
 12.4361 -                                  break;
 12.4362 -                               }
 12.4363 +                                        /* Set window region sensible to mouse motion events */
 12.4364 +                                        PhRegionQuery(PtWidgetRid
 12.4365 +                                                      (wdata->window),
 12.4366 +                                                      &wregion, NULL, NULL,
 12.4367 +                                                      0);
 12.4368 +                                        wregion.events_sense |=
 12.4369 +                                            Ph_EV_PTR_MOTION_BUTTON |
 12.4370 +                                            Ph_EV_PTR_MOTION_NOBUTTON;
 12.4371 +                                        PhRegionChange(Ph_REGION_EV_SENSE, 0,
 12.4372 +                                                       &wregion, NULL, NULL);
 12.4373  
 12.4374 -                               /* Report pressed/released key to SDL */
 12.4375 -                               if (pressed==SDL_TRUE)
 12.4376 -                               {
 12.4377 -                                  SDL_SendKeyboardKey(0, SDL_PRESSED, scancode);
 12.4378 -                               }
 12.4379 -                               else
 12.4380 -                               {
 12.4381 -                                  SDL_SendKeyboardKey(0, SDL_RELEASED, scancode);
 12.4382 -                               }
 12.4383 +                                        /* If window got a focus, the it is visible */
 12.4384 +                                        SDL_SendWindowEvent(window->id,
 12.4385 +                                                            SDL_WINDOWEVENT_SHOWN,
 12.4386 +                                                            0, 0);
 12.4387 +                                    }
 12.4388 +                                }
 12.4389 +                                if (wmevent->event_state ==
 12.4390 +                                    Ph_WM_EVSTATE_FOCUSLOST) {
 12.4391 +                                    if (window != NULL) {
 12.4392 +                                        PhRegion_t wregion;
 12.4393  
 12.4394 -                               /* Photon doesn't send a release event for PrnScr key */
 12.4395 -                               if ((scancode==SDL_SCANCODE_PRINTSCREEN) && (pressed))
 12.4396 -                               {
 12.4397 -                                  SDL_SendKeyboardKey(0, SDL_RELEASED, scancode);
 12.4398 -                               }
 12.4399 +                                        SDL_SendWindowEvent(window->id,
 12.4400 +                                                            SDL_WINDOWEVENT_FOCUS_LOST,
 12.4401 +                                                            0, 0);
 12.4402 +
 12.4403 +                                        /* Set window region ignore mouse motion events */
 12.4404 +                                        PhRegionQuery(PtWidgetRid
 12.4405 +                                                      (wdata->window),
 12.4406 +                                                      &wregion, NULL, NULL,
 12.4407 +                                                      0);
 12.4408 +                                        wregion.events_sense &=
 12.4409 +                                            ~(Ph_EV_PTR_MOTION_BUTTON |
 12.4410 +                                              Ph_EV_PTR_MOTION_NOBUTTON);
 12.4411 +                                        PhRegionChange(Ph_REGION_EV_SENSE, 0,
 12.4412 +                                                       &wregion, NULL, NULL);
 12.4413 +                                    }
 12.4414 +                                }
 12.4415                              }
 12.4416 -                         }
 12.4417 -                         break;
 12.4418 -                    case Ph_EV_SERVICE:
 12.4419 -                         {
 12.4420 -                         }
 12.4421 -                         break;
 12.4422 -                    case Ph_EV_SYSTEM:
 12.4423 -                         {
 12.4424 -                         }
 12.4425 -                         break;
 12.4426 -                    case Ph_EV_WM:
 12.4427 -                         {
 12.4428 -                            PhWindowEvent_t* wmevent=NULL;
 12.4429 -
 12.4430 -                            /* Get associated event data */
 12.4431 -                            wmevent=PhGetData(event);
 12.4432 -                            if (wmevent==NULL)
 12.4433 +                            break;
 12.4434 +                        case Ph_WM_MOVE:
 12.4435                              {
 12.4436 -                               break;
 12.4437 +                                if (window != NULL) {
 12.4438 +                                    SDL_SendWindowEvent(window->id,
 12.4439 +                                                        SDL_WINDOWEVENT_MOVED,
 12.4440 +                                                        wmevent->pos.x,
 12.4441 +                                                        wmevent->pos.y);
 12.4442 +                                }
 12.4443                              }
 12.4444 -
 12.4445 -                            switch(wmevent->event_f)
 12.4446 +                            break;
 12.4447 +                        case Ph_WM_RESIZE:
 12.4448                              {
 12.4449 -                               case Ph_WM_CLOSE:
 12.4450 -                                    {
 12.4451 -                                       if (window!=NULL)
 12.4452 -                                       {
 12.4453 -                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_CLOSE, 0, 0);
 12.4454 -                                       }
 12.4455 -                                    }
 12.4456 -                                    break;
 12.4457 -                               case Ph_WM_FOCUS:
 12.4458 -                                    {
 12.4459 -                                       if (wmevent->event_state==Ph_WM_EVSTATE_FOCUS)
 12.4460 -                                       {
 12.4461 -                                          if (window!=NULL)
 12.4462 -                                          {
 12.4463 -                                             PhRegion_t wregion;
 12.4464 -
 12.4465 -                                             SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
 12.4466 -                                             SDL_SetKeyboardFocus(0, window->id);
 12.4467 -
 12.4468 -                                             /* Set window region sensible to mouse motion events */
 12.4469 -                                             PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
 12.4470 -                                             wregion.events_sense|=Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON;
 12.4471 -                                             PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
 12.4472 -
 12.4473 -                                             /* If window got a focus, the it is visible */
 12.4474 -                                             SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_SHOWN, 0, 0);
 12.4475 -                                          }
 12.4476 -                                       }
 12.4477 -                                       if (wmevent->event_state==Ph_WM_EVSTATE_FOCUSLOST)
 12.4478 -                                       {
 12.4479 -                                          if (window!=NULL)
 12.4480 -                                          {
 12.4481 -                                             PhRegion_t wregion;
 12.4482 -
 12.4483 -                                             SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
 12.4484 -
 12.4485 -                                             /* Set window region ignore mouse motion events */
 12.4486 -                                             PhRegionQuery(PtWidgetRid(wdata->window), &wregion, NULL, NULL, 0);
 12.4487 -                                             wregion.events_sense&=~(Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON);
 12.4488 -                                             PhRegionChange(Ph_REGION_EV_SENSE, 0, &wregion, NULL, NULL);
 12.4489 -                                          }
 12.4490 -                                       }
 12.4491 -                                    }
 12.4492 -                                    break;
 12.4493 -                               case Ph_WM_MOVE:
 12.4494 -                                    {
 12.4495 -                                       if (window!=NULL)
 12.4496 -                                       {
 12.4497 -                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, wmevent->pos.x, wmevent->pos.y);
 12.4498 -                                       }
 12.4499 -                                    }
 12.4500 -                                    break;
 12.4501 -                               case Ph_WM_RESIZE:
 12.4502 -                                    {
 12.4503 -                                       if (window!=NULL)
 12.4504 -                                       {
 12.4505 -                                          /* Set new window position after resize */
 12.4506 -                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MOVED, wmevent->pos.x, wmevent->pos.y);
 12.4507 -                                          /* Set new window size after resize */
 12.4508 -                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESIZED, wmevent->size.w, wmevent->size.h);
 12.4509 -                                       }
 12.4510 -                                    }
 12.4511 -                                    break;
 12.4512 -                               case Ph_WM_HIDE:
 12.4513 -                                    {
 12.4514 -                                       if (window!=NULL)
 12.4515 -                                       {
 12.4516 -                                          /* Send new window state: minimized */
 12.4517 -                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
 12.4518 -                                          /* In case window is minimized, then it is hidden */
 12.4519 -                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_HIDDEN, 0, 0);
 12.4520 -                                       }
 12.4521 -                                    }
 12.4522 -                                    break;
 12.4523 -                               case Ph_WM_MAX:
 12.4524 -                                    {
 12.4525 -                                       if (window!=NULL)
 12.4526 -                                       {
 12.4527 -                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
 12.4528 -                                       }
 12.4529 -                                    }
 12.4530 -                                    break;
 12.4531 -                               case Ph_WM_RESTORE:
 12.4532 -                                    {
 12.4533 -                                       if (window!=NULL)
 12.4534 -                                       {
 12.4535 -                                          SDL_SendWindowEvent(window->id, SDL_WINDOWEVENT_RESTORED, 0, 0);
 12.4536 -                                       }
 12.4537 -                                    }
 12.4538 -                                    break;
 12.4539 +                                if (window != NULL) {
 12.4540 +                                    /* Set new window position after resize */
 12.4541 +                                    SDL_SendWindowEvent(window->id,
 12.4542 +                                                        SDL_WINDOWEVENT_MOVED,
 12.4543 +                                                        wmevent->pos.x,
 12.4544 +                                                        wmevent->pos.y);
 12.4545 +                                    /* Set new window size after resize */
 12.4546 +                                    SDL_SendWindowEvent(window->id,
 12.4547 +                                                        SDL_WINDOWEVENT_RESIZED,
 12.4548 +                                                        wmevent->size.w,
 12.4549 +                                                        wmevent->size.h);
 12.4550 +                                }
 12.4551                              }
 12.4552 -                         }
 12.4553 -                         break;
 12.4554 -                 }
 12.4555 -                 PtEventHandler(event);
 12.4556 -              }
 12.4557 -              break;
 12.4558 -         case 0:
 12.4559 -              {
 12.4560 -                 /* All events are read */
 12.4561 -                 finish=1;
 12.4562 -                 break;
 12.4563 -              }
 12.4564 -         case -1:
 12.4565 -              {
 12.4566 -                 /* Error occured in event reading */
 12.4567 -                 SDL_SetError("Photon: Can't read event");
 12.4568 -                 return;
 12.4569 -              }
 12.4570 -              break;
 12.4571 -      }
 12.4572 -      if (finish!=0)
 12.4573 -      {
 12.4574 -         break;
 12.4575 -      }
 12.4576 -   } while(1);
 12.4577 +                            break;
 12.4578 +                        case Ph_WM_HIDE:
 12.4579 +                            {
 12.4580 +                                if (window != NULL) {
 12.4581 +                                    /* Send new window state: minimized */
 12.4582 +                                    SDL_SendWindowEvent(window->id,
 12.4583 +                                                        SDL_WINDOWEVENT_MINIMIZED,
 12.4584 +                                                        0, 0);
 12.4585 +                                    /* In case window is minimized, then it is hidden */
 12.4586 +                                    SDL_SendWindowEvent(window->id,
 12.4587 +                                                        SDL_WINDOWEVENT_HIDDEN,
 12.4588 +                                                        0, 0);
 12.4589 +                                }
 12.4590 +                            }
 12.4591 +                            break;
 12.4592 +                        case Ph_WM_MAX:
 12.4593 +                            {
 12.4594 +                                if (window != NULL) {
 12.4595 +                                    SDL_SendWindowEvent(window->id,
 12.4596 +                                                        SDL_WINDOWEVENT_MAXIMIZED,
 12.4597 +                                                        0, 0);
 12.4598 +                                }
 12.4599 +                            }
 12.4600 +                            break;
 12.4601 +                        case Ph_WM_RESTORE:
 12.4602 +                            {
 12.4603 +                                if (window != NULL) {
 12.4604 +                                    SDL_SendWindowEvent(window->id,
 12.4605 +                                                        SDL_WINDOWEVENT_RESTORED,
 12.4606 +                                                        0, 0);
 12.4607 +                                }
 12.4608 +                            }
 12.4609 +                            break;
 12.4610 +                        }
 12.4611 +                    }
 12.4612 +                    break;
 12.4613 +                }
 12.4614 +                PtEventHandler(event);
 12.4615 +            }
 12.4616 +            break;
 12.4617 +        case 0:
 12.4618 +            {
 12.4619 +                /* All events are read */
 12.4620 +                finish = 1;
 12.4621 +                break;
 12.4622 +            }
 12.4623 +        case -1:
 12.4624 +            {
 12.4625 +                /* Error occured in event reading */
 12.4626 +                SDL_SetError("Photon: Can't read event");
 12.4627 +                return;
 12.4628 +            }
 12.4629 +            break;
 12.4630 +        }
 12.4631 +        if (finish != 0) {
 12.4632 +            break;
 12.4633 +        }
 12.4634 +    } while (1);
 12.4635  }
 12.4636  
 12.4637  /*****************************************************************************/
 12.4638  /* SDL screen saver related functions                                        */
 12.4639  /*****************************************************************************/
 12.4640 -void photon_suspendscreensaver(_THIS)
 12.4641 +void
 12.4642 +photon_suspendscreensaver(_THIS)
 12.4643  {
 12.4644 -   /* There is no screensaver in pure console, it may exist when running */
 12.4645 -   /* GF under Photon, but I do not know, how to disable screensaver     */
 12.4646 +    /* There is no screensaver in pure console, it may exist when running */
 12.4647 +    /* GF under Photon, but I do not know, how to disable screensaver     */
 12.4648  }
 12.4649  
 12.4650  /* vi: set ts=4 sw=4 expandtab: */
    13.1 --- a/src/video/photon/SDL_photon.h	Fri May 15 15:47:37 2009 +0000
    13.2 +++ b/src/video/photon/SDL_photon.h	Sat May 23 22:41:08 2009 +0000
    13.3 @@ -29,8 +29,8 @@
    13.4  
    13.5  /* GF headers must be included first for the Photon GF functions */
    13.6  #if defined(SDL_VIDEO_OPENGL_ES)
    13.7 -   #include <gf/gf.h>
    13.8 -   #include <GLES/egl.h>
    13.9 +#include <gf/gf.h>
   13.10 +#include <GLES/egl.h>
   13.11  #endif /* SDL_VIDEO_OPENGL_ES */
   13.12  
   13.13  #include "SDL_config.h"
   13.14 @@ -45,17 +45,17 @@
   13.15  
   13.16  typedef struct SDL_VideoData
   13.17  {
   13.18 -   PhRid_t  rid[SDL_VIDEO_PHOTON_MAX_RIDS];
   13.19 -   uint32_t avail_rids;
   13.20 -   uint32_t current_device_id;
   13.21 -   #if defined(SDL_VIDEO_OPENGL_ES)
   13.22 -      gf_dev_t      gfdev;           /* GF device handle                     */
   13.23 -      gf_dev_info_t gfdev_info;      /* GF device information                */
   13.24 -      SDL_bool      gfinitialized;   /* GF device initialization status      */
   13.25 -      EGLDisplay    egldisplay;      /* OpenGL ES display connection         */
   13.26 -      uint32_t      egl_refcount;    /* OpenGL ES reference count            */
   13.27 -      uint32_t      swapinterval;    /* OpenGL ES default swap interval      */
   13.28 -   #endif /* SDL_VIDEO_OPENGL_ES */
   13.29 +    PhRid_t rid[SDL_VIDEO_PHOTON_MAX_RIDS];
   13.30 +    uint32_t avail_rids;
   13.31 +    uint32_t current_device_id;
   13.32 +#if defined(SDL_VIDEO_OPENGL_ES)
   13.33 +    gf_dev_t gfdev;             /* GF device handle                     */
   13.34 +    gf_dev_info_t gfdev_info;   /* GF device information                */
   13.35 +    SDL_bool gfinitialized;     /* GF device initialization status      */
   13.36 +    EGLDisplay egldisplay;      /* OpenGL ES display connection         */
   13.37 +    uint32_t egl_refcount;      /* OpenGL ES reference count            */
   13.38 +    uint32_t swapinterval;      /* OpenGL ES default swap interval      */
   13.39 +#endif                          /* SDL_VIDEO_OPENGL_ES */
   13.40  } SDL_VideoData;
   13.41  
   13.42  /* This is hardcoded value in photon/Pg.h */
   13.43 @@ -67,19 +67,19 @@
   13.44  
   13.45  typedef struct SDL_DisplayData
   13.46  {
   13.47 -   uint32_t          device_id;
   13.48 -   uint32_t          custom_refresh;   /* Custom refresh rate for all modes  */
   13.49 -   SDL_DisplayMode   current_mode;     /* Current video mode                 */
   13.50 -   uint8_t           description[SDL_VIDEO_PHOTON_DEVICENAME_MAX];
   13.51 -                                       /* Device description                 */
   13.52 -   uint32_t          caps;             /* Device capabilities                */
   13.53 -   PhCursorDef_t*    cursor;           /* Global cursor settings             */
   13.54 -   SDL_bool          cursor_visible;   /* SDL_TRUE if cursor visible         */
   13.55 -   uint32_t          cursor_size;      /* Cursor size in memory w/ structure */
   13.56 -   #if defined(SDL_VIDEO_OPENGL_ES)
   13.57 -      gf_display_t      display;       /* GF display handle                  */
   13.58 -      gf_display_info_t display_info;  /* GF display information             */
   13.59 -   #endif /* SDL_VIDEO_OPENGL_ES */
   13.60 +    uint32_t device_id;
   13.61 +    uint32_t custom_refresh;    /* Custom refresh rate for all modes  */
   13.62 +    SDL_DisplayMode current_mode;       /* Current video mode                 */
   13.63 +    uint8_t description[SDL_VIDEO_PHOTON_DEVICENAME_MAX];
   13.64 +    /* Device description                 */
   13.65 +    uint32_t caps;              /* Device capabilities                */
   13.66 +    PhCursorDef_t *cursor;      /* Global cursor settings             */
   13.67 +    SDL_bool cursor_visible;    /* SDL_TRUE if cursor visible         */
   13.68 +    uint32_t cursor_size;       /* Cursor size in memory w/ structure */
   13.69 +#if defined(SDL_VIDEO_OPENGL_ES)
   13.70 +    gf_display_t display;       /* GF display handle                  */
   13.71 +    gf_display_info_t display_info;     /* GF display information             */
   13.72 +#endif                          /* SDL_VIDEO_OPENGL_ES */
   13.73  } SDL_DisplayData;
   13.74  
   13.75  /* Maximum amount of OpenGL ES framebuffer configurations */
   13.76 @@ -87,18 +87,18 @@
   13.77  
   13.78  typedef struct SDL_WindowData
   13.79  {
   13.80 -   SDL_bool       uses_gles;           /* if true window must support OpenGL ES*/
   13.81 -   PtWidget_t*    window;              /* window handle                        */
   13.82 -   #if defined(SDL_VIDEO_OPENGL_ES)
   13.83 -      EGLConfig    gles_configs[SDL_VIDEO_GF_OPENGLES_CONFS];
   13.84 -                                         /* OpenGL ES framebuffer confs        */
   13.85 -      EGLint       gles_config;          /* OpenGL ES configuration index      */
   13.86 -      EGLContext   gles_context;         /* OpenGL ES context                  */
   13.87 -      EGLint       gles_attributes[256]; /* OpenGL ES attributes for context   */
   13.88 -      EGLSurface   gles_surface;         /* OpenGL ES target rendering surface */
   13.89 -      gf_surface_t gfsurface;            /* OpenGL ES GF's surface             */
   13.90 -      PdOffscreenContext_t* phsurface;   /* OpenGL ES Photon's surface         */
   13.91 -   #endif /* SDL_VIDEO_OPENGL_ES */
   13.92 +    SDL_bool uses_gles;         /* if true window must support OpenGL ES */
   13.93 +    PtWidget_t *window;         /* window handle                        */
   13.94 +#if defined(SDL_VIDEO_OPENGL_ES)
   13.95 +    EGLConfig gles_configs[SDL_VIDEO_GF_OPENGLES_CONFS];
   13.96 +    /* OpenGL ES framebuffer confs        */
   13.97 +    EGLint gles_config;         /* OpenGL ES configuration index      */
   13.98 +    EGLContext gles_context;    /* OpenGL ES context                  */
   13.99 +    EGLint gles_attributes[256];        /* OpenGL ES attributes for context   */
  13.100 +    EGLSurface gles_surface;    /* OpenGL ES target rendering surface */
  13.101 +    gf_surface_t gfsurface;     /* OpenGL ES GF's surface             */
  13.102 +    PdOffscreenContext_t *phsurface;    /* OpenGL ES Photon's surface         */
  13.103 +#endif                          /* SDL_VIDEO_OPENGL_ES */
  13.104  } SDL_WindowData;
  13.105  
  13.106  /****************************************************************************/
  13.107 @@ -106,8 +106,8 @@
  13.108  /****************************************************************************/
  13.109  typedef struct Photon_DeviceCaps
  13.110  {
  13.111 -   uint8_t* name;
  13.112 -   uint32_t caps;
  13.113 +    uint8_t *name;
  13.114 +    uint32_t caps;
  13.115  } Photon_DeviceCaps;
  13.116  
  13.117  #define SDL_PHOTON_UNACCELERATED         0x00000000
  13.118 @@ -120,41 +120,42 @@
  13.119  /****************************************************************************/
  13.120  
  13.121  /* Display and window functions */
  13.122 -int  photon_videoinit(_THIS);
  13.123 +int photon_videoinit(_THIS);
  13.124  void photon_videoquit(_THIS);
  13.125  void photon_getdisplaymodes(_THIS);
  13.126 -int  photon_setdisplaymode(_THIS, SDL_DisplayMode* mode);
  13.127 -int  photon_setdisplaypalette(_THIS, SDL_Palette* palette);
  13.128 -int  photon_getdisplaypalette(_THIS, SDL_Palette* palette);
  13.129 -int  photon_setdisplaygammaramp(_THIS, Uint16* ramp);
  13.130 -int  photon_getdisplaygammaramp(_THIS, Uint16* ramp);
  13.131 -int  photon_createwindow(_THIS, SDL_Window* window);
  13.132 -int  photon_createwindowfrom(_THIS, SDL_Window* window, const void* data);
  13.133 -void photon_setwindowtitle(_THIS, SDL_Window* window);
  13.134 -void photon_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon);
  13.135 -void photon_setwindowposition(_THIS, SDL_Window* window);
  13.136 -void photon_setwindowsize(_THIS, SDL_Window* window);
  13.137 -void photon_showwindow(_THIS, SDL_Window* window);
  13.138 -void photon_hidewindow(_THIS, SDL_Window* window);
  13.139 -void photon_raisewindow(_THIS, SDL_Window* window);
  13.140 -void photon_maximizewindow(_THIS, SDL_Window* window);
  13.141 -void photon_minimizewindow(_THIS, SDL_Window* window);
  13.142 -void photon_restorewindow(_THIS, SDL_Window* window);
  13.143 -void photon_setwindowgrab(_THIS, SDL_Window* window);
  13.144 -void photon_destroywindow(_THIS, SDL_Window* window);
  13.145 +int photon_setdisplaymode(_THIS, SDL_DisplayMode * mode);
  13.146 +int photon_setdisplaypalette(_THIS, SDL_Palette * palette);
  13.147 +int photon_getdisplaypalette(_THIS, SDL_Palette * palette);
  13.148 +int photon_setdisplaygammaramp(_THIS, Uint16 * ramp);
  13.149 +int photon_getdisplaygammaramp(_THIS, Uint16 * ramp);
  13.150 +int photon_createwindow(_THIS, SDL_Window * window);
  13.151 +int photon_createwindowfrom(_THIS, SDL_Window * window, const void *data);
  13.152 +void photon_setwindowtitle(_THIS, SDL_Window * window);
  13.153 +void photon_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon);
  13.154 +void photon_setwindowposition(_THIS, SDL_Window * window);
  13.155 +void photon_setwindowsize(_THIS, SDL_Window * window);
  13.156 +void photon_showwindow(_THIS, SDL_Window * window);
  13.157 +void photon_hidewindow(_THIS, SDL_Window * window);
  13.158 +void photon_raisewindow(_THIS, SDL_Window * window);
  13.159 +void photon_maximizewindow(_THIS, SDL_Window * window);
  13.160 +void photon_minimizewindow(_THIS, SDL_Window * window);
  13.161 +void photon_restorewindow(_THIS, SDL_Window * window);
  13.162 +void photon_setwindowgrab(_THIS, SDL_Window * window);
  13.163 +void photon_destroywindow(_THIS, SDL_Window * window);
  13.164  
  13.165  /* Window manager function */
  13.166 -SDL_bool photon_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo* info);
  13.167 +SDL_bool photon_getwindowwminfo(_THIS, SDL_Window * window,
  13.168 +                                struct SDL_SysWMinfo *info);
  13.169  
  13.170  /* OpenGL/OpenGL ES functions */
  13.171 -int photon_gl_loadlibrary(_THIS, const char* path);
  13.172 -void* photon_gl_getprocaddres(_THIS, const char* proc);
  13.173 +int photon_gl_loadlibrary(_THIS, const char *path);
  13.174 +void *photon_gl_getprocaddres(_THIS, const char *proc);
  13.175  void photon_gl_unloadlibrary(_THIS);
  13.176 -SDL_GLContext photon_gl_createcontext(_THIS, SDL_Window* window);
  13.177 -int photon_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context);
  13.178 +SDL_GLContext photon_gl_createcontext(_THIS, SDL_Window * window);
  13.179 +int photon_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context);
  13.180  int photon_gl_setswapinterval(_THIS, int interval);
  13.181  int photon_gl_getswapinterval(_THIS);
  13.182 -void photon_gl_swapwindow(_THIS, SDL_Window* window);
  13.183 +void photon_gl_swapwindow(_THIS, SDL_Window * window);
  13.184  void photon_gl_deletecontext(_THIS, SDL_GLContext context);
  13.185  
  13.186  /* Event handling function */
    14.1 --- a/src/video/photon/SDL_photon_input.c	Fri May 15 15:47:37 2009 +0000
    14.2 +++ b/src/video/photon/SDL_photon_input.c	Sat May 23 22:41:08 2009 +0000
    14.3 @@ -34,727 +34,699 @@
    14.4  #include "SDL_photon_keycodes.h"
    14.5  
    14.6  /* Mouse related functions */
    14.7 -SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y);
    14.8 -int  photon_showcursor(SDL_Cursor* cursor);
    14.9 -void photon_movecursor(SDL_Cursor* cursor);
   14.10 -void photon_freecursor(SDL_Cursor* cursor);
   14.11 -void photon_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y);
   14.12 -void photon_freemouse(SDL_Mouse* mouse);
   14.13 +SDL_Cursor *photon_createcursor(SDL_Surface * surface, int hot_x, int hot_y);
   14.14 +int photon_showcursor(SDL_Cursor * cursor);
   14.15 +void photon_movecursor(SDL_Cursor * cursor);
   14.16 +void photon_freecursor(SDL_Cursor * cursor);
   14.17 +void photon_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y);
   14.18 +void photon_freemouse(SDL_Mouse * mouse);
   14.19  
   14.20 -int32_t photon_addinputdevices(_THIS)
   14.21 +int32_t
   14.22 +photon_addinputdevices(_THIS)
   14.23  {
   14.24 -   SDL_VideoData*    phdata=(SDL_VideoData*)_this->driverdata;
   14.25 -   SDL_DisplayData*  didata=NULL;
   14.26 -   struct SDL_Mouse  photon_mouse;
   14.27 -   SDL_MouseData*    mdata=NULL;
   14.28 -   SDL_Keyboard      photon_keyboard;
   14.29 -   SDLKey   keymap[SDL_NUM_SCANCODES];
   14.30 -   uint32_t it;
   14.31 +    SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
   14.32 +    SDL_DisplayData *didata = NULL;
   14.33 +    struct SDL_Mouse photon_mouse;
   14.34 +    SDL_MouseData *mdata = NULL;
   14.35 +    SDL_Keyboard photon_keyboard;
   14.36 +    SDLKey keymap[SDL_NUM_SCANCODES];
   14.37 +    uint32_t it;
   14.38  
   14.39 -   for (it=0; it<_this->num_displays; it++)
   14.40 -   {
   14.41 -      /* Clear SDL mouse structure */
   14.42 -      SDL_memset(&photon_mouse, 0x00, sizeof(struct SDL_Mouse));
   14.43 +    for (it = 0; it < _this->num_displays; it++) {
   14.44 +        /* Clear SDL mouse structure */
   14.45 +        SDL_memset(&photon_mouse, 0x00, sizeof(struct SDL_Mouse));
   14.46  
   14.47 -      /* Allocate SDL_MouseData structure */
   14.48 -      mdata=(SDL_MouseData*)SDL_calloc(1, sizeof(SDL_MouseData));
   14.49 -      if (mdata==NULL)
   14.50 -      {
   14.51 -         SDL_OutOfMemory();
   14.52 -         return -1;
   14.53 -      }
   14.54 +        /* Allocate SDL_MouseData structure */
   14.55 +        mdata = (SDL_MouseData *) SDL_calloc(1, sizeof(SDL_MouseData));
   14.56 +        if (mdata == NULL) {
   14.57 +            SDL_OutOfMemory();
   14.58 +            return -1;
   14.59 +        }
   14.60  
   14.61 -      /* Mark this mouse with ID 0 */
   14.62 -      photon_mouse.id=it;
   14.63 -      photon_mouse.driverdata=(void*)mdata;
   14.64 -      photon_mouse.CreateCursor=photon_createcursor;
   14.65 -      photon_mouse.ShowCursor=photon_showcursor;
   14.66 -      photon_mouse.MoveCursor=photon_movecursor;
   14.67 -      photon_mouse.FreeCursor=photon_freecursor;
   14.68 -      photon_mouse.WarpMouse=photon_warpmouse;
   14.69 -      photon_mouse.FreeMouse=photon_freemouse;
   14.70 +        /* Mark this mouse with ID 0 */
   14.71 +        photon_mouse.id = it;
   14.72 +        photon_mouse.driverdata = (void *) mdata;
   14.73 +        photon_mouse.CreateCursor = photon_createcursor;
   14.74 +        photon_mouse.ShowCursor = photon_showcursor;
   14.75 +        photon_mouse.MoveCursor = photon_movecursor;
   14.76 +        photon_mouse.FreeCursor = photon_freecursor;
   14.77 +        photon_mouse.WarpMouse = photon_warpmouse;
   14.78 +        photon_mouse.FreeMouse = photon_freemouse;
   14.79  
   14.80 -      /* Get display data */
   14.81 -      didata=(SDL_DisplayData*)_this->displays[it].driverdata;
   14.82 +        /* Get display data */
   14.83 +        didata = (SDL_DisplayData *) _this->displays[it].driverdata;
   14.84  
   14.85 -      /* Store SDL_DisplayData pointer in the mouse driver internals */
   14.86 -      mdata->didata=didata;
   14.87 +        /* Store SDL_DisplayData pointer in the mouse driver internals */
   14.88 +        mdata->didata = didata;
   14.89  
   14.90 -      /* Register mouse cursor in SDL */
   14.91 -      SDL_AddMouse(&photon_mouse, "Photon mouse cursor", 0, 0, 1);
   14.92 -   }
   14.93 +        /* Register mouse cursor in SDL */
   14.94 +        SDL_AddMouse(&photon_mouse, "Photon mouse cursor", 0, 0, 1);
   14.95 +    }
   14.96  
   14.97 -   /* Photon maps all keyboards to one */
   14.98 -   SDL_zero(photon_keyboard);
   14.99 -   SDL_AddKeyboard(&photon_keyboard, -1);
  14.100 +    /* Photon maps all keyboards to one */
  14.101 +    SDL_zero(photon_keyboard);
  14.102 +    SDL_AddKeyboard(&photon_keyboard, -1);
  14.103  
  14.104 -   /* Add default scancode to key mapping */
  14.105 -   SDL_GetDefaultKeymap(keymap);
  14.106 -   SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
  14.107 +    /* Add default scancode to key mapping */
  14.108 +    SDL_GetDefaultKeymap(keymap);
  14.109 +    SDL_SetKeymap(0, 0, keymap, SDL_NUM_SCANCODES);
  14.110  
  14.111 -   return 0;
  14.112 +    return 0;
  14.113  }
  14.114  
  14.115 -int32_t photon_delinputdevices(_THIS)
  14.116 +int32_t
  14.117 +photon_delinputdevices(_THIS)
  14.118  {
  14.119 -   /* Destroy all of the mice */
  14.120 -   SDL_MouseQuit();
  14.121 +    /* Destroy all of the mice */
  14.122 +    SDL_MouseQuit();
  14.123  }
  14.124  
  14.125  /*****************************************************************************/
  14.126  /* Photon mouse related functions                                            */
  14.127  /*****************************************************************************/
  14.128 -SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y)
  14.129 +SDL_Cursor *
  14.130 +photon_createcursor(SDL_Surface * surface, int hot_x, int hot_y)
  14.131  {
  14.132 -   PhCursorDef_t* internal_cursor;
  14.133 -   SDL_Cursor*    sdl_cursor;
  14.134 -   uint8_t*       image0=NULL;
  14.135 -   uint8_t*       image1=NULL;
  14.136 -   uint32_t       it;
  14.137 -   uint32_t       jt;
  14.138 -   uint32_t       shape_color;
  14.139 +    PhCursorDef_t *internal_cursor;
  14.140 +    SDL_Cursor *sdl_cursor;
  14.141 +    uint8_t *image0 = NULL;
  14.142 +    uint8_t *image1 = NULL;
  14.143 +    uint32_t it;
  14.144 +    uint32_t jt;
  14.145 +    uint32_t shape_color;
  14.146  
  14.147 -   /* SDL converts monochrome cursor shape to 32bpp cursor shape      */
  14.148 -   /* and we must convert it back to monochrome, this routine handles */
  14.149 -   /* 24/32bpp surfaces only                                          */
  14.150 -   if ((surface->format->BitsPerPixel!=32) && (surface->format->BitsPerPixel!=24))
  14.151 -   {
  14.152 -      SDL_SetError("Photon: Cursor shape is not 24/32bpp.");
  14.153 -      return NULL;
  14.154 -   }
  14.155 +    /* SDL converts monochrome cursor shape to 32bpp cursor shape      */
  14.156 +    /* and we must convert it back to monochrome, this routine handles */
  14.157 +    /* 24/32bpp surfaces only                                          */
  14.158 +    if ((surface->format->BitsPerPixel != 32)
  14.159 +        && (surface->format->BitsPerPixel != 24)) {
  14.160 +        SDL_SetError("Photon: Cursor shape is not 24/32bpp.");
  14.161 +        return NULL;
  14.162 +    }
  14.163  
  14.164 -   /* Checking data parameters */
  14.165 -   if ((surface->w==0) || (surface->h==0))
  14.166 -   {
  14.167 -      SDL_SetError("Photon: Cursor shape dimensions are zero");
  14.168 -      return NULL;
  14.169 -   }
  14.170 +    /* Checking data parameters */
  14.171 +    if ((surface->w == 0) || (surface->h == 0)) {
  14.172 +        SDL_SetError("Photon: Cursor shape dimensions are zero");
  14.173 +        return NULL;
  14.174 +    }
  14.175  
  14.176 -   /* Allocate memory for the internal cursor format */
  14.177 -   internal_cursor=(PhCursorDef_t*)SDL_calloc(1, sizeof(PhCursorDef_t)+
  14.178 -      ((((surface->w+7)>>3)*surface->h)*2)-1);
  14.179 -   if (internal_cursor==NULL)
  14.180 -   {
  14.181 -      SDL_OutOfMemory();
  14.182 -      return NULL;
  14.183 -   }
  14.184 +    /* Allocate memory for the internal cursor format */
  14.185 +    internal_cursor = (PhCursorDef_t *) SDL_calloc(1, sizeof(PhCursorDef_t) +
  14.186 +                                                   ((((surface->w +
  14.187 +                                                       7) >> 3) *
  14.188 +                                                     surface->h) * 2) - 1);
  14.189 +    if (internal_cursor == NULL) {
  14.190 +        SDL_OutOfMemory();
  14.191 +        return NULL;
  14.192 +    }
  14.193  
  14.194 -   /* Allocate memory for the SDL cursor */
  14.195 -   sdl_cursor=(SDL_Cursor*)SDL_calloc(1, sizeof(SDL_Cursor));
  14.196 -   if (sdl_cursor==NULL)
  14.197 -   {
  14.198 -      SDL_free(internal_cursor);
  14.199 -      SDL_OutOfMemory();
  14.200 -      return NULL;
  14.201 -   }
  14.202 +    /* Allocate memory for the SDL cursor */
  14.203 +    sdl_cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(SDL_Cursor));
  14.204 +    if (sdl_cursor == NULL) {
  14.205 +        SDL_free(internal_cursor);
  14.206 +        SDL_OutOfMemory();
  14.207 +        return NULL;
  14.208 +    }
  14.209  
  14.210 -   /* Set driverdata as photon cursor format */
  14.211 -   image0=(uint8_t*)internal_cursor;
  14.212 -   image0+=sizeof(PhCursorDef_t)-1;
  14.213 -   image1=image0;
  14.214 -   image1+=((surface->w+7)>>3)*surface->h;
  14.215 -   sdl_cursor->driverdata=(void*)internal_cursor;
  14.216 -   internal_cursor->hdr.len=(sizeof(PhCursorDef_t)-sizeof(PhRegionDataHdr_t))+
  14.217 -                            ((((surface->w+7)>>3)*surface->h)*2)-1;
  14.218 -   internal_cursor->hdr.type=Ph_RDATA_CURSOR;
  14.219 -   internal_cursor->size1.x=surface->w;
  14.220 -   internal_cursor->size1.y=surface->h;
  14.221 -   internal_cursor->size2.x=surface->w;
  14.222 -   internal_cursor->size2.y=surface->h;
  14.223 -   internal_cursor->offset1.x=hot_x;
  14.224 -   internal_cursor->offset1.y=hot_y;
  14.225 -   internal_cursor->offset2.x=hot_x;
  14.226 -   internal_cursor->offset2.y=hot_y;
  14.227 -   internal_cursor->bytesperline1=((surface->w+7)>>3);
  14.228 -   internal_cursor->bytesperline2=((surface->w+7)>>3);
  14.229 -   internal_cursor->color1=(SDL_PHOTON_MOUSE_COLOR_BLACK) & 0x00FFFFFF;
  14.230 -   internal_cursor->color2=(SDL_PHOTON_MOUSE_COLOR_WHITE) & 0x00FFFFFF;
  14.231 +    /* Set driverdata as photon cursor format */
  14.232 +    image0 = (uint8_t *) internal_cursor;
  14.233 +    image0 += sizeof(PhCursorDef_t) - 1;
  14.234 +    image1 = image0;
  14.235 +    image1 += ((surface->w + 7) >> 3) * surface->h;
  14.236 +    sdl_cursor->driverdata = (void *) internal_cursor;
  14.237 +    internal_cursor->hdr.len =
  14.238 +        (sizeof(PhCursorDef_t) - sizeof(PhRegionDataHdr_t)) +
  14.239 +        ((((surface->w + 7) >> 3) * surface->h) * 2) - 1;
  14.240 +    internal_cursor->hdr.type = Ph_RDATA_CURSOR;
  14.241 +    internal_cursor->size1.x = surface->w;
  14.242 +    internal_cursor->size1.y = surface->h;
  14.243 +    internal_cursor->size2.x = surface->w;
  14.244 +    internal_cursor->size2.y = surface->h;
  14.245 +    internal_cursor->offset1.x = hot_x;
  14.246 +    internal_cursor->offset1.y = hot_y;
  14.247 +    internal_cursor->offset2.x = hot_x;
  14.248 +    internal_cursor->offset2.y = hot_y;
  14.249 +    internal_cursor->bytesperline1 = ((surface->w + 7) >> 3);
  14.250 +    internal_cursor->bytesperline2 = ((surface->w + 7) >> 3);
  14.251 +    internal_cursor->color1 = (SDL_PHOTON_MOUSE_COLOR_BLACK) & 0x00FFFFFF;
  14.252 +    internal_cursor->color2 = (SDL_PHOTON_MOUSE_COLOR_WHITE) & 0x00FFFFFF;
  14.253  
  14.254 -   /* Convert cursor from 32 bpp */
  14.255 -   for (jt=0; jt<surface->h; jt++)
  14.256 -   {
  14.257 -      for (it=0; it<surface->w; it++)
  14.258 -      {
  14.259 -         shape_color=*((uint32_t*)((uint8_t*)surface->pixels+jt*surface->pitch+it*surface->format->BytesPerPixel));
  14.260 -         switch(shape_color)
  14.261 -         {
  14.262 +    /* Convert cursor from 32 bpp */
  14.263 +    for (jt = 0; jt < surface->h; jt++) {
  14.264 +        for (it = 0; it < surface->w; it++) {
  14.265 +            shape_color =
  14.266 +                *((uint32_t *) ((uint8_t *) surface->pixels +
  14.267 +                                jt * surface->pitch +
  14.268 +                                it * surface->format->BytesPerPixel));
  14.269 +            switch (shape_color) {
  14.270              case SDL_PHOTON_MOUSE_COLOR_BLACK:
  14.271 -                 {
  14.272 -                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))|=0x80>>(it%8);
  14.273 -                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8));
  14.274 -                 }
  14.275 -                 break;
  14.276 +                {
  14.277 +                    *(image0 + jt * (internal_cursor->bytesperline1) +
  14.278 +                      (it >> 3)) |= 0x80 >> (it % 8);
  14.279 +                    *(image1 + jt * (internal_cursor->bytesperline2) +
  14.280 +                      (it >> 3)) &= ~(0x80 >> (it % 8));
  14.281 +                }
  14.282 +                break;
  14.283              case SDL_PHOTON_MOUSE_COLOR_WHITE:
  14.284 -                 {
  14.285 -                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8));
  14.286 -                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))|=0x80>>(it%8);
  14.287 -                 }
  14.288 -                 break;
  14.289 +                {
  14.290 +                    *(image0 + jt * (internal_cursor->bytesperline1) +
  14.291 +                      (it >> 3)) &= ~(0x80 >> (it % 8));
  14.292 +                    *(image1 + jt * (internal_cursor->bytesperline2) +
  14.293 +                      (it >> 3)) |= 0x80 >> (it % 8);
  14.294 +                }
  14.295 +                break;
  14.296              case SDL_PHOTON_MOUSE_COLOR_TRANS:
  14.297 -                 {
  14.298 -                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8));
  14.299 -                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8));
  14.300 -                 }
  14.301 -                 break;
  14.302 +                {
  14.303 +                    *(image0 + jt * (internal_cursor->bytesperline1) +
  14.304 +                      (it >> 3)) &= ~(0x80 >> (it % 8));
  14.305 +                    *(image1 + jt * (internal_cursor->bytesperline2) +
  14.306 +                      (it >> 3)) &= ~(0x80 >> (it % 8));
  14.307 +                }
  14.308 +                break;
  14.309              default:
  14.310 -                 {
  14.311 +                {
  14.312                      /* The same as transparent color, must not happen */
  14.313 -                    *(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8));
  14.314 -                    *(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8));
  14.315 -                 }
  14.316 -                 break;
  14.317 -         }
  14.318 -      }
  14.319 -   }
  14.320 +                    *(image0 + jt * (internal_cursor->bytesperline1) +
  14.321 +                      (it >> 3)) &= ~(0x80 >> (it % 8));
  14.322 +                    *(image1 + jt * (internal_cursor->bytesperline2) +
  14.323 +                      (it >> 3)) &= ~(0x80 >> (it % 8));
  14.324 +                }
  14.325 +                break;
  14.326 +            }
  14.327 +        }
  14.328 +    }
  14.329  
  14.330 -   return sdl_cursor;
  14.331 +    return sdl_cursor;
  14.332  }
  14.333  
  14.334 -int photon_showcursor(SDL_Cursor* cursor)
  14.335 +int
  14.336 +photon_showcursor(SDL_Cursor * cursor)
  14.337  {
  14.338 -   SDL_VideoDisplay* display;
  14.339 -   SDL_DisplayData*  didata;
  14.340 -   SDL_Window*       window;
  14.341 -   SDL_WindowData*   wdata;
  14.342 -   SDL_WindowID      window_id;
  14.343 -   PhCursorDef_t*    internal_cursor;
  14.344 -   int32_t status;
  14.345 +    SDL_VideoDisplay *display;
  14.346 +    SDL_DisplayData *didata;
  14.347 +    SDL_Window *window;
  14.348 +    SDL_WindowData *wdata;
  14.349 +    SDL_WindowID window_id;
  14.350 +    PhCursorDef_t *internal_cursor;
  14.351 +    int32_t status;
  14.352  
  14.353 -   /* Get current window id */
  14.354 -   window_id=SDL_GetFocusWindow();
  14.355 -   if (window_id<=0)
  14.356 -   {
  14.357 -      SDL_MouseData* mdata=NULL;
  14.358 +    /* Get current window id */
  14.359 +    window_id = SDL_GetFocusWindow();
  14.360 +    if (window_id <= 0) {
  14.361 +        SDL_MouseData *mdata = NULL;
  14.362  
  14.363 -      /* If there is no current window, then someone calls this function */
  14.364 -      /* to set global mouse settings during SDL initialization          */
  14.365 -      if (cursor!=NULL)
  14.366 -      {
  14.367 -         /* Store cursor for future usage */
  14.368 -         mdata=(SDL_MouseData*)cursor->mouse->driverdata;
  14.369 -         didata=(SDL_DisplayData*)mdata->didata;
  14.370 -         internal_cursor=(PhCursorDef_t*)cursor->driverdata;
  14.371 +        /* If there is no current window, then someone calls this function */
  14.372 +        /* to set global mouse settings during SDL initialization          */
  14.373 +        if (cursor != NULL) {
  14.374 +            /* Store cursor for future usage */
  14.375 +            mdata = (SDL_MouseData *) cursor->mouse->driverdata;
  14.376 +            didata = (SDL_DisplayData *) mdata->didata;
  14.377 +            internal_cursor = (PhCursorDef_t *) cursor->driverdata;
  14.378  
  14.379 -         if (didata->cursor_size>=(internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t)))
  14.380 -         {
  14.381 -            SDL_memcpy(didata->cursor, internal_cursor, internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t));
  14.382 -         }
  14.383 -         else
  14.384 -         {
  14.385 +            if (didata->cursor_size >=
  14.386 +                (internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t))) {
  14.387 +                SDL_memcpy(didata->cursor, internal_cursor,
  14.388 +                           internal_cursor->hdr.len +
  14.389 +                           sizeof(PhRegionDataHdr_t));
  14.390 +            } else {
  14.391 +                /* Partitial cursor image */
  14.392 +                SDL_memcpy(didata->cursor, internal_cursor,
  14.393 +                           didata->cursor_size);
  14.394 +            }
  14.395 +
  14.396 +            didata->cursor_visible = SDL_TRUE;
  14.397 +            return 0;
  14.398 +        } else {
  14.399 +            /* We can't get SDL_DisplayData at this point, return fake success */
  14.400 +            return 0;
  14.401 +        }
  14.402 +    } else {
  14.403 +        /* Sanity checks */
  14.404 +        window = SDL_GetWindowFromID(window_id);
  14.405 +        if (window != NULL) {
  14.406 +            display = SDL_GetDisplayFromWindow(window);
  14.407 +            if (display != NULL) {
  14.408 +                didata = (SDL_DisplayData *) display->driverdata;
  14.409 +                if (didata != NULL) {
  14.410 +                    wdata = (SDL_WindowData *) window->driverdata;
  14.411 +                    if (wdata == NULL) {
  14.412 +                        return -1;
  14.413 +                    }
  14.414 +                } else {
  14.415 +                    return -1;
  14.416 +                }
  14.417 +            } else {
  14.418 +                return -1;
  14.419 +            }
  14.420 +        } else {
  14.421 +            return -1;
  14.422 +        }
  14.423 +    }
  14.424 +
  14.425 +    /* return if window widget has been destroyed already */
  14.426 +    if (wdata->window == NULL) {
  14.427 +        return;
  14.428 +    }
  14.429 +
  14.430 +    /* Check if we need to set new shape or disable cursor shape */
  14.431 +    if (cursor != NULL) {
  14.432 +        /* Retrieve photon cursor shape */
  14.433 +        internal_cursor = (PhCursorDef_t *) cursor->driverdata;
  14.434 +        if (internal_cursor == NULL) {
  14.435 +            SDL_SetError("Photon: Internal cursor data is absent");
  14.436 +            return -1;
  14.437 +        }
  14.438 +
  14.439 +        /* Setup cursor type */
  14.440 +        status =
  14.441 +            PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP,
  14.442 +                          0);
  14.443 +        if (status != 0) {
  14.444 +            SDL_SetError("Photon: Failed to set cursor type to bitmap");
  14.445 +            return -1;
  14.446 +        }
  14.447 +
  14.448 +        /* Setup cursor color to default */
  14.449 +        status =
  14.450 +            PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR,
  14.451 +                          Ph_CURSOR_DEFAULT_COLOR, 0);
  14.452 +        if (status != 0) {
  14.453 +            SDL_SetError("Photon: Failed to set cursor color");
  14.454 +            return -1;
  14.455 +        }
  14.456 +
  14.457 +        /* Setup cursor shape */
  14.458 +        status =
  14.459 +            PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR,
  14.460 +                          internal_cursor,
  14.461 +                          internal_cursor->hdr.len +
  14.462 +                          sizeof(PhRegionDataHdr_t));
  14.463 +        if (status != 0) {
  14.464 +            SDL_SetError("Photon: Failed to set cursor color");
  14.465 +            return -1;
  14.466 +        }
  14.467 +
  14.468 +        /* Store current cursor for future usage */
  14.469 +        if (didata->cursor_size >=
  14.470 +            (internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t))) {
  14.471 +            SDL_memcpy(didata->cursor, internal_cursor,
  14.472 +                       internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t));
  14.473 +        } else {
  14.474              /* Partitial cursor image */
  14.475              SDL_memcpy(didata->cursor, internal_cursor, didata->cursor_size);
  14.476 -         }
  14.477 +        }
  14.478  
  14.479 -         didata->cursor_visible=SDL_TRUE;
  14.480 -         return 0;
  14.481 -      }
  14.482 -      else
  14.483 -      {
  14.484 -         /* We can't get SDL_DisplayData at this point, return fake success */
  14.485 -         return 0;
  14.486 -      }
  14.487 -   }
  14.488 -   else
  14.489 -   {
  14.490 -      /* Sanity checks */
  14.491 -      window=SDL_GetWindowFromID(window_id);
  14.492 -      if (window!=NULL)
  14.493 -      {
  14.494 -         display=SDL_GetDisplayFromWindow(window);
  14.495 -         if (display!=NULL)
  14.496 -         {
  14.497 -            didata=(SDL_DisplayData*)display->driverdata;
  14.498 -            if (didata!=NULL)
  14.499 -            {
  14.500 -               wdata=(SDL_WindowData*)window->driverdata;
  14.501 -               if (wdata==NULL)
  14.502 -               {
  14.503 -                  return -1;
  14.504 -               }
  14.505 -            }
  14.506 -            else
  14.507 -            {
  14.508 -               return -1;
  14.509 -            }
  14.510 -         }
  14.511 -         else
  14.512 -         {
  14.513 +        /* Set cursor visible */
  14.514 +        didata->cursor_visible = SDL_TRUE;
  14.515 +    } else {
  14.516 +        /* SDL requests to disable cursor */
  14.517 +        status =
  14.518 +            PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE,
  14.519 +                          0);
  14.520 +        if (status != 0) {
  14.521 +            SDL_SetError("Photon: Can't disable cursor");
  14.522              return -1;
  14.523 -         }
  14.524 -      }
  14.525 -      else
  14.526 -      {
  14.527 -         return -1;
  14.528 -      }
  14.529 -   }
  14.530 +        }
  14.531  
  14.532 -   /* return if window widget has been destroyed already */
  14.533 -   if (wdata->window==NULL)
  14.534 -   {
  14.535 -      return;
  14.536 -   }
  14.537 +        /* Set cursor invisible */
  14.538 +        didata->cursor_visible = SDL_FALSE;
  14.539 +    }
  14.540  
  14.541 -   /* Check if we need to set new shape or disable cursor shape */
  14.542 -   if (cursor!=NULL)
  14.543 -   {
  14.544 -      /* Retrieve photon cursor shape */
  14.545 -      internal_cursor=(PhCursorDef_t*)cursor->driverdata;
  14.546 -      if (internal_cursor==NULL)
  14.547 -      {
  14.548 -         SDL_SetError("Photon: Internal cursor data is absent");
  14.549 -         return -1;
  14.550 -      }
  14.551 +    /* Flush all pending widget data */
  14.552 +    PtFlush();
  14.553  
  14.554 -      /* Setup cursor type */
  14.555 -      status=PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0);
  14.556 -      if (status!=0)
  14.557 -      {
  14.558 -         SDL_SetError("Photon: Failed to set cursor type to bitmap");
  14.559 -         return -1;
  14.560 -      }
  14.561 -
  14.562 -      /* Setup cursor color to default */
  14.563 -      status=PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR, 0);
  14.564 -      if (status!=0)
  14.565 -      {
  14.566 -         SDL_SetError("Photon: Failed to set cursor color");
  14.567 -         return -1;
  14.568 -      }
  14.569 -
  14.570 -      /* Setup cursor shape */
  14.571 -      status=PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, internal_cursor,
  14.572 -                           internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t));
  14.573 -      if (status!=0)
  14.574 -      {
  14.575 -         SDL_SetError("Photon: Failed to set cursor color");
  14.576 -         return -1;
  14.577 -      }
  14.578 -
  14.579 -      /* Store current cursor for future usage */
  14.580 -      if (didata->cursor_size>=(internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t)))
  14.581 -      {
  14.582 -         SDL_memcpy(didata->cursor, internal_cursor, internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t));
  14.583 -      }
  14.584 -      else
  14.585 -      {
  14.586 -         /* Partitial cursor image */
  14.587 -         SDL_memcpy(didata->cursor, internal_cursor, didata->cursor_size);
  14.588 -      }
  14.589 -
  14.590 -      /* Set cursor visible */
  14.591 -      didata->cursor_visible=SDL_TRUE;
  14.592 -   }
  14.593 -   else
  14.594 -   {
  14.595 -      /* SDL requests to disable cursor */
  14.596 -      status=PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0);
  14.597 -      if (status!=0)
  14.598 -      {
  14.599 -         SDL_SetError("Photon: Can't disable cursor");
  14.600 -         return -1;
  14.601 -      }
  14.602 -
  14.603 -      /* Set cursor invisible */
  14.604 -      didata->cursor_visible=SDL_FALSE;
  14.605 -   }
  14.606 -
  14.607 -   /* Flush all pending widget data */
  14.608 -   PtFlush();
  14.609 -
  14.610 -   /* New cursor shape is set */
  14.611 -   return 0;
  14.612 +    /* New cursor shape is set */
  14.613 +    return 0;
  14.614  }
  14.615  
  14.616 -void photon_movecursor(SDL_Cursor* cursor)
  14.617 +void
  14.618 +photon_movecursor(SDL_Cursor * cursor)
  14.619  {
  14.620 -   SDL_VideoDisplay* display;
  14.621 -   SDL_DisplayData*  didata;
  14.622 -   SDL_Window*       window;
  14.623 -   SDL_WindowData*   wdata;
  14.624 -   SDL_WindowID window_id;
  14.625 -   int32_t status;
  14.626 +    SDL_VideoDisplay *display;
  14.627 +    SDL_DisplayData *didata;
  14.628 +    SDL_Window *window;
  14.629 +    SDL_WindowData *wdata;
  14.630 +    SDL_WindowID window_id;
  14.631 +    int32_t status;
  14.632  
  14.633 -   /* Get current window id */
  14.634 -   window_id=SDL_GetFocusWindow();
  14.635 -   if (window_id<=0)
  14.636 -   {
  14.637 -      didata=(SDL_DisplayData*)cursor->mouse->driverdata;
  14.638 -   }
  14.639 -   else
  14.640 -   {
  14.641 -      /* Sanity checks */
  14.642 -      window=SDL_GetWindowFromID(window_id);
  14.643 -      if (window!=NULL)
  14.644 -      {
  14.645 -         display=SDL_GetDisplayFromWindow(window);
  14.646 -         if (display!=NULL)
  14.647 -         {
  14.648 -            didata=(SDL_DisplayData*)display->driverdata;
  14.649 -            if (didata!=NULL)
  14.650 -            {
  14.651 -               wdata=(SDL_WindowData*)window->driverdata;
  14.652 -               if (wdata==NULL)
  14.653 -               {
  14.654 -                  return;
  14.655 -               }
  14.656 +    /* Get current window id */
  14.657 +    window_id = SDL_GetFocusWindow();
  14.658 +    if (window_id <= 0) {
  14.659 +        didata = (SDL_DisplayData *) cursor->mouse->driverdata;
  14.660 +    } else {
  14.661 +        /* Sanity checks */
  14.662 +        window = SDL_GetWindowFromID(window_id);
  14.663 +        if (window != NULL) {
  14.664 +            display = SDL_GetDisplayFromWindow(window);
  14.665 +            if (display != NULL) {
  14.666 +                didata = (SDL_DisplayData *) display->driverdata;
  14.667 +                if (didata != NULL) {
  14.668 +                    wdata = (SDL_WindowData *) window->driverdata;
  14.669 +                    if (wdata == NULL) {
  14.670 +                        return;
  14.671 +                    }
  14.672 +                } else {
  14.673 +                    return;
  14.674 +                }
  14.675 +            } else {
  14.676 +                return;
  14.677              }
  14.678 -            else
  14.679 -            {
  14.680 -               return;
  14.681 -            }
  14.682 -         }
  14.683 -         else
  14.684 -         {
  14.685 +        } else {
  14.686              return;
  14.687 -         }
  14.688 -      }
  14.689 -      else
  14.690 -      {
  14.691 -         return;
  14.692 -      }
  14.693 -   }
  14.694 +        }
  14.695 +    }
  14.696  
  14.697 -   /* No need to move mouse cursor manually in the photon */
  14.698 +    /* No need to move mouse cursor manually in the photon */
  14.699  
  14.700 -   return;
  14.701 +    return;
  14.702  }
  14.703  
  14.704 -void photon_freecursor(SDL_Cursor* cursor)
  14.705 +void
  14.706 +photon_freecursor(SDL_Cursor * cursor)
  14.707  {
  14.708 -   PhCursorDef_t* internal_cursor=NULL;
  14.709 +    PhCursorDef_t *internal_cursor = NULL;
  14.710  
  14.711 -   if (cursor!=NULL)
  14.712 -   {
  14.713 -      internal_cursor=(PhCursorDef_t*)cursor->driverdata;
  14.714 -      if (internal_cursor!=NULL)
  14.715 -      {
  14.716 -         SDL_free(internal_cursor);
  14.717 -         cursor->driverdata=NULL;
  14.718 -      }
  14.719 -   }
  14.720 +    if (cursor != NULL) {
  14.721 +        internal_cursor = (PhCursorDef_t *) cursor->driverdata;
  14.722 +        if (internal_cursor != NULL) {
  14.723 +            SDL_free(internal_cursor);
  14.724 +            cursor->driverdata = NULL;
  14.725 +        }
  14.726 +    }
  14.727  }
  14.728  
  14.729 -void photon_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y)
  14.730 +void
  14.731 +photon_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y)
  14.732  {
  14.733 -   SDL_VideoDisplay* display;