Fixed SDL_GetVideoInfo()
authorRyan C. Gordon <icculus@icculus.org>
Tue, 02 Apr 2019 14:15:06 -0400
changeset 1179b264590d276
parent 116 911a1e7bf8b7
child 118 80c6b5470095
Fixed SDL_GetVideoInfo()

Now vfmt is binary compatible with SDL 1.2, and this is now calculated earlier
during init.
src/SDL12_compat.c
     1.1 --- a/src/SDL12_compat.c	Fri Mar 22 23:11:59 2019 -0400
     1.2 +++ b/src/SDL12_compat.c	Tue Apr 02 14:15:06 2019 -0400
     1.3 @@ -231,7 +231,7 @@
     1.4      Uint32 blit_fill    :1;
     1.5      Uint32 UnusedBits3  :16;
     1.6      Uint32 video_mem;
     1.7 -    SDL_PixelFormat *vfmt;
     1.8 +    SDL12_PixelFormat *vfmt;
     1.9      int current_w;
    1.10      int current_h;
    1.11  } SDL12_VideoInfo;
    1.12 @@ -719,6 +719,9 @@
    1.13  static VideoModeList *VideoModes = NULL;
    1.14  static int VideoModesCount = 0;
    1.15  static SDL12_VideoInfo VideoInfo12;
    1.16 +static SDL12_Palette VideoInfoPalette12;
    1.17 +static SDL12_PixelFormat VideoInfoVfmt12;
    1.18 +static SDL_PixelFormat *VideoInfoVfmt20 = NULL;
    1.19  static SDL_bool VideoWindowGrabbed = SDL_FALSE;
    1.20  static SDL_bool VideoCursorHidden = SDL_FALSE;
    1.21  static SDL_Window *VideoWindow20 = NULL;
    1.22 @@ -983,6 +986,69 @@
    1.23      return retval;
    1.24  }
    1.25  
    1.26 +static SDL_PixelFormat *
    1.27 +PixelFormat12to20(SDL_PixelFormat *format20, SDL_Palette *palette20, const SDL12_PixelFormat *format12)
    1.28 +{
    1.29 +    if (format12->palette) {
    1.30 +        palette20->ncolors = format12->palette->ncolors;
    1.31 +        palette20->colors = format12->palette->colors;
    1.32 +        palette20->version = 1;
    1.33 +        palette20->refcount = 1;
    1.34 +        format20->palette = palette20;
    1.35 +    } else {
    1.36 +        format20->palette = NULL;
    1.37 +    }
    1.38 +
    1.39 +    format20->format = SDL20_MasksToPixelFormatEnum(format12->BitsPerPixel, format12->Rmask, format12->Gmask, format12->Bmask, format12->Amask);
    1.40 +    format20->BitsPerPixel = format12->BitsPerPixel;
    1.41 +    format20->BytesPerPixel = format12->BytesPerPixel;
    1.42 +    format20->Rmask = format12->Rmask;
    1.43 +    format20->Gmask = format12->Gmask;
    1.44 +    format20->Bmask = format12->Bmask;
    1.45 +    format20->Amask = format12->Amask;
    1.46 +    format20->Rloss = format12->Rloss;
    1.47 +    format20->Gloss = format12->Gloss;
    1.48 +    format20->Bloss = format12->Bloss;
    1.49 +    format20->Aloss = format12->Aloss;
    1.50 +    format20->Rshift = format12->Rshift;
    1.51 +    format20->Gshift = format12->Gshift;
    1.52 +    format20->Bshift = format12->Bshift;
    1.53 +    format20->Ashift = format12->Ashift;
    1.54 +    format20->refcount = 1;
    1.55 +    format20->next = NULL;
    1.56 +    return format20;
    1.57 +}
    1.58 +
    1.59 +static SDL12_PixelFormat *
    1.60 +PixelFormat20to12(SDL12_PixelFormat *format12, SDL12_Palette *palette12, const SDL_PixelFormat *format20)
    1.61 +{
    1.62 +    if (format20->palette) {
    1.63 +        palette12->ncolors = format20->palette->ncolors;
    1.64 +        palette12->colors = format20->palette->colors;
    1.65 +        format12->palette = palette12;
    1.66 +    } else {
    1.67 +        format12->palette = NULL;
    1.68 +    }
    1.69 +
    1.70 +    format12->BitsPerPixel = format20->BitsPerPixel;
    1.71 +    format12->BytesPerPixel = format20->BytesPerPixel;
    1.72 +    format12->Rloss = format20->Rloss;
    1.73 +    format12->Gloss = format20->Gloss;
    1.74 +    format12->Bloss = format20->Bloss;
    1.75 +    format12->Aloss = format20->Aloss;
    1.76 +    format12->Rshift = format20->Rshift;
    1.77 +    format12->Gshift = format20->Gshift;
    1.78 +    format12->Bshift = format20->Bshift;
    1.79 +    format12->Ashift = format20->Ashift;
    1.80 +    format12->Rmask = format20->Rmask;
    1.81 +    format12->Gmask = format20->Gmask;
    1.82 +    format12->Bmask = format20->Bmask;
    1.83 +    format12->Amask = format20->Amask;
    1.84 +    format12->colorkey = 0;  // this is a surface, not pixelformat, properties in SDL2.
    1.85 +    format12->alpha = 255;  // this is a surface, not pixelformat, properties in SDL2.
    1.86 +    return format12;
    1.87 +}
    1.88 +
    1.89  static int
    1.90  GetVideoDisplay()
    1.91  {
    1.92 @@ -1114,12 +1180,19 @@
    1.93  
    1.94      SDL20_StopTextInput();
    1.95  
    1.96 +    SDL_DisplayMode mode;
    1.97 +    if (SDL20_GetDesktopDisplayMode(VideoDisplayIndex, &mode) == 0) {
    1.98 +        VideoInfoVfmt20 = SDL20_AllocFormat(mode.format);
    1.99 +        VideoInfo12.vfmt = PixelFormat20to12(&VideoInfoVfmt12, &VideoInfoPalette12, VideoInfoVfmt20);
   1.100 +        VideoInfo12.current_w = mode.w;
   1.101 +        VideoInfo12.current_h = mode.h;
   1.102 +        VideoInfo12.wm_available = 1;  FIXME("not sure if we can determine this in SDL2...?");
   1.103 +        VideoInfo12.video_mem = 1024 * 256;  /* good enough. */
   1.104 +    }
   1.105 +
   1.106      return 0;
   1.107  }
   1.108  
   1.109 -
   1.110 -
   1.111 -
   1.112  DECLSPEC int SDLCALL
   1.113  SDL_InitSubSystem(Uint32 sdl12flags)
   1.114  {
   1.115 @@ -1236,9 +1309,10 @@
   1.116      }
   1.117      SDL20_free(VideoModes);
   1.118  
   1.119 -    SDL20_FreeFormat(VideoInfo12.vfmt);
   1.120 +    SDL20_FreeFormat(VideoInfoVfmt20);
   1.121      SDL20_zero(VideoInfo12);
   1.122  
   1.123 +    VideoInfoVfmt20 = NULL;
   1.124      EventFilter12 = NULL;
   1.125      EventQueueAvailable = EventQueueHead = EventQueueTail = NULL;
   1.126      CurrentCursor12 = NULL;
   1.127 @@ -2367,40 +2441,6 @@
   1.128      return retval;
   1.129  }
   1.130  
   1.131 -
   1.132 -static SDL_PixelFormat *
   1.133 -PixelFormat12to20(SDL_PixelFormat *format20, SDL_Palette *palette20, const SDL12_PixelFormat *format12)
   1.134 -{
   1.135 -    if (format12->palette) {
   1.136 -        palette20->ncolors = format12->palette->ncolors;
   1.137 -        palette20->colors = format12->palette->colors;
   1.138 -        palette20->version = 1;
   1.139 -        palette20->refcount = 1;
   1.140 -        format20->palette = palette20;
   1.141 -    } else {
   1.142 -        format20->palette = NULL;
   1.143 -    }
   1.144 -
   1.145 -    format20->format = SDL20_MasksToPixelFormatEnum(format12->BitsPerPixel, format12->Rmask, format12->Gmask, format12->Bmask, format12->Amask);
   1.146 -    format20->BitsPerPixel = format12->BitsPerPixel;
   1.147 -    format20->BytesPerPixel = format12->BytesPerPixel;
   1.148 -    format20->Rmask = format12->Rmask;
   1.149 -    format20->Gmask = format12->Gmask;
   1.150 -    format20->Bmask = format12->Bmask;
   1.151 -    format20->Amask = format12->Amask;
   1.152 -    format20->Rloss = format12->Rloss;
   1.153 -    format20->Gloss = format12->Gloss;
   1.154 -    format20->Bloss = format12->Bloss;
   1.155 -    format20->Aloss = format12->Aloss;
   1.156 -    format20->Rshift = format12->Rshift;
   1.157 -    format20->Gshift = format12->Gshift;
   1.158 -    format20->Bshift = format12->Bshift;
   1.159 -    format20->Ashift = format12->Ashift;
   1.160 -    format20->refcount = 1;
   1.161 -    format20->next = NULL;
   1.162 -    return format20;
   1.163 -}
   1.164 -
   1.165  DECLSPEC Uint32 SDLCALL
   1.166  SDL_MapRGB(const SDL12_PixelFormat *format12, Uint8 r, Uint8 g, Uint8 b)
   1.167  {
   1.168 @@ -2440,19 +2480,7 @@
   1.169  DECLSPEC const SDL12_VideoInfo * SDLCALL
   1.170  SDL_GetVideoInfo(void)
   1.171  {
   1.172 -    SDL_DisplayMode mode;
   1.173 -
   1.174 -    FIXME("calculate this in Init12Video(), then this just does: return VideoInfo.vfmt ? &VideoInfo : NULL;");
   1.175 -
   1.176 -    if (!VideoInfo12.vfmt && SDL20_GetDesktopDisplayMode(VideoDisplayIndex, &mode) == 0) {
   1.177 -        VideoInfo12.vfmt = SDL20_AllocFormat(mode.format);
   1.178 -        VideoInfo12.current_w = mode.w;
   1.179 -        VideoInfo12.current_h = mode.h;
   1.180 -        FIXME("vidinfo details commented out");
   1.181 -        //VideoInfo12.wm_available = 1;
   1.182 -        //VideoInfo12.video_mem = 1024 * 256;
   1.183 -    }
   1.184 -    return &VideoInfo12;
   1.185 +    return VideoInfo12.vfmt ? &VideoInfo12 : NULL;
   1.186  }
   1.187  
   1.188  DECLSPEC int SDLCALL
   1.189 @@ -2505,10 +2533,10 @@
   1.190          return (SDL12_Rect **) (-1);  /* any resolution is fine. */
   1.191      }
   1.192  
   1.193 -    if (format12) {
   1.194 +    if (format12 && (format12 != VideoInfo12.vfmt)) {
   1.195          fmt = SDL20_MasksToPixelFormatEnum(format12->BitsPerPixel, format12->Rmask, format12->Gmask, format12->Bmask, format12->Amask);
   1.196      } else {
   1.197 -        fmt = VideoInfo12.vfmt->format;
   1.198 +        fmt = VideoInfoVfmt20->format;
   1.199      }
   1.200  
   1.201      for (i = 0; i < VideoModesCount; i++) {