In general, fill in pointers to structures, rather than return them.
--- a/include/SDL_audio.h Sat Aug 05 17:12:22 2006 +0000
+++ b/include/SDL_audio.h Sat Aug 05 22:34:23 2006 +0000
@@ -237,7 +237,8 @@
* Must be a value between 0 and (number of audio devices-1).
* Only valid after a successfully initializing the audio subsystem.
*/
-extern DECLSPEC const char *SDLCALL SDL_GetAudioDevice(int index, int iscapture);
+extern DECLSPEC const char *SDLCALL SDL_GetAudioDevice(int index,
+ int iscapture);
/*
@@ -245,11 +246,14 @@
* equivalent to SDL_OpenAudio(). Returns 0 on error, a valid device ID
* on success.
*/
-extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(
- const char * device,
- int iscapture,
- const SDL_AudioSpec * desired,
- SDL_AudioSpec * obtained);
+extern DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(const char
+ *device,
+ int iscapture,
+ const
+ SDL_AudioSpec *
+ desired,
+ SDL_AudioSpec *
+ obtained);
@@ -264,8 +268,8 @@
} SDL_audiostatus;
extern DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioStatus(void);
-extern DECLSPEC SDL_audiostatus SDLCALL SDL_GetAudioDeviceStatus(
- SDL_AudioDeviceID dev);
+extern DECLSPEC SDL_audiostatus SDLCALL
+SDL_GetAudioDeviceStatus(SDL_AudioDeviceID dev);
/*
* This function pauses and unpauses the audio callback processing.
@@ -352,7 +356,8 @@
* using the format of audio device 1. Thus it can be used when no audio
* device is open at all.
*/
-extern DECLSPEC void SDLCALL SDL_MixAudioFormat(Uint8 * dst, const Uint8 * src,
+extern DECLSPEC void SDLCALL SDL_MixAudioFormat(Uint8 * dst,
+ const Uint8 * src,
SDL_AudioFormat format,
Uint32 len, int volume);
--- a/include/SDL_video.h Sat Aug 05 17:12:22 2006 +0000
+++ b/include/SDL_video.h Sat Aug 05 22:34:23 2006 +0000
@@ -432,7 +432,7 @@
extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(void);
/**
- * \fn const SDL_DisplayMode *SDL_GetDisplayMode(int index)
+ * \fn int SDL_GetDisplayMode(int index, SDL_DisplayMode *mode)
*
* \brief Retrieve information about a specific display mode.
*
@@ -444,23 +444,22 @@
*
* \sa SDL_GetNumDisplayModes()
*/
-extern DECLSPEC const SDL_DisplayMode *SDLCALL SDL_GetDisplayMode(int index);
+extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int index,
+ SDL_DisplayMode * mode);
/**
- * \fn const SDL_DisplayMode *SDL_GetDesktopDisplayMode(void)
+ * \fn int SDL_GetDesktopDisplayMode(SDL_DisplayMode *mode)
*
* \brief Retrieve information about the desktop display mode for the current display.
*/
-extern DECLSPEC const SDL_DisplayMode *SDLCALL
-SDL_GetDesktopDisplayMode(void);
+extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode);
/**
- * \fn const SDL_DisplayMode *SDL_GetCurrentDisplayMode(void)
+ * \fn int SDL_GetCurrentDisplayMode(SDL_DisplayMode *mode)
*
* \brief Retrieve information about the current display mode.
*/
-extern DECLSPEC const SDL_DisplayMode *SDLCALL
-SDL_GetCurrentDisplayMode(void);
+extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode);
/**
* \fn SDL_DisplayMode *SDL_GetClosestDisplayMode(const SDL_DisplayMode *mode, SDL_DisplayMode *closest)
@@ -499,13 +498,13 @@
* mode);
/**
- * \fn const SDL_DisplayMode *SDL_GetFullscreenDisplayMode(void)
+ * \fn int SDL_GetFullscreenDisplayMode(SDL_DisplayMode *mode)
*
* \brief Query the display mode used when a fullscreen window is visible
* on the currently selected display.
*/
-extern DECLSPEC const SDL_DisplayMode *SDLCALL
-SDL_GetFullscreenDisplayMode(void);
+extern DECLSPEC int SDLCALL SDL_GetFullscreenDisplayMode(SDL_DisplayMode *
+ mode);
/**
* \fn int SDL_SetDisplayPalette(const SDL_Color *colors, int firstcolor, int ncolors)
--- a/src/SDL_compat.c Sat Aug 05 17:12:22 2006 +0000
+++ b/src/SDL_compat.c Sat Aug 05 22:34:23 2006 +0000
@@ -65,14 +65,15 @@
SDL_GetVideoInfo(void)
{
static SDL_VideoInfo info;
+ SDL_DisplayMode mode;
/* Memory leak, compatibility code, who cares? */
- if (!info.vfmt && SDL_GetDesktopDisplayMode()) {
+ if (!info.vfmt && SDL_GetDesktopDisplayMode(&mode) == 0) {
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
- SDL_PixelFormatEnumToMasks(SDL_GetDesktopDisplayMode()->format, &bpp,
- &Rmask, &Gmask, &Bmask, &Amask);
+ SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask,
+ &Amask);
info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
}
return &info;
@@ -88,17 +89,20 @@
}
if (!(flags & SDL_FULLSCREEN)) {
- return SDL_BITSPERPIXEL(SDL_GetDesktopDisplayMode()->format);
+ SDL_DisplayMode mode;
+ SDL_GetDesktopDisplayMode(&mode);
+ return SDL_BITSPERPIXEL(mode.format);
}
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
- const SDL_DisplayMode *mode = SDL_GetDisplayMode(i);
- if (!mode->w || !mode->h || (width == mode->w && height == mode->h)) {
- if (!mode->format) {
+ SDL_DisplayMode mode;
+ SDL_GetDisplayMode(i, &mode);
+ if (!mode.w || !mode.h || (width == mode.w && height == mode.h)) {
+ if (!mode.format) {
return bpp;
}
- if (SDL_BITSPERPIXEL(mode->format) >= (Uint32) bpp) {
- actual_bpp = SDL_BITSPERPIXEL(mode->format);
+ if (SDL_BITSPERPIXEL(mode.format) >= (Uint32) bpp) {
+ actual_bpp = SDL_BITSPERPIXEL(mode.format);
}
}
}
@@ -123,15 +127,16 @@
nmodes = 0;
modes = NULL;
for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
- const SDL_DisplayMode *mode = SDL_GetDisplayMode(i);
- if (!mode->w || !mode->h) {
+ SDL_DisplayMode mode;
+ SDL_GetDisplayMode(i, &mode);
+ if (!mode.w || !mode.h) {
return (SDL_Rect **) (-1);
}
- if (SDL_BITSPERPIXEL(mode->format) != format->BitsPerPixel) {
+ if (SDL_BITSPERPIXEL(mode.format) != format->BitsPerPixel) {
continue;
}
- if (nmodes > 0 && modes[nmodes - 1]->w == mode->w
- && modes[nmodes - 1]->h == mode->h) {
+ if (nmodes > 0 && modes[nmodes - 1]->w == mode.w
+ && modes[nmodes - 1]->h == mode.h) {
continue;
}
@@ -145,8 +150,8 @@
}
modes[nmodes]->x = 0;
modes[nmodes]->y = 0;
- modes[nmodes]->w = mode->w;
- modes[nmodes]->h = mode->h;
+ modes[nmodes]->w = mode.w;
+ modes[nmodes]->h = mode.h;
++nmodes;
}
if (modes) {
@@ -300,16 +305,17 @@
}
}
if (center) {
- const SDL_DisplayMode *current = SDL_GetDesktopDisplayMode();
- *x = (current->w - w) / 2;
- *y = (current->h - h) / 2;
+ SDL_DisplayMode mode;
+ SDL_GetDesktopDisplayMode(&mode);
+ *x = (mode.w - w) / 2;
+ *y = (mode.h - h) / 2;
}
}
SDL_Surface *
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
{
- const SDL_DisplayMode *desktop_mode;
+ SDL_DisplayMode desktop_mode;
SDL_DisplayMode mode;
int window_x = SDL_WINDOWPOS_UNDEFINED;
int window_y = SDL_WINDOWPOS_UNDEFINED;
@@ -390,8 +396,8 @@
}
/* Set up the desired display mode */
- desktop_mode = SDL_GetDesktopDisplayMode();
- desktop_format = desktop_mode->format;
+ SDL_GetDesktopDisplayMode(&desktop_mode);
+ desktop_format = desktop_mode.format;
if (desktop_format && ((flags & SDL_ANYFORMAT)
|| (bpp == SDL_BITSPERPIXEL(desktop_format)))) {
desired_format = desktop_format;
--- a/src/video/SDL_video.c Sat Aug 05 17:12:22 2006 +0000
+++ b/src/video/SDL_video.c Sat Aug 05 22:34:23 2006 +0000
@@ -422,33 +422,44 @@
return 0;
}
-const SDL_DisplayMode *
-SDL_GetDisplayMode(int index)
+int
+SDL_GetDisplayMode(int index, SDL_DisplayMode * mode)
{
if (index < 0 || index >= SDL_GetNumDisplayModes()) {
SDL_SetError("index must be in the range of 0 - %d",
SDL_GetNumDisplayModes() - 1);
- return NULL;
+ return -1;
}
- return &SDL_CurrentDisplay.display_modes[index];
+ if (mode) {
+ *mode = SDL_CurrentDisplay.display_modes[index];
+ }
+ return 0;
}
-const SDL_DisplayMode *
-SDL_GetDesktopDisplayMode(void)
+int
+SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode)
{
- if (_this) {
- return &SDL_CurrentDisplay.desktop_mode;
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return -1;
}
- return NULL;
+ if (mode) {
+ *mode = SDL_CurrentDisplay.desktop_mode;
+ }
+ return 0;
}
-const SDL_DisplayMode *
-SDL_GetCurrentDisplayMode(void)
+int
+SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode)
{
- if (_this) {
- return &SDL_CurrentDisplay.current_mode;
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return -1;
}
- return NULL;
+ if (mode) {
+ *mode = SDL_CurrentDisplay.current_mode;
+ }
+ return 0;
}
SDL_DisplayMode *
@@ -549,6 +560,7 @@
{
SDL_VideoDisplay *display;
SDL_DisplayMode display_mode;
+ SDL_DisplayMode current_mode;
int i, ncolors;
if (!_this) {
@@ -556,10 +568,10 @@
return -1;
}
+ display = &SDL_CurrentDisplay;
if (!mode) {
- mode = SDL_GetDesktopDisplayMode();
+ mode = &display->desktop_mode;
}
- display = &SDL_CurrentDisplay;
display_mode = *mode;
/* Default to the current mode */
@@ -584,9 +596,8 @@
}
/* See if there's anything left to do */
- if (SDL_memcmp
- (&display_mode, SDL_GetCurrentDisplayMode(),
- sizeof(display_mode)) == 0) {
+ SDL_GetCurrentDisplayMode(¤t_mode);
+ if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) {
return 0;
}
@@ -659,13 +670,17 @@
return 0;
}
-const SDL_DisplayMode *
-SDL_GetFullscreenDisplayMode(void)
+int
+SDL_GetFullscreenDisplayMode(SDL_DisplayMode * mode)
{
- if (_this) {
- return SDL_CurrentDisplay.fullscreen_mode;
+ if (!_this) {
+ SDL_UninitializedVideo();
+ return -1;
}
- return NULL;
+ if (mode) {
+ *mode = *SDL_CurrentDisplay.fullscreen_mode;
+ }
+ return 0;
}
int
--- a/src/video/cocoa/SDL_cocoakeyboard.h Sat Aug 05 17:12:22 2006 +0000
+++ b/src/video/cocoa/SDL_cocoakeyboard.h Sat Aug 05 22:34:23 2006 +0000
@@ -25,7 +25,7 @@
#define _SDL_cocoakeyboard_h
extern void Cocoa_InitKeyboard(_THIS);
-extern void Cocoa_HandleKeyEvent(_THIS, NSEvent *event);
+extern void Cocoa_HandleKeyEvent(_THIS, NSEvent * event);
extern void Cocoa_QuitKeyboard(_THIS);
#endif /* _SDL_cocoakeyboard_h */
--- a/test/common.c Sat Aug 05 17:12:22 2006 +0000
+++ b/test/common.c Sat Aug 05 22:34:23 2006 +0000
@@ -545,7 +545,7 @@
}
if (state->verbose & VERBOSE_MODES) {
- const SDL_DisplayMode *mode;
+ SDL_DisplayMode mode;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
@@ -555,12 +555,12 @@
fprintf(stderr, "Display %d:\n", i);
SDL_SelectVideoDisplay(i);
- mode = SDL_GetDesktopDisplayMode();
- SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, &Gmask,
+ SDL_GetDesktopDisplayMode(&mode);
+ SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
&Bmask, &Amask);
fprintf(stderr,
" Current mode: %dx%d@%dHz, %d bits-per-pixel\n",
- mode->w, mode->h, mode->refresh_rate, bpp);
+ mode.w, mode.h, mode.refresh_rate, bpp);
if (Rmask || Gmask || Bmask) {
fprintf(stderr, " Red Mask = 0x%.8x\n", Rmask);
fprintf(stderr, " Green Mask = 0x%.8x\n", Gmask);
@@ -576,12 +576,12 @@
} else {
fprintf(stderr, " Fullscreen video modes:\n");
for (j = 0; j < m; ++j) {
- mode = SDL_GetDisplayMode(j);
- SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask,
+ SDL_GetDisplayMode(j, &mode);
+ SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
&Gmask, &Bmask, &Amask);
fprintf(stderr,
" Mode %d: %dx%d@%dHz, %d bits-per-pixel\n",
- j, mode->w, mode->h, mode->refresh_rate, bpp);
+ j, mode.w, mode.h, mode.refresh_rate, bpp);
if (Rmask || Gmask || Bmask) {
fprintf(stderr, " Red Mask = 0x%.8x\n",
Rmask);
--- a/test/testgl2.c Sat Aug 05 17:12:22 2006 +0000
+++ b/test/testgl2.c Sat Aug 05 22:34:23 2006 +0000
@@ -165,6 +165,7 @@
int fsaa, accel;
int value;
int i, done;
+ SDL_DisplayMode mode;
SDL_Event event;
Uint32 then, now, frames;
@@ -235,8 +236,8 @@
SDL_GL_SetSwapInterval(0);
}
- printf("Screen BPP: %d\n",
- SDL_BITSPERPIXEL(SDL_GetCurrentDisplayMode()->format));
+ SDL_GetCurrentDisplayMode(&mode);
+ printf("Screen BPP: %d\n", SDL_BITSPERPIXEL(mode.format));
printf("\n");
printf("Vendor : %s\n", glGetString(GL_VENDOR));
printf("Renderer : %s\n", glGetString(GL_RENDERER));
--- a/test/testvidinfo.c Sat Aug 05 17:12:22 2006 +0000
+++ b/test/testvidinfo.c Sat Aug 05 22:34:23 2006 +0000
@@ -419,7 +419,7 @@
const SDL_VideoInfo *info;
int i, d, n;
const char *driver;
- const SDL_DisplayMode *mode;
+ SDL_DisplayMode mode;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
int nmodes;
@@ -452,11 +452,11 @@
printf("Display %d:\n", d);
SDL_SelectVideoDisplay(d);
- mode = SDL_GetDesktopDisplayMode();
- SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, &Gmask, &Bmask,
+ SDL_GetDesktopDisplayMode(&mode);
+ SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask,
&Amask);
- printf(" Current mode: %dx%d@%dHz, %d bits-per-pixel\n", mode->w,
- mode->h, mode->refresh_rate, bpp);
+ printf(" Current mode: %dx%d@%dHz, %d bits-per-pixel\n", mode.w,
+ mode.h, mode.refresh_rate, bpp);
if (Rmask || Gmask || Bmask) {
printf(" Red Mask = 0x%.8x\n", Rmask);
printf(" Green Mask = 0x%.8x\n", Gmask);
@@ -472,11 +472,11 @@
} else {
printf(" Fullscreen video modes:\n");
for (i = 0; i < nmodes; ++i) {
- mode = SDL_GetDisplayMode(i);
- SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask,
+ SDL_GetDisplayMode(i, &mode);
+ SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
&Gmask, &Bmask, &Amask);
printf(" Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", i,
- mode->w, mode->h, mode->refresh_rate, bpp);
+ mode.w, mode.h, mode.refresh_rate, bpp);
if (Rmask || Gmask || Bmask) {
printf(" Red Mask = 0x%.8x\n", Rmask);
printf(" Green Mask = 0x%.8x\n", Gmask);