src/video/SDL_fillrect.c
changeset 3536 0267b8b1595c
parent 3012 7e30c2dc7783
child 3697 f7b03b6838cb
     1.1 --- a/src/video/SDL_fillrect.c	Mon Dec 07 10:08:24 2009 +0000
     1.2 +++ b/src/video/SDL_fillrect.c	Wed Dec 09 15:56:56 2009 +0000
     1.3 @@ -310,24 +310,31 @@
     1.4   * This function performs a fast fill of the given rectangle with 'color'
     1.5   */
     1.6  int
     1.7 -SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
     1.8 +SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
     1.9  {
    1.10 +    SDL_Rect clipped;
    1.11      Uint8 *pixels;
    1.12  
    1.13 +    if (!dst) {
    1.14 +        SDL_SetError("Passed NULL destination surface");
    1.15 +        return -1;
    1.16 +    }
    1.17 +
    1.18      /* This function doesn't work on surfaces < 8 bpp */
    1.19      if (dst->format->BitsPerPixel < 8) {
    1.20          SDL_SetError("SDL_FillRect(): Unsupported surface format");
    1.21 -        return (-1);
    1.22 +        return -1;
    1.23      }
    1.24  
    1.25 -    /* If 'dstrect' == NULL, then fill the whole surface */
    1.26 -    if (dstrect) {
    1.27 +    /* If 'rect' == NULL, then fill the whole surface */
    1.28 +    if (rect) {
    1.29          /* Perform clipping */
    1.30 -        if (!SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect)) {
    1.31 -            return (0);
    1.32 +        if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
    1.33 +            return 0;
    1.34          }
    1.35 +        rect = &clipped;
    1.36      } else {
    1.37 -        dstrect = &dst->clip_rect;
    1.38 +        rect = &dst->clip_rect;
    1.39      }
    1.40  
    1.41      /* Perform software fill */
    1.42 @@ -336,9 +343,8 @@
    1.43          return (-1);
    1.44      }
    1.45  
    1.46 -    pixels =
    1.47 -        (Uint8 *) dst->pixels + dstrect->y * dst->pitch +
    1.48 -        dstrect->x * dst->format->BytesPerPixel;
    1.49 +    pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
    1.50 +                                     rect->x * dst->format->BytesPerPixel;
    1.51  
    1.52      switch (dst->format->BytesPerPixel) {
    1.53      case 1:
    1.54 @@ -347,19 +353,17 @@
    1.55              color |= (color << 16);
    1.56  #ifdef __SSE__
    1.57              if (SDL_HasSSE()) {
    1.58 -                SDL_FillRect1SSE(pixels, dst->pitch, color, dstrect->w,
    1.59 -                                 dstrect->h);
    1.60 +                SDL_FillRect1SSE(pixels, dst->pitch, color, rect->w, rect->h);
    1.61                  break;
    1.62              }
    1.63  #endif
    1.64  #ifdef __MMX__
    1.65              if (SDL_HasMMX()) {
    1.66 -                SDL_FillRect1MMX(pixels, dst->pitch, color, dstrect->w,
    1.67 -                                 dstrect->h);
    1.68 +                SDL_FillRect1MMX(pixels, dst->pitch, color, rect->w, rect->h);
    1.69                  break;
    1.70              }
    1.71  #endif
    1.72 -            SDL_FillRect1(pixels, dst->pitch, color, dstrect->w, dstrect->h);
    1.73 +            SDL_FillRect1(pixels, dst->pitch, color, rect->w, rect->h);
    1.74              break;
    1.75          }
    1.76  
    1.77 @@ -368,26 +372,24 @@
    1.78              color |= (color << 16);
    1.79  #ifdef __SSE__
    1.80              if (SDL_HasSSE()) {
    1.81 -                SDL_FillRect2SSE(pixels, dst->pitch, color, dstrect->w,
    1.82 -                                 dstrect->h);
    1.83 +                SDL_FillRect2SSE(pixels, dst->pitch, color, rect->w, rect->h);
    1.84                  break;
    1.85              }
    1.86  #endif
    1.87  #ifdef __MMX__
    1.88              if (SDL_HasMMX()) {
    1.89 -                SDL_FillRect2MMX(pixels, dst->pitch, color, dstrect->w,
    1.90 -                                 dstrect->h);
    1.91 +                SDL_FillRect2MMX(pixels, dst->pitch, color, rect->w, rect->h);
    1.92                  break;
    1.93              }
    1.94  #endif
    1.95 -            SDL_FillRect2(pixels, dst->pitch, color, dstrect->w, dstrect->h);
    1.96 +            SDL_FillRect2(pixels, dst->pitch, color, rect->w, rect->h);
    1.97              break;
    1.98          }
    1.99  
   1.100      case 3:
   1.101          /* 24-bit RGB is a slow path, at least for now. */
   1.102          {
   1.103 -            SDL_FillRect3(pixels, dst->pitch, color, dstrect->w, dstrect->h);
   1.104 +            SDL_FillRect3(pixels, dst->pitch, color, rect->w, rect->h);
   1.105              break;
   1.106          }
   1.107  
   1.108 @@ -395,25 +397,36 @@
   1.109          {
   1.110  #ifdef __SSE__
   1.111              if (SDL_HasSSE()) {
   1.112 -                SDL_FillRect4SSE(pixels, dst->pitch, color, dstrect->w,
   1.113 -                                 dstrect->h);
   1.114 +                SDL_FillRect4SSE(pixels, dst->pitch, color, rect->w, rect->h);
   1.115                  break;
   1.116              }
   1.117  #endif
   1.118  #ifdef __MMX__
   1.119              if (SDL_HasMMX()) {
   1.120 -                SDL_FillRect4MMX(pixels, dst->pitch, color, dstrect->w,
   1.121 -                                 dstrect->h);
   1.122 +                SDL_FillRect4MMX(pixels, dst->pitch, color, rect->w, rect->h);
   1.123                  break;
   1.124              }
   1.125  #endif
   1.126 -            SDL_FillRect4(pixels, dst->pitch, color, dstrect->w, dstrect->h);
   1.127 +            SDL_FillRect4(pixels, dst->pitch, color, rect->w, rect->h);
   1.128              break;
   1.129          }
   1.130      }
   1.131  
   1.132      /* We're done! */
   1.133 -    return (0);
   1.134 +    return 0;
   1.135 +}
   1.136 +
   1.137 +int
   1.138 +SDL_FillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
   1.139 +              Uint32 color)
   1.140 +{
   1.141 +    int i;
   1.142 +    int status = 0;
   1.143 +
   1.144 +    for (i = 0; i < count; ++i) {
   1.145 +        status = SDL_FillRect(dst, rects[i], color);
   1.146 +    }
   1.147 +    return status;
   1.148  }
   1.149  
   1.150  /* vi: set ts=4 sw=4 expandtab: */