Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
In general, fill in pointers to structures, rather than return them.
  • Loading branch information
slouken committed Aug 5, 2006
1 parent ac528b8 commit 701d787
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 84 deletions.
23 changes: 14 additions & 9 deletions include/SDL_audio.h
Expand Up @@ -237,19 +237,23 @@ extern DECLSPEC int SDLCALL SDL_GetNumAudioDevices(int iscapture);
* 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);


/*
* Open a specific audio device. Passing in a device name of NULL is
* 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);



Expand All @@ -264,8 +268,8 @@ typedef enum
} 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.
Expand Down Expand Up @@ -352,7 +356,8 @@ extern DECLSPEC void SDLCALL SDL_MixAudio(Uint8 * dst, const Uint8 * src,
* 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);

Expand Down
21 changes: 10 additions & 11 deletions include/SDL_video.h
Expand Up @@ -432,7 +432,7 @@ extern DECLSPEC int SDLCALL SDL_GetCurrentVideoDisplay(void);
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.
*
Expand All @@ -444,23 +444,22 @@ extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(void);
*
* \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)
Expand Down Expand Up @@ -499,13 +498,13 @@ extern DECLSPEC int SDLCALL SDL_SetFullscreenDisplayMode(const SDL_DisplayMode
* 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)
Expand Down
50 changes: 28 additions & 22 deletions src/SDL_compat.c
Expand Up @@ -65,14 +65,15 @@ const SDL_VideoInfo *
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;
Expand All @@ -88,17 +89,20 @@ SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
}

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);
}
}
}
Expand All @@ -123,15 +127,16 @@ SDL_ListModes(SDL_PixelFormat * format, Uint32 flags)
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;
}

Expand All @@ -145,8 +150,8 @@ SDL_ListModes(SDL_PixelFormat * format, Uint32 flags)
}
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) {
Expand Down Expand Up @@ -300,16 +305,17 @@ GetEnvironmentWindowPosition(int w, int h, int *x, int *y)
}
}
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;
Expand Down Expand Up @@ -390,8 +396,8 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
}

/* 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;
Expand Down
63 changes: 39 additions & 24 deletions src/video/SDL_video.c
Expand Up @@ -422,33 +422,44 @@ SDL_GetNumDisplayModes()
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;
}
if (mode) {
*mode = SDL_CurrentDisplay.display_modes[index];
}
return &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 *
Expand Down Expand Up @@ -549,17 +560,18 @@ SDL_SetDisplayMode(const SDL_DisplayMode * mode)
{
SDL_VideoDisplay *display;
SDL_DisplayMode display_mode;
SDL_DisplayMode current_mode;
int i, ncolors;

if (!_this) {
SDL_UninitializedVideo();
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 */
Expand All @@ -584,9 +596,8 @@ SDL_SetDisplayMode(const SDL_DisplayMode * mode)
}

/* See if there's anything left to do */
if (SDL_memcmp
(&display_mode, SDL_GetCurrentDisplayMode(),
sizeof(display_mode)) == 0) {
SDL_GetCurrentDisplayMode(&current_mode);
if (SDL_memcmp(&display_mode, &current_mode, sizeof(display_mode)) == 0) {
return 0;
}

Expand Down Expand Up @@ -659,13 +670,17 @@ SDL_SetFullscreenDisplayMode(const SDL_DisplayMode * mode)
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
Expand Down
2 changes: 1 addition & 1 deletion src/video/cocoa/SDL_cocoakeyboard.h
Expand Up @@ -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 */
Expand Down
14 changes: 7 additions & 7 deletions test/common.c
Expand Up @@ -545,7 +545,7 @@ CommonInit(CommonState * state)
}

if (state->verbose & VERBOSE_MODES) {
const SDL_DisplayMode *mode;
SDL_DisplayMode mode;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;

Expand All @@ -555,12 +555,12 @@ CommonInit(CommonState * state)
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);
Expand All @@ -576,12 +576,12 @@ CommonInit(CommonState * state)
} 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);
Expand Down

0 comments on commit 701d787

Please sign in to comment.