Chromium Code Reviews| Index: src/gpu/GrAALinearizingConvexPathRenderer.cpp |
| diff --git a/src/gpu/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/GrAALinearizingConvexPathRenderer.cpp |
| index e03df81def198f76d4bdc09349f726cc7cf4537e..6e672693b369667263f7a0353c8f6c4309a033e8 100644 |
| --- a/src/gpu/GrAALinearizingConvexPathRenderer.cpp |
| +++ b/src/gpu/GrAALinearizingConvexPathRenderer.cpp |
| @@ -23,12 +23,17 @@ |
| #include "SkGeometry.h" |
| #include "SkString.h" |
| #include "SkTraceEvent.h" |
| +#include "SkPathPriv.h" |
| #include "gl/GrGLProcessor.h" |
| #include "gl/GrGLSL.h" |
| #include "gl/GrGLGeometryProcessor.h" |
| #include "gl/builders/GrGLProgramBuilder.h" |
|
robertphillips
2015/06/16 13:13:02
More informative name? Which buffer ?
|
| -#define DEFAULT_BUFFER_SIZE 100 |
| +static const int DEFAULT_BUFFER_SIZE = 100; |
| + |
| +// The thicker the stroke, the harder it is to produce high-quality results using tessellation. For |
| +// the time being, we simply drop back to software rendering above this stroke width. |
| +static const SkScalar kMaxStrokeWidth = 20.0; |
| GrAALinearizingConvexPathRenderer::GrAALinearizingConvexPathRenderer() { |
| } |
| @@ -41,7 +46,21 @@ bool GrAALinearizingConvexPathRenderer::canDrawPath(const GrDrawTarget* target, |
| const SkPath& path, |
| const GrStrokeInfo& stroke, |
| bool antiAlias) const { |
| - return (antiAlias && stroke.isFillStyle() && !path.isInverseFillType() && path.isConvex()); |
| + if (!antiAlias) { |
| + return false; |
| + } |
| + if (path.isInverseFillType()) { |
| + return false; |
| + } |
| + if (!path.isConvex()) { |
| + return false; |
| + } |
| + if (stroke.getStyle() == SkStrokeRec::kStroke_Style) { |
| + return viewMatrix.isSimilarity() && stroke.getWidth() <= kMaxStrokeWidth && |
| + !stroke.isDashed() && SkPathPriv::LastVerbIsClose(path) && |
| + stroke.getJoin() != SkPaint::Join::kRound_Join; |
| + } |
| + return stroke.getStyle() == SkStrokeRec::kFill_Style; |
| } |
| // extract the result vertices and indices from the GrAAConvexTessellator |
| @@ -61,16 +80,15 @@ static void extract_verts(const GrAAConvexTessellator& tess, |
| // Make 'verts' point to the colors |
| verts += sizeof(SkPoint); |
| for (int i = 0; i < tess.numPts(); ++i) { |
| - SkASSERT(tess.depth(i) >= -0.5f && tess.depth(i) <= 0.5f); |
| if (tweakAlphaForCoverage) { |
| - SkASSERT(SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f)) <= 255); |
| - unsigned scale = SkScalarRoundToInt(255.0f * (tess.depth(i) + 0.5f)); |
| + SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255); |
| + unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i)); |
| GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale); |
| *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor; |
| } else { |
| *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color; |
| *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)) = |
| - tess.depth(i) + 0.5f; |
| + tess.coverage(i); |
| } |
| } |
| @@ -98,6 +116,9 @@ public: |
| GrColor fColor; |
| SkMatrix fViewMatrix; |
| SkPath fPath; |
| + SkScalar fStrokeWidth; |
| + SkPaint::Join fJoin; |
| + SkScalar fMiterLimit; |
| }; |
| static GrBatch* Create(const Geometry& geometry) { |
| @@ -159,7 +180,7 @@ public: |
| firstIndex, vertexCount, indexCount); |
| batchTarget->draw(info); |
| } |
| - |
| + |
| void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline) override { |
| bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| @@ -183,8 +204,6 @@ public: |
| vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) : |
| vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); |
| - GrAAConvexTessellator tess; |
| - |
| int instanceCount = fGeoData.count(); |
| int vertexCount = 0; |
| @@ -194,9 +213,8 @@ public: |
| uint8_t* vertices = (uint8_t*) malloc(maxVertices * vertexStride); |
| uint16_t* indices = (uint16_t*) malloc(maxIndices * sizeof(uint16_t)); |
| for (int i = 0; i < instanceCount; i++) { |
| - tess.rewind(); |
| - |
| Geometry& args = fGeoData[i]; |
| + GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMiterLimit); |
| if (!tess.tessellate(args.fViewMatrix, args.fPath)) { |
| continue; |
| @@ -288,7 +306,7 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(GrDrawTarget* target, |
| GrColor color, |
| const SkMatrix& vm, |
| const SkPath& path, |
| - const GrStrokeInfo&, |
| + const GrStrokeInfo& stroke, |
| bool antiAlias) { |
| if (path.isEmpty()) { |
| return true; |
| @@ -297,6 +315,9 @@ bool GrAALinearizingConvexPathRenderer::onDrawPath(GrDrawTarget* target, |
| geometry.fColor = color; |
| geometry.fViewMatrix = vm; |
| geometry.fPath = path; |
| + geometry.fStrokeWidth = stroke.isFillStyle() ? -1.0f : stroke.getWidth(); |
| + geometry.fJoin = stroke.isFillStyle() ? SkPaint::Join::kMiter_Join : stroke.getJoin(); |
| + geometry.fMiterLimit = stroke.getMiter(); |
| SkAutoTUnref<GrBatch> batch(AAFlatteningConvexPathBatch::Create(geometry)); |
| target->drawBatch(pipelineBuilder, batch); |