Mercurial > sdl-ios-xcode
comparison src/SDL_compat.c @ 1967:01e29c3e9a29
In general, fill in pointers to structures, rather than return them.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 05 Aug 2006 22:34:23 +0000 |
parents | a788656ca29a |
children | 5d3724f64f2b |
comparison
equal
deleted
inserted
replaced
1966:6472256c21eb | 1967:01e29c3e9a29 |
---|---|
63 | 63 |
64 const SDL_VideoInfo * | 64 const SDL_VideoInfo * |
65 SDL_GetVideoInfo(void) | 65 SDL_GetVideoInfo(void) |
66 { | 66 { |
67 static SDL_VideoInfo info; | 67 static SDL_VideoInfo info; |
68 SDL_DisplayMode mode; | |
68 | 69 |
69 /* Memory leak, compatibility code, who cares? */ | 70 /* Memory leak, compatibility code, who cares? */ |
70 if (!info.vfmt && SDL_GetDesktopDisplayMode()) { | 71 if (!info.vfmt && SDL_GetDesktopDisplayMode(&mode) == 0) { |
71 int bpp; | 72 int bpp; |
72 Uint32 Rmask, Gmask, Bmask, Amask; | 73 Uint32 Rmask, Gmask, Bmask, Amask; |
73 | 74 |
74 SDL_PixelFormatEnumToMasks(SDL_GetDesktopDisplayMode()->format, &bpp, | 75 SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, &Bmask, |
75 &Rmask, &Gmask, &Bmask, &Amask); | 76 &Amask); |
76 info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask); | 77 info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask); |
77 } | 78 } |
78 return &info; | 79 return &info; |
79 } | 80 } |
80 | 81 |
86 if (!SDL_GetVideoDevice()) { | 87 if (!SDL_GetVideoDevice()) { |
87 return 0; | 88 return 0; |
88 } | 89 } |
89 | 90 |
90 if (!(flags & SDL_FULLSCREEN)) { | 91 if (!(flags & SDL_FULLSCREEN)) { |
91 return SDL_BITSPERPIXEL(SDL_GetDesktopDisplayMode()->format); | 92 SDL_DisplayMode mode; |
93 SDL_GetDesktopDisplayMode(&mode); | |
94 return SDL_BITSPERPIXEL(mode.format); | |
92 } | 95 } |
93 | 96 |
94 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { | 97 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { |
95 const SDL_DisplayMode *mode = SDL_GetDisplayMode(i); | 98 SDL_DisplayMode mode; |
96 if (!mode->w || !mode->h || (width == mode->w && height == mode->h)) { | 99 SDL_GetDisplayMode(i, &mode); |
97 if (!mode->format) { | 100 if (!mode.w || !mode.h || (width == mode.w && height == mode.h)) { |
101 if (!mode.format) { | |
98 return bpp; | 102 return bpp; |
99 } | 103 } |
100 if (SDL_BITSPERPIXEL(mode->format) >= (Uint32) bpp) { | 104 if (SDL_BITSPERPIXEL(mode.format) >= (Uint32) bpp) { |
101 actual_bpp = SDL_BITSPERPIXEL(mode->format); | 105 actual_bpp = SDL_BITSPERPIXEL(mode.format); |
102 } | 106 } |
103 } | 107 } |
104 } | 108 } |
105 return actual_bpp; | 109 return actual_bpp; |
106 } | 110 } |
121 | 125 |
122 /* Memory leak, but this is a compatibility function, who cares? */ | 126 /* Memory leak, but this is a compatibility function, who cares? */ |
123 nmodes = 0; | 127 nmodes = 0; |
124 modes = NULL; | 128 modes = NULL; |
125 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { | 129 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { |
126 const SDL_DisplayMode *mode = SDL_GetDisplayMode(i); | 130 SDL_DisplayMode mode; |
127 if (!mode->w || !mode->h) { | 131 SDL_GetDisplayMode(i, &mode); |
132 if (!mode.w || !mode.h) { | |
128 return (SDL_Rect **) (-1); | 133 return (SDL_Rect **) (-1); |
129 } | 134 } |
130 if (SDL_BITSPERPIXEL(mode->format) != format->BitsPerPixel) { | 135 if (SDL_BITSPERPIXEL(mode.format) != format->BitsPerPixel) { |
131 continue; | 136 continue; |
132 } | 137 } |
133 if (nmodes > 0 && modes[nmodes - 1]->w == mode->w | 138 if (nmodes > 0 && modes[nmodes - 1]->w == mode.w |
134 && modes[nmodes - 1]->h == mode->h) { | 139 && modes[nmodes - 1]->h == mode.h) { |
135 continue; | 140 continue; |
136 } | 141 } |
137 | 142 |
138 modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes)); | 143 modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes)); |
139 if (!modes) { | 144 if (!modes) { |
143 if (!modes[nmodes]) { | 148 if (!modes[nmodes]) { |
144 return NULL; | 149 return NULL; |
145 } | 150 } |
146 modes[nmodes]->x = 0; | 151 modes[nmodes]->x = 0; |
147 modes[nmodes]->y = 0; | 152 modes[nmodes]->y = 0; |
148 modes[nmodes]->w = mode->w; | 153 modes[nmodes]->w = mode.w; |
149 modes[nmodes]->h = mode->h; | 154 modes[nmodes]->h = mode.h; |
150 ++nmodes; | 155 ++nmodes; |
151 } | 156 } |
152 if (modes) { | 157 if (modes) { |
153 modes[nmodes] = NULL; | 158 modes[nmodes] = NULL; |
154 } | 159 } |
298 if (SDL_strcmp(window, "center") == 0) { | 303 if (SDL_strcmp(window, "center") == 0) { |
299 center = window; | 304 center = window; |
300 } | 305 } |
301 } | 306 } |
302 if (center) { | 307 if (center) { |
303 const SDL_DisplayMode *current = SDL_GetDesktopDisplayMode(); | 308 SDL_DisplayMode mode; |
304 *x = (current->w - w) / 2; | 309 SDL_GetDesktopDisplayMode(&mode); |
305 *y = (current->h - h) / 2; | 310 *x = (mode.w - w) / 2; |
311 *y = (mode.h - h) / 2; | |
306 } | 312 } |
307 } | 313 } |
308 | 314 |
309 SDL_Surface * | 315 SDL_Surface * |
310 SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) | 316 SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags) |
311 { | 317 { |
312 const SDL_DisplayMode *desktop_mode; | 318 SDL_DisplayMode desktop_mode; |
313 SDL_DisplayMode mode; | 319 SDL_DisplayMode mode; |
314 int window_x = SDL_WINDOWPOS_UNDEFINED; | 320 int window_x = SDL_WINDOWPOS_UNDEFINED; |
315 int window_y = SDL_WINDOWPOS_UNDEFINED; | 321 int window_y = SDL_WINDOWPOS_UNDEFINED; |
316 Uint32 window_flags; | 322 Uint32 window_flags; |
317 Uint32 desktop_format; | 323 Uint32 desktop_format; |
388 if (window_flags & SDL_WINDOW_BORDERLESS) { | 394 if (window_flags & SDL_WINDOW_BORDERLESS) { |
389 surface_flags |= SDL_NOFRAME; | 395 surface_flags |= SDL_NOFRAME; |
390 } | 396 } |
391 | 397 |
392 /* Set up the desired display mode */ | 398 /* Set up the desired display mode */ |
393 desktop_mode = SDL_GetDesktopDisplayMode(); | 399 SDL_GetDesktopDisplayMode(&desktop_mode); |
394 desktop_format = desktop_mode->format; | 400 desktop_format = desktop_mode.format; |
395 if (desktop_format && ((flags & SDL_ANYFORMAT) | 401 if (desktop_format && ((flags & SDL_ANYFORMAT) |
396 || (bpp == SDL_BITSPERPIXEL(desktop_format)))) { | 402 || (bpp == SDL_BITSPERPIXEL(desktop_format)))) { |
397 desired_format = desktop_format; | 403 desired_format = desktop_format; |
398 } else { | 404 } else { |
399 switch (bpp) { | 405 switch (bpp) { |