diff options
author | joshualitt <joshualitt@chromium.org> | 2015-05-07 13:06:41 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-07 13:06:42 -0700 |
commit | 2fbd4068bde6a9fb50341c0bdfbb8bf18b70d015 (patch) | |
tree | 66315ce7a175ec4d25fd89f21ea2e7cdd97f5931 | |
parent | 96287f7af7ff6aaa48b8d28ec6b7b79836da2d7c (diff) |
tesselating path renderer unit tests
BUG=skia:
Review URL: https://codereview.chromium.org/1127183006
-rw-r--r-- | include/gpu/GrTestUtils.h | 1 | ||||
-rw-r--r-- | src/gpu/GrTessellatingPathRenderer.cpp | 21 | ||||
-rw-r--r-- | src/gpu/GrTestUtils.cpp | 19 |
3 files changed, 38 insertions, 3 deletions
diff --git a/include/gpu/GrTestUtils.h b/include/gpu/GrTestUtils.h index a98548bb2f..2109ad657b 100644 --- a/include/gpu/GrTestUtils.h +++ b/include/gpu/GrTestUtils.h @@ -27,6 +27,7 @@ namespace GrTest { const SkMatrix& TestMatrix(SkRandom*); const SkMatrix& TestMatrixPreservesRightAngles(SkRandom*); const SkMatrix& TestMatrixRectStaysRect(SkRandom*); +const SkMatrix& TestMatrixInvertible(SkRandom*); const SkRect& TestRect(SkRandom*); const SkRRect& TestRRectSimple(SkRandom*); const SkPath& TestPath(SkRandom*); diff --git a/src/gpu/GrTessellatingPathRenderer.cpp b/src/gpu/GrTessellatingPathRenderer.cpp index 24d4068cdb..e2707a9df3 100644 --- a/src/gpu/GrTessellatingPathRenderer.cpp +++ b/src/gpu/GrTessellatingPathRenderer.cpp @@ -9,6 +9,7 @@ #include "GrBatch.h" #include "GrBatchTarget.h" +#include "GrBatchTest.h" #include "GrDefaultGeoProcFactory.h" #include "GrPathUtils.h" #include "GrVertices.h" @@ -1514,3 +1515,23 @@ bool GrTessellatingPathRenderer::onDrawPath(GrDrawTarget* target, return true; } + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef GR_TEST_UTILS + +BATCH_TEST_DEFINE(TesselatingPathRenderer) { + GrColor color = GrRandomColor(random); + SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random); + SkPath path = GrTest::TestPath(random); + SkRect clipBounds = GrTest::TestRect(random); + SkMatrix vmi; + bool result = viewMatrix.invert(&vmi); + if (!result) { + SkFAIL("Cannot invert matrix\n"); + } + vmi.mapRect(&clipBounds); + return TessellatingPathBatch::Create(color, path, viewMatrix, clipBounds); +} + +#endif diff --git a/src/gpu/GrTestUtils.cpp b/src/gpu/GrTestUtils.cpp index 163fb56389..0bb4044eaa 100644 --- a/src/gpu/GrTestUtils.cpp +++ b/src/gpu/GrTestUtils.cpp @@ -12,9 +12,9 @@ #ifdef GR_TEST_UTILS -namespace GrTest { -const SkMatrix& TestMatrix(SkRandom* random) { +static const SkMatrix& test_matrix(SkRandom* random, bool includePerspective) { static SkMatrix gMatrices[5]; + static const int kPerspectiveCount = 1; static bool gOnce; if (!gOnce) { gOnce = true; @@ -24,13 +24,24 @@ const SkMatrix& TestMatrix(SkRandom* random) { gMatrices[3].setRotate(SkIntToScalar(185)); gMatrices[3].postTranslate(SkIntToScalar(66), SkIntToScalar(-33)); gMatrices[3].postScale(SkIntToScalar(2), SK_ScalarHalf); + + // Perspective matrices gMatrices[4].setRotate(SkIntToScalar(215)); gMatrices[4].set(SkMatrix::kMPersp0, 0.00013f); gMatrices[4].set(SkMatrix::kMPersp1, -0.000039f); } - return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))]; + + uint32_t count = static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)); + if (includePerspective) { + return gMatrices[random->nextULessThan(count)]; + } else { + return gMatrices[random->nextULessThan(count - kPerspectiveCount)]; + } } +namespace GrTest { +const SkMatrix& TestMatrix(SkRandom* random) { return test_matrix(random, true); } + const SkMatrix& TestMatrixPreservesRightAngles(SkRandom* random) { static SkMatrix gMatrices[5]; static bool gOnce; @@ -83,6 +94,8 @@ const SkMatrix& TestMatrixRectStaysRect(SkRandom* random) { return gMatrices[random->nextULessThan(static_cast<uint32_t>(SK_ARRAY_COUNT(gMatrices)))]; } +const SkMatrix& TestMatrixInvertible(SkRandom* random) { return test_matrix(random, false); } + const SkRect& TestRect(SkRandom* random) { static SkRect gRects[7]; static bool gOnce; |