Mercurial > sdl-ios-xcode
comparison src/SDL_compat.c @ 5043:da347bfed240
Florian Forster to sdl
in SDL 1.3 (revision 5508 from SVN), the method used to calculate the
bits per pixel from a “int format” differ between “SDL_ListModes” (which
always uses the “SDL_BITSPERPIXEL” macro) and “SDL_PixelFormatEnumTo-
Masks” (which uses either “SDL_BITSPERPIXEL” or “SDL_BYTESPERPIXEL * 8”,
depending on the value of “SDL_BYTESPERPIXEL”).
Because the values are later compared in “SDL_ListModes” this may lead
to some valid video modes not being returned. In my case the only mode
returned by “SDL_GetNumDisplayModes” was dismissed and NULL was
returned. (This led to the calling application sticking its head in the
sand.)
The attached patch copies the method used within “SDL_PixelFormatEnumTo-
Masks” to “SDL_ListModes”. This solved the problem for me though I don't
fully understand the method used by “SDL_PixelFormatEnumToMasks”.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 19 Jan 2011 16:06:47 -0800 |
parents | deadc1219bea |
children | 481dabb098ef |
comparison
equal
deleted
inserted
replaced
5042:8c39b82dc7b0 | 5043:da347bfed240 |
---|---|
153 /* Memory leak, but this is a compatibility function, who cares? */ | 153 /* Memory leak, but this is a compatibility function, who cares? */ |
154 nmodes = 0; | 154 nmodes = 0; |
155 modes = NULL; | 155 modes = NULL; |
156 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { | 156 for (i = 0; i < SDL_GetNumDisplayModes(); ++i) { |
157 SDL_DisplayMode mode; | 157 SDL_DisplayMode mode; |
158 int bpp; | |
159 | |
158 SDL_GetDisplayMode(i, &mode); | 160 SDL_GetDisplayMode(i, &mode); |
159 if (!mode.w || !mode.h) { | 161 if (!mode.w || !mode.h) { |
160 return (SDL_Rect **) (-1); | 162 return (SDL_Rect **) (-1); |
161 } | 163 } |
162 if (SDL_BITSPERPIXEL(mode.format) != format->BitsPerPixel) { | 164 |
165 /* Copied from src/video/SDL_pixels.c:SDL_PixelFormatEnumToMasks */ | |
166 if (SDL_BYTESPERPIXEL(mode.format) <= 2) { | |
167 bpp = SDL_BITSPERPIXEL(mode.format); | |
168 } else { | |
169 bpp = SDL_BYTESPERPIXEL(mode.format) * 8; | |
170 } | |
171 | |
172 if (bpp != format->BitsPerPixel) { | |
163 continue; | 173 continue; |
164 } | 174 } |
165 if (nmodes > 0 && modes[nmodes - 1]->w == mode.w | 175 if (nmodes > 0 && modes[nmodes - 1]->w == mode.w |
166 && modes[nmodes - 1]->h == mode.h) { | 176 && modes[nmodes - 1]->h == mode.h) { |
167 continue; | 177 continue; |