diff src/video/x11/SDL_x11render.c @ 3596:f638ded38b8a

Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color. Renamed SDL_RenderPoint() and SDL_RenderLine() to SDL_RenderDrawPoint() and SDL_RenderDrawLine(). Added API for rectangle drawing (as opposed to filling) Added placeholder API functions for circles and ellipses ... I'm not sure whether these will stay. Optimized software line drawing quite a bit. Added support for Wu's anti-aliased line drawing, currently disabled by default.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 23 Dec 2009 01:55:00 +0000
parents 5f26a7eb5ff0
children 64ce267332c6
line wrap: on
line diff
--- a/src/video/x11/SDL_x11render.c	Fri Dec 18 08:19:18 2009 +0000
+++ b/src/video/x11/SDL_x11render.c	Wed Dec 23 01:55:00 2009 +0000
@@ -50,12 +50,14 @@
                            void **pixels, int *pitch);
 static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
 static int X11_SetDrawBlendMode(SDL_Renderer * renderer);
-static int X11_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points,
-                            int count);
-static int X11_RenderLines(SDL_Renderer * renderer, const SDL_Point * points,
-                           int count);
-static int X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
-                           int count);
+static int X11_RenderDrawPoints(SDL_Renderer * renderer,
+                                const SDL_Point * points, int count);
+static int X11_RenderDrawLines(SDL_Renderer * renderer,
+                               const SDL_Point * points, int count);
+static int X11_RenderDrawRects(SDL_Renderer * renderer,
+                               const SDL_Rect ** rects, int count);
+static int X11_RenderFillRects(SDL_Renderer * renderer,
+                               const SDL_Rect ** rects, int count);
 static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
                           const SDL_Rect * srcrect, const SDL_Rect * dstrect);
 static int X11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
@@ -208,9 +210,10 @@
     renderer->LockTexture = X11_LockTexture;
     renderer->UnlockTexture = X11_UnlockTexture;
     renderer->SetDrawBlendMode = X11_SetDrawBlendMode;
-    renderer->RenderPoints = X11_RenderPoints;
-    renderer->RenderLines = X11_RenderLines;
-    renderer->RenderRects = X11_RenderRects;
+    renderer->RenderDrawPoints = X11_RenderDrawPoints;
+    renderer->RenderDrawLines = X11_RenderDrawLines;
+    renderer->RenderDrawRects = X11_RenderDrawRects;
+    renderer->RenderFillRects = X11_RenderFillRects;
     renderer->RenderCopy = X11_RenderCopy;
     renderer->RenderReadPixels = X11_RenderReadPixels;
     renderer->RenderWritePixels = X11_RenderWritePixels;
@@ -600,7 +603,8 @@
 }
 
 static int
-X11_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
+X11_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
+                     int count)
 {
     X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
     SDL_Window *window = SDL_GetWindowFromID(renderer->window);
@@ -649,7 +653,8 @@
 }
 
 static int
-X11_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
+X11_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
+                    int count)
 {
     X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
     SDL_Window *window = SDL_GetWindowFromID(renderer->window);
@@ -787,7 +792,52 @@
 }
 
 static int
-X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
+X11_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
+{
+    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
+    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
+    SDL_Rect clip, rect;
+    unsigned long foreground;
+    XRectangle *xrects, *xrect;
+    int i, xcount;
+
+    clip.x = 0;
+    clip.y = 0;
+    clip.w = window->w;
+    clip.h = window->h;
+
+    foreground = renderdrawcolor(renderer, 1);
+    XSetForeground(data->display, data->gc, foreground);
+
+    xrect = xrects = SDL_stack_alloc(XRectangle, count);
+    xcount = 0;
+    for (i = 0; i < count; ++i) {
+        if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
+            continue;
+        }
+
+        xrect->x = (short)rect.x;
+        xrect->y = (short)rect.y;
+        xrect->width = (unsigned short)rect.w;
+        xrect->height = (unsigned short)rect.h;
+        ++xrect;
+        ++xcount;
+
+        if (data->makedirty) {
+            SDL_AddDirtyRect(&data->dirty, &rect);
+        }
+    }
+    if (xcount > 0) {
+        XDrawRectangles(data->display, data->drawable, data->gc,
+                        xrects, xcount);
+    }
+    SDL_stack_free(xpoints);
+
+    return 0;
+}
+
+static int
+X11_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
 {
     X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
     SDL_Window *window = SDL_GetWindowFromID(renderer->window);