From: bsalomon Date: Wed, 11 May 2016 22:15:56 +0000 (-0700) Subject: Add isEmpty() query to GrShape and improve comments. X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~129^2~549 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7c73a53894927d222d4aceed96893daae8ea14f1;p=platform%2Fupstream%2FlibSkiaSharp.git Add isEmpty() query to GrShape and improve comments. GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1971613004 Review-Url: https://codereview.chromium.org/1971613004 --- diff --git a/src/gpu/GrShape.h b/src/gpu/GrShape.h index d72b179..81684e8 100644 --- a/src/gpu/GrShape.h +++ b/src/gpu/GrShape.h @@ -115,6 +115,7 @@ public: return GrShape(*this, apply, scale); } + /** Returns the unstyled geometry as a rrect if possible. */ bool asRRect(SkRRect* rrect) const { if (Type::kRRect != fType) { return false; @@ -125,6 +126,7 @@ public: return true; } + /** Returns the unstyled geometry as a path. */ void asPath(SkPath* out) const { switch (fType) { case Type::kEmpty: @@ -141,8 +143,14 @@ public: } /** - * Is it known that the shape has no unclosed contours. This means that it will not have - * any caps if stroked (modulo the effect of any path effect). + * Returns whether the geometry is empty. Note that applying the style could produce a + * non-empty shape. + */ + bool isEmpty() const { return Type::kEmpty == fType; } + + /** + * Is it known that the unstyled geometry has no unclosed contours. This means that it will + * not have any caps if stroked (modulo the effect of any path effect). */ bool knownToBeClosed() const { switch (fType) { diff --git a/tests/GrShapeTest.cpp b/tests/GrShapeTest.cpp index 75f27ed..138028d 100644 --- a/tests/GrShapeTest.cpp +++ b/tests/GrShapeTest.cpp @@ -83,6 +83,15 @@ private: fAppliedPEThenStroke.asPath(&a); fAppliedFull.asPath(&b); REPORTER_ASSERT(r, a == b); + REPORTER_ASSERT(r, fAppliedFull.isEmpty() == fAppliedPEThenStroke.isEmpty()); + + SkPath path; + fBase.asPath(&path); + REPORTER_ASSERT(r, path.isEmpty() == fBase.isEmpty()); + fAppliedPE.asPath(&path); + REPORTER_ASSERT(r, path.isEmpty() == fAppliedPE.isEmpty()); + fAppliedFull.asPath(&path); + REPORTER_ASSERT(r, path.isEmpty() == fAppliedFull.isEmpty()); // Check that the same path is produced when style is applied by GrShape and GrStyle. SkPath preStyle; @@ -170,6 +179,7 @@ void TestCase::compare(skiatest::Reporter* reporter, const TestCase& that, fBase.asPath(&a); that.fBase.asPath(&b); REPORTER_ASSERT(reporter, a == b); + REPORTER_ASSERT(reporter, fBase.isEmpty() == that.fBase.isEmpty()); REPORTER_ASSERT(reporter, fAppliedPEKey != that.fAppliedPEKey); REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey); break; @@ -178,10 +188,12 @@ void TestCase::compare(skiatest::Reporter* reporter, const TestCase& that, fBase.asPath(&a); that.fBase.asPath(&b); REPORTER_ASSERT(reporter, a == b); + REPORTER_ASSERT(reporter, fBase.isEmpty() == that.fBase.isEmpty()); REPORTER_ASSERT(reporter, fAppliedPEKey == that.fAppliedPEKey); fAppliedPE.asPath(&a); that.fAppliedPE.asPath(&b); REPORTER_ASSERT(reporter, a == b); + REPORTER_ASSERT(reporter, fAppliedPE.isEmpty() == that.fAppliedPE.isEmpty()); REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey); break; case kAllSame_ComparisonExpecation: @@ -189,14 +201,17 @@ void TestCase::compare(skiatest::Reporter* reporter, const TestCase& that, fBase.asPath(&a); that.fBase.asPath(&b); REPORTER_ASSERT(reporter, a == b); + REPORTER_ASSERT(reporter, fBase.isEmpty() == that.fBase.isEmpty()); REPORTER_ASSERT(reporter, fAppliedPEKey == that.fAppliedPEKey); fAppliedPE.asPath(&a); that.fAppliedPE.asPath(&b); REPORTER_ASSERT(reporter, a == b); + REPORTER_ASSERT(reporter, fAppliedPE.isEmpty() == that.fAppliedPE.isEmpty()); REPORTER_ASSERT(reporter, fAppliedFullKey == that.fAppliedFullKey); fAppliedFull.asPath(&a); that.fAppliedFull.asPath(&b); REPORTER_ASSERT(reporter, a == b); + REPORTER_ASSERT(reporter, fAppliedFull.isEmpty() == that.fAppliedFull.isEmpty()); break; } } @@ -745,6 +760,7 @@ void test_path_effect_makes_empty_shape(skiatest::Reporter* reporter, const GEO& GrShape emptyShape(emptyPath); Key emptyKey; make_key(&emptyKey, emptyShape); + REPORTER_ASSERT(reporter, emptyShape.isEmpty()); SkPaint pe; pe.setPathEffect(EmptyPathEffect::Make()); @@ -752,6 +768,8 @@ void test_path_effect_makes_empty_shape(skiatest::Reporter* reporter, const GEO& REPORTER_ASSERT(reporter, geoCase.appliedFullStyleKey() == emptyKey); REPORTER_ASSERT(reporter, geoCase.appliedPathEffectKey() == emptyKey); REPORTER_ASSERT(reporter, geoCase.appliedPathEffectThenStrokeKey() == emptyKey); + REPORTER_ASSERT(reporter, geoCase.appliedPathEffectShape().isEmpty()); + REPORTER_ASSERT(reporter, geoCase.appliedFullStyleShape().isEmpty()); SkPaint peStroke; peStroke.setPathEffect(EmptyPathEffect::Make()); @@ -761,12 +779,17 @@ void test_path_effect_makes_empty_shape(skiatest::Reporter* reporter, const GEO& REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() == emptyKey); REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == emptyKey); REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectThenStrokeKey() == emptyKey); + REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectShape().isEmpty()); + REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleShape().isEmpty()); } void test_empty_shape(skiatest::Reporter* reporter) { SkPath emptyPath; SkPaint fill; TestCase fillEmptyCase(emptyPath, fill, reporter); + REPORTER_ASSERT(reporter, fillEmptyCase.baseShape().isEmpty()); + REPORTER_ASSERT(reporter, fillEmptyCase.appliedPathEffectShape().isEmpty()); + REPORTER_ASSERT(reporter, fillEmptyCase.appliedFullStyleShape().isEmpty()); Key emptyKey(fillEmptyCase.baseKey()); REPORTER_ASSERT(reporter, emptyKey.count());