Implement SkCanvasGlue::clipRegion() using clipPath().
(Canvas clipRegion() public API is scheduled for deprecation)
The SkCanvas clip stack does not support clipRegion() ops. Implementing
these in terms of clipPath() makes persisting clips for SaveFlags
emulation purposes a whole lot simpler.
Change-Id: I41d1eb9e292ce370fba224338f9071d5e4068621
diff --git a/core/jni/android/graphics/Canvas.cpp b/core/jni/android/graphics/Canvas.cpp
index bdaf3a0..cf63dfb 100644
--- a/core/jni/android/graphics/Canvas.cpp
+++ b/core/jni/android/graphics/Canvas.cpp
@@ -298,7 +298,16 @@
jlong deviceRgnHandle, jint op) {
SkCanvas* canvas = getNativeCanvas(canvasHandle);
SkRegion* deviceRgn = reinterpret_cast<SkRegion*>(deviceRgnHandle);
- canvas->clipRegion(*deviceRgn, static_cast<SkRegion::Op>(op));
+ SkPath rgnPath;
+ if (deviceRgn->getBoundaryPath(&rgnPath)) {
+ // The region is specified in device space.
+ SkMatrix savedMatrix = canvas->getTotalMatrix();
+ canvas->resetMatrix();
+ canvas->clipPath(rgnPath, static_cast<SkRegion::Op>(op));
+ canvas->setMatrix(savedMatrix);
+ } else {
+ canvas->clipRect(SkRect::MakeEmpty(), static_cast<SkRegion::Op>(op));
+ }
return hasNonEmptyClip(*canvas);
}