Chromium Code Reviews| Index: src/gpu/batches/GrNonAAStrokeRectBatch.cpp |
| diff --git a/src/gpu/batches/GrNonAAStrokeRectBatch.cpp b/src/gpu/batches/GrNonAAStrokeRectBatch.cpp |
| index a38760c362ea14b8f04796bf07f9b5fe8c8972f2..19dd3a80f65cd787825df28aef2d6e6b122aea15 100644 |
| --- a/src/gpu/batches/GrNonAAStrokeRectBatch.cpp |
| +++ b/src/gpu/batches/GrNonAAStrokeRectBatch.cpp |
| @@ -211,29 +211,30 @@ private: |
| typedef GrVertexBatch INHERITED; |
| }; |
| +// Allow all hairlines and all miters, so long as the miter limit doesn't produce beveled corners. |
| +inline static bool allowed_stroke(const SkStrokeRec& stroke) { |
| + SkASSERT(stroke.getStyle() == SkStrokeRec::kStroke_Style || |
| + stroke.getStyle() == SkStrokeRec::kHairline_Style); |
| + return !stroke.getWidth() || |
| + (stroke.getJoin() == SkPaint::kMiter_Join && stroke.getMiter() > SK_ScalarSqrt2); |
| +} |
| + |
| namespace GrNonAAStrokeRectBatch { |
| GrDrawBatch* Create(GrColor color, |
| const SkMatrix& viewMatrix, |
| const SkRect& rect, |
| - SkScalar strokeWidth, |
| + const SkStrokeRec& stroke, |
| bool snapToPixelCenters) { |
| + if (!allowed_stroke(stroke)) { |
| + return nullptr; |
| + } |
| NonAAStrokeRectBatch* batch = NonAAStrokeRectBatch::Create(); |
| - batch->append(color, viewMatrix, rect, strokeWidth); |
| + batch->append(color, viewMatrix, rect, stroke.getWidth()); |
| batch->init(snapToPixelCenters); |
| return batch; |
| } |
| -void Append(GrBatch* origBatch, |
| - GrColor color, |
| - const SkMatrix& viewMatrix, |
| - const SkRect& rect, |
| - SkScalar strokeWidth, |
| - bool snapToPixelCenters) { |
| - NonAAStrokeRectBatch* batch = origBatch->cast<NonAAStrokeRectBatch>(); |
| - batch->appendAndUpdateBounds(color, viewMatrix, rect, strokeWidth, snapToPixelCenters); |
| -} |
| - |
| }; |
| #ifdef GR_TEST_UTILS |
| @@ -243,8 +244,13 @@ DRAW_BATCH_TEST_DEFINE(NonAAStrokeRectBatch) { |
| GrColor color = GrRandomColor(random); |
| SkRect rect = GrTest::TestRect(random); |
| SkScalar strokeWidth = random->nextBool() ? 0.0f : 1.0f; |
|
robertphillips
2016/07/06 17:08:30
Do we care about testing kRound_Join here ?
bsalomon
2016/07/06 17:13:40
It would fail unless we're in hairline mode, in wh
bsalomon
2016/07/06 17:40:50
I modified it to always use miter since bevel is a
|
| - |
| - return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeWidth, random->nextBool()); |
| + SkPaint::Join join = random->nextBool() ? SkPaint::kBevel_Join : SkPaint::kMiter_Join; |
| + SkPaint paint; |
| + paint.setStrokeWidth(strokeWidth); |
| + paint.setStyle(SkPaint::kStroke_Style); |
| + paint.setStrokeJoin(join); |
| + SkStrokeRec strokeRec(paint); |
| + return GrNonAAStrokeRectBatch::Create(color, viewMatrix, rect, strokeRec, random->nextBool()); |
| } |
| #endif |