Major changes to drawing. Reverted back to core X11 functions due to regressions.
authorSunny Sachanandani <sunnysachanandani@gmail.com>
Sun, 18 Jul 2010 18:27:38 +0530
changeset 459866e13a224bd6
parent 4597 95be206b3cb7
child 4599 ce0643707bb0
child 4600 8b22d33d8260
Major changes to drawing. Reverted back to core X11 functions due to regressions.
src/video/x11/SDL_x11render.c
test/testsprite2.c
     1.1 --- a/src/video/x11/SDL_x11render.c	Sun Jul 18 12:43:04 2010 +0530
     1.2 +++ b/src/video/x11/SDL_x11render.c	Sun Jul 18 18:27:38 2010 +0530
     1.3 @@ -32,6 +32,8 @@
     1.4  #include "../SDL_yuv_sw_c.h"
     1.5  #include "SDL_surface.h"
     1.6  
     1.7 +//#define EXPT
     1.8 +
     1.9  /* X11 renderer implementation */
    1.10  
    1.11  static SDL_Renderer *X11_CreateRenderer(SDL_Window * window, Uint32 flags);
    1.12 @@ -102,10 +104,12 @@
    1.13      Pixmap brush;
    1.14      Picture brush_pict;
    1.15  #ifndef NO_SHARED_MEMORY
    1.16 +#ifdef EXPT
    1.17      XImage *stencil_image;
    1.18      SDL_Surface *stencil_surface;
    1.19      XShmSegmentInfo stencil_shminfo;
    1.20  #endif
    1.21 +#endif
    1.22      Picture xwindow_pict;
    1.23      Picture pixmap_picts[3];
    1.24      Picture drawable_pict;
    1.25 @@ -135,7 +139,6 @@
    1.26      Picture picture;
    1.27      XRenderPictFormat* picture_fmt;
    1.28      int blend_op;
    1.29 -//    SDL_bool use_xrender;
    1.30  #endif
    1.31      XImage *image;
    1.32  #ifndef NO_SHARED_MEMORY
    1.33 @@ -318,6 +321,7 @@
    1.34                                                             PictStandardARGB32),
    1.35                                   CPRepeat, &brush_attr);
    1.36  #ifndef NO_SHARED_MEMORY
    1.37 +#ifdef EXPT
    1.38          /* Create a mask image using MIT-SHM */
    1.39          data->stencil_image = NULL;
    1.40          data->stencil_surface = NULL;
    1.41 @@ -326,22 +330,10 @@
    1.42              data->stencil_image =
    1.43                  XShmCreateImage(data->display, data->visual, 8, ZPixmap,
    1.44                                  NULL, shminfo, window->w, window->h);
    1.45 -            if (!data->stencil_image) {
    1.46 -                printf("XShmCreateImage() failed");
    1.47 -                break;
    1.48 -            } else {
    1.49 -                printf("image created\n");
    1.50 -            }
    1.51              shminfo->shmid = shmget(IPC_PRIVATE,
    1.52                                      data->stencil_image->bytes_per_line *
    1.53                                      data->stencil_image->height,
    1.54                                      IPC_CREAT|0777);
    1.55 -            if (!shminfo->shmid) {
    1.56 -                printf("shmget() failed");
    1.57 -                break;
    1.58 -            } else {
    1.59 -                printf("shmid aquired\n");
    1.60 -            }
    1.61              shminfo->shmaddr = data->stencil_image->data = shmat(shminfo->shmid, 0, 0);
    1.62              shminfo->readOnly = False;
    1.63              XShmAttach(data->display, shminfo);
    1.64 @@ -354,15 +346,10 @@
    1.65                                           8,
    1.66                                           data->stencil_image->bytes_per_line,
    1.67                                           0, 0, 0, 0xFF);
    1.68 -            if (!data->stencil_surface) {
    1.69 -                printf("SDL_CreateRGBSurfaceFrom() failed");
    1.70 -                break;
    1.71 -            } else {
    1.72 -                printf("surface created\n");
    1.73 -            }
    1.74              break;
    1.75          }
    1.76  #endif
    1.77 +#endif
    1.78          // Set the default blending mode.
    1.79          renderer->blendMode = SDL_BLENDMODE_BLEND;
    1.80          data->blend_op = PictOpOver;
    1.81 @@ -461,7 +448,7 @@
    1.82      /* Create the drawing context */
    1.83      gcv.graphics_exposures = False;
    1.84      data->gc =
    1.85 -        XCreateGC(data->display, data->xwindow, GCGraphicsExposures, &gcv);
    1.86 +        XCreateGC(data->display, data->drawable, GCGraphicsExposures, &gcv);
    1.87      if (!data->gc) {
    1.88          X11_DestroyRenderer(renderer);
    1.89          SDL_SetError("XCreateGC() failed");
    1.90 @@ -1059,35 +1046,40 @@
    1.91      clip.y = 0;
    1.92      clip.w = window->w;
    1.93      clip.h = window->h;
    1.94 +    if (data->makedirty) {
    1.95  
    1.96 +        /* Get the smallest rectangle that contains everything */
    1.97 +        rect.x = 0;
    1.98 +        rect.y = 0;
    1.99 +        rect.w = window->w;
   1.100 +        rect.h = window->h;
   1.101 +        if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
   1.102 +            /* Nothing to draw */
   1.103 +            return 0;
   1.104 +        }
   1.105 +        SDL_AddDirtyRect(&data->dirty, &rect);
   1.106 +    }
   1.107 +/*
   1.108  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   1.109  #ifndef NO_SHARED_MEMORY
   1.110 +#ifdef EXPT
   1.111      if (data->use_xrender && data->stencil_image && data->stencil_surface) {
   1.112 -        SDL_FillRect(data->stencil_surface, NULL, 0x00);
   1.113 +        SDL_FillRect(data->stencil_surface, &rect, 0x00);
   1.114  
   1.115          SDL_SetClipRect(data->stencil_surface, NULL);
   1.116 +
   1.117          SDL_DrawPoints(data->stencil_surface, points, count, 0xFF);
   1.118  
   1.119          XShmPutImage(data->display, data->stencil, data->stencil_gc, data->stencil_image,
   1.120 -                     0, 0, 0, 0, window->w, window->h, False);
   1.121 +                     rect.x, rect.y, rect.x, rect.y, rect.w, rect.h, False);
   1.122 +
   1.123 +        XSync(data->display, False);
   1.124      } else
   1.125  #endif
   1.126  #endif
   1.127 +#endif
   1.128 +*/
   1.129      {
   1.130 -        if (data->makedirty) {
   1.131 -
   1.132 -            /* Get the smallest rectangle that contains everything */
   1.133 -            rect.x = 0;
   1.134 -            rect.y = 0;
   1.135 -            rect.w = window->w;
   1.136 -            rect.h = window->h;
   1.137 -            if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
   1.138 -                /* Nothing to draw */
   1.139 -                return 0;
   1.140 -            }
   1.141 -            SDL_AddDirtyRect(&data->dirty, &rect);
   1.142 -        }
   1.143 -
   1.144          xpoint = xpoints = SDL_stack_alloc(XPoint, count);
   1.145          xcount = 0;
   1.146          for (i = 0; i < count; ++i) {
   1.147 @@ -1101,17 +1093,19 @@
   1.148              ++xpoint;
   1.149              ++xcount;
   1.150          }
   1.151 +/*
   1.152  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   1.153          if (data->use_xrender) {
   1.154              XSetForeground(data->display, data->stencil_gc, 0x00);
   1.155              XFillRectangle(data->display, data->stencil, data->stencil_gc,
   1.156 -                           0, 0, window->w, window->h);
   1.157 +                           rect.x, rect.y, rect.w, rect.h);
   1.158              XSetForeground(data->display, data->stencil_gc, 0xFF);
   1.159              XDrawPoints(data->display, data->stencil, data->stencil_gc, xpoints, xcount,
   1.160                          CoordModeOrigin);
   1.161          }
   1.162 -#endif
   1.163 +#endif*/
   1.164      }
   1.165 +/*
   1.166  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   1.167      if (data->use_xrender) {
   1.168          XRenderColor foreground;
   1.169 @@ -1120,10 +1114,11 @@
   1.170                               &foreground, 0, 0, 1, 1);
   1.171          XRenderComposite(data->display, data->blend_op, data->brush_pict,
   1.172                           data->stencil_pict, data->drawable_pict,
   1.173 -                         0, 0, 0, 0, 0, 0, window->w, window->h);
   1.174 +                         rect.x, rect.y, rect.x, rect.y, rect.x, rect.y, rect.w, rect.h);
   1.175      }
   1.176      else
   1.177  #endif
   1.178 +*/
   1.179      {
   1.180          unsigned long foreground = renderdrawcolor(renderer, 1);
   1.181          XSetForeground(data->display, data->gc, foreground);
   1.182 @@ -1157,22 +1152,30 @@
   1.183      clip.y = 0;
   1.184      clip.w = window->w;
   1.185      clip.h = window->h;
   1.186 +/*
   1.187  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   1.188  #ifndef NO_SHARED_MEMORY
   1.189 +#ifdef EXPT
   1.190      if (data->use_xrender && data->stencil_image && data->stencil_surface) {
   1.191          SDL_FillRect(data->stencil_surface, NULL, 0x00);
   1.192  
   1.193 +        SDL_DrawLines(data->stencil_surface, points, count, 0xFF);
   1.194 +
   1.195          SDL_SetClipRect(data->stencil_surface, NULL);
   1.196 -        SDL_DrawLines(data->stencil_surface, points, count, 0xFF);
   1.197  
   1.198          XShmPutImage(data->display, data->stencil, data->stencil_gc, data->stencil_image,
   1.199                       0, 0, 0, 0, window->w, window->h, False);
   1.200 +
   1.201 +        XSync(data->display, False);
   1.202      } else
   1.203  #endif
   1.204  #endif
   1.205 +#endif
   1.206 +*/
   1.207      {
   1.208          Pixmap drawable;
   1.209          GC gc;
   1.210 +/*
   1.211  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   1.212          if (data->use_xrender) {
   1.213              drawable = data->stencil;
   1.214 @@ -1184,6 +1187,7 @@
   1.215          }
   1.216          else
   1.217  #endif
   1.218 +*/
   1.219          {
   1.220              drawable = data->drawable;
   1.221              gc = data->gc;
   1.222 @@ -1306,6 +1310,7 @@
   1.223              }
   1.224          }
   1.225      }
   1.226 +/*
   1.227  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   1.228      if (data->use_xrender) {
   1.229          XRenderColor xrforeground = xrenderdrawcolor(renderer);
   1.230 @@ -1316,6 +1321,7 @@
   1.231                           0, 0, 0, 0, 0, 0, window->w, window->h);
   1.232      }
   1.233  #endif
   1.234 +*/
   1.235      SDL_stack_free(xpoints);
   1.236  
   1.237      return 0;
   1.238 @@ -1336,21 +1342,27 @@
   1.239      clip.y = 0;
   1.240      clip.w = window->w;
   1.241      clip.h = window->h;
   1.242 -
   1.243 +/*
   1.244  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   1.245  #ifndef NO_SHARED_MEMORY
   1.246 +#ifdef EXPT
   1.247      if (data->use_xrender && data->stencil_image && data->stencil_surface) {
   1.248          SDL_FillRect(data->stencil_surface, NULL, 0x00);
   1.249  
   1.250          SDL_SetClipRect(data->stencil_surface, NULL);
   1.251 +
   1.252          SDL_DrawRects(data->stencil_surface, rects, count, 1);
   1.253  
   1.254          XShmPutImage(data->display, data->stencil, data->stencil_gc, data->stencil_image,
   1.255                       0, 0, 0, 0, window->w, window->h, False);
   1.256 +
   1.257 +        XSync(data->display, False);
   1.258      }
   1.259      else
   1.260  #endif
   1.261  #endif
   1.262 +#endif
   1.263 +*/
   1.264      {
   1.265  
   1.266          for (i = 0; i < count; ++i) {
   1.267 @@ -1369,6 +1381,7 @@
   1.268                  SDL_AddDirtyRect(&data->dirty, &rect);
   1.269              }
   1.270          }
   1.271 +/*
   1.272  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   1.273          if (data->use_xrender) {
   1.274              XSetForeground(data->display, data->stencil_gc, 0x00);
   1.275 @@ -1379,7 +1392,9 @@
   1.276              XDrawRectangles(data->display, data->stencil, data->stencil_gc, xrects, xcount);
   1.277          }
   1.278  #endif
   1.279 -    } 
   1.280 +*/
   1.281 +    }
   1.282 +/*
   1.283  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   1.284      if (data->use_xrender) {
   1.285          XRenderColor foreground;
   1.286 @@ -1387,13 +1402,13 @@
   1.287  
   1.288          XRenderFillRectangle(data->display, PictOpSrc, data->brush_pict,
   1.289                               &foreground, 0, 0, 1, 1);
   1.290 -
   1.291          XRenderComposite(data->display, data->blend_op, data->brush_pict,
   1.292                           data->stencil_pict, data->drawable_pict,
   1.293                           0, 0, 0, 0, 0, 0, window->w, window->h);
   1.294      }
   1.295      else
   1.296  #endif
   1.297 +*/
   1.298      {
   1.299          unsigned long foreground;
   1.300          
   1.301 @@ -1447,8 +1462,15 @@
   1.302      if (data->use_xrender) {
   1.303          XRenderColor foreground;
   1.304          foreground = xrenderdrawcolor(renderer);
   1.305 -        XRenderFillRectangles(data->display, data->blend_op, data->drawable_pict,
   1.306 -                              &foreground, xrects, xcount);
   1.307 +        if (xcount == 1) {
   1.308 +            XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict,
   1.309 +                                 &foreground, xrects[0].x, xrects[0].y,
   1.310 +                                 xrects[0].width, xrects[0].height);
   1.311 +        }
   1.312 +        else if (xcount > 1) {
   1.313 +            XRenderFillRectangles(data->display, data->blend_op, data->drawable_pict,
   1.314 +                                  &foreground, xrects, xcount);
   1.315 +        }
   1.316      }
   1.317      else
   1.318  #endif
   1.319 @@ -1705,7 +1727,7 @@
   1.320          for (dirty = data->dirty.list; dirty; dirty = dirty->next) {
   1.321              const SDL_Rect *rect = &dirty->rect;
   1.322  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
   1.323 -            if(data->use_xrender == SDL_TRUE)
   1.324 +            if (data->use_xrender)
   1.325              {
   1.326                  XRenderComposite(data->display,
   1.327                                   data->blend_op,
   1.328 @@ -1726,7 +1748,7 @@
   1.329              }
   1.330          }
   1.331          SDL_ClearDirtyRects(&data->dirty);
   1.332 -   }
   1.333 +    }
   1.334      XSync(data->display, False);
   1.335  
   1.336      /* Update the flipping chain, if any */
     2.1 --- a/test/testsprite2.c	Sun Jul 18 12:43:04 2010 +0530
     2.2 +++ b/test/testsprite2.c	Sun Jul 18 18:27:38 2010 +0530
     2.3 @@ -144,8 +144,8 @@
     2.4      /* Test points */
     2.5      SDL_SetRenderDrawColor(0xFF, 0x00, 0x00, 0xFF);
     2.6      SDL_RenderDrawPoint(0, 0);
     2.7 -    SDL_RenderDrawPoint(window_w-1, 0);
     2.8 -    SDL_RenderDrawPoint(0, window_h-1);
     2.9 +    SDL_RenderDrawPoint(window_w/2-1, window_h/2-1);
    2.10 +    SDL_RenderDrawPoint(window_w/2-1, window_h/2-1);
    2.11      SDL_RenderDrawPoint(window_w-1, window_h-1);
    2.12  
    2.13      /* Test horizontal and vertical lines */