Got testsprite2 to work reasonably.
authorSunny Sachanandani <sunnysachanandani@gmail.com>
Sun, 18 Jul 2010 08:28:35 +0530
changeset 4596dc26c37ad70e
parent 4595 73eeadf7ed8e
child 4597 95be206b3cb7
Got testsprite2 to work reasonably.
src/video/x11/SDL_x11render.c
src/video/x11/SDL_x11sym.h
test/testsprite2.c
     1.1 --- a/src/video/x11/SDL_x11render.c	Sat Jul 17 15:53:29 2010 +0530
     1.2 +++ b/src/video/x11/SDL_x11render.c	Sun Jul 18 08:28:35 2010 +0530
     1.3 @@ -101,7 +101,6 @@
     1.4      Picture xwindow_pict;
     1.5      Picture pixmap_picts[3];
     1.6      Picture drawable_pict;
     1.7 -    Picture mask_pict;
     1.8      int blend_op;
     1.9      XRenderPictFormat* xwindow_pict_fmt;
    1.10      GC mask_gc;
    1.11 @@ -182,6 +181,7 @@
    1.12      info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YUY2;
    1.13      info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
    1.14      info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU;
    1.15 +    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_ARGB8888;
    1.16  
    1.17      for (i = 0; i < _this->num_displays; ++i) {
    1.18          SDL_AddRenderDriver(&_this->displays[i], &X11_RenderDriver);
    1.19 @@ -197,6 +197,7 @@
    1.20      SDL_Renderer *renderer;
    1.21      X11_RenderData *data;
    1.22      XGCValues gcv;
    1.23 +    gcv.graphics_exposures = False;
    1.24      int i, n;
    1.25      int bpp;
    1.26      Uint32 Rmask, Gmask, Bmask, Amask;
    1.27 @@ -291,25 +292,15 @@
    1.28              SDL_SetError("XCreatePixmap() failed");
    1.29              return NULL;
    1.30          }
    1.31 -        data->mask_pict =
    1.32 -            XRenderCreatePicture(data->display, data->mask,
    1.33 -                                 XRenderFindStandardFormat(data->display,
    1.34 -                                                           PictStandardA1),
    1.35 -                                 0, NULL);
    1.36 -        if (!data->mask_pict) {
    1.37 -            SDL_SetError("XRenderCreatePicture() failed");
    1.38 -            return NULL;
    1.39 -        }
    1.40          // Create the GC for the clip mask.
    1.41 -        XGCValues gcv_mask;
    1.42 -        gcv_mask.foreground = 1;
    1.43 -        gcv_mask.background = 0;
    1.44          data->mask_gc = XCreateGC(data->display, data->mask,
    1.45 -                                  GCBackground | GCForeground, &gcv_mask);
    1.46 +                                  GCGraphicsExposures, &gcv);
    1.47          if (!data->mask_gc) {
    1.48              SDL_SetError("XCreateGC() failed");
    1.49              return NULL;
    1.50          }
    1.51 +        XSetBackground(data->display, data->mask_gc, 0);
    1.52 +        XSetForeground(data->display, data->mask_gc, 1);
    1.53          // Set the default blending mode.
    1.54          renderer->blendMode = SDL_BLENDMODE_BLEND;
    1.55          data->blend_op = PictOpOver;
    1.56 @@ -425,6 +416,16 @@
    1.57      SDL_Window *window = renderer->window;
    1.58      int i, n;
    1.59  
    1.60 +#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
    1.61 +    if (data->use_xrender) {
    1.62 +        XRenderFreePicture(data->display, data->xwindow_pict);
    1.63 +        data->xwindow_pict_fmt =
    1.64 +            XRenderFindVisualFormat(data->display, data->visual);
    1.65 +        data->xwindow_pict =
    1.66 +            XRenderCreatePicture(data->display, data->xwindow,
    1.67 +                                 data->xwindow_pict_fmt, 0, NULL);
    1.68 +    }
    1.69 +#endif
    1.70      if (renderer->info.flags & SDL_RENDERER_SINGLEBUFFER) {
    1.71          n = 0;
    1.72      } else if (renderer->info.flags & SDL_RENDERER_PRESENTFLIP2) {
    1.73 @@ -439,6 +440,7 @@
    1.74              XFreePixmap(data->display, data->pixmaps[i]);
    1.75              data->pixmaps[i] = None;
    1.76  #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
    1.77 +            XRenderFreePicture(data->display, data->pixmap_picts[i]);
    1.78              data->pixmap_picts[i] = None;
    1.79  #endif
    1.80          }
    1.81 @@ -1038,27 +1040,20 @@
    1.82           */
    1.83          attributes.clip_mask = data->mask;
    1.84          valuemask = CPClipMask;
    1.85 -
    1.86 -        XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict,
    1.87 -                         0, 0, 0, 0, 0, 0, window->w, window->h);
    1.88 +        
    1.89 +        XSetForeground(data->display, data->mask_gc, 0);
    1.90 +        XFillRectangle(data->display, data->mask, data->mask_gc,
    1.91 +                       0, 0, window->w, window->h);
    1.92 +        XSetForeground(data->display, data->mask_gc, 1);
    1.93  
    1.94          XDrawPoints(data->display, data->mask, data->mask_gc, xpoints, xcount,
    1.95                      CoordModeOrigin);
    1.96          XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
    1.97 -        Picture fill =
    1.98 -            XRenderCreateSolidFill(data->display, &foreground);
    1.99 -        if (!fill) {
   1.100 -            SDL_SetError("XRenderCreateSolidFill() failed");
   1.101 -            return -1;
   1.102 -        }
   1.103 -
   1.104 -        XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
   1.105 -                         data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
   1.106 -
   1.107 +        /*XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict,
   1.108 +                             &foreground, 0, 0, window->w, window->h);*/
   1.109          // Reset the clip_mask
   1.110          attributes.clip_mask = None;
   1.111          XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
   1.112 -        XRenderFreePicture(data->display, fill);
   1.113      }
   1.114      else
   1.115  #endif
   1.116 @@ -1101,8 +1096,10 @@
   1.117      if (data->use_xrender == SDL_TRUE) {
   1.118          drawable = data->mask;
   1.119          gc = data->mask_gc;
   1.120 -        XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict,
   1.121 -                         0, 0, 0, 0, 0, 0, window->w, window->h);
   1.122 +        XSetForeground(data->display, data->mask_gc, 0);
   1.123 +        XFillRectangle(data->display, data->mask, data->mask_gc,
   1.124 +                       0, 0, window->w, window->h);
   1.125 +        XSetForeground(data->display, data->mask_gc, 1);
   1.126      }
   1.127      else
   1.128  #endif
   1.129 @@ -1234,16 +1231,10 @@
   1.130          attributes.clip_mask = data->mask;
   1.131          unsigned long valuemask = CPClipMask;
   1.132          XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
   1.133 -        Picture fill = XRenderCreateSolidFill(data->display, &xrforeground);
   1.134 -        if (!fill) {
   1.135 -            SDL_SetError("XRenderCreateSolidFill() failed");
   1.136 -            return -1;
   1.137 -        }
   1.138 -        XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
   1.139 -                         data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
   1.140 +        /*XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict,
   1.141 +                             &xrforeground, 0, 0, window->w, window->h);*/
   1.142          attributes.clip_mask = None;
   1.143          XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
   1.144 -        XRenderFreePicture(data->display, fill);
   1.145      }
   1.146  #endif
   1.147      SDL_stack_free(xpoints);
   1.148 @@ -1294,21 +1285,17 @@
   1.149          valuemask = CPClipMask;
   1.150          attributes.clip_mask = data->mask;
   1.151          
   1.152 -        XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict,
   1.153 -                         0, 0, 0, 0, 0, 0, window->w, window->h);
   1.154 +        XSetForeground(data->display, data->mask_gc, 0);
   1.155 +        XFillRectangle(data->display, data->mask, data->mask_gc,
   1.156 +                       0, 0, window->w, window->h);
   1.157 +        XSetForeground(data->display, data->mask_gc, 1);
   1.158 +
   1.159          XDrawRectangles(data->display, data->mask, data->mask_gc, xrects, xcount);
   1.160          XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
   1.161 -        Picture fill =
   1.162 -            XRenderCreateSolidFill(data->display, &foreground);
   1.163 -        if (!fill) {
   1.164 -            SDL_SetError("XRenderCreateSolidFill() failed");
   1.165 -            return -1;
   1.166 -        }
   1.167 -        XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
   1.168 -                         data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
   1.169 +        /*XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict,
   1.170 +                             &foreground, 0, 0, window->w, window->h);*/
   1.171          attributes.clip_mask = None;
   1.172          XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
   1.173 -        XRenderFreePicture(data->display, fill);
   1.174      }
   1.175      else
   1.176  #endif
   1.177 @@ -1369,23 +1356,19 @@
   1.178          foreground = xrenderdrawcolor(renderer);
   1.179          attributes.clip_mask = data->mask;
   1.180          
   1.181 -        XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict,
   1.182 -                         0, 0, 0, 0, 0, 0, window->w, window->h);
   1.183 +        XSetForeground(data->display, data->mask_gc, 0);
   1.184 +        XFillRectangle(data->display, data->mask, data->mask_gc,
   1.185 +                       0, 0, window->w, window->h);
   1.186 +        XSetForeground(data->display, data->mask_gc, 1);
   1.187 +
   1.188          XFillRectangles(data->display, data->mask, data->mask_gc,
   1.189                          xrects, xcount);
   1.190  
   1.191          XRenderChangePicture(data->display, data->drawable_pict, CPClipMask, &attributes);
   1.192 -        Picture fill = XRenderCreateSolidFill(data->display,
   1.193 -                                              &foreground);
   1.194 -        if (!fill) {
   1.195 -            SDL_SetError("XRenderCreateSolidFill() failed");
   1.196 -            return -1;
   1.197 -        }
   1.198 -        XRenderComposite(data->display, data->blend_op, fill, None,
   1.199 -                         data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
   1.200 +        /*XRenderFillRectangle(data->display, data->blend_op, data->drawable_pict,
   1.201 +                               &foreground, 0, 0, window->w, window->h);*/
   1.202          attributes.clip_mask = None;
   1.203          XRenderChangePicture(data->display, data->drawable_pict, CPClipMask, &attributes);
   1.204 -        XRenderFreePicture(data->display, fill);
   1.205      }
   1.206      else
   1.207  #endif
   1.208 @@ -1746,9 +1729,6 @@
   1.209          if (data->mask_gc) {
   1.210              XFreeGC(data->display, data->mask_gc);
   1.211          }
   1.212 -        if (data->mask_pict) {
   1.213 -            XRenderFreePicture(data->display, data->mask_pict);
   1.214 -        }
   1.215          if (data->mask) {
   1.216              XFreePixmap(data->display, data->mask);
   1.217          }
     2.1 --- a/src/video/x11/SDL_x11sym.h	Sat Jul 17 15:53:29 2010 +0530
     2.2 +++ b/src/video/x11/SDL_x11sym.h	Sun Jul 18 08:28:35 2010 +0530
     2.3 @@ -151,6 +151,8 @@
     2.4  SDL_X11_SYM(SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display* a,int b,SDL_X11_XESetWireToEventRetType c),(a,b,c),return)
     2.5  SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display* a,int b,SDL_X11_XESetEventToWireRetType c),(a,b,c),return)
     2.6  SDL_X11_SYM(XExtensionErrorHandler,XSetExtensionErrorHandler,(XExtensionErrorHandler a),(a),return)
     2.7 +SDL_X11_SYM(int,XFillRectangle,(Display *dpy,Drawable d,GC gc,int x,int y,unsigned int width,unsigned int height),(dpy,d,gc,x,y,width,height),return)
     2.8 +SDL_X11_SYM(int,XSetBackground,(Display *dpy,GC gc,unsigned long background),(dpy,gc,background),return)
     2.9  
    2.10  #if NeedWidePrototypes
    2.11  SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display* a,unsigned int b,int c),(a,b,c),return)
    2.12 @@ -246,6 +248,7 @@
    2.13  SDL_X11_SYM(void,XRenderComposite,(Display *dpy,int op,Picture src,Picture mask,Picture dst,int src_x,int src_y,int mask_x,int mask_y,int dst_x,int dst_y,unsigned int width,unsigned int height),(dpy,op,src,mask,dst,src_x,src_y,mask_x,mask_y,dst_x,dst_y,width,height),return)
    2.14  SDL_X11_SYM(Picture,XRenderCreateSolidFill,(Display *dpy,const XRenderColor *color),(dpy,color),return)
    2.15  SDL_X11_SYM(void,XRenderSetPictureTransform,(Display *dpy,Picture picture,XTransform *transform),(dpy,picture,transform),return)
    2.16 +SDL_X11_SYM(void,XRenderFillRectangle,(Display *dpy,int op,Picture dst,_Xconst XRenderColor *color,int x,int y,unsigned int width,unsigned int height),(dpy,op,dst,color,x,y,width,height),return)
    2.17  #endif
    2.18  /* *INDENT-ON* */
    2.19  
     3.1 --- a/test/testsprite2.c	Sat Jul 17 15:53:29 2010 +0530
     3.2 +++ b/test/testsprite2.c	Sun Jul 18 08:28:35 2010 +0530
     3.3 @@ -20,7 +20,7 @@
     3.4  static SDL_Rect *positions;
     3.5  static SDL_Rect *velocities;
     3.6  static int sprite_w, sprite_h;
     3.7 -static SDL_BlendMode blendMode = SDL_BLENDMODE_MASK;
     3.8 +static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
     3.9  static SDL_TextureScaleMode scaleMode = SDL_TEXTURESCALEMODE_NONE;
    3.10  
    3.11  /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */