OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrDefaultPathRenderer.h" | 8 #include "GrDefaultPathRenderer.h" |
9 | 9 |
10 #include "GrBatchTarget.h" | 10 #include "GrBatchTarget.h" |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 srcSpaceTolSqd, vert, | 202 srcSpaceTolSqd, vert, |
203 GrPathUtils::quadraticPointCount(pts, srcSpaceTol)); | 203 GrPathUtils::quadraticPointCount(pts, srcSpaceTol)); |
204 if (indexed) { | 204 if (indexed) { |
205 for (uint16_t i = 0; i < numPts; ++i) { | 205 for (uint16_t i = 0; i < numPts; ++i) { |
206 append_countour_edge_indices(isHairline, subpathIdxStart, | 206 append_countour_edge_indices(isHairline, subpathIdxStart, |
207 firstQPtIdx + i, idx); | 207 firstQPtIdx + i, idx); |
208 } | 208 } |
209 } | 209 } |
210 } | 210 } |
211 | 211 |
212 class DefaultPathBatch : public GrBatch { | 212 class DefaultPathBatch : public GrVertexBatch { |
213 public: | 213 public: |
214 struct Geometry { | 214 struct Geometry { |
215 GrColor fColor; | 215 GrColor fColor; |
216 SkPath fPath; | 216 SkPath fPath; |
217 SkScalar fTolerance; | 217 SkScalar fTolerance; |
218 }; | 218 }; |
219 | 219 |
220 static GrBatch* Create(const Geometry& geometry, uint8_t coverage, const SkM
atrix& viewMatrix, | 220 static GrDrawBatch* Create(const Geometry& geometry, uint8_t coverage, |
221 bool isHairline, const SkRect& devBounds) { | 221 const SkMatrix& viewMatrix, bool isHairline, |
| 222 const SkRect& devBounds) { |
222 return SkNEW_ARGS(DefaultPathBatch, (geometry, coverage, viewMatrix, isH
airline, | 223 return SkNEW_ARGS(DefaultPathBatch, (geometry, coverage, viewMatrix, isH
airline, |
223 devBounds)); | 224 devBounds)); |
224 } | 225 } |
225 | 226 |
226 const char* name() const override { return "DefaultPathBatch"; } | 227 const char* name() const override { return "DefaultPathBatch"; } |
227 | 228 |
228 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 229 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
229 // When this is called on a batch, there is only one geometry bundle | 230 // When this is called on a batch, there is only one geometry bundle |
230 out->setKnownFourComponents(fGeoData[0].fColor); | 231 out->setKnownFourComponents(fGeoData[0].fColor); |
231 } | 232 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 this->initClassID<DefaultPathBatch>(); | 381 this->initClassID<DefaultPathBatch>(); |
381 fBatch.fCoverage = coverage; | 382 fBatch.fCoverage = coverage; |
382 fBatch.fIsHairline = isHairline; | 383 fBatch.fIsHairline = isHairline; |
383 fBatch.fViewMatrix = viewMatrix; | 384 fBatch.fViewMatrix = viewMatrix; |
384 fGeoData.push_back(geometry); | 385 fGeoData.push_back(geometry); |
385 | 386 |
386 this->setBounds(devBounds); | 387 this->setBounds(devBounds); |
387 } | 388 } |
388 | 389 |
389 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 390 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
390 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel
ine(), t->bounds(), | 391 DefaultPathBatch* that = t->cast<DefaultPathBatch>(); |
391 caps)) { | 392 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 393 that->bounds(), caps)) { |
392 return false; | 394 return false; |
393 } | 395 } |
394 | 396 |
395 DefaultPathBatch* that = t->cast<DefaultPathBatch>(); | |
396 | |
397 if (this->color() != that->color()) { | 397 if (this->color() != that->color()) { |
398 return false; | 398 return false; |
399 } | 399 } |
400 | 400 |
401 if (this->coverage() != that->coverage()) { | 401 if (this->coverage() != that->coverage()) { |
402 return false; | 402 return false; |
403 } | 403 } |
404 | 404 |
405 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { | 405 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
406 return false; | 406 return false; |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 } else { | 690 } else { |
691 if (passCount > 1) { | 691 if (passCount > 1) { |
692 pipelineBuilder->setDisableColorXPFactory(); | 692 pipelineBuilder->setDisableColorXPFactory(); |
693 } | 693 } |
694 | 694 |
695 DefaultPathBatch::Geometry geometry; | 695 DefaultPathBatch::Geometry geometry; |
696 geometry.fColor = color; | 696 geometry.fColor = color; |
697 geometry.fPath = path; | 697 geometry.fPath = path; |
698 geometry.fTolerance = srcSpaceTol; | 698 geometry.fTolerance = srcSpaceTol; |
699 | 699 |
700 SkAutoTUnref<GrBatch> batch(DefaultPathBatch::Create(geometry, newCo
verage, viewMatrix, | 700 SkAutoTUnref<GrDrawBatch> batch(DefaultPathBatch::Create(geometry, n
ewCoverage, |
701 isHairline, dev
Bounds)); | 701 viewMatrix,
isHairline, |
| 702 devBounds))
; |
702 | 703 |
703 target->drawBatch(*pipelineBuilder, batch); | 704 target->drawBatch(*pipelineBuilder, batch); |
704 } | 705 } |
705 } | 706 } |
706 return true; | 707 return true; |
707 } | 708 } |
708 | 709 |
709 bool GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { | 710 bool GrDefaultPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) const { |
710 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. | 711 // this class can draw any path with any fill but doesn't do any anti-aliasi
ng. |
711 return !args.fAntiAlias && (args.fStroke->isFillStyle() || | 712 return !args.fAntiAlias && (args.fStroke->isFillStyle() || |
(...skipping 15 matching lines...) Expand all Loading... |
727 SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType()); | 728 SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType()); |
728 SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType()); | 729 SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType()); |
729 this->internalDrawPath(args.fTarget, args.fPipelineBuilder, GrColor_WHITE, *
args.fViewMatrix, | 730 this->internalDrawPath(args.fTarget, args.fPipelineBuilder, GrColor_WHITE, *
args.fViewMatrix, |
730 *args.fPath, *args.fStroke, true); | 731 *args.fPath, *args.fStroke, true); |
731 } | 732 } |
732 | 733 |
733 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 734 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
734 | 735 |
735 #ifdef GR_TEST_UTILS | 736 #ifdef GR_TEST_UTILS |
736 | 737 |
737 BATCH_TEST_DEFINE(DefaultPathBatch) { | 738 DRAW_BATCH_TEST_DEFINE(DefaultPathBatch) { |
738 GrColor color = GrRandomColor(random); | 739 GrColor color = GrRandomColor(random); |
739 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 740 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
740 | 741 |
741 // For now just hairlines because the other types of draws require two batch
es. | 742 // For now just hairlines because the other types of draws require two batch
es. |
742 // TODO we should figure out a way to combine the stencil and cover steps in
to one batch | 743 // TODO we should figure out a way to combine the stencil and cover steps in
to one batch |
743 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); | 744 GrStrokeInfo stroke(SkStrokeRec::kHairline_InitStyle); |
744 SkPath path = GrTest::TestPath(random); | 745 SkPath path = GrTest::TestPath(random); |
745 | 746 |
746 // Compute srcSpaceTol | 747 // Compute srcSpaceTol |
747 SkRect bounds = path.getBounds(); | 748 SkRect bounds = path.getBounds(); |
748 SkScalar tol = GrPathUtils::kDefaultTolerance; | 749 SkScalar tol = GrPathUtils::kDefaultTolerance; |
749 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bou
nds); | 750 SkScalar srcSpaceTol = GrPathUtils::scaleToleranceToSrc(tol, viewMatrix, bou
nds); |
750 | 751 |
751 DefaultPathBatch::Geometry geometry; | 752 DefaultPathBatch::Geometry geometry; |
752 geometry.fColor = color; | 753 geometry.fColor = color; |
753 geometry.fPath = path; | 754 geometry.fPath = path; |
754 geometry.fTolerance = srcSpaceTol; | 755 geometry.fTolerance = srcSpaceTol; |
755 | 756 |
756 viewMatrix.mapRect(&bounds); | 757 viewMatrix.mapRect(&bounds); |
757 uint8_t coverage = GrRandomCoverage(random); | 758 uint8_t coverage = GrRandomCoverage(random); |
758 return DefaultPathBatch::Create(geometry, coverage, viewMatrix, true, bounds
); | 759 return DefaultPathBatch::Create(geometry, coverage, viewMatrix, true, bounds
); |
759 } | 760 } |
760 | 761 |
761 #endif | 762 #endif |
OLD | NEW |