src/SDL12_compat.c
changeset 73 040f36454e95
parent 72 d20d9d70694b
child 74 4e3e77f78520
     1.1 --- a/src/SDL12_compat.c	Tue Feb 19 16:40:38 2019 -0500
     1.2 +++ b/src/SDL12_compat.c	Tue Feb 19 16:40:20 2019 -0500
     1.3 @@ -142,6 +142,14 @@
     1.4  #define SDL12_INIT_EVENTTHREAD 0x01000000
     1.5  #define SDL12_INIT_EVERYTHING  0x0000FFFF
     1.6  
     1.7 +typedef struct SDL12_Rect
     1.8 +{
     1.9 +    Sint16 x;
    1.10 +    Sint16 y;
    1.11 +    Uint16 w;
    1.12 +    Uint16 h;
    1.13 +} SDL12_Rect;
    1.14 +
    1.15  typedef struct SDL12_Palette
    1.16  {
    1.17      int       ncolors;
    1.18 @@ -179,7 +187,7 @@
    1.19      void *pixels;
    1.20      int offset;
    1.21      SDL_Surface *surface20; /* the real SDL 1.2 has an opaque pointer to a platform-specific thing here named "hwdata". */
    1.22 -    SDL_Rect clip_rect;
    1.23 +    SDL12_Rect clip_rect;
    1.24      Uint32 unused1;
    1.25      Uint32 locked;
    1.26      void *blitmap;
    1.27 @@ -392,7 +400,7 @@
    1.28  
    1.29  typedef struct
    1.30  {
    1.31 -    SDL_Rect area;
    1.32 +    SDL12_Rect area;
    1.33      Sint16 hot_x;
    1.34      Sint16 hot_y;
    1.35      Uint8 *data;
    1.36 @@ -427,8 +435,8 @@
    1.37  typedef struct
    1.38  {
    1.39      Uint32 format;
    1.40 -    SDL_Rect *modeslist;
    1.41 -    SDL_Rect **modes;  /* ptrs to each item in modeslist, for SDL_ListModes() */
    1.42 +    SDL12_Rect *modeslist12;
    1.43 +    SDL12_Rect **modes12;  /* ptrs to each item in modeslist, for SDL_ListModes() */
    1.44  } VideoModeList;
    1.45  
    1.46  // !!! FIXME: go through all of these.
    1.47 @@ -619,7 +627,7 @@
    1.48  
    1.49          if (!vmode || (mode.format != vmode->format)) {  // SDL20_GetDisplayMode() sorts on bpp first. We know when to change arrays.
    1.50              if (VideoModesCount > 0) {
    1.51 -                VideoModes[VideoModesCount-1].modes[num_modes] = NULL;
    1.52 +                VideoModes[VideoModesCount-1].modes12[num_modes] = NULL;
    1.53              }
    1.54              ptr = (VideoModeList *) SDL20_realloc(VideoModes, sizeof (VideoModeList) * (VideoModesCount+1));
    1.55              if (!ptr) {
    1.56 @@ -628,15 +636,15 @@
    1.57              VideoModes = (VideoModeList *) ptr;
    1.58              vmode = &VideoModes[VideoModesCount];
    1.59              vmode->format = mode.format;
    1.60 -            vmode->modeslist = NULL;
    1.61 -            vmode->modes = NULL;
    1.62 +            vmode->modeslist12 = NULL;
    1.63 +            vmode->modes12 = NULL;
    1.64              VideoModesCount++;
    1.65              num_modes = 0;
    1.66          }
    1.67  
    1.68          /* make sure we don't have this one already (with a different refresh rate, etc). */
    1.69          for (j = 0; j < num_modes; j++) {
    1.70 -            if ((vmode->modeslist[j].w == mode.w) && (vmode->modeslist[j].h == mode.h)) {
    1.71 +            if ((vmode->modeslist12[j].w == mode.w) && (vmode->modeslist12[j].h == mode.h)) {
    1.72                  break;
    1.73              }
    1.74          }
    1.75 @@ -645,30 +653,32 @@
    1.76              continue;  /* already have this one. */
    1.77          }
    1.78  
    1.79 -        ptr = SDL20_realloc(vmode->modes, sizeof (SDL_Rect *) * (num_modes + 2));
    1.80 +        FIXME("Make sure mode dimensions fit in 16-bits for SDL12_Rect");
    1.81 +
    1.82 +        ptr = SDL20_realloc(vmode->modes12, sizeof (SDL12_Rect *) * (num_modes + 2));
    1.83          if (ptr == NULL) {
    1.84              return SDL20_OutOfMemory();
    1.85          }
    1.86 -        vmode->modes = (SDL_Rect **) ptr;
    1.87 -
    1.88 -        ptr = SDL20_realloc(vmode->modeslist, sizeof (SDL_Rect) * (num_modes + 1));
    1.89 +        vmode->modes12 = (SDL12_Rect **) ptr;
    1.90 +
    1.91 +        ptr = SDL20_realloc(vmode->modeslist12, sizeof (SDL12_Rect) * (num_modes + 1));
    1.92          if (ptr == NULL) {
    1.93              return SDL20_OutOfMemory();
    1.94          }
    1.95 -        vmode->modeslist = (SDL_Rect *) ptr;
    1.96 -
    1.97 -        vmode->modeslist[num_modes].x = 0;
    1.98 -        vmode->modeslist[num_modes].y = 0;
    1.99 -        vmode->modeslist[num_modes].w = mode.w;
   1.100 -        vmode->modeslist[num_modes].h = mode.h;
   1.101 -
   1.102 -        vmode->modes[num_modes] = &vmode->modeslist[num_modes];
   1.103 +        vmode->modeslist12 = (SDL12_Rect *) ptr;
   1.104 +
   1.105 +        vmode->modeslist12[num_modes].x = 0;
   1.106 +        vmode->modeslist12[num_modes].y = 0;
   1.107 +        vmode->modeslist12[num_modes].w = mode.w;
   1.108 +        vmode->modeslist12[num_modes].h = mode.h;
   1.109 +
   1.110 +        vmode->modes12[num_modes] = &vmode->modeslist12[num_modes];
   1.111  
   1.112          num_modes++;
   1.113      }
   1.114  
   1.115      if (VideoModesCount > 0) {
   1.116 -        VideoModes[VideoModesCount-1].modes[num_modes] = NULL;
   1.117 +        VideoModes[VideoModesCount-1].modes12[num_modes] = NULL;
   1.118      }
   1.119  
   1.120      return 0;
   1.121 @@ -813,8 +823,8 @@
   1.122      int i;
   1.123  
   1.124      for (i = 0; i < VideoModesCount; i++) {
   1.125 -        SDL20_free(VideoModes[i].modeslist);
   1.126 -        SDL20_free(VideoModes[i].modes);
   1.127 +        SDL20_free(VideoModes[i].modeslist12);
   1.128 +        SDL20_free(VideoModes[i].modes12);
   1.129      }
   1.130      SDL20_free(VideoModes);
   1.131  
   1.132 @@ -1268,6 +1278,26 @@
   1.133  }
   1.134  
   1.135  
   1.136 +static SDL12_Rect *
   1.137 +Rect20to12(const SDL_Rect *rect20, SDL12_Rect *rect12)
   1.138 +{
   1.139 +    rect12->x = (Sint16) rect20->x;
   1.140 +    rect12->y = (Sint16) rect20->y;
   1.141 +    rect12->w = (Uint16) rect20->w;
   1.142 +    rect12->h = (Uint16) rect20->h;
   1.143 +    return rect12;
   1.144 +}
   1.145 +
   1.146 +static SDL_Rect *
   1.147 +Rect12to20(const SDL12_Rect *rect12, SDL_Rect *rect20)
   1.148 +{
   1.149 +    rect20->x = (int) rect12->x;
   1.150 +    rect20->y = (int) rect12->y;
   1.151 +    rect20->w = (int) rect12->w;
   1.152 +    rect20->h = (int) rect12->h;
   1.153 +    return rect20;
   1.154 +}
   1.155 +
   1.156  static SDL12_Surface *
   1.157  Surface20to12(SDL_Surface *surface20)
   1.158  {
   1.159 @@ -1333,7 +1363,7 @@
   1.160      surface12->pixels = surface20->pixels;
   1.161      surface12->offset = 0;
   1.162      surface12->surface20 = surface20;
   1.163 -    SDL20_memcpy(&surface12->clip_rect, &surface20->clip_rect, sizeof (SDL_Rect));
   1.164 +    Rect20to12(&surface20->clip_rect, &surface12->clip_rect);
   1.165      surface12->refcount = surface20->refcount;
   1.166  
   1.167      return surface12;
   1.168 @@ -1387,33 +1417,38 @@
   1.169  }
   1.170  
   1.171  DECLSPEC void SDLCALL
   1.172 -SDL_GetClipRect(SDL12_Surface *surface12, SDL_Rect *rect)
   1.173 +SDL_GetClipRect(SDL12_Surface *surface12, SDL12_Rect *rect)
   1.174  {
   1.175 -    if (surface12 && rect)
   1.176 -	    SDL_memcpy(rect, &surface12->clip_rect, sizeof (SDL_Rect));
   1.177 +    if (surface12 && rect) {
   1.178 +        SDL_memcpy(rect, &surface12->clip_rect, sizeof (SDL12_Rect));
   1.179 +    }
   1.180  }
   1.181  
   1.182  DECLSPEC SDL_bool SDLCALL
   1.183 -SDL_SetClipRect(SDL12_Surface *surface12, const SDL_Rect *rect)
   1.184 +SDL_SetClipRect(SDL12_Surface *surface12, const SDL12_Rect *rect12)
   1.185  {
   1.186      SDL_bool retval = SDL_FALSE;
   1.187      if (surface12)
   1.188      {
   1.189 -        retval = SDL20_SetClipRect(surface12->surface20, rect);
   1.190 -        SDL20_GetClipRect(surface12->surface20, &surface12->clip_rect);
   1.191 +        SDL_Rect rect20;
   1.192 +        retval = SDL20_SetClipRect(surface12->surface20, rect12 ? Rect12to20(rect12, &rect20) : NULL);
   1.193 +        SDL20_GetClipRect(surface12->surface20, &rect20);
   1.194 +        Rect20to12(&rect20, &surface12->clip_rect);
   1.195      }
   1.196      return retval;
   1.197  }
   1.198  
   1.199  DECLSPEC int SDLCALL
   1.200 -SDL_FillRect(SDL12_Surface *dst, SDL_Rect *dstrect, Uint32 color)
   1.201 +SDL_FillRect(SDL12_Surface *dst, SDL12_Rect *dstrect12, Uint32 color)
   1.202  {
   1.203 -    const int retval = SDL20_FillRect(dst->surface20, dstrect, color);
   1.204 +    SDL_Rect dstrect20;
   1.205 +    const int retval = SDL20_FillRect(dst->surface20, dstrect12 ? Rect12to20(dstrect12, &dstrect20) : NULL, color);
   1.206      if (retval != -1)
   1.207      {
   1.208 -        if (dstrect) {  /* 1.2 stores the clip intersection in dstrect */
   1.209 -            const SDL_Rect orig_dstrect = *dstrect;
   1.210 -            SDL20_IntersectRect(&orig_dstrect, &dst->clip_rect, dstrect);
   1.211 +        if (dstrect12) {  /* 1.2 stores the clip intersection in dstrect */
   1.212 +            SDL_Rect intersected20;
   1.213 +            SDL20_IntersectRect(&dstrect20, &dst->surface20->clip_rect, &intersected20);
   1.214 +            Rect20to12(&intersected20, dstrect12);
   1.215          }
   1.216      }
   1.217      return retval;
   1.218 @@ -1533,7 +1568,7 @@
   1.219      return actual_bpp;
   1.220  }
   1.221  
   1.222 -DECLSPEC SDL_Rect ** SDLCALL
   1.223 +DECLSPEC SDL12_Rect ** SDLCALL
   1.224  SDL_ListModes(const SDL12_PixelFormat *format12, Uint32 flags)
   1.225  {
   1.226      Uint32 fmt;
   1.227 @@ -1549,7 +1584,7 @@
   1.228      }
   1.229  
   1.230      if (!(flags & SDL12_FULLSCREEN)) {
   1.231 -        return (SDL_Rect **) (-1);  /* any resolution is fine. */
   1.232 +        return (SDL12_Rect **) (-1);  /* any resolution is fine. */
   1.233      }
   1.234  
   1.235      if (format12) {
   1.236 @@ -1561,7 +1596,7 @@
   1.237      for (i = 0; i < VideoModesCount; i++) {
   1.238          VideoModeList *modes = &VideoModes[i];
   1.239          if (modes->format == fmt) {
   1.240 -            return modes->modes;
   1.241 +            return modes->modes12;
   1.242          }
   1.243      }
   1.244  
   1.245 @@ -1955,15 +1990,43 @@
   1.246  }
   1.247  
   1.248  DECLSPEC int SDLCALL
   1.249 -SDL_UpperBlit(SDL12_Surface *src, SDL_Rect *srcrect, SDL12_Surface *dst, SDL_Rect *dstrect)
   1.250 +SDL_UpperBlit(SDL12_Surface *src, SDL12_Rect *srcrect12, SDL12_Surface *dst, SDL12_Rect *dstrect12)
   1.251  {
   1.252 -    return SDL20_UpperBlit(src->surface20, srcrect, dst->surface20, dstrect);
   1.253 +    SDL_Rect srcrect20, dstrect20;
   1.254 +    const int retval = SDL20_UpperBlit(src->surface20,
   1.255 +                                       srcrect12 ? Rect12to20(srcrect12, &srcrect20) : NULL,
   1.256 +                                       dst->surface20,
   1.257 +                                       dstrect12 ? Rect12to20(dstrect12, &dstrect20) : NULL);
   1.258 +
   1.259 +    if (srcrect12) {
   1.260 +        Rect20to12(&srcrect20, srcrect12);
   1.261 +    }
   1.262 +
   1.263 +    if (srcrect12) {
   1.264 +        Rect20to12(&dstrect20, dstrect12);
   1.265 +    }
   1.266 +
   1.267 +    return retval;
   1.268  }
   1.269  
   1.270  DECLSPEC int SDLCALL
   1.271 -SDL_LowerBlit(SDL12_Surface *src, SDL_Rect *srcrect, SDL12_Surface *dst, SDL_Rect *dstrect)
   1.272 +SDL_LowerBlit(SDL12_Surface *src, SDL12_Rect *srcrect12, SDL12_Surface *dst, SDL12_Rect *dstrect12)
   1.273  {
   1.274 -    return SDL20_LowerBlit(src->surface20, srcrect, dst->surface20, dstrect);
   1.275 +    SDL_Rect srcrect20, dstrect20;
   1.276 +    const int retval = SDL20_LowerBlit(src->surface20,
   1.277 +                                       srcrect12 ? Rect12to20(srcrect12, &srcrect20) : NULL,
   1.278 +                                       dst->surface20,
   1.279 +                                       dstrect12 ? Rect12to20(dstrect12, &dstrect20) : NULL);
   1.280 +
   1.281 +    if (srcrect12) {
   1.282 +        Rect20to12(&srcrect20, srcrect12);
   1.283 +    }
   1.284 +
   1.285 +    if (srcrect12) {
   1.286 +        Rect20to12(&dstrect20, dstrect12);
   1.287 +    }
   1.288 +
   1.289 +    return retval;
   1.290  }
   1.291  
   1.292  DECLSPEC int SDLCALL
   1.293 @@ -2035,7 +2098,7 @@
   1.294  }
   1.295  
   1.296  DECLSPEC void SDLCALL
   1.297 -SDL_UpdateRects(SDL12_Surface *surface12, int numrects, SDL_Rect *rects)
   1.298 +SDL_UpdateRects(SDL12_Surface *surface12, int numrects, SDL12_Rect *rects12)
   1.299  {
   1.300      /* strangely, SDL 1.2 doesn't check if surface12 is NULL before touching it */
   1.301      /* (UpdateRect, singular, does...) */
   1.302 @@ -2051,12 +2114,12 @@
   1.303  SDL_UpdateRect(SDL12_Surface *screen12, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
   1.304  {
   1.305      if (screen12) {
   1.306 -        SDL_Rect rect;
   1.307 -        rect.x = (int) x;
   1.308 -        rect.y = (int) y;
   1.309 -        rect.w = (int) (w ? w : screen12->w);
   1.310 -        rect.h = (int) (h ? h : screen12->h);
   1.311 -        SDL_UpdateRects(screen12, 1, &rect);
   1.312 +        SDL12_Rect rect12;
   1.313 +        rect12.x = (Sint16) x;
   1.314 +        rect12.y = (Sint16) y;
   1.315 +        rect12.w = (Uint16) (w ? w : screen12->w);
   1.316 +        rect12.h = (Uint16) (h ? h : screen12->h);
   1.317 +        SDL_UpdateRects(screen12, 1, &rect12);
   1.318      }
   1.319  }
   1.320  
   1.321 @@ -2209,7 +2272,7 @@
   1.322  }
   1.323  
   1.324  DECLSPEC int SDLCALL
   1.325 -SDL_DisplayYUVOverlay(SDL12_Overlay * overlay, SDL_Rect * dstrect)
   1.326 +SDL_DisplayYUVOverlay(SDL12_Overlay * overlay, SDL12_Rect * dstrect12)
   1.327  {
   1.328      FIXME("write me");
   1.329      return SDL20_Unsupported();