Merge "Fix clip area behavior for REPLACE op" into mnc-dev

This commit is contained in:
Chris Craik
2015-07-16 22:11:38 +00:00
committed by Android (Google) Code Review
3 changed files with 18 additions and 4 deletions

View File

@ -263,10 +263,11 @@ void ClipArea::enterRectangleMode() {
bool ClipArea::rectangleModeClipRectWithTransform(const Rect& r, bool ClipArea::rectangleModeClipRectWithTransform(const Rect& r,
const mat4* transform, SkRegion::Op op) { const mat4* transform, SkRegion::Op op) {
// TODO: we should be able to handle kReplace_Op efficiently without if (op == SkRegion::kReplace_Op && transform->rectToRect()) {
// going through RegionMode and later falling back into RectangleMode. mClipRect = r;
transform->mapRect(mClipRect);
if (op != SkRegion::kIntersect_Op) { return true;
} else if (op != SkRegion::kIntersect_Op) {
enterRegionMode(); enterRegionMode();
return regionModeClipRectWithTransform(r, transform, op); return regionModeClipRectWithTransform(r, transform, op);
} }

View File

@ -153,6 +153,8 @@ private:
} }
void regionFromPath(const SkPath& path, SkRegion& pathAsRegion) { void regionFromPath(const SkPath& path, SkRegion& pathAsRegion) {
// TODO: this should not mask every path to the viewport - this makes it impossible to use
// paths to clip to larger areas (which is valid e.g. with SkRegion::kReplace_Op)
pathAsRegion.setPath(path, createViewportRegion()); pathAsRegion.setPath(path, createViewportRegion());
} }

View File

@ -112,5 +112,16 @@ TEST(ClipArea, paths) {
regionBounds.set(skRect); regionBounds.set(skRect);
EXPECT_EQ(expected, regionBounds); EXPECT_EQ(expected, regionBounds);
} }
TEST(ClipArea, replaceNegative) {
ClipArea area(createClipArea());
area.setClip(0, 0, 100, 100);
Matrix4 transform;
transform.loadIdentity();
Rect expected(-50, -50, 50, 50);
area.clipRectWithTransform(expected, &transform, SkRegion::kReplace_Op);
EXPECT_EQ(expected, area.getClipRect());
}
} }
} }