Date: Mon, 23 Mar 2009 09:17:24 +0200
authorSam Lantinga <slouken@libsdl.org>
Tue, 24 Mar 2009 10:33:12 +0000
changeset 309982e60908fab1
parent 3098 5f372cef955d
child 3100 7dc982143c06
Date: Mon, 23 Mar 2009 09:17:24 +0200
From: "Mike Gorchak"
Subject: New QNX patches

Please apply patch qnx4.diff, which is attached. What has been done:
1)Added back OpenGL ES renderer for QNX target. Added few corrections to
OpenGL ES renderer to let it work under QNX. OpenGL ES renderer do not
support textures under QNX, so I think some additional work must be done.
2) Added GL_OES_query_matrix extension to SDL_opengles.h header file, which
required by OpenGL ES 1.1 specification.
3) Added attribute clearing at the entrance of function
SDL_GL_GetAttribure(). Added error checking into the function
SDL_GL_GetAttribure(), because some attributes can't be obtained in OpenGL
ES 1.0.
4) Porting testdyngles to OpenGL ES 1.0 (1.1 has glColor4ub() and
glColor4f() functions, but 1.0 has glColor4f() only).
5) Added error checking after obtaining attributes using
SDL_GL_GetAttribute() function to the testgl2 and testgles.
6) Small correction to testmultiaudio with printing errors.
7) Added software and accelerated OpenGL ES 1.0 support into the QNX GF
driver.

Please remove ./src/audio/nto directory - it will not be used anymore.
Please create ./src/audio/qsa directory and add content of the archive
qsa.tar.gz into this directory. I rewrote some sound code, added support for
multiple audio cards, enumeration, etc. Added initial support for capture.

As far as I can understand SDL 1.3 is not supporting audio capture right now
? Sam, Am I right ? Or audio capture must be supported through the
PlayDevice routine ?

