diff options
author | Jim Van Verth <jvanverth@google.com> | 2017-07-31 09:34:58 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-31 13:55:32 +0000 |
commit | 1af03d4396a9567e3ca127830676eb4fd5a76266 (patch) | |
tree | 985b377567124e1aab52f46609b4e8ea18919caa /tests | |
parent | 0d67fafa3eccc31e5187c740ee19e1c55b135152 (diff) |
Compute correct bounds for DrawShadowRec.
Bug: skia:6880
Change-Id: Ia8b94e52eec3feb5104d2351bf7a7e6f99101deb
Reviewed-on: https://skia-review.googlesource.com/26370
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ShadowTest.cpp (renamed from tests/ShadowUtilsTest.cpp) | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/ShadowUtilsTest.cpp b/tests/ShadowTest.cpp index c0e20d57e4..8a921d8bc8 100644 --- a/tests/ShadowUtilsTest.cpp +++ b/tests/ShadowTest.cpp @@ -6,6 +6,7 @@ */ #include "SkCanvas.h" +#include "SkDrawShadowInfo.h" #include "SkPath.h" #include "SkShadowTessellator.h" #include "SkShadowUtils.h" @@ -58,3 +59,60 @@ DEF_TEST(ShadowUtils, reporter) { } tessellate_shadow(reporter, path, canvas.getTotalMatrix(), false); } + +void check_xformed_bounds(skiatest::Reporter* reporter, const SkPath& path, const SkMatrix& ctm) { + const SkDrawShadowRec rec = { + SkPoint3::Make(0, 0, 4), + SkPoint3::Make(100, 0, 600), + 800.f, + 0.035f, + 0.25f, + SK_ColorBLACK, + 0 + }; + SkRect bounds; + SkDrawShadowMetrics::GetLocalBounds(path, rec, ctm, &bounds); + ctm.mapRect(&bounds); + + auto verts = SkShadowTessellator::MakeAmbient(path, ctm, rec.fZPlaneParams, true); + if (verts) { + REPORTER_ASSERT(reporter, bounds.contains(verts->bounds())); + } + + SkPoint mapXY = ctm.mapXY(rec.fLightPos.fX, rec.fLightPos.fY); + SkPoint3 devLightPos = SkPoint3::Make(mapXY.fX, mapXY.fY, rec.fLightPos.fZ); + verts = SkShadowTessellator::MakeSpot(path, ctm, rec.fZPlaneParams, devLightPos, + rec.fLightRadius, false); + if (verts) { + REPORTER_ASSERT(reporter, bounds.contains(verts->bounds())); + } +} + +void check_bounds(skiatest::Reporter* reporter, const SkPath& path) { + SkMatrix ctm; + ctm.setTranslate(100, 100); + check_xformed_bounds(reporter, path, ctm); + ctm.postScale(2, 2); + check_xformed_bounds(reporter, path, ctm); + ctm.preRotate(45); + check_xformed_bounds(reporter, path, ctm); + ctm.preSkew(40, -20); + check_xformed_bounds(reporter, path, ctm); + ctm[SkMatrix::kMPersp0] = 0.0001f; + ctm[SkMatrix::kMPersp1] = 12.f; + check_xformed_bounds(reporter, path, ctm); +} + +DEF_TEST(ShadowBounds, reporter) { + SkPath path; + path.addRRect(SkRRect::MakeRectXY(SkRect::MakeLTRB(-50, -20, 40, 30), 4, 4)); + check_bounds(reporter, path); + + path.reset(); + path.addOval(SkRect::MakeLTRB(300, 300, 900, 900)); + check_bounds(reporter, path); + + path.reset(); + path.cubicTo(100, 50, 20, 100, 0, 0); + check_bounds(reporter, path); +} |