Added API requested in bug #43: SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Sat, 20 May 2006 04:35:58 +0000
branchSDL-1.3
changeset 16608b9d79e7eacf
parent 1659 14717b52abc0
child 1661 281d3f4870e5
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()
WhatsNew
include/SDL_audio.h
include/SDL_video.h
src/audio/SDL_audio.c
src/video/SDL_video.c
test/loopwave.c
test/testvidinfo.c
     1.1 --- a/WhatsNew	Wed May 17 08:18:28 2006 +0000
     1.2 +++ b/WhatsNew	Sat May 20 04:35:58 2006 +0000
     1.3 @@ -1,7 +1,11 @@
     1.4  
     1.5  This is a list of API changes in SDL's version history.
     1.6  
     1.7 -Version 1.0:
     1.8 +1.3.0:
     1.9 +	Added SDL_GetNumVideoDrivers() and SDL_GetVideoDriver().
    1.10 +	Replaced SDL_VideoDriverName() with SDL_GetCurrentVideoDriver()
    1.11 +	Added SDL_GetNumAudioDrivers() and SDL_GetAudioDriver().
    1.12 +	Replaced SDL_AudioDriverName() with SDL_GetCurrentAudioDriver()
    1.13  
    1.14  1.2.10:
    1.15  	If SDL_OpenAudio() is passed zero for the desired format
    1.16 @@ -416,8 +420,6 @@
    1.17  1.0.0:
    1.18  	New public release
    1.19  
    1.20 -Version 0.11:
    1.21 -
    1.22  0.11.5:
    1.23  	A new function SDL_GetVideoSurface() has been added, and returns
    1.24  	a pointer to the current display surface.
    1.25 @@ -436,8 +438,6 @@
    1.26  	installing fatal signal handlers on operating systems that support
    1.27  	them.
    1.28  
    1.29 -Version 0.9:
    1.30 -
    1.31  0.9.15:
    1.32  	SDL_CreateColorCursor() has been removed.  Color cursors should
    1.33  	be implemented as sprites, blitted by the application when the
     2.1 --- a/include/SDL_audio.h	Wed May 17 08:18:28 2006 +0000
     2.2 +++ b/include/SDL_audio.h	Sat May 20 04:35:58 2006 +0000
     2.3 @@ -95,6 +95,12 @@
     2.4  
     2.5  /* Function prototypes */
     2.6  
     2.7 +/* These functions return the list of built in video drivers, in the 
     2.8 + * order that they are normally initialized by default.
     2.9 + */
    2.10 +extern DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
    2.11 +extern DECLSPEC const char * SDLCALL SDL_GetAudioDriver(int index);
    2.12 +
    2.13  /* These functions are used internally, and should not be used unless you
    2.14   * have a specific need to specify the audio driver you want to use.
    2.15   * You should normally use SDL_Init() or SDL_InitSubSystem().
    2.16 @@ -102,11 +108,10 @@
    2.17  extern DECLSPEC int SDLCALL SDL_AudioInit(const char *driver_name);
    2.18  extern DECLSPEC void SDLCALL SDL_AudioQuit(void);
    2.19  
    2.20 -/* This function fills the given character buffer with the name of the
    2.21 - * current audio driver, and returns a pointer to it if the audio driver has
    2.22 - * been initialized.  It returns NULL if no driver has been initialized.
    2.23 +/* This function returns the name of the current audio driver, or NULL
    2.24 + * if no driver has been initialized.
    2.25   */
    2.26 -extern DECLSPEC char * SDLCALL SDL_AudioDriverName(char *namebuf, int maxlen);
    2.27 +extern DECLSPEC const char * SDLCALL SDL_GetCurrentAudioDriver(void);
    2.28  
    2.29  /*
    2.30   * This function opens the audio device with the desired parameters, and
     3.1 --- a/include/SDL_video.h	Wed May 17 08:18:28 2006 +0000
     3.2 +++ b/include/SDL_video.h	Sat May 20 04:35:58 2006 +0000
     3.3 @@ -224,6 +224,12 @@
     3.4  
     3.5  /* Function prototypes */
     3.6  
     3.7 +/* These functions return the list of built in video drivers, in the 
     3.8 + * order that they are normally initialized by default.
     3.9 + */
    3.10 +extern DECLSPEC int SDLCALL SDL_GetNumVideoDrivers(void);
    3.11 +extern DECLSPEC const char * SDLCALL SDL_GetVideoDriver(int index);
    3.12 +
    3.13  /* These functions are used internally, and should not be used unless you
    3.14   * have a specific need to specify the video driver you want to use.
    3.15   * You should normally use SDL_Init() or SDL_InitSubSystem().
    3.16 @@ -240,11 +246,10 @@
    3.17  extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name, Uint32 flags);
    3.18  extern DECLSPEC void SDLCALL SDL_VideoQuit(void);
    3.19  
    3.20 -/* This function fills the given character buffer with the name of the
    3.21 - * video driver, and returns a pointer to it if the video driver has
    3.22 - * been initialized.  It returns NULL if no driver has been initialized.
    3.23 +/* This function returns the name of the current video driver, or NULL
    3.24 + * if no driver has been initialized.
    3.25   */
    3.26 -extern DECLSPEC char * SDLCALL SDL_VideoDriverName(char *namebuf, int maxlen);
    3.27 +extern DECLSPEC const char * SDLCALL SDL_GetCurrentVideoDriver(void);
    3.28  
    3.29  /*
    3.30   * This function returns a pointer to the current display surface.
     4.1 --- a/src/audio/SDL_audio.c	Wed May 17 08:18:28 2006 +0000
     4.2 +++ b/src/audio/SDL_audio.c	Sat May 20 04:35:58 2006 +0000
     4.3 @@ -330,6 +330,19 @@
     4.4  	return format;
     4.5  }
     4.6  
     4.7 +int SDL_GetNumAudioDrivers(void)
     4.8 +{
     4.9 +	return(SDL_arraysize(bootstrap)-1);
    4.10 +}
    4.11 +
    4.12 +const char *SDL_GetAudioDriver(int index)
    4.13 +{
    4.14 +	if ( index >= 0 && index < SDL_GetNumAudioDrivers() ) {
    4.15 +		return(bootstrap[index]->name);
    4.16 +	}
    4.17 +	return(NULL);
    4.18 +}
    4.19 +
    4.20  int SDL_AudioInit(const char *driver_name)
    4.21  {
    4.22  	SDL_AudioDevice *audio;
    4.23 @@ -419,11 +432,10 @@
    4.24  	return(0);
    4.25  }
    4.26  
    4.27 -char *SDL_AudioDriverName(char *namebuf, int maxlen)
    4.28 +const char *SDL_GetCurrentAudioDriver()
    4.29  {
    4.30 -	if ( current_audio != NULL ) {
    4.31 -		SDL_strlcpy(namebuf, current_audio->name, maxlen);
    4.32 -		return(namebuf);
    4.33 +	if ( current_audio ) {
    4.34 +		return current_audio->name;
    4.35  	}
    4.36  	return(NULL);
    4.37  }
     5.1 --- a/src/video/SDL_video.c	Wed May 17 08:18:28 2006 +0000
     5.2 +++ b/src/video/SDL_video.c	Sat May 20 04:35:58 2006 +0000
     5.3 @@ -137,6 +137,18 @@
     5.4  
     5.5  static SDL_GrabMode SDL_WM_GrabInputOff(void);
     5.6  
     5.7 +int SDL_GetNumVideoDrivers(void)
     5.8 +{
     5.9 +	return(SDL_arraysize(bootstrap)-1);
    5.10 +}
    5.11 +
    5.12 +const char *SDL_GetVideoDriver(int index)
    5.13 +{
    5.14 +	if ( index >= 0 && index < SDL_GetNumVideoDrivers() ) {
    5.15 +		return(bootstrap[index]->name);
    5.16 +	}
    5.17 +	return(NULL);
    5.18 +}
    5.19  
    5.20  /*
    5.21   * Initialize the video and event subsystems -- determine native pixel format
    5.22 @@ -278,11 +290,10 @@
    5.23  	return(0);
    5.24  }
    5.25  
    5.26 -char *SDL_VideoDriverName(char *namebuf, int maxlen)
    5.27 +const char *SDL_GetCurrentVideoDriver()
    5.28  {
    5.29 -	if ( current_video != NULL ) {
    5.30 -		SDL_strlcpy(namebuf, current_video->name, maxlen);
    5.31 -		return(namebuf);
    5.32 +	if ( current_video ) {
    5.33 +		return current_video->name;
    5.34  	}
    5.35  	return(NULL);
    5.36  }
     6.1 --- a/test/loopwave.c	Wed May 17 08:18:28 2006 +0000
     6.2 +++ b/test/loopwave.c	Sat May 20 04:35:58 2006 +0000
     6.3 @@ -62,7 +62,22 @@
     6.4  
     6.5  int main(int argc, char *argv[])
     6.6  {
     6.7 -	char name[32];
     6.8 +	int i, n;
     6.9 +
    6.10 +	/* Print available audio drivers */
    6.11 +	n = SDL_GetNumAudioDrivers();
    6.12 +	if ( n == 0 ) {
    6.13 +		printf("No built-in audio drivers\n");
    6.14 +	} else {
    6.15 +		printf("Built-in audio drivers:");
    6.16 +		for ( i = 0; i < n; ++i ) {
    6.17 +			if ( i > 0 ) {
    6.18 +				printf(",");
    6.19 +			}
    6.20 +			printf(" %s", SDL_GetAudioDriver(i));
    6.21 +		}
    6.22 +		printf("\n");
    6.23 +	}
    6.24  
    6.25  	/* Load the SDL library */
    6.26  	if ( SDL_Init(SDL_INIT_AUDIO) < 0 ) {
    6.27 @@ -102,7 +117,7 @@
    6.28  	SDL_PauseAudio(0);
    6.29  
    6.30  	/* Let the audio run */
    6.31 -	printf("Using audio driver: %s\n", SDL_AudioDriverName(name, 32));
    6.32 +	printf("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
    6.33  	while ( ! done && (SDL_GetAudioStatus() == SDL_AUDIO_PLAYING) )
    6.34  		SDL_Delay(1000);
    6.35  
     7.1 --- a/test/testvidinfo.c	Wed May 17 08:18:28 2006 +0000
     7.2 +++ b/test/testvidinfo.c	Sat May 20 04:35:58 2006 +0000
     7.3 @@ -386,16 +386,32 @@
     7.4  int main(int argc, char *argv[])
     7.5  {
     7.6  	const SDL_VideoInfo *info;
     7.7 -	int i;
     7.8 +	int i, n;
     7.9  	SDL_Rect **modes;
    7.10 -	char driver[128];
    7.11 +	const char *driver;
    7.12 +
    7.13 +	/* Print available video drivers */
    7.14 +	n = SDL_GetNumVideoDrivers();
    7.15 +	if ( n == 0 ) {
    7.16 +		printf("No built-in video drivers\n");
    7.17 +	} else {
    7.18 +		printf("Built-in video drivers:");
    7.19 +		for ( i = 0; i < n; ++i ) {
    7.20 +			if ( i > 0 ) {
    7.21 +				printf(",");
    7.22 +			}
    7.23 +			printf(" %s", SDL_GetVideoDriver(i));
    7.24 +		}
    7.25 +		printf("\n");
    7.26 +	}
    7.27  
    7.28  	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    7.29  		fprintf(stderr,
    7.30  			"Couldn't initialize SDL: %s\n", SDL_GetError());
    7.31  		exit(1);
    7.32  	}
    7.33 -	if ( SDL_VideoDriverName(driver, sizeof(driver)) ) {
    7.34 +	driver = SDL_GetCurrentVideoDriver();
    7.35 +	if ( driver ) {
    7.36  		printf("Video driver: %s\n", driver);
    7.37  	}
    7.38  	info = SDL_GetVideoInfo();