First functioning version of SW-only clip mask creator

http://codereview.appspot.com/6208072/



git-svn-id: http://skia.googlecode.com/svn/trunk@3984 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index 410223c..817f55a 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -101,7 +101,7 @@
 SkXfermode::Mode op_to_mode(SkRegion::Op op) {
 
     static const SkXfermode::Mode modeMap[] = {
-        SkXfermode::kSrcOut_Mode,   // kDifference_Op
+        SkXfermode::kDstOut_Mode,   // kDifference_Op
         SkXfermode::kMultiply_Mode, // kIntersect_Op
         SkXfermode::kSrcOver_Mode,  // kUnion_Op
         SkXfermode::kXor_Mode,      // kXOR_Op
@@ -118,14 +118,14 @@
  * Draw a single rect element of the clip stack into the accumulation bitmap
  */
 void GrSWMaskHelper::draw(const GrRect& clientRect, SkRegion::Op op, 
-                          bool antiAlias) {
+                          bool antiAlias, GrColor color) {
     SkPaint paint;
 
     SkXfermode* mode = SkXfermode::Create(op_to_mode(op));
 
     paint.setXfermode(mode);
     paint.setAntiAlias(antiAlias);
-    paint.setColor(SK_ColorWHITE);
+    paint.setColor(color);
 
     fDraw.drawRect(clientRect, paint);
 
@@ -136,7 +136,7 @@
  * Draw a single path element of the clip stack into the accumulation bitmap
  */
 void GrSWMaskHelper::draw(const SkPath& clientPath, SkRegion::Op op,
-                          GrPathFill fill, bool antiAlias) {
+                          GrPathFill fill, bool antiAlias, GrColor color) {
 
     SkPaint paint;
     SkPath tmpPath;
@@ -157,23 +157,30 @@
 
     paint.setXfermode(mode);
     paint.setAntiAlias(antiAlias);
-    paint.setColor(SK_ColorWHITE);
+    paint.setColor(color);
 
     fDraw.drawPath(*pathToDraw, paint);
 
     SkSafeUnref(mode);
 }
 
-bool GrSWMaskHelper::init(const GrIRect& pathDevBounds, const GrPoint* translate) {
-    fMatrix = fContext->getMatrix();
+bool GrSWMaskHelper::init(const GrIRect& pathDevBounds, 
+                          const GrPoint* translate,
+                          bool useMatrix) {
+    if (useMatrix) {    
+        fMatrix = fContext->getMatrix();
+    } else {
+        fMatrix.setIdentity();
+    }
+
     if (NULL != translate) {
         fMatrix.postTranslate(translate->fX, translate->fY);
     }
 
     fMatrix.postTranslate(-pathDevBounds.fLeft * SK_Scalar1,
-                            -pathDevBounds.fTop * SK_Scalar1);
+                          -pathDevBounds.fTop * SK_Scalar1);
     GrIRect bounds = GrIRect::MakeWH(pathDevBounds.width(),
-                                        pathDevBounds.height());
+                                     pathDevBounds.height());
 
     fBM.setConfig(SkBitmap::kA8_Config, bounds.fRight, bounds.fBottom);
     if (!fBM.allocPixels()) {
@@ -237,11 +244,12 @@
                                   bool antiAlias) {
     GrSWMaskHelper helper(context);
 
-    if (!helper.init(pathDevBounds, translate)) {
+    if (!helper.init(pathDevBounds, translate, true)) {
         return false;
     }
 
-    helper.draw(clientPath, SkRegion::kReplace_Op, fill, antiAlias);
+    helper.draw(clientPath, SkRegion::kReplace_Op, 
+                fill, antiAlias, SK_ColorWHITE);
 
     if (!helper.getTexture(tex)) {
         return false;
@@ -339,4 +347,3 @@
 
     return false;
 }
-