diff src/video/SDL_fillrect.c @ 3536:0267b8b1595c

Added interfaces for batch drawing of points, lines and rects: SDL_DrawPoints() SDL_BlendPoints() SDL_BlendLines() SDL_DrawLines() SDL_FillRects() SDL_BlendRects() SDL_RenderPoints() SDL_RenderLines() SDL_RenderRects() Renamed SDL_RenderFill() to SDL_RenderRect()
author Sam Lantinga <slouken@libsdl.org>
date Wed, 09 Dec 2009 15:56:56 +0000
parents 7e30c2dc7783
children f7b03b6838cb
line wrap: on
line diff
--- a/src/video/SDL_fillrect.c	Mon Dec 07 10:08:24 2009 +0000
+++ b/src/video/SDL_fillrect.c	Wed Dec 09 15:56:56 2009 +0000
@@ -310,24 +310,31 @@
  * This function performs a fast fill of the given rectangle with 'color'
  */
 int
-SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color)
+SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color)
 {
+    SDL_Rect clipped;
     Uint8 *pixels;
 
+    if (!dst) {
+        SDL_SetError("Passed NULL destination surface");
+        return -1;
+    }
+
     /* This function doesn't work on surfaces < 8 bpp */
     if (dst->format->BitsPerPixel < 8) {
         SDL_SetError("SDL_FillRect(): Unsupported surface format");
-        return (-1);
+        return -1;
     }
 
-    /* If 'dstrect' == NULL, then fill the whole surface */
-    if (dstrect) {
+    /* If 'rect' == NULL, then fill the whole surface */
+    if (rect) {
         /* Perform clipping */
-        if (!SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect)) {
-            return (0);
+        if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) {
+            return 0;
         }
+        rect = &clipped;
     } else {
-        dstrect = &dst->clip_rect;
+        rect = &dst->clip_rect;
     }
 
     /* Perform software fill */
@@ -336,9 +343,8 @@
         return (-1);
     }
 
-    pixels =
-        (Uint8 *) dst->pixels + dstrect->y * dst->pitch +
-        dstrect->x * dst->format->BytesPerPixel;
+    pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch +
+                                     rect->x * dst->format->BytesPerPixel;
 
     switch (dst->format->BytesPerPixel) {
     case 1:
@@ -347,19 +353,17 @@
             color |= (color << 16);
 #ifdef __SSE__
             if (SDL_HasSSE()) {
-                SDL_FillRect1SSE(pixels, dst->pitch, color, dstrect->w,
-                                 dstrect->h);
+                SDL_FillRect1SSE(pixels, dst->pitch, color, rect->w, rect->h);
                 break;
             }
 #endif
 #ifdef __MMX__
             if (SDL_HasMMX()) {
-                SDL_FillRect1MMX(pixels, dst->pitch, color, dstrect->w,
-                                 dstrect->h);
+                SDL_FillRect1MMX(pixels, dst->pitch, color, rect->w, rect->h);
                 break;
             }
 #endif
-            SDL_FillRect1(pixels, dst->pitch, color, dstrect->w, dstrect->h);
+            SDL_FillRect1(pixels, dst->pitch, color, rect->w, rect->h);
             break;
         }
 
@@ -368,26 +372,24 @@
             color |= (color << 16);
 #ifdef __SSE__
             if (SDL_HasSSE()) {
-                SDL_FillRect2SSE(pixels, dst->pitch, color, dstrect->w,
-                                 dstrect->h);
+                SDL_FillRect2SSE(pixels, dst->pitch, color, rect->w, rect->h);
                 break;
             }
 #endif
 #ifdef __MMX__
             if (SDL_HasMMX()) {
-                SDL_FillRect2MMX(pixels, dst->pitch, color, dstrect->w,
-                                 dstrect->h);
+                SDL_FillRect2MMX(pixels, dst->pitch, color, rect->w, rect->h);
                 break;
             }
 #endif
-            SDL_FillRect2(pixels, dst->pitch, color, dstrect->w, dstrect->h);
+            SDL_FillRect2(pixels, dst->pitch, color, rect->w, rect->h);
             break;
         }
 
     case 3:
         /* 24-bit RGB is a slow path, at least for now. */
         {
-            SDL_FillRect3(pixels, dst->pitch, color, dstrect->w, dstrect->h);
+            SDL_FillRect3(pixels, dst->pitch, color, rect->w, rect->h);
             break;
         }
 
@@ -395,25 +397,36 @@
         {
 #ifdef __SSE__
             if (SDL_HasSSE()) {
-                SDL_FillRect4SSE(pixels, dst->pitch, color, dstrect->w,
-                                 dstrect->h);
+                SDL_FillRect4SSE(pixels, dst->pitch, color, rect->w, rect->h);
                 break;
             }
 #endif
 #ifdef __MMX__
             if (SDL_HasMMX()) {
-                SDL_FillRect4MMX(pixels, dst->pitch, color, dstrect->w,
-                                 dstrect->h);
+                SDL_FillRect4MMX(pixels, dst->pitch, color, rect->w, rect->h);
                 break;
             }
 #endif
-            SDL_FillRect4(pixels, dst->pitch, color, dstrect->w, dstrect->h);
+            SDL_FillRect4(pixels, dst->pitch, color, rect->w, rect->h);
             break;
         }
     }
 
     /* We're done! */
-    return (0);
+    return 0;
+}
+
+int
+SDL_FillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count,
+              Uint32 color)
+{
+    int i;
+    int status = 0;
+
+    for (i = 0; i < count; ++i) {
+        status = SDL_FillRect(dst, rects[i], color);
+    }
+    return status;
 }
 
 /* vi: set ts=4 sw=4 expandtab: */