X11 driver compiles again, lines are not yet implemented
authorSam Lantinga <slouken@libsdl.org>
Thu, 10 Dec 2009 09:27:23 +0000
changeset 3538a1896642a47e
parent 3537 e897a4a9f578
child 3539 f2846bf19360
X11 driver compiles again, lines are not yet implemented
src/video/x11/SDL_x11render.c
src/video/x11/SDL_x11sym.h
     1.1 --- a/src/video/x11/SDL_x11render.c	Thu Dec 10 08:28:26 2009 +0000
     1.2 +++ b/src/video/x11/SDL_x11render.c	Thu Dec 10 09:27:23 2009 +0000
     1.3 @@ -48,10 +48,12 @@
     1.4                             void **pixels, int *pitch);
     1.5  static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
     1.6  static int X11_SetDrawBlendMode(SDL_Renderer * renderer);
     1.7 -static int X11_RenderPoint(SDL_Renderer * renderer, int x, int y);
     1.8 -static int X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
     1.9 -                          int y2);
    1.10 -static int X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
    1.11 +static int X11_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points,
    1.12 +                            int count);
    1.13 +static int X11_RenderLines(SDL_Renderer * renderer, const SDL_Point * points,
    1.14 +                           int count);
    1.15 +static int X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
    1.16 +                           int count);
    1.17  static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
    1.18                            const SDL_Rect * srcrect, const SDL_Rect * dstrect);
    1.19  static void X11_RenderPresent(SDL_Renderer * renderer);
    1.20 @@ -200,9 +202,9 @@
    1.21      renderer->LockTexture = X11_LockTexture;
    1.22      renderer->UnlockTexture = X11_UnlockTexture;
    1.23      renderer->SetDrawBlendMode = X11_SetDrawBlendMode;
    1.24 -    renderer->RenderPoint = X11_RenderPoint;
    1.25 -    renderer->RenderLine = X11_RenderLine;
    1.26 -    renderer->RenderFill = X11_RenderFill;
    1.27 +    renderer->RenderPoints = X11_RenderPoints;
    1.28 +    renderer->RenderLines = X11_RenderLines;
    1.29 +    renderer->RenderRects = X11_RenderRects;
    1.30      renderer->RenderCopy = X11_RenderCopy;
    1.31      renderer->RenderPresent = X11_RenderPresent;
    1.32      renderer->DestroyTexture = X11_DestroyTexture;
    1.33 @@ -590,73 +592,126 @@
    1.34  }
    1.35  
    1.36  static int
    1.37 -X11_RenderPoint(SDL_Renderer * renderer, int x, int y)
    1.38 +X11_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count)
    1.39  {
    1.40      X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
    1.41 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
    1.42      unsigned long foreground;
    1.43 +    XPoint *xpoints, *xpoint;
    1.44 +    int i, xcount;
    1.45  
    1.46      if (data->makedirty) {
    1.47          SDL_Rect rect;
    1.48  
    1.49 -        rect.x = x;
    1.50 -        rect.y = y;
    1.51 -        rect.w = 1;
    1.52 -        rect.h = 1;
    1.53 -        SDL_AddDirtyRect(&data->dirty, &rect);
    1.54 -    }
    1.55 -
    1.56 -    foreground = renderdrawcolor(renderer, 1);
    1.57 -    XSetForeground(data->display, data->gc, foreground);
    1.58 -    XDrawPoint(data->display, data->drawable, data->gc, x, y);
    1.59 -    return 0;
    1.60 -}
    1.61 -
    1.62 -static int
    1.63 -X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
    1.64 -{
    1.65 -    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
    1.66 -    unsigned long foreground;
    1.67 -
    1.68 -    if (data->makedirty) {
    1.69 -        SDL_Rect rect;
    1.70 -
    1.71 -        if (x1 < x2) {
    1.72 -            rect.x = x1;
    1.73 -            rect.w = (x2 - x1) + 1;
    1.74 -        } else {
    1.75 -            rect.x = x2;
    1.76 -            rect.w = (x1 - x2) + 1;
    1.77 -        }
    1.78 -        if (y1 < y2) {
    1.79 -            rect.y = y1;
    1.80 -            rect.h = (y2 - y1) + 1;
    1.81 -        } else {
    1.82 -            rect.y = y2;
    1.83 -            rect.h = (y1 - y2) + 1;
    1.84 +        /* Get the smallest rectangle that contains everything */
    1.85 +        rect.x = 0;
    1.86 +        rect.y = 0;
    1.87 +        rect.w = window->w;
    1.88 +        rect.h = window->h;
    1.89 +        if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
    1.90 +            /* Nothing to draw */
    1.91 +            return 0;
    1.92          }
    1.93          SDL_AddDirtyRect(&data->dirty, &rect);
    1.94      }
    1.95  
    1.96      foreground = renderdrawcolor(renderer, 1);
    1.97      XSetForeground(data->display, data->gc, foreground);
    1.98 -    XDrawLine(data->display, data->drawable, data->gc, x1, y1, x2, y2);
    1.99 +
   1.100 +    xpoint = xpoints = SDL_stack_alloc(XPoint, count);
   1.101 +    xcount = 0;
   1.102 +    for (i = 0; i < count; ++i) {
   1.103 +        int x = points[i].x;
   1.104 +        int y = points[i].y;
   1.105 +        if (x < 0 || x >= window->w || y < 0 || y >= window->h) {
   1.106 +            continue;
   1.107 +        }
   1.108 +        xpoint->x = (short)x;
   1.109 +        xpoint->y = (short)y;
   1.110 +        ++xpoint;
   1.111 +        ++xcount;
   1.112 +    }
   1.113 +    if (xcount > 0) {
   1.114 +        XDrawPoints(data->display, data->drawable, data->gc, xpoints, xcount,
   1.115 +                    CoordModeOrigin);
   1.116 +    }
   1.117 +    SDL_stack_free(xpoints);
   1.118 +
   1.119      return 0;
   1.120  }
   1.121  
   1.122  static int
   1.123 -X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
   1.124 +X11_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count)
   1.125  {
   1.126      X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   1.127 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.128 +    SDL_Rect clip, rect;
   1.129      unsigned long foreground;
   1.130  
   1.131 +    clip.x = 0;
   1.132 +    clip.y = 0;
   1.133 +    clip.w = window->w;
   1.134 +    clip.h = window->h;
   1.135 +
   1.136      if (data->makedirty) {
   1.137 -        SDL_AddDirtyRect(&data->dirty, rect);
   1.138 +        /* Get the smallest rectangle that contains everything */
   1.139 +        SDL_EnclosePoints(points, count, NULL, &rect);
   1.140 +        if (!SDL_IntersectRect(&rect, &clip, &rect)) {
   1.141 +            /* Nothing to draw */
   1.142 +            return 0;
   1.143 +        }
   1.144 +        SDL_AddDirtyRect(&data->dirty, &rect);
   1.145      }
   1.146  
   1.147      foreground = renderdrawcolor(renderer, 1);
   1.148      XSetForeground(data->display, data->gc, foreground);
   1.149 -    XFillRectangle(data->display, data->drawable, data->gc, rect->x, rect->y,
   1.150 -                   rect->w, rect->h);
   1.151 +    /* FIXME: Can we properly handle lines that extend beyond visible space? */
   1.152 +    //XDrawLine(data->display, data->drawable, data->gc, x1, y1, x2, y2);
   1.153 +    return 0;
   1.154 +}
   1.155 +
   1.156 +static int
   1.157 +X11_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
   1.158 +{
   1.159 +    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
   1.160 +    SDL_Window *window = SDL_GetWindowFromID(renderer->window);
   1.161 +    SDL_Rect clip, rect;
   1.162 +    unsigned long foreground;
   1.163 +    XRectangle *xrects, *xrect;
   1.164 +    int i, xcount;
   1.165 +
   1.166 +    clip.x = 0;
   1.167 +    clip.y = 0;
   1.168 +    clip.w = window->w;
   1.169 +    clip.h = window->h;
   1.170 +
   1.171 +    foreground = renderdrawcolor(renderer, 1);
   1.172 +    XSetForeground(data->display, data->gc, foreground);
   1.173 +
   1.174 +    xrect = xrects = SDL_stack_alloc(XRectangle, count);
   1.175 +    xcount = 0;
   1.176 +    for (i = 0; i < count; ++i) {
   1.177 +        if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
   1.178 +            continue;
   1.179 +        }
   1.180 +
   1.181 +        xrect->x = (short)rect.x;
   1.182 +        xrect->y = (short)rect.y;
   1.183 +        xrect->width = (unsigned short)rect.w;
   1.184 +        xrect->height = (unsigned short)rect.h;
   1.185 +        ++xrect;
   1.186 +        ++xcount;
   1.187 +
   1.188 +        if (data->makedirty) {
   1.189 +            SDL_AddDirtyRect(&data->dirty, &rect);
   1.190 +        }
   1.191 +    }
   1.192 +    if (xcount > 0) {
   1.193 +        XFillRectangles(data->display, data->drawable, data->gc,
   1.194 +                        xrects, xcount);
   1.195 +    }
   1.196 +    SDL_stack_free(xpoints);
   1.197 +
   1.198      return 0;
   1.199  }
   1.200  
     2.1 --- a/src/video/x11/SDL_x11sym.h	Thu Dec 10 08:28:26 2009 +0000
     2.2 +++ b/src/video/x11/SDL_x11sym.h	Thu Dec 10 09:27:23 2009 +0000
     2.3 @@ -50,8 +50,7 @@
     2.4  SDL_X11_SYM(int,XDeleteProperty,(Display* a,Window b,Atom c),(a,b,c),return)
     2.5  SDL_X11_SYM(int,XDestroyWindow,(Display* a,Window b),(a,b),return)
     2.6  SDL_X11_SYM(int,XDisplayKeycodes,(Display* a,int* b,int* c),(a,b,c),return)
     2.7 -SDL_X11_SYM(int,XDrawRectangle,(Display* a,Drawable b,GC c,int d, int e, unsigned int f, unsigned int g),(a,b,c,d,e,f,g),return)
     2.8 -SDL_X11_SYM(int,XFillRectangle,(Display* a,Drawable b,GC c,int d, int e, unsigned int f, unsigned int g),(a,b,c,d,e,f,g),return)
     2.9 +SDL_X11_SYM(int,XFillRectangles,(Display* a,Drawable b,GC c,XRectangle* d,int e),(a,b,c,d,e),return)
    2.10  SDL_X11_SYM(char*,XDisplayName,(_Xconst char* a),(a),return)
    2.11  SDL_X11_SYM(int,XEventsQueued,(Display* a,int b),(a,b),return)
    2.12  SDL_X11_SYM(Bool,XFilterEvent,(XEvent *event,Window w),(event,w),return)
    2.13 @@ -95,8 +94,8 @@
    2.14  SDL_X11_SYM(int,XPeekEvent,(Display* a,XEvent* b),(a,b),return)
    2.15  SDL_X11_SYM(int,XPending,(Display* a),(a),return)
    2.16  SDL_X11_SYM(int,XPutImage,(Display* a,Drawable b,GC c,XImage* d,int e,int f,int g,int h,unsigned int i,unsigned int j),(a,b,c,d,e,f,g,h,i,j),return)
    2.17 -SDL_X11_SYM(int,XDrawLine,(Display* a, Drawable b, GC c, int d, int e, int f, int g),(a,b,c,d,e,f,g),return)
    2.18 -SDL_X11_SYM(int,XDrawPoint,(Display* a, Drawable b, GC c, int d, int e),(a,b,c,d,e),return)
    2.19 +SDL_X11_SYM(int,XDrawLines,(Display* a, Drawable b, GC c, XPoint* d, int e, int f),(a,b,c,d,e,f),return)
    2.20 +SDL_X11_SYM(int,XDrawPoints,(Display* a, Drawable b, GC c, XPoint* d, int e, int f),(a,b,c,d,e,f),return)
    2.21  SDL_X11_SYM(int,XQueryColors,(Display* a,Colormap b,XColor* c,int d),(a,b,c,d),return)
    2.22  SDL_X11_SYM(int,XQueryKeymap,(Display* a,char *b),(a,b),return)
    2.23  SDL_X11_SYM(Bool,XQueryPointer,(Display* a,Window b,Window* c,Window* d,int* e,int* f,int* g,int* h,unsigned int* i),(a,b,c,d,e,f,g,h,i),return)