| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 DEFINE_BATCH_CLASS_ID | 121 DEFINE_BATCH_CLASS_ID |
| 122 | 122 |
| 123 AAStrokeRectBatch(GrColor color, const SkMatrix& viewMatrix, | 123 AAStrokeRectBatch(GrColor color, const SkMatrix& viewMatrix, |
| 124 const SkRect& devOutside, const SkRect& devInside) | 124 const SkRect& devOutside, const SkRect& devInside) |
| 125 : INHERITED(ClassID()) | 125 : INHERITED(ClassID()) |
| 126 , fViewMatrix(viewMatrix) { | 126 , fViewMatrix(viewMatrix) { |
| 127 SkASSERT(!devOutside.isEmpty()) | 127 SkASSERT(!devOutside.isEmpty()) |
| 128 SkASSERT(!devInside.isEmpty()) | 128 SkASSERT(!devInside.isEmpty()) |
| 129 | 129 |
| 130 fGeoData.emplace_back(Geometry{color, devOutside, devOutside, devInside,
false}); | 130 fGeoData.emplace_back(Geometry{color, devOutside, devOutside, devInside,
false}); |
| 131 fBounds = devOutside; | 131 this->setBounds(devOutside, HasAABloat::kYes, IsZeroArea::kNo); |
| 132 fMiterStroke = true; | 132 fMiterStroke = true; |
| 133 } | 133 } |
| 134 | 134 |
| 135 static GrDrawBatch* Create(GrColor color, const SkMatrix& viewMatrix, const
SkRect& rect, | 135 static GrDrawBatch* Create(GrColor color, const SkMatrix& viewMatrix, const
SkRect& rect, |
| 136 const SkStrokeRec& stroke) { | 136 const SkStrokeRec& stroke) { |
| 137 bool isMiter; | 137 bool isMiter; |
| 138 if (!allowed_stroke(stroke, &isMiter)) { | 138 if (!allowed_stroke(stroke, &isMiter)) { |
| 139 return nullptr; | 139 return nullptr; |
| 140 } | 140 } |
| 141 | 141 |
| 142 AAStrokeRectBatch* batch = new AAStrokeRectBatch(); | 142 AAStrokeRectBatch* batch = new AAStrokeRectBatch(); |
| 143 batch->fMiterStroke = isMiter; | 143 batch->fMiterStroke = isMiter; |
| 144 Geometry& geo = batch->fGeoData.push_back(); | 144 Geometry& geo = batch->fGeoData.push_back(); |
| 145 compute_rects(&geo.fDevOutside, &geo.fDevOutsideAssist, &geo.fDevInside,
&geo.fDegenerate, | 145 compute_rects(&geo.fDevOutside, &geo.fDevOutsideAssist, &geo.fDevInside,
&geo.fDegenerate, |
| 146 viewMatrix, rect, stroke.getWidth(), isMiter); | 146 viewMatrix, rect, stroke.getWidth(), isMiter); |
| 147 geo.fColor = color; | 147 geo.fColor = color; |
| 148 batch->fBounds = geo.fDevOutside; | 148 batch->setBounds(geo.fDevOutside, HasAABloat::kYes, IsZeroArea::kNo); |
| 149 batch->fBounds.join(geo.fDevOutsideAssist); | |
| 150 batch->fViewMatrix = viewMatrix; | 149 batch->fViewMatrix = viewMatrix; |
| 151 return batch; | 150 return batch; |
| 152 } | 151 } |
| 153 | 152 |
| 154 const char* name() const override { return "AAStrokeRect"; } | 153 const char* name() const override { return "AAStrokeRect"; } |
| 155 | 154 |
| 156 void computePipelineOptimizations(GrInitInvariantOutput* color, | 155 void computePipelineOptimizations(GrInitInvariantOutput* color, |
| 157 GrInitInvariantOutput* coverage, | 156 GrInitInvariantOutput* coverage, |
| 158 GrBatchToXPOverrides* overrides) const ove
rride { | 157 GrBatchToXPOverrides* overrides) const ove
rride { |
| 159 // When this is called on a batch, there is only one geometry bundle | 158 // When this is called on a batch, there is only one geometry bundle |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 // In the event of two batches, one who can tweak, one who cannot, we just f
all back to | 405 // In the event of two batches, one who can tweak, one who cannot, we just f
all back to |
| 407 // not tweaking | 406 // not tweaking |
| 408 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()) { | 407 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()) { |
| 409 fBatch.fCanTweakAlphaForCoverage = false; | 408 fBatch.fCanTweakAlphaForCoverage = false; |
| 410 } | 409 } |
| 411 | 410 |
| 412 if (this->color() != that->color()) { | 411 if (this->color() != that->color()) { |
| 413 fBatch.fColor = GrColor_ILLEGAL; | 412 fBatch.fColor = GrColor_ILLEGAL; |
| 414 } | 413 } |
| 415 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); | 414 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
| 416 this->joinBounds(that->bounds()); | 415 this->joinBounds(*that); |
| 417 return true; | 416 return true; |
| 418 } | 417 } |
| 419 | 418 |
| 420 static void setup_scale(int* scale, SkScalar inset) { | 419 static void setup_scale(int* scale, SkScalar inset) { |
| 421 if (inset < SK_ScalarHalf) { | 420 if (inset < SK_ScalarHalf) { |
| 422 *scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); | 421 *scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); |
| 423 SkASSERT(*scale >= 0 && *scale <= 255); | 422 SkASSERT(*scale >= 0 && *scale <= 255); |
| 424 } else { | 423 } else { |
| 425 *scale = 0xff; | 424 *scale = 0xff; |
| 426 } | 425 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); | 613 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); |
| 615 rec.setStrokeStyle(strokeWidth); | 614 rec.setStrokeStyle(strokeWidth); |
| 616 rec.setStrokeParams(SkPaint::kButt_Cap, | 615 rec.setStrokeParams(SkPaint::kButt_Cap, |
| 617 miterStroke ? SkPaint::kMiter_Join : SkPaint::kBevel_Joi
n, | 616 miterStroke ? SkPaint::kMiter_Join : SkPaint::kBevel_Joi
n, |
| 618 1.f); | 617 1.f); |
| 619 SkMatrix matrix = GrTest::TestMatrixRectStaysRect(random); | 618 SkMatrix matrix = GrTest::TestMatrixRectStaysRect(random); |
| 620 return GrAAStrokeRectBatch::Create(color, matrix, rect, rec); | 619 return GrAAStrokeRectBatch::Create(color, matrix, rect, rec); |
| 621 } | 620 } |
| 622 | 621 |
| 623 #endif | 622 #endif |
| OLD | NEW |