changeset 4588:0ddd78496d68

Preliminary support for blending modes on drawing operations.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Sun, 27 Jun 2010 09:51:51 +0530
parents 25391ccf16a0
children 8d8a889530eb
files src/video/x11/SDL_x11render.c
diffstat 1 files changed, 32 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/x11/SDL_x11render.c	Tue Jun 22 20:01:38 2010 +0530
+++ b/src/video/x11/SDL_x11render.c	Sun Jun 27 09:51:51 2010 +0530
@@ -102,6 +102,7 @@
     Picture pixmap_picts[3];
     Picture drawable_pict;
     Picture mask_pict;
+    int blend_op;
     XRenderPictFormat* xwindow_pict_fmt;
     GC mask_gc;
     SDL_bool use_xrender;
@@ -743,14 +744,27 @@
 static int
 X11_SetDrawBlendMode(SDL_Renderer * renderer)
 {
+    X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
     switch (renderer->blendMode) {
     case SDL_BLENDMODE_NONE:
+#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
+        data->blend_op = PictOpSrc;
         return 0;
-#ifdef SDL_VIDEO_DRIVER_X11_XRENDER
     case SDL_BLENDMODE_MASK: // Use src pict as mask
+        data->blend_op = PictOpSrc;
+        return 0;
     case SDL_BLENDMODE_ADD: // PictOpAdd
+        data->blend_op = PictOpAdd;
+        return 0;
     case SDL_BLENDMODE_BLEND: // PictOpOver
+        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:
@@ -840,8 +854,8 @@
         Picture fill =
             XRenderCreateSolidFill(data->display, &foreground);
 
-        XRenderComposite(data->display, PictOpOver, fill, data->mask_pict, data->drawable_pict,
-                         0, 0, 0, 0, 0, 0, window->w, window->h);
+        XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
+                         data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
 
         XRenderFreePicture(data->display, fill);
     }
@@ -1016,8 +1030,8 @@
     if(data->use_xrender == SDL_TRUE) {
         XRenderColor xrforeground = xrenderdrawcolor(renderer);
         Picture fill = XRenderCreateSolidFill(data->display, &xrforeground);
-        XRenderComposite(data->display, PictOpOver, fill, data->mask_pict, data->drawable_pict,
-                         0, 0, 0, 0, 0, 0, window->w, window->h);
+        XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
+                         data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
         XRenderFreePicture(data->display, fill);
     }
 #endif
@@ -1067,8 +1081,8 @@
         XDrawRectangles(data->display, data->mask, data->mask_gc, xrects, xcount);
         Picture fill =
             XRenderCreateSolidFill(data->display, &foreground);
-        XRenderComposite(data->display, PictOpOver, fill, data->mask_pict, data->drawable_pict,
-                         0, 0, 0, 0, 0, 0, window->w, window->h);
+        XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
+                         data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
         XRenderFreePicture(data->display, fill);
     }
     else
@@ -1134,8 +1148,8 @@
                         xrects, xcount);
         Picture fill = 
             XRenderCreateSolidFill(data->display, &foreground);
-        XRenderComposite(data->display, PictOpOver, fill, data->mask_pict, data->drawable_pict,
-                         0, 0, 0, 0, 0, 0, window->w, window->h);
+        XRenderComposite(data->display, data->blend_op, fill, data->mask_pict,
+                         data->drawable_pict, 0, 0, 0, 0, 0, 0, window->w, window->h);
         XRenderFreePicture(data->display, fill);
     }
     else
@@ -1392,8 +1406,15 @@
 #ifdef SDL_VIDEO_DRIVER_X11_XRENDER
             if(data->use_xrender == SDL_TRUE)
             {
-                XRenderComposite(data->display, PictOpOver, data->drawable_pict, None, data->xwindow_pict,
-                                 rect->x, rect->y, 0, 0, rect->x, rect->y, rect->w, rect->h);
+                if(renderer->blendMode == SDL_BLENDMODE_MASK)
+                    XRenderComposite(data->display, data->blend_op, data->drawable_pict,
+                                     data->drawable_pict, data->xwindow_pict, rect->x, rect->y,
+                                     0, 0, rect->x, rect->y, rect->w, rect->h);
+                else
+                    XRenderComposite(data->display, data->blend_op, data->drawable_pict, None,
+                                     data->xwindow_pict, rect->x, rect->y, 0, 0, rect->x, rect->y,
+                                     rect->w, rect->h);
+
             }
             else
 #endif