changeset 4589:8d8a889530eb

Fix blending modes for primitives.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Thu, 01 Jul 2010 07:35:15 +0530
parents 0ddd78496d68
children 1ad70fb49fcb
files src/video/x11/SDL_x11render.c
diffstat 1 files changed, 48 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/x11/SDL_x11render.c	Sun Jun 27 09:51:51 2010 +0530
+++ b/src/video/x11/SDL_x11render.c	Thu Jul 01 07:35:15 2010 +0530
@@ -231,9 +231,11 @@
             goto fallback;
         }
         // Create a 1 bit depth mask
-        data->mask = XCreatePixmap(data->display, data->xwindow, window->w, window->h, 1);
+        data->mask = XCreatePixmap(data->display, data->xwindow,
+                                   window->w, window->h, 1);
         data->mask_pict = XRenderCreatePicture(data->display, data->mask,
-                                               XRenderFindStandardFormat(data->display, PictStandardA1),
+                                               XRenderFindStandardFormat(data->display,
+                                                                         PictStandardA1),
                                                0, NULL);
         XGCValues gcv_mask;
         gcv_mask.foreground = 1;
@@ -301,7 +303,8 @@
             if(!data->pixmap_picts[i]) {
                 data->use_xrender = SDL_FALSE;
             }
-            XRenderComposite(data->display, PictOpClear, data->pixmap_picts[i], None, data->pixmap_picts[i],
+            XRenderComposite(data->display, PictOpClear,
+                             data->pixmap_picts[i], None, data->pixmap_picts[i],
                              0, 0, 0, 0, 0, 0, window->w, window->h);
         }
 #endif
@@ -387,7 +390,8 @@
             if(!data->pixmap_picts[i]) {
                 data->use_xrender = SDL_FALSE;
             }
-            XRenderComposite(data->display, PictOpClear, data->pixmap_picts[i], None, data->pixmap_picts[i],
+            XRenderComposite(data->display, PictOpClear,
+                             data->pixmap_picts[i], None, data->pixmap_picts[i],
                              0, 0, 0, 0, 0, 0, window->w, window->h);
         }
 #endif
@@ -570,26 +574,8 @@
 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
     if(renderdata->use_xrender && data->pixmap) {
         data->use_xrender = SDL_TRUE;
-        /*unsigned long x11_fmt_mask; // Format mask
-        XRenderPictFormat x11_templ_fmt; // Format template
-        x11_fmt_mask =
-            (PictFormatRedMask | PictFormatGreenMask
-            | PictFormatBlueMask | PictFormatAlphaMask);
-        Uint32 Rmask, Gmask, Bmask, Amask;
-        int bpp;
-        SDL_PixelFormatEnumToMasks(data->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
-        x11_templ_fmt.depth = bpp;
-        x11_templ_fmt.type = PictTypeDirect;
-        x11_templ_fmt.direct.red = Rmask / 0xff;
-        x11_templ_fmt.direct.green = Gmask / 0xff;
-        x11_templ_fmt.direct.blue = Bmask / 0xff;
-        x11_templ_fmt.direct.alpha = Amask / 0xff;
-        printf("%d %d %d %d\n", Rmask/0xff, Gmask/0xff, Bmask/0xff, Amask/0xff);
-        // Return a matching XRenderPictFormat
         data->picture_fmt =
-            XRenderFindFormat(renderdata->display, x11_fmt_mask, &x11_templ_fmt, 0);*/
-        data->picture_fmt =
-            XRenderFindVisualFormat(renderdata->display, renderdata->visual);
+        XRenderFindVisualFormat(renderdata->display, renderdata->visual);
         if(!data->picture_fmt) {
             printf("XRenderFindFormat failed!\n");
             data->use_xrender = SDL_FALSE;
@@ -760,16 +746,14 @@
         data->blend_op = PictOpOver;
         return 0;
     /* FIXME case SDL_BLENDMODE_MOD: */
-    default: // PictOpSrc
-        SDL_Unsupported();
-        renderer->blendMode = SDL_BLENDMODE_NONE;
-        data->blend_op = PictOpSrc;
-        return -1;
 #endif
         return 0;
     default:
         SDL_Unsupported();
         renderer->blendMode = SDL_BLENDMODE_NONE;
+#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
+        data->blend_op = PictOpSrc;
+#endif
         return -1;
     }
 }
@@ -842,21 +826,31 @@
 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
     if (data->use_xrender == SDL_TRUE) {
         XRenderColor foreground;
+        XRenderPictureAttributes attributes;
+        unsigned long valuemask;
         
         foreground = xrenderdrawcolor(renderer);
+        /* Set the clip mask to restrict rendering to
+         * the primitive being drawn
+         */
+        attributes.clip_mask = data->mask;
+        valuemask = CPClipMask;
 
         XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict,
                          0, 0, 0, 0, 0, 0, window->w, window->h);
 
         XDrawPoints(data->display, data->mask, data->mask_gc, xpoints, xcount,
                     CoordModeOrigin);
-
+        XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
         Picture fill =
             XRenderCreateSolidFill(data->display, &foreground);
 
         XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
                          data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
 
+        // Reset the clip_mask
+        attributes.clip_mask = None;
+        XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
         XRenderFreePicture(data->display, fill);
     }
     else
@@ -1029,9 +1023,15 @@
 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
     if(data->use_xrender == SDL_TRUE) {
         XRenderColor xrforeground = xrenderdrawcolor(renderer);
+        XRenderPictureAttributes attributes;
+        attributes.clip_mask = data->mask;
+        unsigned long valuemask = CPClipMask;
+        XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
         Picture fill = XRenderCreateSolidFill(data->display, &xrforeground);
         XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
                          data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
+        attributes.clip_mask = None;
+        XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
         XRenderFreePicture(data->display, fill);
     }
 #endif
@@ -1074,15 +1074,23 @@
 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
     if(data->use_xrender == SDL_TRUE) {
         XRenderColor foreground;
+        XRenderPictureAttributes attributes;
+        unsigned long valuemask;
+
         foreground = xrenderdrawcolor(renderer);
+        valuemask = CPClipMask;
+        attributes.clip_mask = data->mask;
         
         XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict,
                          0, 0, 0, 0, 0, 0, window->w, window->h);
         XDrawRectangles(data->display, data->mask, data->mask_gc, xrects, xcount);
+        XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
         Picture fill =
             XRenderCreateSolidFill(data->display, &foreground);
         XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
                          data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
+        attributes.clip_mask = None;
+        XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
         XRenderFreePicture(data->display, fill);
     }
     else
@@ -1139,17 +1147,27 @@
 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
     if(data->use_xrender == SDL_TRUE) {
         XRenderColor foreground;
+        XRenderPictureAttributes attributes;
+        unsigned long valuemask;
 
         foreground = xrenderdrawcolor(renderer);
-         
+        attributes.clip_mask = data->mask;
+        valuemask = CPClipMask;
+        attributes.clip_mask = data->mask;
+        
         XRenderComposite(data->display, PictOpClear, data->mask_pict, None, data->mask_pict,
                          0, 0, 0, 0, 0, 0, window->w, window->h);
         XFillRectangles(data->display, data->mask, data->mask_gc,
                         xrects, xcount);
+
+        XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
+
         Picture fill = 
             XRenderCreateSolidFill(data->display, &foreground);
         XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
                          data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
+        attributes.clip_mask = None;
+        XRenderChangePicture(data->display, data->drawable_pict, valuemask, &attributes);
         XRenderFreePicture(data->display, fill);
     }
     else