| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrAAStrokeRectBatch.h" | 8 #include "GrAAStrokeRectBatch.h" |
| 9 | 9 |
| 10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 // to draw the outside of the octagon. Because there are 8 vertices on the o
uter | 573 // to draw the outside of the octagon. Because there are 8 vertices on the o
uter |
| 574 // edge, while vertex number of inner edge is 4, the same as miter-stroke. | 574 // edge, while vertex number of inner edge is 4, the same as miter-stroke. |
| 575 if (!miterStroke) { | 575 if (!miterStroke) { |
| 576 devOutside->inset(0, ry); | 576 devOutside->inset(0, ry); |
| 577 devOutsideAssist->outset(0, ry); | 577 devOutsideAssist->outset(0, ry); |
| 578 } | 578 } |
| 579 } | 579 } |
| 580 | 580 |
| 581 namespace GrAAStrokeRectBatch { | 581 namespace GrAAStrokeRectBatch { |
| 582 | 582 |
| 583 GrDrawBatch* Create(GrColor color, | 583 GrDrawBatch* CreateFillBetweenRects(GrColor color, |
| 584 const SkMatrix& viewMatrix, | 584 const SkMatrix& viewMatrix, |
| 585 const SkRect& devOutside, | 585 const SkRect& devOutside, |
| 586 const SkRect& devOutsideAssist, | 586 const SkRect& devInside) { |
| 587 const SkRect& devInside, | 587 SkASSERT(!devOutside.isEmpty()) |
| 588 bool miterStroke, | 588 SkASSERT(!devInside.isEmpty()) |
| 589 bool degenerate) { | 589 AAStrokeRectBatch* batch = AAStrokeRectBatch::Create(viewMatrix, true); |
| 590 AAStrokeRectBatch* batch = AAStrokeRectBatch::Create(viewMatrix, miterStroke
); | 590 batch->append(color, devOutside, devOutside, devInside, false); |
| 591 batch->append(color, devOutside, devOutsideAssist, devInside, degenerate); | |
| 592 batch->init(); | 591 batch->init(); |
| 593 return batch; | 592 return batch; |
| 594 } | 593 } |
| 595 | 594 |
| 596 GrDrawBatch* Create(GrColor color, | 595 GrDrawBatch* Create(GrColor color, |
| 597 const SkMatrix& viewMatrix, | 596 const SkMatrix& viewMatrix, |
| 598 const SkRect& rect, | 597 const SkRect& rect, |
| 599 const SkStrokeRec& stroke) { | 598 const SkStrokeRec& stroke) { |
| 600 bool isMiterStroke = is_miter(stroke); | 599 bool isMiterStroke = is_miter(stroke); |
| 601 AAStrokeRectBatch* batch = AAStrokeRectBatch::Create(viewMatrix, isMiterStro
ke); | 600 AAStrokeRectBatch* batch = AAStrokeRectBatch::Create(viewMatrix, isMiterStro
ke); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 635 |
| 637 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 636 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 638 | 637 |
| 639 #ifdef GR_TEST_UTILS | 638 #ifdef GR_TEST_UTILS |
| 640 | 639 |
| 641 #include "GrBatchTest.h" | 640 #include "GrBatchTest.h" |
| 642 | 641 |
| 643 DRAW_BATCH_TEST_DEFINE(AAStrokeRectBatch) { | 642 DRAW_BATCH_TEST_DEFINE(AAStrokeRectBatch) { |
| 644 bool miterStroke = random->nextBool(); | 643 bool miterStroke = random->nextBool(); |
| 645 | 644 |
| 646 // Create mock stroke rect | 645 // Create either a empty rect or a non-empty rect. |
| 647 SkRect outside = GrTest::TestRect(random); | 646 SkRect rect = random->nextBool() ? SkRect::MakeXYWH(10, 10, 50, 40) : |
| 648 SkScalar minDim = SkMinScalar(outside.width(), outside.height()); | 647 SkRect::MakeXYWH(6, 7, 0, 0); |
| 649 SkScalar strokeWidth = minDim * 0.1f; | 648 SkScalar minDim = SkMinScalar(rect.width(), rect.height()); |
| 650 SkRect outsideAssist = outside; | 649 SkScalar strokeWidth = random->nextUScalar1() * minDim; |
| 651 outsideAssist.outset(strokeWidth, strokeWidth); | |
| 652 SkRect inside = outside; | |
| 653 inside.inset(strokeWidth, strokeWidth); | |
| 654 | 650 |
| 655 GrColor color = GrRandomColor(random); | 651 GrColor color = GrRandomColor(random); |
| 656 | 652 |
| 657 return GrAAStrokeRectBatch::Create(color, GrTest::TestMatrix(random), outsid
e, outsideAssist, | 653 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); |
| 658 inside, miterStroke, inside.isFinite() &&
inside.isEmpty()); | 654 rec.setStrokeStyle(strokeWidth); |
| 655 rec.setStrokeParams(SkPaint::kButt_Cap, |
| 656 miterStroke ? SkPaint::kMiter_Join : SkPaint::kBevel_Joi
n, |
| 657 1.f); |
| 658 SkMatrix matrix = GrTest::TestMatrixRectStaysRect(random); |
| 659 return GrAAStrokeRectBatch::Create(color, matrix, rect, rec); |
| 659 } | 660 } |
| 660 | 661 |
| 661 #endif | 662 #endif |
| OLD | NEW |