diff options
author | 2017-02-03 10:33:25 -0500 | |
---|---|---|
committer | 2017-02-03 16:08:46 +0000 | |
commit | 0dda9cb881900241c1c2193ddf3bede72cda898b (patch) | |
tree | dd12f754b75f3a6802944b404dc196f659f6d338 /tests | |
parent | 48ded38da99c1171ba1bb469f6500f8214e9105c (diff) |
Make shadow tessellators fail gracefully and add unit test for this.
Change-Id: I42a9d06a18928588347a6dea2f6150518ba29aa8
Reviewed-on: https://skia-review.googlesource.com/7886
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ShadowUtilsTest.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/ShadowUtilsTest.cpp b/tests/ShadowUtilsTest.cpp new file mode 100644 index 0000000000..adcb5031f4 --- /dev/null +++ b/tests/ShadowUtilsTest.cpp @@ -0,0 +1,61 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkCanvas.h" +#include "SkPath.h" +#include "SkShadowTessellator.h" +#include "SkShadowUtils.h" +#include "Test.h" + +void tessellate_shadow(skiatest::Reporter* reporter, const SkPath& path, bool expectSuccess) { + static constexpr SkScalar kRadius = 2.f; + static constexpr SkColor kUmbraColor = 0xFFFFFFFF; + static constexpr SkColor kPenumbraColor = 0x20202020; + auto verts = SkShadowVertices::MakeAmbient(path, kRadius, kUmbraColor, kPenumbraColor, true); + if (expectSuccess != SkToBool(verts)) { + ERRORF(reporter, "Expected shadow tessellation to % but it did not.", + expectSuccess ? "succeed" : "fail"); + } + verts = SkShadowVertices::MakeAmbient(path, kRadius, kUmbraColor, kPenumbraColor, false); + if (expectSuccess != SkToBool(verts)) { + ERRORF(reporter, "Expected shadow tessellation to % but it did not.", + expectSuccess ? "succeed" : "fail"); + } + verts = SkShadowVertices::MakeSpot(path, 1.5f, {0, 0}, kRadius, kUmbraColor, kPenumbraColor, + false); + if (expectSuccess != SkToBool(verts)) { + ERRORF(reporter, "Expected shadow tessellation to % but it did not.", + expectSuccess ? "succeed" : "fail"); + } + verts = SkShadowVertices::MakeSpot(path, 1.5f, {0, 0}, kRadius, kUmbraColor, kPenumbraColor, + true); + if (expectSuccess != SkToBool(verts)) { + ERRORF(reporter, "Expected shadow tessellation to % but it did not.", + expectSuccess ? "succeed" : "fail"); + } +} + +DEF_TEST(ShadowUtils, reporter) { + SkCanvas canvas(100, 100); + // Currently SkShadowUtils doesn't really stupport cubics when compiled without SK_SUPPORT_GPU. + // However, this should now crash. + SkPath path; + path.cubicTo(100, 50, 20, 100, 0, 0); + tessellate_shadow(reporter, path, (bool)SK_SUPPORT_GPU); + + // This line segment has no area and no shadow. + path.reset(); + path.lineTo(10.f, 10.f); + tessellate_shadow(reporter, path, false); + + // A series of colinear line segments + path.reset(); + for (int i = 0; i < 10; ++i) { + path.lineTo((SkScalar)i, (SkScalar)i); + } + tessellate_shadow(reporter, path, false); +} |