path ops : make it real

Add an option to SkCanvas to turn on path
ops when combining clips. 

Allow Op() to use one of the input paths
as an output path.

Fix a bug in Op() when the minuend is empty
and the subtrahend is not (for difference).

Change the build to allow core to depend on pathops.
Review URL: https://codereview.chromium.org/14474002

git-svn-id: http://skia.googlecode.com/svn/trunk@8855 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 1dc4fad..d200ba3 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -15,6 +15,7 @@
 #include "SkDrawFilter.h"
 #include "SkDrawLooper.h"
 #include "SkMetaData.h"
+#include "SkPathOps.h"
 #include "SkPicture.h"
 #include "SkRasterClip.h"
 #include "SkRRect.h"
@@ -508,6 +509,7 @@
     fLocalBoundsCompareType.setEmpty();
     fLocalBoundsCompareTypeDirty = true;
     fAllowSoftClip = true;
+    fAllowSimplifyClip = false;
     fDeviceCMDirty = false;
     fSaveLayerCount = 0;
     fMetaData = NULL;
@@ -1241,6 +1243,35 @@
     // if we called path.swap() we could avoid a deep copy of this path
     fClipStack.clipDevPath(devPath, op, doAA);
 
+    if (fAllowSimplifyClip) {
+        devPath.reset();
+        devPath.setFillType(SkPath::kInverseEvenOdd_FillType);
+        const SkClipStack* clipStack = getClipStack();
+        SkClipStack::Iter iter(*clipStack, SkClipStack::Iter::kBottom_IterStart);
+        const SkClipStack::Element* element;
+        while ((element = iter.next())) {
+            SkClipStack::Element::Type type = element->getType();
+            if (type == SkClipStack::Element::kEmpty_Type) {
+                continue;
+            }
+            SkPath operand;
+            if (type == SkClipStack::Element::kRect_Type) {
+                operand.addRect(element->getRect());
+            } else if (type == SkClipStack::Element::kPath_Type) {
+                operand = element->getPath();
+            } else {
+                SkDEBUGFAIL("Unexpected type.");
+            }
+            SkRegion::Op elementOp = element->getOp();
+            if (elementOp == SkRegion::kReplace_Op) {
+                devPath = operand;
+            } else {
+                Op(devPath, operand, (SkPathOp) elementOp, &devPath);
+            }
+        }
+        op = SkRegion::kReplace_Op;
+    }
+
     return clipPathHelper(this, fMCRec->fRasterClip, devPath, op, doAA);
 }