Added API requested in bug #43:
Added SDL_GetNumVideoDrivers() and SDL_GetVideoDriver().
Replaced SDL_VideoDriverName() with SDL_GetCurrentVideoDriver()
Added SDL_GetNumAudioDrivers() and SDL_GetAudioDriver().
Replaced SDL_AudioDriverName() with SDL_GetCurrentAudioDriver()
--- a/WhatsNew Wed May 17 08:18:28 2006 +0000
+++ b/WhatsNew Sat May 20 04:35:58 2006 +0000
@@ -1,7 +1,11 @@
This is a list of API changes in SDL's version history.
-Version 1.0:
+1.3.0:
+ Added SDL_GetNumVideoDrivers() and SDL_GetVideoDriver().
+ Replaced SDL_VideoDriverName() with SDL_GetCurrentVideoDriver()
+ Added SDL_GetNumAudioDrivers() and SDL_GetAudioDriver().
+ Replaced SDL_AudioDriverName() with SDL_GetCurrentAudioDriver()
1.2.10:
If SDL_OpenAudio() is passed zero for the desired format
@@ -416,8 +420,6 @@
1.0.0:
New public release
-Version 0.11:
-
0.11.5:
A new function SDL_GetVideoSurface() has been added, and returns
a pointer to the current display surface.
@@ -436,8 +438,6 @@
installing fatal signal handlers on operating systems that support
them.
-Version 0.9:
-
0.9.15:
SDL_CreateColorCursor() has been removed. Color cursors should
be implemented as sprites, blitted by the application when the
--- a/include/SDL_audio.h Wed May 17 08:18:28 2006 +0000
+++ b/include/SDL_audio.h Sat May 20 04:35:58 2006 +0000
@@ -95,6 +95,12 @@
/* Function prototypes */
+/* These functions return the list of built in video drivers, in the
+ * order that they are normally initialized by default.
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
+extern DECLSPEC const char * SDLCALL SDL_GetAudioDriver(int index);
+
/* These functions are used internally, and should not be used unless you
* have a specific need to specify the audio driver you want to use.
* You should normally use SDL_Init() or SDL_InitSubSystem().
@@ -102,11 +108,10 @@
extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name);
extern DECLSPEC void SDLCALL SDL_AudioQuit(void);
-/* This function fills the given character buffer with the name of the
- * current audio driver, and returns a pointer to it if the audio driver has
- * been initialized. It returns NULL if no driver has been initialized.
+/* This function returns the name of the current audio driver, or NULL
+ * if no driver has been initialized.
*/
-extern DECLSPEC char * SDLCALL SDL_AudioDriverName(char *namebuf, int maxlen);
+extern DECLSPEC const char * SDLCALL SDL_GetCurrentAudioDriver(void);
/*
* This function opens the audio device with the desired parameters, and
--- a/include/SDL_video.h Wed May 17 08:18:28 2006 +0000
+++ b/include/SDL_video.h Sat May 20 04:35:58 2006 +0000
@@ -224,6 +224,12 @@
/* Function prototypes */
+/* These functions return the list of built in video drivers, in the
+ * order that they are normally initialized by default.
+ */
+extern DECLSPEC int SDLCALL SDL_GetNumVideoDrivers(void);
+extern DECLSPEC const char * SDLCALL SDL_GetVideoDriver(int index);
+
/* These functions are used internally, and should not be used unless you
* have a specific need to specify the video driver you want to use.
* You should normally use SDL_Init() or SDL_InitSubSystem().
@@ -240,11 +246,10 @@
extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name, Uint32 flags);
extern DECLSPEC void SDLCALL SDL_VideoQuit(void);
-/* This function fills the given character buffer with the name of the
- * video driver, and returns a pointer to it if the video driver has
- * been initialized. It returns NULL if no driver has been initialized.
+/* This function returns the name of the current video driver, or NULL
+ * if no driver has been initialized.
*/
-extern DECLSPEC char * SDLCALL SDL_VideoDriverName(char *namebuf, int maxlen);
+extern DECLSPEC const char * SDLCALL SDL_GetCurrentVideoDriver(void);
/*
* This function returns a pointer to the current display surface.
--- a/src/audio/SDL_audio.c Wed May 17 08:18:28 2006 +0000
+++ b/src/audio/SDL_audio.c Sat May 20 04:35:58 2006 +0000
@@ -330,6 +330,19 @@
return format;
}
+int SDL_GetNumAudioDrivers(void)
+{
+ return(SDL_arraysize(bootstrap)-1);
+}
+
+const char *SDL_GetAudioDriver(int index)
+{
+ if ( index >= 0 && index < SDL_GetNumAudioDrivers() ) {
+ return(bootstrap[index]->name);
+ }
+ return(NULL);
+}
+
int SDL_AudioInit(const char *driver_name)
{
SDL_AudioDevice *audio;
@@ -419,11 +432,10 @@
return(0);
}
-char *SDL_AudioDriverName(char *namebuf, int maxlen)
+const char *SDL_GetCurrentAudioDriver()
{
- if ( current_audio != NULL ) {
- SDL_strlcpy(namebuf, current_audio->name, maxlen);
- return(namebuf);
+ if ( current_audio ) {
+ return current_audio->name;
}
return(NULL);
}
--- a/src/video/SDL_video.c Wed May 17 08:18:28 2006 +0000
+++ b/src/video/SDL_video.c Sat May 20 04:35:58 2006 +0000
@@ -137,6 +137,18 @@
static SDL_GrabMode SDL_WM_GrabInputOff(void);
+int SDL_GetNumVideoDrivers(void)
+{
+ return(SDL_arraysize(bootstrap)-1);
+}
+
+const char *SDL_GetVideoDriver(int index)
+{
+ if ( index >= 0 && index < SDL_GetNumVideoDrivers() ) {
+ return(bootstrap[index]->name);
+ }
+ return(NULL);
+}
/*
* Initialize the video and event subsystems -- determine native pixel format
@@ -278,11 +290,10 @@
return(0);
}
-char *SDL_VideoDriverName(char *namebuf, int maxlen)
+const char *SDL_GetCurrentVideoDriver()
{
- if ( current_video != NULL ) {
- SDL_strlcpy(namebuf, current_video->name, maxlen);
- return(namebuf);
+ if ( current_video ) {
+ return current_video->name;
}
return(NULL);
}
--- a/test/loopwave.c Wed May 17 08:18:28 2006 +0000
+++ b/test/loopwave.c Sat May 20 04:35:58 2006 +0000
@@ -62,7 +62,22 @@
int main(int argc, char *argv[])
{
- char name[32];
+ int i, n;
+
+ /* Print available audio drivers */
+ n = SDL_GetNumAudioDrivers();
+ if ( n == 0 ) {
+ printf("No built-in audio drivers\n");
+ } else {
+ printf("Built-in audio drivers:");
+ for ( i = 0; i < n; ++i ) {
+ if ( i > 0 ) {
+ printf(",");
+ }
+ printf(" %s", SDL_GetAudioDriver(i));
+ }
+ printf("\n");
+ }
/* Load the SDL library */
if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
@@ -102,7 +117,7 @@
SDL_PauseAudio(0);
/* Let the audio run */
- printf("Using audio driver: %s\n", SDL_AudioDriverName(name, 32));
+ printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
while ( ! done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) )
SDL_Delay(1000);
--- a/test/testvidinfo.c Wed May 17 08:18:28 2006 +0000
+++ b/test/testvidinfo.c Sat May 20 04:35:58 2006 +0000
@@ -386,16 +386,32 @@
int main(int argc, char *argv[])
{
const SDL_VideoInfo *info;
- int i;
+ int i, n;
SDL_Rect **modes;
- char driver[128];
+ const char *driver;
+
+ /* Print available video drivers */
+ n = SDL_GetNumVideoDrivers();
+ if ( n == 0 ) {
+ printf("No built-in video drivers\n");
+ } else {
+ printf("Built-in video drivers:");
+ for ( i = 0; i < n; ++i ) {
+ if ( i > 0 ) {
+ printf(",");
+ }
+ printf(" %s", SDL_GetVideoDriver(i));
+ }
+ printf("\n");
+ }
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,
"Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
}
- if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
+ driver = SDL_GetCurrentVideoDriver();
+ if ( driver ) {
printf("Video driver: %s\n", driver);
}
info = SDL_GetVideoInfo();