Bunch More Work on sdl12-compat.
authorRyan C. Gordon <icculus@icculus.org>
Fri, 08 Mar 2013 00:10:44 -0500
changeset 17473158daa1de
parent 16 ad3e9ebcfd90
child 18 221a624a97fb
Bunch More Work on sdl12-compat.
src/SDL12_compat.c
src/SDL20_syms.h
     1.1 --- a/src/SDL12_compat.c	Thu Mar 07 22:34:19 2013 -0500
     1.2 +++ b/src/SDL12_compat.c	Fri Mar 08 00:10:44 2013 -0500
     1.3 @@ -41,10 +41,7 @@
     1.4  // !!! IMPLEMENT_ME SDL_EventState
     1.5  // !!! IMPLEMENT_ME SDL_FillRect
     1.6  // !!! IMPLEMENT_ME SDL_FreeCursor
     1.7 -// !!! IMPLEMENT_ME SDL_FreeSurface
     1.8  // !!! IMPLEMENT_ME SDL_GL_GetAttribute
     1.9 -// !!! IMPLEMENT_ME SDL_GL_GetProcAddress
    1.10 -// !!! IMPLEMENT_ME SDL_GL_LoadLibrary
    1.11  // !!! IMPLEMENT_ME SDL_GL_Lock
    1.12  // !!! IMPLEMENT_ME SDL_GL_SetAttribute
    1.13  // !!! IMPLEMENT_ME SDL_GL_Unlock
    1.14 @@ -56,13 +53,9 @@
    1.15  // !!! IMPLEMENT_ME SDL_GetKeyState
    1.16  // !!! IMPLEMENT_ME SDL_GetModState
    1.17  // !!! IMPLEMENT_ME SDL_GetMouseState
    1.18 -// !!! IMPLEMENT_ME SDL_GetRGB
    1.19 -// !!! IMPLEMENT_ME SDL_GetRGBA
    1.20  // !!! IMPLEMENT_ME SDL_GetRelativeMouseState
    1.21  // !!! IMPLEMENT_ME SDL_LockSurface
    1.22  // !!! IMPLEMENT_ME SDL_LowerBlit
    1.23 -// !!! IMPLEMENT_ME SDL_MapRGB
    1.24 -// !!! IMPLEMENT_ME SDL_MapRGBA
    1.25  // !!! IMPLEMENT_ME SDL_PeepEvents
    1.26  // !!! IMPLEMENT_ME SDL_PollEvent
    1.27  // !!! IMPLEMENT_ME SDL_PumpEvents
    1.28 @@ -169,6 +162,7 @@
    1.29  #define SDL12_PREALLOC 0x01000000
    1.30  
    1.31  
    1.32 +static SDL12_VideoInfo VideoInfo;
    1.33  static SDL_Window *VideoWindow = NULL;
    1.34  static SDL_Surface *WindowSurface = NULL;
    1.35  static SDL_Surface *VideoSurface = NULL;
    1.36 @@ -347,6 +341,12 @@
    1.37      if (sdl12flags & SDL12_INIT_CDROM)
    1.38          CDRomInit = 0;
    1.39  
    1.40 +    // !!! FIXME: reset a bunch of other global variables too.
    1.41 +    if (sdl12flags & SDL12_INIT_VIDEO) {
    1.42 +        SDL20_FreeFormat(VideoInfo.vfmt);
    1.43 +        SDL_zero(VideoInfo);
    1.44 +    }
    1.45 +
    1.46      // !!! FIXME: do something about SDL12_INIT_EVENTTHREAD
    1.47      SDL20_QuitSubSystem(sdl20flags);
    1.48  
    1.49 @@ -356,6 +356,9 @@
    1.50  void
    1.51  SDL_Quit(void)
    1.52  {
    1.53 +    // !!! FIXME: reset a bunch of other global variables too.
    1.54 +    SDL20_FreeFormat(VideoInfo.vfmt);
    1.55 +    SDL_zero(VideoInfo);
    1.56      CDRomInit = 0;
    1.57      SDL20_Quit();
    1.58      UnloadSDL20();
    1.59 @@ -487,7 +490,7 @@
    1.60      MAPSURFACEFLAGS(RLEACCEL);
    1.61      MAPSURFACEFLAGS(DONTFREE);
    1.62      #undef MAPSURFACEFLAGS
    1.63 -    SDL_assert(flags == 0);  /* non-zero if there's a flag we didn't map. */
    1.64 +    assert(flags == 0);  /* non-zero if there's a flag we didn't map. */
    1.65  
    1.66      surface12->format = format12;
    1.67      surface12->w = surface20->w;
    1.68 @@ -518,7 +521,7 @@
    1.69          return NULL;
    1.70      }
    1.71  
    1.72 -    SDL_assert(surface12->flags == 0);  // shouldn't have prealloc, rleaccel, or dontfree.
    1.73 +    assert(surface12->flags == 0);  // shouldn't have prealloc, rleaccel, or dontfree.
    1.74      return surface12;
    1.75  }
    1.76  
    1.77 @@ -532,7 +535,7 @@
    1.78          return NULL;
    1.79      }
    1.80  
    1.81 -    SDL_assert(surface12->flags == SDL12_PREALLOC);  // should _only_ have prealloc.
    1.82 +    assert(surface12->flags == SDL12_PREALLOC);  // should _only_ have prealloc.
    1.83      return surface12;
    1.84  }
    1.85  
    1.86 @@ -548,23 +551,84 @@
    1.87      }
    1.88  }
    1.89  
    1.90 +static SDL_PixelFormat *
    1.91 +PixelFormat12to20(SDL_PixelFormat *format20, SDL_Palette *palette20, SDL12_PixelFormat *format12)
    1.92 +{
    1.93 +    palette20->ncolors = format12->palette->ncolors;
    1.94 +    palette20->colors = format12->palette->colors;
    1.95 +    palette20->version = 1;
    1.96 +    palette20->refcount = 1;
    1.97 +    format20->format = SDL_MasksToPixelFormatEnum(format12->BitsPerPixel, format12->Rmask, format12->Gmask, format12->Bmask, format12->Amask);
    1.98 +    format20->palette = palette20;
    1.99 +    format20->BitsPerPixel = format12->BitsPerPixel;
   1.100 +    format20->BytesPerPixel = format12->BytesPerPixel;
   1.101 +    format20->Rmask = format12->Rmask;
   1.102 +    format20->Gmask = format12->Gmask;
   1.103 +    format20->Bmask = format12->Bmask;
   1.104 +    format20->Amask = format12->Amask;
   1.105 +    format20->Rloss = format12->Rloss;
   1.106 +    format20->Gloss = format12->Gloss;
   1.107 +    format20->Bloss = format12->Bloss;
   1.108 +    format20->Aloss = format12->Aloss;
   1.109 +    format20->Rshift = format12->Rshift;
   1.110 +    format20->Gshift = format12->Gshift;
   1.111 +    format20->Bshift = format12->Bshift;
   1.112 +    format20->Ashift = format12->Ashift;
   1.113 +    format20->refcount = 1;
   1.114 +    format20->next = NULL;
   1.115 +    return format20;
   1.116 +}
   1.117 +
   1.118 +Uint32
   1.119 +SDL_MapRGB(const SDL12_PixelFormat *format12, Uint8 r, Uint8 g, Uint8 b)
   1.120 +{
   1.121 +    /* This is probably way slower than apps expect. */
   1.122 +    SDL_PixelFormat format20;
   1.123 +    SDL_Palette palette20;
   1.124 +    return SDL20_MapRGB(PixelFormat12to20(&format20, &palette20, format12), r, g, b);
   1.125 +}
   1.126 +
   1.127 +Uint32
   1.128 +SDL_MapRGBA(const SDL12_PixelFormat *format12, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
   1.129 +{
   1.130 +    /* This is probably way slower than apps expect. */
   1.131 +    SDL_PixelFormat format20;
   1.132 +    SDL_Palette palette20;
   1.133 +    return SDL20_MapRGBA(PixelFormat12to20(&format20, &palette20, format12), r, g, b, a);
   1.134 +}
   1.135 +
   1.136 +void
   1.137 +SDL_GetRGB(Uint32 pixel, const SDL12_PixelFormat *format12, Uint8 *r, Uint8 *g, Uint8 *b)
   1.138 +{
   1.139 +    /* This is probably way slower than apps expect. */
   1.140 +    SDL_PixelFormat format20;
   1.141 +    SDL_Palette palette20;
   1.142 +    return SDL20_GetRGB(pixel, PixelFormat12to20(&format20, &palette20, format12), r, g, b);
   1.143 +}
   1.144 +
   1.145 +void
   1.146 +SDL_GetRGBA(Uint32 pixel, const SDL12_PixelFormat *format12, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)
   1.147 +{
   1.148 +    /* This is probably way slower than apps expect. */
   1.149 +    SDL_PixelFormat format20;
   1.150 +    SDL_Palette palette20;
   1.151 +    return SDL20_GetRGB(pixel, PixelFormat12to20(&format20, &palette20, format12), r, g, b, a);
   1.152 +}
   1.153  
   1.154  const SDL12_VideoInfo *
   1.155  SDL_GetVideoInfo(void)
   1.156  {
   1.157 -    static SDL12_VideoInfo info;
   1.158      SDL_DisplayMode mode;
   1.159  
   1.160 -    /* !!! FIXME: Memory leak, compatibility code, who cares? */
   1.161 -    if (!info.vfmt && SDL20_GetDesktopDisplayMode(VideoDisplayIndex, &mode) == 0) {
   1.162 -        info.vfmt = SDL20_AllocFormat(mode.format);
   1.163 -        info.current_w = mode.w;
   1.164 -        info.current_h = mode.h;
   1.165 +    if (!VideoInfo.vfmt && SDL20_GetDesktopDisplayMode(VideoDisplayIndex, &mode) == 0) {
   1.166 +        VideoInfo.vfmt = SDL20_AllocFormat(mode.format);
   1.167 +        VideoInfo.current_w = mode.w;
   1.168 +        VideoInfo.current_h = mode.h;
   1.169          // !!! FIXME
   1.170 -        //info.wm_available = 1;
   1.171 -        //info.video_mem = 1024 * 256;
   1.172 +        //VideoInfo.wm_available = 1;
   1.173 +        //VideoInfo.video_mem = 1024 * 256;
   1.174      }
   1.175 -    return &info;
   1.176 +    return &VideoInfo;
   1.177  }
   1.178  
   1.179  int
   1.180 @@ -599,7 +663,7 @@
   1.181  }
   1.182  
   1.183  SDL_Rect **
   1.184 -SDL_ListModes(const SDL12_PixelFormat * format, Uint32 flags)
   1.185 +SDL_ListModes(const SDL12_PixelFormat *format, Uint32 flags)
   1.186  {
   1.187      int i, nmodes;
   1.188      SDL_Rect **modes;
   1.189 @@ -613,10 +677,10 @@
   1.190      }
   1.191  
   1.192      if (!format) {
   1.193 -        format = SDL_GetVideoInfo()->vfmt;
   1.194 +        format = VideoInfo.vfmt;
   1.195      }
   1.196  
   1.197 -    /* Memory leak, but this is a compatibility function, who cares? */
   1.198 +    /* !!! FIXME: Memory leak */
   1.199      nmodes = 0;
   1.200      modes = NULL;
   1.201      for (i = 0; i < SDL20_GetNumDisplayModes(VideoDisplayIndex); ++i) {
   1.202 @@ -643,11 +707,11 @@
   1.203              continue;
   1.204          }
   1.205  
   1.206 -        modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes));
   1.207 +        modes = SDL20_realloc(modes, (nmodes + 2) * sizeof(*modes));
   1.208          if (!modes) {
   1.209              return NULL;
   1.210          }
   1.211 -        modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
   1.212 +        modes[nmodes] = (SDL_Rect *) SDL20_malloc(sizeof(SDL_Rect));
   1.213          if (!modes[nmodes]) {
   1.214              return NULL;
   1.215          }
   1.216 @@ -663,6 +727,7 @@
   1.217      return modes;
   1.218  }
   1.219  
   1.220 +/* !!! FIXME: don't need a filter, just do this in the SDL_PumpEvents() implementation. */
   1.221  static int
   1.222  SDL_CompatEventFilter(void *userdata, SDL_Event * event)
   1.223  {
   1.224 @@ -672,9 +737,9 @@
   1.225      case SDL_WINDOWEVENT:
   1.226          switch (event->window.event) {
   1.227          case SDL_WINDOWEVENT_EXPOSED:
   1.228 -            if (!SDL_HasEvent(SDL_VIDEOEXPOSE)) {
   1.229 +            if (!SDL20_HasEvent(SDL_VIDEOEXPOSE)) {
   1.230                  fake.type = SDL_VIDEOEXPOSE;
   1.231 -                SDL_PushEvent(&fake);
   1.232 +                SDL20_PushEvent(&fake);
   1.233              }
   1.234              break;
   1.235          case SDL_WINDOWEVENT_RESIZED:
   1.236 @@ -828,11 +893,11 @@
   1.237  ClearVideoSurface()
   1.238  {
   1.239      if (ShadowSurface) {
   1.240 -        SDL_FillRect(ShadowSurface, NULL,
   1.241 -            SDL_MapRGB(ShadowSurface->format, 0, 0, 0));
   1.242 +        SDL20_FillRect(ShadowSurface, NULL,
   1.243 +            SDL20_MapRGB(ShadowSurface->format, 0, 0, 0));
   1.244      }
   1.245 -    SDL_FillRect(WindowSurface, NULL, 0);
   1.246 -    SDL_UpdateWindowSurface(VideoWindow);
   1.247 +    SDL20_FillRect(WindowSurface, NULL, 0);
   1.248 +    SDL20_UpdateWindowSurface(VideoWindow);
   1.249  }
   1.250  
   1.251  static void
   1.252 @@ -851,14 +916,14 @@
   1.253          allow_screensaver = SDL_TRUE;
   1.254      }
   1.255      if (allow_screensaver) {
   1.256 -        SDL_EnableScreenSaver();
   1.257 +        SDL20_EnableScreenSaver();
   1.258      } else {
   1.259 -        SDL_DisableScreenSaver();
   1.260 +        SDL20_DisableScreenSaver();
   1.261      }
   1.262  }
   1.263  
   1.264  static int
   1.265 -SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags)
   1.266 +ResizeVideoMode(int width, int height, int bpp, Uint32 flags)
   1.267  {
   1.268      int w, h;
   1.269  
   1.270 @@ -955,7 +1020,7 @@
   1.271      }
   1.272  
   1.273      /* See if we can simply resize the existing window and surface */
   1.274 -    if (SDL_ResizeVideoMode(width, height, bpp, flags) == 0) {
   1.275 +    if (ResizeVideoMode(width, height, bpp, flags) == 0) {
   1.276          return PublicSurface;
   1.277      }
   1.278  
     2.1 --- a/src/SDL20_syms.h	Thu Mar 07 22:34:19 2013 -0500
     2.2 +++ b/src/SDL20_syms.h	Fri Mar 08 00:10:44 2013 -0500
     2.3 @@ -34,11 +34,15 @@
     2.4  SDL20_SYM_PASSTHROUGH(int,AudioInit,(const char *a),(a),return)
     2.5  SDL20_SYM_PASSTHROUGH(void,AudioQuit,(void),(),)
     2.6  
     2.7 +SDL20_SYM(SDL_PixelFormat *,AllocFormat,(Uint32 a),(a),return)
     2.8 +SDL20_SYM(void,FreeFormat,(SDL_PixelFormat *a),(a),)
     2.9  SDL20_SYM(SDL_Surface *,CreateRGBSurface,(Uint32 a, int b, int c, int d, Uint32 e, Uint32 f, Uint32 g, Uint32 h),(a,b,c,d,e,f,g,h),return)
    2.10  SDL20_SYM(SDL_Surface *,CreateRGBSurfaceFrom,(void *a, int b, int c, int d, int e, Uint32 f, Uint32 g, Uint32 h, Uint32 i),(a,b,c,d,e,f,g,h,i),return)
    2.11  SDL20_SYM(void,SDL_FreeSurface,(SDL_Surface *a),(a),)
    2.12  SDL20_SYM(SDL_Surface*,LoadBMP_RW,(SDL_RWops *a, int b),(a,b),return)
    2.13  SDL20_SYM(int,SaveBMP_RW,(SDL_Surface *a, SDL_RWops *b, int c),(a,b,c),return)
    2.14 +SDL20_SYM_PASSTHROUGH(int,SDL_GL_LoadLibrary,(const char *a),(a),return)
    2.15 +SDL20_SYM_PASSTHROUGH(void *,SDL_GL_GetProcAddress,(const char *a),(a),return)
    2.16  
    2.17  SDL20_SYM_PASSTHROUGH(Uint32,GetThreadID,(SDL_Thread *a),(a),return)
    2.18  SDL20_SYM_PASSTHROUGH(Uint32,ThreadID,(void),(),return)