From 622d3aded25f7ddf220634546cc3da12bf30d5a6 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Thu, 7 May 2015 08:13:11 -0700 Subject: [PATCH] Adding unit tests for limited subset of DefaultPathRenderer BUG=skia: Review URL: https://codereview.chromium.org/1129203002 --- src/gpu/GrDefaultPathRenderer.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/gpu/GrDefaultPathRenderer.cpp b/src/gpu/GrDefaultPathRenderer.cpp index e1ba1c8451..41e4d390c3 100644 --- a/src/gpu/GrDefaultPathRenderer.cpp +++ b/src/gpu/GrDefaultPathRenderer.cpp @@ -9,6 +9,7 @@ #include "GrBatch.h" #include "GrBatchTarget.h" +#include "GrBatchTest.h" #include "GrBufferAllocPool.h" #include "GrContext.h" #include "GrDefaultGeoProcFactory.h" @@ -748,3 +749,33 @@ void GrDefaultPathRenderer::onStencilPath(GrDrawTarget* target, SkASSERT(SkPath::kInverseWinding_FillType != path.getFillType()); this->internalDrawPath(target, pipelineBuilder, GrColor_WHITE, viewMatrix, path, stroke, true); } + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +#ifdef GR_TEST_UTILS + +BATCH_TEST_DEFINE(DefaultPathRenderer) { + GrColor color = GrRandomColor(random); + SkMatrix viewMatrix = GrTest::TestMatrix(random); + + // For now just hairlines because the other types of draws require two batches. + // TODO we should figure out a way to combine the stencil and cover steps into one batch + GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); + SkPath path = GrTest::TestPath(random); + + // Compute srcSpaceTol + SkRect bounds = path.getBounds(); + SkScalar tol = GrPathUtils::kDefaultTolerance; + SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bounds); + + DefaultPathBatch::Geometry geometry; + geometry.fColor = color; + geometry.fPath = path; + geometry.fTolerance = srcSpaceTol; + + viewMatrix.mapRect(&bounds); + uint8_t coverage = GrRandomCoverage(random); + return DefaultPathBatch::Create(geometry, coverage, viewMatrix, true, bounds); +} + +#endif -- 2.34.1