diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.c b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.c deleted file mode 120000 index f193b1511..000000000 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.c +++ /dev/null @@ -1 +0,0 @@ -../../../../sdl-1.3/src/video/SDL_pixels.c \ No newline at end of file diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.c b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.c new file mode 100644 index 000000000..77ca8b0e7 --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.c @@ -0,0 +1,936 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" +#include "SDL_version.h" + +/* General (mostly internal) pixel/color manipulation routines for SDL */ + +#include "SDL_endian.h" +#if SDL_VERSION_ATLEAST(1,3,0) +#include "SDL_video.h" +#include "SDL_sysvideo.h" +#else +#include "SDL_video-1.3.h" +#include "SDL_sysvideo-1.3.h" +#endif +#include "SDL_blit.h" +#include "SDL_pixels_c.h" +#if SDL_VERSION_ATLEAST(1,3,0) +#include "SDL_RLEaccel_c.h" +#endif + +#if SDL_VERSION_ATLEAST(1,3,0) +struct SDL_PaletteWatch +{ + SDL_PaletteChangedFunc callback; + void *userdata; + struct SDL_PaletteWatch *next; +}; +#endif + +/* Helper functions */ + +SDL_bool +SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask, + Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask) +{ + Uint32 masks[4]; + + /* Initialize the values here */ + if (SDL_BYTESPERPIXEL(format) <= 2) { + *bpp = SDL_BITSPERPIXEL(format); + } else { + *bpp = SDL_BYTESPERPIXEL(format) * 8; + } + *Rmask = *Gmask = *Bmask = *Amask = 0; + + if (format == SDL_PIXELFORMAT_RGB24) { +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + *Rmask = 0x00FF0000; + *Gmask = 0x0000FF00; + *Bmask = 0x000000FF; +#else + *Rmask = 0x000000FF; + *Gmask = 0x0000FF00; + *Bmask = 0x00FF0000; +#endif + return SDL_TRUE; + } + + if (format == SDL_PIXELFORMAT_BGR24) { +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + *Rmask = 0x000000FF; + *Gmask = 0x0000FF00; + *Bmask = 0x00FF0000; +#else + *Rmask = 0x00FF0000; + *Gmask = 0x0000FF00; + *Bmask = 0x000000FF; +#endif + return SDL_TRUE; + } + + if (SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED8 && + SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED16 && + SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED32) { + /* Not a format that uses masks */ + return SDL_TRUE; + } + + switch (SDL_PIXELLAYOUT(format)) { + case SDL_PACKEDLAYOUT_332: + masks[0] = 0x00000000; + masks[1] = 0x000000E0; + masks[2] = 0x0000001C; + masks[3] = 0x00000003; + break; + case SDL_PACKEDLAYOUT_4444: + masks[0] = 0x0000F000; + masks[1] = 0x00000F00; + masks[2] = 0x000000F0; + masks[3] = 0x0000000F; + break; + case SDL_PACKEDLAYOUT_1555: + masks[0] = 0x00008000; + masks[1] = 0x00007C00; + masks[2] = 0x000003E0; + masks[3] = 0x0000001F; + break; + case SDL_PACKEDLAYOUT_5551: + masks[0] = 0x0000F800; + masks[1] = 0x000007C0; + masks[2] = 0x0000003E; + masks[3] = 0x00000001; + break; + case SDL_PACKEDLAYOUT_565: + masks[0] = 0x00000000; + masks[1] = 0x0000F800; + masks[2] = 0x000007E0; + masks[3] = 0x0000001F; + break; + case SDL_PACKEDLAYOUT_8888: + masks[0] = 0xFF000000; + masks[1] = 0x00FF0000; + masks[2] = 0x0000FF00; + masks[3] = 0x000000FF; + break; + case SDL_PACKEDLAYOUT_2101010: + masks[0] = 0xC0000000; + masks[1] = 0x3FF00000; + masks[2] = 0x000FFC00; + masks[3] = 0x000003FF; + break; + case SDL_PACKEDLAYOUT_1010102: + masks[0] = 0xFFC00000; + masks[1] = 0x003FF000; + masks[2] = 0x00000FFC; + masks[3] = 0x00000003; + break; + default: + SDL_SetError("Unknown pixel format"); + return SDL_FALSE; + } + + switch (SDL_PIXELORDER(format)) { + case SDL_PACKEDORDER_XRGB: + *Rmask = masks[1]; + *Gmask = masks[2]; + *Bmask = masks[3]; + break; + case SDL_PACKEDORDER_RGBX: + *Rmask = masks[0]; + *Gmask = masks[1]; + *Bmask = masks[2]; + break; + case SDL_PACKEDORDER_ARGB: + *Amask = masks[0]; + *Rmask = masks[1]; + *Gmask = masks[2]; + *Bmask = masks[3]; + break; + case SDL_PACKEDORDER_RGBA: + *Rmask = masks[0]; + *Gmask = masks[1]; + *Bmask = masks[2]; + *Amask = masks[3]; + break; + case SDL_PACKEDORDER_XBGR: + *Bmask = masks[1]; + *Gmask = masks[2]; + *Rmask = masks[3]; + break; + case SDL_PACKEDORDER_BGRX: + *Bmask = masks[0]; + *Gmask = masks[1]; + *Rmask = masks[2]; + break; + case SDL_PACKEDORDER_BGRA: + *Bmask = masks[0]; + *Gmask = masks[1]; + *Rmask = masks[2]; + *Amask = masks[3]; + break; + case SDL_PACKEDORDER_ABGR: + *Amask = masks[0]; + *Bmask = masks[1]; + *Gmask = masks[2]; + *Rmask = masks[3]; + break; + default: + SDL_SetError("Unknown pixel format"); + return SDL_FALSE; + } + return SDL_TRUE; +} + +Uint32 +SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, + Uint32 Amask) +{ + switch (bpp) { + case 8: + switch (Rmask) { + case 0: + return SDL_PIXELFORMAT_INDEX8; + case 0xE0: + return SDL_PIXELFORMAT_RGB332; + } + break; + case 12: + switch (Rmask) { + case 0x0F00: + return SDL_PIXELFORMAT_RGB444; + } + break; + case 15: + switch (Rmask) { + case 0x001F: + return SDL_PIXELFORMAT_BGR555; + case 0x7C00: + return SDL_PIXELFORMAT_RGB555; + } + break; + case 16: + switch (Rmask) { + case 0x000F: + return SDL_PIXELFORMAT_ABGR4444; + case 0x001F: + if (Gmask == 0x07E0) { + return SDL_PIXELFORMAT_BGR565; + } + return SDL_PIXELFORMAT_ABGR1555; + case 0x0F00: + return SDL_PIXELFORMAT_ARGB4444; + case 0x7C00: + return SDL_PIXELFORMAT_ARGB1555; + case 0xF800: + return SDL_PIXELFORMAT_RGB565; + } + break; + case 24: + switch (Rmask) { + case 0x00FF0000: +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + return SDL_PIXELFORMAT_RGB24; +#else + return SDL_PIXELFORMAT_BGR24; +#endif + case 0x000000FF: +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + return SDL_PIXELFORMAT_BGR24; +#else + return SDL_PIXELFORMAT_RGB24; +#endif + case 0x00000000: + /* FIXME: At this point we can't distinguish */ + /* if this format is RGB24 or BGR24 */ + return SDL_PIXELFORMAT_RGB24; + } + case 32: + switch (Rmask) { + case 0xFF000000: + if (Amask == 0x000000FF) { + return SDL_PIXELFORMAT_RGBA8888; + } + break; + case 0x00FF0000: + if (Amask == 0xFF000000) { + return SDL_PIXELFORMAT_ARGB8888; + } else { + return SDL_PIXELFORMAT_RGB888; + } + break; + case 0x0000FF00: + if (Amask == 0x000000FF) { + return SDL_PIXELFORMAT_BGRA8888; + } + break; + case 0x000000FF: + if (Amask == 0xFF000000) { + return SDL_PIXELFORMAT_ABGR8888; + } else { + return SDL_PIXELFORMAT_BGR888; + } + break; + case 0x3FF00000: + return SDL_PIXELFORMAT_ARGB2101010; + } + } + return SDL_PIXELFORMAT_UNKNOWN; +} + +#if SDL_VERSION_ATLEAST(1,3,0) +SDL_Palette * +SDL_AllocPalette(int ncolors) +{ + SDL_Palette *palette; + + palette = (SDL_Palette *) SDL_malloc(sizeof(*palette)); + if (!palette) { + SDL_OutOfMemory(); + return NULL; + } + palette->colors = + (SDL_Color *) SDL_malloc(ncolors * sizeof(*palette->colors)); + if (!palette->colors) { + SDL_free(palette); + return NULL; + } + palette->ncolors = ncolors; + palette->watch = NULL; + palette->refcount = 1; + + SDL_memset(palette->colors, 0xFF, ncolors * sizeof(*palette->colors)); + + return palette; +} + +int +SDL_AddPaletteWatch(SDL_Palette * palette, SDL_PaletteChangedFunc callback, + void *userdata) +{ + SDL_PaletteWatch *watch; + + if (!palette) { + return -1; + } + + watch = (SDL_PaletteWatch *) SDL_malloc(sizeof(*watch)); + if (!watch) { + SDL_OutOfMemory(); + return -1; + } + + watch->callback = callback; + watch->userdata = userdata; + watch->next = palette->watch; + palette->watch = watch; + ++palette->refcount; + return 0; +} + +void +SDL_DelPaletteWatch(SDL_Palette * palette, SDL_PaletteChangedFunc callback, + void *userdata) +{ + SDL_PaletteWatch *prev, *watch; + + if (!palette) { + return; + } + + for (prev = NULL, watch = palette->watch; watch; + prev = watch, watch = watch->next) { + if (watch->callback == callback && watch->userdata == userdata) { + if (prev) { + prev->next = watch->next; + } else { + palette->watch = watch->next; + } + SDL_free(watch); + SDL_FreePalette(palette); + return; + } + } +} + +int +SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors, + int firstcolor, int ncolors) +{ + SDL_PaletteWatch *watch; + int status = 0; + + /* Verify the parameters */ + if (!palette) { + return -1; + } + if (ncolors > (palette->ncolors - firstcolor)) { + ncolors = (palette->ncolors - firstcolor); + status = -1; + } + + if (colors != (palette->colors + firstcolor)) { + SDL_memcpy(palette->colors + firstcolor, colors, + ncolors * sizeof(*colors)); + } + + for (watch = palette->watch; watch; watch = watch->next) { + if (watch->callback(watch->userdata, palette) < 0) { + status = -1; + } + } + + return status; +} + +void +SDL_FreePalette(SDL_Palette * palette) +{ + if (!palette) { + return; + } + if (--palette->refcount > 0) { + return; + } + if (palette->colors) { + SDL_free(palette->colors); + } + SDL_free(palette); +} + +/* + * Allocate a pixel format structure and fill it according to the given info. + */ +SDL_PixelFormat * +SDL_AllocFormat(int bpp, + Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) +{ + SDL_PixelFormat *format; + + /* Allocate an empty pixel format structure */ + format = SDL_malloc(sizeof(*format)); + if (format == NULL) { + SDL_OutOfMemory(); + return (NULL); + } + + /* Set up the format */ + return SDL_InitFormat(format, bpp, Rmask, Gmask, Bmask, Amask); +} + +#endif + +SDL_PixelFormat * +SDL_InitFormat(SDL_PixelFormat * format, int bpp, Uint32 Rmask, Uint32 Gmask, + Uint32 Bmask, Uint32 Amask) +{ + Uint32 mask; + + /* Set up the format */ + SDL_zerop(format); + format->BitsPerPixel = bpp; + format->BytesPerPixel = (bpp + 7) / 8; + if (Rmask || Bmask || Gmask) { /* Packed pixels with custom mask */ + format->Rshift = 0; + format->Rloss = 8; + if (Rmask) { + for (mask = Rmask; !(mask & 0x01); mask >>= 1) + ++format->Rshift; + for (; (mask & 0x01); mask >>= 1) + --format->Rloss; + } + format->Gshift = 0; + format->Gloss = 8; + if (Gmask) { + for (mask = Gmask; !(mask & 0x01); mask >>= 1) + ++format->Gshift; + for (; (mask & 0x01); mask >>= 1) + --format->Gloss; + } + format->Bshift = 0; + format->Bloss = 8; + if (Bmask) { + for (mask = Bmask; !(mask & 0x01); mask >>= 1) + ++format->Bshift; + for (; (mask & 0x01); mask >>= 1) + --format->Bloss; + } + format->Ashift = 0; + format->Aloss = 8; + if (Amask) { + for (mask = Amask; !(mask & 0x01); mask >>= 1) + ++format->Ashift; + for (; (mask & 0x01); mask >>= 1) + --format->Aloss; + } + format->Rmask = Rmask; + format->Gmask = Gmask; + format->Bmask = Bmask; + format->Amask = Amask; + } else if (bpp > 8) { /* Packed pixels with standard mask */ + /* R-G-B */ + if (bpp > 24) + bpp = 24; + format->Rloss = 8 - (bpp / 3); + format->Gloss = 8 - (bpp / 3) - (bpp % 3); + format->Bloss = 8 - (bpp / 3); + format->Rshift = ((bpp / 3) + (bpp % 3)) + (bpp / 3); + format->Gshift = (bpp / 3); + format->Bshift = 0; + format->Rmask = ((0xFF >> format->Rloss) << format->Rshift); + format->Gmask = ((0xFF >> format->Gloss) << format->Gshift); + format->Bmask = ((0xFF >> format->Bloss) << format->Bshift); + } else { + /* Palettized formats have no mask info */ + format->Rloss = 8; + format->Gloss = 8; + format->Bloss = 8; + format->Aloss = 8; + format->Rshift = 0; + format->Gshift = 0; + format->Bshift = 0; + format->Ashift = 0; + format->Rmask = 0; + format->Gmask = 0; + format->Bmask = 0; + format->Amask = 0; + } + format->palette = NULL; + + return format; +} + +#if SDL_VERSION_ATLEAST(1,3,0) + +/* + * Change any previous mappings from/to the new surface format + */ +void +SDL_FormatChanged(SDL_Surface * surface) +{ + static int format_version = 0; + ++format_version; + if (format_version < 0) { /* It wrapped... */ + format_version = 1; + } + surface->format_version = format_version; + SDL_InvalidateMap(surface->map); +} + +/* + * Free a previously allocated format structure + */ +void +SDL_FreeFormat(SDL_PixelFormat * format) +{ + if (!format) { + return; + } + SDL_free(format); +} + +/* + * Calculate an 8-bit (3 red, 3 green, 2 blue) dithered palette of colors + */ +void +SDL_DitherColors(SDL_Color * colors, int bpp) +{ + int i; + if (bpp != 8) + return; /* only 8bpp supported right now */ + + for (i = 0; i < 256; i++) { + int r, g, b; + /* map each bit field to the full [0, 255] interval, + so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */ + r = i & 0xe0; + r |= r >> 3 | r >> 6; + colors[i].r = r; + g = (i << 3) & 0xe0; + g |= g >> 3 | g >> 6; + colors[i].g = g; + b = i & 0x3; + b |= b << 2; + b |= b << 4; + colors[i].b = b; + colors[i].unused = SDL_ALPHA_OPAQUE; + } +} + +/* + * Calculate the pad-aligned scanline width of a surface + */ +int +SDL_CalculatePitch(SDL_Surface * surface) +{ + int pitch; + + /* Surface should be 4-byte aligned for speed */ + pitch = surface->w * surface->format->BytesPerPixel; + switch (surface->format->BitsPerPixel) { + case 1: + pitch = (pitch + 7) / 8; + break; + case 4: + pitch = (pitch + 1) / 2; + break; + default: + break; + } +// 4-byte aligning adds extra memcpy() with OpenGL ES renderer +// TODO: check if we really can disable that for Android +#ifndef ANDROID + pitch = (pitch + 3) & ~3; /* 4-byte aligning */ +#endif + return (pitch); +} + +/* + * Match an RGB value to a particular palette index + */ +Uint8 +SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b) +{ + /* Do colorspace distance matching */ + unsigned int smallest; + unsigned int distance; + int rd, gd, bd; + int i; + Uint8 pixel = 0; + + smallest = ~0; + for (i = 0; i < pal->ncolors; ++i) { + rd = pal->colors[i].r - r; + gd = pal->colors[i].g - g; + bd = pal->colors[i].b - b; + distance = (rd * rd) + (gd * gd) + (bd * bd); + if (distance < smallest) { + pixel = i; + if (distance == 0) { /* Perfect match! */ + break; + } + smallest = distance; + } + } + return (pixel); +} + +/* Find the opaque pixel value corresponding to an RGB triple */ +Uint32 +SDL_MapRGB(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b) +{ + if (format->palette == NULL) { + return (r >> format->Rloss) << format->Rshift + | (g >> format->Gloss) << format->Gshift + | (b >> format->Bloss) << format->Bshift | format->Amask; + } else { + return SDL_FindColor(format->palette, r, g, b); + } +} + +/* Find the pixel value corresponding to an RGBA quadruple */ +Uint32 +SDL_MapRGBA(const SDL_PixelFormat * format, Uint8 r, Uint8 g, Uint8 b, + Uint8 a) +{ + if (format->palette == NULL) { + return (r >> format->Rloss) << format->Rshift + | (g >> format->Gloss) << format->Gshift + | (b >> format->Bloss) << format->Bshift + | ((a >> format->Aloss) << format->Ashift & format->Amask); + } else { + return SDL_FindColor(format->palette, r, g, b); + } +} + +void +SDL_GetRGB(Uint32 pixel, const SDL_PixelFormat * format, Uint8 * r, Uint8 * g, + Uint8 * b) +{ + if (format->palette == NULL) { + /* + * This makes sure that the result is mapped to the + * interval [0..255], and the maximum value for each + * component is 255. This is important to make sure + * that white is indeed reported as (255, 255, 255). + * This only works for RGB bit fields at least 4 bit + * wide, which is almost always the case. + */ + unsigned v; + v = (pixel & format->Rmask) >> format->Rshift; + *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1))); + v = (pixel & format->Gmask) >> format->Gshift; + *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1))); + v = (pixel & format->Bmask) >> format->Bshift; + *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1))); + } else { + *r = format->palette->colors[pixel].r; + *g = format->palette->colors[pixel].g; + *b = format->palette->colors[pixel].b; + } +} + +void +SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format, + Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a) +{ + if (format->palette == NULL) { + /* + * This makes sure that the result is mapped to the + * interval [0..255], and the maximum value for each + * component is 255. This is important to make sure + * that white is indeed reported as (255, 255, 255), + * and that opaque alpha is 255. + * This only works for RGB bit fields at least 4 bit + * wide, which is almost always the case. + */ + unsigned v; + v = (pixel & format->Rmask) >> format->Rshift; + *r = (v << format->Rloss) + (v >> (8 - (format->Rloss << 1))); + v = (pixel & format->Gmask) >> format->Gshift; + *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1))); + v = (pixel & format->Bmask) >> format->Bshift; + *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1))); + if (format->Amask) { + v = (pixel & format->Amask) >> format->Ashift; + *a = (v << format->Aloss) + (v >> (8 - (format->Aloss << 1))); + } else { + *a = SDL_ALPHA_OPAQUE; + } + } else { + *r = format->palette->colors[pixel].r; + *g = format->palette->colors[pixel].g; + *b = format->palette->colors[pixel].b; + *a = SDL_ALPHA_OPAQUE; + } +} + +/* Apply gamma to a set of colors - this is easy. :) */ +void +SDL_ApplyGamma(Uint16 * gamma, SDL_Color * colors, SDL_Color * output, + int ncolors) +{ + int i; + + for (i = 0; i < ncolors; ++i) { + output[i].r = gamma[0 * 256 + colors[i].r] >> 8; + output[i].g = gamma[1 * 256 + colors[i].g] >> 8; + output[i].b = gamma[2 * 256 + colors[i].b] >> 8; + } +} + +/* Map from Palette to Palette */ +static Uint8 * +Map1to1(SDL_Palette * src, SDL_Palette * dst, int *identical) +{ + Uint8 *map; + int i; + + if (identical) { + if (src->ncolors <= dst->ncolors) { + /* If an identical palette, no need to map */ + if (src == dst + || + (SDL_memcmp + (src->colors, dst->colors, + src->ncolors * sizeof(SDL_Color)) == 0)) { + *identical = 1; + return (NULL); + } + } + *identical = 0; + } + map = (Uint8 *) SDL_malloc(src->ncolors); + if (map == NULL) { + SDL_OutOfMemory(); + return (NULL); + } + for (i = 0; i < src->ncolors; ++i) { + map[i] = SDL_FindColor(dst, + src->colors[i].r, src->colors[i].g, + src->colors[i].b); + } + return (map); +} + +/* Map from Palette to BitField */ +static Uint8 * +Map1toN(SDL_PixelFormat * src, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod, Uint8 Amod, + SDL_PixelFormat * dst) +{ + Uint8 *map; + int i; + int bpp; + SDL_Palette *pal = src->palette; + + bpp = ((dst->BytesPerPixel == 3) ? 4 : dst->BytesPerPixel); + map = (Uint8 *) SDL_malloc(pal->ncolors * bpp); + if (map == NULL) { + SDL_OutOfMemory(); + return (NULL); + } + + /* We memory copy to the pixel map so the endianness is preserved */ + for (i = 0; i < pal->ncolors; ++i) { + Uint8 A = Amod; + Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255); + Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255); + Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255); + ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A); + } + return (map); +} + +/* Map from BitField to Dithered-Palette to Palette */ +static Uint8 * +MapNto1(SDL_PixelFormat * src, SDL_PixelFormat * dst, int *identical) +{ + /* Generate a 256 color dither palette */ + SDL_Palette dithered; + SDL_Color colors[256]; + SDL_Palette *pal = dst->palette; + + dithered.ncolors = 256; + SDL_DitherColors(colors, 8); + dithered.colors = colors; + return (Map1to1(&dithered, pal, identical)); +} + +SDL_BlitMap * +SDL_AllocBlitMap(void) +{ + SDL_BlitMap *map; + + /* Allocate the empty map */ + map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map)); + if (map == NULL) { + SDL_OutOfMemory(); + return (NULL); + } + map->info.r = 0xFF; + map->info.g = 0xFF; + map->info.b = 0xFF; + map->info.a = 0xFF; + + /* It's ready to go */ + return (map); +} + +void +SDL_InvalidateMap(SDL_BlitMap * map) +{ + if (!map) { + return; + } + map->dst = NULL; + map->format_version = (unsigned int) -1; + if (map->info.table) { + SDL_free(map->info.table); + map->info.table = NULL; + } +} + +int +SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst) +{ + SDL_PixelFormat *srcfmt; + SDL_PixelFormat *dstfmt; + SDL_BlitMap *map; + + /* Clear out any previous mapping */ + map = src->map; + if ((src->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { + SDL_UnRLESurface(src, 1); + } + SDL_InvalidateMap(map); + + /* Figure out what kind of mapping we're doing */ + map->identity = 0; + srcfmt = src->format; + dstfmt = dst->format; + switch (srcfmt->BytesPerPixel) { + case 1: + switch (dstfmt->BytesPerPixel) { + case 1: + /* Palette --> Palette */ + map->info.table = + Map1to1(srcfmt->palette, dstfmt->palette, &map->identity); + if (!map->identity) { + if (map->info.table == NULL) { + return (-1); + } + } + if (srcfmt->BitsPerPixel != dstfmt->BitsPerPixel) + map->identity = 0; + break; + + default: + /* Palette --> BitField */ + map->info.table = + Map1toN(srcfmt, src->map->info.r, src->map->info.g, + src->map->info.b, src->map->info.a, dstfmt); + if (map->info.table == NULL) { + return (-1); + } + break; + } + break; + default: + switch (dstfmt->BytesPerPixel) { + case 1: + /* BitField --> Palette */ + map->info.table = MapNto1(srcfmt, dstfmt, &map->identity); + if (!map->identity) { + if (map->info.table == NULL) { + return (-1); + } + } + map->identity = 0; /* Don't optimize to copy */ + break; + default: + /* BitField --> BitField */ + if (FORMAT_EQUAL(srcfmt, dstfmt)) + map->identity = 1; + break; + } + break; + } + + map->dst = dst; + map->format_version = dst->format_version; + + /* Choose your blitters wisely */ + return (SDL_CalculateBlit(src)); +} + +void +SDL_FreeBlitMap(SDL_BlitMap * map) +{ + if (map) { + SDL_InvalidateMap(map); + SDL_free(map); + } +} +#endif + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.h deleted file mode 120000 index cf8db31f8..000000000 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.h +++ /dev/null @@ -1 +0,0 @@ -../../../../sdl-1.3/include/SDL_pixels.h \ No newline at end of file diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.h new file mode 100644 index 000000000..deb82ca13 --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels.h @@ -0,0 +1,417 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/** + * \file SDL_pixels.h + * + * Header for the enumerated pixel format definitions. + */ + +#ifndef _SDL_pixels_h +#define _SDL_pixels_h + +#include "SDL_version.h" + +#if SDL_VERSION_ATLEAST(1,3,0) +#include "SDL_video.h" +#else +#include "SDL_video-1.3.h" +#endif + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/** + * \name Transparency definitions + * + * These define alpha as the opacity of a surface. + */ +/*@{*/ +#define SDL_ALPHA_OPAQUE 255 +#define SDL_ALPHA_TRANSPARENT 0 +/*@}*/ + +/** Pixel type. */ +enum +{ + SDL_PIXELTYPE_UNKNOWN, + SDL_PIXELTYPE_INDEX1, + SDL_PIXELTYPE_INDEX4, + SDL_PIXELTYPE_INDEX8, + SDL_PIXELTYPE_PACKED8, + SDL_PIXELTYPE_PACKED16, + SDL_PIXELTYPE_PACKED32, + SDL_PIXELTYPE_ARRAYU8, + SDL_PIXELTYPE_ARRAYU16, + SDL_PIXELTYPE_ARRAYU32, + SDL_PIXELTYPE_ARRAYF16, + SDL_PIXELTYPE_ARRAYF32 +}; + +/** Bitmap pixel order, high bit -> low bit. */ +enum +{ + SDL_BITMAPORDER_NONE, + SDL_BITMAPORDER_4321, + SDL_BITMAPORDER_1234 +}; + +/** Packed component order, high bit -> low bit. */ +enum +{ + SDL_PACKEDORDER_NONE, + SDL_PACKEDORDER_XRGB, + SDL_PACKEDORDER_RGBX, + SDL_PACKEDORDER_ARGB, + SDL_PACKEDORDER_RGBA, + SDL_PACKEDORDER_XBGR, + SDL_PACKEDORDER_BGRX, + SDL_PACKEDORDER_ABGR, + SDL_PACKEDORDER_BGRA +}; + +/** Array component order, low byte -> high byte. */ +enum +{ + SDL_ARRAYORDER_NONE, + SDL_ARRAYORDER_RGB, + SDL_ARRAYORDER_RGBA, + SDL_ARRAYORDER_ARGB, + SDL_ARRAYORDER_BGR, + SDL_ARRAYORDER_BGRA, + SDL_ARRAYORDER_ABGR +}; + +/** Packed component layout. */ +enum +{ + SDL_PACKEDLAYOUT_NONE, + SDL_PACKEDLAYOUT_332, + SDL_PACKEDLAYOUT_4444, + SDL_PACKEDLAYOUT_1555, + SDL_PACKEDLAYOUT_5551, + SDL_PACKEDLAYOUT_565, + SDL_PACKEDLAYOUT_8888, + SDL_PACKEDLAYOUT_2101010, + SDL_PACKEDLAYOUT_1010102 +}; + +#define SDL_DEFINE_PIXELFOURCC(A, B, C, D) SDL_FOURCC(A, B, C, D) + +#define SDL_DEFINE_PIXELFORMAT(type, order, layout, bits, bytes) \ + ((1 << 31) | ((type) << 24) | ((order) << 20) | ((layout) << 16) | \ + ((bits) << 8) | ((bytes) << 0)) + +#define SDL_PIXELTYPE(X) (((X) >> 24) & 0x0F) +#define SDL_PIXELORDER(X) (((X) >> 20) & 0x0F) +#define SDL_PIXELLAYOUT(X) (((X) >> 16) & 0x0F) +#define SDL_BITSPERPIXEL(X) (((X) >> 8) & 0xFF) +#define SDL_BYTESPERPIXEL(X) (((X) >> 0) & 0xFF) + +#define SDL_ISPIXELFORMAT_INDEXED(format) \ + ((SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX1) || \ + (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX4) || \ + (SDL_PIXELTYPE(format) == SDL_PIXELTYPE_INDEX8)) + +#define SDL_ISPIXELFORMAT_ALPHA(format) \ + ((SDL_PIXELORDER(format) == SDL_PACKEDORDER_ARGB) || \ + (SDL_PIXELORDER(format) == SDL_PACKEDORDER_RGBA) || \ + (SDL_PIXELORDER(format) == SDL_PACKEDORDER_ABGR) || \ + (SDL_PIXELORDER(format) == SDL_PACKEDORDER_BGRA)) + +#define SDL_ISPIXELFORMAT_FOURCC(format) \ + ((format) && !((format) & 0x80000000)) + +enum +{ + SDL_PIXELFORMAT_UNKNOWN, + SDL_PIXELFORMAT_INDEX1LSB = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_1234, 0, + 1, 0), + SDL_PIXELFORMAT_INDEX1MSB = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX1, SDL_BITMAPORDER_4321, 0, + 1, 0), + SDL_PIXELFORMAT_INDEX4LSB = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_1234, 0, + 4, 0), + SDL_PIXELFORMAT_INDEX4MSB = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX4, SDL_BITMAPORDER_4321, 0, + 4, 0), + SDL_PIXELFORMAT_INDEX8 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_INDEX8, 0, 0, 8, 1), + SDL_PIXELFORMAT_RGB332 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED8, SDL_PACKEDORDER_XRGB, + SDL_PACKEDLAYOUT_332, 8, 1), + SDL_PIXELFORMAT_RGB444 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, + SDL_PACKEDLAYOUT_4444, 12, 2), + SDL_PIXELFORMAT_RGB555 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, + SDL_PACKEDLAYOUT_1555, 15, 2), + SDL_PIXELFORMAT_BGR555 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR, + SDL_PACKEDLAYOUT_1555, 15, 2), + SDL_PIXELFORMAT_ARGB4444 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB, + SDL_PACKEDLAYOUT_4444, 16, 2), + SDL_PIXELFORMAT_ABGR4444 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR, + SDL_PACKEDLAYOUT_4444, 16, 2), + SDL_PIXELFORMAT_RGBA4444 = /* Android-specific */ + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA, + SDL_PACKEDLAYOUT_4444, 16, 2), + SDL_PIXELFORMAT_ARGB1555 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB, + SDL_PACKEDLAYOUT_1555, 16, 2), + SDL_PIXELFORMAT_ABGR1555 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR, + SDL_PACKEDLAYOUT_1555, 16, 2), + SDL_PIXELFORMAT_RGBA5551 = /* Android-specific */ + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA, + SDL_PACKEDLAYOUT_5551, 16, 2), + SDL_PIXELFORMAT_RGB565 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB, + SDL_PACKEDLAYOUT_565, 16, 2), + SDL_PIXELFORMAT_BGR565 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XBGR, + SDL_PACKEDLAYOUT_565, 16, 2), + SDL_PIXELFORMAT_RGB24 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_RGB, 0, + 24, 3), + SDL_PIXELFORMAT_BGR24 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_ARRAYU8, SDL_ARRAYORDER_BGR, 0, + 24, 3), + SDL_PIXELFORMAT_RGB888 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XRGB, + SDL_PACKEDLAYOUT_8888, 24, 4), + SDL_PIXELFORMAT_BGR888 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_XBGR, + SDL_PACKEDLAYOUT_8888, 24, 4), + SDL_PIXELFORMAT_ARGB8888 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB, + SDL_PACKEDLAYOUT_8888, 32, 4), + SDL_PIXELFORMAT_RGBA8888 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_RGBA, + SDL_PACKEDLAYOUT_8888, 32, 4), + SDL_PIXELFORMAT_ABGR8888 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ABGR, + SDL_PACKEDLAYOUT_8888, 32, 4), + SDL_PIXELFORMAT_BGRA8888 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_BGRA, + SDL_PACKEDLAYOUT_8888, 32, 4), + SDL_PIXELFORMAT_ARGB2101010 = + SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB, + SDL_PACKEDLAYOUT_2101010, 32, 4), + +#if SDL_VERSION_ATLEAST(1,3,0) + SDL_PIXELFORMAT_YV12 = /**< Planar mode: Y + V + U (3 planes) */ + SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'), + SDL_PIXELFORMAT_IYUV = /**< Planar mode: Y + U + V (3 planes) */ + SDL_DEFINE_PIXELFOURCC('I', 'Y', 'U', 'V'), + SDL_PIXELFORMAT_YUY2 = /**< Packed mode: Y0+U0+Y1+V0 (1 plane) */ + SDL_DEFINE_PIXELFOURCC('Y', 'U', 'Y', '2'), + SDL_PIXELFORMAT_UYVY = /**< Packed mode: U0+Y0+V0+Y1 (1 plane) */ + SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'), + SDL_PIXELFORMAT_YVYU = /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */ + SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U') +#endif +}; + +#if SDL_VERSION_ATLEAST(1,3,0) +typedef struct SDL_Color +{ + Uint8 r; + Uint8 g; + Uint8 b; + Uint8 unused; +} SDL_Color; +#define SDL_Colour SDL_Color + +typedef struct SDL_Palette SDL_Palette; +typedef int (*SDL_PaletteChangedFunc) (void *userdata, SDL_Palette * palette); +typedef struct SDL_PaletteWatch SDL_PaletteWatch; + +struct SDL_Palette +{ + int ncolors; + SDL_Color *colors; + + int refcount; + SDL_PaletteWatch *watch; +}; + +/** + * \note Everything in the pixel format structure is read-only. + */ +typedef struct SDL_PixelFormat +{ + SDL_Palette *palette; + Uint8 BitsPerPixel; + Uint8 BytesPerPixel; + Uint8 Rloss; + Uint8 Gloss; + Uint8 Bloss; + Uint8 Aloss; + Uint8 Rshift; + Uint8 Gshift; + Uint8 Bshift; + Uint8 Ashift; + Uint32 Rmask; + Uint32 Gmask; + Uint32 Bmask; + Uint32 Amask; +} SDL_PixelFormat; +#endif + +/** + * \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks. + * + * \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible. + * + * \sa SDL_MasksToPixelFormatEnum() + */ +extern DECLSPEC SDL_bool SDLCALL SDL_PixelFormatEnumToMasks(Uint32 format, + int *bpp, + Uint32 * Rmask, + Uint32 * Gmask, + Uint32 * Bmask, + Uint32 * Amask); + +/** + * \brief Convert a bpp and RGBA masks to an enumerated pixel format. + * + * \return The pixel format, or ::SDL_PIXELFORMAT_UNKNOWN if the conversion + * wasn't possible. + * + * \sa SDL_PixelFormatEnumToMasks() + */ +extern DECLSPEC Uint32 SDLCALL SDL_MasksToPixelFormatEnum(int bpp, + Uint32 Rmask, + Uint32 Gmask, + Uint32 Bmask, + Uint32 Amask); + +/** + * \brief Create a palette structure with the specified number of color + * entries. + * + * \return A new palette, or NULL if there wasn't enough memory. + * + * \note The palette entries are initialized to white. + * + * \sa SDL_FreePalette() + */ +extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors); + +/** + * \brief Add a callback function which is called when the palette changes. + * + * \sa SDL_DelPaletteWatch() + */ +#if SDL_VERSION_ATLEAST(1,3,0) +extern DECLSPEC int SDLCALL SDL_AddPaletteWatch(SDL_Palette * palette, + SDL_PaletteChangedFunc + callback, void *userdata); + +/** + * \brief Remove a callback function previously added with + * SDL_AddPaletteWatch(). + * + * \sa SDL_AddPaletteWatch() + */ +extern DECLSPEC void SDLCALL SDL_DelPaletteWatch(SDL_Palette * palette, + SDL_PaletteChangedFunc + callback, void *userdata); +#endif +/** + * \brief Set a range of colors in a palette. + * + * \param palette The palette to modify. + * \param colors An array of colors to copy into the palette. + * \param firstcolor The index of the first palette entry to modify. + * \param ncolors The number of entries to modify. + * + * \return 0 on success, or -1 if not all of the colors could be set. + */ +extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette, + const SDL_Color * colors, + int firstcolor, int ncolors); + +/** + * \brief Free a palette created with SDL_AllocPalette(). + * + * \sa SDL_AllocPalette() + */ +extern DECLSPEC void SDLCALL SDL_FreePalette(SDL_Palette * palette); + +/** + * \brief Maps an RGB triple to an opaque pixel value for a given pixel format. + * + * \sa SDL_MapRGBA + */ +extern DECLSPEC Uint32 SDLCALL SDL_MapRGB(const SDL_PixelFormat * format, + Uint8 r, Uint8 g, Uint8 b); + +/** + * \brief Maps an RGBA quadruple to a pixel value for a given pixel format. + * + * \sa SDL_MapRGB + */ +extern DECLSPEC Uint32 SDLCALL SDL_MapRGBA(const SDL_PixelFormat * format, + Uint8 r, Uint8 g, Uint8 b, + Uint8 a); + +/** + * \brief Get the RGB components from a pixel of the specified format. + * + * \sa SDL_GetRGBA + */ +extern DECLSPEC void SDLCALL SDL_GetRGB(Uint32 pixel, + const SDL_PixelFormat * format, + Uint8 * r, Uint8 * g, Uint8 * b); + +/** + * \brief Get the RGBA components from a pixel of the specified format. + * + * \sa SDL_GetRGB + */ +extern DECLSPEC void SDLCALL SDL_GetRGBA(Uint32 pixel, + const SDL_PixelFormat * format, + Uint8 * r, Uint8 * g, Uint8 * b, + Uint8 * a); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif +#include "close_code.h" + +#endif /* _SDL_pixels_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels_c.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels_c.h deleted file mode 120000 index 955a28ff3..000000000 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels_c.h +++ /dev/null @@ -1 +0,0 @@ -../../../../sdl-1.3/src/video/SDL_pixels_c.h \ No newline at end of file diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels_c.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels_c.h new file mode 100644 index 000000000..0db2f1247 --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_pixels_c.h @@ -0,0 +1,51 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" +#include "SDL_version.h" + +/* Useful functions and variables from SDL_pixel.c */ + +#include "SDL_blit.h" + +/* Pixel format functions */ +extern SDL_PixelFormat *SDL_AllocFormat(int bpp, + Uint32 Rmask, Uint32 Gmask, + Uint32 Bmask, Uint32 Amask); +extern SDL_PixelFormat *SDL_InitFormat(SDL_PixelFormat * format, int bpp, + Uint32 Rmask, Uint32 Gmask, + Uint32 Bmask, Uint32 Amask); +extern void SDL_FormatChanged(SDL_Surface * surface); +extern void SDL_FreeFormat(SDL_PixelFormat * format); + +/* Blit mapping functions */ +extern SDL_BlitMap *SDL_AllocBlitMap(void); +extern void SDL_InvalidateMap(SDL_BlitMap * map); +extern int SDL_MapSurface(SDL_Surface * src, SDL_Surface * dst); +extern void SDL_FreeBlitMap(SDL_BlitMap * map); + +/* Miscellaneous functions */ +extern int SDL_CalculatePitch(SDL_Surface * surface); +extern void SDL_DitherColors(SDL_Color * colors, int bpp); +extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b); +extern void SDL_ApplyGamma(Uint16 * gamma, SDL_Color * colors, + SDL_Color * output, int ncolors); +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.c b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.c deleted file mode 120000 index 7ac4319eb..000000000 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.c +++ /dev/null @@ -1 +0,0 @@ -../../../../sdl-1.3/src/video/SDL_rect.c \ No newline at end of file diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.c b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.c new file mode 100644 index 000000000..cb84e6ee6 --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.c @@ -0,0 +1,405 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#include "SDL_video.h" +#include "SDL_rect_c.h" + +SDL_bool +SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B) +{ + int Amin, Amax, Bmin, Bmax; + + /* Horizontal intersection */ + Amin = A->x; + Amax = Amin + A->w; + Bmin = B->x; + Bmax = Bmin + B->w; + if (Bmin > Amin) + Amin = Bmin; + if (Bmax < Amax) + Amax = Bmax; + if (Amax <= Amin) + return SDL_FALSE; + + /* Vertical intersection */ + Amin = A->y; + Amax = Amin + A->h; + Bmin = B->y; + Bmax = Bmin + B->h; + if (Bmin > Amin) + Amin = Bmin; + if (Bmax < Amax) + Amax = Bmax; + if (Amax <= Amin) + return SDL_FALSE; + + return SDL_TRUE; +} + +SDL_bool +SDL_IntersectRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result) +{ + int Amin, Amax, Bmin, Bmax; + + /* Horizontal intersection */ + Amin = A->x; + Amax = Amin + A->w; + Bmin = B->x; + Bmax = Bmin + B->w; + if (Bmin > Amin) + Amin = Bmin; + result->x = Amin; + if (Bmax < Amax) + Amax = Bmax; + result->w = Amax - Amin; + + /* Vertical intersection */ + Amin = A->y; + Amax = Amin + A->h; + Bmin = B->y; + Bmax = Bmin + B->h; + if (Bmin > Amin) + Amin = Bmin; + result->y = Amin; + if (Bmax < Amax) + Amax = Bmax; + result->h = Amax - Amin; + + return !SDL_RectEmpty(result); +} + +void +SDL_UnionRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result) +{ + int Amin, Amax, Bmin, Bmax; + + /* Horizontal union */ + Amin = A->x; + Amax = Amin + A->w; + Bmin = B->x; + Bmax = Bmin + B->w; + if (Bmin < Amin) + Amin = Bmin; + result->x = Amin; + if (Bmax > Amax) + Amax = Bmax; + result->w = Amax - Amin; + + /* Vertical intersection */ + Amin = A->y; + Amax = Amin + A->h; + Bmin = B->y; + Bmax = Bmin + B->h; + if (Bmin < Amin) + Amin = Bmin; + result->y = Amin; + if (Bmax > Amax) + Amax = Bmax; + result->h = Amax - Amin; +} + +SDL_bool +SDL_EnclosePoints(const SDL_Point * points, int count, const SDL_Rect * clip, + SDL_Rect * result) +{ + int minx = 0; + int miny = 0; + int maxx = 0; + int maxy = 0; + int x, y, i; + + if (count < 1) { + return SDL_FALSE; + } + + if (clip) { + SDL_bool added = SDL_FALSE; + int clip_minx = clip->x; + int clip_miny = clip->y; + int clip_maxx = clip->x+clip->w-1; + int clip_maxy = clip->y+clip->h-1; + + for (i = 0; i < count; ++i) { + x = points[i].x; + y = points[i].y; + + if (x < clip_minx || x > clip_maxx || + y < clip_miny || y > clip_maxy) { + continue; + } + if (!added) { + minx = maxx = x; + miny = maxy = y; + added = SDL_TRUE; + continue; + } + if (x < minx) { + minx = x; + } else if (x > maxx) { + maxx = x; + } + if (y < miny) { + miny = y; + } else if (y > maxy) { + maxy = y; + } + } + if (!added) { + return SDL_FALSE; + } + } else { + /* No clipping, always add the first point */ + minx = maxx = points[0].x; + miny = maxy = points[0].y; + + for (i = 1; i < count; ++i) { + x = points[i].x; + y = points[i].y; + + if (x < minx) { + minx = x; + } else if (x > maxx) { + maxx = x; + } + if (y < miny) { + miny = y; + } else if (y > maxy) { + maxy = y; + } + } + } + + if (result) { + result->x = minx; + result->y = miny; + result->w = (maxx-minx)+1; + result->h = (maxy-miny)+1; + } + return SDL_TRUE; +} + +/* Use the Cohen-Sutherland algorithm for line clipping */ +#define CODE_BOTTOM 1 +#define CODE_TOP 2 +#define CODE_LEFT 4 +#define CODE_RIGHT 8 + +static int ComputeOutCode(const SDL_Rect * rect, int x, int y) +{ + int code = 0; + if (y < 0) { + code |= CODE_TOP; + } else if (y >= rect->y + rect->h) { + code |= CODE_BOTTOM; + } + if (x < 0) { + code |= CODE_LEFT; + } else if (x >= rect->x + rect->w) { + code |= CODE_RIGHT; + } + return code; +} + +SDL_bool +SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, + int *Y2) +{ + int x = 0; + int y = 0; + int x1, y1; + int x2, y2; + int rectx1; + int recty1; + int rectx2; + int recty2; + int outcode1, outcode2; + + if (!rect || !X1 || !Y1 || !X2 || !Y2) { + return SDL_FALSE; + } + + x1 = *X1; + y1 = *Y1; + x2 = *X2; + y2 = *Y2; + rectx1 = rect->x; + recty1 = rect->y; + rectx2 = rect->x + rect->w - 1; + recty2 = rect->y + rect->h - 1; + + /* Check to see if entire line is inside rect */ + if (x1 >= rectx1 && x1 <= rectx2 && x2 >= rectx1 && x2 <= rectx2 && + y1 >= recty1 && y1 <= recty2 && y2 >= recty1 && y2 <= recty2) { + return SDL_TRUE; + } + + /* Check to see if entire line is to one side of rect */ + if ((x1 < rectx1 && x2 < rectx1) || (x1 > rectx2 && x2 > rectx2) || + (y1 < recty1 && y2 < recty1) || (y1 > recty2 && y2 > recty2)) { + return SDL_FALSE; + } + + if (y1 == y2) { + /* Horizontal line, easy to clip */ + if (x1 < rectx1) { + *X1 = rectx1; + } else if (x1 > rectx2) { + *X1 = rectx2; + } + if (x2 < rectx1) { + *X2 = rectx1; + } else if (x2 > rectx2) { + *X2 = rectx2; + } + return SDL_TRUE; + } + + if (x1 == x2) { + /* Vertical line, easy to clip */ + if (y1 < recty1) { + *Y1 = recty1; + } else if (y1 > recty2) { + *Y1 = recty2; + } + if (y2 < recty1) { + *Y2 = recty1; + } else if (y2 > recty2) { + *Y2 = recty2; + } + return SDL_TRUE; + } + + /* More complicated Cohen-Sutherland algorithm */ + outcode1 = ComputeOutCode(rect, x1, y1); + outcode2 = ComputeOutCode(rect, x2, y2); + while (outcode1 || outcode2) { + if (outcode1 & outcode2) { + return SDL_FALSE; + } + + if (outcode1) { + if (outcode1 & CODE_TOP) { + y = recty1; + x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1); + } else if (outcode1 & CODE_BOTTOM) { + y = recty2; + x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1); + } else if (outcode1 & CODE_LEFT) { + x = rectx1; + y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1); + } else if (outcode1 & CODE_RIGHT) { + x = rectx2; + y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1); + } + x1 = x; + y1 = y; + outcode1 = ComputeOutCode(rect, x, y); + } else { + if (outcode2 & CODE_TOP) { + y = recty1; + x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1); + } else if (outcode2 & CODE_BOTTOM) { + y = recty2; + x = x1 + ((x2 - x1) * (y - y1)) / (y2 - y1); + } else if (outcode2 & CODE_LEFT) { + x = rectx1; + y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1); + } else if (outcode2 & CODE_RIGHT) { + x = rectx2; + y = y1 + ((y2 - y1) * (x - x1)) / (x2 - x1); + } + x2 = x; + y2 = y; + outcode2 = ComputeOutCode(rect, x, y); + } + } + *X1 = x1; + *Y1 = y1; + *X2 = x2; + *Y2 = y2; + return SDL_TRUE; +} + +void +SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect) +{ + SDL_DirtyRect *dirty; + + /* FIXME: At what point is this optimization too expensive? */ + for (dirty = list->list; dirty; dirty = dirty->next) { + if (SDL_HasIntersection(&dirty->rect, rect)) { + SDL_UnionRect(&dirty->rect, rect, &dirty->rect); + return; + } + } + + if (list->free) { + dirty = list->free; + list->free = dirty->next; + } else { + dirty = (SDL_DirtyRect *) SDL_malloc(sizeof(*dirty)); + if (!dirty) { + return; + } + } + dirty->rect = *rect; + dirty->next = list->list; + list->list = dirty; +} + +void +SDL_ClearDirtyRects(SDL_DirtyRectList * list) +{ + SDL_DirtyRect *prev, *curr; + + /* Skip to the end of the free list */ + prev = NULL; + for (curr = list->free; curr; curr = curr->next) { + prev = curr; + } + + /* Add the list entries to the end */ + if (prev) { + prev->next = list->list; + } else { + list->free = list->list; + } + list->list = NULL; +} + +void +SDL_FreeDirtyRects(SDL_DirtyRectList * list) +{ + while (list->list) { + SDL_DirtyRect *elem = list->list; + list->list = elem->next; + SDL_free(elem); + } + while (list->free) { + SDL_DirtyRect *elem = list->free; + list->free = elem->next; + SDL_free(elem); + } +} + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.h deleted file mode 120000 index af8d2b636..000000000 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.h +++ /dev/null @@ -1 +0,0 @@ -../../../../sdl-1.3/include/SDL_rect.h \ No newline at end of file diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.h new file mode 100644 index 000000000..9b531bff0 --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect.h @@ -0,0 +1,142 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/** + * \file SDL_rect.h + * + * Header file for SDL_rect definition and management functions. + */ + +#ifndef _SDL_rect_h +#define _SDL_rect_h + +#include "SDL_stdinc.h" +#include "SDL_error.h" +#include "SDL_rwops.h" +#include "SDL_version.h" +#if ! SDL_VERSION_ATLEAST(1,3,0) +#include "SDL_video.h" +#endif + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/** + * \brief The structure that defines a point + * + * \sa SDL_EnclosePoints + */ +typedef struct +{ + int x; + int y; +} SDL_Point; + +/** + * \brief A rectangle, with the origin at the upper left. + * + * \sa SDL_RectEmpty + * \sa SDL_RectEquals + * \sa SDL_HasIntersection + * \sa SDL_IntersectRect + * \sa SDL_UnionRect + * \sa SDL_EnclosePoints + */ +#if SDL_VERSION_ATLEAST(1,3,0) +typedef struct SDL_Rect +{ + int x, y; + int w, h; +} SDL_Rect; +#endif + +/** + * \brief Returns true if the rectangle has no area. + */ +#define SDL_RectEmpty(X) (((X)->w <= 0) || ((X)->h <= 0)) + +/** + * \brief Returns true if the two rectangles are equal. + */ +#define SDL_RectEquals(A, B) (((A)->x == (B)->x) && ((A)->y == (B)->y) && \ + ((A)->w == (B)->w) && ((A)->h == (B)->h)) + +/** + * \brief Determine whether two rectangles intersect. + * + * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise. + */ +extern DECLSPEC SDL_bool SDLCALL SDL_HasIntersection(const SDL_Rect * A, + const SDL_Rect * B); + +/** + * \brief Calculate the intersection of two rectangles. + * + * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise. + */ +extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRect(const SDL_Rect * A, + const SDL_Rect * B, + SDL_Rect * result); + +/** + * \brief Calculate the union of two rectangles. + */ +extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A, + const SDL_Rect * B, + SDL_Rect * result); + +/** + * \brief Calculate a minimal rectangle enclosing a set of points + * + * \return SDL_TRUE if any points were within the clipping rect + */ +extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points, + int count, + const SDL_Rect * clip, + SDL_Rect * result); + +/** + * \brief Calculate the intersection of a rectangle and line segment. + * + * \return SDL_TRUE if there is an intersection, SDL_FALSE otherwise. + */ +extern DECLSPEC SDL_bool SDLCALL SDL_IntersectRectAndLine(const SDL_Rect * + rect, int *X1, + int *Y1, int *X2, + int *Y2); + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif +#include "close_code.h" + +#endif /* _SDL_rect_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect_c.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect_c.h deleted file mode 120000 index 427c01e8f..000000000 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect_c.h +++ /dev/null @@ -1 +0,0 @@ -../../../../sdl-1.3/src/video/SDL_rect_c.h \ No newline at end of file diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect_c.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect_c.h new file mode 100644 index 000000000..8438a231f --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_rect_c.h @@ -0,0 +1,41 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" +#include "SDL_rect.h" + +typedef struct SDL_DirtyRect +{ + SDL_Rect rect; + struct SDL_DirtyRect *next; +} SDL_DirtyRect; + +typedef struct SDL_DirtyRectList +{ + SDL_DirtyRect *list; + SDL_DirtyRect *free; +} SDL_DirtyRectList; + +extern void SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect); +extern void SDL_ClearDirtyRects(SDL_DirtyRectList * list); +extern void SDL_FreeDirtyRects(SDL_DirtyRectList * list); + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_renderer_gles.c b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_renderer_gles.c deleted file mode 120000 index 0b020c883..000000000 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_renderer_gles.c +++ /dev/null @@ -1 +0,0 @@ -../../../../sdl-1.3/src/video/SDL_renderer_gles.c \ No newline at end of file diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_renderer_gles.c b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_renderer_gles.c new file mode 100644 index 000000000..b4f58eb54 --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_renderer_gles.c @@ -0,0 +1,1062 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" +#include "SDL_version.h" + +#if SDL_VIDEO_RENDER_OGL_ES + +#if SDL_VERSION_ATLEAST(1,3,0) +#include "SDL_video.h" +#include "SDL_sysvideo.h" +#else +#include "SDL_video-1.3.h" +#include "SDL_sysvideo-1.3.h" +#endif +#include "SDL_opengles.h" +#include "SDL_pixels_c.h" +#include "SDL_rect_c.h" +#if SDL_VERSION_ATLEAST(1,3,0) +#include "SDL_yuv_sw_c.h" +#endif +#ifdef ANDROID +#include +#endif + +#if defined(__QNXNTO__) +/* Include QNX system header to check QNX version later */ +#include +#endif /* __QNXNTO__ */ + +#if defined(SDL_VIDEO_DRIVER_QNXGF) || \ + defined(SDL_VIDEO_DRIVER_PHOTON) || \ + defined(SDL_VIDEO_DRIVER_PANDORA) + +/* Empty function stub to get OpenGL ES 1.x support without */ +/* OpenGL ES extension GL_OES_draw_texture supported */ +GL_API void GL_APIENTRY +glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height) +{ + return; +} + +#endif /* QNXGF || PHOTON || PANDORA */ + +/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */ + +static const float inv255f = 1.0f / 255.0f; + +static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags); +static int GLES_ActivateRenderer(SDL_Renderer * renderer); +static int GLES_DisplayModeChanged(SDL_Renderer * renderer); +static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); +static int GLES_QueryTexturePixels(SDL_Renderer * renderer, + SDL_Texture * texture, void **pixels, + int *pitch); +static int GLES_SetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, + const SDL_Color * colors, int firstcolor, + int ncolors); +static int GLES_GetTexturePalette(SDL_Renderer * renderer, + SDL_Texture * texture, SDL_Color * colors, + int firstcolor, int ncolors); +static int GLES_SetTextureColorMod(SDL_Renderer * renderer, + SDL_Texture * texture); +static int GLES_SetTextureAlphaMod(SDL_Renderer * renderer, + SDL_Texture * texture); +static int GLES_SetTextureBlendMode(SDL_Renderer * renderer, + SDL_Texture * texture); +static int GLES_SetTextureScaleMode(SDL_Renderer * renderer, + SDL_Texture * texture); +static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, + int pitch); +static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, int markDirty, + void **pixels, int *pitch); +static void GLES_UnlockTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, + int numrects, const SDL_Rect * rects); +static int GLES_RenderDrawPoints(SDL_Renderer * renderer, + const SDL_Point * points, int count); +static int GLES_RenderDrawLines(SDL_Renderer * renderer, + const SDL_Point * points, int count); +static int GLES_RenderDrawRects(SDL_Renderer * renderer, + const SDL_Rect ** rects, int count); +static int GLES_RenderFillRects(SDL_Renderer * renderer, + const SDL_Rect ** rects, int count); +static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, + const SDL_Rect * dstrect); +static void GLES_RenderPresent(SDL_Renderer * renderer); +static void GLES_DestroyTexture(SDL_Renderer * renderer, + SDL_Texture * texture); +static void GLES_DestroyRenderer(SDL_Renderer * renderer); + + +SDL_RenderDriver GL_ES_RenderDriver = { + GLES_CreateRenderer, + { + "opengl_es", + (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD | + SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED), + (SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR | + SDL_TEXTUREMODULATE_ALPHA), + (SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK | + SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD), + (SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST | + SDL_TEXTURESCALEMODE_SLOW), 5, + { + /* OpenGL ES 1.x supported formats list */ + SDL_PIXELFORMAT_ABGR4444, + SDL_PIXELFORMAT_ABGR1555, + SDL_PIXELFORMAT_BGR565, +#ifdef ANDROID + SDL_PIXELFORMAT_RGB565, // Android is special, GL pixelformat has R and B channels not swapped + SDL_PIXELFORMAT_RGBA5551, + SDL_PIXELFORMAT_RGBA4444, +#endif + SDL_PIXELFORMAT_BGR24, + SDL_PIXELFORMAT_ABGR8888}, + 0, + 0} +}; + +typedef struct +{ + SDL_GLContext context; + SDL_bool updateSize; + int blendMode; + +#ifndef APIENTRY +#define APIENTRY +#endif + + SDL_bool useDrawTexture; + SDL_bool GL_OES_draw_texture_supported; + + /* OpenGL ES functions */ +#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params; +#include "SDL_glesfuncs.h" +#undef SDL_PROC + +} GLES_RenderData; + +typedef struct +{ + GLuint texture; + GLenum type; + GLfloat texw; + GLfloat texh; + GLenum format; + GLenum formattype; + void *pixels; + int pitch; + SDL_DirtyRectList dirty; +} GLES_TextureData; + +static void +GLES_SetError(const char *prefix, GLenum result) +{ + const char *error; + + switch (result) { + case GL_NO_ERROR: + error = "GL_NO_ERROR"; + break; + case GL_INVALID_ENUM: + error = "GL_INVALID_ENUM"; + break; + case GL_INVALID_VALUE: + error = "GL_INVALID_VALUE"; + break; + case GL_INVALID_OPERATION: + error = "GL_INVALID_OPERATION"; + break; + case GL_STACK_OVERFLOW: + error = "GL_STACK_OVERFLOW"; + break; + case GL_STACK_UNDERFLOW: + error = "GL_STACK_UNDERFLOW"; + break; + case GL_OUT_OF_MEMORY: + error = "GL_OUT_OF_MEMORY"; + break; + default: + error = "UNKNOWN"; + break; + } + SDL_SetError("%s: %s", prefix, error); +} + +static int +GLES_LoadFunctions(GLES_RenderData * data) +{ + +#define SDL_PROC(ret,func,params) \ + data->func = func; +#include "SDL_glesfuncs.h" +#undef SDL_PROC + + return 0; +} + +SDL_Renderer * +GLES_CreateRenderer(SDL_Window * window, Uint32 flags) +{ + + SDL_Renderer *renderer; + GLES_RenderData *data; + GLint value; + int doublebuffer; + +#if SDL_VERSION_ATLEAST(1,3,0) + if (!(window->flags & SDL_WINDOW_OPENGL)) { + if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) { + return NULL; + } + } +#endif + + renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); + if (!renderer) { + SDL_OutOfMemory(); + return NULL; + } + + data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data)); + if (!data) { + GLES_DestroyRenderer(renderer); + SDL_OutOfMemory(); + return NULL; + } + + renderer->ActivateRenderer = GLES_ActivateRenderer; + renderer->DisplayModeChanged = GLES_DisplayModeChanged; + renderer->CreateTexture = GLES_CreateTexture; + renderer->QueryTexturePixels = GLES_QueryTexturePixels; + renderer->SetTexturePalette = GLES_SetTexturePalette; + renderer->GetTexturePalette = GLES_GetTexturePalette; + renderer->SetTextureColorMod = GLES_SetTextureColorMod; + renderer->SetTextureAlphaMod = GLES_SetTextureAlphaMod; + renderer->SetTextureBlendMode = GLES_SetTextureBlendMode; + renderer->SetTextureScaleMode = GLES_SetTextureScaleMode; + renderer->UpdateTexture = GLES_UpdateTexture; + renderer->LockTexture = GLES_LockTexture; + renderer->UnlockTexture = GLES_UnlockTexture; + renderer->DirtyTexture = GLES_DirtyTexture; + renderer->RenderDrawPoints = GLES_RenderDrawPoints; + renderer->RenderDrawLines = GLES_RenderDrawLines; + renderer->RenderDrawRects = GLES_RenderDrawRects; + renderer->RenderFillRects = GLES_RenderFillRects; + renderer->RenderCopy = GLES_RenderCopy; + renderer->RenderPresent = GLES_RenderPresent; + renderer->DestroyTexture = GLES_DestroyTexture; + renderer->DestroyRenderer = GLES_DestroyRenderer; + renderer->info = GL_ES_RenderDriver.info; + renderer->window = window; + renderer->driverdata = data; + + renderer->info.flags = + (SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED); + +#if defined(__QNXNTO__) +#if _NTO_VERSION<=641 + /* QNX's OpenGL ES implementation is broken regarding */ + /* packed textures support, affected versions 6.3.2, 6.4.0, 6.4.1 */ + renderer->info.num_texture_formats = 2; + renderer->info.texture_formats[0] = SDL_PIXELFORMAT_ABGR8888; + renderer->info.texture_formats[1] = SDL_PIXELFORMAT_BGR24; +#endif /* _NTO_VERSION */ +#endif /* __QNXNTO__ */ + + if (GLES_LoadFunctions(data) < 0) { + GLES_DestroyRenderer(renderer); + return NULL; + } + + data->context = SDL_GL_CreateContext(window); + if (!data->context) { + GLES_DestroyRenderer(renderer); + return NULL; + } + if (SDL_GL_MakeCurrent(window, data->context) < 0) { + GLES_DestroyRenderer(renderer); + return NULL; + } + + if (flags & SDL_RENDERER_PRESENTVSYNC) { + SDL_GL_SetSwapInterval(1); + } else { + SDL_GL_SetSwapInterval(0); + } + if (SDL_GL_GetSwapInterval() > 0) { + renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; + } + +#ifdef ANDROID + // Always double-buffered +#else + if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer) == 0) { + if (!doublebuffer) { + renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER; + } + } +#endif +#if SDL_VIDEO_DRIVER_PANDORA + data->GL_OES_draw_texture_supported = SDL_FALSE; + data->useDrawTexture = SDL_FALSE; +#else + if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) { + data->GL_OES_draw_texture_supported = SDL_TRUE; + data->useDrawTexture = SDL_TRUE; + } else { + data->GL_OES_draw_texture_supported = SDL_FALSE; + data->useDrawTexture = SDL_FALSE; + } +#ifdef ANDROID + data->GL_OES_draw_texture_supported = SDL_TRUE; + data->useDrawTexture = SDL_TRUE; +#endif +#endif + + data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); + renderer->info.max_texture_width = value; + data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); + renderer->info.max_texture_height = value; + + /* Set up parameters for rendering */ + data->blendMode = -1; + data->glDisable(GL_DEPTH_TEST); + data->glDisable(GL_CULL_FACE); + data->updateSize = SDL_TRUE; + + return renderer; +} + +static int +GLES_ActivateRenderer(SDL_Renderer * renderer) +{ + + GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; + SDL_Window *window = renderer->window; + + if (SDL_GL_MakeCurrent(window, data->context) < 0) { + return -1; + } + if (data->updateSize) { + data->glMatrixMode(GL_PROJECTION); + data->glLoadIdentity(); + data->glMatrixMode(GL_MODELVIEW); + data->glLoadIdentity(); +#if SDL_VIDEO_RENDER_RESIZE + __android_log_print(ANDROID_LOG_INFO, "libSDL", "GLES_ActivateRenderer(): %dx%d", (int)window->display->desktop_mode.w, (int)window->display->desktop_mode.h); + data->glViewport(0, 0, window->display->desktop_mode.w, window->display->desktop_mode.h); + data->glOrthof(0.0, (GLfloat) window->display->desktop_mode.w, (GLfloat) window->display->desktop_mode.h, + 0.0, 0.0, 1.0); +#else + data->glViewport(0, 0, window->w, window->h); + data->glOrthof(0.0, (GLfloat) window->w, (GLfloat) window->h, + 0.0, 0.0, 1.0); +#endif + data->updateSize = SDL_FALSE; + } + return 0; +} + +static int +GLES_DisplayModeChanged(SDL_Renderer * renderer) +{ + GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; + + data->updateSize = SDL_TRUE; + return 0; +} + +static __inline__ int +power_of_2(int input) +{ + int value = 1; + + while (value < input) { + value <<= 1; + } + return value; +} + +static int +GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; + GLES_TextureData *data; + GLint internalFormat; + GLenum format, type; + int texture_w, texture_h; + GLenum result; + + switch (texture->format) { + case SDL_PIXELFORMAT_BGR24: + internalFormat = GL_RGB; + format = GL_RGB; + type = GL_UNSIGNED_BYTE; + break; + case SDL_PIXELFORMAT_ABGR8888: + internalFormat = GL_RGBA; + format = GL_RGBA; + type = GL_UNSIGNED_BYTE; + break; + case SDL_PIXELFORMAT_BGR565: + internalFormat = GL_RGB; + format = GL_RGB; + type = GL_UNSIGNED_SHORT_5_6_5; + break; + case SDL_PIXELFORMAT_ABGR1555: + internalFormat = GL_RGBA; + format = GL_RGBA; + type = GL_UNSIGNED_SHORT_5_5_5_1; + break; + case SDL_PIXELFORMAT_ABGR4444: + internalFormat = GL_RGBA; + format = GL_RGBA; + type = GL_UNSIGNED_SHORT_4_4_4_4; + break; +#ifdef ANDROID + case SDL_PIXELFORMAT_RGB565: + internalFormat = GL_RGB; + format = GL_RGB; + type = GL_UNSIGNED_SHORT_5_6_5; + break; + case SDL_PIXELFORMAT_RGBA5551: + internalFormat = GL_RGBA; + format = GL_RGBA; + type = GL_UNSIGNED_SHORT_5_5_5_1; + break; + case SDL_PIXELFORMAT_RGBA4444: + internalFormat = GL_RGBA; + format = GL_RGBA; + type = GL_UNSIGNED_SHORT_4_4_4_4; + break; +#endif + default: + SDL_SetError("Unsupported by OpenGL ES texture format"); + return -1; + } + + data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data)); + if (!data) { + SDL_OutOfMemory(); + return -1; + } + + if (texture->access == SDL_TEXTUREACCESS_STREAMING) { + data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); + data->pixels = SDL_malloc(texture->h * data->pitch); + if (!data->pixels) { + SDL_OutOfMemory(); + SDL_free(data); + return -1; + } + } + + texture->driverdata = data; + + renderdata->glGetError(); + renderdata->glEnable(GL_TEXTURE_2D); + renderdata->glGenTextures(1, &data->texture); + + data->type = GL_TEXTURE_2D; + /* no NPOV textures allowed in OpenGL ES (yet) */ + texture_w = power_of_2(texture->w); + texture_h = power_of_2(texture->h); + data->texw = (GLfloat) texture->w / texture_w; + data->texh = (GLfloat) texture->h / texture_h; + + data->format = format; + data->formattype = type; + renderdata->glBindTexture(data->type, data->texture); + renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, + GL_NEAREST); + renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, + GL_NEAREST); + renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S, + GL_CLAMP_TO_EDGE); + renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T, + GL_CLAMP_TO_EDGE); + + renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w, + texture_h, 0, format, type, NULL); + renderdata->glDisable(GL_TEXTURE_2D); + + result = renderdata->glGetError(); + if (result != GL_NO_ERROR) { + GLES_SetError("glTexImage2D()", result); + return -1; + } + return 0; +} + +static int +GLES_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, + void **pixels, int *pitch) +{ + GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; + + *pixels = data->pixels; + *pitch = data->pitch; + return 0; +} + +static int +GLES_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Color * colors, int firstcolor, int ncolors) +{ + SDL_SetError("OpenGL ES does not support paletted textures"); + return -1; +} + +static int +GLES_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, + SDL_Color * colors, int firstcolor, int ncolors) +{ + SDL_SetError("OpenGL ES does not support paletted textures"); + return -1; +} + +static void +SetupTextureUpdate(GLES_RenderData * renderdata, SDL_Texture * texture, + int pitch) +{ + GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; + renderdata->glBindTexture(data->type, data->texture); + renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1); +} + +static int +GLES_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture) +{ + return 0; +} + +static int +GLES_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture) +{ + return 0; +} + +static int +GLES_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) +{ + switch (texture->blendMode) { + case SDL_BLENDMODE_NONE: + case SDL_BLENDMODE_MASK: + case SDL_BLENDMODE_BLEND: + case SDL_BLENDMODE_ADD: + case SDL_BLENDMODE_MOD: + return 0; + default: + SDL_Unsupported(); + texture->blendMode = SDL_BLENDMODE_NONE; + return -1; + } +} + +static int +GLES_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) +{ + switch (texture->scaleMode) { + case SDL_TEXTURESCALEMODE_NONE: + case SDL_TEXTURESCALEMODE_FAST: + case SDL_TEXTURESCALEMODE_SLOW: + return 0; + case SDL_TEXTURESCALEMODE_BEST: + SDL_Unsupported(); + texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW; + return -1; + default: + SDL_Unsupported(); + texture->scaleMode = SDL_TEXTURESCALEMODE_NONE; + return -1; + } +} + +static int +GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, int pitch) +{ + GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; + GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; + GLenum result; + int bpp = SDL_BYTESPERPIXEL(texture->format); + void * temp_buffer; + void * temp_ptr; + int i; + + renderdata->glGetError(); + renderdata->glEnable(data->type); + SetupTextureUpdate(renderdata, texture, pitch); + + if( rect->w * bpp == pitch ) { + temp_buffer = (void *)pixels; /* No need to reformat */ + } else { + /* Reformatting of mem area required */ + temp_buffer = SDL_malloc(rect->w * rect->h * bpp); + temp_ptr = temp_buffer; + for (i = 0; i < rect->h; i++) { + SDL_memcpy(temp_ptr, pixels, rect->w * bpp); + temp_ptr += rect->w * bpp; + pixels += pitch; + } + } + + renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w, + rect->h, data->format, data->formattype, + temp_buffer); + + if( temp_buffer != pixels ) { + SDL_free(temp_buffer); + } + + renderdata->glDisable(data->type); + result = renderdata->glGetError(); + if (result != GL_NO_ERROR) { + GLES_SetError("glTexSubImage2D()", result); + return -1; + } + return 0; +} + +static int +GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, int markDirty, void **pixels, + int *pitch) +{ + GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; + + if (markDirty) { + SDL_AddDirtyRect(&data->dirty, rect); + } + + *pixels = + (void *) ((Uint8 *) data->pixels + rect->y * data->pitch + + rect->x * SDL_BYTESPERPIXEL(texture->format)); + *pitch = data->pitch; + return 0; +} + +static void +GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ +} + +static void +GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, + int numrects, const SDL_Rect * rects) +{ + GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; + int i; + + for (i = 0; i < numrects; ++i) { + SDL_AddDirtyRect(&data->dirty, &rects[i]); + } +} + +static void +GLES_SetBlendMode(GLES_RenderData * data, int blendMode, int isprimitive) +{ + if (blendMode != data->blendMode) { + switch (blendMode) { + case SDL_BLENDMODE_NONE: + data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + data->glDisable(GL_BLEND); + break; + case SDL_BLENDMODE_MASK: + if (isprimitive) { + data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + data->glDisable(GL_BLEND); + /* The same as SDL_BLENDMODE_NONE */ + blendMode = SDL_BLENDMODE_NONE; + break; + } + /* fall through */ + case SDL_BLENDMODE_BLEND: + data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + data->glEnable(GL_BLEND); + data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + break; + case SDL_BLENDMODE_ADD: + data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + data->glEnable(GL_BLEND); + data->glBlendFunc(GL_SRC_ALPHA, GL_ONE); + break; + case SDL_BLENDMODE_MOD: + data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + data->glEnable(GL_BLEND); + data->glBlendFunc(GL_ZERO, GL_SRC_COLOR); + break; + } + data->blendMode = blendMode; + } +} + +static int +GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points, + int count) +{ + GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; + int i; + GLshort *vertices; + + GLES_SetBlendMode(data, renderer->blendMode, 1); + + data->glColor4f((GLfloat) renderer->r * inv255f, + (GLfloat) renderer->g * inv255f, + (GLfloat) renderer->b * inv255f, + (GLfloat) renderer->a * inv255f); + + vertices = SDL_stack_alloc(GLshort, count*2); + for (i = 0; i < count; ++i) { + vertices[2*i+0] = (GLshort)points[i].x; + vertices[2*i+1] = (GLshort)points[i].y; + } + data->glVertexPointer(2, GL_SHORT, 0, vertices); + data->glEnableClientState(GL_VERTEX_ARRAY); + data->glDrawArrays(GL_POINTS, 0, count); + data->glDisableClientState(GL_VERTEX_ARRAY); + SDL_stack_free(vertices); + + return 0; +} + +static int +GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points, + int count) +{ + GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; + int i; + GLshort *vertices; + + GLES_SetBlendMode(data, renderer->blendMode, 1); + + data->glColor4f((GLfloat) renderer->r * inv255f, + (GLfloat) renderer->g * inv255f, + (GLfloat) renderer->b * inv255f, + (GLfloat) renderer->a * inv255f); + + vertices = SDL_stack_alloc(GLshort, count*2); + for (i = 0; i < count; ++i) { + vertices[2*i+0] = (GLshort)points[i].x; + vertices[2*i+1] = (GLshort)points[i].y; + } + data->glVertexPointer(2, GL_SHORT, 0, vertices); + data->glEnableClientState(GL_VERTEX_ARRAY); + if (count > 2 && + points[0].x == points[count-1].x && points[0].y == points[count-1].y) { + /* GL_LINE_LOOP takes care of the final segment */ + --count; + data->glDrawArrays(GL_LINE_LOOP, 0, count); + } else { + data->glDrawArrays(GL_LINE_STRIP, 0, count); + } + data->glDisableClientState(GL_VERTEX_ARRAY); + SDL_stack_free(vertices); + + return 0; +} + +static int +GLES_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, + int count) +{ + GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; + int i; + + GLES_SetBlendMode(data, renderer->blendMode, 1); + + data->glColor4f((GLfloat) renderer->r * inv255f, + (GLfloat) renderer->g * inv255f, + (GLfloat) renderer->b * inv255f, + (GLfloat) renderer->a * inv255f); + + data->glEnableClientState(GL_VERTEX_ARRAY); + for (i = 0; i < count; ++i) { + const SDL_Rect *rect = rects[i]; + GLshort minx = rect->x; + GLshort maxx = rect->x + rect->w; + GLshort miny = rect->y; + GLshort maxy = rect->y + rect->h; + GLshort vertices[8]; + vertices[0] = minx; + vertices[1] = miny; + vertices[2] = maxx; + vertices[3] = miny; + vertices[4] = minx; + vertices[5] = maxy; + vertices[6] = maxx; + vertices[7] = maxy; + + data->glVertexPointer(2, GL_SHORT, 0, vertices); + data->glDrawArrays(GL_LINE_LOOP, 0, 4); + } + data->glDisableClientState(GL_VERTEX_ARRAY); + + return 0; +} + +static int +GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, + int count) +{ + GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; + int i; + + GLES_SetBlendMode(data, renderer->blendMode, 1); + + data->glColor4f((GLfloat) renderer->r * inv255f, + (GLfloat) renderer->g * inv255f, + (GLfloat) renderer->b * inv255f, + (GLfloat) renderer->a * inv255f); + + data->glEnableClientState(GL_VERTEX_ARRAY); + for (i = 0; i < count; ++i) { + const SDL_Rect *rect = rects[i]; + GLshort minx = rect->x; + GLshort maxx = rect->x + rect->w; + GLshort miny = rect->y; + GLshort maxy = rect->y + rect->h; + GLshort vertices[8]; + vertices[0] = minx; + vertices[1] = miny; + vertices[2] = maxx; + vertices[3] = miny; + vertices[4] = minx; + vertices[5] = maxy; + vertices[6] = maxx; + vertices[7] = maxy; + + data->glVertexPointer(2, GL_SHORT, 0, vertices); + data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } + data->glDisableClientState(GL_VERTEX_ARRAY); + + return 0; +} + +static int +GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_Rect * dstrect) +{ + + GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; + GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata; + int minx, miny, maxx, maxy; + GLfloat minu, maxu, minv, maxv; + int i; + void *temp_buffer; /* used for reformatting dirty rect pixels */ + void *temp_ptr; + + data->glEnable(GL_TEXTURE_2D); + + if (texturedata->dirty.list) { + SDL_DirtyRect *dirty; + void *pixels; + int bpp = SDL_BYTESPERPIXEL(texture->format); + int pitch = texturedata->pitch; + + SetupTextureUpdate(data, texture, pitch); + + data->glBindTexture(texturedata->type, texturedata->texture); + for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) { + SDL_Rect *rect = &dirty->rect; + pixels = + (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch + + rect->x * bpp); + /* There is no GL_UNPACK_ROW_LENGTH in OpenGLES + we must do this reformatting ourselves(!) + + maybe it'd be a good idea to keep a temp buffer around + for this purpose rather than allocating it each time + */ + if( rect->x == 0 && rect->w * bpp == pitch ) { + temp_buffer = pixels; /* Updating whole texture, no need to reformat */ + } else { + temp_buffer = SDL_malloc(rect->w * rect->h * bpp); + temp_ptr = temp_buffer; + for (i = 0; i < rect->h; i++) { + SDL_memcpy(temp_ptr, pixels, rect->w * bpp); + temp_ptr += rect->w * bpp; + pixels += pitch; + } + } + + data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y, + rect->w, rect->h, texturedata->format, + texturedata->formattype, temp_buffer); + + if( temp_buffer != pixels ) { + SDL_free(temp_buffer); + } + } + SDL_ClearDirtyRects(&texturedata->dirty); + } + + data->glBindTexture(texturedata->type, texturedata->texture); + + if (texture->modMode) { + data->glColor4f((GLfloat) texture->r * inv255f, + (GLfloat) texture->g * inv255f, + (GLfloat) texture->b * inv255f, + (GLfloat) texture->a * inv255f); + } else { + data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + } + + GLES_SetBlendMode(data, texture->blendMode, 0); + + switch (texture->scaleMode) { + case SDL_TEXTURESCALEMODE_NONE: + case SDL_TEXTURESCALEMODE_FAST: + data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, + GL_NEAREST); + data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, + GL_NEAREST); + break; + case SDL_TEXTURESCALEMODE_SLOW: + case SDL_TEXTURESCALEMODE_BEST: + data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER, + GL_LINEAR); + data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER, + GL_LINEAR); + break; + } + + if (data->GL_OES_draw_texture_supported && data->useDrawTexture) { + /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */ + SDL_Window *window = renderer->window; + + GLint cropRect[4]; + cropRect[0] = srcrect->x; + cropRect[1] = srcrect->y + srcrect->h; + cropRect[2] = srcrect->w; + cropRect[3] = -srcrect->h; + data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, + cropRect); + //__android_log_print(ANDROID_LOG_INFO, "libSDL", "GLES_RenderCopy glDrawTexiOES(%d, %d, %d, %d) cropRect %d:%d:%d:%d", dstrect->x, window->display->desktop_mode.h - dstrect->y - dstrect->h, dstrect->w, dstrect->h, cropRect[0], cropRect[1], cropRect[2], cropRect[3]); + data->glDrawTexiOES(dstrect->x, +#if SDL_VIDEO_RENDER_RESIZE + window->display->desktop_mode.h - dstrect->y - dstrect->h, +#else + window->h - dstrect->y - dstrect->h, +#endif + 0, dstrect->w, dstrect->h); + } else { + + minx = dstrect->x; + miny = dstrect->y; + maxx = dstrect->x + dstrect->w; + maxy = dstrect->y + dstrect->h; + + minu = (GLfloat) srcrect->x / texture->w; + minu *= texturedata->texw; + maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w; + maxu *= texturedata->texw; + minv = (GLfloat) srcrect->y / texture->h; + minv *= texturedata->texh; + maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h; + maxv *= texturedata->texh; + + GLshort vertices[8]; + GLfloat texCoords[8]; + + vertices[0] = minx; + vertices[1] = miny; + vertices[2] = maxx; + vertices[3] = miny; + vertices[4] = minx; + vertices[5] = maxy; + vertices[6] = maxx; + vertices[7] = maxy; + + texCoords[0] = minu; + texCoords[1] = minv; + texCoords[2] = maxu; + texCoords[3] = minv; + texCoords[4] = minu; + texCoords[5] = maxv; + texCoords[6] = maxu; + texCoords[7] = maxv; + + data->glVertexPointer(2, GL_SHORT, 0, vertices); + data->glEnableClientState(GL_VERTEX_ARRAY); + data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords); + data->glEnableClientState(GL_TEXTURE_COORD_ARRAY); + data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + data->glDisableClientState(GL_TEXTURE_COORD_ARRAY); + data->glDisableClientState(GL_VERTEX_ARRAY); + } + + data->glDisable(GL_TEXTURE_2D); + + return 0; +} + +static void +GLES_RenderPresent(SDL_Renderer * renderer) +{ + SDL_GL_SwapWindow(renderer->window); +} + +static void +GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture) +{ + GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; + + if (!data) { + return; + } + if (data->texture) { + glDeleteTextures(1, &data->texture); + } + if (data->pixels) { + SDL_free(data->pixels); + } + SDL_FreeDirtyRects(&data->dirty); + SDL_free(data); + texture->driverdata = NULL; +} + +static void +GLES_DestroyRenderer(SDL_Renderer * renderer) +{ + GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; + + if (data) { + if (data->context) { + SDL_GL_DeleteContext(data->context); + } + SDL_free(data); + } + SDL_free(renderer); +} + +#endif /* SDL_VIDEO_RENDER_OGL_ES */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_sysvideo-1.3.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_sysvideo-1.3.h deleted file mode 120000 index 0d114b5b8..000000000 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_sysvideo-1.3.h +++ /dev/null @@ -1 +0,0 @@ -../../../../sdl-1.3/src/video/SDL_sysvideo.h \ No newline at end of file diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_sysvideo-1.3.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_sysvideo-1.3.h new file mode 100644 index 000000000..ba89f3e84 --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_sysvideo-1.3.h @@ -0,0 +1,462 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" + +#ifndef _SDL_sysvideo_1_3_h +#define _SDL_sysvideo_1_3_h + +#include "SDL_mouse.h" +#include "SDL_keysym.h" +#include "SDL_rect.h" + +/* The SDL video driver */ + +typedef struct SDL_Renderer SDL_Renderer; +typedef struct SDL_RenderDriver SDL_RenderDriver; +typedef struct SDL_VideoDisplay SDL_VideoDisplay; +typedef struct SDL_VideoDevice SDL_VideoDevice; + +/* Define the SDL texture structure */ +struct SDL_Texture +{ + const void *magic; + Uint32 format; /**< The pixel format of the texture */ + int access; /**< SDL_TextureAccess */ + int w; /**< The width of the texture */ + int h; /**< The height of the texture */ + int modMode; /**< The texture modulation mode */ + int blendMode; /**< The texture blend mode */ + int scaleMode; /**< The texture scale mode */ + Uint8 r, g, b, a; /**< Texture modulation values */ + + SDL_Renderer *renderer; + + void *driverdata; /**< Driver specific texture representation */ + + SDL_Texture *prev; + SDL_Texture *next; +}; + +/* Define the SDL renderer structure */ +struct SDL_Renderer +{ + int (*ActivateRenderer) (SDL_Renderer * renderer); + int (*DisplayModeChanged) (SDL_Renderer * renderer); + int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture); + int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture, + void **pixels, int *pitch); + int (*SetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Color * colors, int firstcolor, + int ncolors); + int (*GetTexturePalette) (SDL_Renderer * renderer, SDL_Texture * texture, + SDL_Color * colors, int firstcolor, + int ncolors); + int (*SetTextureColorMod) (SDL_Renderer * renderer, + SDL_Texture * texture); + int (*SetTextureAlphaMod) (SDL_Renderer * renderer, + SDL_Texture * texture); + int (*SetTextureBlendMode) (SDL_Renderer * renderer, + SDL_Texture * texture); + int (*SetTextureScaleMode) (SDL_Renderer * renderer, + SDL_Texture * texture); + int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, const void *pixels, + int pitch); + int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * rect, int markDirty, void **pixels, + int *pitch); + void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture); + void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture, + int numrects, const SDL_Rect * rects); + int (*SetDrawColor) (SDL_Renderer * renderer); + int (*SetDrawBlendMode) (SDL_Renderer * renderer); + int (*RenderClear) (SDL_Renderer * renderer); + int (*RenderDrawPoints) (SDL_Renderer * renderer, const SDL_Point * points, + int count); + int (*RenderDrawLines) (SDL_Renderer * renderer, const SDL_Point * points, + int count); + int (*RenderDrawRects) (SDL_Renderer * renderer, const SDL_Rect ** rects, + int count); + int (*RenderFillRects) (SDL_Renderer * renderer, const SDL_Rect ** rects, + int count); + int (*RenderDrawEllipse) (SDL_Renderer * renderer, int x, int y, + int w, int h); + int (*RenderFillEllipse) (SDL_Renderer * renderer, int x, int y, + int w, int h); + int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture, + const SDL_Rect * srcrect, const SDL_Rect * dstrect); + int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 format, void * pixels, int pitch); + int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect, + Uint32 format, const void * pixels, int pitch); + void (*RenderPresent) (SDL_Renderer * renderer); + void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture); + + void (*DestroyRenderer) (SDL_Renderer * renderer); + + /* The current renderer info */ + SDL_RendererInfo info; + + /* The window associated with the renderer */ + SDL_Window *window; + + /* The list of textures */ + SDL_Texture *textures; + + Uint8 r, g, b, a; /**< Color for drawing operations values */ + int blendMode; /**< The drawing blend mode */ + + void *driverdata; +}; + +/* Define the SDL render driver structure */ +struct SDL_RenderDriver +{ + SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags); + + /* Info about the renderer capabilities */ + SDL_RendererInfo info; + /* Used for resizing renderer */ + size_t infoSize; +}; + +/* Define the SDL window structure, corresponding to toplevel windows */ +struct SDL_Window +{ + const void *magic; + Uint32 id; + char *title; + int x, y; + int w, h; + Uint32 flags; + + SDL_VideoDisplay *display; + SDL_Renderer *renderer; + + SDL_DisplayMode fullscreen_mode; + + void *userdata; + void *driverdata; + + SDL_Window *prev; + SDL_Window *next; +}; +#define FULLSCREEN_VISIBLE(W) \ + (((W)->flags & SDL_WINDOW_FULLSCREEN) && \ + ((W)->flags & SDL_WINDOW_SHOWN) && \ + !((W)->flags & SDL_WINDOW_MINIMIZED)) + +/* + * Define the SDL display structure This corresponds to physical monitors + * attached to the system. + */ +struct SDL_VideoDisplay +{ + int max_display_modes; + int num_display_modes; + SDL_DisplayMode *display_modes; + SDL_DisplayMode desktop_mode; + SDL_DisplayMode current_mode; + SDL_bool updating_fullscreen; + SDL_Palette *palette; + + Uint16 *gamma; + Uint16 *saved_gamma; /* (just offset into gamma) */ + + int num_render_drivers; + SDL_RenderDriver *render_drivers; + + SDL_Window *windows; + SDL_Window *fullscreen_window; + + SDL_Renderer *current_renderer; + + SDL_VideoDevice *device; + + void *driverdata; +}; + +/* Define the SDL video driver structure */ +#define _THIS SDL_VideoDevice *_this + +struct SDL_VideoDevice +{ + /* * * */ + /* The name of this video driver */ + const char *name; + + /* * * */ + /* Initialization/Query functions */ + + /* + * Initialize the native video subsystem, filling in the list of + * displays for this driver, returning 0 or -1 if there's an error. + */ + int (*VideoInit) (_THIS); + + /* + * Reverse the effects VideoInit() -- called if VideoInit() fails or + * if the application is shutting down the video subsystem. + */ + void (*VideoQuit) (_THIS); + + /* * * */ + /* + * Display functions + */ + + /* + * Get the bounds of a display + */ + int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect); + + /* + * Get a list of the available display modes. e.g. + * SDL_AddDisplayMode(_this->current_display, mode) + */ + void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display); + + /* + * Setting the display mode is independent of creating windows, so + * when the display mode is changed, all existing windows should have + * their data updated accordingly, including the display surfaces + * associated with them. + */ + int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode); + + /* Set the color entries of the display palette */ + int (*SetDisplayPalette) (_THIS, SDL_VideoDisplay * display, SDL_Palette * palette); + + /* Get the color entries of the display palette */ + int (*GetDisplayPalette) (_THIS, SDL_VideoDisplay * display, SDL_Palette * palette); + + /* Set the gamma ramp */ + int (*SetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp); + + /* Get the gamma ramp */ + int (*GetDisplayGammaRamp) (_THIS, SDL_VideoDisplay * display, Uint16 * ramp); + + /* * * */ + /* + * Window functions + */ + int (*CreateWindow) (_THIS, SDL_Window * window); + int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data); + void (*SetWindowTitle) (_THIS, SDL_Window * window); + void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon); + void (*SetWindowPosition) (_THIS, SDL_Window * window); + void (*SetWindowSize) (_THIS, SDL_Window * window); + void (*ShowWindow) (_THIS, SDL_Window * window); + void (*HideWindow) (_THIS, SDL_Window * window); + void (*RaiseWindow) (_THIS, SDL_Window * window); + void (*MaximizeWindow) (_THIS, SDL_Window * window); + void (*MinimizeWindow) (_THIS, SDL_Window * window); + void (*RestoreWindow) (_THIS, SDL_Window * window); + void (*SetWindowGrab) (_THIS, SDL_Window * window); + void (*DestroyWindow) (_THIS, SDL_Window * window); + + /* Get some platform dependent window information */ + SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window, + struct SDL_SysWMinfo * info); + + /* * * */ + /* + * OpenGL support + */ + int (*GL_LoadLibrary) (_THIS, const char *path); + void *(*GL_GetProcAddress) (_THIS, const char *proc); + void (*GL_UnloadLibrary) (_THIS); + SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window); + int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context); + int (*GL_SetSwapInterval) (_THIS, int interval); + int (*GL_GetSwapInterval) (_THIS); + void (*GL_SwapWindow) (_THIS, SDL_Window * window); + void (*GL_DeleteContext) (_THIS, SDL_GLContext context); + + /* * * */ + /* + * Event manager functions + */ + void (*PumpEvents) (_THIS); + + /* Suspend the screensaver */ + void (*SuspendScreenSaver) (_THIS); + + /* Text input */ + void (*StartTextInput) (_THIS); + void (*StopTextInput) (_THIS); + void (*SetTextInputRect) (_THIS, SDL_Rect *rect); + + /* Clipboard */ + int (*SetClipboardText) (_THIS, const char *text); + char * (*GetClipboardText) (_THIS); + SDL_bool (*HasClipboardText) (_THIS); + + /* * * */ + /* Data common to all drivers */ + SDL_bool suspend_screensaver; + int num_displays; + SDL_VideoDisplay *displays; + int current_display; + Uint8 window_magic; + Uint8 texture_magic; + Uint32 next_object_id; + char * clipboard_text; + + /* * * */ + /* Data used by the GL drivers */ + struct + { + int red_size; + int green_size; + int blue_size; + int alpha_size; + int depth_size; + int buffer_size; + int stencil_size; + int double_buffer; + int accum_red_size; + int accum_green_size; + int accum_blue_size; + int accum_alpha_size; + int stereo; + int multisamplebuffers; + int multisamplesamples; + int accelerated; + int major_version; + int minor_version; + int retained_backing; + int driver_loaded; + char driver_path[256]; + void *dll_handle; + } gl_config; + + /* * * */ + /* Data private to this driver */ + void *driverdata; + struct SDL_GLDriverData *gl_data; + +#if SDL_VIDEO_DRIVER_PANDORA + struct SDL_PrivateGLESData *gles_data; +#endif + + /* * * */ + /* The function used to dispose of this structure */ + void (*free) (_THIS); +}; + +typedef struct VideoBootStrap +{ + const char *name; + const char *desc; + int (*available) (void); + SDL_VideoDevice *(*create) (int devindex); +} VideoBootStrap; + +#if SDL_VIDEO_DRIVER_COCOA +extern VideoBootStrap COCOA_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_X11 +extern VideoBootStrap X11_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_FBCON +extern VideoBootStrap FBCON_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_DIRECTFB +extern VideoBootStrap DirectFB_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_PS3 +extern VideoBootStrap PS3_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_SVGALIB +extern VideoBootStrap SVGALIB_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_GAPI +extern VideoBootStrap GAPI_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_WIN32 +extern VideoBootStrap WIN32_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_BWINDOW +extern VideoBootStrap BWINDOW_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_PHOTON +extern VideoBootStrap photon_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_QNXGF +extern VideoBootStrap qnxgf_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_EPOC +extern VideoBootStrap EPOC_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_RISCOS +extern VideoBootStrap RISCOS_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_UIKIT +extern VideoBootStrap UIKIT_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_ANDROID +extern VideoBootStrap ANDROID_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_DUMMY +extern VideoBootStrap DUMMY_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_NDS +extern VideoBootStrap NDS_bootstrap; +#endif +#if SDL_VIDEO_DRIVER_PANDORA +extern VideoBootStrap PND_bootstrap; +#endif + +#define SDL_CurrentDisplay (&_this->displays[_this->current_display]) +#define SDL_CurrentRenderer (SDL_CurrentDisplay->current_renderer) + +extern SDL_VideoDevice *SDL_GetVideoDevice(void); +extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode); +extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display); +extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode); +extern int SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display); +extern int SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode); +extern int SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode); +extern int SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode); +extern SDL_DisplayMode * SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode, SDL_DisplayMode * closest); +extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode); +extern int SDL_SetPaletteForDisplay(SDL_VideoDisplay * display, const SDL_Color * colors, int firstcolor, int ncolors); +extern int SDL_GetPaletteForDisplay(SDL_VideoDisplay * display, SDL_Color * colors, int firstcolor, int ncolors); +extern int SDL_SetGammaRampForDisplay(SDL_VideoDisplay * display, const Uint16 * red, const Uint16 * green, const Uint16 * blue); +extern int SDL_GetGammaRampForDisplay(SDL_VideoDisplay * display, Uint16 * red, Uint16 * green, Uint16 * blue); +extern void SDL_AddRenderDriver(SDL_VideoDisplay *display, const SDL_RenderDriver * driver); + +extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags); + +extern void SDL_OnWindowShown(SDL_Window * window); +extern void SDL_OnWindowHidden(SDL_Window * window); +extern void SDL_OnWindowResized(SDL_Window * window); +extern void SDL_OnWindowMinimized(SDL_Window * window); +extern void SDL_OnWindowRestored(SDL_Window * window); +extern void SDL_OnWindowFocusGained(SDL_Window * window); +extern void SDL_OnWindowFocusLost(SDL_Window * window); +extern SDL_Window * SDL_GetFocusWindow(void); + +#endif /* _SDL_sysvideo_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video-1.3.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video-1.3.h deleted file mode 120000 index 203da73fe..000000000 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video-1.3.h +++ /dev/null @@ -1 +0,0 @@ -../../../../sdl-1.3/include/SDL_video.h \ No newline at end of file diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video-1.3.h b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video-1.3.h new file mode 100644 index 000000000..2f0f1fe19 --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video-1.3.h @@ -0,0 +1,1468 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ + +/** + * \file SDL_video.h + * + * Header file for SDL video functions. + */ + +#ifndef _SDL_video_1_3_h +#define _SDL_video_1_3_h + +#include "SDL_stdinc.h" +#include "SDL_rect.h" +#include "SDL_pixels.h" +#include "SDL_surface.h" +#include "SDL_version.h" +#if ! SDL_VERSION_ATLEAST(1,3,0) +#include "SDL_video.h" +#endif + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/** + * \brief The structure that defines a display mode + * + * \sa SDL_GetNumDisplayModes() + * \sa SDL_GetDisplayMode() + * \sa SDL_GetDesktopDisplayMode() + * \sa SDL_GetCurrentDisplayMode() + * \sa SDL_GetClosestDisplayMode() + * \sa SDL_SetWindowDisplayMode() + * \sa SDL_GetWindowDisplayMode() + */ +typedef struct +{ + Uint32 format; /**< pixel format */ + int w; /**< width */ + int h; /**< height */ + int refresh_rate; /**< refresh rate (or zero for unspecified) */ + void *driverdata; /**< driver-specific data, initialize to 0 */ +} SDL_DisplayMode; + +/** + * \brief The type used to identify a window + * + * \sa SDL_CreateWindow() + * \sa SDL_CreateWindowFrom() + * \sa SDL_DestroyWindow() + * \sa SDL_GetWindowData() + * \sa SDL_GetWindowFlags() + * \sa SDL_GetWindowGrab() + * \sa SDL_GetWindowPosition() + * \sa SDL_GetWindowSize() + * \sa SDL_GetWindowTitle() + * \sa SDL_HideWindow() + * \sa SDL_MaximizeWindow() + * \sa SDL_MinimizeWindow() + * \sa SDL_RaiseWindow() + * \sa SDL_RestoreWindow() + * \sa SDL_SetWindowData() + * \sa SDL_SetWindowFullscreen() + * \sa SDL_SetWindowGrab() + * \sa SDL_SetWindowIcon() + * \sa SDL_SetWindowPosition() + * \sa SDL_SetWindowSize() + * \sa SDL_SetWindowTitle() + * \sa SDL_ShowWindow() + */ +typedef struct SDL_Window SDL_Window; + +/** + * \brief The flags on a window + * + * \sa SDL_GetWindowFlags() + */ +typedef enum +{ + SDL_WINDOW_FULLSCREEN = 0x00000001, /**< fullscreen window, implies borderless */ + SDL_WINDOW_OPENGL = 0x00000002, /**< window usable with OpenGL context */ + SDL_WINDOW_SHOWN = 0x00000004, /**< window is visible */ + SDL_WINDOW_BORDERLESS = 0x00000008, /**< no window decoration */ + SDL_WINDOW_RESIZABLE = 0x00000010, /**< window can be resized */ + SDL_WINDOW_MINIMIZED = 0x00000020, /**< window is minimized */ + SDL_WINDOW_MAXIMIZED = 0x00000040, /**< window is maximized */ + SDL_WINDOW_INPUT_GRABBED = 0x00000100, /**< window has grabbed input focus */ + SDL_WINDOW_INPUT_FOCUS = 0x00000200, /**< window has input focus */ + SDL_WINDOW_MOUSE_FOCUS = 0x00000400, /**< window has mouse focus */ + SDL_WINDOW_FOREIGN = 0x00000800 /**< window not created by SDL */ +} SDL_WindowFlags; + +/** + * \brief Used to indicate that you don't care what the window position is. + */ +#define SDL_WINDOWPOS_UNDEFINED 0x7FFFFFF + +/** + * \brief Used to indicate that the window position should be centered. + */ +#define SDL_WINDOWPOS_CENTERED 0x7FFFFFE + +/** + * \brief Event subtype for window events + */ +typedef enum +{ + SDL_WINDOWEVENT_NONE, /**< Never used */ + SDL_WINDOWEVENT_SHOWN, /**< Window has been shown */ + SDL_WINDOWEVENT_HIDDEN, /**< Window has been hidden */ + SDL_WINDOWEVENT_EXPOSED, /**< Window has been exposed and should be + redrawn */ + SDL_WINDOWEVENT_MOVED, /**< Window has been moved to data1, data2 + */ + SDL_WINDOWEVENT_RESIZED, /**< Window size changed to data1xdata2 */ + SDL_WINDOWEVENT_MINIMIZED, /**< Window has been minimized */ + SDL_WINDOWEVENT_MAXIMIZED, /**< Window has been maximized */ + SDL_WINDOWEVENT_RESTORED, /**< Window has been restored to normal size + and position */ + SDL_WINDOWEVENT_ENTER, /**< Window has gained mouse focus */ + SDL_WINDOWEVENT_LEAVE, /**< Window has lost mouse focus */ + SDL_WINDOWEVENT_FOCUS_GAINED, /**< Window has gained keyboard focus */ + SDL_WINDOWEVENT_FOCUS_LOST, /**< Window has lost keyboard focus */ + SDL_WINDOWEVENT_CLOSE /**< The window manager requests that the + window be closed */ +} SDL_WindowEventID; + +/** + * \brief Flags used when creating a rendering context + */ +typedef enum +{ + SDL_RENDERER_SINGLEBUFFER = 0x00000001, /**< Render directly to the + window, if possible */ + + SDL_RENDERER_PRESENTCOPY = 0x00000002, /**< Present uses a copy from + back buffer to the front + buffer */ + + SDL_RENDERER_PRESENTFLIP2 = 0x00000004, /**< Present uses a flip, + swapping back buffer and + front buffer */ + + SDL_RENDERER_PRESENTFLIP3 = 0x00000008, /**< Present uses a flip, + rotating between two back + buffers and a front buffer + */ + + SDL_RENDERER_PRESENTDISCARD = 0x00000010, /**< Present leaves the contents + of the backbuffer undefined + */ + + SDL_RENDERER_PRESENTVSYNC = 0x00000020, /**< Present is synchronized + with the refresh rate */ + + SDL_RENDERER_ACCELERATED = 0x00000040 /**< The renderer uses hardware + acceleration */ + + } SDL_RendererFlags; + +/** + * \brief Information on the capabilities of a render driver or context. + */ +typedef struct SDL_RendererInfo +{ + const char *name; /**< The name of the renderer */ + Uint32 flags; /**< Supported ::SDL_RendererFlags */ + Uint32 mod_modes; /**< A mask of supported channel modulation */ + Uint32 blend_modes; /**< A mask of supported blend modes */ + Uint32 scale_modes; /**< A mask of supported scale modes */ + Uint32 num_texture_formats; /**< The number of available texture formats */ + Uint32 texture_formats[20]; /**< The available texture formats */ + int max_texture_width; /**< The maximimum texture width */ + int max_texture_height; /**< The maximimum texture height */ +} SDL_RendererInfo; + +/** + * \brief The access pattern allowed for a texture. + */ +typedef enum +{ + SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */ + SDL_TEXTUREACCESS_STREAMING /**< Changes frequently, lockable */ +} SDL_TextureAccess; + +/** + * \brief The texture channel modulation used in SDL_RenderCopy(). + */ +typedef enum +{ + SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */ + SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */ + SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */ +} SDL_TextureModulate; + +/** + * \brief The blend mode used in SDL_RenderCopy() and drawing operations. + */ +typedef enum +{ + SDL_BLENDMODE_NONE = 0x00000000, /**< No blending */ + SDL_BLENDMODE_MASK = 0x00000001, /**< dst = A ? src : dst + (alpha is mask) */ + + SDL_BLENDMODE_BLEND = 0x00000002, /**< dst = (src * A) + (dst * (1-A)) */ + SDL_BLENDMODE_ADD = 0x00000004, /**< dst = (src * A) + dst */ + SDL_BLENDMODE_MOD = 0x00000008 /**< dst = src * dst */ +} SDL_BlendMode; + +/** + * \brief The texture scale mode used in SDL_RenderCopy(). + */ +typedef enum +{ + SDL_TEXTURESCALEMODE_NONE = 0x00000000, /**< No scaling, rectangles must + match dimensions */ + + SDL_TEXTURESCALEMODE_FAST = 0x00000001, /**< Point sampling or + equivalent algorithm */ + + SDL_TEXTURESCALEMODE_SLOW = 0x00000002, /**< Linear filtering or + equivalent algorithm */ + + SDL_TEXTURESCALEMODE_BEST = 0x00000004 /**< Bicubic filtering or + equivalent algorithm */ +} SDL_TextureScaleMode; + +/** + * \brief An efficient driver-specific representation of pixel data + */ +struct SDL_Texture; +typedef struct SDL_Texture SDL_Texture; + +/** + * \brief An opaque handle to an OpenGL context. + */ +typedef void *SDL_GLContext; + +#if SDL_VERSION_ATLEAST(1,3,0) +/** + * \brief OpenGL configuration attributes + */ +typedef enum +{ + SDL_GL_RED_SIZE, + SDL_GL_GREEN_SIZE, + SDL_GL_BLUE_SIZE, + SDL_GL_ALPHA_SIZE, + SDL_GL_BUFFER_SIZE, + SDL_GL_DOUBLEBUFFER, + SDL_GL_DEPTH_SIZE, + SDL_GL_STENCIL_SIZE, + SDL_GL_ACCUM_RED_SIZE, + SDL_GL_ACCUM_GREEN_SIZE, + SDL_GL_ACCUM_BLUE_SIZE, + SDL_GL_ACCUM_ALPHA_SIZE, + SDL_GL_STEREO, + SDL_GL_MULTISAMPLEBUFFERS, + SDL_GL_MULTISAMPLESAMPLES, + SDL_GL_ACCELERATED_VISUAL, + SDL_GL_RETAINED_BACKING, + SDL_GL_CONTEXT_MAJOR_VERSION, + SDL_GL_CONTEXT_MINOR_VERSION +} SDL_GLattr; +#endif + +/* Function prototypes */ + +/** + * \brief Get the number of video drivers compiled into SDL + * + * \sa SDL_GetVideoDriver() + */ +extern DECLSPEC int SDLCALL SDL_GetNumVideoDrivers(void); + +/** + * \brief Get the name of a built in video driver. + * + * \note The video drivers are presented in the order in which they are + * normally checked during initialization. + * + * \sa SDL_GetNumVideoDrivers() + */ +extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index); + +/** + * \brief Initialize the video subsystem, optionally specifying a video driver. + * + * \param driver_name Initialize a specific driver by name, or NULL for the + * default video driver. + * + * \param flags FIXME: Still needed? + * + * \return 0 on success, -1 on error + * + * This function initializes the video subsystem; setting up a connection + * to the window manager, etc, and determines the available display modes + * and pixel formats, but does not initialize a window or graphics mode. + * + * \sa SDL_VideoQuit() + */ +extern DECLSPEC int SDLCALL +#if SDL_VERSION_ATLEAST(1,3,0) +SDL_VideoInit +#else +SDL_VideoInit_1_3 +#endif +(const char *driver_name, Uint32 flags); + +/** + * \brief Shuts down the video subsystem. + * + * This function closes all windows, and restores the original video mode. + * + * \sa SDL_VideoInit() + */ +extern DECLSPEC void SDLCALL SDL_VideoQuit(void); + +/** + * \brief Returns the name of the currently initialized video driver. + * + * \return The name of the current video driver or NULL if no driver + * has been initialized + * + * \sa SDL_GetNumVideoDrivers() + * \sa SDL_GetVideoDriver() + */ +extern DECLSPEC const char *SDLCALL SDL_GetCurrentVideoDriver(void); + +/** + * \brief Returns the number of available video displays. + * + * \sa SDL_GetDisplayBounds() + * \sa SDL_SelectVideoDisplay() + */ +extern DECLSPEC int SDLCALL SDL_GetNumVideoDisplays(void); + +/** + * \brief Get the desktop area represented by a display, with the primary + * display located at 0,0 + * + * \return 0 on success, or -1 if the index is out of range. + * + * \sa SDL_GetNumVideoDisplays() + */ +extern DECLSPEC int SDLCALL SDL_GetDisplayBounds(int index, SDL_Rect * rect); + +/** + * \brief Set the index of the currently selected display. + * + * \return 0 on success, or -1 if the index is out of range. + * + * \sa SDL_GetNumVideoDisplays() + * \sa SDL_GetCurrentVideoDisplay() + */ +extern DECLSPEC int SDLCALL SDL_SelectVideoDisplay(int index); + +/** + * \brief Get the index of the currently selected display. + * + * \return The index of the currently selected display. + * + * \sa SDL_GetNumVideoDisplays() + * \sa SDL_SelectVideoDisplay() + */ +extern DECLSPEC int SDLCALL SDL_GetCurrentVideoDisplay(void); + +/** + * \brief Returns the number of available display modes for the current display. + * + * \sa SDL_GetDisplayMode() + */ +extern DECLSPEC int SDLCALL SDL_GetNumDisplayModes(void); + +/** + * \brief Fill in information about a specific display mode. + * + * \note The display modes are sorted in this priority: + * \li bits per pixel -> more colors to fewer colors + * \li width -> largest to smallest + * \li height -> largest to smallest + * \li refresh rate -> highest to lowest + * + * \sa SDL_GetNumDisplayModes() + */ +extern DECLSPEC int SDLCALL SDL_GetDisplayMode(int index, + SDL_DisplayMode * mode); + +/** + * \brief Fill in information about the desktop display mode for the current + * display. + */ +extern DECLSPEC int SDLCALL SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode); + +/** + * \brief Fill in information about the current display mode. + */ +extern DECLSPEC int SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode); + + +/** + * \brief Get the closest match to the requested display mode. + * + * \param mode The desired display mode + * \param closest A pointer to a display mode to be filled in with the closest + * match of the available display modes. + * + * \return The passed in value \c closest, or NULL if no matching video mode + * was available. + * + * The available display modes are scanned, and \c closest is filled in with the + * closest mode matching the requested mode and returned. The mode format and + * refresh_rate default to the desktop mode if they are 0. The modes are + * scanned with size being first priority, format being second priority, and + * finally checking the refresh_rate. If all the available modes are too + * small, then NULL is returned. + * + * \sa SDL_GetNumDisplayModes() + * \sa SDL_GetDisplayMode() + */ +extern DECLSPEC SDL_DisplayMode *SDLCALL SDL_GetClosestDisplayMode(const + SDL_DisplayMode + * mode, + SDL_DisplayMode + * closest); + +/** + * \brief Set the display mode used when a fullscreen window is visible + * on the currently selected display. By default the window's + * dimensions and the desktop format and refresh rate are used. + * + * \param mode The mode to use, or NULL for the default mode. + * + * \return 0 on success, or -1 if setting the display mode failed. + * + * \sa SDL_GetWindowDisplayMode() + * \sa SDL_SetWindowFullscreen() + */ +extern DECLSPEC int SDLCALL SDL_SetWindowDisplayMode(SDL_Window * window, + const SDL_DisplayMode + * mode); + +/** + * \brief Fill in information about the display mode used when a fullscreen + * window is visible on the currently selected display. + * + * \sa SDL_SetWindowDisplayMode() + * \sa SDL_SetWindowFullscreen() + */ +extern DECLSPEC int SDLCALL SDL_GetWindowDisplayMode(SDL_Window * window, + SDL_DisplayMode * mode); + +/** + * \brief Set the palette entries for indexed display modes. + * + * \return 0 on success, or -1 if the display mode isn't palettized or the + * colors couldn't be set. + */ +extern DECLSPEC int SDLCALL SDL_SetDisplayPalette(const SDL_Color * colors, + int firstcolor, + int ncolors); + +/** + * \brief Gets the palette entries for indexed display modes. + * + * \return 0 on success, or -1 if the display mode isn't palettized + */ +extern DECLSPEC int SDLCALL SDL_GetDisplayPalette(SDL_Color * colors, + int firstcolor, + int ncolors); + +/** + * \brief Set the gamma correction for each of the color channels on the + * currently selected display. + * + * \return 0 on success, or -1 if setting the gamma isn't supported. + * + * \sa SDL_SetGammaRamp() + */ +extern DECLSPEC int SDLCALL SDL_SetGamma(float red, float green, float blue); + +/** + * \brief Set the gamma ramp for the currently selected display. + * + * \param red The translation table for the red channel, or NULL. + * \param green The translation table for the green channel, or NULL. + * \param blue The translation table for the blue channel, or NULL. + * + * \return 0 on success, or -1 if gamma ramps are unsupported. + * + * Set the gamma translation table for the red, green, and blue channels + * of the video hardware. Each table is an array of 256 16-bit quantities, + * representing a mapping between the input and output for that channel. + * The input is the index into the array, and the output is the 16-bit + * gamma value at that index, scaled to the output color precision. + * + * \sa SDL_GetGammaRamp() + */ +extern DECLSPEC int SDLCALL SDL_SetGammaRamp(const Uint16 * red, + const Uint16 * green, + const Uint16 * blue); + +/** + * \brief Get the gamma ramp for the currently selected display. + * + * \param red A pointer to a 256 element array of 16-bit quantities to hold + * the translation table for the red channel, or NULL. + * \param green A pointer to a 256 element array of 16-bit quantities to hold + * the translation table for the green channel, or NULL. + * \param blue A pointer to a 256 element array of 16-bit quantities to hold + * the translation table for the blue channel, or NULL. + * + * \return 0 on success, or -1 if gamma ramps are unsupported. + * + * \sa SDL_SetGammaRamp() + */ +extern DECLSPEC int SDLCALL SDL_GetGammaRamp(Uint16 * red, Uint16 * green, + Uint16 * blue); + + +/** + * \brief Create a window with the specified position, dimensions, and flags. + * + * \param title The title of the window, in UTF-8 encoding. + * \param x The x position of the window, ::SDL_WINDOWPOS_CENTERED, or + * ::SDL_WINDOWPOS_UNDEFINED. + * \param y The y position of the window, ::SDL_WINDOWPOS_CENTERED, or + * ::SDL_WINDOWPOS_UNDEFINED. + * \param w The width of the window. + * \param h The height of the window. + * \param flags The flags for the window, a mask of any of the following: + * ::SDL_WINDOW_FULLSCREEN, ::SDL_WINDOW_OPENGL, + * ::SDL_WINDOW_SHOWN, ::SDL_WINDOW_BORDERLESS, + * ::SDL_WINDOW_RESIZABLE, ::SDL_WINDOW_MAXIMIZED, + * ::SDL_WINDOW_MINIMIZED, ::SDL_WINDOW_INPUT_GRABBED. + * + * \return The id of the window created, or zero if window creation failed. + * + * \sa SDL_DestroyWindow() + */ +extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindow(const char *title, + int x, int y, int w, + int h, Uint32 flags); + +/** + * \brief Create an SDL window from an existing native window. + * + * \param data A pointer to driver-dependent window creation data + * + * \return The id of the window created, or zero if window creation failed. + * + * \sa SDL_DestroyWindow() + */ +extern DECLSPEC SDL_Window * SDLCALL SDL_CreateWindowFrom(const void *data); + +/** + * \brief Get the numeric ID of the window, for logging purposes. + */ +extern DECLSPEC Uint32 SDLCALL SDL_GetWindowID(SDL_Window * window); + +/** + * \brief Get a window from a stored ID, or NULL if it doesn't exist. + */ +extern DECLSPEC SDL_Window * SDLCALL SDL_GetWindowFromID(Uint32 id); + +/** + * \brief Get the window flags. + */ +extern DECLSPEC Uint32 SDLCALL SDL_GetWindowFlags(SDL_Window * window); + +/** + * \brief Set the title of the window, in UTF-8 format. + * + * \sa SDL_GetWindowTitle() + */ +extern DECLSPEC void SDLCALL SDL_SetWindowTitle(SDL_Window * window, + const char *title); + +/** + * \brief Get the title of the window, in UTF-8 format. + * + * \sa SDL_SetWindowTitle() + */ +extern DECLSPEC const char *SDLCALL SDL_GetWindowTitle(SDL_Window * window); + +/** + * \brief Set the icon of the window. + * + * \param icon The icon for the window. + */ +extern DECLSPEC void SDLCALL SDL_SetWindowIcon(SDL_Window * window, + SDL_Surface * icon); + +/** + * \brief Associate an arbitrary pointer with the window. + * + * \sa SDL_GetWindowData() + */ +extern DECLSPEC void SDLCALL SDL_SetWindowData(SDL_Window * window, + void *userdata); + +/** + * \brief Retrieve the data pointer associated with the window. + * + * \sa SDL_SetWindowData() + */ +extern DECLSPEC void *SDLCALL SDL_GetWindowData(SDL_Window * window); + +/** + * \brief Set the position of the window. + * + * \param window The window to reposition. + * \param x The x coordinate of the window, ::SDL_WINDOWPOS_CENTERED, or + ::SDL_WINDOWPOS_UNDEFINED. + * \param y The y coordinate of the window, ::SDL_WINDOWPOS_CENTERED, or + ::SDL_WINDOWPOS_UNDEFINED. + * + * \note The window coordinate origin is the upper left of the display. + * + * \sa SDL_GetWindowPosition() + */ +extern DECLSPEC void SDLCALL SDL_SetWindowPosition(SDL_Window * window, + int x, int y); + +/** + * \brief Get the position of the window. + * + * \sa SDL_SetWindowPosition() + */ +extern DECLSPEC void SDLCALL SDL_GetWindowPosition(SDL_Window * window, + int *x, int *y); + +/** + * \brief Set the size of the window's client area. + * + * \note You can't change the size of a fullscreen window, it automatically + * matches the size of the display mode. + * + * \sa SDL_GetWindowSize() + */ +extern DECLSPEC void SDLCALL SDL_SetWindowSize(SDL_Window * window, int w, + int h); + +/** + * \brief Get the size of the window's client area. + * + * \sa SDL_SetWindowSize() + */ +extern DECLSPEC void SDLCALL SDL_GetWindowSize(SDL_Window * window, int *w, + int *h); + +/** + * \brief Show the window. + * + * \sa SDL_HideWindow() + */ +extern DECLSPEC void SDLCALL SDL_ShowWindow(SDL_Window * window); + +/** + * \brief Hide the window. + * + * \sa SDL_ShowWindow() + */ +extern DECLSPEC void SDLCALL SDL_HideWindow(SDL_Window * window); + +/** + * \brief Raise the window above other windows and set the input focus. + */ +extern DECLSPEC void SDLCALL SDL_RaiseWindow(SDL_Window * window); + +/** + * \brief Make the window as large as possible. + * + * \sa SDL_RestoreWindow() + */ +extern DECLSPEC void SDLCALL SDL_MaximizeWindow(SDL_Window * window); + +/** + * \brief Minimize the window to an iconic representation. + * + * \sa SDL_RestoreWindow() + */ +extern DECLSPEC void SDLCALL SDL_MinimizeWindow(SDL_Window * window); + +/** + * \brief Restore the size and position of a minimized or maximized window. + * + * \sa SDL_MaximizeWindow() + * \sa SDL_MinimizeWindow() + */ +extern DECLSPEC void SDLCALL SDL_RestoreWindow(SDL_Window * window); + +/** + * \brief Set the window's fullscreen state. + * + * \return 0 on success, or -1 if setting the display mode failed. + * + * \sa SDL_SetWindowDisplayMode() + * \sa SDL_GetWindowDisplayMode() + */ +extern DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window * window, + int fullscreen); + +/** + * \brief Set the window's input grab mode. + * + * \param mode This is 1 to grab input, and 0 to release input. + * + * \sa SDL_GetWindowGrab() + */ +extern DECLSPEC void SDLCALL SDL_SetWindowGrab(SDL_Window * window, + int mode); + +/** + * \brief Get the window's input grab mode. + * + * \return This returns 1 if input is grabbed, and 0 otherwise. + * + * \sa SDL_SetWindowGrab() + */ +extern DECLSPEC int SDLCALL SDL_GetWindowGrab(SDL_Window * window); + +/** + * \brief Get driver specific information about a window. + * + * \note Include SDL_syswm.h for the declaration of SDL_SysWMinfo. + */ +struct SDL_SysWMinfo; +extern DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window * window, + struct SDL_SysWMinfo + *info); + +/** + * \brief Destroy a window. + */ +extern DECLSPEC void SDLCALL SDL_DestroyWindow(SDL_Window * window); + +/** + * \brief Get the number of 2D rendering drivers available for the current + * display. + * + * A render driver is a set of code that handles rendering and texture + * management on a particular display. Normally there is only one, but + * some drivers may have several available with different capabilities. + * + * \sa SDL_GetRenderDriverInfo() + * \sa SDL_CreateRenderer() + */ +extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void); + +/** + * \brief Get information about a specific 2D rendering driver for the current + * display. + * + * \param index The index of the driver to query information about. + * \param info A pointer to an SDL_RendererInfo struct to be filled with + * information on the rendering driver. + * + * \return 0 on success, -1 if the index was out of range. + * + * \sa SDL_CreateRenderer() + */ +extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index, + SDL_RendererInfo * info); + +/** + * \brief Create and make active a 2D rendering context for a window. + * + * \param window The window where rendering is displayed. + * \param index The index of the rendering driver to initialize, or -1 to + * initialize the first one supporting the requested flags. + * \param flags ::SDL_RendererFlags. + * + * \return 0 on success, -1 if there was an error creating the renderer. + * + * \sa SDL_SelectRenderer() + * \sa SDL_GetRendererInfo() + * \sa SDL_DestroyRenderer() + */ +extern DECLSPEC int SDLCALL SDL_CreateRenderer(SDL_Window * window, + int index, Uint32 flags); + +/** + * \brief Select the rendering context for a particular window. + * + * \return 0 on success, -1 if the selected window doesn't have a + * rendering context. + */ +extern DECLSPEC int SDLCALL SDL_SelectRenderer(SDL_Window * window); + +/** + * \brief Get information about the current rendering context. + */ +extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_RendererInfo * info); + +/** + * \brief Create a texture for the current rendering context. + * + * \param format The format of the texture. + * \param access One of the enumerated values in ::SDL_TextureAccess. + * \param w The width of the texture in pixels. + * \param h The height of the texture in pixels. + * + * \return The created texture is returned, or 0 if no rendering context was + * active, the format was unsupported, or the width or height were out + * of range. + * + * \sa SDL_QueryTexture() + * \sa SDL_DestroyTexture() + */ +extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(Uint32 format, + int access, int w, + int h); + +/** + * \brief Create a texture from an existing surface. + * + * \param format The format of the texture, or 0 to pick an appropriate format. + * \param surface The surface containing pixel data used to fill the texture. + * + * \return The created texture is returned, or 0 if no rendering context was + * active, the format was unsupported, or the surface width or height + * were out of range. + * + * \note The surface is not modified or freed by this function. + * + * \sa SDL_QueryTexture() + * \sa SDL_DestroyTexture() + */ +extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(Uint32 + format, + SDL_Surface + * surface); + +/** + * \brief Query the attributes of a texture + * + * \param texture A texture to be queried. + * \param format A pointer filled in with the raw format of the texture. The + * actual format may differ, but pixel transfers will use this + * format. + * \param access A pointer filled in with the actual access to the texture. + * \param w A pointer filled in with the width of the texture in pixels. + * \param h A pointer filled in with the height of the texture in pixels. + * + * \return 0 on success, or -1 if the texture is not valid. + */ +extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture, + Uint32 * format, int *access, + int *w, int *h); + +/** + * \brief Query the pixels of a texture, if the texture does not need to be + * locked for pixel access. + * + * \param texture A texture to be queried, which was created with + * ::SDL_TEXTUREACCESS_STREAMING. + * \param pixels A pointer filled with a pointer to the pixels for the + * texture. + * \param pitch A pointer filled in with the pitch of the pixel data. + * + * \return 0 on success, or -1 if the texture is not valid, or must be locked + * for pixel access. + */ +extern DECLSPEC int SDLCALL SDL_QueryTexturePixels(SDL_Texture * texture, + void **pixels, int *pitch); + +/** + * \brief Set the color palette of an indexed texture. + * + * \param texture The texture to update. + * \param colors The array of RGB color data. + * \param firstcolor The first index to update. + * \param ncolors The number of palette entries to fill with the color data. + * + * \return 0 on success, or -1 if the texture is not valid or not an indexed + * texture. + */ +extern DECLSPEC int SDLCALL SDL_SetTexturePalette(SDL_Texture * texture, + const SDL_Color * colors, + int firstcolor, + int ncolors); + +/** + * \brief Get the color palette from an indexed texture if it has one. + * + * \param texture The texture to update. + * \param colors The array to fill with RGB color data. + * \param firstcolor The first index to retrieve. + * \param ncolors The number of palette entries to retrieve. + * + * \return 0 on success, or -1 if the texture is not valid or not an indexed + * texture. + */ +extern DECLSPEC int SDLCALL SDL_GetTexturePalette(SDL_Texture * texture, + SDL_Color * colors, + int firstcolor, + int ncolors); + +/** + * \brief Set an additional color value used in render copy operations. + * + * \param texture The texture to update. + * \param r The red source color value multiplied into copy operations. + * \param g The green source color value multiplied into copy operations. + * \param b The blue source color value multiplied into copy operations. + * + * \return 0 on success, or -1 if the texture is not valid or color modulation + * is not supported. + * + * \sa SDL_GetTextureColorMod() + */ +extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture, + Uint8 r, Uint8 g, Uint8 b); + + +/** + * \brief Get the additional color value used in render copy operations. + * + * \param texture The texture to query. + * \param r A pointer filled in with the source red color value. + * \param g A pointer filled in with the source green color value. + * \param b A pointer filled in with the source blue color value. + * + * \return 0 on success, or -1 if the texture is not valid. + * + * \sa SDL_SetTextureColorMod() + */ +extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture, + Uint8 * r, Uint8 * g, + Uint8 * b); + +/** + * \brief Set an additional alpha value used in render copy operations. + * + * \param texture The texture to update. + * \param alpha The source alpha value multiplied into copy operations. + * + * \return 0 on success, or -1 if the texture is not valid or alpha modulation + * is not supported. + * + * \sa SDL_GetTextureAlphaMod() + */ +extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture, + Uint8 alpha); + +/** + * \brief Get the additional alpha value used in render copy operations. + * + * \param texture The texture to query. + * \param alpha A pointer filled in with the source alpha value. + * + * \return 0 on success, or -1 if the texture is not valid. + * + * \sa SDL_SetTextureAlphaMod() + */ +extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture, + Uint8 * alpha); + +/** + * \brief Set the blend mode used for texture copy operations. + * + * \param texture The texture to update. + * \param blendMode ::SDL_BlendMode to use for texture blending. + * + * \return 0 on success, or -1 if the texture is not valid or the blend mode is + * not supported. + * + * \note If the blend mode is not supported, the closest supported mode is + * chosen. + * + * \sa SDL_GetTextureBlendMode() + */ +extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture, + int blendMode); + +/** + * \brief Get the blend mode used for texture copy operations. + * + * \param texture The texture to query. + * \param blendMode A pointer filled in with the current blend mode. + * + * \return 0 on success, or -1 if the texture is not valid. + * + * \sa SDL_SetTextureBlendMode() + */ +extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture, + int *blendMode); + +/** + * \brief Set the scale mode used for texture copy operations. + * + * \param texture The texture to update. + * \param scaleMode ::SDL_TextureScaleMode to use for texture scaling. + * + * \return 0 on success, or -1 if the texture is not valid or the scale mode is + * not supported. + * + * \note If the scale mode is not supported, the closest supported mode is + * chosen. + * + * \sa SDL_GetTextureScaleMode() + */ +extern DECLSPEC int SDLCALL SDL_SetTextureScaleMode(SDL_Texture * texture, + int scaleMode); + +/** + * \brief Get the scale mode used for texture copy operations. + * + * \param texture The texture to query. + * \param scaleMode A pointer filled in with the current scale mode. + * + * \return 0 on success, or -1 if the texture is not valid. + * + * \sa SDL_SetTextureScaleMode() + */ +extern DECLSPEC int SDLCALL SDL_GetTextureScaleMode(SDL_Texture * texture, + int *scaleMode); + +/** + * \brief Update the given texture rectangle with new pixel data. + * + * \param texture The texture to update + * \param rect A pointer to the rectangle of pixels to update, or NULL to + * update the entire texture. + * \param pixels The raw pixel data. + * \param pitch The number of bytes between rows of pixel data. + * + * \return 0 on success, or -1 if the texture is not valid. + * + * \note This is a fairly slow function. + */ +extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture, + const SDL_Rect * rect, + const void *pixels, int pitch); + +/** + * \brief Lock a portion of the texture for pixel access. + * + * \param texture The texture to lock for access, which was created with + * ::SDL_TEXTUREACCESS_STREAMING. + * \param rect A pointer to the rectangle to lock for access. If the rect + * is NULL, the entire texture will be locked. + * \param markDirty If this is nonzero, the locked area will be marked dirty + * when the texture is unlocked. + * \param pixels This is filled in with a pointer to the locked pixels, + * appropriately offset by the locked area. + * \param pitch This is filled in with the pitch of the locked pixels. + * + * \return 0 on success, or -1 if the texture is not valid or was created with + * ::SDL_TEXTUREACCESS_STATIC. + * + * \sa SDL_DirtyTexture() + * \sa SDL_UnlockTexture() + */ +extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture, + const SDL_Rect * rect, + int markDirty, void **pixels, + int *pitch); + +/** + * \brief Unlock a texture, uploading the changes to video memory, if needed. + * + * \sa SDL_LockTexture() + * \sa SDL_DirtyTexture() + */ +extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture); + +/** + * \brief Mark the specified rectangles of the texture as dirty. + * + * \param texture The texture to mark dirty, which was created with + * ::SDL_TEXTUREACCESS_STREAMING. + * \param numrects The number of rectangles pointed to by rects. + * \param rects The pointer to an array of dirty rectangles. + * + * \sa SDL_LockTexture() + * \sa SDL_UnlockTexture() + */ +extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_Texture * texture, + int numrects, + const SDL_Rect * rects); + +/** + * \brief Set the color used for drawing operations (Fill and Line). + * + * \param r The red value used to draw on the rendering target. + * \param g The green value used to draw on the rendering target. + * \param b The blue value used to draw on the rendering target. + * \param a The alpha value used to draw on the rendering target, usually + * ::SDL_ALPHA_OPAQUE (255). + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, + Uint8 a); + +/** + * \brief Get the color used for drawing operations (Fill and Line). + * + * \param r A pointer to the red value used to draw on the rendering target. + * \param g A pointer to the green value used to draw on the rendering target. + * \param b A pointer to the blue value used to draw on the rendering target. + * \param a A pointer to the alpha value used to draw on the rendering target, + * usually ::SDL_ALPHA_OPAQUE (255). + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDL_GetRenderDrawColor(Uint8 * r, Uint8 * g, Uint8 * b, + Uint8 * a); + +/** + * \brief Set the blend mode used for drawing operations (Fill and Line). + * + * \param blendMode ::SDL_BlendMode to use for blending. + * + * \return 0 on success, or -1 if there is no rendering context current. + * + * \note If the blend mode is not supported, the closest supported mode is + * chosen. + * + * \sa SDL_GetRenderDrawBlendMode() + */ +extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(int blendMode); + +/** + * \brief Get the blend mode used for drawing operations. + * + * \param blendMode A pointer filled in with the current blend mode. + * + * \return 0 on success, or -1 if there is no rendering context current. + * + * \sa SDL_SetRenderDrawBlendMode() + */ +extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode); + +/** + * \brief Clear the current rendering target with the drawing color + */ +extern DECLSPEC int SDLCALL SDL_RenderClear(void); + +/** + * \brief Draw a point on the current rendering target. + * + * \param x The x coordinate of the point. + * \param y The y coordinate of the point. + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(int x, int y); + +/** + * \brief Draw some number of points on the current rendering target. + * + * \param points The points to draw + * \param count The number of points to draw + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(const SDL_Point * points, + int count); + +/** + * \brief Draw a line on the current rendering target. + * + * \param x1 The x coordinate of the start point. + * \param y1 The y coordinate of the start point. + * \param x2 The x coordinate of the end point. + * \param y2 The y coordinate of the end point. + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderDrawLine(int x1, int y1, int x2, int y2); + +/** + * \brief Draw a series of connected lines on the current rendering target. + * + * \param points The points along the lines + * \param count The number of points, drawing count-1 lines + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderDrawLines(const SDL_Point * points, + int count); + +/** + * \brief Draw a rectangle on the current rendering target with the drawing color. + * + * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target. + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderDrawRect(const SDL_Rect * rect); + +/** + * \brief Draw some number of rectangles in the current rendering target with the drawing color. + * + * \param rects A pointer to an array of destination rectangles. + * \param count The number of rectangles. + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderDrawRects(const SDL_Rect ** rect, int count); + +/** + * \brief Fill a rectangle on the current rendering target with the drawing color. + * + * \param rect A pointer to the destination rectangle, or NULL for the entire + * rendering target. + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderFillRect(const SDL_Rect * rect); + +/** + * \brief Fill some number of rectangles in the current rendering target with the drawing color. + * + * \param rects A pointer to an array of destination rectangles. + * \param count The number of rectangles. + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderFillRects(const SDL_Rect ** rect, int count); + +/** + * \brief Copy a portion of the texture to the current rendering target. + * + * \param texture The source texture. + * \param srcrect A pointer to the source rectangle, or NULL for the entire + * texture. + * \param dstrect A pointer to the destination rectangle, or NULL for the + * entire rendering target. + * + * \return 0 on success, or -1 if there is no rendering context current, or the + * driver doesn't support the requested operation. + */ +extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Texture * texture, + const SDL_Rect * srcrect, + const SDL_Rect * dstrect); + +/** + * \brief Read pixels from the current rendering target. + * + * \param rect A pointer to the rectangle to read, or NULL for the entire + * render target. + * \param format The desired format of the pixel data, or 0 to use the format + * of the rendering target + * \param pixels A pointer to be filled in with the pixel data + * \param pitch The pitch of the pixels parameter. + * + * \return 0 on success, or -1 if pixel reading is not supported. + * + * \warning This is a very slow operation, and should not be used frequently. + */ +extern DECLSPEC int SDLCALL SDL_RenderReadPixels(const SDL_Rect * rect, + Uint32 format, + void *pixels, int pitch); + +/** + * \brief Write pixels to the current rendering target. + * + * \param rect A pointer to the rectangle to write, or NULL for the entire + * render target. + * \param format The format of the pixel data, or 0 to use the format + * of the rendering target + * \param pixels A pointer to the pixel data to write. + * \param pitch The pitch of the pixels parameter. + * + * \return 0 on success, or -1 if pixel writing is not supported. + * + * \warning This is a very slow operation, and should not be used frequently. + */ +extern DECLSPEC int SDLCALL SDL_RenderWritePixels(const SDL_Rect * rect, + Uint32 format, + const void *pixels, + int pitch); + +/** + * \brief Update the screen with rendering performed. + */ +extern DECLSPEC void SDLCALL SDL_RenderPresent(void); + +/** + * \brief Destroy the specified texture. + * + * \sa SDL_CreateTexture() + * \sa SDL_CreateTextureFromSurface() + */ +extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture); + +/** + * \brief Destroy the rendering context for a window and free associated + * textures. + * + * \sa SDL_CreateRenderer() + */ +extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Window * window); + +/** + * \brief Returns whether the screensaver is currently enabled (default off). + * + * \sa SDL_EnableScreenSaver() + * \sa SDL_DisableScreenSaver() + */ +extern DECLSPEC SDL_bool SDLCALL SDL_IsScreenSaverEnabled(void); + +/** + * \brief Allow the screen to be blanked by a screensaver + * + * \sa SDL_IsScreenSaverEnabled() + * \sa SDL_DisableScreenSaver() + */ +extern DECLSPEC void SDLCALL SDL_EnableScreenSaver(void); + +/** + * \brief Prevent the screen from being blanked by a screensaver + * + * \sa SDL_IsScreenSaverEnabled() + * \sa SDL_EnableScreenSaver() + */ +extern DECLSPEC void SDLCALL SDL_DisableScreenSaver(void); + + +/** + * \name OpenGL support functions + */ +/*@{*/ + +/** + * \brief Dynamically load an OpenGL library. + * + * \param path The platform dependent OpenGL library name, or NULL to open the + * default OpenGL library. + * + * \return 0 on success, or -1 if the library couldn't be loaded. + * + * This should be done after initializing the video driver, but before + * creating any OpenGL windows. If no OpenGL library is loaded, the default + * library will be loaded upon creation of the first OpenGL window. + * + * \note If you do this, you need to retrieve all of the GL functions used in + * your program from the dynamic library using SDL_GL_GetProcAddress(). + * + * \sa SDL_GL_GetProcAddress() + * \sa SDL_GL_UnloadLibrary() + */ +extern DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path); + +/** + * \brief Get the address of an OpenGL function. + */ +extern DECLSPEC void *SDLCALL SDL_GL_GetProcAddress(const char *proc); + +/** + * \brief Unload the OpenGL library previously loaded by SDL_GL_LoadLibrary(). + * + * \sa SDL_GL_LoadLibrary() + */ +extern DECLSPEC void SDLCALL SDL_GL_UnloadLibrary(void); + +/** + * \brief Return true if an OpenGL extension is supported for the current + * context. + */ +extern DECLSPEC SDL_bool SDLCALL SDL_GL_ExtensionSupported(const char + *extension); + +/** + * \brief Set an OpenGL window attribute before window creation. + */ +extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value); + +/** + * \brief Get the actual value for an attribute from the current context. + */ +extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value); + +/** + * \brief Create an OpenGL context for use with an OpenGL window, and make it + * current. + * + * \sa SDL_GL_DeleteContext() + */ +extern DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window * + window); + +/** + * \brief Set up an OpenGL context for rendering into an OpenGL window. + * + * \note The context must have been created with a compatible window. + */ +extern DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_Window * window, + SDL_GLContext context); + +/** + * \brief Set the swap interval for the current OpenGL context. + * + * \param interval 0 for immediate updates, 1 for updates synchronized with the + * vertical retrace. + * + * \return 0 on success, or -1 if setting the swap interval is not supported. + * + * \sa SDL_GL_GetSwapInterval() + */ +extern DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval); + +/** + * \brief Get the swap interval for the current OpenGL context. + * + * \return 0 if there is no vertical retrace synchronization, 1 if the buffer + * swap is synchronized with the vertical retrace, and -1 if getting + * the swap interval is not supported. + * + * \sa SDL_GL_SetSwapInterval() + */ +extern DECLSPEC int SDLCALL SDL_GL_GetSwapInterval(void); + +/** + * \brief Swap the OpenGL buffers for the window, if double-buffering is + * supported. + */ +extern DECLSPEC void SDLCALL SDL_GL_SwapWindow(SDL_Window * window); + +/** + * \brief Delete an OpenGL context. + * + * \sa SDL_GL_CreateContext() + */ +extern DECLSPEC void SDLCALL SDL_GL_DeleteContext(SDL_GLContext context); + +/*@}*//*OpenGL support functions*/ + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif +#include "close_code.h" + +#endif /* _SDL_video_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video.c b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video.c deleted file mode 120000 index 19ecad5a4..000000000 --- a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video.c +++ /dev/null @@ -1 +0,0 @@ -../../../../sdl-1.3/src/video/SDL_video.c \ No newline at end of file diff --git a/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video.c b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video.c new file mode 100644 index 000000000..f46ba8bb9 --- /dev/null +++ b/alienblaster/project/sdl/sdl-1.2/src/video/android/SDL_video.c @@ -0,0 +1,3675 @@ +/* + SDL - Simple DirectMedia Layer + Copyright (C) 1997-2010 Sam Lantinga + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + Sam Lantinga + slouken@libsdl.org +*/ +#include "SDL_config.h" +#include "SDL_version.h" + +/* The high-level video driver subsystem */ + +#include "SDL.h" +#if SDL_VERSION_ATLEAST(1,3,0) +#include "SDL_video.h" +#include "SDL_sysvideo.h" +#else +#include "SDL_video-1.3.h" +#include "SDL_sysvideo-1.3.h" +#include "SDL_androidvideo.h" +#endif +#include "SDL_blit.h" +#include "SDL_pixels_c.h" +#include "SDL_renderer_gl.h" +#include "SDL_renderer_gles.h" +#include "SDL_renderer_sw.h" +#if SDL_VERSION_ATLEAST(1,3,0) +#include "../events/SDL_sysevents.h" +#include "../events/SDL_events_c.h" +#endif +#ifdef ANDROID +#include +#endif + +#if SDL_VIDEO_OPENGL_ES +#include "SDL_opengles.h" +#endif /* SDL_VIDEO_OPENGL_ES */ + +#if SDL_VIDEO_OPENGL +#include "SDL_opengl.h" + +/* On Windows, windows.h defines CreateWindow */ +#ifdef CreateWindow +#undef CreateWindow +#endif +#endif /* SDL_VIDEO_OPENGL */ + +/* Available video drivers */ +static VideoBootStrap *bootstrap[] = { +#if SDL_VIDEO_DRIVER_COCOA + &COCOA_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_X11 + &X11_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_FBCON + &FBCON_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_DIRECTFB + &DirectFB_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_PS3 + &PS3_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_SVGALIB + &SVGALIB_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_GAPI + &GAPI_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_WIN32 + &WIN32_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_BWINDOW + &BWINDOW_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_PHOTON + &photon_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_QNXGF + &qnxgf_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_EPOC + &EPOC_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_RISCOS + &RISCOS_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_NDS + &NDS_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_UIKIT + &UIKIT_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_ANDROID + &ANDROID_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_DUMMY + &DUMMY_bootstrap, +#endif +#if SDL_VIDEO_DRIVER_PANDORA + &PND_bootstrap, +#endif + NULL +}; + +static SDL_VideoDevice *_this = NULL; + +#define CHECK_WINDOW_MAGIC(window, retval) \ + if (!_this) { \ + SDL_UninitializedVideo(); \ + return retval; \ + } \ + if (!window || window->magic != &_this->window_magic) { \ + SDL_SetError("Invalid window"); \ + return retval; \ + } + +#define CHECK_TEXTURE_MAGIC(texture, retval) \ + if (!_this) { \ + SDL_UninitializedVideo(); \ + return retval; \ + } \ + if (!texture || texture->magic != &_this->texture_magic) { \ + SDL_SetError("Invalid texture"); \ + return retval; \ + } + +/* Various local functions */ +static void SDL_UpdateWindowGrab(SDL_Window * window); + +static int +cmpmodes(const void *A, const void *B) +{ + SDL_DisplayMode a = *(const SDL_DisplayMode *) A; + SDL_DisplayMode b = *(const SDL_DisplayMode *) B; + + if (a.w != b.w) { + return b.w - a.w; + } + if (a.h != b.h) { + return b.h - a.h; + } + if (SDL_BITSPERPIXEL(a.format) != SDL_BITSPERPIXEL(b.format)) { + return SDL_BITSPERPIXEL(b.format) - SDL_BITSPERPIXEL(a.format); + } + if (SDL_PIXELLAYOUT(a.format) != SDL_PIXELLAYOUT(b.format)) { + return SDL_PIXELLAYOUT(b.format) - SDL_PIXELLAYOUT(a.format); + } + if (a.refresh_rate != b.refresh_rate) { + return b.refresh_rate - a.refresh_rate; + } + return 0; +} + +static void +SDL_UninitializedVideo() +{ + SDL_SetError("Video subsystem has not been initialized"); +} + +int +SDL_GetNumVideoDrivers(void) +{ + return SDL_arraysize(bootstrap) - 1; +} + +const char * +SDL_GetVideoDriver(int index) +{ + if (index >= 0 && index < SDL_GetNumVideoDrivers()) { + return bootstrap[index]->name; + } + return NULL; +} + +/* + * Initialize the video and event subsystems -- determine native pixel format + */ +#if SDL_VERSION_ATLEAST(1,3,0) +int SDL_VideoInit +#else +int SDL_VideoInit_1_3 +#endif +(const char *driver_name, Uint32 flags) +{ + SDL_VideoDevice *video; + int index; + int i; + + /* Check to make sure we don't overwrite '_this' */ + if (_this != NULL) { + SDL_VideoQuit(); + } + +#if SDL_VERSION_ATLEAST(1,3,0) + /* Toggle the event thread flags, based on OS requirements */ +#if defined(MUST_THREAD_EVENTS) + flags |= SDL_INIT_EVENTTHREAD; +#elif defined(CANT_THREAD_EVENTS) + if ((flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD) { + SDL_SetError("OS doesn't support threaded events"); + return -1; + } +#endif + + /* Start the event loop */ + if (SDL_StartEventLoop(flags) < 0) { + return -1; + } +#endif + /* Select the proper video driver */ + index = 0; + video = NULL; +#if SDL_VERSION_ATLEAST(1,3,0) + if (driver_name == NULL) { + driver_name = SDL_getenv("SDL_VIDEODRIVER"); + } + if (driver_name != NULL) { + for (i = 0; bootstrap[i]; ++i) { + if (SDL_strcasecmp(bootstrap[i]->name, driver_name) == 0) { + video = bootstrap[i]->create(index); + break; + } + } + } else { + for (i = 0; bootstrap[i]; ++i) { + if (bootstrap[i]->available()) { + video = bootstrap[i]->create(index); + if (video != NULL) { + break; + } + } + } + } + if (video == NULL) { + if (driver_name) { + SDL_SetError("%s not available", driver_name); + } else { + SDL_SetError("No available video device"); + } + return -1; + } + + _this = video; + _this->name = bootstrap[i]->name; +#else + video = ANDROID_CreateDevice_1_3(0); + _this = video; + _this->name = "android"; +#endif + _this->next_object_id = 1; + + + /* Set some very sane GL defaults */ + _this->gl_config.driver_loaded = 0; + _this->gl_config.dll_handle = NULL; + _this->gl_config.red_size = 3; + _this->gl_config.green_size = 3; + _this->gl_config.blue_size = 2; + _this->gl_config.alpha_size = 0; + _this->gl_config.buffer_size = 0; + _this->gl_config.depth_size = 16; + _this->gl_config.stencil_size = 0; + _this->gl_config.double_buffer = 1; + _this->gl_config.accum_red_size = 0; + _this->gl_config.accum_green_size = 0; + _this->gl_config.accum_blue_size = 0; + _this->gl_config.accum_alpha_size = 0; + _this->gl_config.stereo = 0; + _this->gl_config.multisamplebuffers = 0; + _this->gl_config.multisamplesamples = 0; + _this->gl_config.retained_backing = 1; + _this->gl_config.accelerated = -1; /* accelerated or not, both are fine */ + _this->gl_config.major_version = 2; + _this->gl_config.minor_version = 1; + + /* Initialize the video subsystem */ + if (_this->VideoInit(_this) < 0) { + SDL_VideoQuit(); + return -1; + } + /* Make sure some displays were added */ + if (_this->num_displays == 0) { + SDL_SetError("The video driver did not add any displays"); + SDL_VideoQuit(); + return (-1); + } + /* The software renderer is always available */ + for (i = 0; i < _this->num_displays; ++i) { + SDL_VideoDisplay *display = &_this->displays[i]; + if (_this->GL_CreateContext) { +#if SDL_VIDEO_RENDER_OGL + SDL_AddRenderDriver(display, &GL_RenderDriver); +#endif +#if SDL_VIDEO_RENDER_OGL_ES + SDL_AddRenderDriver(display, &GL_ES_RenderDriver); +#endif + } +#if SDL_VERSION_ATLEAST(1,3,0) + if (display->num_render_drivers > 0) { + SDL_AddRenderDriver(display, &SW_RenderDriver); + } +#endif + } + + /* We're ready to go! */ + return 0; +} + +const char * +SDL_GetCurrentVideoDriver() +{ + if (!_this) { + SDL_UninitializedVideo(); + return NULL; + } + return _this->name; +} + +SDL_VideoDevice * +SDL_GetVideoDevice(void) +{ + return _this; +} + +int +SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode) +{ + SDL_VideoDisplay display; + + SDL_zero(display); + if (desktop_mode) { + display.desktop_mode = *desktop_mode; + } + display.current_mode = display.desktop_mode; + + return SDL_AddVideoDisplay(&display); +} + +int +SDL_AddVideoDisplay(const SDL_VideoDisplay * display) +{ + SDL_VideoDisplay *displays; + int index = -1; + + displays = + SDL_realloc(_this->displays, + (_this->num_displays + 1) * sizeof(*displays)); + if (displays) { + index = _this->num_displays++; + displays[index] = *display; + displays[index].device = _this; + _this->displays = displays; + } else { + SDL_OutOfMemory(); + } + return index; +} + +int +SDL_GetNumVideoDisplays(void) +{ + if (!_this) { + SDL_UninitializedVideo(); + return 0; + } + return _this->num_displays; +} + +int +SDL_GetDisplayBounds(int index, SDL_Rect * rect) +{ + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + if (index < 0 || index >= _this->num_displays) { + SDL_SetError("index must be in the range 0 - %d", + _this->num_displays - 1); + return -1; + } + if (rect) { + SDL_VideoDisplay *display = &_this->displays[index]; + + if (_this->GetDisplayBounds) { + if (_this->GetDisplayBounds(_this, display, rect) < 0) { + return -1; + } + } else { + /* Assume that the displays are left to right */ + if (index == 0) { + rect->x = 0; + rect->y = 0; + } else { + SDL_GetDisplayBounds(index-1, rect); + rect->x += rect->w; + } + rect->w = display->desktop_mode.w; + rect->h = display->desktop_mode.h; + } + } + return 0; +} + +int +SDL_SelectVideoDisplay(int index) +{ + if (!_this) { + SDL_UninitializedVideo(); + return (-1); + } + if (index < 0 || index >= _this->num_displays) { + SDL_SetError("index must be in the range 0 - %d", + _this->num_displays - 1); + return -1; + } + _this->current_display = index; + return 0; +} + +int +SDL_GetCurrentVideoDisplay(void) +{ + if (!_this) { + SDL_UninitializedVideo(); + return (-1); + } + return _this->current_display; +} + +SDL_bool +SDL_AddDisplayMode(SDL_VideoDisplay * display, const SDL_DisplayMode * mode) +{ + SDL_DisplayMode *modes; + int i, nmodes; + + /* Make sure we don't already have the mode in the list */ + modes = display->display_modes; + nmodes = display->num_display_modes; + for (i = nmodes; i--;) { + if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) { + return SDL_FALSE; + } + } + + /* Go ahead and add the new mode */ + if (nmodes == display->max_display_modes) { + modes = + SDL_realloc(modes, + (display->max_display_modes + 32) * sizeof(*modes)); + if (!modes) { + return SDL_FALSE; + } + display->display_modes = modes; + display->max_display_modes += 32; + } + modes[nmodes] = *mode; + display->num_display_modes++; + + /* Re-sort video modes */ + SDL_qsort(display->display_modes, display->num_display_modes, + sizeof(SDL_DisplayMode), cmpmodes); + + return SDL_TRUE; +} + +int +SDL_GetNumDisplayModesForDisplay(SDL_VideoDisplay * display) +{ + if (!display->num_display_modes && _this->GetDisplayModes) { + _this->GetDisplayModes(_this, display); + SDL_qsort(display->display_modes, display->num_display_modes, + sizeof(SDL_DisplayMode), cmpmodes); + } + return display->num_display_modes; +} + +int +SDL_GetNumDisplayModes() +{ + if (_this) { + return SDL_GetNumDisplayModesForDisplay(SDL_CurrentDisplay); + } + return 0; +} + +int +SDL_GetDisplayModeForDisplay(SDL_VideoDisplay * display, int index, SDL_DisplayMode * mode) +{ + if (index < 0 || index >= SDL_GetNumDisplayModesForDisplay(display)) { + SDL_SetError("index must be in the range of 0 - %d", + SDL_GetNumDisplayModesForDisplay(display) - 1); + return -1; + } + if (mode) { + *mode = display->display_modes[index]; + } + return 0; +} + +int +SDL_GetDisplayMode(int index, SDL_DisplayMode * mode) +{ + return SDL_GetDisplayModeForDisplay(SDL_CurrentDisplay, index, mode); +} + +int +SDL_GetDesktopDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode) +{ + if (mode) { + *mode = display->desktop_mode; + } + return 0; +} + +int +SDL_GetDesktopDisplayMode(SDL_DisplayMode * mode) +{ + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + return SDL_GetDesktopDisplayModeForDisplay(SDL_CurrentDisplay, mode); +} + +int +SDL_GetCurrentDisplayModeForDisplay(SDL_VideoDisplay * display, SDL_DisplayMode * mode) +{ + if (mode) { + *mode = display->current_mode; + } + return 0; +} + +int +SDL_GetCurrentDisplayMode(SDL_DisplayMode * mode) +{ + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + return SDL_GetCurrentDisplayModeForDisplay(SDL_CurrentDisplay, mode); +} + +SDL_DisplayMode * +SDL_GetClosestDisplayModeForDisplay(SDL_VideoDisplay * display, + const SDL_DisplayMode * mode, + SDL_DisplayMode * closest) +{ + Uint32 target_format; + int target_refresh_rate; + int i; + SDL_DisplayMode *current, *match; + + if (!mode || !closest) { + SDL_SetError("Missing desired mode or closest mode parameter"); + return NULL; + } + + /* Default to the desktop format */ + if (mode->format) { + target_format = mode->format; + } else { + target_format = display->desktop_mode.format; + } + + /* Default to the desktop refresh rate */ + if (mode->refresh_rate) { + target_refresh_rate = mode->refresh_rate; + } else { + target_refresh_rate = display->desktop_mode.refresh_rate; + } + + match = NULL; + for (i = 0; i < SDL_GetNumDisplayModesForDisplay(display); ++i) { + current = &display->display_modes[i]; + + if (current->w && (current->w < mode->w)) { + /* Out of sorted modes large enough here */ + break; + } + if (current->h && (current->h < mode->h)) { + if (current->w && (current->w == mode->w)) { + /* Out of sorted modes large enough here */ + break; + } + /* Wider, but not tall enough, due to a different + aspect ratio. This mode must be skipped, but closer + modes may still follow. */ + continue; + } + if (!match || current->w < match->w || current->h < match->h) { + match = current; + continue; + } + if (current->format != match->format) { + /* Sorted highest depth to lowest */ + if (current->format == target_format || + (SDL_BITSPERPIXEL(current->format) >= + SDL_BITSPERPIXEL(target_format) + && SDL_PIXELTYPE(current->format) == + SDL_PIXELTYPE(target_format))) { + match = current; + } + continue; + } + if (current->refresh_rate != match->refresh_rate) { + /* Sorted highest refresh to lowest */ + if (current->refresh_rate >= target_refresh_rate) { + match = current; + } + } + } + if (match) { + if (match->format) { + closest->format = match->format; + } else { + closest->format = mode->format; + } + if (match->w && match->h) { + closest->w = match->w; + closest->h = match->h; + } else { + closest->w = mode->w; + closest->h = mode->h; + } + if (match->refresh_rate) { + closest->refresh_rate = match->refresh_rate; + } else { + closest->refresh_rate = mode->refresh_rate; + } + closest->driverdata = match->driverdata; + + /* + * Pick some reasonable defaults if the app and driver don't + * care + */ + if (!closest->format) { + closest->format = SDL_PIXELFORMAT_RGB888; + } + if (!closest->w) { + closest->w = 640; + } + if (!closest->h) { + closest->h = 480; + } + return closest; + } + return NULL; +} + +SDL_DisplayMode * +SDL_GetClosestDisplayMode(const SDL_DisplayMode * mode, + SDL_DisplayMode * closest) +{ + if (!_this) { + SDL_UninitializedVideo(); + return NULL; + } + return SDL_GetClosestDisplayModeForDisplay(SDL_CurrentDisplay, mode, closest); +} + +int +SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * mode) +{ + SDL_DisplayMode display_mode; + SDL_DisplayMode current_mode; + int ncolors; + + if (mode) { + display_mode = *mode; + + /* Default to the current mode */ + if (!display_mode.format) { + display_mode.format = display->current_mode.format; + } + if (!display_mode.w) { + display_mode.w = display->current_mode.w; + } + if (!display_mode.h) { + display_mode.h = display->current_mode.h; + } + if (!display_mode.refresh_rate) { + display_mode.refresh_rate = display->current_mode.refresh_rate; + } + + /* Get a good video mode, the closest one possible */ + if (!SDL_GetClosestDisplayModeForDisplay(display, &display_mode, &display_mode)) { + SDL_SetError("No video mode large enough for %dx%d", + display_mode.w, display_mode.h); + return -1; + } + } else { + display_mode = display->desktop_mode; + } + + /* See if there's anything left to do */ + SDL_GetCurrentDisplayModeForDisplay(display, ¤t_mode); + if (SDL_memcmp(&display_mode, ¤t_mode, sizeof(display_mode)) == 0) { + return 0; + } + + /* Actually change the display mode */ + if (_this->SetDisplayMode(_this, display, &display_mode) < 0) { + return -1; + } + display->current_mode = display_mode; + +#if SDL_VERSION_ATLEAST(1,3,0) + /* Set up a palette, if necessary */ + if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) { + ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format)); + } else { + ncolors = 0; + } + if ((!ncolors && display->palette) || (ncolors && !display->palette) + || (ncolors && ncolors != display->palette->ncolors)) { + if (display->palette) { + SDL_FreePalette(display->palette); + display->palette = NULL; + } + if (ncolors) { + display->palette = SDL_AllocPalette(ncolors); + if (!display->palette) { + return -1; + } + SDL_DitherColors(display->palette->colors, + SDL_BITSPERPIXEL(display_mode.format)); + } + } +#endif + + return 0; +} + +int +SDL_SetWindowDisplayMode(SDL_Window * window, const SDL_DisplayMode * mode) +{ + CHECK_WINDOW_MAGIC(window, -1); + + if (mode) { + window->fullscreen_mode = *mode; + } else { + SDL_zero(window->fullscreen_mode); + } + return 0; +} + +int +SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) +{ + SDL_DisplayMode fullscreen_mode; + + CHECK_WINDOW_MAGIC(window, -1); + + fullscreen_mode = window->fullscreen_mode; + if (!fullscreen_mode.w) { + fullscreen_mode.w = window->w; + } + if (!fullscreen_mode.h) { + fullscreen_mode.h = window->h; + } + + if (!SDL_GetClosestDisplayModeForDisplay(window->display, + &fullscreen_mode, + &fullscreen_mode)) { + SDL_SetError("Couldn't find display mode match"); + return -1; + } + + if (mode) { + *mode = fullscreen_mode; + } + return 0; +} + +#if SDL_VERSION_ATLEAST(1,3,0) + +static void +SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt) +{ + SDL_VideoDisplay *display = window->display; + + /* See if we're already processing a window */ + if (display->updating_fullscreen) { + return; + } + + display->updating_fullscreen = SDL_TRUE; + + /* See if we even want to do anything here */ + if ((window->flags & SDL_WINDOW_FULLSCREEN) && + (window->flags & SDL_WINDOW_SHOWN)) { + if (attempt) { + /* We just gained some state, try to gain all states */ + if (window->flags & SDL_WINDOW_MINIMIZED) { + SDL_RestoreWindow(window); + } else { + SDL_RaiseWindow(window); + } + } else { + /* We just lost some state, try to release all states */ + SDL_MinimizeWindow(window); + } + } + + if (FULLSCREEN_VISIBLE(window)) { + /* Hide any other fullscreen windows */ + SDL_Window *other; + for (other = display->windows; other; other = other->next) { + if (other != window && FULLSCREEN_VISIBLE(other)) { + SDL_MinimizeWindow(other); + } + } + } + + display->updating_fullscreen = SDL_FALSE; + + /* See if there are any fullscreen windows */ + for (window = display->windows; window; window = window->next) { + if (FULLSCREEN_VISIBLE(window)) { + SDL_DisplayMode fullscreen_mode; + if (SDL_GetWindowDisplayMode(window, &fullscreen_mode) == 0) { + SDL_SetDisplayModeForDisplay(display, &fullscreen_mode); + display->fullscreen_window = window; + return; + } + } + } + + /* Nope, restore the desktop mode */ + SDL_SetDisplayModeForDisplay(display, NULL); + display->fullscreen_window = NULL; +} + +int +SDL_SetPaletteForDisplay(SDL_VideoDisplay * display, const SDL_Color * colors, int firstcolor, int ncolors) +{ + SDL_Palette *palette; + int status = 0; + + palette = display->palette; + if (!palette) { + SDL_SetError("Display mode does not have a palette"); + return -1; + } + status = SDL_SetPaletteColors(palette, colors, firstcolor, ncolors); + + if (_this->SetDisplayPalette) { + if (_this->SetDisplayPalette(_this, display, palette) < 0) { + status = -1; + } + } + return status; +} + +int +SDL_SetDisplayPalette(const SDL_Color * colors, int firstcolor, int ncolors) +{ + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + return SDL_SetPaletteForDisplay(SDL_CurrentDisplay, colors, firstcolor, ncolors); +} + +int +SDL_GetPaletteForDisplay(SDL_VideoDisplay * display, SDL_Color * colors, int firstcolor, int ncolors) +{ + SDL_Palette *palette; + + palette = display->palette; + if (!palette || !palette->ncolors) { + SDL_SetError("Display mode does not have a palette"); + return -1; + } + if (firstcolor < 0 || (firstcolor + ncolors) > palette->ncolors) { + SDL_SetError("Palette indices are out of range"); + return -1; + } + SDL_memcpy(colors, &palette->colors[firstcolor], + ncolors * sizeof(*colors)); + return 0; +} + +int +SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors) +{ + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + return SDL_GetPaletteForDisplay(SDL_CurrentDisplay, colors, firstcolor, ncolors); +} + +#endif + +SDL_Window * +SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) +{ + const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | + SDL_WINDOW_OPENGL | + SDL_WINDOW_BORDERLESS | + SDL_WINDOW_RESIZABLE | + SDL_WINDOW_INPUT_GRABBED); + SDL_VideoDisplay *display; + SDL_Window *window; + +#if SDL_VERSION_ATLEAST(1,3,0) + if (!_this) { + /* Initialize the video system if needed */ + if (SDL_VideoInit(NULL, 0) < 0) { + return NULL; + } + } + if (flags & SDL_WINDOW_OPENGL) { + if (!_this->GL_CreateContext) { + SDL_SetError("No OpenGL support in video driver"); + return NULL; + } + SDL_GL_LoadLibrary(NULL); + } +#endif + + display = SDL_CurrentDisplay; + window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); + window->magic = &_this->window_magic; + window->id = _this->next_object_id++; + window->x = x; + window->y = y; + window->w = w; + window->h = h; + window->flags = (flags & allowed_flags); + window->display = display; + window->next = display->windows; + if (display->windows) { + display->windows->prev = window; + } + display->windows = window; + +#if SDL_VERSION_ATLEAST(1,3,0) + if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) { + SDL_DestroyWindow(window); + return NULL; + } + + if (title) { + SDL_SetWindowTitle(window, title); + } + if (flags & SDL_WINDOW_MAXIMIZED) { + SDL_MaximizeWindow(window); + } + if (flags & SDL_WINDOW_MINIMIZED) { + SDL_MinimizeWindow(window); + } + if (flags & SDL_WINDOW_SHOWN) { + SDL_ShowWindow(window); + } + SDL_UpdateWindowGrab(window); +#endif + + return window; +} + +#if SDL_VERSION_ATLEAST(1,3,0) + +SDL_Window * +SDL_CreateWindowFrom(const void *data) +{ + SDL_VideoDisplay *display; + SDL_Window *window; + + if (!_this) { + SDL_UninitializedVideo(); + return NULL; + } + display = SDL_CurrentDisplay; + window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); + window->magic = &_this->window_magic; + window->id = _this->next_object_id++; + window->flags = SDL_WINDOW_FOREIGN; + window->display = display; + window->next = display->windows; + if (display->windows) { + display->windows->prev = window; + } + display->windows = window; + + if (!_this->CreateWindowFrom || + _this->CreateWindowFrom(_this, window, data) < 0) { + SDL_DestroyWindow(window); + return NULL; + } + return window; +} + +int +SDL_RecreateWindow(SDL_Window * window, Uint32 flags) +{ + const Uint32 allowed_flags = (SDL_WINDOW_FULLSCREEN | + SDL_WINDOW_OPENGL | + SDL_WINDOW_BORDERLESS | + SDL_WINDOW_RESIZABLE | + SDL_WINDOW_INPUT_GRABBED | + SDL_WINDOW_FOREIGN); + char *title = window->title; + + if ((flags & SDL_WINDOW_OPENGL) && !_this->GL_CreateContext) { + SDL_SetError("No OpenGL support in video driver"); + return -1; + } + if ((window->flags & SDL_WINDOW_OPENGL) != (flags & SDL_WINDOW_OPENGL)) { + if (flags & SDL_WINDOW_OPENGL) { + SDL_GL_LoadLibrary(NULL); + } else { + SDL_GL_UnloadLibrary(); + } + } + + if (window->flags & SDL_WINDOW_FOREIGN) { + /* Can't destroy and re-create foreign windows, hrm */ + flags |= SDL_WINDOW_FOREIGN; + } else { + flags &= ~SDL_WINDOW_FOREIGN; + } + + if (_this->DestroyWindow && !(flags & SDL_WINDOW_FOREIGN)) { + _this->DestroyWindow(_this, window); + } + + window->title = NULL; + window->flags = (flags & allowed_flags); + + if (_this->CreateWindow && !(flags & SDL_WINDOW_FOREIGN)) { + if (_this->CreateWindow(_this, window) < 0) { + if (flags & SDL_WINDOW_OPENGL) { + SDL_GL_UnloadLibrary(); + } + return -1; + } + } + + if (title) { + SDL_SetWindowTitle(window, title); + SDL_free(title); + } + if (flags & SDL_WINDOW_MAXIMIZED) { + SDL_MaximizeWindow(window); + } + if (flags & SDL_WINDOW_MINIMIZED) { + SDL_MinimizeWindow(window); + } + if (flags & SDL_WINDOW_SHOWN) { + SDL_ShowWindow(window); + } + SDL_UpdateWindowGrab(window); + + return 0; +} +#endif + +static __inline__ SDL_Renderer * +SDL_GetCurrentRenderer(SDL_bool create) +{ + if (!_this) { + SDL_UninitializedVideo(); + return NULL; + } + if (!SDL_CurrentRenderer) { + if (!create) { + SDL_SetError("Use SDL_CreateRenderer() to create a renderer"); + return NULL; + } + if (SDL_CreateRenderer(0, -1, 0) < 0) { + return NULL; + } + } + return SDL_CurrentRenderer; +} + +#if SDL_VERSION_ATLEAST(1,3,0) +Uint32 +SDL_GetWindowID(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, 0); + + return window->id; +} + +SDL_Window * +SDL_GetWindowFromID(Uint32 id) +{ + SDL_Window *window; + int i; + + if (!_this) { + return NULL; + } + /* FIXME: Should we keep a separate hash table for these? */ + for (i = _this->num_displays; i--;) { + SDL_VideoDisplay *display = &_this->displays[i]; + for (window = display->windows; window; window = window->next) { + if (window->id == id) { + return window; + } + } + } + return NULL; +} + +Uint32 +SDL_GetWindowFlags(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, 0); + + return window->flags; +} + +void +SDL_SetWindowTitle(SDL_Window * window, const char *title) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (title == window->title) { + return; + } + if (window->title) { + SDL_free(window->title); + } + if (title) { + window->title = SDL_strdup(title); + } else { + window->title = NULL; + } + + if (_this->SetWindowTitle) { + _this->SetWindowTitle(_this, window); + } +} + +const char * +SDL_GetWindowTitle(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, NULL); + + return window->title; +} + +void +SDL_SetWindowIcon(SDL_Window * window, SDL_Surface * icon) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (_this->SetWindowIcon) { + _this->SetWindowIcon(_this, window, icon); + } +} + +void +SDL_SetWindowData(SDL_Window * window, void *userdata) +{ + CHECK_WINDOW_MAGIC(window, ); + + window->userdata = userdata; +} + +void * +SDL_GetWindowData(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, NULL); + + return window->userdata; +} + +void +SDL_SetWindowPosition(SDL_Window * window, int x, int y) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (x != SDL_WINDOWPOS_UNDEFINED) { + window->x = x; + } + if (y != SDL_WINDOWPOS_UNDEFINED) { + window->y = y; + } + if (_this->SetWindowPosition) { + _this->SetWindowPosition(_this, window); + } + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MOVED, x, y); +} + +void +SDL_GetWindowPosition(SDL_Window * window, int *x, int *y) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (x) { + *x = window->x; + } + if (y) { + *y = window->y; + } +} + +void +SDL_SetWindowSize(SDL_Window * window, int w, int h) +{ + CHECK_WINDOW_MAGIC(window, ); + + window->w = w; + window->h = h; + + if (_this->SetWindowSize) { + _this->SetWindowSize(_this, window); + } + SDL_OnWindowResized(window); +} + +void +SDL_GetWindowSize(SDL_Window * window, int *w, int *h) +{ + if (window) { + if (w) { + *w = window->w; + } + if (h) { + *h = window->h; + } + } else { + if (w) { + *w = 0; + } + if (h) { + *h = 0; + } + } +} + +void +SDL_ShowWindow(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (window->flags & SDL_WINDOW_SHOWN) { + return; + } + + if (_this->ShowWindow) { + _this->ShowWindow(_this, window); + } + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SHOWN, 0, 0); +} + +void +SDL_HideWindow(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (!(window->flags & SDL_WINDOW_SHOWN)) { + return; + } + + if (_this->HideWindow) { + _this->HideWindow(_this, window); + } + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_HIDDEN, 0, 0); +} + +void +SDL_RaiseWindow(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (!(window->flags & SDL_WINDOW_SHOWN)) { + return; + } + if (_this->RaiseWindow) { + _this->RaiseWindow(_this, window); + } else { + /* FIXME: What we really want is a way to request focus */ + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0); + } +} + +void +SDL_MaximizeWindow(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (window->flags & SDL_WINDOW_MAXIMIZED) { + return; + } + + if (_this->MaximizeWindow) { + _this->MaximizeWindow(_this, window); + } + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MAXIMIZED, 0, 0); +} + +void +SDL_MinimizeWindow(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (window->flags & SDL_WINDOW_MINIMIZED) { + return; + } + + if (_this->MinimizeWindow) { + _this->MinimizeWindow(_this, window); + } + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_MINIMIZED, 0, 0); +} + +void +SDL_RestoreWindow(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (!(window->flags & (SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED))) { + return; + } + + if (_this->RestoreWindow) { + _this->RestoreWindow(_this, window); + } + SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0); +} + +int +SDL_SetWindowFullscreen(SDL_Window * window, int fullscreen) +{ + CHECK_WINDOW_MAGIC(window, -1); + + if (fullscreen) { + fullscreen = SDL_WINDOW_FULLSCREEN; + } + if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) { + return 0; + } + if (fullscreen) { + window->flags |= SDL_WINDOW_FULLSCREEN; + + SDL_UpdateFullscreenMode(window, SDL_TRUE); + } else { + window->flags &= ~SDL_WINDOW_FULLSCREEN; + + SDL_UpdateFullscreenMode(window, SDL_FALSE); + } + return 0; +} + +void +SDL_SetWindowGrab(SDL_Window * window, int mode) +{ + CHECK_WINDOW_MAGIC(window, ); + + if ((!!mode == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) { + return; + } + if (mode) { + window->flags |= SDL_WINDOW_INPUT_GRABBED; + } else { + window->flags &= ~SDL_WINDOW_INPUT_GRABBED; + } + SDL_UpdateWindowGrab(window); +} + +static void +SDL_UpdateWindowGrab(SDL_Window * window) +{ + if ((window->flags & SDL_WINDOW_INPUT_FOCUS) && _this->SetWindowGrab) { + _this->SetWindowGrab(_this, window); + } +} + +int +SDL_GetWindowGrab(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, 0); + + return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0); +} + +void +SDL_OnWindowShown(SDL_Window * window) +{ + SDL_RaiseWindow(window); + SDL_UpdateFullscreenMode(window, SDL_TRUE); +} + +void +SDL_OnWindowHidden(SDL_Window * window) +{ + SDL_UpdateFullscreenMode(window, SDL_FALSE); +} + +void +SDL_OnWindowResized(SDL_Window * window) +{ + SDL_Renderer *renderer = window->renderer; + + if (renderer && renderer->DisplayModeChanged) { + renderer->DisplayModeChanged(renderer); + } +} + +void +SDL_OnWindowMinimized(SDL_Window * window) +{ + SDL_UpdateFullscreenMode(window, SDL_FALSE); +} + +void +SDL_OnWindowRestored(SDL_Window * window) +{ + SDL_RaiseWindow(window); + SDL_UpdateFullscreenMode(window, SDL_TRUE); +} + +void +SDL_OnWindowFocusGained(SDL_Window * window) +{ + SDL_VideoDisplay *display = window->display; + + if (display->gamma && _this->SetDisplayGammaRamp) { + _this->SetDisplayGammaRamp(_this, display, display->gamma); + } + if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN)) + && _this->SetWindowGrab) { + _this->SetWindowGrab(_this, window); + } +} + +void +SDL_OnWindowFocusLost(SDL_Window * window) +{ + SDL_VideoDisplay *display = window->display; + + /* If we're fullscreen on a single-head system and lose focus, minimize */ + if ((window->flags & SDL_WINDOW_FULLSCREEN) && + _this->num_displays == 1) { + SDL_MinimizeWindow(window); + } + + if (display->gamma && _this->SetDisplayGammaRamp) { + _this->SetDisplayGammaRamp(_this, display, display->saved_gamma); + } + if ((window->flags & (SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_FULLSCREEN)) + && _this->SetWindowGrab) { + _this->SetWindowGrab(_this, window); + } +} + +SDL_Window * +SDL_GetFocusWindow(void) +{ + SDL_VideoDisplay *display; + SDL_Window *window; + + if (!_this) { + return NULL; + } + display = SDL_CurrentDisplay; + for (window = display->windows; window; window = window->next) { + if (window->flags & SDL_WINDOW_INPUT_FOCUS) { + return window; + } + } + return NULL; +} + +#endif + +void +SDL_DestroyWindow(SDL_Window * window) +{ + SDL_VideoDisplay *display; + + CHECK_WINDOW_MAGIC(window, ); + window->magic = NULL; + + if (window->title) { + SDL_free(window->title); + } + if (window->renderer) { + SDL_DestroyRenderer(window); + } + +#if SDL_VERSION_ATLEAST(1,3,0) + /* Restore video mode, etc. */ + SDL_UpdateFullscreenMode(window, SDL_FALSE); +#endif + + if (_this->DestroyWindow) { + _this->DestroyWindow(_this, window); + } +#if SDL_VERSION_ATLEAST(1,3,0) + if (window->flags & SDL_WINDOW_OPENGL) { + SDL_GL_UnloadLibrary(); + } +#endif + + /* Unlink the window from the list */ + display = window->display; + if (window->next) { + window->next->prev = window->prev; + } + if (window->prev) { + window->prev->next = window->next; + } else { + display->windows = window->next; + } + + SDL_free(window); +} + +void +SDL_AddRenderDriver(SDL_VideoDisplay * display, const SDL_RenderDriver * driver) +{ + SDL_RenderDriver *render_drivers; + + render_drivers = + SDL_realloc(display->render_drivers, + (display->num_render_drivers + + 1) * sizeof(*render_drivers)); + if (render_drivers) { + render_drivers[display->num_render_drivers] = *driver; + display->render_drivers = render_drivers; + display->num_render_drivers++; + } +} + +int +SDL_GetNumRenderDrivers(void) +{ + if (_this) { + return SDL_CurrentDisplay->num_render_drivers; + } + return 0; +} + +int +SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info) +{ + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + if (index < 0 || index >= SDL_GetNumRenderDrivers()) { + SDL_SetError("index must be in the range of 0 - %d", + SDL_GetNumRenderDrivers() - 1); + return -1; + } + *info = SDL_CurrentDisplay->render_drivers[index].info; + return 0; +} + +int +SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) +{ + CHECK_WINDOW_MAGIC(window, -1); + + /* Free any existing renderer */ + SDL_DestroyRenderer(window); + +#if SDL_VERSION_ATLEAST(1,3,0) + if (index < 0) { + char *override = SDL_getenv("SDL_VIDEO_RENDERER"); + int n = SDL_GetNumRenderDrivers(); + +#if SDL_VIDEO_RENDER_OGL + if (!override && (window->flags & SDL_WINDOW_OPENGL)) { + override = "opengl"; + } +#endif /* SDL_VIDEO_RENDER_OGL */ +#if SDL_VIDEO_RENDER_OGL_ES + if (!override && (window->flags & SDL_WINDOW_OPENGL)) { + override = "opengl_es"; + } +#endif /* SDL_VIDEO_RENDER_OGL_ES */ + if (override) { + for (index = 0; index < n; ++index) { + SDL_RenderDriver *driver = + &SDL_CurrentDisplay->render_drivers[index]; + + if (SDL_strcasecmp(override, driver->info.name) == 0) { + /* Create a new renderer instance */ + window->renderer = driver->CreateRenderer(window, flags); + break; + } + } + } else { + for (index = 0; index < n; ++index) { + SDL_RenderDriver *driver = + &SDL_CurrentDisplay->render_drivers[index]; + + if ((driver->info.flags & flags) == flags) { + /* Create a new renderer instance */ + window->renderer = driver->CreateRenderer(window, flags); + if (window->renderer) { + /* Yay, we got one! */ + break; + } + } + } + } + if (index == n) { + SDL_SetError("Couldn't find matching render driver"); + return -1; + } + } else { + if (index >= SDL_GetNumRenderDrivers()) { + SDL_SetError("index must be -1 or in the range of 0 - %d", + SDL_GetNumRenderDrivers() - 1); + return -1; + } + /* Create a new renderer instance */ + window->renderer = SDL_CurrentDisplay->render_drivers[index].CreateRenderer(window, flags); + } +#else + window->renderer = GL_ES_RenderDriver.CreateRenderer(window, flags); +#endif + + if (window->renderer == NULL) { + /* Assuming renderer set its error */ + return -1; + } + + SDL_SelectRenderer(window); + + return 0; +} + +int +SDL_SelectRenderer(SDL_Window * window) +{ + SDL_Renderer *renderer; + + CHECK_WINDOW_MAGIC(window, -1); + + renderer = window->renderer; + if (!renderer) { + SDL_SetError("Use SDL_CreateRenderer() to create a renderer"); + return -1; + } + if (renderer->ActivateRenderer) { + if (renderer->ActivateRenderer(renderer) < 0) { + return -1; + } + } + SDL_CurrentDisplay->current_renderer = renderer; + return 0; +} + +int +SDL_GetRendererInfo(SDL_RendererInfo * info) +{ + SDL_Renderer *renderer = SDL_GetCurrentRenderer(SDL_FALSE); + if (!renderer) { + return -1; + } + *info = renderer->info; + return 0; +} + +SDL_Texture * +SDL_CreateTexture(Uint32 format, int access, int w, int h) +{ + SDL_Renderer *renderer; + SDL_Texture *texture; + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return 0; + } + if (!renderer->CreateTexture) { + SDL_Unsupported(); + return 0; + } + if (w <= 0 || h <= 0) { + SDL_SetError("Texture dimensions can't be 0"); + return 0; + } + texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture)); + if (!texture) { + SDL_OutOfMemory(); + return 0; + } + texture->magic = &_this->texture_magic; + texture->format = format; + texture->access = access; + texture->w = w; + texture->h = h; + texture->r = 255; + texture->g = 255; + texture->b = 255; + texture->a = 255; + texture->renderer = renderer; + texture->next = renderer->textures; + if (renderer->textures) { + renderer->textures->prev = texture; + } + renderer->textures = texture; + + if (renderer->CreateTexture(renderer, texture) < 0) { + SDL_DestroyTexture(texture); + return 0; + } + return texture; +} + +SDL_Texture * +SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) +{ + SDL_Texture *texture; + Uint32 requested_format = format; + SDL_PixelFormat *fmt; + SDL_Renderer *renderer; + int bpp; + Uint32 Rmask, Gmask, Bmask, Amask; + + if (!surface) { + SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface"); + return 0; + } + fmt = surface->format; + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return 0; + } + + if (format) { + if (!SDL_PixelFormatEnumToMasks + (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { + SDL_SetError("Unknown pixel format"); + return 0; + } + } else { + if (surface->format->Amask +#if SDL_VERSION_ATLEAST(1,3,0) + || !(surface->map->info.flags & + (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) { +#else + || !(surface->flags & + (SDL_SRCCOLORKEY | SDL_SRCALPHA))) { +#endif + Uint32 it; + int pfmt; + + /* Pixel formats, sorted by best first */ + static const Uint32 sdl_pformats[] = { + SDL_PIXELFORMAT_ARGB8888, + SDL_PIXELFORMAT_RGBA8888, + SDL_PIXELFORMAT_ABGR8888, + SDL_PIXELFORMAT_BGRA8888, + SDL_PIXELFORMAT_RGB888, + SDL_PIXELFORMAT_BGR888, + SDL_PIXELFORMAT_RGB24, + SDL_PIXELFORMAT_BGR24, + SDL_PIXELFORMAT_RGB565, + SDL_PIXELFORMAT_BGR565, + SDL_PIXELFORMAT_ARGB1555, + SDL_PIXELFORMAT_ABGR1555, + SDL_PIXELFORMAT_RGBA5551, + SDL_PIXELFORMAT_RGB555, + SDL_PIXELFORMAT_BGR555, + SDL_PIXELFORMAT_ARGB4444, + SDL_PIXELFORMAT_ABGR4444, + SDL_PIXELFORMAT_RGBA4444, + SDL_PIXELFORMAT_RGB444, + SDL_PIXELFORMAT_ARGB2101010, + SDL_PIXELFORMAT_INDEX8, + SDL_PIXELFORMAT_INDEX4LSB, + SDL_PIXELFORMAT_INDEX4MSB, + SDL_PIXELFORMAT_RGB332, + SDL_PIXELFORMAT_INDEX1LSB, + SDL_PIXELFORMAT_INDEX1MSB, + SDL_PIXELFORMAT_UNKNOWN + }; + + bpp = fmt->BitsPerPixel; + Rmask = fmt->Rmask; + Gmask = fmt->Gmask; + Bmask = fmt->Bmask; + Amask = fmt->Amask; + + format = + SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask); + if (!format) { + SDL_SetError("Unknown pixel format"); + return 0; + } + + /* Search requested format in the supported texture */ + /* formats by current renderer */ + for (it = 0; it < renderer->info.num_texture_formats; it++) { + if (renderer->info.texture_formats[it] == format) { + break; + } + } + + /* If requested format can't be found, search any best */ + /* format which renderer provides */ + if (it == renderer->info.num_texture_formats) { + pfmt = 0; + for (;;) { + if (sdl_pformats[pfmt] == SDL_PIXELFORMAT_UNKNOWN) { + break; + } + + for (it = 0; it < renderer->info.num_texture_formats; + it++) { + if (renderer->info.texture_formats[it] == + sdl_pformats[pfmt]) { + break; + } + } + + if (it != renderer->info.num_texture_formats) { + /* The best format has been found */ + break; + } + pfmt++; + } + + /* If any format can't be found, then return an error */ + if (it == renderer->info.num_texture_formats) { + SDL_SetError + ("Any of the supported pixel formats can't be found"); + return 0; + } + + /* Convert found pixel format back to color masks */ + if (SDL_PixelFormatEnumToMasks + (renderer->info.texture_formats[it], &bpp, &Rmask, &Gmask, + &Bmask, &Amask) != SDL_TRUE) { + SDL_SetError("Unknown pixel format"); + return 0; + } + } + } else { + /* Need a format with alpha */ + Uint32 it; + int apfmt; + + /* Pixel formats with alpha, sorted by best first */ + static const Uint32 sdl_alpha_pformats[] = { + SDL_PIXELFORMAT_ARGB8888, + SDL_PIXELFORMAT_RGBA8888, + SDL_PIXELFORMAT_ABGR8888, + SDL_PIXELFORMAT_BGRA8888, + SDL_PIXELFORMAT_ARGB1555, + SDL_PIXELFORMAT_ABGR1555, + SDL_PIXELFORMAT_RGBA5551, + SDL_PIXELFORMAT_ARGB4444, + SDL_PIXELFORMAT_ABGR4444, + SDL_PIXELFORMAT_RGBA4444, + SDL_PIXELFORMAT_ARGB2101010, + SDL_PIXELFORMAT_UNKNOWN + }; + + if (surface->format->Amask) { + /* If surface already has alpha, then try an original */ + /* surface format first */ + bpp = fmt->BitsPerPixel; + Rmask = fmt->Rmask; + Gmask = fmt->Gmask; + Bmask = fmt->Bmask; + Amask = fmt->Amask; + } else { + bpp = 32; + Rmask = 0x00FF0000; + Gmask = 0x0000FF00; + Bmask = 0x000000FF; + Amask = 0xFF000000; + } + + format = + SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask); + if (!format) { + SDL_SetError("Unknown pixel format"); + return 0; + } + + /* Search this format in the supported texture formats */ + /* by current renderer */ + for (it = 0; it < renderer->info.num_texture_formats; it++) { + if (renderer->info.texture_formats[it] == format) { + break; + } + } + + /* If this format can't be found, search any best */ + /* compatible format with alpha which renderer provides */ + if (it == renderer->info.num_texture_formats) { + apfmt = 0; + for (;;) { + if (sdl_alpha_pformats[apfmt] == SDL_PIXELFORMAT_UNKNOWN) { + break; + } + + for (it = 0; it < renderer->info.num_texture_formats; + it++) { + if (renderer->info.texture_formats[it] == + sdl_alpha_pformats[apfmt]) { + break; + } + } + + if (it != renderer->info.num_texture_formats) { + /* Compatible format has been found */ + break; + } + apfmt++; + } + + /* If compatible format can't be found, then return an error */ + if (it == renderer->info.num_texture_formats) { + SDL_SetError("Compatible pixel format can't be found"); + return 0; + } + + /* Convert found pixel format back to color masks */ + if (SDL_PixelFormatEnumToMasks + (renderer->info.texture_formats[it], &bpp, &Rmask, &Gmask, + &Bmask, &Amask) != SDL_TRUE) { + SDL_SetError("Unknown pixel format"); + return 0; + } + } + } + + format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask); + if (!format) { + SDL_SetError("Unknown pixel format"); + return 0; + } + } + + texture = + SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, + surface->h); + if (!texture && !requested_format) { + SDL_DisplayMode desktop_mode; + SDL_GetDesktopDisplayMode(&desktop_mode); + format = desktop_mode.format; + texture = + SDL_CreateTexture(format, SDL_TEXTUREACCESS_STATIC, surface->w, + surface->h); + } + if (!texture) { + return 0; + } + if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask + && Bmask == fmt->Bmask && Amask == fmt->Amask) { + if (SDL_MUSTLOCK(surface)) { + SDL_LockSurface(surface); + SDL_UpdateTexture(texture, NULL, surface->pixels, + surface->pitch); + SDL_UnlockSurface(surface); + } else { + SDL_UpdateTexture(texture, NULL, surface->pixels, + surface->pitch); + } + } else { + SDL_PixelFormat dst_fmt; + SDL_Surface *dst = NULL; + + /* Set up a destination surface for the texture update */ + SDL_InitFormat(&dst_fmt, bpp, Rmask, Gmask, Bmask, Amask); +#if SDL_VERSION_ATLEAST(1,3,0) + if (SDL_ISPIXELFORMAT_INDEXED(format)) { + dst_fmt.palette = + SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format))); + if (dst_fmt.palette) { + /* + * FIXME: Should we try to copy + * fmt->palette? + */ + SDL_DitherColors(dst_fmt.palette->colors, + SDL_BITSPERPIXEL(format)); + } + } +#endif + dst = SDL_ConvertSurface(surface, &dst_fmt, 0); + if (dst) { + SDL_UpdateTexture(texture, NULL, dst->pixels, dst->pitch); + SDL_FreeSurface(dst); + } +#if SDL_VERSION_ATLEAST(1,3,0) + if (dst_fmt.palette) { + SDL_FreePalette(dst_fmt.palette); + } +#endif + if (!dst) { + SDL_DestroyTexture(texture); + return 0; + } + } + + { + Uint8 r, g, b, a; + int blendMode; + int scaleMode; + +#if SDL_VERSION_ATLEAST(1,3,0) + SDL_GetSurfaceColorMod(surface, &r, &g, &b); + SDL_SetTextureColorMod(texture, r, g, b); + + SDL_GetSurfaceAlphaMod(surface, &a); + SDL_SetTextureAlphaMod(texture, a); + + SDL_GetSurfaceBlendMode(surface, &blendMode); + SDL_SetTextureBlendMode(texture, blendMode); + + SDL_GetSurfaceScaleMode(surface, &scaleMode); + SDL_SetTextureScaleMode(texture, scaleMode); +#else + if(surface->flags & SDL_SRCALPHA) { + SDL_SetTextureAlphaMod(texture, surface->format->alpha); + SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); + } +#endif + } + +#if SDL_VERSION_ATLEAST(1,3,0) + if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) { + SDL_SetTexturePalette(texture, fmt->palette->colors, 0, + fmt->palette->ncolors); + } +#endif + return texture; +} + +int +SDL_QueryTexture(SDL_Texture * texture, Uint32 * format, int *access, + int *w, int *h) +{ + CHECK_TEXTURE_MAGIC(texture, -1); + + if (format) { + *format = texture->format; + } + if (access) { + *access = texture->access; + } + if (w) { + *w = texture->w; + } + if (h) { + *h = texture->h; + } + return 0; +} + +int +SDL_QueryTexturePixels(SDL_Texture * texture, void **pixels, int *pitch) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, -1); + + renderer = texture->renderer; + if (!renderer->QueryTexturePixels) { + SDL_Unsupported(); + return -1; + } + return renderer->QueryTexturePixels(renderer, texture, pixels, pitch); +} + +int +SDL_SetTexturePalette(SDL_Texture * texture, const SDL_Color * colors, + int firstcolor, int ncolors) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, -1); + + renderer = texture->renderer; + if (!renderer->SetTexturePalette) { + SDL_Unsupported(); + return -1; + } + return renderer->SetTexturePalette(renderer, texture, colors, firstcolor, + ncolors); +} + +int +SDL_GetTexturePalette(SDL_Texture * texture, SDL_Color * colors, + int firstcolor, int ncolors) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, -1); + + renderer = texture->renderer; + if (!renderer->GetTexturePalette) { + SDL_Unsupported(); + return -1; + } + return renderer->GetTexturePalette(renderer, texture, colors, firstcolor, + ncolors); +} + +int +SDL_SetTextureColorMod(SDL_Texture * texture, Uint8 r, Uint8 g, Uint8 b) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, -1); + + renderer = texture->renderer; + if (!renderer->SetTextureColorMod) { + SDL_Unsupported(); + return -1; + } + if (r < 255 || g < 255 || b < 255) { + texture->modMode |= SDL_TEXTUREMODULATE_COLOR; + } else { + texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR; + } + texture->r = r; + texture->g = g; + texture->b = b; + return renderer->SetTextureColorMod(renderer, texture); +} + +int +SDL_GetTextureColorMod(SDL_Texture * texture, Uint8 * r, Uint8 * g, + Uint8 * b) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, -1); + + renderer = texture->renderer; + if (r) { + *r = texture->r; + } + if (g) { + *g = texture->g; + } + if (b) { + *b = texture->b; + } + return 0; +} + +int +SDL_SetTextureAlphaMod(SDL_Texture * texture, Uint8 alpha) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, -1); + + renderer = texture->renderer; + if (!renderer->SetTextureAlphaMod) { + SDL_Unsupported(); + return -1; + } + if (alpha < 255) { + texture->modMode |= SDL_TEXTUREMODULATE_ALPHA; + } else { + texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA; + } + texture->a = alpha; + return renderer->SetTextureAlphaMod(renderer, texture); +} + +int +SDL_GetTextureAlphaMod(SDL_Texture * texture, Uint8 * alpha) +{ + CHECK_TEXTURE_MAGIC(texture, -1); + + if (alpha) { + *alpha = texture->a; + } + return 0; +} + +int +SDL_SetTextureBlendMode(SDL_Texture * texture, int blendMode) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, -1); + + renderer = texture->renderer; + if (!renderer->SetTextureBlendMode) { + SDL_Unsupported(); + return -1; + } + texture->blendMode = blendMode; + return renderer->SetTextureBlendMode(renderer, texture); +} + +int +SDL_GetTextureBlendMode(SDL_Texture * texture, int *blendMode) +{ + CHECK_TEXTURE_MAGIC(texture, -1); + + if (blendMode) { + *blendMode = texture->blendMode; + } + return 0; +} + +int +SDL_SetTextureScaleMode(SDL_Texture * texture, int scaleMode) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, -1); + + renderer = texture->renderer; + if (!renderer->SetTextureScaleMode) { + SDL_Unsupported(); + return -1; + } + texture->scaleMode = scaleMode; + return renderer->SetTextureScaleMode(renderer, texture); +} + +int +SDL_GetTextureScaleMode(SDL_Texture * texture, int *scaleMode) +{ + CHECK_TEXTURE_MAGIC(texture, -1); + + if (scaleMode) { + *scaleMode = texture->scaleMode; + } + return 0; +} + +int +SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect, + const void *pixels, int pitch) +{ + SDL_Renderer *renderer; + SDL_Rect full_rect; + + CHECK_TEXTURE_MAGIC(texture, -1); + + renderer = texture->renderer; + if (!renderer->UpdateTexture) { + SDL_Unsupported(); + return -1; + } + if (!rect) { + full_rect.x = 0; + full_rect.y = 0; + full_rect.w = texture->w; + full_rect.h = texture->h; + rect = &full_rect; + } + return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch); +} + +int +SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, int markDirty, + void **pixels, int *pitch) +{ + SDL_Renderer *renderer; + SDL_Rect full_rect; + + CHECK_TEXTURE_MAGIC(texture, -1); + + if (texture->access != SDL_TEXTUREACCESS_STREAMING) { + SDL_SetError("SDL_LockTexture(): texture must be streaming"); + return -1; + } + renderer = texture->renderer; + if (!renderer->LockTexture) { + SDL_Unsupported(); + return -1; + } + if (!rect) { + full_rect.x = 0; + full_rect.y = 0; + full_rect.w = texture->w; + full_rect.h = texture->h; + rect = &full_rect; + } + return renderer->LockTexture(renderer, texture, rect, markDirty, pixels, + pitch); +} + +void +SDL_UnlockTexture(SDL_Texture * texture) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, ); + + if (texture->access != SDL_TEXTUREACCESS_STREAMING) { + return; + } + renderer = texture->renderer; + if (!renderer->UnlockTexture) { + return; + } + renderer->UnlockTexture(renderer, texture); +} + +void +SDL_DirtyTexture(SDL_Texture * texture, int numrects, + const SDL_Rect * rects) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, ); + + if (texture->access != SDL_TEXTUREACCESS_STREAMING) { + return; + } + renderer = texture->renderer; + if (!renderer->DirtyTexture) { + return; + } + renderer->DirtyTexture(renderer, texture, numrects, rects); +} + +int +SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + SDL_Renderer *renderer; + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + renderer->r = r; + renderer->g = g; + renderer->b = b; + renderer->a = a; + if (renderer->SetDrawColor) { + return renderer->SetDrawColor(renderer); + } else { + return 0; + } +} + +int +SDL_GetRenderDrawColor(Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a) +{ + SDL_Renderer *renderer; + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + if (r) { + *r = renderer->r; + } + if (g) { + *g = renderer->g; + } + if (b) { + *b = renderer->b; + } + if (a) { + *a = renderer->a; + } + return 0; +} + +int +SDL_SetRenderDrawBlendMode(int blendMode) +{ + SDL_Renderer *renderer; + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + renderer->blendMode = blendMode; + if (renderer->SetDrawBlendMode) { + return renderer->SetDrawBlendMode(renderer); + } else { + return 0; + } +} + +int +SDL_GetRenderDrawBlendMode(int *blendMode) +{ + SDL_Renderer *renderer; + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + *blendMode = renderer->blendMode; + return 0; +} + +int +SDL_RenderClear() +{ + SDL_Renderer *renderer; + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + if (!renderer->RenderClear) { + int blendMode = renderer->blendMode; + int status; + + if (blendMode >= SDL_BLENDMODE_BLEND) { + SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); + } + + status = SDL_RenderFillRect(NULL); + + if (blendMode >= SDL_BLENDMODE_BLEND) { + SDL_SetRenderDrawBlendMode(blendMode); + } + return status; + } + return renderer->RenderClear(renderer); +} + +#if SDL_VIDEO_RENDER_RESIZE + +static inline void +SDL_RESIZE_resizePoints(int realW, int fakeW, int realH, int fakeH, + const SDL_Point * src, SDL_Point * dest, int count ) +{ + int i; + for( i = 0; i < count; i++ ) { + dest[i].x = src[i].x * realW / fakeW; + dest[i].y = src[i].y * realH / fakeH; + } +} + +static inline void +SDL_RESIZE_resizeRects(int realW, int fakeW, int realH, int fakeH, + const SDL_Rect ** src, SDL_Rect * dest, int count ) +{ + int i; + for( i = 0; i < count; i++ ) { + // Calculate bottom-right corner instead of width/height, and substract upper-left corner, + // otherwise we'll have rounding errors and holes between textures + dest[i].x = src[i]->x * realW / fakeW; + dest[i].y = src[i]->y * realH / fakeH; + dest[i].w = (src[i]->w + src[i]->x) * realW / fakeW - dest[i].x; + dest[i].h = (src[i]->h + src[i]->y) * realH / fakeH - dest[i].y; + } +} + +#endif + +int +SDL_RenderDrawPoint(int x, int y) +{ + SDL_Point point; + + point.x = x; + point.y = y; + + return SDL_RenderDrawPoints(&point, 1); +} + +int +SDL_RenderDrawPoints(const SDL_Point * points, int count) +{ + SDL_Renderer *renderer; +#if SDL_VIDEO_RENDER_RESIZE + int realW, realH, fakeW, fakeH, ret; +#endif + + if (!points) { + SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points"); + return -1; + } + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + if (!renderer->RenderDrawPoints) { + SDL_Unsupported(); + return -1; + } + if (count < 1) { + return 0; + } + +#if SDL_VIDEO_RENDER_RESIZE + realW = renderer->window->display->desktop_mode.w; + realH = renderer->window->display->desktop_mode.h; + fakeW = renderer->window->w; + fakeH = renderer->window->h; + //if( fakeW > realW || fakeH > realH ) + { + SDL_Point * resized = SDL_stack_alloc( SDL_Point, count ); + if( ! resized ) { + SDL_OutOfMemory(); + return -1; + } + SDL_RESIZE_resizePoints( realW, fakeW, realH, fakeH, points, resized, count ); + ret = renderer->RenderDrawPoints(renderer, resized, count); + SDL_stack_free(resized); + return ret; + } +#endif + + return renderer->RenderDrawPoints(renderer, points, count); +} + +int +SDL_RenderDrawLine(int x1, int y1, int x2, int y2) +{ + SDL_Point points[2]; + + points[0].x = x1; + points[0].y = y1; + points[1].x = x2; + points[1].y = y2; + return SDL_RenderDrawLines(points, 2); +} + +int +SDL_RenderDrawLines(const SDL_Point * points, int count) +{ + SDL_Renderer *renderer; +#if SDL_VIDEO_RENDER_RESIZE + int realW, realH, fakeW, fakeH, ret; +#endif + + if (!points) { + SDL_SetError("SDL_RenderDrawLines(): Passed NULL points"); + return -1; + } + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + if (!renderer->RenderDrawLines) { + SDL_Unsupported(); + return -1; + } + if (count < 2) { + return 0; + } + +#if SDL_VIDEO_RENDER_RESIZE + realW = renderer->window->display->desktop_mode.w; + realH = renderer->window->display->desktop_mode.h; + fakeW = renderer->window->w; + fakeH = renderer->window->h; + //if( fakeW > realW || fakeH > realH ) + { + SDL_Point * resized = SDL_stack_alloc( SDL_Point, count ); + if( ! resized ) { + SDL_OutOfMemory(); + return -1; + } + SDL_RESIZE_resizePoints( realW, fakeW, realH, fakeH, points, resized, count ); + ret = renderer->RenderDrawLines(renderer, resized, count); + SDL_stack_free(resized); + return ret; + } +#endif + + return renderer->RenderDrawLines(renderer, points, count); +} + +int +SDL_RenderDrawRect(const SDL_Rect * rect) +{ + return SDL_RenderDrawRects(&rect, 1); +} + +int +SDL_RenderDrawRects(const SDL_Rect ** rects, int count) +{ + SDL_Renderer *renderer; + int i; +#if SDL_VIDEO_RENDER_RESIZE + int realW, realH, fakeW, fakeH, ret; +#endif + + if (!rects) { + SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects"); + return -1; + } + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + if (!renderer->RenderDrawRects) { + SDL_Unsupported(); + return -1; + } + if (count < 1) { + return 0; + } + /* Check for NULL rect, which means fill entire window */ + for (i = 0; i < count; ++i) { + if (rects[i] == NULL) { + SDL_Window *window = renderer->window; + SDL_Rect full_rect; + const SDL_Rect *rect; + + full_rect.x = 0; + full_rect.y = 0; + full_rect.w = window->w; + full_rect.h = window->h; + rect = &full_rect; + return renderer->RenderDrawRects(renderer, &rect, 1); + } + } + +#if SDL_VIDEO_RENDER_RESIZE + realW = renderer->window->display->desktop_mode.w; + realH = renderer->window->display->desktop_mode.h; + fakeW = renderer->window->w; + fakeH = renderer->window->h; + //if( fakeW > realW || fakeH > realH ) + { + SDL_Rect * resized = SDL_stack_alloc( SDL_Rect, count ); + if( ! resized ) { + SDL_OutOfMemory(); + return -1; + } + + const SDL_Rect ** resizedPtrs = SDL_stack_alloc( const SDL_Rect *, count ); + if( ! resizedPtrs ) { + SDL_OutOfMemory(); + return -1; + } + + for( i = 0; i < count; i++ ) { + resizedPtrs[i] = &(resized[i]); + } + SDL_RESIZE_resizeRects( realW, fakeW, realH, fakeH, rects, resized, count ); + ret = renderer->RenderDrawRects(renderer, resizedPtrs, count); + SDL_stack_free(resizedPtrs); + SDL_stack_free(resized); + return ret; + } +#endif + + return renderer->RenderDrawRects(renderer, rects, count); +} + +int +SDL_RenderFillRect(const SDL_Rect * rect) +{ + return SDL_RenderFillRects(&rect, 1); +} + +int +SDL_RenderFillRects(const SDL_Rect ** rects, int count) +{ + SDL_Renderer *renderer; + int i; +#if SDL_VIDEO_RENDER_RESIZE + int realW, realH, fakeW, fakeH, ret; +#endif + + if (!rects) { + SDL_SetError("SDL_RenderFillRects(): Passed NULL rects"); + return -1; + } + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + if (!renderer->RenderFillRects) { + SDL_Unsupported(); + return -1; + } + if (count < 1) { + return 0; + } + /* Check for NULL rect, which means fill entire window */ + for (i = 0; i < count; ++i) { + if (rects[i] == NULL) { + SDL_Window *window = renderer->window; + SDL_Rect full_rect; + const SDL_Rect *rect; + + full_rect.x = 0; + full_rect.y = 0; + full_rect.w = window->w; + full_rect.h = window->h; + rect = &full_rect; + return renderer->RenderFillRects(renderer, &rect, 1); + } + } + +#if SDL_VIDEO_RENDER_RESIZE + realW = renderer->window->display->desktop_mode.w; + realH = renderer->window->display->desktop_mode.h; + fakeW = renderer->window->w; + fakeH = renderer->window->h; + //if( fakeW > realW || fakeH > realH ) + { + SDL_Rect * resized = SDL_stack_alloc( SDL_Rect, count ); + if( ! resized ) { + SDL_OutOfMemory(); + return -1; + } + + const SDL_Rect ** resizedPtrs = SDL_stack_alloc( const SDL_Rect *, count ); + if( ! resizedPtrs ) { + SDL_OutOfMemory(); + return -1; + } + + for( i = 0; i < count; i++ ) { + resizedPtrs[i] = &(resized[i]); + } + SDL_RESIZE_resizeRects( realW, fakeW, realH, fakeH, rects, resized, count ); + ret = renderer->RenderFillRects(renderer, resizedPtrs, count); + SDL_stack_free(resizedPtrs); + SDL_stack_free(resized); + return ret; + } +#endif + + return renderer->RenderFillRects(renderer, rects, count); +} + +int +SDL_RenderCopy(SDL_Texture * texture, const SDL_Rect * srcrect, + const SDL_Rect * dstrect) +{ + SDL_Renderer *renderer; + SDL_Window *window; + SDL_Rect real_srcrect; + SDL_Rect real_dstrect; +#if SDL_VIDEO_RENDER_RESIZE + int realW; + int realH; + int fakeW; + int fakeH; +#endif + + CHECK_TEXTURE_MAGIC(texture, -1); + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + if (texture->renderer != renderer) { + SDL_SetError("Texture was not created with this renderer"); + return -1; + } + if (!renderer->RenderCopy) { + SDL_Unsupported(); + return -1; + } + window = renderer->window; + + real_srcrect.x = 0; + real_srcrect.y = 0; + real_srcrect.w = texture->w; + real_srcrect.h = texture->h; + if (srcrect) { + if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) { + return 0; + } + } + + real_dstrect.x = 0; + real_dstrect.y = 0; + real_dstrect.w = window->w; + real_dstrect.h = window->h; + if (dstrect) { + if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) { + return 0; + } + /* Clip srcrect by the same amount as dstrect was clipped */ + if (dstrect->w != real_dstrect.w) { + int deltax = (real_dstrect.x - dstrect->x); + int deltaw = (real_dstrect.w - dstrect->w); + real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w; + real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w; + } + if (dstrect->h != real_dstrect.h) { + int deltay = (real_dstrect.y - dstrect->y); + int deltah = (real_dstrect.h - dstrect->h); + real_srcrect.y += (deltay * real_srcrect.h) / dstrect->h; + real_srcrect.h += (deltah * real_srcrect.h) / dstrect->h; + } + } + +#if SDL_VIDEO_RENDER_RESIZE + realW = window->display->desktop_mode.w; + realH = window->display->desktop_mode.h; + fakeW = window->w; + fakeH = window->h; + //if( fakeW > realW || fakeH > realH ) + { + // Calculate bottom-right corner instead of width/height, and substract upper-left corner, + // otherwise we'll have rounding errors and holes between textures + real_dstrect.w = (real_dstrect.w + real_dstrect.x) * realW / fakeW; + real_dstrect.h = (real_dstrect.h + real_dstrect.y) * realH / fakeH; + real_dstrect.x = real_dstrect.x * realW / fakeW; + real_dstrect.y = real_dstrect.y * realH / fakeH; + real_dstrect.w -= real_dstrect.x; + real_dstrect.h -= real_dstrect.y; + //__android_log_print(ANDROID_LOG_INFO, "libSDL", "SDL_RenderCopy dest %d:%d+%d+%d desktop_mode %d:%d", (int)real_dstrect.x, (int)real_dstrect.y, (int)real_dstrect.w, (int)real_dstrect.h, (int)realW, (int)realH); + } +#endif + + return renderer->RenderCopy(renderer, texture, &real_srcrect, + &real_dstrect); +} + +int +SDL_RenderReadPixels(const SDL_Rect * rect, Uint32 format, + void * pixels, int pitch) +{ + SDL_Renderer *renderer; + SDL_Window *window; + SDL_Rect real_rect; + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + if (!renderer->RenderReadPixels) { + SDL_Unsupported(); + return -1; + } + window = renderer->window; + + if (!format) { + format = window->display->current_mode.format; + } + + real_rect.x = 0; + real_rect.y = 0; + real_rect.w = window->w; + real_rect.h = window->h; + if (rect) { + if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { + return 0; + } + if (real_rect.y > rect->y) { + pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y); + } + if (real_rect.x > rect->x) { + Uint32 format = SDL_CurrentDisplay->current_mode.format; + int bpp = SDL_BYTESPERPIXEL(format); + pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x); + } + } + + return renderer->RenderReadPixels(renderer, &real_rect, + format, pixels, pitch); +} + +int +SDL_RenderWritePixels(const SDL_Rect * rect, Uint32 format, + const void * pixels, int pitch) +{ + SDL_Renderer *renderer; + SDL_Window *window; + SDL_Rect real_rect; + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer) { + return -1; + } + if (!renderer->RenderWritePixels) { + SDL_Unsupported(); + return -1; + } + window = renderer->window; + + if (!format) { + format = window->display->current_mode.format; + } + + real_rect.x = 0; + real_rect.y = 0; + real_rect.w = window->w; + real_rect.h = window->h; + if (rect) { + if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { + return 0; + } + if (real_rect.y > rect->y) { + pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y); + } + if (real_rect.x > rect->x) { + Uint32 format = SDL_CurrentDisplay->current_mode.format; + int bpp = SDL_BYTESPERPIXEL(format); + pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x); + } + } + + return renderer->RenderWritePixels(renderer, &real_rect, + format, pixels, pitch); +} + +void +SDL_RenderPresent(void) +{ + SDL_Renderer *renderer; + + renderer = SDL_GetCurrentRenderer(SDL_TRUE); + if (!renderer || !renderer->RenderPresent) { + return; + } + renderer->RenderPresent(renderer); +} + +void +SDL_DestroyTexture(SDL_Texture * texture) +{ + SDL_Renderer *renderer; + + CHECK_TEXTURE_MAGIC(texture, ); + texture->magic = NULL; + + renderer = texture->renderer; + if (texture->next) { + texture->next->prev = texture->prev; + } + if (texture->prev) { + texture->prev->next = texture->next; + } else { + renderer->textures = texture->next; + } + + renderer->DestroyTexture(renderer, texture); + SDL_free(texture); +} + +void +SDL_DestroyRenderer(SDL_Window * window) +{ + SDL_Renderer *renderer; + + CHECK_WINDOW_MAGIC(window, ); + + renderer = window->renderer; + if (!renderer) { + return; + } + + /* Free existing textures for this renderer */ + while (renderer->textures) { + SDL_DestroyTexture(renderer->textures); + } + + /* Free the renderer instance */ + renderer->DestroyRenderer(renderer); + + /* Clear references */ + window->renderer = NULL; + if (SDL_CurrentDisplay->current_renderer == renderer) { + SDL_CurrentDisplay->current_renderer = NULL; + } +} + +SDL_bool +SDL_IsScreenSaverEnabled() +{ + if (!_this) { + return SDL_TRUE; + } + return _this->suspend_screensaver ? SDL_FALSE : SDL_TRUE; +} + +void +SDL_EnableScreenSaver() +{ + if (!_this) { + return; + } + if (!_this->suspend_screensaver) { + return; + } + _this->suspend_screensaver = SDL_FALSE; + if (_this->SuspendScreenSaver) { + _this->SuspendScreenSaver(_this); + } +} + +void +SDL_DisableScreenSaver() +{ + if (!_this) { + return; + } + if (_this->suspend_screensaver) { + return; + } + _this->suspend_screensaver = SDL_TRUE; + if (_this->SuspendScreenSaver) { + _this->SuspendScreenSaver(_this); + } +} + +#if SDL_VERSION_ATLEAST(1,3,0) + +void +SDL_VideoQuit(void) +{ + int i, j; + + if (!_this) { + return; + } + /* Halt event processing before doing anything else */ + SDL_StopEventLoop(); + SDL_EnableScreenSaver(); + + /* Clean up the system video */ + for (i = _this->num_displays; i--;) { + SDL_VideoDisplay *display = &_this->displays[i]; + while (display->windows) { + SDL_DestroyWindow(display->windows); + } + if (display->render_drivers) { + SDL_free(display->render_drivers); + display->render_drivers = NULL; + } + display->num_render_drivers = 0; + } + _this->VideoQuit(_this); + + for (i = _this->num_displays; i--;) { + SDL_VideoDisplay *display = &_this->displays[i]; + for (j = display->num_display_modes; j--;) { + if (display->display_modes[j].driverdata) { + SDL_free(display->display_modes[j].driverdata); + display->display_modes[j].driverdata = NULL; + } + } + if (display->display_modes) { + SDL_free(display->display_modes); + display->display_modes = NULL; + } + if (display->desktop_mode.driverdata) { + SDL_free(display->desktop_mode.driverdata); + display->desktop_mode.driverdata = NULL; + } + if (display->palette) { + SDL_FreePalette(display->palette); + display->palette = NULL; + } + if (display->gamma) { + SDL_free(display->gamma); + display->gamma = NULL; + } + if (display->driverdata) { + SDL_free(display->driverdata); + display->driverdata = NULL; + } + } + if (_this->displays) { + SDL_free(_this->displays); + _this->displays = NULL; + } + if (_this->clipboard_text) { + SDL_free(_this->clipboard_text); + _this->clipboard_text = NULL; + } + _this->free(_this); + _this = NULL; +} + +int +SDL_GL_LoadLibrary(const char *path) +{ + int retval; + + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + if (_this->gl_config.driver_loaded) { + if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) { + SDL_SetError("OpenGL library already loaded"); + return -1; + } + retval = 0; + } else { + if (!_this->GL_LoadLibrary) { + SDL_SetError("No dynamic GL support in video driver"); + return -1; + } + retval = _this->GL_LoadLibrary(_this, path); + } + if (retval == 0) { + ++_this->gl_config.driver_loaded; + } + return (retval); +} + +void * +SDL_GL_GetProcAddress(const char *proc) +{ + void *func; + + if (!_this) { + SDL_UninitializedVideo(); + return NULL; + } + func = NULL; + if (_this->GL_GetProcAddress) { + if (_this->gl_config.driver_loaded) { + func = _this->GL_GetProcAddress(_this, proc); + } else { + SDL_SetError("No GL driver has been loaded"); + } + } else { + SDL_SetError("No dynamic GL support in video driver"); + } + return func; +} + +void +SDL_GL_UnloadLibrary(void) +{ + if (!_this) { + SDL_UninitializedVideo(); + return; + } + if (_this->gl_config.driver_loaded > 0) { + if (--_this->gl_config.driver_loaded > 0) { + return; + } + if (_this->GL_UnloadLibrary) { + _this->GL_UnloadLibrary(_this); + } + } +} + +#endif + +SDL_bool +SDL_GL_ExtensionSupported(const char *extension) +{ +#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES + const GLubyte *(APIENTRY * glGetStringFunc) (GLenum); + const char *extensions; + const char *start; + const char *where, *terminator; + + /* Extension names should not have spaces. */ + where = SDL_strchr(extension, ' '); + if (where || *extension == '\0') { + return SDL_FALSE; + } + /* See if there's an environment variable override */ + start = SDL_getenv(extension); + if (start && *start == '0') { + return SDL_FALSE; + } + /* Lookup the available extensions */ + glGetStringFunc = SDL_GL_GetProcAddress("glGetString"); + if (glGetStringFunc) { + extensions = (const char *) glGetStringFunc(GL_EXTENSIONS); + } else { + extensions = NULL; + } + if (!extensions) { + return SDL_FALSE; + } + /* + * It takes a bit of care to be fool-proof about parsing the OpenGL + * extensions string. Don't be fooled by sub-strings, etc. + */ + + start = extensions; + + for (;;) { + where = SDL_strstr(start, extension); + if (!where) + break; + + terminator = where + SDL_strlen(extension); + if (where == start || *(where - 1) == ' ') + if (*terminator == ' ' || *terminator == '\0') + return SDL_TRUE; + + start = terminator; + } + return SDL_FALSE; +#else + return SDL_FALSE; +#endif +} + +#if SDL_VERSION_ATLEAST(1,3,0) + +int +SDL_GL_SetAttribute(SDL_GLattr attr, int value) +{ +#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES + int retval; + + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + retval = 0; + switch (attr) { + case SDL_GL_RED_SIZE: + _this->gl_config.red_size = value; + break; + case SDL_GL_GREEN_SIZE: + _this->gl_config.green_size = value; + break; + case SDL_GL_BLUE_SIZE: + _this->gl_config.blue_size = value; + break; + case SDL_GL_ALPHA_SIZE: + _this->gl_config.alpha_size = value; + break; + case SDL_GL_DOUBLEBUFFER: + _this->gl_config.double_buffer = value; + break; + case SDL_GL_BUFFER_SIZE: + _this->gl_config.buffer_size = value; + break; + case SDL_GL_DEPTH_SIZE: + _this->gl_config.depth_size = value; + break; + case SDL_GL_STENCIL_SIZE: + _this->gl_config.stencil_size = value; + break; + case SDL_GL_ACCUM_RED_SIZE: + _this->gl_config.accum_red_size = value; + break; + case SDL_GL_ACCUM_GREEN_SIZE: + _this->gl_config.accum_green_size = value; + break; + case SDL_GL_ACCUM_BLUE_SIZE: + _this->gl_config.accum_blue_size = value; + break; + case SDL_GL_ACCUM_ALPHA_SIZE: + _this->gl_config.accum_alpha_size = value; + break; + case SDL_GL_STEREO: + _this->gl_config.stereo = value; + break; + case SDL_GL_MULTISAMPLEBUFFERS: + _this->gl_config.multisamplebuffers = value; + break; + case SDL_GL_MULTISAMPLESAMPLES: + _this->gl_config.multisamplesamples = value; + break; + case SDL_GL_ACCELERATED_VISUAL: + _this->gl_config.accelerated = value; + break; + case SDL_GL_RETAINED_BACKING: + _this->gl_config.retained_backing = value; + break; + case SDL_GL_CONTEXT_MAJOR_VERSION: + _this->gl_config.major_version = value; + break; + case SDL_GL_CONTEXT_MINOR_VERSION: + _this->gl_config.minor_version = value; + break; + default: + SDL_SetError("Unknown OpenGL attribute"); + retval = -1; + break; + } + return retval; +#else + SDL_Unsupported(); + return -1; +#endif /* SDL_VIDEO_OPENGL */ +} + +int +SDL_GL_GetAttribute(SDL_GLattr attr, int *value) +{ +#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES + void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params); + GLenum(APIENTRY * glGetErrorFunc) (void); + GLenum attrib = 0; + GLenum error = 0; + + glGetIntegervFunc = SDL_GL_GetProcAddress("glGetIntegerv"); + if (!glGetIntegervFunc) { + return -1; + } + + glGetErrorFunc = SDL_GL_GetProcAddress("glGetError"); + if (!glGetErrorFunc) { + return -1; + } + + /* Clear value in any case */ + *value = 0; + + switch (attr) { + case SDL_GL_RETAINED_BACKING: + *value = _this->gl_config.retained_backing; + return 0; + case SDL_GL_RED_SIZE: + attrib = GL_RED_BITS; + break; + case SDL_GL_BLUE_SIZE: + attrib = GL_BLUE_BITS; + break; + case SDL_GL_GREEN_SIZE: + attrib = GL_GREEN_BITS; + break; + case SDL_GL_ALPHA_SIZE: + attrib = GL_ALPHA_BITS; + break; + case SDL_GL_DOUBLEBUFFER: +#ifndef SDL_VIDEO_OPENGL_ES + attrib = GL_DOUBLEBUFFER; + break; +#else + /* OpenGL ES 1.0 and above specifications have EGL_SINGLE_BUFFER */ + /* parameter which switches double buffer to single buffer. OpenGL ES */ + /* SDL driver must set proper value after initialization */ + *value = _this->gl_config.double_buffer; + return 0; +#endif + case SDL_GL_DEPTH_SIZE: + attrib = GL_DEPTH_BITS; + break; + case SDL_GL_STENCIL_SIZE: + attrib = GL_STENCIL_BITS; + break; +#ifndef SDL_VIDEO_OPENGL_ES + case SDL_GL_ACCUM_RED_SIZE: + attrib = GL_ACCUM_RED_BITS; + break; + case SDL_GL_ACCUM_GREEN_SIZE: + attrib = GL_ACCUM_GREEN_BITS; + break; + case SDL_GL_ACCUM_BLUE_SIZE: + attrib = GL_ACCUM_BLUE_BITS; + break; + case SDL_GL_ACCUM_ALPHA_SIZE: + attrib = GL_ACCUM_ALPHA_BITS; + break; + case SDL_GL_STEREO: + attrib = GL_STEREO; + break; +#else + case SDL_GL_ACCUM_RED_SIZE: + case SDL_GL_ACCUM_GREEN_SIZE: + case SDL_GL_ACCUM_BLUE_SIZE: + case SDL_GL_ACCUM_ALPHA_SIZE: + case SDL_GL_STEREO: + /* none of these are supported in OpenGL ES */ + *value = 0; + return 0; +#endif + case SDL_GL_MULTISAMPLEBUFFERS: +#ifndef SDL_VIDEO_OPENGL_ES + attrib = GL_SAMPLE_BUFFERS_ARB; +#else + attrib = GL_SAMPLE_BUFFERS; +#endif + break; + case SDL_GL_MULTISAMPLESAMPLES: +#ifndef SDL_VIDEO_OPENGL_ES + attrib = GL_SAMPLES_ARB; +#else + attrib = GL_SAMPLES; +#endif + break; + case SDL_GL_BUFFER_SIZE: + { + GLint bits = 0; + GLint component; + + /* + * there doesn't seem to be a single flag in OpenGL + * for this! + */ + glGetIntegervFunc(GL_RED_BITS, &component); + bits += component; + glGetIntegervFunc(GL_GREEN_BITS, &component); + bits += component; + glGetIntegervFunc(GL_BLUE_BITS, &component); + bits += component; + glGetIntegervFunc(GL_ALPHA_BITS, &component); + bits += component; + + *value = bits; + return 0; + } + case SDL_GL_ACCELERATED_VISUAL: + { + /* FIXME: How do we get this information? */ + *value = (_this->gl_config.accelerated != 0); + return 0; + } + default: + SDL_SetError("Unknown OpenGL attribute"); + return -1; + } + + glGetIntegervFunc(attrib, (GLint *) value); + error = glGetErrorFunc(); + if (error != GL_NO_ERROR) { + switch (error) { + case GL_INVALID_ENUM: + { + SDL_SetError("OpenGL error: GL_INVALID_ENUM"); + } + break; + case GL_INVALID_VALUE: + { + SDL_SetError("OpenGL error: GL_INVALID_VALUE"); + } + break; + default: + { + SDL_SetError("OpenGL error: %08X", error); + } + break; + } + return -1; + } + return 0; +#else + SDL_Unsupported(); + return -1; +#endif /* SDL_VIDEO_OPENGL */ +} + +#endif /* SDL 1.3.0 */ + +SDL_GLContext +SDL_GL_CreateContext(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, NULL); + + if (!(window->flags & SDL_WINDOW_OPENGL)) { + SDL_SetError("The specified window isn't an OpenGL window"); + return NULL; + } + return _this->GL_CreateContext(_this, window); +} + +int +SDL_GL_MakeCurrent(SDL_Window * window, SDL_GLContext context) +{ + CHECK_WINDOW_MAGIC(window, -1); + + if (!(window->flags & SDL_WINDOW_OPENGL)) { + SDL_SetError("The specified window isn't an OpenGL window"); + return -1; + } + if (!context) { + window = NULL; + } + return _this->GL_MakeCurrent(_this, window, context); +} + +int +SDL_GL_SetSwapInterval(int interval) +{ + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + if (_this->GL_SetSwapInterval) { + return _this->GL_SetSwapInterval(_this, interval); + } else { + SDL_SetError("Setting the swap interval is not supported"); + return -1; + } +} + +int +SDL_GL_GetSwapInterval(void) +{ + if (!_this) { + SDL_UninitializedVideo(); + return -1; + } + if (_this->GL_GetSwapInterval) { + return _this->GL_GetSwapInterval(_this); + } else { + SDL_SetError("Getting the swap interval is not supported"); + return -1; + } +} + +void +SDL_GL_SwapWindow(SDL_Window * window) +{ + CHECK_WINDOW_MAGIC(window, ); + + if (!(window->flags & SDL_WINDOW_OPENGL)) { + SDL_SetError("The specified window isn't an OpenGL window"); + return; + } + _this->GL_SwapWindow(_this, window); +} + +void +SDL_GL_DeleteContext(SDL_GLContext context) +{ + if (!_this || !_this->gl_data || !context) { + return; + } + _this->GL_MakeCurrent(_this, NULL, NULL); + _this->GL_DeleteContext(_this, context); +} + +#if 0 // FIXME +/* + * Utility function used by SDL_WM_SetIcon(); flags & 1 for color key, flags + * & 2 for alpha channel. + */ +static void +CreateMaskFromColorKeyOrAlpha(SDL_Surface * icon, Uint8 * mask, int flags) +{ + int x, y; + Uint32 colorkey; +#define SET_MASKBIT(icon, x, y, mask) \ + mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) + + colorkey = icon->format->colorkey; + switch (icon->format->BytesPerPixel) { + case 1: + { + Uint8 *pixels; + for (y = 0; y < icon->h; ++y) { + pixels = (Uint8 *) icon->pixels + y * icon->pitch; + for (x = 0; x < icon->w; ++x) { + if (*pixels++ == colorkey) { + SET_MASKBIT(icon, x, y, mask); + } + } + } + } + break; + + case 2: + { + Uint16 *pixels; + for (y = 0; y < icon->h; ++y) { + pixels = (Uint16 *) icon->pixels + y * icon->pitch / 2; + for (x = 0; x < icon->w; ++x) { + if ((flags & 1) && *pixels == colorkey) { + SET_MASKBIT(icon, x, y, mask); + } else if ((flags & 2) + && (*pixels & icon->format->Amask) == 0) { + SET_MASKBIT(icon, x, y, mask); + } + pixels++; + } + } + } + break; + + case 4: + { + Uint32 *pixels; + for (y = 0; y < icon->h; ++y) { + pixels = (Uint32 *) icon->pixels + y * icon->pitch / 4; + for (x = 0; x < icon->w; ++x) { + if ((flags & 1) && *pixels == colorkey) { + SET_MASKBIT(icon, x, y, mask); + } else if ((flags & 2) + && (*pixels & icon->format->Amask) == 0) { + SET_MASKBIT(icon, x, y, mask); + } + pixels++; + } + } + } + break; + } +} + +/* + * Sets the window manager icon for the display window. + */ +void +SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask) +{ + if (icon && _this->SetIcon) { + /* Generate a mask if necessary, and create the icon! */ + if (mask == NULL) { + int mask_len = icon->h * (icon->w + 7) / 8; + int flags = 0; + mask = (Uint8 *) SDL_malloc(mask_len); + if (mask == NULL) { + return; + } + SDL_memset(mask, ~0, mask_len); + if (icon->flags & SDL_SRCCOLORKEY) + flags |= 1; + if (icon->flags & SDL_SRCALPHA) + flags |= 2; + if (flags) { + CreateMaskFromColorKeyOrAlpha(icon, mask, flags); + } + _this->SetIcon(_this, icon, mask); + SDL_free(mask); + } else { + _this->SetIcon(_this, icon, mask); + } + } +} +#endif + +#if SDL_VERSION_ATLEAST(1,3,0) +SDL_bool +SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info) +{ + CHECK_WINDOW_MAGIC(window, SDL_FALSE); + + if (!_this->GetWindowWMInfo) { + return SDL_FALSE; + } + return (_this->GetWindowWMInfo(_this, window, info)); +} + +void +SDL_StartTextInput(void) +{ + if (_this && _this->StartTextInput) { + _this->StartTextInput(_this); + } + SDL_EventState(SDL_TEXTINPUT, SDL_ENABLE); + SDL_EventState(SDL_TEXTEDITING, SDL_ENABLE); +} + +void +SDL_StopTextInput(void) +{ + if (_this && _this->StopTextInput) { + _this->StopTextInput(_this); + } + SDL_EventState(SDL_TEXTINPUT, SDL_DISABLE); + SDL_EventState(SDL_TEXTEDITING, SDL_DISABLE); +} + +void +SDL_SetTextInputRect(SDL_Rect *rect) +{ + if (_this && _this->SetTextInputRect) { + _this->SetTextInputRect(_this, rect); + } +} +#endif + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.3/include/SDL_pixels.h b/alienblaster/project/sdl/sdl-1.3/include/SDL_pixels.h index deb82ca13..8c3216b07 100644 --- a/alienblaster/project/sdl/sdl-1.3/include/SDL_pixels.h +++ b/alienblaster/project/sdl/sdl-1.3/include/SDL_pixels.h @@ -29,14 +29,6 @@ #ifndef _SDL_pixels_h #define _SDL_pixels_h -#include "SDL_version.h" - -#if SDL_VERSION_ATLEAST(1,3,0) -#include "SDL_video.h" -#else -#include "SDL_video-1.3.h" -#endif - #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus @@ -227,7 +219,6 @@ enum SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED32, SDL_PACKEDORDER_ARGB, SDL_PACKEDLAYOUT_2101010, 32, 4), -#if SDL_VERSION_ATLEAST(1,3,0) SDL_PIXELFORMAT_YV12 = /**< Planar mode: Y + V + U (3 planes) */ SDL_DEFINE_PIXELFOURCC('Y', 'V', '1', '2'), SDL_PIXELFORMAT_IYUV = /**< Planar mode: Y + U + V (3 planes) */ @@ -238,10 +229,8 @@ enum SDL_DEFINE_PIXELFOURCC('U', 'Y', 'V', 'Y'), SDL_PIXELFORMAT_YVYU = /**< Packed mode: Y0+V0+Y1+U0 (1 plane) */ SDL_DEFINE_PIXELFOURCC('Y', 'V', 'Y', 'U') -#endif }; -#if SDL_VERSION_ATLEAST(1,3,0) typedef struct SDL_Color { Uint8 r; @@ -285,7 +274,6 @@ typedef struct SDL_PixelFormat Uint32 Bmask; Uint32 Amask; } SDL_PixelFormat; -#endif /** * \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks. @@ -332,7 +320,6 @@ extern DECLSPEC SDL_Palette *SDLCALL SDL_AllocPalette(int ncolors); * * \sa SDL_DelPaletteWatch() */ -#if SDL_VERSION_ATLEAST(1,3,0) extern DECLSPEC int SDLCALL SDL_AddPaletteWatch(SDL_Palette * palette, SDL_PaletteChangedFunc callback, void *userdata); @@ -346,7 +333,7 @@ extern DECLSPEC int SDLCALL SDL_AddPaletteWatch(SDL_Palette * palette, extern DECLSPEC void SDLCALL SDL_DelPaletteWatch(SDL_Palette * palette, SDL_PaletteChangedFunc callback, void *userdata); -#endif + /** * \brief Set a range of colors in a palette. * diff --git a/alienblaster/project/sdl/sdl-1.3/include/SDL_rect.h b/alienblaster/project/sdl/sdl-1.3/include/SDL_rect.h index 9b531bff0..4229d34db 100644 --- a/alienblaster/project/sdl/sdl-1.3/include/SDL_rect.h +++ b/alienblaster/project/sdl/sdl-1.3/include/SDL_rect.h @@ -31,11 +31,8 @@ #include "SDL_stdinc.h" #include "SDL_error.h" +#include "SDL_pixels.h" #include "SDL_rwops.h" -#include "SDL_version.h" -#if ! SDL_VERSION_ATLEAST(1,3,0) -#include "SDL_video.h" -#endif #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ @@ -66,13 +63,11 @@ typedef struct * \sa SDL_UnionRect * \sa SDL_EnclosePoints */ -#if SDL_VERSION_ATLEAST(1,3,0) typedef struct SDL_Rect { int x, y; int w, h; } SDL_Rect; -#endif /** * \brief Returns true if the rectangle has no area. diff --git a/alienblaster/project/sdl/sdl-1.3/include/SDL_video.h b/alienblaster/project/sdl/sdl-1.3/include/SDL_video.h index 2f0f1fe19..804869f69 100644 --- a/alienblaster/project/sdl/sdl-1.3/include/SDL_video.h +++ b/alienblaster/project/sdl/sdl-1.3/include/SDL_video.h @@ -26,17 +26,13 @@ * Header file for SDL video functions. */ -#ifndef _SDL_video_1_3_h -#define _SDL_video_1_3_h +#ifndef _SDL_video_h +#define _SDL_video_h #include "SDL_stdinc.h" -#include "SDL_rect.h" #include "SDL_pixels.h" +#include "SDL_rect.h" #include "SDL_surface.h" -#include "SDL_version.h" -#if ! SDL_VERSION_ATLEAST(1,3,0) -#include "SDL_video.h" -#endif #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ @@ -260,7 +256,6 @@ typedef struct SDL_Texture SDL_Texture; */ typedef void *SDL_GLContext; -#if SDL_VERSION_ATLEAST(1,3,0) /** * \brief OpenGL configuration attributes */ @@ -286,7 +281,7 @@ typedef enum SDL_GL_CONTEXT_MAJOR_VERSION, SDL_GL_CONTEXT_MINOR_VERSION } SDL_GLattr; -#endif + /* Function prototypes */ @@ -323,13 +318,8 @@ extern DECLSPEC const char *SDLCALL SDL_GetVideoDriver(int index); * * \sa SDL_VideoQuit() */ -extern DECLSPEC int SDLCALL -#if SDL_VERSION_ATLEAST(1,3,0) -SDL_VideoInit -#else -SDL_VideoInit_1_3 -#endif -(const char *driver_name, Uint32 flags); +extern DECLSPEC int SDLCALL SDL_VideoInit(const char *driver_name, + Uint32 flags); /** * \brief Shuts down the video subsystem. diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_pixels.c b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_pixels.c index 77ca8b0e7..3ada76536 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_pixels.c +++ b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_pixels.c @@ -20,32 +20,22 @@ slouken@libsdl.org */ #include "SDL_config.h" -#include "SDL_version.h" /* General (mostly internal) pixel/color manipulation routines for SDL */ #include "SDL_endian.h" -#if SDL_VERSION_ATLEAST(1,3,0) #include "SDL_video.h" #include "SDL_sysvideo.h" -#else -#include "SDL_video-1.3.h" -#include "SDL_sysvideo-1.3.h" -#endif #include "SDL_blit.h" #include "SDL_pixels_c.h" -#if SDL_VERSION_ATLEAST(1,3,0) #include "SDL_RLEaccel_c.h" -#endif -#if SDL_VERSION_ATLEAST(1,3,0) struct SDL_PaletteWatch { SDL_PaletteChangedFunc callback; void *userdata; struct SDL_PaletteWatch *next; }; -#endif /* Helper functions */ @@ -298,7 +288,7 @@ SDL_MasksToPixelFormatEnum(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, return SDL_PIXELFORMAT_UNKNOWN; } -#if SDL_VERSION_ATLEAST(1,3,0) + SDL_Palette * SDL_AllocPalette(int ncolors) { @@ -438,8 +428,6 @@ SDL_AllocFormat(int bpp, return SDL_InitFormat(format, bpp, Rmask, Gmask, Bmask, Amask); } -#endif - SDL_PixelFormat * SDL_InitFormat(SDL_PixelFormat * format, int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) @@ -520,8 +508,6 @@ SDL_InitFormat(SDL_PixelFormat * format, int bpp, Uint32 Rmask, Uint32 Gmask, return format; } -#if SDL_VERSION_ATLEAST(1,3,0) - /* * Change any previous mappings from/to the new surface format */ @@ -597,11 +583,7 @@ SDL_CalculatePitch(SDL_Surface * surface) default: break; } -// 4-byte aligning adds extra memcpy() with OpenGL ES renderer -// TODO: check if we really can disable that for Android -#ifndef ANDROID pitch = (pitch + 3) & ~3; /* 4-byte aligning */ -#endif return (pitch); } @@ -931,6 +913,5 @@ SDL_FreeBlitMap(SDL_BlitMap * map) SDL_free(map); } } -#endif /* vi: set ts=4 sw=4 expandtab: */ diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_pixels_c.h b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_pixels_c.h index 0db2f1247..f307400e9 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_pixels_c.h +++ b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_pixels_c.h @@ -20,7 +20,6 @@ slouken@libsdl.org */ #include "SDL_config.h" -#include "SDL_version.h" /* Useful functions and variables from SDL_pixel.c */ diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_rect_c.h b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_rect_c.h index 8438a231f..2f444760f 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_rect_c.h +++ b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_rect_c.h @@ -20,7 +20,6 @@ slouken@libsdl.org */ #include "SDL_config.h" -#include "SDL_rect.h" typedef struct SDL_DirtyRect { diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_renderer_gles.c b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_renderer_gles.c index b4f58eb54..3b0d9d2e0 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_renderer_gles.c +++ b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_renderer_gles.c @@ -20,23 +20,15 @@ slouken@libsdl.org */ #include "SDL_config.h" -#include "SDL_version.h" #if SDL_VIDEO_RENDER_OGL_ES -#if SDL_VERSION_ATLEAST(1,3,0) #include "SDL_video.h" -#include "SDL_sysvideo.h" -#else -#include "SDL_video-1.3.h" -#include "SDL_sysvideo-1.3.h" -#endif #include "SDL_opengles.h" +#include "SDL_sysvideo.h" #include "SDL_pixels_c.h" #include "SDL_rect_c.h" -#if SDL_VERSION_ATLEAST(1,3,0) #include "SDL_yuv_sw_c.h" -#endif #ifdef ANDROID #include #endif @@ -229,13 +221,11 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags) GLint value; int doublebuffer; -#if SDL_VERSION_ATLEAST(1,3,0) if (!(window->flags & SDL_WINDOW_OPENGL)) { if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) { return NULL; } } -#endif renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer)); if (!renderer) { @@ -313,15 +303,11 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC; } -#ifdef ANDROID - // Always double-buffered -#else if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer) == 0) { if (!doublebuffer) { renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER; } } -#endif #if SDL_VIDEO_DRIVER_PANDORA data->GL_OES_draw_texture_supported = SDL_FALSE; data->useDrawTexture = SDL_FALSE; @@ -369,7 +355,6 @@ GLES_ActivateRenderer(SDL_Renderer * renderer) data->glMatrixMode(GL_MODELVIEW); data->glLoadIdentity(); #if SDL_VIDEO_RENDER_RESIZE - __android_log_print(ANDROID_LOG_INFO, "libSDL", "GLES_ActivateRenderer(): %dx%d", (int)window->display->desktop_mode.w, (int)window->display->desktop_mode.h); data->glViewport(0, 0, window->display->desktop_mode.w, window->display->desktop_mode.h); data->glOrthof(0.0, (GLfloat) window->display->desktop_mode.w, (GLfloat) window->display->desktop_mode.h, 0.0, 0.0, 1.0); @@ -951,7 +936,6 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, if (data->GL_OES_draw_texture_supported && data->useDrawTexture) { /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */ SDL_Window *window = renderer->window; - GLint cropRect[4]; cropRect[0] = srcrect->x; cropRect[1] = srcrect->y + srcrect->h; diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_sysvideo.h b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_sysvideo.h index ba89f3e84..15cf4cd82 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_sysvideo.h +++ b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_sysvideo.h @@ -21,12 +21,11 @@ */ #include "SDL_config.h" -#ifndef _SDL_sysvideo_1_3_h -#define _SDL_sysvideo_1_3_h +#ifndef _SDL_sysvideo_h +#define _SDL_sysvideo_h #include "SDL_mouse.h" #include "SDL_keysym.h" -#include "SDL_rect.h" /* The SDL video driver */ diff --git a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_video.c b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_video.c index f46ba8bb9..48fed2f66 100644 --- a/alienblaster/project/sdl/sdl-1.3/src/video/SDL_video.c +++ b/alienblaster/project/sdl/sdl-1.3/src/video/SDL_video.c @@ -20,28 +20,19 @@ slouken@libsdl.org */ #include "SDL_config.h" -#include "SDL_version.h" /* The high-level video driver subsystem */ #include "SDL.h" -#if SDL_VERSION_ATLEAST(1,3,0) #include "SDL_video.h" #include "SDL_sysvideo.h" -#else -#include "SDL_video-1.3.h" -#include "SDL_sysvideo-1.3.h" -#include "SDL_androidvideo.h" -#endif #include "SDL_blit.h" #include "SDL_pixels_c.h" #include "SDL_renderer_gl.h" #include "SDL_renderer_gles.h" #include "SDL_renderer_sw.h" -#if SDL_VERSION_ATLEAST(1,3,0) #include "../events/SDL_sysevents.h" #include "../events/SDL_events_c.h" -#endif #ifdef ANDROID #include #endif @@ -191,12 +182,8 @@ SDL_GetVideoDriver(int index) /* * Initialize the video and event subsystems -- determine native pixel format */ -#if SDL_VERSION_ATLEAST(1,3,0) -int SDL_VideoInit -#else -int SDL_VideoInit_1_3 -#endif -(const char *driver_name, Uint32 flags) +int +SDL_VideoInit(const char *driver_name, Uint32 flags) { SDL_VideoDevice *video; int index; @@ -207,7 +194,6 @@ int SDL_VideoInit_1_3 SDL_VideoQuit(); } -#if SDL_VERSION_ATLEAST(1,3,0) /* Toggle the event thread flags, based on OS requirements */ #if defined(MUST_THREAD_EVENTS) flags |= SDL_INIT_EVENTTHREAD; @@ -222,11 +208,10 @@ int SDL_VideoInit_1_3 if (SDL_StartEventLoop(flags) < 0) { return -1; } -#endif + /* Select the proper video driver */ index = 0; video = NULL; -#if SDL_VERSION_ATLEAST(1,3,0) if (driver_name == NULL) { driver_name = SDL_getenv("SDL_VIDEODRIVER"); } @@ -255,14 +240,8 @@ int SDL_VideoInit_1_3 } return -1; } - _this = video; _this->name = bootstrap[i]->name; -#else - video = ANDROID_CreateDevice_1_3(0); - _this = video; - _this->name = "android"; -#endif _this->next_object_id = 1; @@ -311,11 +290,9 @@ int SDL_VideoInit_1_3 SDL_AddRenderDriver(display, &GL_ES_RenderDriver); #endif } -#if SDL_VERSION_ATLEAST(1,3,0) if (display->num_render_drivers > 0) { SDL_AddRenderDriver(display, &SW_RenderDriver); } -#endif } /* We're ready to go! */ @@ -721,7 +698,6 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * } display->current_mode = display_mode; -#if SDL_VERSION_ATLEAST(1,3,0) /* Set up a palette, if necessary */ if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) { ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format)); @@ -743,7 +719,6 @@ SDL_SetDisplayModeForDisplay(SDL_VideoDisplay * display, const SDL_DisplayMode * SDL_BITSPERPIXEL(display_mode.format)); } } -#endif return 0; } @@ -789,8 +764,6 @@ SDL_GetWindowDisplayMode(SDL_Window * window, SDL_DisplayMode * mode) return 0; } -#if SDL_VERSION_ATLEAST(1,3,0) - static void SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool attempt) { @@ -908,8 +881,6 @@ SDL_GetDisplayPalette(SDL_Color * colors, int firstcolor, int ncolors) return SDL_GetPaletteForDisplay(SDL_CurrentDisplay, colors, firstcolor, ncolors); } -#endif - SDL_Window * SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) { @@ -921,7 +892,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) SDL_VideoDisplay *display; SDL_Window *window; -#if SDL_VERSION_ATLEAST(1,3,0) if (!_this) { /* Initialize the video system if needed */ if (SDL_VideoInit(NULL, 0) < 0) { @@ -935,8 +905,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) } SDL_GL_LoadLibrary(NULL); } -#endif - display = SDL_CurrentDisplay; window = (SDL_Window *)SDL_calloc(1, sizeof(*window)); window->magic = &_this->window_magic; @@ -953,7 +921,6 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) } display->windows = window; -#if SDL_VERSION_ATLEAST(1,3,0) if (_this->CreateWindow && _this->CreateWindow(_this, window) < 0) { SDL_DestroyWindow(window); return NULL; @@ -972,13 +939,10 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) SDL_ShowWindow(window); } SDL_UpdateWindowGrab(window); -#endif return window; } -#if SDL_VERSION_ATLEAST(1,3,0) - SDL_Window * SDL_CreateWindowFrom(const void *data) { @@ -1072,7 +1036,6 @@ SDL_RecreateWindow(SDL_Window * window, Uint32 flags) return 0; } -#endif static __inline__ SDL_Renderer * SDL_GetCurrentRenderer(SDL_bool create) @@ -1093,7 +1056,6 @@ SDL_GetCurrentRenderer(SDL_bool create) return SDL_CurrentRenderer; } -#if SDL_VERSION_ATLEAST(1,3,0) Uint32 SDL_GetWindowID(SDL_Window * window) { @@ -1485,8 +1447,6 @@ SDL_GetFocusWindow(void) return NULL; } -#endif - void SDL_DestroyWindow(SDL_Window * window) { @@ -1502,19 +1462,15 @@ SDL_DestroyWindow(SDL_Window * window) SDL_DestroyRenderer(window); } -#if SDL_VERSION_ATLEAST(1,3,0) /* Restore video mode, etc. */ SDL_UpdateFullscreenMode(window, SDL_FALSE); -#endif if (_this->DestroyWindow) { _this->DestroyWindow(_this, window); } -#if SDL_VERSION_ATLEAST(1,3,0) if (window->flags & SDL_WINDOW_OPENGL) { SDL_GL_UnloadLibrary(); } -#endif /* Unlink the window from the list */ display = window->display; @@ -1579,7 +1535,6 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) /* Free any existing renderer */ SDL_DestroyRenderer(window); -#if SDL_VERSION_ATLEAST(1,3,0) if (index < 0) { char *override = SDL_getenv("SDL_VIDEO_RENDERER"); int n = SDL_GetNumRenderDrivers(); @@ -1633,9 +1588,6 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) /* Create a new renderer instance */ window->renderer = SDL_CurrentDisplay->render_drivers[index].CreateRenderer(window, flags); } -#else - window->renderer = GL_ES_RenderDriver.CreateRenderer(window, flags); -#endif if (window->renderer == NULL) { /* Assuming renderer set its error */ @@ -1754,13 +1706,8 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) } } else { if (surface->format->Amask -#if SDL_VERSION_ATLEAST(1,3,0) || !(surface->map->info.flags & (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) { -#else - || !(surface->flags & - (SDL_SRCCOLORKEY | SDL_SRCALPHA))) { -#endif Uint32 it; int pfmt; @@ -1985,7 +1932,6 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) /* Set up a destination surface for the texture update */ SDL_InitFormat(&dst_fmt, bpp, Rmask, Gmask, Bmask, Amask); -#if SDL_VERSION_ATLEAST(1,3,0) if (SDL_ISPIXELFORMAT_INDEXED(format)) { dst_fmt.palette = SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format))); @@ -1998,17 +1944,14 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) SDL_BITSPERPIXEL(format)); } } -#endif dst = SDL_ConvertSurface(surface, &dst_fmt, 0); if (dst) { SDL_UpdateTexture(texture, NULL, dst->pixels, dst->pitch); SDL_FreeSurface(dst); } -#if SDL_VERSION_ATLEAST(1,3,0) if (dst_fmt.palette) { SDL_FreePalette(dst_fmt.palette); } -#endif if (!dst) { SDL_DestroyTexture(texture); return 0; @@ -2020,7 +1963,6 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) int blendMode; int scaleMode; -#if SDL_VERSION_ATLEAST(1,3,0) SDL_GetSurfaceColorMod(surface, &r, &g, &b); SDL_SetTextureColorMod(texture, r, g, b); @@ -2032,20 +1974,12 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface) SDL_GetSurfaceScaleMode(surface, &scaleMode); SDL_SetTextureScaleMode(texture, scaleMode); -#else - if(surface->flags & SDL_SRCALPHA) { - SDL_SetTextureAlphaMod(texture, surface->format->alpha); - SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); - } -#endif } -#if SDL_VERSION_ATLEAST(1,3,0) if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) { SDL_SetTexturePalette(texture, fmt->palette->colors, 0, fmt->palette->ncolors); } -#endif return texture; } @@ -3020,8 +2954,6 @@ SDL_DisableScreenSaver() } } -#if SDL_VERSION_ATLEAST(1,3,0) - void SDL_VideoQuit(void) { @@ -3156,8 +3088,6 @@ SDL_GL_UnloadLibrary(void) } } -#endif - SDL_bool SDL_GL_ExtensionSupported(const char *extension) { @@ -3212,8 +3142,6 @@ SDL_GL_ExtensionSupported(const char *extension) #endif } -#if SDL_VERSION_ATLEAST(1,3,0) - int SDL_GL_SetAttribute(SDL_GLattr attr, int value) { @@ -3451,8 +3379,6 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) #endif /* SDL_VIDEO_OPENGL */ } -#endif /* SDL 1.3.0 */ - SDL_GLContext SDL_GL_CreateContext(SDL_Window * window) { @@ -3631,7 +3557,6 @@ SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask) } #endif -#if SDL_VERSION_ATLEAST(1,3,0) SDL_bool SDL_GetWindowWMInfo(SDL_Window * window, struct SDL_SysWMinfo *info) { @@ -3670,6 +3595,5 @@ SDL_SetTextInputRect(SDL_Rect *rect) _this->SetTextInputRect(_this, rect); } } -#endif /* vi: set ts=4 sw=4 expandtab: */