From 4c4337291d873c4f27cb7903645863dc65b98a7b Mon Sep 17 00:00:00 2001 From: "tomhudson@google.com" Date: Fri, 9 Mar 2012 16:48:20 +0000 Subject: [PATCH] If we try to clip against a path and the path only contains a rect, treat it as a clip against a rect. (Works around a performance issue: JavaScript Canvas2D API only provides canvas.clipPath(), and we don't optimize path clips nearly as much as we can rects; this shows up more in Ganesh than in the software rasterizer.) http://codereview.appspot.com/5795044/ git-svn-id: http://skia.googlecode.com/svn/trunk@3355 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkClipStack.cpp | 4 ++++ tests/ClipStackTest.cpp | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/core/SkClipStack.cpp b/src/core/SkClipStack.cpp index f885240..cfa9482 100644 --- a/src/core/SkClipStack.cpp +++ b/src/core/SkClipStack.cpp @@ -165,6 +165,10 @@ void SkClipStack::clipDevRect(const SkRect& rect, SkRegion::Op op, bool doAA) { } void SkClipStack::clipDevPath(const SkPath& path, SkRegion::Op op, bool doAA) { + SkRect alt; + if (path.isRect(&alt)) { + return this->clipDevRect(alt, op, doAA); + } Rec* rec = (Rec*)fDeque.back(); if (rec && rec->canBeIntersected(fSaveCount, op)) { const SkRect& pathBounds = path.getBounds(); diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp index 40738df..a1e8323 100644 --- a/tests/ClipStackTest.cpp +++ b/tests/ClipStackTest.cpp @@ -55,12 +55,17 @@ static void test_assign_and_comparison(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, s != copy); // Test that different state (clip type) triggers not equal. + // NO LONGER VALID: if a path contains only a rect, we turn + // it into a bare rect for performance reasons (working + // around Chromium/JavaScript bad pattern). +/* s.restore(); s.save(); SkPath rp; rp.addRect(r); s.clipDevPath(rp, SkRegion::kUnion_Op, doAA); REPORTER_ASSERT(reporter, s != copy); +*/ // Test that different rects triggers not equal. s.restore(); -- 2.7.4