Added SDL_DrawRect(), SDL_DrawRects(), SDL_BlendRect() and SDL_BlendRects()
authorSam Lantinga <slouken@libsdl.org>
Fri, 18 Dec 2009 07:41:59 +0000
changeset 3594c8bed77b0386
parent 3593 b931bcfd94a0
child 3595 b7c6828d4039
Added SDL_DrawRect(), SDL_DrawRects(), SDL_BlendRect() and SDL_BlendRects()
Fixed line drawing so when blending a sequence of lines there are no overlapping pixels drawn.
src/video/SDL_blendfillrect.c
src/video/SDL_blendline.c
src/video/SDL_blendrect.c
src/video/SDL_draw.h
src/video/SDL_drawline.c
src/video/SDL_drawrect.c
     1.1 --- a/src/video/SDL_blendfillrect.c	Fri Dec 18 07:03:09 2009 +0000
     1.2 +++ b/src/video/SDL_blendfillrect.c	Fri Dec 18 07:41:59 2009 +0000
     1.3 @@ -203,11 +203,6 @@
     1.4          return -1;
     1.5      }
     1.6  
     1.7 -    if (blendMode < SDL_BLENDMODE_BLEND) {
     1.8 -        Uint32 color = SDL_MapRGBA(dst->format, r, g, b, a);
     1.9 -        return SDL_FillRect(dst, rect, color);
    1.10 -    }
    1.11 -
    1.12      /* This function doesn't work on surfaces < 8 bpp */
    1.13      if (dst->format->BitsPerPixel < 8) {
    1.14          SDL_SetError("SDL_BlendFillRect(): Unsupported surface format");
    1.15 @@ -281,11 +276,6 @@
    1.16          return -1;
    1.17      }
    1.18  
    1.19 -    if (blendMode < SDL_BLENDMODE_BLEND) {
    1.20 -        Uint32 color = SDL_MapRGBA(dst->format, r, g, b, a);
    1.21 -        return SDL_FillRects(dst, rects, color);
    1.22 -    }
    1.23 -
    1.24      /* This function doesn't work on surfaces < 8 bpp */
    1.25      if (dst->format->BitsPerPixel < 8) {
    1.26          SDL_SetError("SDL_BlendFillRects(): Unsupported surface format");
     2.1 --- a/src/video/SDL_blendline.c	Fri Dec 18 07:03:09 2009 +0000
     2.2 +++ b/src/video/SDL_blendline.c	Fri Dec 18 07:41:59 2009 +0000
     2.3 @@ -25,22 +25,23 @@
     2.4  
     2.5  static int
     2.6  SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
     2.7 -                     int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
     2.8 +                     int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
     2.9 +                     SDL_bool draw_end)
    2.10  {
    2.11      unsigned inva = 0xff - a;
    2.12  
    2.13      switch (blendMode) {
    2.14      case SDL_BLENDMODE_BLEND:
    2.15 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB555);
    2.16 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB555, draw_end);
    2.17          break;
    2.18      case SDL_BLENDMODE_ADD:
    2.19 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB555);
    2.20 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB555, draw_end);
    2.21          break;
    2.22      case SDL_BLENDMODE_MOD:
    2.23 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB555);
    2.24 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB555, draw_end);
    2.25          break;
    2.26      default:
    2.27 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB555);
    2.28 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB555, draw_end);
    2.29          break;
    2.30      }
    2.31      return 0;
    2.32 @@ -48,22 +49,23 @@
    2.33  
    2.34  static int
    2.35  SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
    2.36 -                     int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
    2.37 +                     int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
    2.38 +                     SDL_bool draw_end)
    2.39  {
    2.40      unsigned inva = 0xff - a;
    2.41  
    2.42      switch (blendMode) {
    2.43      case SDL_BLENDMODE_BLEND:
    2.44 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB565);
    2.45 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB565, draw_end);
    2.46          break;
    2.47      case SDL_BLENDMODE_ADD:
    2.48 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB565);
    2.49 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB565, draw_end);
    2.50          break;
    2.51      case SDL_BLENDMODE_MOD:
    2.52 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB565);
    2.53 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB565, draw_end);
    2.54          break;
    2.55      default:
    2.56 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB565);
    2.57 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB565, draw_end);
    2.58          break;
    2.59      }
    2.60      return 0;
    2.61 @@ -71,22 +73,23 @@
    2.62  
    2.63  static int
    2.64  SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
    2.65 -                     int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
    2.66 +                     int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
    2.67 +                     SDL_bool draw_end)
    2.68  {
    2.69      unsigned inva = 0xff - a;
    2.70  
    2.71      switch (blendMode) {
    2.72      case SDL_BLENDMODE_BLEND:
    2.73 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB888);
    2.74 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_RGB888, draw_end);
    2.75          break;
    2.76      case SDL_BLENDMODE_ADD:
    2.77 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB888);
    2.78 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_RGB888, draw_end);
    2.79          break;
    2.80      case SDL_BLENDMODE_MOD:
    2.81 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB888);
    2.82 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_RGB888, draw_end);
    2.83          break;
    2.84      default:
    2.85 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB888);
    2.86 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_RGB888, draw_end);
    2.87          break;
    2.88      }
    2.89      return 0;
    2.90 @@ -94,22 +97,23 @@
    2.91  
    2.92  static int
    2.93  SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
    2.94 -                       int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
    2.95 +                       int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
    2.96 +                       SDL_bool draw_end)
    2.97  {
    2.98      unsigned inva = 0xff - a;
    2.99  
   2.100      switch (blendMode) {
   2.101      case SDL_BLENDMODE_BLEND:
   2.102 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_ARGB8888);
   2.103 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_BLEND_ARGB8888, draw_end);
   2.104          break;
   2.105      case SDL_BLENDMODE_ADD:
   2.106 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_ARGB8888);
   2.107 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ADD_ARGB8888, draw_end);
   2.108          break;
   2.109      case SDL_BLENDMODE_MOD:
   2.110 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_ARGB8888);
   2.111 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_MOD_ARGB8888, draw_end);
   2.112          break;
   2.113      default:
   2.114 -        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ARGB8888);
   2.115 +        DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY_ARGB8888, draw_end);
   2.116          break;
   2.117      }
   2.118      return 0;
   2.119 @@ -117,7 +121,8 @@
   2.120  
   2.121  static int
   2.122  SDL_BlendLine_RGB(SDL_Surface * dst, int x1, int y1, int x2, int y2,
   2.123 -                  int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
   2.124 +                  int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
   2.125 +                  SDL_bool draw_end)
   2.126  {
   2.127      SDL_PixelFormat *fmt = dst->format;
   2.128      unsigned inva = 0xff - a;
   2.129 @@ -126,32 +131,32 @@
   2.130      case 2:
   2.131          switch (blendMode) {
   2.132          case SDL_BLENDMODE_BLEND:
   2.133 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_BLEND_RGB);
   2.134 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_BLEND_RGB, draw_end);
   2.135              break;
   2.136          case SDL_BLENDMODE_ADD:
   2.137 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_ADD_RGB);
   2.138 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_ADD_RGB, draw_end);
   2.139              break;
   2.140          case SDL_BLENDMODE_MOD:
   2.141 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_MOD_RGB);
   2.142 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_MOD_RGB, draw_end);
   2.143              break;
   2.144          default:
   2.145 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_RGB);
   2.146 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY2_RGB, draw_end);
   2.147              break;
   2.148          }
   2.149          return 0;
   2.150      case 4:
   2.151          switch (blendMode) {
   2.152          case SDL_BLENDMODE_BLEND:
   2.153 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGB);
   2.154 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGB, draw_end);
   2.155              break;
   2.156          case SDL_BLENDMODE_ADD:
   2.157 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGB);
   2.158 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGB, draw_end);
   2.159              break;
   2.160          case SDL_BLENDMODE_MOD:
   2.161 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGB);
   2.162 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGB, draw_end);
   2.163              break;
   2.164          default:
   2.165 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGB);
   2.166 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGB, draw_end);
   2.167              break;
   2.168          }
   2.169          return 0;
   2.170 @@ -163,7 +168,8 @@
   2.171  
   2.172  static int
   2.173  SDL_BlendLine_RGBA(SDL_Surface * dst, int x1, int y1, int x2, int y2,
   2.174 -                   int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
   2.175 +                   int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
   2.176 +                   SDL_bool draw_end)
   2.177  {
   2.178      SDL_PixelFormat *fmt = dst->format;
   2.179      unsigned inva = 0xff - a;
   2.180 @@ -172,16 +178,16 @@
   2.181      case 4:
   2.182          switch (blendMode) {
   2.183          case SDL_BLENDMODE_BLEND:
   2.184 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGBA);
   2.185 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_BLEND_RGBA, draw_end);
   2.186              break;
   2.187          case SDL_BLENDMODE_ADD:
   2.188 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGBA);
   2.189 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_ADD_RGBA, draw_end);
   2.190              break;
   2.191          case SDL_BLENDMODE_MOD:
   2.192 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGBA);
   2.193 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_MOD_RGBA, draw_end);
   2.194              break;
   2.195          default:
   2.196 -            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGBA);
   2.197 +            DRAWLINE(x1, y1, x2, y2, DRAW_SETPIXELXY4_RGBA, draw_end);
   2.198              break;
   2.199          }
   2.200          return 0;
   2.201 @@ -218,14 +224,14 @@
   2.202          switch (dst->format->Rmask) {
   2.203          case 0x7C00:
   2.204              return SDL_BlendLine_RGB555(dst, x1, y1, x2, y2, blendMode, r, g,
   2.205 -                                        b, a);
   2.206 +                                        b, a, SDL_TRUE);
   2.207          }
   2.208          break;
   2.209      case 16:
   2.210          switch (dst->format->Rmask) {
   2.211          case 0xF800:
   2.212              return SDL_BlendLine_RGB565(dst, x1, y1, x2, y2, blendMode, r, g,
   2.213 -                                        b, a);
   2.214 +                                        b, a, SDL_TRUE);
   2.215          }
   2.216          break;
   2.217      case 32:
   2.218 @@ -233,10 +239,10 @@
   2.219          case 0x00FF0000:
   2.220              if (!dst->format->Amask) {
   2.221                  return SDL_BlendLine_RGB888(dst, x1, y1, x2, y2, blendMode, r,
   2.222 -                                            g, b, a);
   2.223 +                                            g, b, a, SDL_TRUE);
   2.224              } else {
   2.225                  return SDL_BlendLine_ARGB8888(dst, x1, y1, x2, y2, blendMode,
   2.226 -                                              r, g, b, a);
   2.227 +                                              r, g, b, a, SDL_TRUE);
   2.228              }
   2.229              break;
   2.230          }
   2.231 @@ -246,9 +252,11 @@
   2.232      }
   2.233  
   2.234      if (!dst->format->Amask) {
   2.235 -        return SDL_BlendLine_RGB(dst, x1, y1, x2, y2, blendMode, r, g, b, a);
   2.236 +        return SDL_BlendLine_RGB(dst, x1, y1, x2, y2, blendMode,
   2.237 +                                 r, g, b, a, SDL_TRUE);
   2.238      } else {
   2.239 -        return SDL_BlendLine_RGBA(dst, x1, y1, x2, y2, blendMode, r, g, b, a);
   2.240 +        return SDL_BlendLine_RGBA(dst, x1, y1, x2, y2, blendMode,
   2.241 +                                  r, g, b, a, SDL_TRUE);
   2.242      }
   2.243  }
   2.244  
   2.245 @@ -260,7 +268,8 @@
   2.246      int x1, y1;
   2.247      int x2, y2;
   2.248      int (*func)(SDL_Surface * dst, int x1, int y1, int x2, int y2,
   2.249 -                int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL;
   2.250 +                int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a,
   2.251 +                SDL_bool draw_end) = NULL;
   2.252      int status = 0;
   2.253  
   2.254      if (!dst) {
   2.255 @@ -328,7 +337,10 @@
   2.256              continue;
   2.257          }
   2.258  
   2.259 -        status = func(dst, x1, y1, x2, y2, blendMode, r, g, b, a);
   2.260 +        status = func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_FALSE);
   2.261 +    }
   2.262 +    if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
   2.263 +        SDL_BlendPoint(dst, points[count-1].x, points[count-1].y, r, g, b, a);
   2.264      }
   2.265      return status;
   2.266  }
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/video/SDL_blendrect.c	Fri Dec 18 07:41:59 2009 +0000
     3.3 @@ -0,0 +1,75 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997-2009 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +#include "SDL_config.h"
    3.26 +
    3.27 +#include "SDL_video.h"
    3.28 +
    3.29 +
    3.30 +int
    3.31 +SDL_BlendRect(SDL_Surface * dst, const SDL_Rect * rect,
    3.32 +              int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
    3.33 +{
    3.34 +    SDL_Rect full_rect;
    3.35 +    SDL_Point points[5];
    3.36 +
    3.37 +    if (!dst) {
    3.38 +        SDL_SetError("Passed NULL destination surface");
    3.39 +        return -1;
    3.40 +    }
    3.41 +
    3.42 +    /* If 'rect' == NULL, then outline the whole surface */
    3.43 +    if (!rect) {
    3.44 +        full_rect.x = 0;
    3.45 +        full_rect.y = 0;
    3.46 +        full_rect.w = dst->w;
    3.47 +        full_rect.h = dst->h;
    3.48 +        rect = &full_rect;
    3.49 +    }
    3.50 +
    3.51 +    points[0].x = rect->x;
    3.52 +    points[0].y = rect->y;
    3.53 +    points[1].x = rect->x+rect->w-1;
    3.54 +    points[1].y = rect->y;
    3.55 +    points[2].x = rect->x+rect->w-1;
    3.56 +    points[2].y = rect->y+rect->h-1;
    3.57 +    points[3].x = rect->x;
    3.58 +    points[3].y = rect->y+rect->h-1;
    3.59 +    points[4].x = rect->x;
    3.60 +    points[4].y = rect->y;
    3.61 +    return SDL_BlendLines(dst, points, 5, blendMode, r, g, b, a);
    3.62 +}
    3.63 +
    3.64 +int
    3.65 +SDL_BlendRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
    3.66 +               int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
    3.67 +{
    3.68 +    int i;
    3.69 +
    3.70 +    for (i = 0; i < count; ++i) {
    3.71 +        if (SDL_BlendRect(dst, rects[i], blendMode, r, g, b, a) < 0) {
    3.72 +            return -1;
    3.73 +        }
    3.74 +    }
    3.75 +    return 0;
    3.76 +}
    3.77 +
    3.78 +/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/SDL_draw.h	Fri Dec 18 07:03:09 2009 +0000
     4.2 +++ b/src/video/SDL_draw.h	Fri Dec 18 07:41:59 2009 +0000
     4.3 @@ -283,7 +283,7 @@
     4.4  
     4.5  #define ABS(_x) ((_x) < 0 ? -(_x) : (_x))
     4.6  
     4.7 -#define BRESENHAM(x1, y1, x2, y2, op) \
     4.8 +#define BRESENHAM(x1, y1, x2, y2, op, draw_end) \
     4.9  { \
    4.10      int i, deltax, deltay, numpixels; \
    4.11      int d, dinc1, dinc2; \
    4.12 @@ -325,6 +325,9 @@
    4.13      x = x1; \
    4.14      y = y1; \
    4.15   \
    4.16 +    if (!draw_end) { \
    4.17 +        --numpixels; \
    4.18 +    } \
    4.19      for (i = 0; i < numpixels; ++i) { \
    4.20          op(x, y); \
    4.21          if (d < 0) { \
    4.22 @@ -338,10 +341,11 @@
    4.23          } \
    4.24      } \
    4.25  }
    4.26 -#define DRAWLINE(x0, y0, x1, y1, op)	BRESENHAM(x0, y0, x1, y1, op)
    4.27 +#define DRAWLINE    BRESENHAM
    4.28  
    4.29  /*
    4.30   * Define draw rect macro
    4.31 + * (not tested, this level of optimization not needed ... yet?)
    4.32   */
    4.33  #define DRAWRECT(type, op) \
    4.34  do { \
     5.1 --- a/src/video/SDL_drawline.c	Fri Dec 18 07:03:09 2009 +0000
     5.2 +++ b/src/video/SDL_drawline.c	Fri Dec 18 07:41:59 2009 +0000
     5.3 @@ -46,16 +46,16 @@
     5.4  
     5.5      switch (dst->format->BytesPerPixel) {
     5.6      case 1:
     5.7 -        DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1);
     5.8 +        DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1, SDL_TRUE);
     5.9          break;
    5.10      case 2:
    5.11 -        DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2);
    5.12 +        DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2, SDL_TRUE);
    5.13          break;
    5.14      case 3:
    5.15          SDL_Unsupported();
    5.16          return -1;
    5.17      case 4:
    5.18 -        DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4);
    5.19 +        DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4, SDL_TRUE);
    5.20          break;
    5.21      }
    5.22      return 0;
    5.23 @@ -96,16 +96,16 @@
    5.24  
    5.25          switch (dst->format->BytesPerPixel) {
    5.26          case 1:
    5.27 -            DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1);
    5.28 +            DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1, SDL_TRUE);
    5.29              break;
    5.30          case 2:
    5.31 -            DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2);
    5.32 +            DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2, SDL_TRUE);
    5.33              break;
    5.34          case 3:
    5.35              SDL_Unsupported();
    5.36              return -1;
    5.37          case 4:
    5.38 -            DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4);
    5.39 +            DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4, SDL_TRUE);
    5.40              break;
    5.41          }
    5.42      }
     6.1 --- a/src/video/SDL_drawrect.c	Fri Dec 18 07:03:09 2009 +0000
     6.2 +++ b/src/video/SDL_drawrect.c	Fri Dec 18 07:41:59 2009 +0000
     6.3 @@ -22,398 +22,39 @@
     6.4  #include "SDL_config.h"
     6.5  
     6.6  #include "SDL_video.h"
     6.7 -#include "SDL_blit.h"
     6.8  
     6.9  
    6.10 -#ifdef __SSE__
    6.11 -/* *INDENT-OFF* */
    6.12 -
    6.13 -#ifdef _MSC_VER
    6.14 -#define SSE_BEGIN \
    6.15 -    __m128 c128; \
    6.16 -    c128.m128_u32[0] = color; \
    6.17 -    c128.m128_u32[1] = color; \
    6.18 -    c128.m128_u32[2] = color; \
    6.19 -    c128.m128_u32[3] = color;
    6.20 -#else
    6.21 -#define SSE_BEGIN \
    6.22 -    DECLARE_ALIGNED(Uint32, cccc[4], 16); \
    6.23 -    cccc[0] = color; \
    6.24 -    cccc[1] = color; \
    6.25 -    cccc[2] = color; \
    6.26 -    cccc[3] = color; \
    6.27 -    __m128 c128 = *(__m128 *)cccc;
    6.28 -#endif
    6.29 -
    6.30 -#define SSE_WORK \
    6.31 -    for (i = n / 64; i--;) { \
    6.32 -        _mm_stream_ps((float *)(p+0), c128); \
    6.33 -        _mm_stream_ps((float *)(p+16), c128); \
    6.34 -        _mm_stream_ps((float *)(p+32), c128); \
    6.35 -        _mm_stream_ps((float *)(p+48), c128); \
    6.36 -        p += 64; \
    6.37 -    }
    6.38 -
    6.39 -#define SSE_END
    6.40 -
    6.41 -#define DEFINE_SSE_FILLRECT(bpp, type) \
    6.42 -static void \
    6.43 -SDL_DrawRect##bpp##SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
    6.44 -{ \
    6.45 -    SSE_BEGIN; \
    6.46 - \
    6.47 -    while (h--) { \
    6.48 -        int i, n = w * bpp; \
    6.49 -        Uint8 *p = pixels; \
    6.50 - \
    6.51 -        if (n > 63) { \
    6.52 -            int adjust = 16 - ((uintptr_t)p & 15); \
    6.53 -            if (adjust < 16) { \
    6.54 -                n -= adjust; \
    6.55 -                adjust /= bpp; \
    6.56 -                while (adjust--) { \
    6.57 -                    *((type *)p) = (type)color; \
    6.58 -                    p += bpp; \
    6.59 -                } \
    6.60 -            } \
    6.61 -            SSE_WORK; \
    6.62 -        } \
    6.63 -        if (n & 63) { \
    6.64 -            int remainder = (n & 63); \
    6.65 -            remainder /= bpp; \
    6.66 -            while (remainder--) { \
    6.67 -                *((type *)p) = (type)color; \
    6.68 -                p += bpp; \
    6.69 -            } \
    6.70 -        } \
    6.71 -        pixels += pitch; \
    6.72 -    } \
    6.73 - \
    6.74 -    SSE_END; \
    6.75 -}
    6.76 -
    6.77 -static void
    6.78 -SDL_DrawRect1SSE(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
    6.79 -{
    6.80 -    SSE_BEGIN;
    6.81 -
    6.82 -    while (h--) {
    6.83 -        int i, n = w;
    6.84 -        Uint8 *p = pixels;
    6.85 -
    6.86 -        if (n > 63) {
    6.87 -            int adjust = 16 - ((uintptr_t)p & 15);
    6.88 -            if (adjust) {
    6.89 -                n -= adjust;
    6.90 -                SDL_memset(p, color, adjust);
    6.91 -                p += adjust;
    6.92 -            }
    6.93 -            SSE_WORK;
    6.94 -        }
    6.95 -        if (n & 63) {
    6.96 -            int remainder = (n & 63);
    6.97 -            SDL_memset(p, color, remainder);
    6.98 -            p += remainder;
    6.99 -        }
   6.100 -        pixels += pitch;
   6.101 -    }
   6.102 -
   6.103 -    SSE_END;
   6.104 -}
   6.105 -/*DEFINE_SSE_FILLRECT(1, Uint8)*/
   6.106 -DEFINE_SSE_FILLRECT(2, Uint16)
   6.107 -DEFINE_SSE_FILLRECT(4, Uint32)
   6.108 -
   6.109 -/* *INDENT-ON* */
   6.110 -#endif /* __SSE__ */
   6.111 -
   6.112 -#ifdef __MMX__
   6.113 -/* *INDENT-OFF* */
   6.114 -
   6.115 -#define MMX_BEGIN \
   6.116 -    __m64 c64 = _mm_set_pi32(color, color)
   6.117 -
   6.118 -#define MMX_WORK \
   6.119 -    for (i = n / 64; i--;) { \
   6.120 -        _mm_stream_pi((__m64 *)(p+0), c64); \
   6.121 -        _mm_stream_pi((__m64 *)(p+8), c64); \
   6.122 -        _mm_stream_pi((__m64 *)(p+16), c64); \
   6.123 -        _mm_stream_pi((__m64 *)(p+24), c64); \
   6.124 -        _mm_stream_pi((__m64 *)(p+32), c64); \
   6.125 -        _mm_stream_pi((__m64 *)(p+40), c64); \
   6.126 -        _mm_stream_pi((__m64 *)(p+48), c64); \
   6.127 -        _mm_stream_pi((__m64 *)(p+56), c64); \
   6.128 -        p += 64; \
   6.129 -    }
   6.130 -
   6.131 -#define MMX_END \
   6.132 -    _mm_empty()
   6.133 -
   6.134 -#define DEFINE_MMX_FILLRECT(bpp, type) \
   6.135 -static void \
   6.136 -SDL_DrawRect##bpp##MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h) \
   6.137 -{ \
   6.138 -    MMX_BEGIN; \
   6.139 - \
   6.140 -    while (h--) { \
   6.141 -        int i, n = w * bpp; \
   6.142 -        Uint8 *p = pixels; \
   6.143 - \
   6.144 -        if (n > 63) { \
   6.145 -            int adjust = 8 - ((uintptr_t)p & 7); \
   6.146 -            if (adjust < 8) { \
   6.147 -                n -= adjust; \
   6.148 -                adjust /= bpp; \
   6.149 -                while (adjust--) { \
   6.150 -                    *((type *)p) = (type)color; \
   6.151 -                    p += bpp; \
   6.152 -                } \
   6.153 -            } \
   6.154 -            MMX_WORK; \
   6.155 -        } \
   6.156 -        if (n & 63) { \
   6.157 -            int remainder = (n & 63); \
   6.158 -            remainder /= bpp; \
   6.159 -            while (remainder--) { \
   6.160 -                *((type *)p) = (type)color; \
   6.161 -                p += bpp; \
   6.162 -            } \
   6.163 -        } \
   6.164 -        pixels += pitch; \
   6.165 -    } \
   6.166 - \
   6.167 -    MMX_END; \
   6.168 -}
   6.169 -
   6.170 -static void
   6.171 -SDL_DrawRect1MMX(Uint8 *pixels, int pitch, Uint32 color, int w, int h)
   6.172 -{
   6.173 -    MMX_BEGIN;
   6.174 -
   6.175 -    while (h--) {
   6.176 -        int i, n = w;
   6.177 -        Uint8 *p = pixels;
   6.178 -
   6.179 -        if (n > 63) {
   6.180 -            int adjust = 8 - ((uintptr_t)p & 7);
   6.181 -            if (adjust) {
   6.182 -                n -= adjust;
   6.183 -                SDL_memset(p, color, adjust);
   6.184 -                p += adjust;
   6.185 -            }
   6.186 -            MMX_WORK;
   6.187 -        }
   6.188 -        if (n & 63) {
   6.189 -            int remainder = (n & 63);
   6.190 -            SDL_memset(p, color, remainder);
   6.191 -            p += remainder;
   6.192 -        }
   6.193 -        pixels += pitch;
   6.194 -    }
   6.195 -
   6.196 -    MMX_END;
   6.197 -}
   6.198 -/*DEFINE_MMX_FILLRECT(1, Uint8)*/
   6.199 -DEFINE_MMX_FILLRECT(2, Uint16)
   6.200 -DEFINE_MMX_FILLRECT(4, Uint32)
   6.201 -
   6.202 -/* *INDENT-ON* */
   6.203 -#endif /* __MMX__ */
   6.204 -
   6.205 -static void
   6.206 -SDL_DrawRect1(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
   6.207 -{
   6.208 -    while (h--) {
   6.209 -        int n = w;
   6.210 -        Uint8 *p = pixels;
   6.211 -
   6.212 -        if (n > 3) {
   6.213 -            switch ((uintptr_t) p & 3) {
   6.214 -            case 1:
   6.215 -                *p++ = (Uint8) color;
   6.216 -                --n;
   6.217 -            case 2:
   6.218 -                *p++ = (Uint8) color;
   6.219 -                --n;
   6.220 -            case 3:
   6.221 -                *p++ = (Uint8) color;
   6.222 -                --n;
   6.223 -            }
   6.224 -            SDL_memset4(p, color, (n >> 2));
   6.225 -        }
   6.226 -        if (n & 3) {
   6.227 -            p += (n & ~3);
   6.228 -            switch (n & 3) {
   6.229 -            case 3:
   6.230 -                *p++ = (Uint8) color;
   6.231 -            case 2:
   6.232 -                *p++ = (Uint8) color;
   6.233 -            case 1:
   6.234 -                *p++ = (Uint8) color;
   6.235 -            }
   6.236 -        }
   6.237 -        pixels += pitch;
   6.238 -    }
   6.239 -}
   6.240 -
   6.241 -static void
   6.242 -SDL_DrawRect2(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
   6.243 -{
   6.244 -    while (h--) {
   6.245 -        int n = w;
   6.246 -        Uint16 *p = (Uint16 *) pixels;
   6.247 -
   6.248 -        if (n > 1) {
   6.249 -            if ((uintptr_t) p & 2) {
   6.250 -                *p++ = (Uint16) color;
   6.251 -                --n;
   6.252 -            }
   6.253 -            SDL_memset4(p, color, (n >> 1));
   6.254 -        }
   6.255 -        if (n & 1) {
   6.256 -            p[n - 1] = (Uint16) color;
   6.257 -        }
   6.258 -        pixels += pitch;
   6.259 -    }
   6.260 -}
   6.261 -
   6.262 -static void
   6.263 -SDL_DrawRect3(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
   6.264 -{
   6.265 -    Uint8 r = (Uint8) ((color >> 16) & 0xFF);
   6.266 -    Uint8 g = (Uint8) ((color >> 8) & 0xFF);
   6.267 -    Uint8 b = (Uint8) (color & 0xFF);
   6.268 -
   6.269 -    while (h--) {
   6.270 -        int n = w;
   6.271 -        Uint8 *p = pixels;
   6.272 -
   6.273 -        while (n--) {
   6.274 -            *p++ = r;
   6.275 -            *p++ = g;
   6.276 -            *p++ = b;
   6.277 -        }
   6.278 -        pixels += pitch;
   6.279 -    }
   6.280 -}
   6.281 -
   6.282 -static void
   6.283 -SDL_DrawRect4(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
   6.284 -{
   6.285 -    while (h--) {
   6.286 -        SDL_memset4(pixels, color, w);
   6.287 -        pixels += pitch;
   6.288 -    }
   6.289 -}
   6.290 -
   6.291 -/* 
   6.292 - * This function performs a fast fill of the given rectangle with 'color'
   6.293 - */
   6.294  int
   6.295  SDL_DrawRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
   6.296  {
   6.297 -    SDL_Rect clipped;
   6.298 -    Uint8 *pixels;
   6.299 +    SDL_Rect full_rect;
   6.300 +    SDL_Point points[5];
   6.301  
   6.302      if (!dst) {
   6.303          SDL_SetError("Passed NULL destination surface");
   6.304          return -1;
   6.305      }
   6.306  
   6.307 -    /* This function doesn't work on surfaces < 8 bpp */
   6.308 -    if (dst->format->BitsPerPixel < 8) {
   6.309 -        SDL_SetError("SDL_DrawRect(): Unsupported surface format");
   6.310 -        return -1;
   6.311 +    /* If 'rect' == NULL, then outline the whole surface */
   6.312 +    if (!rect) {
   6.313 +        full_rect.x = 0;
   6.314 +        full_rect.y = 0;
   6.315 +        full_rect.w = dst->w;
   6.316 +        full_rect.h = dst->h;
   6.317 +        rect = &full_rect;
   6.318      }
   6.319  
   6.320 -    /* If 'rect' == NULL, then fill the whole surface */
   6.321 -    if (rect) {
   6.322 -        /* Perform clipping */
   6.323 -        if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
   6.324 -            return 0;
   6.325 -        }
   6.326 -        rect = &clipped;
   6.327 -    } else {
   6.328 -        rect = &dst->clip_rect;
   6.329 -    }
   6.330 -
   6.331 -    /* Perform software fill */
   6.332 -    if (!dst->pixels) {
   6.333 -        SDL_SetError("SDL_DrawRect(): You must lock the surface");
   6.334 -        return (-1);
   6.335 -    }
   6.336 -
   6.337 -    pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
   6.338 -                                     rect->x * dst->format->BytesPerPixel;
   6.339 -
   6.340 -    switch (dst->format->BytesPerPixel) {
   6.341 -    case 1:
   6.342 -        {
   6.343 -            color |= (color << 8);
   6.344 -            color |= (color << 16);
   6.345 -#ifdef __SSE__
   6.346 -            if (SDL_HasSSE()) {
   6.347 -                SDL_DrawRect1SSE(pixels, dst->pitch, color, rect->w, rect->h);
   6.348 -                break;
   6.349 -            }
   6.350 -#endif
   6.351 -#ifdef __MMX__
   6.352 -            if (SDL_HasMMX()) {
   6.353 -                SDL_DrawRect1MMX(pixels, dst->pitch, color, rect->w, rect->h);
   6.354 -                break;
   6.355 -            }
   6.356 -#endif
   6.357 -            SDL_DrawRect1(pixels, dst->pitch, color, rect->w, rect->h);
   6.358 -            break;
   6.359 -        }
   6.360 -
   6.361 -    case 2:
   6.362 -        {
   6.363 -            color |= (color << 16);
   6.364 -#ifdef __SSE__
   6.365 -            if (SDL_HasSSE()) {
   6.366 -                SDL_DrawRect2SSE(pixels, dst->pitch, color, rect->w, rect->h);
   6.367 -                break;
   6.368 -            }
   6.369 -#endif
   6.370 -#ifdef __MMX__
   6.371 -            if (SDL_HasMMX()) {
   6.372 -                SDL_DrawRect2MMX(pixels, dst->pitch, color, rect->w, rect->h);
   6.373 -                break;
   6.374 -            }
   6.375 -#endif
   6.376 -            SDL_DrawRect2(pixels, dst->pitch, color, rect->w, rect->h);
   6.377 -            break;
   6.378 -        }
   6.379 -
   6.380 -    case 3:
   6.381 -        /* 24-bit RGB is a slow path, at least for now. */
   6.382 -        {
   6.383 -            SDL_DrawRect3(pixels, dst->pitch, color, rect->w, rect->h);
   6.384 -            break;
   6.385 -        }
   6.386 -
   6.387 -    case 4:
   6.388 -        {
   6.389 -#ifdef __SSE__
   6.390 -            if (SDL_HasSSE()) {
   6.391 -                SDL_DrawRect4SSE(pixels, dst->pitch, color, rect->w, rect->h);
   6.392 -                break;
   6.393 -            }
   6.394 -#endif
   6.395 -#ifdef __MMX__
   6.396 -            if (SDL_HasMMX()) {
   6.397 -                SDL_DrawRect4MMX(pixels, dst->pitch, color, rect->w, rect->h);
   6.398 -                break;
   6.399 -            }
   6.400 -#endif
   6.401 -            SDL_DrawRect4(pixels, dst->pitch, color, rect->w, rect->h);
   6.402 -            break;
   6.403 -        }
   6.404 -    }
   6.405 -
   6.406 -    /* We're done! */
   6.407 -    return 0;
   6.408 +    points[0].x = rect->x;
   6.409 +    points[0].y = rect->y;
   6.410 +    points[1].x = rect->x+rect->w-1;
   6.411 +    points[1].y = rect->y;
   6.412 +    points[2].x = rect->x+rect->w-1;
   6.413 +    points[2].y = rect->y+rect->h-1;
   6.414 +    points[3].x = rect->x;
   6.415 +    points[3].y = rect->y+rect->h-1;
   6.416 +    points[4].x = rect->x;
   6.417 +    points[4].y = rect->y;
   6.418 +    return SDL_DrawLines(dst, points, 5, color);
   6.419  }
   6.420  
   6.421  int
   6.422 @@ -421,12 +62,13 @@
   6.423                Uint32 color)
   6.424  {
   6.425      int i;
   6.426 -    int status = 0;
   6.427  
   6.428      for (i = 0; i < count; ++i) {
   6.429 -        status = SDL_DrawRect(dst, rects[i], color);
   6.430 +        if (SDL_DrawRect(dst, rects[i], color) < 0) {
   6.431 +            return -1;
   6.432 +        }
   6.433      }
   6.434 -    return status;
   6.435 +    return 0;
   6.436  }
   6.437  
   6.438  /* vi: set ts=4 sw=4 expandtab: */