And last, please put file SDL_gf_opengles.c to the ./src/video/qnxgf
directory. It is OpenGL ES 1.1 emulation layer for some functions, which are
not supported by OpenGL ES 1.0.
README.QNX
configure.in
include/SDL_config.h.in
include/SDL_opengles.h
src/audio/SDL_audio.c
src/audio/nto/SDL_nto_audio.c
src/audio/nto/SDL_nto_audio.h
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/qnxgf/SDL_gf_opengles.c
src/video/qnxgf/SDL_gf_render.c
src/video/qnxgf/SDL_qnxgf.c
src/video/qnxgf/SDL_qnxgf.h
test/testdyngles.c
test/testgl2.c
test/testgles.c
test/testmultiaudio.c
     1.1 --- a/README.QNX	Mon Mar 23 05:37:45 2009 +0000
     1.2 +++ b/README.QNX	Tue Mar 24 10:33:12 2009 +0000
     1.3 @@ -1,7 +1,38 @@
     1.4  README.QNX by Mike Gorchak <mike@malva.ua>, <lestat@i.com.ua>
     1.5 -Last changed at 10 Mar 2009.
     1.6 +Last changed at 22 Mar 2009.
     1.7  
     1.8 -QNX Photon and GF drivers are under construction. Please be patient.
     1.9 +QNX Photon and GF drivers are being constructed.
    1.10 +QNX QSA (QNX Sound Architecture) driver is ready.
    1.11 +QNX CDROM driver is ready.
    1.12 +QNX HID input driver is being constructed.
    1.13 +
    1.14 +----------------------
    1.15 + -- SDL QSA driver --
    1.16 +----------------------
    1.17 +
    1.18 +   Due to QNX Sound Architecture limitations software could  not  determine
    1.19 +what playback channels are designed for, so some casus can be. For example,
    1.20 +output after testmultiaudio test utility execution:
    1.21 +
    1.22 +Using audio driver: qsa
    1.23 +playing on device #0: ('Vortex 8820 @ fb000000 d0')...done.
    1.24 +playing on device #1: ('Vortex 8820 @ fb000000 d1')...done.
    1.25 +playing on device #2: ('i8x0 @ d800 d0')...done.
    1.26 +playing on device #3: ('i8x0 @ d800 d1')...done.
    1.27 +playing on all devices...
    1.28 +Open device 3 failed: QSA: snd_pcm_channel_params failed: Invalid argument
    1.29 +
    1.30 +If  speakers  are  connected  to  both  audio  cards: Vortex 8820 and Intel
    1.31 +Integrated Audio we can hear sound playback on device #0 and devices #2, #3
    1.32 +only. Device #1 is an unknown PCM channel which does not produce any sound.
    1.33 +
    1.34 +As for error during device #3 opening, it's caused  by QSA  software  mixer
    1.35 +channel, because  it can't open real hardware device #2, since it's already
    1.36 +opened by SDL.
    1.37 +
    1.38 +After simultaneous sound playback  on  all  devices  utility testmultiaudio
    1.39 +stays running waiting for  sound playback  finish  on  device #1,  which is
    1.40 +locked up due to some Aureal Vortex 8820 driver limitations.
    1.41  
    1.42  ---------------------
    1.43   -- SDL GF driver --
    1.44 @@ -15,43 +46,61 @@
    1.45  
    1.46  0. Introduction.
    1.47  
    1.48 -   SDL GF driver is a layer between SDL and QNX Graphics Framework (GF). Hardware
    1.49 -accelerated features which SDL could support depends on real hardware capabilities.
    1.50 +   SDL GF driver is a layer between  SDL  and  QNX Graphics Framework (GF).
    1.51 +SDL GF driver also supports OpenGL ES  through the  QNX Graphics Framework.
    1.52 +Hardware accelerated features which SDL can support depend on real hardware
    1.53 +capabilities.
    1.54  
    1.55  1. Environment variables which GF driver supports.
    1.56  
    1.57 -   GF driver supports the following environment variables for QNX GF specific
    1.58 -customization options:
    1.59 -   a) SDL_VIDEO_GF_REFRESH_RATE - refresh rate of video output in Hz. Without
    1.60 -      this environment variable declaration SDL controls refresh rate of your
    1.61 -      display. If this enironment variable is set to 0, SDL will control refresh
    1.62 -      rate of display, otherwise value of SDL_VIDEO_GF_REFRESH_RATE is used for
    1.63 -      all screen resolutions as refresh rate. This example will set 60Hz refresh
    1.64 -      rate as refresh rate for all graphics modes:
    1.65 +   GF  driver  supports  the  following  environment  variables for  QNX GF
    1.66 +specific customization options:
    1.67 +   a) SDL_VIDEO_GF_REFRESH_RATE - refresh  rate  of  video  output  in  Hz.
    1.68 +      Without this environment variable declaration  SDL  controls  refresh
    1.69 +      rate of your display.  If this enironment  variable is set  to 0, SDL
    1.70 +      will control  refresh  rate  of  display,  otherwise  value  of  flag
    1.71 +      SDL_VIDEO_GF_REFRESH_RATE  is  used  for  all  screen  resolutions as
    1.72 +      refresh rate. This example will set 60Hz refresh rate as refresh rate
    1.73 +      for all graphics modes:
    1.74  
    1.75        export SDL_VIDEO_GF_REFRESH_RATE=60
    1.76  
    1.77  2. Custom video modes.
    1.78  
    1.79 -   Since most QNX graphics drivers supports GENERIC video modes, i.e. you could
    1.80 -specify any horizontal and vertical resolution and any refresh rate, SDL GF
    1.81 -driver uses its own fullscreen modes list, which could be incomplete. You could
    1.82 -add any custom video mode, which your QNX graphics driver supports by editing
    1.83 -file ./src/video/qnxgf/SDL_qnxgf.c. Custom graphics mode definition looks like
    1.84 +   Since most QNX graphics drivers support GENERIC  video  modes, i.e.  you
    1.85 +can specify any horizontal and vertical resolution and  any  refresh  rate,
    1.86 +SDL GF driver uses its own fullscreen modes list, which can be  incomplete.
    1.87 +You can add any custom video mode, which your QNX graphics driver  supports
    1.88 +by  editing  file  ./src/video/qnxgf/SDL_qnxgf.c.   Custom   graphics  mode
    1.89 +definition looks like this:
    1.90  
    1.91 -   {0, 1024, 640, 60, NULL},   /* 1024x640 mode is 60Hz only               */
    1.92 +   {0, 1024, 640, 60, NULL},   /* 1024x640 mode is 60Hz only             */
    1.93  
    1.94 -You must specify horizontal resolution as second parameter, vertical resolution
    1.95 -as third parameter and refresh rate as fourth parameter. Please leave first and
    1.96 -last parameters as 0 and NULL. Then please send me your changes to e-mail address
    1.97 -which is specified in the header of this document.
    1.98 +You must specify horizontal resolution as  the  second  parameter, vertical
    1.99 +resolution as the third one and  refresh  rate  as  the  fourth  parameter.
   1.100 +Please leave the first and the last parameters as 0 and NULL.  Then send me
   1.101 +your changes to e-mail address which is specified in  the  header  of  this
   1.102 +document.
   1.103  
   1.104  3. Limitations.
   1.105  
   1.106     There are few limitations while using SDL GF driver:
   1.107  
   1.108 -   a) Since GF driver supports fullscreen modes only, when you are not specifing
   1.109 -SDL_WINDOW_FULLSCREEN flag, an SDL GF driver will try to find the fullscreen
   1.110 -graphics mode which corresponds to SDL window size. Refresh rate will be the
   1.111 -lowest available, if SDL_VIDEO_GF_REFRESH_RATE environment variable is not set.
   1.112 +   a) Since  GF   driver   supports   fullscreen  modes  only,   when  flag
   1.113 +SDL_WINDOW_FULLSCREEN is not specified, SDL GF driver will try to find  the
   1.114 +fullscreen graphics mode which corresponds to SDL window size. Refresh rate
   1.115 +will be the  lowest  available,  if  SDL_VIDEO_GF_REFRESH_RATE  environment
   1.116 +variable is not set.
   1.117 +   b) As confirmed by QSSL none of existing video  drivers  has  support of
   1.118 +doublescan low-resolution video modes.  So  modes  below  640x480  are  not
   1.119 +supported. If your video driver supports low-resolution video modes, please
   1.120 +add SDL_GF_LOWRESOLUTION flag to the gf_devicename array in the SDL_qnxgf.c
   1.121 +source file.
   1.122  
   1.123 +-------------------------
   1.124 + -- SDL Photon driver --
   1.125 +-------------------------
   1.126 +
   1.127 +----------------------------
   1.128 + -- SDL HID input driver --
   1.129 +----------------------------
     2.1 --- a/configure.in	Mon Mar 23 05:37:45 2009 +0000
     2.2 +++ b/configure.in	Tue Mar 24 10:33:12 2009 +0000
     2.3 @@ -1705,6 +1705,7 @@
     2.4          AC_MSG_RESULT($video_opengl)
     2.5          if test x$video_opengl = xyes; then
     2.6              AC_DEFINE(SDL_VIDEO_OPENGL_ES)
     2.7 +            AC_DEFINE(SDL_VIDEO_RENDER_OGL_ES)
     2.8              EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lGLES_CM"
     2.9          else
    2.10              AC_MSG_CHECKING(for QNX OpenGL ES (CL) support)
    2.11 @@ -1719,7 +1720,8 @@
    2.12              AC_MSG_RESULT($video_opengl)
    2.13              if test x$video_opengl = xyes; then
    2.14                  AC_DEFINE(SDL_VIDEO_OPENGL_ES)
    2.15 -                EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lGLES_CL"
    2.16 +                AC_DEFINE(SDL_VIDEO_RENDER_OGL_ES)
    2.17 +                EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lGLES_CLS"
    2.18              fi
    2.19          fi
    2.20      fi
    2.21 @@ -2501,8 +2503,8 @@
    2.22  
    2.23          # Set up files for the audio library
    2.24          if test x$enable_audio = xyes; then
    2.25 -            AC_DEFINE(SDL_AUDIO_DRIVER_QNXNTO)
    2.26 -            SOURCES="$SOURCES $srcdir/src/audio/nto/*.c"
    2.27 +            AC_DEFINE(SDL_AUDIO_DRIVER_QSA)
    2.28 +            SOURCES="$SOURCES $srcdir/src/audio/qsa/*.c"
    2.29              EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lasound"
    2.30              have_audio=yes
    2.31          fi
     3.1 --- a/include/SDL_config.h.in	Mon Mar 23 05:37:45 2009 +0000
     3.2 +++ b/include/SDL_config.h.in	Tue Mar 24 10:33:12 2009 +0000
     3.3 @@ -193,7 +193,7 @@
     3.4  #undef SDL_AUDIO_DRIVER_OSS
     3.5  #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H
     3.6  #undef SDL_AUDIO_DRIVER_PAUDIO
     3.7 -#undef SDL_AUDIO_DRIVER_QNXNTO
     3.8 +#undef SDL_AUDIO_DRIVER_QSA
     3.9  #undef SDL_AUDIO_DRIVER_SNDMGR
    3.10  #undef SDL_AUDIO_DRIVER_SUNAUDIO
    3.11  #undef SDL_AUDIO_DRIVER_WINWAVEOUT
     4.1 --- a/include/SDL_opengles.h	Mon Mar 23 05:37:45 2009 +0000
     4.2 +++ b/include/SDL_opengles.h	Tue Mar 24 10:33:12 2009 +0000
     4.3 @@ -962,6 +962,12 @@
     4.4                                                    const GLvoid * pointer);
     4.5  #endif
     4.6  
     4.7 +/* GL_OES_query_matrix */
     4.8 +#ifndef GL_OES_query_matrix
     4.9 +#define GL_OES_query_matrix 1
    4.10 +    GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16]);
    4.11 +#endif /* GL_OES_query_matrix */
    4.12 +
    4.13  /* GL_OES_point_sprite */
    4.14  #ifndef GL_OES_point_sprite
    4.15  #define GL_OES_point_sprite 1
     5.1 --- a/src/audio/SDL_audio.c	Mon Mar 23 05:37:45 2009 +0000
     5.2 +++ b/src/audio/SDL_audio.c	Tue Mar 24 10:33:12 2009 +0000
     5.3 @@ -49,7 +49,7 @@
     5.4  extern AudioBootStrap DMA_bootstrap;
     5.5  extern AudioBootStrap ALSA_bootstrap;
     5.6  extern AudioBootStrap PULSEAUDIO_bootstrap;
     5.7 -extern AudioBootStrap QNXNTOAUDIO_bootstrap;
     5.8 +extern AudioBootStrap QSAAUDIO_bootstrap;
     5.9  extern AudioBootStrap SUNAUDIO_bootstrap;
    5.10  extern AudioBootStrap DMEDIA_bootstrap;
    5.11  extern AudioBootStrap ARTS_bootstrap;
    5.12 @@ -91,8 +91,8 @@
    5.13      &DSP_bootstrap,
    5.14      &DMA_bootstrap,
    5.15  #endif
    5.16 -#if SDL_AUDIO_DRIVER_QNXNTO
    5.17 -    &QNXNTOAUDIO_bootstrap,
    5.18 +#if SDL_AUDIO_DRIVER_QSA
    5.19 +    &QSAAUDIO_bootstrap,
    5.20  #endif
    5.21  #if SDL_AUDIO_DRIVER_SUNAUDIO
    5.22      &SUNAUDIO_bootstrap,
     6.1 --- a/src/audio/nto/SDL_nto_audio.c	Mon Mar 23 05:37:45 2009 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,467 +0,0 @@
     6.4 -/*
     6.5 -    SDL - Simple DirectMedia Layer
     6.6 -    Copyright (C) 1997-2009 Sam Lantinga
     6.7 -
     6.8 -    This library is free software; you can redistribute it and/or
     6.9 -    modify it under the terms of the GNU Library General Public
    6.10 -    License as published by the Free Software Foundation; either
    6.11 -    version 2 of the License, or (at your option) any later version.
    6.12 -
    6.13 -    This library is distributed in the hope that it will be useful,
    6.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 -    Library General Public License for more details.
    6.17 -
    6.18 -    You should have received a copy of the GNU Library General Public
    6.19 -    License along with this library; if not, write to the Free
    6.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.21 -
    6.22 -    Sam Lantinga
    6.23 -    slouken@libsdl.org
    6.24 -*/
    6.25 -#include "SDL_config.h"
    6.26 -
    6.27 -#include <errno.h>
    6.28 -#include <unistd.h>
    6.29 -#include <fcntl.h>
    6.30 -#include <signal.h>
    6.31 -#include <sys/types.h>
    6.32 -#include <sys/time.h>
    6.33 -#include <sched.h>
    6.34 -#include <sys/select.h>
    6.35 -#include <sys/neutrino.h>
    6.36 -#include <sys/asoundlib.h>
    6.37 -
    6.38 -#include "SDL_timer.h"
    6.39 -#include "SDL_audio.h"
    6.40 -#include "../SDL_audiomem.h"
    6.41 -#include "../SDL_audio_c.h"
    6.42 -#include "SDL_nto_audio.h"
    6.43 -
    6.44 -/* The tag name used by NTO audio */
    6.45 -#define DRIVER_NAME "qsa-nto"
    6.46 -
    6.47 -/* default channel communication parameters */
    6.48 -#define DEFAULT_CPARAMS_RATE 22050
    6.49 -#define DEFAULT_CPARAMS_VOICES 1
    6.50 -/* FIXME: need to add in the near future flexible logic with frag_size and frags count */
    6.51 -#define DEFAULT_CPARAMS_FRAG_SIZE 4096
    6.52 -#define DEFAULT_CPARAMS_FRAGS_MIN 1
    6.53 -#define DEFAULT_CPARAMS_FRAGS_MAX 1
    6.54 -
    6.55 -/* Open the audio device for playback, and don't block if busy */
    6.56 -#define OPEN_FLAGS SND_PCM_OPEN_PLAYBACK
    6.57 -
    6.58 -#define QSA_NO_WORKAROUNDS  0x00000000
    6.59 -#define QSA_MMAP_WORKAROUND 0x00000001
    6.60 -
    6.61 -struct BuggyCards
    6.62 -{
    6.63 -    char *cardname;
    6.64 -    unsigned long bugtype;
    6.65 -};
    6.66 -
    6.67 -#define QSA_WA_CARDS 3
    6.68 -
    6.69 -struct BuggyCards buggycards[QSA_WA_CARDS] = {
    6.70 -    {"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
    6.71 -    {"Vortex 8820", QSA_MMAP_WORKAROUND},
    6.72 -    {"Vortex 8830", QSA_MMAP_WORKAROUND},
    6.73 -};
    6.74 -
    6.75 -
    6.76 -static inline void
    6.77 -NTO_SetError(const char *fn, int rval)
    6.78 -{
    6.79 -    SDL_SetError("NTO: %s failed: %s", fn, snd_strerror(rval));
    6.80 -}
    6.81 -
    6.82 -
    6.83 -/* card names check to apply the workarounds */
    6.84 -static int
    6.85 -NTO_CheckBuggyCards(_THIS, unsigned long checkfor)
    6.86 -{
    6.87 -    char scardname[33];
    6.88 -    int it;
    6.89 -
    6.90 -    if (snd_card_get_name(this->hidden->cardno, scardname, 32) < 0) {
    6.91 -        return 0;
    6.92 -    }
    6.93 -
    6.94 -    for (it = 0; it < QSA_WA_CARDS; it++) {
    6.95 -        if (SDL_strcmp(buggycards[it].cardname, scardname) == 0) {
    6.96 -            if (buggycards[it].bugtype == checkfor) {
    6.97 -                return 1;
    6.98 -            }
    6.99 -        }
   6.100 -    }
   6.101 -
   6.102 -    return 0;
   6.103 -}
   6.104 -
   6.105 -static void
   6.106 -NTO_ThreadInit(_THIS)
   6.107 -{
   6.108 -    struct sched_param param;
   6.109 -    int status = SchedGet(0, 0, &param);
   6.110 -
   6.111 -    /* increasing default 10 priority to 25 to avoid jerky sound */
   6.112 -    param.sched_priority = param.sched_curpriority + 15;
   6.113 -    status = SchedSet(0, 0, SCHED_NOCHANGE, &param);
   6.114 -}
   6.115 -
   6.116 -/* PCM transfer channel parameters initialize function */
   6.117 -static void
   6.118 -NTO_InitAudioParams(snd_pcm_channel_params_t * cpars)
   6.119 -{
   6.120 -    SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
   6.121 -
   6.122 -    cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
   6.123 -    cpars->mode = SND_PCM_MODE_BLOCK;
   6.124 -    cpars->start_mode = SND_PCM_START_DATA;
   6.125 -    cpars->stop_mode = SND_PCM_STOP_STOP;
   6.126 -    cpars->format.format = SND_PCM_SFMT_S16_LE;
   6.127 -    cpars->format.interleave = 1;
   6.128 -    cpars->format.rate = DEFAULT_CPARAMS_RATE;
   6.129 -    cpars->format.voices = DEFAULT_CPARAMS_VOICES;
   6.130 -    cpars->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
   6.131 -    cpars->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
   6.132 -    cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
   6.133 -}
   6.134 -
   6.135 -
   6.136 -/* This function waits until it is possible to write a full sound buffer */
   6.137 -static void
   6.138 -NTO_WaitDevice(_THIS)
   6.139 -{
   6.140 -    fd_set wfds;
   6.141 -    int selectret;
   6.142 -
   6.143 -    FD_ZERO(&wfds);
   6.144 -    FD_SET(this->hidden->audio_fd, &wfds);
   6.145 -
   6.146 -    do {
   6.147 -        selectret =
   6.148 -            select(this->hidden->audio_fd + 1, NULL, &wfds, NULL, NULL);
   6.149 -        switch (selectret) {
   6.150 -        case -1:
   6.151 -        case 0:
   6.152 -            SDL_SetError("NTO: select() failed: %s\n", strerror(errno));
   6.153 -            return;
   6.154 -        default:
   6.155 -            if (FD_ISSET(this->hidden->audio_fd, &wfds)) {
   6.156 -                return;
   6.157 -            }
   6.158 -            break;
   6.159 -        }
   6.160 -    } while (1);
   6.161 -}
   6.162 -
   6.163 -static void
   6.164 -NTO_PlayDevice(_THIS)
   6.165 -{
   6.166 -    snd_pcm_channel_status_t cstatus;
   6.167 -    int written, rval;
   6.168 -    int towrite;
   6.169 -    void *pcmbuffer;
   6.170 -
   6.171 -    if ((!this->enabled) || (!this->hidden)) {
   6.172 -        return;
   6.173 -    }
   6.174 -
   6.175 -    towrite = this->spec.size;
   6.176 -    pcmbuffer = this->hidden->pcm_buf;
   6.177 -
   6.178 -    /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
   6.179 -    do {
   6.180 -        written = snd_pcm_plugin_write(this->hidden->audio_handle,
   6.181 -                                       pcmbuffer, towrite);
   6.182 -        if (written != towrite) {
   6.183 -            if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
   6.184 -                /* Let a little CPU time go by and try to write again */
   6.185 -                SDL_Delay(1);
   6.186 -                /* if we wrote some data */
   6.187 -                towrite -= written;
   6.188 -                pcmbuffer += written * this->spec.channels;
   6.189 -                continue;
   6.190 -            } else if ((errno == EINVAL) || (errno == EIO)) {
   6.191 -                SDL_memset(&cstatus, 0, sizeof(cstatus));
   6.192 -                cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
   6.193 -                rval = snd_pcm_plugin_status(this->hidden->audio_handle,
   6.194 -                                             &cstatus);
   6.195 -                if (rval < 0) {
   6.196 -                    NTO_SetError("snd_pcm_plugin_status", rval);
   6.197 -                    return;
   6.198 -                }
   6.199 -
   6.200 -                if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) ||
   6.201 -                    (cstatus.status == SND_PCM_STATUS_READY)) {
   6.202 -                    rval = snd_pcm_plugin_prepare(this->hidden->audio_handle,
   6.203 -                                                  SND_PCM_CHANNEL_PLAYBACK);
   6.204 -                    if (rval < 0) {
   6.205 -                        NTO_SetError("snd_pcm_plugin_prepare", rval);
   6.206 -                        return;
   6.207 -                    }
   6.208 -                }
   6.209 -                continue;
   6.210 -            } else {
   6.211 -                return;
   6.212 -            }
   6.213 -        } else {
   6.214 -            /* we wrote all remaining data */
   6.215 -            towrite -= written;
   6.216 -            pcmbuffer += written * this->spec.channels;
   6.217 -        }
   6.218 -    } while ((towrite > 0) && (this->enabled));
   6.219 -
   6.220 -    /* If we couldn't write, assume fatal error for now */
   6.221 -    if (towrite != 0) {
   6.222 -        this->enabled = 0;
   6.223 -    }
   6.224 -}
   6.225 -
   6.226 -static Uint8 *
   6.227 -NTO_GetDeviceBuf(_THIS)
   6.228 -{
   6.229 -    return this->hidden->pcm_buf;
   6.230 -}
   6.231 -
   6.232 -static void
   6.233 -NTO_CloseDevice(_THIS)
   6.234 -{
   6.235 -    if (this->hidden != NULL) {
   6.236 -        if (this->hidden->audio_handle != NULL) {
   6.237 -            snd_pcm_plugin_flush(this->hidden->audio_handle,
   6.238 -                                 SND_PCM_CHANNEL_PLAYBACK);
   6.239 -            snd_pcm_close(this->hidden->audio_handle);
   6.240 -            this->hidden->audio_handle = NULL;
   6.241 -        }
   6.242 -        if (this->hidden->pcm_buf != NULL) {
   6.243 -            SDL_FreeAudioMem(this->hidden->pcm_buf);
   6.244 -            this->hidden->pcm_buf = NULL;
   6.245 -        }
   6.246 -        SDL_free(this->hidden);
   6.247 -        this->hidden = NULL;
   6.248 -    }
   6.249 -}
   6.250 -
   6.251 -static int
   6.252 -NTO_OpenDevice(_THIS, const char *devname, int iscapture)
   6.253 -{
   6.254 -    int rval = 0;
   6.255 -    int format = 0;
   6.256 -    SDL_AudioFormat test_format = 0;
   6.257 -    int found = 0;
   6.258 -    snd_pcm_channel_setup_t csetup;
   6.259 -    snd_pcm_channel_params_t cparams;
   6.260 -
   6.261 -    /* Initialize all variables that we clean on shutdown */
   6.262 -    this->hidden = (struct SDL_PrivateAudioData *)
   6.263 -        SDL_malloc((sizeof *this->hidden));
   6.264 -    if (this->hidden == NULL) {
   6.265 -        SDL_OutOfMemory();
   6.266 -        return 0;
   6.267 -    }
   6.268 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   6.269 -
   6.270 -    /* initialize channel transfer parameters to default */
   6.271 -    NTO_InitAudioParams(&cparams);
   6.272 -
   6.273 -    /* Open the audio device */
   6.274 -    rval = snd_pcm_open_preferred(&this->hidden->audio_handle,
   6.275 -                                  &this->hidden->cardno,
   6.276 -                                  &this->hidden->deviceno, OPEN_FLAGS);
   6.277 -
   6.278 -    if (rval < 0) {
   6.279 -        NTO_CloseDevice(this);
   6.280 -        NTO_SetError("snd_pcm_open", rval);
   6.281 -        return 0;
   6.282 -    }
   6.283 -
   6.284 -    if (!NTO_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) {
   6.285 -        /* enable count status parameter */
   6.286 -        rval = snd_pcm_plugin_set_disable(this->hidden->audio_handle,
   6.287 -                                          PLUGIN_DISABLE_MMAP);
   6.288 -        if (rval < 0) {
   6.289 -            NTO_CloseDevice(this);
   6.290 -            NTO_SetError("snd_pcm_plugin_set_disable", rval);
   6.291 -            return 0;
   6.292 -        }
   6.293 -    }
   6.294 -
   6.295 -    /* Try for a closest match on audio format */
   6.296 -    format = 0;
   6.297 -    /* can't use format as SND_PCM_SFMT_U8 = 0 in nto */
   6.298 -    found = 0;
   6.299 -
   6.300 -    for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;) {
   6.301 -        /* if match found set format to equivalent ALSA format */
   6.302 -        switch (test_format) {
   6.303 -        case AUDIO_U8:
   6.304 -            format = SND_PCM_SFMT_U8;
   6.305 -            found = 1;
   6.306 -            break;
   6.307 -        case AUDIO_S8:
   6.308 -            format = SND_PCM_SFMT_S8;
   6.309 -            found = 1;
   6.310 -            break;
   6.311 -        case AUDIO_S16LSB:
   6.312 -            format = SND_PCM_SFMT_S16_LE;
   6.313 -            found = 1;
   6.314 -            break;
   6.315 -        case AUDIO_S16MSB:
   6.316 -            format = SND_PCM_SFMT_S16_BE;
   6.317 -            found = 1;
   6.318 -            break;
   6.319 -        case AUDIO_U16LSB:
   6.320 -            format = SND_PCM_SFMT_U16_LE;
   6.321 -            found = 1;
   6.322 -            break;
   6.323 -        case AUDIO_U16MSB:
   6.324 -            format = SND_PCM_SFMT_U16_BE;
   6.325 -            found = 1;
   6.326 -            break;
   6.327 -        case AUDIO_S32LSB:
   6.328 -            format = SND_PCM_SFMT_S32_LE;
   6.329 -            found = 1;
   6.330 -            break;
   6.331 -        case AUDIO_S32MSB:
   6.332 -            format = SND_PCM_SFMT_S32_BE;
   6.333 -            found = 1;
   6.334 -            break;
   6.335 -        case AUDIO_F32LSB:
   6.336 -            format = SND_PCM_SFMT_FLOAT_LE;
   6.337 -            found = 1;
   6.338 -            break;
   6.339 -        case AUDIO_F32MSB:
   6.340 -            format = SND_PCM_SFMT_FLOAT_BE;
   6.341 -            found = 1;
   6.342 -            break;
   6.343 -        default:
   6.344 -            break;
   6.345 -        }
   6.346 -
   6.347 -        if (!found) {
   6.348 -            test_format = SDL_NextAudioFormat();
   6.349 -        }
   6.350 -    }
   6.351 -
   6.352 -    /* assumes test_format not 0 on success */
   6.353 -    if (test_format == 0) {
   6.354 -        NTO_CloseDevice(this);
   6.355 -        SDL_SetError("NTO: Couldn't find any hardware audio formats");
   6.356 -        return 0;
   6.357 -    }
   6.358 -
   6.359 -    this->spec.format = test_format;
   6.360 -
   6.361 -    /* Set the audio format */
   6.362 -    cparams.format.format = format;
   6.363 -
   6.364 -    /* Set mono or stereo audio (currently only two channels supported) */
   6.365 -    cparams.format.voices = this->spec.channels;
   6.366 -
   6.367 -    /* Set rate */
   6.368 -    cparams.format.rate = this->spec.freq;
   6.369 -
   6.370 -    /* Setup the transfer parameters according to cparams */
   6.371 -    rval = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
   6.372 -    if (rval < 0) {
   6.373 -        NTO_CloseDevice(this);
   6.374 -        NTO_SetError("snd_pcm_channel_params", rval);
   6.375 -        return 0;
   6.376 -    }
   6.377 -
   6.378 -    /* Make sure channel is setup right one last time */
   6.379 -    SDL_memset(&csetup, '\0', sizeof(csetup));
   6.380 -    csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
   6.381 -    if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
   6.382 -        NTO_CloseDevice(this);
   6.383 -        SDL_SetError("NTO: Unable to setup playback channel\n");
   6.384 -        return 0;
   6.385 -    }
   6.386 -
   6.387 -    /* Calculate the final parameters for this audio specification */
   6.388 -    SDL_CalculateAudioSpec(&this->spec);
   6.389 -
   6.390 -    this->hidden->pcm_len = this->spec.size;
   6.391 -
   6.392 -    if (this->hidden->pcm_len == 0) {
   6.393 -        this->hidden->pcm_len =
   6.394 -            csetup.buf.block.frag_size * this->spec.channels *
   6.395 -            (snd_pcm_format_width(format) / 8);
   6.396 -    }
   6.397 -
   6.398 -    /*
   6.399 -     * Allocate memory to the audio buffer and initialize with silence
   6.400 -     *  (Note that buffer size must be a multiple of fragment size, so find
   6.401 -     *  closest multiple)
   6.402 -     */
   6.403 -    this->hidden->pcm_buf =
   6.404 -        (Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len);
   6.405 -    if (this->hidden->pcm_buf == NULL) {
   6.406 -        NTO_CloseDevice(this);
   6.407 -        SDL_OutOfMemory();
   6.408 -        return 0;
   6.409 -    }
   6.410 -    SDL_memset(this->hidden->pcm_buf, this->spec.silence,
   6.411 -               this->hidden->pcm_len);
   6.412 -
   6.413 -    /* get the file descriptor */
   6.414 -    this->hidden->audio_fd =
   6.415 -        snd_pcm_file_descriptor(this->hidden->audio_handle,
   6.416 -                                SND_PCM_CHANNEL_PLAYBACK);
   6.417 -    if (this->hidden->audio_fd < 0) {
   6.418 -        NTO_CloseDevice(this);
   6.419 -        NTO_SetError("snd_pcm_file_descriptor", rval);
   6.420 -        return 0;
   6.421 -    }
   6.422 -
   6.423 -    /* Trigger audio playback */
   6.424 -    rval = snd_pcm_plugin_prepare(this->hidden->audio_handle,
   6.425 -                                  SND_PCM_CHANNEL_PLAYBACK);
   6.426 -    if (rval < 0) {
   6.427 -        NTO_CloseDevice(this);
   6.428 -        NTO_SetError("snd_pcm_plugin_prepare", rval);
   6.429 -        return 0;
   6.430 -    }
   6.431 -
   6.432 -    /* We're really ready to rock and roll. :-) */
   6.433 -    return 1;
   6.434 -}
   6.435 -
   6.436 -
   6.437 -static int
   6.438 -NTO_Init(SDL_AudioDriverImpl * impl)
   6.439 -{
   6.440 -    /* !!! FIXME: not right for device enum? */
   6.441 -    /*  See if we can open a nonblocking channel. */
   6.442 -    snd_pcm_t *handle = NULL;
   6.443 -    int rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS);
   6.444 -    if (rval < 0) {
   6.445 -        SDL_SetError("NTO: couldn't open preferred audio device");
   6.446 -        return 0;
   6.447 -    }
   6.448 -    if ((rval = snd_pcm_close(handle)) < 0) {
   6.449 -        SDL_SetError("NTO: couldn't close test audio device");
   6.450 -        return 0;
   6.451 -    }
   6.452 -
   6.453 -    /* Set the function pointers */
   6.454 -    impl->OpenDevice = NTO_OpenDevice;
   6.455 -    impl->ThreadInit = NTO_ThreadInit;
   6.456 -    impl->WaitDevice = NTO_WaitDevice;
   6.457 -    impl->PlayDevice = NTO_PlayDevice;
   6.458 -    impl->GetDeviceBuf = NTO_GetDeviceBuf;
   6.459 -    impl->CloseDevice = NTO_CloseDevice;
   6.460 -    impl->OnlyHasDefaultOutputDevice = 1;       /* !!! FIXME: add device enum! */
   6.461 -
   6.462 -    /* !!! FIXME: device enum might make this 1. */
   6.463 -    return 2;                   /* 2 == definitely has an audio device. */
   6.464 -}
   6.465 -
   6.466 -AudioBootStrap QNXNTOAUDIO_bootstrap = {
   6.467 -    DRIVER_NAME, "QNX6 QSA-NTO Audio", NTO_Init, 0
   6.468 -};
   6.469 -
   6.470 -/* vi: set ts=4 sw=4 expandtab: */
     7.1 --- a/src/audio/nto/SDL_nto_audio.h	Mon Mar 23 05:37:45 2009 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,53 +0,0 @@
     7.4 -/*
     7.5 -    SDL - Simple DirectMedia Layer
     7.6 -    Copyright (C) 1997-2009 Sam Lantinga
     7.7 -
     7.8 -    This library is free software; you can redistribute it and/or
     7.9 -    modify it under the terms of the GNU Library General Public
    7.10 -    License as published by the Free Software Foundation; either
    7.11 -    version 2 of the License, or (at your option) any later version.
    7.12 -
    7.13 -    This library is distributed in the hope that it will be useful,
    7.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 -    Library General Public License for more details.
    7.17 -
    7.18 -    You should have received a copy of the GNU Library General Public
    7.19 -    License along with this library; if not, write to the Free
    7.20 -    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.21 -
    7.22 -    Sam Lantinga
    7.23 -    slouken@libsdl.org
    7.24 -*/
    7.25 -#include "SDL_config.h"
    7.26 -
    7.27 -#ifndef __SDL_NTO_AUDIO_H__
    7.28 -#define __SDL_NTO_AUDIO_H__
    7.29 -
    7.30 -#include <sys/asoundlib.h>
    7.31 -
    7.32 -#include "../SDL_sysaudio.h"
    7.33 -
    7.34 -/* Hidden "this" pointer for the audio functions */
    7.35 -#define _THIS	SDL_AudioDevice *this
    7.36 -
    7.37 -struct SDL_PrivateAudioData
    7.38 -{
    7.39 -    /* The audio device handle */
    7.40 -    int cardno;
    7.41 -    int deviceno;
    7.42 -    snd_pcm_t *audio_handle;
    7.43 -
    7.44 -    /* The audio file descriptor */
    7.45 -    int audio_fd;
    7.46 -
    7.47 -    /* The parent process id, to detect when application quits */
    7.48 -    pid_t parent;
    7.49 -
    7.50 -    /* Raw mixing buffer */
    7.51 -    Uint8 *pcm_buf;
    7.52 -    Uint32 pcm_len;
    7.53 -};
    7.54 -
    7.55 -#endif /* __SDL_NTO_AUDIO_H__ */
    7.56 -/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/audio/qsa/SDL_qsa_audio.c	Tue Mar 24 10:33:12 2009 +0000
     8.3 @@ -0,0 +1,945 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997-2009 Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Library General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Library General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Library General Public
    8.19 +    License along with this library; if not, write to the Free
    8.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +
    8.25 +    QNX Sound Architecture (QSA) SDL driver
    8.26 +    Copyright (C) 2009 Mike Gorchak
    8.27 +    (mike@malva.ua, lestat@i.com.ua)
    8.28 +*/
    8.29 +
    8.30 +#include "SDL_config.h"
    8.31 +
    8.32 +#include <errno.h>
    8.33 +#include <unistd.h>
    8.34 +#include <fcntl.h>
    8.35 +#include <signal.h>
    8.36 +#include <sys/types.h>
    8.37 +#include <sys/time.h>
    8.38 +#include <sched.h>
    8.39 +#include <sys/select.h>
    8.40 +#include <sys/neutrino.h>
    8.41 +#include <sys/asoundlib.h>
    8.42 +
    8.43 +#include "SDL_timer.h"
    8.44 +#include "SDL_audio.h"
    8.45 +#include "../SDL_audiomem.h"
    8.46 +#include "../SDL_audio_c.h"
    8.47 +#include "SDL_qsa_audio.h"
    8.48 +
    8.49 +/* The tag name used by QSA audio framework */
    8.50 +#define DRIVER_NAME "qsa"
    8.51 +
    8.52 +/* default channel communication parameters */
    8.53 +#define DEFAULT_CPARAMS_RATE   44100
    8.54 +#define DEFAULT_CPARAMS_VOICES 1
    8.55 +
    8.56 +#define DEFAULT_CPARAMS_FRAG_SIZE 4096
    8.57 +#define DEFAULT_CPARAMS_FRAGS_MIN 1
    8.58 +#define DEFAULT_CPARAMS_FRAGS_MAX 1
    8.59 +
    8.60 +#define QSA_NO_WORKAROUNDS  0x00000000
    8.61 +#define QSA_MMAP_WORKAROUND 0x00000001
    8.62 +
    8.63 +struct BuggyCards
    8.64 +{
    8.65 +    char* cardname;
    8.66 +    unsigned long bugtype;
    8.67 +};
    8.68 +
    8.69 +#define QSA_WA_CARDS             3
    8.70 +#define QSA_MAX_CARD_NAME_LENGTH 33
    8.71 +
    8.72 +struct BuggyCards buggycards[QSA_WA_CARDS]=
    8.73 +{
    8.74 +   {"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
    8.75 +   {"Vortex 8820", QSA_MMAP_WORKAROUND},
    8.76 +   {"Vortex 8830", QSA_MMAP_WORKAROUND},
    8.77 +};
    8.78 +
    8.79 +/* List of found devices */
    8.80 +#define QSA_MAX_DEVICES       32
    8.81 +#define QSA_MAX_NAME_LENGTH   81+16 /* Hardcoded in QSA, can't be changed */
    8.82 +
    8.83 +typedef struct _QSA_Device
    8.84 +{
    8.85 +   char  name[QSA_MAX_NAME_LENGTH];   /* Long audio device name for SDL  */
    8.86 +   int   cardno;
    8.87 +   int   deviceno;
    8.88 +} QSA_Device;
    8.89 +
    8.90 +QSA_Device qsa_playback_device[QSA_MAX_DEVICES];
    8.91 +uint32_t   qsa_playback_devices;
    8.92 +
    8.93 +QSA_Device qsa_capture_device[QSA_MAX_DEVICES];
    8.94 +uint32_t   qsa_capture_devices;
    8.95 +
    8.96 +static inline void QSA_SetError(const char* fn, int status)
    8.97 +{
    8.98 +   SDL_SetError("QSA: %s failed: %s", fn, snd_strerror(status));
    8.99 +}
   8.100 +
   8.101 +/* card names check to apply the workarounds */
   8.102 +static int QSA_CheckBuggyCards(_THIS, unsigned long checkfor)
   8.103 +{
   8.104 +   char scardname[QSA_MAX_CARD_NAME_LENGTH];
   8.105 +   int it;
   8.106 +
   8.107 +   if (snd_card_get_name(this->hidden->cardno, scardname, QSA_MAX_CARD_NAME_LENGTH-1)<0)
   8.108 +   {
   8.109 +      return 0;
   8.110 +   }
   8.111 +
   8.112 +   for (it=0; it<QSA_WA_CARDS; it++)
   8.113 +   {
   8.114 +      if (SDL_strcmp(buggycards[it].cardname, scardname)==0)
   8.115 +      {
   8.116 +         if (buggycards[it].bugtype==checkfor)
   8.117 +         {
   8.118 +            return 1;
   8.119 +         }
   8.120 +      }
   8.121 +   }
   8.122 +
   8.123 +   return 0;
   8.124 +}
   8.125 +
   8.126 +static void QSA_ThreadInit(_THIS)
   8.127 +{
   8.128 +   struct sched_param param;
   8.129 +   int status;
   8.130 +
   8.131 +   /* Increase default 10 priority to 25 to avoid jerky sound */
   8.132 +   status=SchedGet(0, 0, &param);
   8.133 +   param.sched_priority=param.sched_curpriority + 15;
   8.134 +   status=SchedSet(0, 0, SCHED_NOCHANGE, &param);
   8.135 +}
   8.136 +
   8.137 +/* PCM channel parameters initialize function */
   8.138 +static void QSA_InitAudioParams(snd_pcm_channel_params_t* cpars)
   8.139 +{
   8.140 +   SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
   8.141 +
   8.142 +   cpars->channel=SND_PCM_CHANNEL_PLAYBACK;
   8.143 +   cpars->mode=SND_PCM_MODE_BLOCK;
   8.144 +   cpars->start_mode=SND_PCM_START_DATA;
   8.145 +   cpars->stop_mode=SND_PCM_STOP_STOP;
   8.146 +   cpars->format.format=SND_PCM_SFMT_S16_LE;
   8.147 +   cpars->format.interleave=1;
   8.148 +   cpars->format.rate=DEFAULT_CPARAMS_RATE;
   8.149 +   cpars->format.voices=DEFAULT_CPARAMS_VOICES;
   8.150 +   cpars->buf.block.frag_size=DEFAULT_CPARAMS_FRAG_SIZE;
   8.151 +   cpars->buf.block.frags_min=DEFAULT_CPARAMS_FRAGS_MIN;
   8.152 +   cpars->buf.block.frags_max=DEFAULT_CPARAMS_FRAGS_MAX;
   8.153 +}
   8.154 +
   8.155 +/* This function waits until it is possible to write a full sound buffer */
   8.156 +static void QSA_WaitDevice(_THIS)
   8.157 +{
   8.158 +   fd_set wfds;
   8.159 +   fd_set rfds;
   8.160 +   int selectret;
   8.161 +   struct timeval timeout;
   8.162 +
   8.163 +   if (!this->hidden->iscapture)
   8.164 +   {
   8.165 +      FD_ZERO(&wfds);
   8.166 +      FD_SET(this->hidden->audio_fd, &wfds);
   8.167 +   }
   8.168 +   else
   8.169 +   {
   8.170 +      FD_ZERO(&rfds);
   8.171 +      FD_SET(this->hidden->audio_fd, &rfds);
   8.172 +   }
   8.173 +
   8.174 +   do {
   8.175 +      /* Setup timeout for playing one fragment equal to 2 seconds          */
   8.176 +      /* If timeout occured than something wrong with hardware or driver    */
   8.177 +      /* For example, Vortex 8820 audio driver stucks on second DAC because */
   8.178 +      /* it doesn't exist !                                                 */
   8.179 +      timeout.tv_sec=2;
   8.180 +      timeout.tv_usec=0;
   8.181 +      this->hidden->timeout_on_wait=0;
   8.182 +
   8.183 +      if (!this->hidden->iscapture)
   8.184 +      {
   8.185 +         selectret=select(this->hidden->audio_fd+1, NULL, &wfds, NULL, &timeout);
   8.186 +      }
   8.187 +      else
   8.188 +      {
   8.189 +         selectret=select(this->hidden->audio_fd+1, &rfds, NULL, NULL, &timeout);
   8.190 +      }
   8.191 +
   8.192 +      switch(selectret)
   8.193 +      {
   8.194 +         case -1:
   8.195 +              {
   8.196 +                 SDL_SetError("QSA: select() failed: %s\n", strerror(errno));
   8.197 +                 return;
   8.198 +              }
   8.199 +              break;
   8.200 +         case 0:
   8.201 +              {
   8.202 +                 SDL_SetError("QSA: timeout on buffer waiting occured\n");
   8.203 +                 this->hidden->timeout_on_wait=1;
   8.204 +                 return;
   8.205 +              }
   8.206 +              break;
   8.207 +         default:
   8.208 +              {
   8.209 +                 if (!this->hidden->iscapture)
   8.210 +                 {
   8.211 +                    if (FD_ISSET(this->hidden->audio_fd, &wfds))
   8.212 +                    {
   8.213 +                       return;
   8.214 +                    }
   8.215 +                 }
   8.216 +                 else
   8.217 +                 {
   8.218 +                    if (FD_ISSET(this->hidden->audio_fd, &rfds))
   8.219 +                    {
   8.220 +                       return;
   8.221 +                    }
   8.222 +                 }
   8.223 +              }
   8.224 +              break;
   8.225 +      }
   8.226 +   } while (1);
   8.227 +}
   8.228 +
   8.229 +static void QSA_PlayDevice(_THIS)
   8.230 +{
   8.231 +   snd_pcm_channel_status_t cstatus;
   8.232 +   int   written;
   8.233 +   int   status;
   8.234 +   int   towrite;
   8.235 +   void* pcmbuffer;
   8.236 +
   8.237 +   if ((!this->enabled) || (!this->hidden))
   8.238 +   {
   8.239 +      return;
   8.240 +   }
   8.241 +
   8.242 +   towrite = this->spec.size;
   8.243 +   pcmbuffer = this->hidden->pcm_buf;
   8.244 +
   8.245 +   /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
   8.246 +   do {
   8.247 +      written=snd_pcm_plugin_write(this->hidden->audio_handle, pcmbuffer, towrite);
   8.248 +      if (written!=towrite)
   8.249 +      {
   8.250 +         /* Check if samples playback got stuck somewhere in hardware or in */
   8.251 +         /* the audio device driver */
   8.252 +         if ((errno==EAGAIN) && (written==0))
   8.253 +         {
   8.254 +            if (this->hidden->timeout_on_wait!=0)
   8.255 +            {
   8.256 +               SDL_SetError("QSA: buffer playback timeout\n");
   8.257 +               return;
   8.258 +            }
   8.259 +         }
   8.260 +
   8.261 +         /* Check for errors or conditions */
   8.262 +         if ((errno==EAGAIN)||(errno==EWOULDBLOCK))
   8.263 +         {
   8.264 +            /* Let a little CPU time go by and try to write again */
   8.265 +            SDL_Delay(1);
   8.266 +
   8.267 +            /* if we wrote some data */
   8.268 +            towrite-=written;
   8.269 +            pcmbuffer+=written*this->spec.channels;
   8.270 +            continue;
   8.271 +         }
   8.272 +         else
   8.273 +         {
   8.274 +            if ((errno==EINVAL)||(errno==EIO))
   8.275 +            {
   8.276 +               SDL_memset(&cstatus, 0, sizeof(cstatus));
   8.277 +               if (!this->hidden->iscapture)
   8.278 +               {
   8.279 +                  cstatus.channel=SND_PCM_CHANNEL_PLAYBACK;
   8.280 +               }
   8.281 +               else
   8.282 +               {
   8.283 +                  cstatus.channel=SND_PCM_CHANNEL_CAPTURE;
   8.284 +               }
   8.285 +
   8.286 +               status=snd_pcm_plugin_status(this->hidden->audio_handle, &cstatus);
   8.287 +               if (status<0)
   8.288 +               {
   8.289 +                  QSA_SetError("snd_pcm_plugin_status", status);
   8.290 +                  return;
   8.291 +               }
   8.292 +
   8.293 +               if ((cstatus.status==SND_PCM_STATUS_UNDERRUN) ||
   8.294 +                   (cstatus.status==SND_PCM_STATUS_READY))
   8.295 +               {
   8.296 +                  if (!this->hidden->iscapture)
   8.297 +                  {
   8.298 +                     status=snd_pcm_plugin_prepare(this->hidden->audio_handle,
   8.299 +                                                   SND_PCM_CHANNEL_PLAYBACK);
   8.300 +                  }
   8.301 +                  else
   8.302 +                  {
   8.303 +                     status=snd_pcm_plugin_prepare(this->hidden->audio_handle,
   8.304 +                                                   SND_PCM_CHANNEL_CAPTURE);
   8.305 +                  }
   8.306 +                  if (status<0)
   8.307 +                  {
   8.308 +                     QSA_SetError("snd_pcm_plugin_prepare", status);
   8.309 +                     return;
   8.310 +                  }
   8.311 +               }
   8.312 +               continue;
   8.313 +            }
   8.314 +            else
   8.315 +            {
   8.316 +                return;
   8.317 +            }
   8.318 +         }
   8.319 +      }
   8.320 +      else
   8.321 +      {
   8.322 +         /* we wrote all remaining data */
   8.323 +         towrite -= written;
   8.324 +         pcmbuffer += written * this->spec.channels;
   8.325 +      }
   8.326 +   } while ((towrite>0) && (this->enabled));
   8.327 +
   8.328 +   /* If we couldn't write, assume fatal error for now */
   8.329 +   if (towrite!=0)
   8.330 +   {
   8.331 +      this->enabled=0;
   8.332 +   }
   8.333 +}
   8.334 +
   8.335 +static Uint8* QSA_GetDeviceBuf(_THIS)
   8.336 +{
   8.337 +   return this->hidden->pcm_buf;
   8.338 +}
   8.339 +
   8.340 +static void QSA_CloseDevice(_THIS)
   8.341 +{
   8.342 +   if (this->hidden!=NULL)
   8.343 +   {
   8.344 +      if (this->hidden->audio_handle!=NULL)
   8.345 +      {
   8.346 +         if (!this->hidden->iscapture)
   8.347 +         {
   8.348 +            /* Finish playing available samples */
   8.349 +            snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK);
   8.350 +         }
   8.351 +         else
   8.352 +         {
   8.353 +            /* Cancel unread samples during capture */
   8.354 +            snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE);
   8.355 +         }
   8.356 +         snd_pcm_close(this->hidden->audio_handle);
   8.357 +         this->hidden->audio_handle=NULL;
   8.358 +      }
   8.359 +
   8.360 +      if (this->hidden->pcm_buf!=NULL)
   8.361 +      {
   8.362 +         SDL_FreeAudioMem(this->hidden->pcm_buf);
   8.363 +         this->hidden->pcm_buf=NULL;
   8.364 +      }
   8.365 +
   8.366 +      SDL_free(this->hidden);
   8.367 +      this->hidden=NULL;
   8.368 +   }
   8.369 +}
   8.370 +
   8.371 +static int QSA_OpenDevice(_THIS, const char* devname, int iscapture)
   8.372 +{
   8.373 +   int status=0;
   8.374 +   int format=0;
   8.375 +   SDL_AudioFormat test_format=0;
   8.376 +   int found=0;
   8.377 +   snd_pcm_channel_setup_t  csetup;
   8.378 +   snd_pcm_channel_params_t cparams;
   8.379 +
   8.380 +   /* Initialize all variables that we clean on shutdown */
   8.381 +   this->hidden=(struct SDL_PrivateAudioData*)SDL_calloc(1, (sizeof(struct SDL_PrivateAudioData)));
   8.382 +   if (this->hidden==NULL)
   8.383 +   {
   8.384 +      SDL_OutOfMemory();
   8.385 +      return 0;
   8.386 +   }
   8.387 +   SDL_memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
   8.388 +
   8.389 +   /* Initialize channel transfer parameters to default */
   8.390 +   QSA_InitAudioParams(&cparams);
   8.391 +
   8.392 +   /* Initialize channel direction: capture or playback */
   8.393 +   this->hidden->iscapture=iscapture;
   8.394 +
   8.395 +   /* Find deviceid and cardid by device name for playback */
   8.396 +   if ((!this->hidden->iscapture) && (devname!=NULL))
   8.397 +   {
   8.398 +      uint32_t device;
   8.399 +      int32_t  status;
   8.400 +
   8.401 +      /* Search in the playback devices */
   8.402 +      device=0;
   8.403 +      do {
   8.404 +         status=SDL_strcmp(qsa_playback_device[device].name, devname);
   8.405 +         if (status==0)
   8.406 +         {
   8.407 +            /* Found requested device */
   8.408 +            this->hidden->deviceno=qsa_playback_device[device].deviceno;
   8.409 +            this->hidden->cardno=qsa_playback_device[device].cardno;
   8.410 +            break;
   8.411 +         }
   8.412 +         device++;
   8.413 +         if (device>=qsa_playback_devices)
   8.414 +         {
   8.415 +            QSA_CloseDevice(this);
   8.416 +            SDL_SetError("No such playback device");
   8.417 +            return 0;
   8.418 +         }
   8.419 +      } while(1);
   8.420 +   }
   8.421 +
   8.422 +   /* Find deviceid and cardid by device name for capture */
   8.423 +   if ((this->hidden->iscapture) && (devname!=NULL))
   8.424 +   {
   8.425 +      /* Search in the capture devices */
   8.426 +      uint32_t device;
   8.427 +      int32_t  status;
   8.428 +
   8.429 +      /* Searching in the playback devices */
   8.430 +      device=0;
   8.431 +      do {
   8.432 +         status=SDL_strcmp(qsa_capture_device[device].name, devname);
   8.433 +         if (status==0)
   8.434 +         {
   8.435 +            /* Found requested device */
   8.436 +            this->hidden->deviceno=qsa_capture_device[device].deviceno;
   8.437 +            this->hidden->cardno=qsa_capture_device[device].cardno;
   8.438 +            break;
   8.439 +         }
   8.440 +         device++;
   8.441 +         if (device>=qsa_capture_devices)
   8.442 +         {
   8.443 +            QSA_CloseDevice(this);
   8.444 +            SDL_SetError("No such capture device");
   8.445 +            return 0;
   8.446 +         }
   8.447 +      } while(1);
   8.448 +   }
   8.449 +
   8.450 +   /* Check if SDL requested default audio device */
   8.451 +   if (devname==NULL)
   8.452 +   {
   8.453 +      /* Open system default audio device */
   8.454 +      if (!this->hidden->iscapture)
   8.455 +      {
   8.456 +         status=snd_pcm_open_preferred(&this->hidden->audio_handle,
   8.457 +                                       &this->hidden->cardno,
   8.458 +                                       &this->hidden->deviceno, SND_PCM_OPEN_PLAYBACK);
   8.459 +      }
   8.460 +      else
   8.461 +      {
   8.462 +         status=snd_pcm_open_preferred(&this->hidden->audio_handle,
   8.463 +                                       &this->hidden->cardno,
   8.464 +                                       &this->hidden->deviceno, SND_PCM_OPEN_CAPTURE);
   8.465 +      }
   8.466 +   }
   8.467 +   else
   8.468 +   {
   8.469 +      /* Open requested audio device */
   8.470 +      if (!this->hidden->iscapture)
   8.471 +      {
   8.472 +         status=snd_pcm_open(&this->hidden->audio_handle, this->hidden->cardno,
   8.473 +                              this->hidden->deviceno, SND_PCM_OPEN_PLAYBACK);
   8.474 +      }
   8.475 +      else
   8.476 +      {
   8.477 +         status=snd_pcm_open(&this->hidden->audio_handle, this->hidden->cardno,
   8.478 +                              this->hidden->deviceno, SND_PCM_OPEN_CAPTURE);
   8.479 +      }
   8.480 +   }
   8.481 +
   8.482 +   /* Check if requested device is opened */
   8.483 +   if (status<0)
   8.484 +   {
   8.485 +      QSA_CloseDevice(this);
   8.486 +      QSA_SetError("snd_pcm_open", status);
   8.487 +      return 0;
   8.488 +   }
   8.489 +
   8.490 +   if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND))
   8.491 +   {
   8.492 +      /* Disable QSA MMAP plugin for buggy audio drivers */
   8.493 +      status=snd_pcm_plugin_set_disable(this->hidden->audio_handle, PLUGIN_DISABLE_MMAP);
   8.494 +      if (status<0)
   8.495 +      {
   8.496 +         QSA_CloseDevice(this);
   8.497 +         QSA_SetError("snd_pcm_plugin_set_disable", status);
   8.498 +         return 0;
   8.499 +      }
   8.500 +   }
   8.501 +
   8.502 +   /* Try for a closest match on audio format */
   8.503 +   format = 0;
   8.504 +   /* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */
   8.505 +   found = 0;
   8.506 +
   8.507 +   for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;)
   8.508 +   {
   8.509 +      /* if match found set format to equivalent QSA format */
   8.510 +      switch (test_format)
   8.511 +      {
   8.512 +         case AUDIO_U8:
   8.513 +              {
   8.514 +                 format=SND_PCM_SFMT_U8;
   8.515 +                 found=1;
   8.516 +              }
   8.517 +              break;
   8.518 +         case AUDIO_S8:
   8.519 +              {
   8.520 +                 format=SND_PCM_SFMT_S8;
   8.521 +                 found=1;
   8.522 +              }
   8.523 +              break;
   8.524 +         case AUDIO_S16LSB:
   8.525 +              {
   8.526 +                 format=SND_PCM_SFMT_S16_LE;
   8.527 +                 found=1;
   8.528 +              }
   8.529 +              break;
   8.530 +         case AUDIO_S16MSB:
   8.531 +              {
   8.532 +                 format=SND_PCM_SFMT_S16_BE;
   8.533 +                 found=1;
   8.534 +              }
   8.535 +              break;
   8.536 +         case AUDIO_U16LSB:
   8.537 +              {
   8.538 +                 format=SND_PCM_SFMT_U16_LE;
   8.539 +                 found=1;
   8.540 +              }
   8.541 +              break;
   8.542 +         case AUDIO_U16MSB:
   8.543 +              {
   8.544 +                 format=SND_PCM_SFMT_U16_BE;
   8.545 +                 found=1;
   8.546 +              }
   8.547 +              break;
   8.548 +         case AUDIO_S32LSB:
   8.549 +              {
   8.550 +                 format=SND_PCM_SFMT_S32_LE;
   8.551 +                 found=1;
   8.552 +              }
   8.553 +              break;
   8.554 +         case AUDIO_S32MSB:
   8.555 +              {
   8.556 +                 format=SND_PCM_SFMT_S32_BE;
   8.557 +                 found=1;
   8.558 +              }
   8.559 +              break;
   8.560 +         case AUDIO_F32LSB:
   8.561 +              {
   8.562 +                 format=SND_PCM_SFMT_FLOAT_LE;
   8.563 +                 found=1;
   8.564 +              }
   8.565 +              break;
   8.566 +         case AUDIO_F32MSB:
   8.567 +              {
   8.568 +                 format=SND_PCM_SFMT_FLOAT_BE;
   8.569 +                 found=1;
   8.570 +              }
   8.571 +              break;
   8.572 +         default:
   8.573 +              {
   8.574 +                 break;
   8.575 +              }
   8.576 +      }
   8.577 +
   8.578 +      if (!found)
   8.579 +      {
   8.580 +         test_format = SDL_NextAudioFormat();
   8.581 +      }
   8.582 +   }
   8.583 +
   8.584 +   /* assumes test_format not 0 on success */
   8.585 +   if (test_format==0)
   8.586 +   {
   8.587 +      QSA_CloseDevice(this);
   8.588 +      SDL_SetError("QSA: Couldn't find any hardware audio formats");
   8.589 +      return 0;
   8.590 +   }
   8.591 +
   8.592 +   this->spec.format=test_format;
   8.593 +
   8.594 +   /* Set the audio format */
   8.595 +   cparams.format.format=format;
   8.596 +
   8.597 +   /* Set mono/stereo/4ch/6ch/8ch audio */
   8.598 +   cparams.format.voices=this->spec.channels;
   8.599 +
   8.600 +   /* Set rate */
   8.601 +   cparams.format.rate=this->spec.freq;
   8.602 +
   8.603 +   /* Setup the transfer parameters according to cparams */
   8.604 +   status=snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
   8.605 +   if (status<0)
   8.606 +   {
   8.607 +      QSA_CloseDevice(this);
   8.608 +      QSA_SetError("snd_pcm_channel_params", status);
   8.609 +      return 0;
   8.610 +   }
   8.611 +
   8.612 +   /* Make sure channel is setup right one last time */
   8.613 +   SDL_memset(&csetup, '\0', sizeof(csetup));
   8.614 +   if (!this->hidden->iscapture)
   8.615 +   {
   8.616 +      csetup.channel=SND_PCM_CHANNEL_PLAYBACK;
   8.617 +   }
   8.618 +   else
   8.619 +   {
   8.620 +      csetup.channel=SND_PCM_CHANNEL_CAPTURE;
   8.621 +   }
   8.622 +
   8.623 +   /* Setup an audio channel */
   8.624 +   if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0)
   8.625 +   {
   8.626 +      QSA_CloseDevice(this);
   8.627 +      SDL_SetError("QSA: Unable to setup channel\n");
   8.628 +      return 0;
   8.629 +   }
   8.630 +
   8.631 +   /* Calculate the final parameters for this audio specification */
   8.632 +   SDL_CalculateAudioSpec(&this->spec);
   8.633 +
   8.634 +   this->hidden->pcm_len = this->spec.size;
   8.635 +
   8.636 +   if (this->hidden->pcm_len==0)
   8.637 +   {
   8.638 +      this->hidden->pcm_len=csetup.buf.block.frag_size * this->spec.channels *
   8.639 +                           (snd_pcm_format_width(format) / 8);
   8.640 +   }
   8.641 +
   8.642 +   /*
   8.643 +    * Allocate memory to the audio buffer and initialize with silence
   8.644 +    *  (Note that buffer size must be a multiple of fragment size, so find
   8.645 +    *  closest multiple)
   8.646 +    */
   8.647 +   this->hidden->pcm_buf=(Uint8*)SDL_AllocAudioMem(this->hidden->pcm_len);
   8.648 +   if (this->hidden->pcm_buf==NULL)
   8.649 +   {
   8.650 +      QSA_CloseDevice(this);
   8.651 +      SDL_OutOfMemory();
   8.652 +      return 0;
   8.653 +   }
   8.654 +   SDL_memset(this->hidden->pcm_buf, this->spec.silence, this->hidden->pcm_len);
   8.655 +
   8.656 +   /* get the file descriptor */
   8.657 +   if (!this->hidden->iscapture)
   8.658 +   {
   8.659 +      this->hidden->audio_fd=snd_pcm_file_descriptor(this->hidden->audio_handle,
   8.660 +                                                     SND_PCM_CHANNEL_PLAYBACK);
   8.661 +   }
   8.662 +   else
   8.663 +   {
   8.664 +      this->hidden->audio_fd=snd_pcm_file_descriptor(this->hidden->audio_handle,
   8.665 +                                                     SND_PCM_CHANNEL_CAPTURE);
   8.666 +   }
   8.667 +
   8.668 +   if (this->hidden->audio_fd<0)
   8.669 +   {
   8.670 +      QSA_CloseDevice(this);
   8.671 +      QSA_SetError("snd_pcm_file_descriptor", status);
   8.672 +      return 0;
   8.673 +   }
   8.674 +
   8.675 +   /* Prepare an audio channel */
   8.676 +   if (!this->hidden->iscapture)
   8.677 +   {
   8.678 +      /* Prepare audio playback */
   8.679 +      status=snd_pcm_plugin_prepare(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK);
   8.680 +   }
   8.681 +   else
   8.682 +   {
   8.683 +      /* Prepare audio capture */
   8.684 +      status=snd_pcm_plugin_prepare(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE);
   8.685 +   }
   8.686 +
   8.687 +   if (status<0)
   8.688 +   {
   8.689 +      QSA_CloseDevice(this);
   8.690 +      QSA_SetError("snd_pcm_plugin_prepare", status);
   8.691 +      return 0;
   8.692 +   }
   8.693 +
   8.694 +   /* We're really ready to rock and roll. :-) */
   8.695 +   return 1;
   8.696 +}
   8.697 +
   8.698 +int QSA_DetectDevices(int iscapture)
   8.699 +{
   8.700 +   uint32_t it;
   8.701 +   uint32_t cards;
   8.702 +   uint32_t devices;
   8.703 +   int32_t  status;
   8.704 +
   8.705 +   /* Detect amount of available devices       */
   8.706 +   /* this value can be changed in the runtime */
   8.707 +   cards=snd_cards();
   8.708 +
   8.709 +   /* If io-audio manager is not running we will get 0 as number */
   8.710 +   /* of available audio devices                                 */
   8.711 +   if (cards==0)
   8.712 +   {
   8.713 +      /* We have no any available audio devices */
   8.714 +      return 0;
   8.715 +   }
   8.716 +
   8.717 +   /* Find requested devices by type */
   8.718 +   if (!iscapture)
   8.719 +   {
   8.720 +      /* Playback devices enumeration requested */
   8.721 +      for(it=0; it<cards; it++)
   8.722 +      {
   8.723 +         devices=0;
   8.724 +         do {
   8.725 +            status=snd_card_get_longname(it, qsa_playback_device[qsa_playback_devices].name, QSA_MAX_NAME_LENGTH);
   8.726 +            if (status==EOK)
   8.727 +            {
   8.728 +               snd_pcm_t* handle;
   8.729 +
   8.730 +               /* Add device number to device name */
   8.731 +               sprintf(qsa_playback_device[qsa_playback_devices].name + SDL_strlen(qsa_playback_device[qsa_playback_devices].name), " d%d", devices);
   8.732 +
   8.733 +               /* Store associated card number id */
   8.734 +               qsa_playback_device[qsa_playback_devices].cardno=it;
   8.735 +
   8.736 +               /* Check if this device id could play anything */
   8.737 +               status=snd_pcm_open(&handle, it, devices, SND_PCM_OPEN_PLAYBACK);
   8.738 +               if (status==EOK)
   8.739 +               {
   8.740 +                  qsa_playback_device[qsa_playback_devices].deviceno=devices;
   8.741 +                  status=snd_pcm_close(handle);
   8.742 +                  if (status==EOK)
   8.743 +                  {
   8.744 +                     qsa_playback_devices++;
   8.745 +                  }
   8.746 +               }
   8.747 +               else
   8.748 +               {
   8.749 +                  /* Check if we got end of devices list */
   8.750 +                  if (status==-ENOENT)
   8.751 +                  {
   8.752 +                     break;
   8.753 +                  }
   8.754 +               }
   8.755 +            }
   8.756 +            else
   8.757 +            {
   8.758 +               break;
   8.759 +            }
   8.760 +
   8.761 +            /* Check if we reached maximum devices count */
   8.762 +            if (qsa_playback_devices>=QSA_MAX_DEVICES)
   8.763 +            {
   8.764 +               break;
   8.765 +            }
   8.766 +            devices++;
   8.767 +         } while(1);
   8.768 +
   8.769 +         /* Check if we reached maximum devices count */
   8.770 +         if (qsa_playback_devices>=QSA_MAX_DEVICES)
   8.771 +         {
   8.772 +            break;
   8.773 +         }
   8.774 +      }
   8.775 +   }
   8.776 +   else
   8.777 +   {
   8.778 +      /* Capture devices enumeration requested */
   8.779 +      for(it=0; it<cards; it++)
   8.780 +      {
   8.781 +         devices=0;
   8.782 +         do {
   8.783 +            status=snd_card_get_longname(it, qsa_capture_device[qsa_capture_devices].name, QSA_MAX_NAME_LENGTH);
   8.784 +            if (status==EOK)
   8.785 +            {
   8.786 +               snd_pcm_t* handle;
   8.787 +
   8.788 +               /* Add device number to device name */
   8.789 +               sprintf(qsa_capture_device[qsa_capture_devices].name + SDL_strlen(qsa_capture_device[qsa_capture_devices].name), " d%d", devices);
   8.790 +
   8.791 +               /* Store associated card number id */
   8.792 +               qsa_capture_device[qsa_capture_devices].cardno=it;
   8.793 +
   8.794 +               /* Check if this device id could play anything */
   8.795 +               status=snd_pcm_open(&handle, it, devices, SND_PCM_OPEN_CAPTURE);
   8.796 +               if (status==EOK)
   8.797 +               {
   8.798 +                  qsa_capture_device[qsa_capture_devices].deviceno=devices;
   8.799 +                  status=snd_pcm_close(handle);
   8.800 +                  if (status==EOK)
   8.801 +                  {
   8.802 +                     qsa_capture_devices++;
   8.803 +                  }
   8.804 +               }
   8.805 +               else
   8.806 +               {
   8.807 +                  /* Check if we got end of devices list */
   8.808 +                  if (status==-ENOENT)
   8.809 +                  {
   8.810 +                     break;
   8.811 +                  }
   8.812 +               }
   8.813 +
   8.814 +               /* Check if we reached maximum devices count */
   8.815 +               if (qsa_capture_devices>=QSA_MAX_DEVICES)
   8.816 +               {
   8.817 +                  break;
   8.818 +               }
   8.819 +            }
   8.820 +            else
   8.821 +            {
   8.822 +               break;
   8.823 +            }
   8.824 +            devices++;
   8.825 +         } while(1);
   8.826 +
   8.827 +         /* Check if we reached maximum devices count */
   8.828 +         if (qsa_capture_devices>=QSA_MAX_DEVICES)
   8.829 +         {
   8.830 +            break;
   8.831 +         }
   8.832 +      }
   8.833 +   }
   8.834 +
   8.835 +   /* Return amount of available playback or capture devices */
   8.836 +   if (!iscapture)
   8.837 +   {
   8.838 +      return qsa_playback_devices;
   8.839 +   }
   8.840 +   else
   8.841 +   {
   8.842 +      return qsa_capture_devices;
   8.843 +   }
   8.844 +}
   8.845 +
   8.846 +const char* QSA_GetDeviceName(int index, int iscapture)
   8.847 +{
   8.848 +   if (!iscapture)
   8.849 +   {
   8.850 +      if (index>=qsa_playback_devices)
   8.851 +      {
   8.852 +         return "No such playback device";
   8.853 +      }
   8.854 +
   8.855 +      return qsa_playback_device[index].name;
   8.856 +   }
   8.857 +   else
   8.858 +   {
   8.859 +      if (index>=qsa_capture_devices)
   8.860 +      {
   8.861 +         return "No such capture device";
   8.862 +      }
   8.863 +
   8.864 +      return qsa_capture_device[index].name;
   8.865 +   }
   8.866 +}
   8.867 +
   8.868 +void QSA_WaitDone(_THIS)
   8.869 +{
   8.870 +   if (!this->hidden->iscapture)
   8.871 +   {
   8.872 +      if (this->hidden->audio_handle!=NULL)
   8.873 +      {
   8.874 +         /* Wait till last fragment is played and stop channel */
   8.875 +         snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK);
   8.876 +      }
   8.877 +   }
   8.878 +   else
   8.879 +   {
   8.880 +      if (this->hidden->audio_handle!=NULL)
   8.881 +      {
   8.882 +         /* Discard all unread data and stop channel */
   8.883 +         snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE);
   8.884 +      }
   8.885 +   }
   8.886 +}
   8.887 +
   8.888 +void QSA_Deinitialize(void)
   8.889 +{
   8.890 +   /* Clear devices array on shutdown */
   8.891 +   SDL_memset(qsa_playback_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
   8.892 +   SDL_memset(qsa_capture_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
   8.893 +   qsa_playback_devices=0;
   8.894 +   qsa_capture_devices=0;
   8.895 +}
   8.896 +
   8.897 +static int QSA_Init(SDL_AudioDriverImpl* impl)
   8.898 +{
   8.899 +   snd_pcm_t* handle=NULL;
   8.900 +   int32_t    status=0;
   8.901 +
   8.902 +   /* Clear devices array */
   8.903 +   SDL_memset(qsa_playback_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
   8.904 +   SDL_memset(qsa_capture_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES);
   8.905 +   qsa_playback_devices=0;
   8.906 +   qsa_capture_devices=0;
   8.907 +
   8.908 +   /* Set function pointers                                     */
   8.909 +   /* DeviceLock and DeviceUnlock functions are used default,   */
   8.910 +   /* provided by SDL, which uses pthread_mutex for lock/unlock */
   8.911 +   impl->DetectDevices=QSA_DetectDevices;
   8.912 +   impl->GetDeviceName=QSA_GetDeviceName;
   8.913 +   impl->OpenDevice=QSA_OpenDevice;
   8.914 +   impl->ThreadInit=QSA_ThreadInit;
   8.915 +   impl->WaitDevice=QSA_WaitDevice;
   8.916 +   impl->PlayDevice=QSA_PlayDevice;
   8.917 +   impl->GetDeviceBuf=QSA_GetDeviceBuf;
   8.918 +   impl->CloseDevice=QSA_CloseDevice;
   8.919 +   impl->WaitDone=QSA_WaitDone;
   8.920 +   impl->Deinitialize=QSA_Deinitialize;
   8.921 +   impl->LockDevice=NULL;
   8.922 +   impl->UnlockDevice=NULL;
   8.923 +
   8.924 +   impl->OnlyHasDefaultOutputDevice=0;
   8.925 +   impl->ProvidesOwnCallbackThread=0;
   8.926 +   impl->SkipMixerLock=0;
   8.927 +   impl->HasCaptureSupport=1;
   8.928 +   impl->OnlyHasDefaultOutputDevice=0;
   8.929 +   impl->OnlyHasDefaultInputDevice=0;
   8.930 +
   8.931 +   /* Check if io-audio manager is running or not */
   8.932 +   status=snd_cards();
   8.933 +   if (status==0)
   8.934 +   {
   8.935 +      /* if no, return immediately */
   8.936 +      return 1;
   8.937 +   }
   8.938 +
   8.939 +   /* At this point we are definitely has an audio device */
   8.940 +   return 2;
   8.941 +}
   8.942 +
   8.943 +AudioBootStrap QSAAUDIO_bootstrap=
   8.944 +{
   8.945 +   DRIVER_NAME, "QNX QSA Audio", QSA_Init, 0
   8.946 +};
   8.947 +
   8.948 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/audio/qsa/SDL_qsa_audio.h	Tue Mar 24 10:33:12 2009 +0000
     9.3 @@ -0,0 +1,62 @@
     9.4 +/*
     9.5 +    SDL - Simple DirectMedia Layer
     9.6 +    Copyright (C) 1997-2009 Sam Lantinga
     9.7 +
     9.8 +    This library is free software; you can redistribute it and/or
     9.9 +    modify it under the terms of the GNU Library General Public
    9.10 +    License as published by the Free Software Foundation; either
    9.11 +    version 2 of the License, or (at your option) any later version.
    9.12 +
    9.13 +    This library is distributed in the hope that it will be useful,
    9.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    9.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    9.16 +    Library General Public License for more details.
    9.17 +
    9.18 +    You should have received a copy of the GNU Library General Public
    9.19 +    License along with this library; if not, write to the Free
    9.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    9.21 +
    9.22 +    Sam Lantinga
    9.23 +    slouken@libsdl.org
    9.24 +
    9.25 +    QNX Sound Architecture (QSA) SDL driver
    9.26 +    Copyright (C) 2009 Mike Gorchak
    9.27 +    (mike@malva.ua, lestat@i.com.ua)
    9.28 +*/
    9.29 +
    9.30 +#include "SDL_config.h"
    9.31 +
    9.32 +#ifndef __SDL_QSA_AUDIO_H__
    9.33 +#define __SDL_QSA_AUDIO_H__
    9.34 +
    9.35 +#include <sys/asoundlib.h>
    9.36 +
    9.37 +#include "../SDL_sysaudio.h"
    9.38 +
    9.39 +/* Hidden "this" pointer for the audio functions */
    9.40 +#define _THIS SDL_AudioDevice* this
    9.41 +
    9.42 +struct SDL_PrivateAudioData
    9.43 +{
    9.44 +    /* SDL capture state */
    9.45 +    int iscapture;
    9.46 +
    9.47 +    /* The audio device handle */
    9.48 +    int cardno;
    9.49 +    int deviceno;
    9.50 +    snd_pcm_t* audio_handle;
    9.51 +
    9.52 +    /* The audio file descriptor */
    9.53 +    int audio_fd;
    9.54 +
    9.55 +    /* Select timeout status */
    9.56 +    uint32_t timeout_on_wait;
    9.57 +
    9.58 +    /* Raw mixing buffer */
    9.59 +    Uint8* pcm_buf;
    9.60 +    Uint32 pcm_len;
    9.61 +};
    9.62 +
    9.63 +#endif /* __SDL_QSA_AUDIO_H__ */
    9.64 +
    9.65 +/* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/video/SDL_renderer_gles.c	Mon Mar 23 05:37:45 2009 +0000
    10.2 +++ b/src/video/SDL_renderer_gles.c	Tue Mar 24 10:33:12 2009 +0000
    10.3 @@ -30,6 +30,17 @@
    10.4  #include "SDL_rect_c.h"
    10.5  #include "SDL_yuv_sw_c.h"
    10.6  
    10.7 +#ifdef __QNXNTO__
    10.8 +
    10.9 +/* Empty function stub to get OpenGL ES 1.0 support without  */
   10.10 +/* OpenGL ES extension GL_OES_draw_texture_supported         */
   10.11 +GL_API void GL_APIENTRY glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
   10.12 +{
   10.13 +   return;
   10.14 +}
   10.15 +
   10.16 +#endif /* __QNXNTO__ */
   10.17 +
   10.18  /* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
   10.19  
   10.20  static const float inv255f = 1.0f / 255.0f;
   10.21 @@ -349,6 +360,7 @@
   10.22      GLenum format, type;
   10.23      int texture_w, texture_h;
   10.24      GLenum result;
   10.25 +
   10.26      switch (texture->format) {
   10.27      case SDL_PIXELFORMAT_INDEX1LSB:
   10.28      case SDL_PIXELFORMAT_INDEX1MSB:
   10.29 @@ -479,8 +491,6 @@
   10.30  SetupTextureUpdate(GLES_RenderData * renderdata, SDL_Texture * texture,
   10.31                     int pitch)
   10.32  {
   10.33 -
   10.34 -
   10.35      GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
   10.36      renderdata->glBindTexture(data->type, data->texture);
   10.37      renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   10.38 @@ -888,6 +898,6 @@
   10.39      SDL_free(renderer);
   10.40  }
   10.41  
   10.42 -#endif /* SDL_VIDEO_RENDER_OGL */
   10.43 +#endif /* SDL_VIDEO_RENDER_OGL_ES */
   10.44  
   10.45  /* vi: set ts=4 sw=4 expandtab: */
    11.1 --- a/src/video/SDL_video.c	Mon Mar 23 05:37:45 2009 +0000
    11.2 +++ b/src/video/SDL_video.c	Tue Mar 24 10:33:12 2009 +0000
    11.3 @@ -2711,12 +2711,23 @@
    11.4  {
    11.5  #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
    11.6      void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
    11.7 +    GLenum (APIENTRY * glGetErrorFunc) (void);
    11.8      GLenum attrib = 0;
    11.9 +    GLenum error = 0;
   11.10  
   11.11      glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv");
   11.12      if (!glGetIntegervFunc) {
   11.13          return -1;
   11.14      }
   11.15 +
   11.16 +    glGetErrorFunc = SDL_GL_GetProcAddress("glGetError");
   11.17 +    if (!glGetErrorFunc) {
   11.18 +        return -1;
   11.19 +    }
   11.20 +
   11.21 +    /* Clear value in any case */
   11.22 +    *value=0;
   11.23 +
   11.24      switch (attr) {
   11.25      case SDL_GL_RETAINED_BACKING:
   11.26          *value = _this->gl_config.retained_backing;
   11.27 @@ -2738,11 +2749,10 @@
   11.28          attrib = GL_DOUBLEBUFFER;
   11.29          break;
   11.30  #else
   11.31 -        /*
   11.32 -         * I believe double buffering is the only option in OpenGL ES
   11.33 -         * -- in any case, GL_DOUBLEBUFFER doesn't exist
   11.34 -         */
   11.35 -        *value = 1;
   11.36 +        /* OpenGL ES 1.0 and above specifications have EGL_SINGLE_BUFFER      */
   11.37 +        /* parameter which switches double buffer to single buffer. OpenGL ES */
   11.38 +        /* SDL driver must set proper value after initialization              */
   11.39 +        *value = _this->gl_config.double_buffer;
   11.40          return 0;
   11.41  #endif
   11.42      case SDL_GL_DEPTH_SIZE:
   11.43 @@ -2824,6 +2834,29 @@
   11.44      }
   11.45  
   11.46      glGetIntegervFunc(attrib, (GLint *) value);
   11.47 +    error=glGetErrorFunc();
   11.48 +    if (error!=GL_NO_ERROR)
   11.49 +    {
   11.50 +       switch (error)
   11.51 +       {
   11.52 +          case GL_INVALID_ENUM:
   11.53 +               {
   11.54 +                  SDL_SetError("OpenGL error: GL_INVALID_ENUM");
   11.55 +               }
   11.56 +               break;
   11.57 +          case GL_INVALID_VALUE:
   11.58 +               {
   11.59 +                  SDL_SetError("OpenGL error: GL_INVALID_VALUE");
   11.60 +               }
   11.61 +               break;
   11.62 +          default:
   11.63 +               {
   11.64 +                  SDL_SetError("OpenGL error: %08X", error);
   11.65 +               }
   11.66 +               break;
   11.67 +       }
   11.68 +       return -1;
   11.69 +    }
   11.70      return 0;
   11.71  #else
   11.72      SDL_Unsupported();
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/video/qnxgf/SDL_gf_opengles.c	Tue Mar 24 10:33:12 2009 +0000
    12.3 @@ -0,0 +1,56 @@
    12.4 +Date: Mon, 23 Mar 2009 09:17:24 +0200
    12.5 +From: "Mike Gorchak" <mike@malva.ua>
    12.6 +To: "Sam Lantinga" <slouken@devolution.com>
    12.7 +Subject: New QNX patches
    12.8 +
    12.9 +/*
   12.10 +    SDL - Simple DirectMedia Layer
   12.11 +    Copyright (C) 1997-2009 Sam Lantinga
   12.12 +
   12.13 +    This library is free software; you can redistribute it and/or
   12.14 +    modify it under the terms of the GNU Lesser General Public
   12.15 +    License as published by the Free Software Foundation; either
   12.16 +    version 2.1 of the License, or (at your option) any later version.
   12.17 +
   12.18 +    This library is distributed in the hope that it will be useful,
   12.19 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.20 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.21 +    Lesser General Public License for more details.
   12.22 +
   12.23 +    You should have received a copy of the GNU Lesser General Public
   12.24 +    License along with this library; if not, write to the Free Software
   12.25 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   12.26 +
   12.27 +    Sam Lantinga
   12.28 +    slouken@libsdl.org
   12.29 +
   12.30 +    QNX Graphics Framework SDL driver
   12.31 +    Copyright (C) 2009 Mike Gorchak
   12.32 +    (mike@malva.ua, lestat@i.com.ua)
   12.33 +*/
   12.34 +
   12.35 +#include <GLES/gl.h>
   12.36 +#include <GLES/glext.h>
   12.37 +
   12.38 +/* This is OpenGL ES 1.0 helper functions from OpenGL ES 1.1 specification,  */
   12.39 +/* which could be implemented independently from hardware, just wrappers     */
   12.40 +
   12.41 +GLAPI void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param)
   12.42 +{
   12.43 +   glTexParameterx(target, pname, (GLfixed)param);
   12.44 +   return;
   12.45 +}
   12.46 +
   12.47 +GLAPI void APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint* params)
   12.48 +{
   12.49 +   /* Retrieve one parameter only */
   12.50 +   glTexParameterx(target, pname, (GLfixed)*params);
   12.51 +   return;
   12.52 +}
   12.53 +
   12.54 +GLAPI void APIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
   12.55 +{
   12.56 +   glColor4f(((GLfloat)red)/255.f, ((GLfloat)green)/255.f, ((GLfloat)blue)/255.f, ((GLfloat)alpha)/255.f);
   12.57 +   return;
   12.58 +}
   12.59 +
    13.1 --- a/src/video/qnxgf/SDL_gf_render.c	Mon Mar 23 05:37:45 2009 +0000
    13.2 +++ b/src/video/qnxgf/SDL_gf_render.c	Tue Mar 24 10:33:12 2009 +0000
    13.3 @@ -103,6 +103,13 @@
    13.4     int32_t  jt;
    13.5     int32_t  status;
    13.6  
    13.7 +   /* Check if it is OpenGL ES window */
    13.8 +   if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL)
    13.9 +   {
   13.10 +      /* No error, just no need to create 2D renderer for OpenGL ES window */
   13.11 +      return NULL;
   13.12 +   }
   13.13 +
   13.14     /* Allocate new renderer structure */
   13.15     renderer=(SDL_Renderer*)SDL_calloc(1, sizeof(SDL_Renderer));
   13.16     if (renderer==NULL)
    14.1 --- a/src/video/qnxgf/SDL_qnxgf.c	Mon Mar 23 05:37:45 2009 +0000
    14.2 +++ b/src/video/qnxgf/SDL_qnxgf.c	Tue Mar 24 10:33:12 2009 +0000
    14.3 @@ -29,6 +29,7 @@
    14.4  #include "../SDL_sysvideo.h"
    14.5  #include "SDL_version.h"
    14.6  #include "SDL_syswm.h"
    14.7 +#include "SDL_loadso.h"
    14.8  
    14.9  /* Include QNX Graphics Framework declarations */
   14.10  #include <gf/gf.h>
   14.11 @@ -46,104 +47,132 @@
   14.12  /******************************************************************************/
   14.13  static SDL_DisplayMode generic_mode[]=
   14.14  {
   14.15 -   {0, 320, 200, 70, NULL},    /* 320x200 modes are 70Hz and 85Hz          */
   14.16 -   {0, 320, 200, 85, NULL},
   14.17 -   {0, 320, 240, 70, NULL},    /* 320x240 modes are 70Hz and 85Hz          */
   14.18 -   {0, 320, 240, 85, NULL},
   14.19 -   {0, 512, 384, 60, NULL},    /* 512x384 modes are 60Hz and 70Hz          */
   14.20 -   {0, 512, 384, 70, NULL},
   14.21 -   {0, 640, 480, 60, NULL},    /* 640x480 modes are 60Hz, 75Hz, 85Hz       */
   14.22 -   {0, 640, 480, 75, NULL},
   14.23 -   {0, 640, 480, 85, NULL},
   14.24 -   {0, 800, 600, 60, NULL},    /* 800x600 modes are 60Hz, 75Hz, 85Hz       */
   14.25 -   {0, 800, 600, 75, NULL},
   14.26 -   {0, 800, 600, 85, NULL},
   14.27 -   {0, 800, 480, 60, NULL},    /* 800x480 mode is 60Hz only                */
   14.28 -   {0, 1024, 640, 60, NULL},   /* 1024x640 mode is 60Hz only               */
   14.29 -   {0, 1024, 768, 60, NULL},   /* 1024x768 modes are 60Hz, 70Hz, 75Hz      */
   14.30 -   {0, 1024, 768, 70, NULL},
   14.31 -   {0, 1024, 768, 75, NULL},
   14.32 -   {0, 1280, 720, 60, NULL},   /* 1280x720 mode is 60Hz only               */
   14.33 -   {0, 1280, 768, 60, NULL},   /* 1280x768 mode is 60Hz only               */
   14.34 -   {0, 1280, 800, 60, NULL},   /* 1280x800 mode is 60Hz only               */
   14.35 -   {0, 1280, 960, 60, NULL},   /* 1280x960 mode is 60Hz only               */
   14.36 -   {0, 1280, 1024, 60, NULL},  /* 1280x1024 modes are 60Hz, 75Hz, 85Hz and */
   14.37 -   {0, 1280, 1024, 75, NULL},  /* 100 Hz                                   */
   14.38 -   {0, 1280, 1024, 85, NULL},  /*                                          */
   14.39 +   {0, 320,  200,  70,  NULL}, /* 320x200 modes are 70Hz and 85Hz          */
   14.40 +   {0, 320,  200,  85,  NULL},
   14.41 +   {0, 320,  240,  70,  NULL}, /* 320x240 modes are 70Hz and 85Hz          */
   14.42 +   {0, 320,  240,  85,  NULL},
   14.43 +   {0, 512,  384,  60,  NULL}, /* 512x384 modes are 60Hz and 70Hz          */
   14.44 +   {0, 512,  384,  70,  NULL},
   14.45 +   {0, 640,  480,  60,  NULL}, /* 640x480 modes are 60Hz, 75Hz, 85Hz       */
   14.46 +   {0, 640,  480,  75,  NULL},
   14.47 +   {0, 640,  480,  85,  NULL},
   14.48 +   {0, 800,  600,  60,  NULL}, /* 800x600 modes are 60Hz, 75Hz, 85Hz       */
   14.49 +   {0, 800,  600,  75,  NULL},
   14.50 +   {0, 800,  600,  85,  NULL},
   14.51 +   {0, 800,  480,  60,  NULL}, /* 800x480 mode is 60Hz only                */
   14.52 +   {0, 1024, 640,  60,  NULL}, /* 1024x640 mode is 60Hz only               */
   14.53 +   {0, 1024, 768,  60,  NULL}, /* 1024x768 modes are 60Hz, 70Hz, 75Hz      */
   14.54 +   {0, 1024, 768,  70,  NULL},
   14.55 +   {0, 1024, 768,  75,  NULL},
   14.56 +   {0, 1280, 720,  60,  NULL}, /* 1280x720 mode is 60Hz only               */
   14.57 +   {0, 1280, 768,  60,  NULL}, /* 1280x768 mode is 60Hz only               */
   14.58 +   {0, 1280, 800,  60,  NULL}, /* 1280x800 mode is 60Hz only               */
   14.59 +   {0, 1280, 960,  60,  NULL}, /* 1280x960 mode is 60Hz only               */
   14.60 +   {0, 1280, 1024, 60,  NULL}, /* 1280x1024 modes are 60Hz, 75Hz, 85Hz and */
   14.61 +   {0, 1280, 1024, 75,  NULL}, /* 100 Hz                                   */
   14.62 +   {0, 1280, 1024, 85,  NULL}, /*                                          */
   14.63     {0, 1280, 1024, 100, NULL}, /*                                          */
   14.64 -   {0, 1400, 1050, 60, NULL},  /* 1400x1050 mode is 60Hz only              */
   14.65 -   {0, 1440, 900, 60, NULL},   /* 1440x900 mode is 60Hz only               */
   14.66 -   {0, 1440, 960, 60, NULL},   /* 1440x960 mode is 60Hz only               */
   14.67 -   {0, 1600, 1200, 60, NULL},  /* 1600x1200 mode is 60Hz only              */
   14.68 -   {0, 1680, 1050, 60, NULL},  /* 1680x1050 mode is 60Hz only              */
   14.69 -   {0, 1920, 1080, 60, NULL},  /* 1920x1080 mode is 60Hz only              */
   14.70 -   {0, 1920, 1200, 60, NULL},  /* 1920x1200 mode is 60Hz only              */
   14.71 -   {0, 2048, 1536, 60, NULL},  /* 2048x1536 mode is 60Hz only              */
   14.72 -   {0, 2048, 1080, 60, NULL},  /* 2048x1080 mode is 60Hz only              */
   14.73 -   {0,    0,    0,  0, NULL}   /* End of generic mode list                 */
   14.74 +   {0, 1400, 1050, 60,  NULL}, /* 1400x1050 mode is 60Hz only              */
   14.75 +   {0, 1440, 900,  60,  NULL}, /* 1440x900 mode is 60Hz only               */
   14.76 +   {0, 1440, 960,  60,  NULL}, /* 1440x960 mode is 60Hz only               */
   14.77 +   {0, 1600, 1200, 60,  NULL}, /* 1600x1200 mode is 60Hz only              */
   14.78 +   {0, 1680, 1050, 60,  NULL}, /* 1680x1050 mode is 60Hz only              */
   14.79 +   {0, 1920, 1080, 60,  NULL}, /* 1920x1080 mode is 60Hz only              */
   14.80 +   {0, 1920, 1200, 60,  NULL}, /* 1920x1200 mode is 60Hz only              */
   14.81 +   {0, 2048, 1536, 60,  NULL}, /* 2048x1536 mode is 60Hz only              */
   14.82 +   {0, 2048, 1080, 60,  NULL}, /* 2048x1080 mode is 60Hz only              */
   14.83 +   {0,    0,    0,  0,  NULL}  /* End of generic mode list                 */
   14.84  };
   14.85  
   14.86  /* Low level device graphics driver names, which they are reporting */
   14.87  GF_DeviceCaps gf_devicename[]=
   14.88  {
   14.89     /* ATI Rage 128 graphics driver (devg-ati_rage128)      */
   14.90 -   {"ati_rage128", SDL_GF_ACCELERATED},
   14.91 +   {"ati_rage128", SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
   14.92 +                   SDL_GF_UNACCELERATED_3D},
   14.93     /* Fujitsu Carmine graphics driver (devg-carmine.so)    */
   14.94 -   {"carmine", SDL_GF_ACCELERATED},
   14.95 +   {"carmine",     SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
   14.96 +                   SDL_GF_ACCELERATED_3D},
   14.97     /* C&T graphics driver (devg-chips.so)                  */
   14.98 -   {"chips", SDL_GF_ACCELERATED},
   14.99 +   {"chips",       SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION | 
  14.100 +                   SDL_GF_UNACCELERATED_3D},
  14.101     /* Fujitsu Coral graphics driver (devg-coral.so)        */
  14.102 -   {"coral", SDL_GF_ACCELERATED},
  14.103 +   {"coral",       SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.104 +                   SDL_GF_ACCELERATED_3D},
  14.105     /* Intel integrated graphics driver (devg-extreme2.so)  */
  14.106 -   {"extreme2", SDL_GF_ACCELERATED},
  14.107 +   {"extreme2",    SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.108 +                   SDL_GF_ACCELERATED_3D},
  14.109     /* Unaccelerated FB driver (devg-flat.so)               */
  14.110 -   {"flat", SDL_GF_UNACCELERATED},
  14.111 +   {"flat",        SDL_GF_UNACCELERATED | SDL_GF_LOWRESOLUTION |
  14.112 +                   SDL_GF_UNACCELERATED_3D},
  14.113     /* NS Geode graphics driver (devg-geode.so)             */
  14.114 -   {"geode", SDL_GF_ACCELERATED},
  14.115 +   {"geode",       SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.116 +                   SDL_GF_UNACCELERATED_3D},
  14.117     /* Geode LX graphics driver (devg-geodelx.so)           */
  14.118 -   {"geodelx", SDL_GF_ACCELERATED},
  14.119 +   {"geodelx",     SDL_GF_ACCELERATED | SDL_GF_LOWRESOLUTION |
  14.120 +                   SDL_GF_UNACCELERATED_3D},
  14.121     /* Intel integrated graphics driver (devg-gma9xx.so)    */
  14.122 -   {"gma", SDL_GF_ACCELERATED},
  14.123 +   {"gma",         SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.124 +                   SDL_GF_ACCELERATED_3D},
  14.125     /* Intel integrated graphics driver (devg-i810.so)      */
  14.126 -   {"i810", SDL_GF_ACCELERATED},
  14.127 +   {"i810",        SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.128 +                   SDL_GF_UNACCELERATED_3D},
  14.129     /* Intel integrated graphics driver (devg-i830.so)      */
  14.130 -   {"i830", SDL_GF_ACCELERATED},
  14.131 +   {"i830",        SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.132 +                   SDL_GF_UNACCELERATED_3D},
  14.133     /* Geode LX graphics driver (devg-lx800.so)             */
  14.134 -   {"lx800", SDL_GF_ACCELERATED},
  14.135 +   {"lx800",       SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.136 +                   SDL_GF_UNACCELERATED_3D},
  14.137     /* Matrox Gxx graphics driver (devg-matroxg.so)         */
  14.138 -   {"matroxg", SDL_GF_ACCELERATED},
  14.139 +   {"matroxg",     SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.140 +                   SDL_GF_UNACCELERATED_3D},
  14.141     /* Intel Poulsbo graphics driver (devg-poulsbo.so)      */
  14.142 -   {"poulsbo", SDL_GF_ACCELERATED},
  14.143 +   {"poulsbo",     SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.144 +                   SDL_GF_ACCELERATED_3D},
  14.145     /* ATI Radeon driver (devg-radeon.so)                   */
  14.146 -   {"radeon", SDL_GF_ACCELERATED},
  14.147 +   {"radeon",      SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.148 +                   SDL_GF_UNACCELERATED_3D},
  14.149     /* ATI Rage driver (devg-rage.so)                       */
  14.150 -   {"rage", SDL_GF_ACCELERATED},
  14.151 +   {"rage",        SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.152 +                   SDL_GF_UNACCELERATED_3D},
  14.153     /* S3 Savage graphics driver (devg-s3_savage.so)        */
  14.154 -   {"s3_savage", SDL_GF_ACCELERATED},
  14.155 +   {"s3_savage",   SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.156 +                   SDL_GF_UNACCELERATED_3D},
  14.157     /* SiS630 integrated graphics driver (devg-sis630.so)   */
  14.158 -   {"sis630", SDL_GF_ACCELERATED},
  14.159 +   {"sis630",      SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.160 +                   SDL_GF_UNACCELERATED_3D},
  14.161     /* PowerVR SGX 535 graphics driver (devg-poulsbo.so)    */
  14.162 -   {"sgx", SDL_GF_ACCELERATED},
  14.163 +   {"sgx",         SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.164 +                   SDL_GF_ACCELERATED_3D},
  14.165     /* SM Voyager GX graphics driver (devg-smi5xx.so)       */
  14.166 -   {"smi5xx", SDL_GF_ACCELERATED},
  14.167 +   {"smi5xx",      SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.168 +                   SDL_GF_UNACCELERATED_3D},
  14.169     /* Silicon Motion graphics driver (devg-smi7xx.so)      */
  14.170 -   {"smi7xx", SDL_GF_ACCELERATED},
  14.171 +   {"smi7xx",      SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.172 +                   SDL_GF_UNACCELERATED_3D},
  14.173     /* SVGA unaccelerated gfx driver (devg-svga.so)         */
  14.174 -   {"svga", SDL_GF_UNACCELERATED},
  14.175 +   {"svga",        SDL_GF_UNACCELERATED | SDL_GF_LOWRESOLUTION |
  14.176 +                   SDL_GF_UNACCELERATED_3D},
  14.177     /* nVidia TNT graphics driver (devg-tnt.so)             */
  14.178 -   {"tnt", SDL_GF_ACCELERATED},
  14.179 +   {"tnt",         SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.180 +                   SDL_GF_UNACCELERATED_3D},
  14.181     /* VIA integrated graphics driver (devg-tvia.so)        */
  14.182 -   {"tvia", SDL_GF_ACCELERATED},
  14.183 +   {"tvia",        SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
  14.184 +                   SDL_GF_UNACCELERATED_3D},
  14.185     /* VIA UniChrome graphics driver (devg-unichrome.so)    */
  14.186 -   {"unichrome", SDL_GF_ACCELERATED},
  14.187 +   {"unichrome",   SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION | 
  14.188 +                   SDL_GF_UNACCELERATED_3D},
  14.189     /* VESA unaccelerated gfx driver (devg-vesa.so)         */
  14.190 -   {"vesa", SDL_GF_UNACCELERATED},
  14.191 +   {"vesa",        SDL_GF_UNACCELERATED | SDL_GF_LOWRESOLUTION |
  14.192 +                   SDL_GF_UNACCELERATED_3D},
  14.193     /* VmWare graphics driver (devg-volari.so)              */
  14.194 -   {"vmware", SDL_GF_ACCELERATED},
  14.195 +   {"vmware",      SDL_GF_ACCELERATED | SDL_GF_LOWRESOLUTION |
  14.196 +                   SDL_GF_UNACCELERATED_3D},
  14.197     /* XGI XP10 graphics driver (devg-volari.so)            */
  14.198 -   {"volari", SDL_GF_ACCELERATED},
  14.199 +   {"volari",      SDL_GF_ACCELERATED | SDL_GF_LOWRESOLUTION |
  14.200 +                   SDL_GF_UNACCELERATED_3D},
  14.201     /* End of list */
  14.202 -   {NULL, 0x00000000}
  14.203 +   {NULL,          0x00000000}
  14.204  };
  14.205  
  14.206  /*****************************************************************************/
  14.207 @@ -314,7 +343,7 @@
  14.208        {
  14.209           /* video initialization problem */
  14.210           SDL_free(didata);
  14.211 -         SDL_SetError("display query failed");
  14.212 +         SDL_SetError("GF: Display query failed");
  14.213           return -1;
  14.214        }
  14.215  
  14.216 @@ -324,7 +353,7 @@
  14.217        {
  14.218           /* video initialization problem */
  14.219           SDL_free(didata);
  14.220 -         SDL_SetError("couldn't attach to display");
  14.221 +         SDL_SetError("GF: Couldn't attach to display");
  14.222           return -1;
  14.223        }
  14.224  
  14.225 @@ -335,7 +364,7 @@
  14.226        status=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0);
  14.227        if (status!=GF_ERR_OK)
  14.228        {
  14.229 -         SDL_SetError("couldn't attach to main layer, it could be busy");
  14.230 +         SDL_SetError("GF: Couldn't attach to main layer, it could be busy");
  14.231  
  14.232           /* Failed to attach to main layer */
  14.233           return -1;
  14.234 @@ -432,6 +461,16 @@
  14.235                    break;
  14.236                 }
  14.237  
  14.238 +               /* Check if driver do not supports doublescan video modes */
  14.239 +               if ((didata->caps & SDL_GF_LOWRESOLUTION)!=SDL_GF_LOWRESOLUTION)
  14.240 +               {
  14.241 +                  if (generic_mode[jt].w<640)
  14.242 +                  {
  14.243 +                     jt++;
  14.244 +                     continue;
  14.245 +                  }
  14.246 +               }
  14.247 +
  14.248                 mode.w=generic_mode[jt].w;
  14.249                 mode.h=generic_mode[jt].h;
  14.250                 mode.refresh_rate=generic_mode[jt].refresh_rate;
  14.251 @@ -597,7 +636,7 @@
  14.252     if (result!=GF_ERR_OK)
  14.253     {
  14.254        /* Display mode/resolution switch has been failed */
  14.255 -      SDL_SetError("mode is not supported by graphics driver");
  14.256 +      SDL_SetError("GF: Mode is not supported by graphics driver");
  14.257        return -1;
  14.258     }
  14.259     else
  14.260 @@ -610,7 +649,7 @@
  14.261     result=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0);
  14.262     if (result!=GF_ERR_OK)
  14.263     {
  14.264 -      SDL_SetError("couldn't attach to main layer, it could be busy");
  14.265 +      SDL_SetError("GF: Couldn't attach to main layer, it could be busy");
  14.266  
  14.267        /* Failed to attach to main displayable layer */
  14.268        return -1;
  14.269 @@ -674,8 +713,10 @@
  14.270  
  14.271  int qnxgf_createwindow(_THIS, SDL_Window* window)
  14.272  {
  14.273 +   SDL_VideoData*   gfdata=(SDL_VideoData*)_this->driverdata;
  14.274     SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
  14.275     SDL_WindowData*  wdata;
  14.276 +   int32_t          status;
  14.277  
  14.278     /* QNX GF supports fullscreen window modes only */
  14.279     if ((window->flags & SDL_WINDOW_FULLSCREEN)!=SDL_WINDOW_FULLSCREEN)
  14.280 @@ -705,7 +746,7 @@
  14.281        /* Check if end of display list has been reached */
  14.282        if (mode.refresh_rate==0x0000FFFF)
  14.283        {
  14.284 -         SDL_SetError("desired video mode is not supported");
  14.285 +         SDL_SetError("GF: Desired video mode is not supported");
  14.286  
  14.287           /* Failed to create new window */
  14.288           return -1;
  14.289 @@ -716,7 +757,12 @@
  14.290           window->flags|=SDL_WINDOW_FULLSCREEN;
  14.291  
  14.292           /* Setup fullscreen mode, bpp used from desktop mode in this case */
  14.293 -         qnxgf_setdisplaymode(_this, &mode);
  14.294 +         status=qnxgf_setdisplaymode(_this, &mode);
  14.295 +         if (status!=0)
  14.296 +         {
  14.297 +            /* Failed to swith fullscreen video mode */
  14.298 +            return -1;
  14.299 +         }
  14.300        }
  14.301     }
  14.302  
  14.303 @@ -744,8 +790,37 @@
  14.304     /* Check if window must support OpenGL ES rendering */
  14.305     if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL)
  14.306     {
  14.307 -      /* Mark this window as OpenGL ES compatible */
  14.308 -      wdata->uses_gles=SDL_TRUE;
  14.309 +      #if defined(SDL_VIDEO_OPENGL_ES)
  14.310 +         EGLBoolean initstatus;
  14.311 +
  14.312 +         /* Mark this window as OpenGL ES compatible */
  14.313 +         wdata->uses_gles=SDL_TRUE;
  14.314 +
  14.315 +         /* Create connection to OpenGL ES */
  14.316 +         if (gfdata->egldisplay==EGL_NO_DISPLAY)
  14.317 +         {
  14.318 +            gfdata->egldisplay=eglGetDisplay(gfdata->gfdev);
  14.319 +            if (gfdata->egldisplay==EGL_NO_DISPLAY)
  14.320 +            {
  14.321 +               SDL_SetError("GF: Can't get connection to OpenGL ES");
  14.322 +               return -1;
  14.323 +            }
  14.324 +
  14.325 +            /* Initialize OpenGL ES library, ignore EGL version */
  14.326 +            initstatus=eglInitialize(gfdata->egldisplay, NULL, NULL);
  14.327 +            if (initstatus!=EGL_TRUE)
  14.328 +            {
  14.329 +               SDL_SetError("GF: Can't init OpenGL ES library");
  14.330 +               return -1;
  14.331 +            }
  14.332 +         }
  14.333 +
  14.334 +         /* Increment GL ES reference count usage */
  14.335 +         gfdata->egl_refcount++;
  14.336 +      #else
  14.337 +         SDL_SetError("GF: OpenGL ES support is not compiled in");
  14.338 +         return -1;
  14.339 +      #endif /* SDL_VIDEO_OPENGL_ES */
  14.340     }
  14.341  
  14.342     /* Window has been successfully created */
  14.343 @@ -804,11 +879,37 @@
  14.344  
  14.345  void qnxgf_destroywindow(_THIS, SDL_Window* window)
  14.346  {
  14.347 +   SDL_VideoData*   gfdata=(SDL_VideoData*)_this->driverdata;
  14.348     SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
  14.349     SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
  14.350  
  14.351     if (wdata!=NULL)
  14.352     {
  14.353 +      #if defined(SDL_VIDEO_OPENGL_ES)
  14.354 +         /* Destroy OpenGL ES surface if it was created */
  14.355 +         if (wdata->gles_surface!=EGL_NO_SURFACE)
  14.356 +         {
  14.357 +            eglDestroySurface(gfdata->egldisplay, wdata->gles_surface);
  14.358 +         }
  14.359 +
  14.360 +         /* Free any 3D target if it was created before */
  14.361 +         if (wdata->target_created==SDL_TRUE)
  14.362 +         {
  14.363 +            gf_3d_target_free(wdata->target);
  14.364 +         }
  14.365 +
  14.366 +
  14.367 +         gfdata->egl_refcount--;
  14.368 +         if (gfdata->egl_refcount==0)
  14.369 +         {
  14.370 +            /* Terminate connection to OpenGL ES */
  14.371 +            if (gfdata->egldisplay!=EGL_NO_DISPLAY)
  14.372 +            {
  14.373 +               eglTerminate(gfdata->egldisplay);
  14.374 +               gfdata->egldisplay=EGL_NO_DISPLAY;
  14.375 +            }
  14.376 +         }
  14.377 +      #endif /* SDL_VIDEO_OPENGL_ES */
  14.378     }
  14.379  }
  14.380  
  14.381 @@ -826,7 +927,7 @@
  14.382     }
  14.383     else
  14.384     {
  14.385 -      SDL_SetError("application not compiled with SDL %d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
  14.386 +      SDL_SetError("Application not compiled with SDL %d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
  14.387        return SDL_FALSE;
  14.388     }
  14.389  
  14.390 @@ -839,50 +940,382 @@
  14.391  /*****************************************************************************/
  14.392  int qnxgf_gl_loadlibrary(_THIS, const char* path)
  14.393  {
  14.394 -   /* Failed to load new GL library */
  14.395 -   return -1;
  14.396 +   #if defined(SDL_VIDEO_OPENGL_ES)
  14.397 +      /* Check if OpenGL ES library is specified for GF driver */
  14.398 +      if (path==NULL)
  14.399 +      {
  14.400 +         path=SDL_getenv("SDL_OPENGL_LIBRARY");
  14.401 +         if (path==NULL)
  14.402 +         {
  14.403 +            path=SDL_getenv("SDL_OPENGLES_LIBRARY");
  14.404 +         }
  14.405 +      }
  14.406 +
  14.407 +      /* Check if default library loading requested */
  14.408 +      if (path==NULL)
  14.409 +      {
  14.410 +         /* Already linked with GF library which provides egl* subset of  */
  14.411 +         /* functions, use Common profile of OpenGL ES library by default */
  14.412 +         path="/usr/lib/libGLES_CM.so.1";
  14.413 +      }
  14.414 +
  14.415 +      /* Load dynamic library */
  14.416 +      _this->gl_config.dll_handle=SDL_LoadObject(path);
  14.417 +      if (!_this->gl_config.dll_handle)
  14.418 +      {
  14.419 +         /* Failed to load new GL ES library */
  14.420 +         SDL_SetError("GF: Failed to locate OpenGL ES library");
  14.421 +         return -1;
  14.422 +      }
  14.423 +
  14.424 +      /* Store OpenGL ES library path and name */
  14.425 +      SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path));
  14.426 +
  14.427 +      /* New OpenGL ES library is loaded */
  14.428 +      return 0;
  14.429 +   #else
  14.430 +      SDL_SetError("GF: OpenGL ES support is not compiled in");
  14.431 +      return -1;
  14.432 +   #endif /* SDL_VIDEO_OPENGL_ES */
  14.433  }
  14.434  
  14.435  void* qnxgf_gl_getprocaddres(_THIS, const char* proc)
  14.436  {
  14.437 -   /* Failed to get GL function address pointer */
  14.438 -   return NULL;
  14.439 +   #if defined(SDL_VIDEO_OPENGL_ES)
  14.440 +      void* function_address;
  14.441 +
  14.442 +      /* Try to get function address through the egl interface */
  14.443 +      function_address=eglGetProcAddress(proc);
  14.444 +      if (function_address!=NULL)
  14.445 +      {
  14.446 +         return function_address;
  14.447 +      }
  14.448 +
  14.449 +      /* Then try to get function in the OpenGL ES library */
  14.450 +      if (_this->gl_config.dll_handle)
  14.451 +      {
  14.452 +         function_address=SDL_LoadFunction(_this->gl_config.dll_handle, proc);
  14.453 +         if (function_address!=NULL)
  14.454 +         {
  14.455 +            return function_address;
  14.456 +         }
  14.457 +      }
  14.458 +
  14.459 +      /* Failed to get GL ES function address pointer */
  14.460 +      SDL_SetError("GF: Cannot locate given function name");
  14.461 +      return NULL;
  14.462 +   #else
  14.463 +      SDL_SetError("GF: OpenGL ES support is not compiled in");
  14.464 +      return NULL;
  14.465 +   #endif /* SDL_VIDEO_OPENGL_ES */
  14.466  }
  14.467  
  14.468  void qnxgf_gl_unloadlibrary(_THIS)
  14.469  {
  14.470 +   #if defined(SDL_VIDEO_OPENGL_ES)
  14.471 +      /* Unload OpenGL ES library */
  14.472 +      if (_this->gl_config.dll_handle)
  14.473 +      {
  14.474 +         SDL_UnloadObject(_this->gl_config.dll_handle);
  14.475 +         _this->gl_config.dll_handle=NULL;
  14.476 +      }
  14.477 +   #else
  14.478 +      SDL_SetError("GF: OpenGL ES support is not compiled in");
  14.479 +      return;
  14.480 +   #endif /* SDL_VIDEO_OPENGL_ES */
  14.481  }
  14.482  
  14.483  SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window)
  14.484  {
  14.485 -   /* Failed to create GL context */
  14.486 -   return NULL;
  14.487 +   #if defined(SDL_VIDEO_OPENGL_ES)
  14.488 +      SDL_VideoData*   gfdata=(SDL_VideoData*)_this->driverdata;
  14.489 +      SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
  14.490 +      SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata;
  14.491 +      EGLBoolean       status;
  14.492 +      int32_t          gfstatus;
  14.493 +      EGLint           configs;
  14.494 +      uint32_t         surfaces;
  14.495 +      uint32_t         attr_pos;
  14.496 +
  14.497 +      /* Prepare attributes list to pass them to OpenGL ES */
  14.498 +      attr_pos=0;
  14.499 +      wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID;
  14.500 +      wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
  14.501 +      wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE;
  14.502 +      wdata->gles_attributes[attr_pos++]=_this->gl_config.red_size;
  14.503 +      wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE;
  14.504 +      wdata->gles_attributes[attr_pos++]=_this->gl_config.green_size;
  14.505 +      wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE;
  14.506 +      wdata->gles_attributes[attr_pos++]=_this->gl_config.blue_size;
  14.507 +      wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE;
  14.508 +      if (_this->gl_config.alpha_size)
  14.509 +      {
  14.510 +         wdata->gles_attributes[attr_pos++]=_this->gl_config.alpha_size;
  14.511 +      }
  14.512 +      else
  14.513 +      {
  14.514 +         wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
  14.515 +      }
  14.516 +      wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
  14.517 +      wdata->gles_attributes[attr_pos++]=_this->gl_config.depth_size;
  14.518 +      if (_this->gl_config.buffer_size)
  14.519 +      {
  14.520 +         wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE;
  14.521 +         wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
  14.522 +      }
  14.523 +      if (_this->gl_config.stencil_size)
  14.524 +      {
  14.525 +         wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
  14.526 +         wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
  14.527 +      }
  14.528 +
  14.529 +      /* OpenGL ES 1.0 uses double buffer by default, so if application */
  14.530 +      /* do not requested double buffering, switch to single buffer     */
  14.531 +      if (!_this->gl_config.double_buffer)
  14.532 +      {
  14.533 +         wdata->gles_attributes[attr_pos++]=EGL_SINGLE_BUFFER;
  14.534 +         wdata->gles_attributes[attr_pos++]=EGL_TRUE;
  14.535 +         surfaces=1;
  14.536 +      }
  14.537 +      else
  14.538 +      {
  14.539 +         surfaces=2;
  14.540 +      }
  14.541 +
  14.542 +      /* Set number of samples in multisampling */
  14.543 +      if (_this->gl_config.multisamplesamples)
  14.544 +      {
  14.545 +         wdata->gles_attributes[attr_pos++]=EGL_SAMPLES;
  14.546 +         wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplesamples;
  14.547 +      }
  14.548 +
  14.549 +      /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
  14.550 +      if (_this->gl_config.multisamplebuffers)
  14.551 +      {
  14.552 +         wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS;
  14.553 +         wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplebuffers;
  14.554 +      }
  14.555 +
  14.556 +      /* Finish attributes list */
  14.557 +      wdata->gles_attributes[attr_pos]=EGL_NONE;
  14.558 +
  14.559 +      /* Request first suitable framebuffer configuration */
  14.560 +      status=eglChooseConfig(gfdata->egldisplay, wdata->gles_attributes, &wdata->gles_config, 1, &configs);
  14.561 +      if (status!=EGL_TRUE)
  14.562 +      {
  14.563 +         SDL_SetError("GF: Can't find closest configuration for OpenGL ES");
  14.564 +         return NULL;
  14.565 +      }
  14.566 +
  14.567 +      /* Create OpenGL ES context */
  14.568 +      wdata->gles_context=eglCreateContext(gfdata->egldisplay, wdata->gles_config, EGL_NO_CONTEXT, NULL);
  14.569 +      if (wdata->gles_context==EGL_NO_CONTEXT)
  14.570 +      {
  14.571 +         SDL_SetError("GF: OpenGL ES context creation has been failed");
  14.572 +         return NULL;
  14.573 +      }
  14.574 +
  14.575 +      /* Free any 3D target if it was created before */
  14.576 +      if (wdata->target_created==SDL_TRUE)
  14.577 +      {
  14.578 +         gf_3d_target_free(wdata->target);
  14.579 +      }
  14.580 +
  14.581 +      /* Create surface(s) target for OpenGL ES */
  14.582 +      gfstatus=gf_3d_target_create(&wdata->target, didata->layer, NULL,
  14.583 +               surfaces, didata->current_mode.w, didata->current_mode.h,
  14.584 +               qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format));
  14.585 +
  14.586 +      if (gfstatus!=GF_ERR_OK)
  14.587 +      {
  14.588 +         /* Destroy just created context */
  14.589 +         eglDestroyContext(gfdata->egldisplay, wdata->gles_context);
  14.590 +         wdata->gles_context=EGL_NO_CONTEXT;
  14.591 +
  14.592 +         /* Mark 3D target as unallocated */
  14.593 +         wdata->target_created=SDL_FALSE;
  14.594 +         SDL_SetError("GF: OpenGL ES target could not be created");
  14.595 +         return NULL;
  14.596 +      }
  14.597 +      else
  14.598 +      {
  14.599 +         wdata->target_created=SDL_TRUE;
  14.600 +      }
  14.601 +
  14.602 +      /* Create target rendering surface on whole screen */
  14.603 +      wdata->gles_surface=eglCreateWindowSurface(gfdata->egldisplay, wdata->gles_config, wdata->target, NULL);
  14.604 +      if (wdata->gles_surface==EGL_NO_SURFACE)
  14.605 +      {
  14.606 +         /* Destroy 3d target */
  14.607 +         gf_3d_target_free(wdata->target);
  14.608 +         wdata->target_created=SDL_FALSE;
  14.609 +
  14.610 +         /* Destroy OpenGL ES context */
  14.611 +         eglDestroyContext(gfdata->egldisplay, wdata->gles_context);
  14.612 +         wdata->gles_context=EGL_NO_CONTEXT;
  14.613 +
  14.614 +         SDL_SetError("GF: OpenGL ES surface could not be created");
  14.615 +         return NULL;
  14.616 +      }
  14.617 +
  14.618 +      /* Make just created context current */
  14.619 +      status=eglMakeCurrent(gfdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context);
  14.620 +      if (status!=EGL_TRUE)
  14.621 +      {
  14.622 +         /* Destroy OpenGL ES surface */
  14.623 +         eglDestroySurface(gfdata->egldisplay, wdata->gles_surface);
  14.624 +
  14.625 +         /* Destroy 3d target */
  14.626 +         gf_3d_target_free(wdata->target);
  14.627 +         wdata->target_created=SDL_FALSE;
  14.628 +
  14.629 +         /* Destroy OpenGL ES context */
  14.630 +         eglDestroyContext(gfdata->egldisplay, wdata->gles_context);
  14.631 +         wdata->gles_context=EGL_NO_CONTEXT;
  14.632 +
  14.633 +         /* Failed to set current GL ES context */
  14.634 +         SDL_SetError("GF: Can't set OpenGL ES context on creation");
  14.635 +         return NULL;
  14.636 +      }
  14.637 +
  14.638 +      /* Setup into SDL internals state of OpenGL ES:  */
  14.639 +      /* it is accelerated or not                      */
  14.640 +      if ((didata->caps & SDL_GF_ACCELERATED_3D)==SDL_GF_ACCELERATED_3D)
  14.641 +      {
  14.642 +         _this->gl_config.accelerated=1;
  14.643 +      }
  14.644 +      else
  14.645 +      {
  14.646 +         _this->gl_config.accelerated=0;
  14.647 +      }
  14.648 +
  14.649 +      /* Always clear stereo enable, since OpenGL ES do not supports stereo */
  14.650 +      _this->gl_config.stereo=0;
  14.651 +
  14.652 +      /* Failed to create GL ES context */
  14.653 +      return wdata->gles_context;
  14.654 +   #else
  14.655 +      SDL_SetError("GF: OpenGL ES support is not compiled in");
  14.656 +      return NULL;
  14.657 +   #endif /* SDL_VIDEO_OPENGL_ES */
  14.658  }
  14.659  
  14.660  int qnxgf_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context)
  14.661  {
  14.662 -   /* Failed to set current GL context */
  14.663 -   return -1;
  14.664 +   #if defined(SDL_VIDEO_OPENGL_ES)
  14.665 +      SDL_VideoData*   gfdata=(SDL_VideoData*)_this->driverdata;
  14.666 +      SDL_WindowData*  wdata;
  14.667 +      EGLBoolean status;
  14.668 +
  14.669 +      if ((window==NULL) && (context==NULL))
  14.670 +      {
  14.671 +         status=eglMakeCurrent(gfdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  14.672 +         if (status!=EGL_TRUE)
  14.673 +         {
  14.674 +            /* Failed to set current GL ES context */
  14.675 +            SDL_SetError("GF: Can't set OpenGL ES context");
  14.676 +            return -1;
  14.677 +         }
  14.678 +      }
  14.679 +      else
  14.680 +      {
  14.681 +         wdata=(SDL_WindowData*)window->driverdata;
  14.682 +         status=eglMakeCurrent(gfdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context);
  14.683 +         if (status!=EGL_TRUE)
  14.684 +         {
  14.685 +            /* Failed to set current GL ES context */
  14.686 +            SDL_SetError("GF: Can't set OpenGL ES context");
  14.687 +            return -1;
  14.688 +         }
  14.689 +      }
  14.690 +
  14.691 +      return 0;
  14.692 +   #else
  14.693 +      SDL_SetError("GF: OpenGL ES support is not compiled in");
  14.694 +      return -1;
  14.695 +   #endif /* SDL_VIDEO_OPENGL_ES */
  14.696  }
  14.697  
  14.698  int qnxgf_gl_setswapinterval(_THIS, int interval)
  14.699  {
  14.700 -   /* Failed to set swap interval */
  14.701 -   return -1;
  14.702 +   #if defined(SDL_VIDEO_OPENGL_ES)
  14.703 +      SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata;
  14.704 +      EGLBoolean     status;
  14.705 +
  14.706 +      /* Check if OpenGL ES connection has been initialized */
  14.707 +      if (gfdata->egldisplay!=EGL_NO_DISPLAY)
  14.708 +      {
  14.709 +         /* Set swap OpenGL ES interval */
  14.710 +         status=eglSwapInterval(gfdata->egldisplay, interval);
  14.711 +         if (status==EGL_TRUE)
  14.712 +         {
  14.713 +            /* Return success to upper level */
  14.714 +            gfdata->swapinterval=interval;
  14.715 +            return 0;
  14.716 +         }
  14.717 +      }
  14.718 +
  14.719 +      /* Failed to set swap interval */
  14.720 +      SDL_SetError("GF: Cannot set swap interval");
  14.721 +      return -1;
  14.722 +   #else
  14.723 +      SDL_SetError("GF: OpenGL ES support is not compiled in");
  14.724 +      return -1;
  14.725 +   #endif /* SDL_VIDEO_OPENGL_ES */
  14.726  }
  14.727  
  14.728  int qnxgf_gl_getswapinterval(_THIS)
  14.729  {
  14.730 -   /* Failed to get default swap interval */
  14.731 -   return -1;
  14.732 +   #if defined(SDL_VIDEO_OPENGL_ES)
  14.733 +      SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata;
  14.734 +
  14.735 +      /* Return default swap interval value */
  14.736 +      return gfdata->swapinterval;
  14.737 +   #else
  14.738 +      SDL_SetError("GF: OpenGL ES support is not compiled in");
  14.739 +      return -1;
  14.740 +   #endif /* SDL_VIDEO_OPENGL_ES */
  14.741  }
  14.742  
  14.743  void qnxgf_gl_swapwindow(_THIS, SDL_Window* window)
  14.744  {
  14.745 +   #if defined(SDL_VIDEO_OPENGL_ES)
  14.746 +      SDL_VideoData*   gfdata=(SDL_VideoData*)_this->driverdata;
  14.747 +      SDL_WindowData*  wdata=(SDL_WindowData*)window->driverdata;
  14.748 +
  14.749 +      eglSwapBuffers(gfdata->egldisplay, wdata->gles_surface);
  14.750 +   #else
  14.751 +      SDL_SetError("GF: OpenGL ES support is not compiled in");
  14.752 +      return;
  14.753 +   #endif /* SDL_VIDEO_OPENGL_ES */
  14.754  }
  14.755  
  14.756  void qnxgf_gl_deletecontext(_THIS, SDL_GLContext context)
  14.757  {
  14.758 +   #if defined(SDL_VIDEO_OPENGL_ES)
  14.759 +      SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata;
  14.760 +      EGLBoolean     status;
  14.761 +
  14.762 +      /* Check if OpenGL ES connection has been initialized */
  14.763 +      if (gfdata->egldisplay!=EGL_NO_DISPLAY)
  14.764 +      {
  14.765 +         if (context!=EGL_NO_CONTEXT)
  14.766 +         {
  14.767 +            status=eglDestroyContext(gfdata->egldisplay, context);
  14.768 +            if (status!=EGL_TRUE)
  14.769 +            {
  14.770 +               /* Error during OpenGL ES context destroying */
  14.771 +               SDL_SetError("GF: OpenGL ES context destroy error");
  14.772 +               return;
  14.773 +            }
  14.774 +         }
  14.775 +      }
  14.776 +
  14.777 +      return;
  14.778 +   #else
  14.779 +      SDL_SetError("GF: OpenGL ES support is not compiled in");
  14.780 +      return;
  14.781 +   #endif /* SDL_VIDEO_OPENGL_ES */
  14.782  }
  14.783  
  14.784  /*****************************************************************************/
    15.1 --- a/src/video/qnxgf/SDL_qnxgf.h	Mon Mar 23 05:37:45 2009 +0000
    15.2 +++ b/src/video/qnxgf/SDL_qnxgf.h	Tue Mar 24 10:33:12 2009 +0000
    15.3 @@ -30,12 +30,22 @@
    15.4  #include "../SDL_sysvideo.h"
    15.5  
    15.6  #include <gf/gf.h>
    15.7 +#include <gf/gf3d.h>
    15.8 +
    15.9 +#if defined(SDL_VIDEO_OPENGL_ES)
   15.10 +   #include <GLES/egl.h>
   15.11 +#endif /* SDL_VIDEO_OPENGL_ES */
   15.12  
   15.13  typedef struct SDL_VideoData
   15.14  {
   15.15     gf_dev_t      gfdev;              /* GF device handle                     */
   15.16     gf_dev_info_t gfdev_info;         /* GF device information                */
   15.17     SDL_bool      gfinitialized;      /* GF device initialization status      */
   15.18 +   #if defined(SDL_VIDEO_OPENGL_ES)
   15.19 +      EGLDisplay egldisplay;         /* OpenGL ES display connection         */
   15.20 +      uint32_t   egl_refcount;       /* OpenGL ES reference count            */
   15.21 +      uint32_t   swapinterval;       /* OpenGL ES default swap interval      */
   15.22 +   #endif /* SDL_VIDEO_OPENGL_ES */
   15.23  } SDL_VideoData;
   15.24  
   15.25  #define SDL_VIDEO_GF_DEVICENAME_MAX 257
   15.26 @@ -55,9 +65,23 @@
   15.27  
   15.28  typedef struct SDL_WindowData
   15.29  {
   15.30 -   SDL_bool     uses_gles;           /* if true window must support OpenGL ES*/
   15.31 +   SDL_bool   uses_gles;               /* true if window support OpenGL ES   */
   15.32 +   #if defined(SDL_VIDEO_OPENGL_ES)
   15.33 +      gf_3d_target_t target;           /* OpenGL ES window target            */
   15.34 +      SDL_bool   target_created;       /* GF 3D target is created if true    */
   15.35 +      EGLConfig  gles_config;          /* OpenGL ES framebuffer configuration*/
   15.36 +      EGLContext gles_context;         /* OpenGL ES context                  */
   15.37 +      EGLint     gles_attributes[256]; /* OpenGL ES attributes for context   */
   15.38 +      EGLSurface gles_surface;         /* OpenGL ES target rendering surface */
   15.39 +   #endif /* SDL_VIDEO_OPENGL_ES */
   15.40  } SDL_WindowData;
   15.41  
   15.42 +typedef struct SDL_GLDriverData
   15.43 +{
   15.44 +   #if defined(SDL_VIDEO_OPENGL_ES)
   15.45 +   #endif /* SDL_VIDEO_OPENGL_ES */
   15.46 +} SDL_GLDriverData;
   15.47 +
   15.48  /****************************************************************************/
   15.49  /* Low level GF graphics driver capabilities                                */
   15.50  /****************************************************************************/
   15.51 @@ -69,6 +93,10 @@
   15.52  
   15.53  #define SDL_GF_UNACCELERATED         0x00000000
   15.54  #define SDL_GF_ACCELERATED           0x00000001
   15.55 +#define SDL_GF_NOLOWRESOLUTION       0x00000000
   15.56 +#define SDL_GF_LOWRESOLUTION         0x00000002
   15.57 +#define SDL_GF_UNACCELERATED_3D      0x00000000
   15.58 +#define SDL_GF_ACCELERATED_3D        0x00000004
   15.59  
   15.60  /****************************************************************************/
   15.61  /* SDL_VideoDevice functions declaration                                    */
    16.1 --- a/test/testdyngles.c	Mon Mar 23 05:37:45 2009 +0000
    16.2 +++ b/test/testdyngles.c	Tue Mar 24 10:33:12 2009 +0000
    16.3 @@ -65,7 +65,7 @@
    16.4      void (APIENTRY * glClear) (GLbitfield);
    16.5      void (APIENTRY * glDisable) (GLenum);
    16.6      void (APIENTRY * glEnable) (GLenum);
    16.7 -    void (APIENTRY * glColor4ub) (GLubyte, GLubyte, GLubyte, GLubyte);
    16.8 +    void (APIENTRY * glColor4f) (GLfloat, GLfloat, GLfloat, GLfloat);
    16.9      void (APIENTRY * glPointSize) (GLfloat);
   16.10      void (APIENTRY * glHint) (GLenum, GLenum);
   16.11      void (APIENTRY * glBlendFunc) (GLenum, GLenum);
   16.12 @@ -89,7 +89,7 @@
   16.13      f->glClear = get_funcaddr("glClear");
   16.14      f->glDisable = get_funcaddr("glDisable");
   16.15      f->glEnable = get_funcaddr("glEnable");
   16.16 -    f->glColor4ub = get_funcaddr("glColor4ub");
   16.17 +    f->glColor4f = get_funcaddr("glColor4f");
   16.18      f->glPointSize = get_funcaddr("glPointSize");
   16.19      f->glHint = get_funcaddr("glHint");
   16.20      f->glBlendFunc = get_funcaddr("glBlendFunc");
   16.21 @@ -118,6 +118,10 @@
   16.22      /* you may want to change these according to the platform */
   16.23      video_w = 320;
   16.24      video_h = 480;
   16.25 +    #ifdef __QNXNTO__
   16.26 +       video_h = 640;
   16.27 +       video_w = 480;
   16.28 +    #endif /* __QNXNTO__ */
   16.29  
   16.30      if (argv[1]) {
   16.31          gl_library = argv[1];
   16.32 @@ -149,7 +153,11 @@
   16.33          pixels[3 * i + 2] = rand() % 250 - 125;
   16.34      }
   16.35  
   16.36 -    f.glViewport(0, 0, video_w, video_h);
   16.37 +    #ifdef __QNXNTO__
   16.38 +       f.glViewport(0, 0, video_h, video_w);
   16.39 +    #else
   16.40 +       f.glViewport(0, 0, video_w, video_h);
   16.41 +    #endif /* __QNXNTO__ */
   16.42  
   16.43      f.glMatrixMode(GL_PROJECTION);
   16.44      f.glLoadIdentity();
   16.45 @@ -180,7 +188,7 @@
   16.46          f.glRotatef(2.0, 1.0, 1.0, 1.0);
   16.47          f.glRotatef(1.0, 0.0, 1.0, 1.0);
   16.48  
   16.49 -        f.glColor4ub(255, 255, 255, 255);
   16.50 +        f.glColor4f(1.0, 1.0, 1.0, 1.0);
   16.51  
   16.52          f.glEnableClientState(GL_VERTEX_ARRAY);
   16.53          f.glVertexPointer(3, GL_FLOAT, 0, pixels);
   16.54 @@ -189,6 +197,8 @@
   16.55          SDL_GL_SwapBuffers();
   16.56  
   16.57          while (SDL_PollEvent(&event)) {
   16.58 +            if (event.type == SDL_QUIT)
   16.59 +                done = 1;
   16.60              if (event.type == SDL_KEYDOWN)
   16.61                  done = 1;
   16.62          }
    17.1 --- a/test/testgl2.c	Mon Mar 23 05:37:45 2009 +0000
    17.2 +++ b/test/testgl2.c	Tue Mar 24 10:33:12 2009 +0000
    17.3 @@ -168,6 +168,7 @@
    17.4      SDL_DisplayMode mode;
    17.5      SDL_Event event;
    17.6      Uint32 then, now, frames;
    17.7 +    int status;
    17.8  
    17.9      /* Initialize parameters */
   17.10      fsaa = 0;
   17.11 @@ -241,26 +242,52 @@
   17.12      printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
   17.13      printf("\n");
   17.14  
   17.15 -    SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
   17.16 -    printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
   17.17 -    SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
   17.18 -    printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
   17.19 -    SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
   17.20 -    printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
   17.21 -    SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
   17.22 -    printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
   17.23 -    SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &value);
   17.24 -    printf("SDL_GL_DOUBLEBUFFER: requested 1, got %d\n", value);
   17.25 +    status=SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
   17.26 +    if (!status) {
   17.27 +        printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
   17.28 +    } else {
   17.29 +        printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
   17.30 +    }
   17.31 +    status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
   17.32 +    if (!status) {
   17.33 +        printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
   17.34 +    } else {
   17.35 +        printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
   17.36 +    }
   17.37 +    status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
   17.38 +    if (!status) {
   17.39 +        printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
   17.40 +    } else {
   17.41 +        printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
   17.42 +    }
   17.43 +    status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
   17.44 +    if (!status) {
   17.45 +        printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
   17.46 +    } else {
   17.47 +        printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
   17.48 +    }
   17.49      if (fsaa) {
   17.50 -        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
   17.51 -        printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
   17.52 -        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
   17.53 -        printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
   17.54 -               value);
   17.55 +        status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
   17.56 +        if (!status) {
   17.57 +            printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
   17.58 +        } else {
   17.59 +            printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError());
   17.60 +        }
   17.61 +        status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
   17.62 +        if (!status) {
   17.63 +            printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value);
   17.64 +        } else {
   17.65 +            printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError());
   17.66 +        }
   17.67      }
   17.68      if (accel) {
   17.69 -        SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
   17.70 -        printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
   17.71 +        status=SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
   17.72 +        if (!status)
   17.73 +        {
   17.74 +            printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
   17.75 +        } else {
   17.76 +            printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError());
   17.77 +        }
   17.78      }
   17.79  
   17.80      /* Set rendering settings */
    18.1 --- a/test/testgles.c	Mon Mar 23 05:37:45 2009 +0000
    18.2 +++ b/test/testgles.c	Tue Mar 24 10:33:12 2009 +0000
    18.3 @@ -88,6 +88,7 @@
    18.4      SDL_DisplayMode mode;
    18.5      SDL_Event event;
    18.6      Uint32 then, now, frames;
    18.7 +    int status;
    18.8  
    18.9      /* Initialize parameters */
   18.10      fsaa = 0;
   18.11 @@ -160,24 +161,52 @@
   18.12      printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
   18.13      printf("\n");
   18.14  
   18.15 -    SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
   18.16 -    printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
   18.17 -    SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
   18.18 -    printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
   18.19 -    SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
   18.20 -    printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
   18.21 -    SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
   18.22 -    printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
   18.23 +    status=SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
   18.24 +    if (!status) {
   18.25 +        printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
   18.26 +    } else {
   18.27 +        printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
   18.28 +    }
   18.29 +    status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
   18.30 +    if (!status) {
   18.31 +        printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
   18.32 +    } else {
   18.33 +        printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
   18.34 +    }
   18.35 +    status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
   18.36 +    if (!status) {
   18.37 +        printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
   18.38 +    } else {
   18.39 +        printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
   18.40 +    }
   18.41 +    status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
   18.42 +    if (!status) {
   18.43 +        printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
   18.44 +    } else {
   18.45 +        printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
   18.46 +    }
   18.47      if (fsaa) {
   18.48 -        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
   18.49 -        printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
   18.50 -        SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
   18.51 -        printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
   18.52 -               value);
   18.53 +        status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
   18.54 +        if (!status) {
   18.55 +            printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
   18.56 +        } else {
   18.57 +            printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError());
   18.58 +        }
   18.59 +        status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
   18.60 +        if (!status) {
   18.61 +            printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value);
   18.62 +        } else {
   18.63 +            printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError());
   18.64 +        }
   18.65      }
   18.66      if (accel) {
   18.67 -        SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
   18.68 -        printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
   18.69 +        status=SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
   18.70 +        if (!status)
   18.71 +        {
   18.72 +            printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
   18.73 +        } else {
   18.74 +            printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError());
   18.75 +        }
   18.76      }
   18.77  
   18.78      /* Set rendering settings */
    19.1 --- a/test/testmultiaudio.c	Mon Mar 23 05:37:45 2009 +0000
    19.2 +++ b/test/testmultiaudio.c	Tue Mar 24 10:33:12 2009 +0000
    19.3 @@ -55,7 +55,7 @@
    19.4          spec.userdata = &cbd[0];
    19.5          cbd[0].dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
    19.6          if (cbd[0].dev == 0) {
    19.7 -            printf("Open device failed: %s\n", SDL_GetError());
    19.8 +            printf("\nOpen device failed: %s\n", SDL_GetError());
    19.9          } else {
   19.10              SDL_PauseAudioDevice(cbd[0].dev, 0);
   19.11              while (!cbd[0].done)