| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrDashingEffect.h" | 8 #include "GrDashingEffect.h" |
| 9 | 9 |
| 10 #include "GrBatchTarget.h" | 10 #include "GrBatchTarget.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 * This GrGeometryProcessor is meant for dashed lines that only have a single on
/off interval pair. | 236 * This GrGeometryProcessor is meant for dashed lines that only have a single on
/off interval pair. |
| 237 * Bounding geometry is rendered and the effect computes coverage based on the f
ragment's | 237 * Bounding geometry is rendered and the effect computes coverage based on the f
ragment's |
| 238 * position relative to the dashed line. | 238 * position relative to the dashed line. |
| 239 */ | 239 */ |
| 240 static GrGeometryProcessor* create_dash_gp(GrColor, | 240 static GrGeometryProcessor* create_dash_gp(GrColor, |
| 241 DashAAMode aaMode, | 241 DashAAMode aaMode, |
| 242 DashCap cap, | 242 DashCap cap, |
| 243 const SkMatrix& localMatrix, | 243 const SkMatrix& localMatrix, |
| 244 bool usesLocalCoords); | 244 bool usesLocalCoords); |
| 245 | 245 |
| 246 class DashBatch : public GrBatch { | 246 class DashBatch : public GrVertexBatch { |
| 247 public: | 247 public: |
| 248 struct Geometry { | 248 struct Geometry { |
| 249 GrColor fColor; | 249 GrColor fColor; |
| 250 SkMatrix fViewMatrix; | 250 SkMatrix fViewMatrix; |
| 251 SkMatrix fSrcRotInv; | 251 SkMatrix fSrcRotInv; |
| 252 SkPoint fPtsRot[2]; | 252 SkPoint fPtsRot[2]; |
| 253 SkScalar fSrcStrokeWidth; | 253 SkScalar fSrcStrokeWidth; |
| 254 SkScalar fPhase; | 254 SkScalar fPhase; |
| 255 SkScalar fIntervals[2]; | 255 SkScalar fIntervals[2]; |
| 256 SkScalar fParallelScale; | 256 SkScalar fParallelScale; |
| 257 SkScalar fPerpendicularScale; | 257 SkScalar fPerpendicularScale; |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 static GrBatch* Create(const Geometry& geometry, SkPaint::Cap cap, DashAAMod
e aaMode, | 260 static GrDrawBatch* Create(const Geometry& geometry, SkPaint::Cap cap, DashA
AMode aaMode, |
| 261 bool fullDash) { | 261 bool fullDash) { |
| 262 return SkNEW_ARGS(DashBatch, (geometry, cap, aaMode, fullDash)); | 262 return SkNEW_ARGS(DashBatch, (geometry, cap, aaMode, fullDash)); |
| 263 } | 263 } |
| 264 | 264 |
| 265 const char* name() const override { return "DashBatch"; } | 265 const char* name() const override { return "DashBatch"; } |
| 266 | 266 |
| 267 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 267 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 268 // When this is called on a batch, there is only one geometry bundle | 268 // When this is called on a batch, there is only one geometry bundle |
| 269 out->setKnownFourComponents(fGeoData[0].fColor); | 269 out->setKnownFourComponents(fGeoData[0].fColor); |
| 270 } | 270 } |
| 271 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 271 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 fBounds.set(geometry.fPtsRot[0], geometry.fPtsRot[1]); | 611 fBounds.set(geometry.fPtsRot[0], geometry.fPtsRot[1]); |
| 612 fBounds.outset(xBloat, halfStrokeWidth); | 612 fBounds.outset(xBloat, halfStrokeWidth); |
| 613 | 613 |
| 614 // Note, we actually create the combined matrix here, and save the work | 614 // Note, we actually create the combined matrix here, and save the work |
| 615 SkMatrix& combinedMatrix = fGeoData[0].fSrcRotInv; | 615 SkMatrix& combinedMatrix = fGeoData[0].fSrcRotInv; |
| 616 combinedMatrix.postConcat(geometry.fViewMatrix); | 616 combinedMatrix.postConcat(geometry.fViewMatrix); |
| 617 combinedMatrix.mapRect(&fBounds); | 617 combinedMatrix.mapRect(&fBounds); |
| 618 } | 618 } |
| 619 | 619 |
| 620 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 620 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
| 621 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel
ine(), t->bounds(), | 621 DashBatch* that = t->cast<DashBatch>(); |
| 622 caps)) { | 622 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 623 that->bounds(), caps)) { |
| 623 return false; | 624 return false; |
| 624 } | 625 } |
| 625 | 626 |
| 626 DashBatch* that = t->cast<DashBatch>(); | |
| 627 | |
| 628 if (this->aaMode() != that->aaMode()) { | 627 if (this->aaMode() != that->aaMode()) { |
| 629 return false; | 628 return false; |
| 630 } | 629 } |
| 631 | 630 |
| 632 if (this->fullDash() != that->fullDash()) { | 631 if (this->fullDash() != that->fullDash()) { |
| 633 return false; | 632 return false; |
| 634 } | 633 } |
| 635 | 634 |
| 636 if (this->cap() != that->cap()) { | 635 if (this->cap() != that->cap()) { |
| 637 return false; | 636 return false; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 bool fFullDash; | 669 bool fFullDash; |
| 671 }; | 670 }; |
| 672 | 671 |
| 673 static const int kVertsPerDash = 4; | 672 static const int kVertsPerDash = 4; |
| 674 static const int kIndicesPerDash = 6; | 673 static const int kIndicesPerDash = 6; |
| 675 | 674 |
| 676 BatchTracker fBatch; | 675 BatchTracker fBatch; |
| 677 SkSTArray<1, Geometry, true> fGeoData; | 676 SkSTArray<1, Geometry, true> fGeoData; |
| 678 }; | 677 }; |
| 679 | 678 |
| 680 static GrBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, const Sk
Point pts[2], | 679 static GrDrawBatch* create_batch(GrColor color, const SkMatrix& viewMatrix, cons
t SkPoint pts[2], |
| 681 bool useAA, const GrStrokeInfo& strokeInfo, bool ms
aaRT) { | 680 bool useAA, const GrStrokeInfo& strokeInfo, boo
l msaaRT) { |
| 682 const SkScalar* intervals = strokeInfo.getDashIntervals(); | 681 const SkScalar* intervals = strokeInfo.getDashIntervals(); |
| 683 SkScalar phase = strokeInfo.getDashPhase(); | 682 SkScalar phase = strokeInfo.getDashPhase(); |
| 684 | 683 |
| 685 SkPaint::Cap cap = strokeInfo.getCap(); | 684 SkPaint::Cap cap = strokeInfo.getCap(); |
| 686 | 685 |
| 687 DashBatch::Geometry geometry; | 686 DashBatch::Geometry geometry; |
| 688 geometry.fSrcStrokeWidth = strokeInfo.getWidth(); | 687 geometry.fSrcStrokeWidth = strokeInfo.getWidth(); |
| 689 | 688 |
| 690 // the phase should be normalized to be [0, sum of all intervals) | 689 // the phase should be normalized to be [0, sum of all intervals) |
| 691 SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]); | 690 SkASSERT(phase >= 0 && phase < intervals[0] + intervals[1]); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 geometry.fIntervals[0] = intervals[0]; | 726 geometry.fIntervals[0] = intervals[0]; |
| 728 geometry.fIntervals[1] = intervals[1]; | 727 geometry.fIntervals[1] = intervals[1]; |
| 729 | 728 |
| 730 return DashBatch::Create(geometry, cap, aaMode, fullDash); | 729 return DashBatch::Create(geometry, cap, aaMode, fullDash); |
| 731 } | 730 } |
| 732 | 731 |
| 733 bool GrDashingEffect::DrawDashLine(GrDrawTarget* target, | 732 bool GrDashingEffect::DrawDashLine(GrDrawTarget* target, |
| 734 const GrPipelineBuilder& pipelineBuilder, GrC
olor color, | 733 const GrPipelineBuilder& pipelineBuilder, GrC
olor color, |
| 735 const SkMatrix& viewMatrix, const SkPoint pts
[2], | 734 const SkMatrix& viewMatrix, const SkPoint pts
[2], |
| 736 bool useAA, const GrStrokeInfo& strokeInfo) { | 735 bool useAA, const GrStrokeInfo& strokeInfo) { |
| 737 SkAutoTUnref<GrBatch> batch( | 736 SkAutoTUnref<GrDrawBatch> batch( |
| 738 create_batch(color, viewMatrix, pts, useAA, strokeInfo, | 737 create_batch(color, viewMatrix, pts, useAA, strokeInfo, |
| 739 pipelineBuilder.getRenderTarget()->isUnifiedMultisample
d())); | 738 pipelineBuilder.getRenderTarget()->isUnifiedMultisample
d())); |
| 740 if (!batch) { | 739 if (!batch) { |
| 741 return false; | 740 return false; |
| 742 } | 741 } |
| 743 | 742 |
| 744 target->drawBatch(pipelineBuilder, batch); | 743 target->drawBatch(pipelineBuilder, batch); |
| 745 return true; | 744 return true; |
| 746 } | 745 } |
| 747 | 746 |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 case kNonRound_DashCap: | 1221 case kNonRound_DashCap: |
| 1223 return DashingLineEffect::Create(color, dashAAMode, invert, usesLoca
lCoords); | 1222 return DashingLineEffect::Create(color, dashAAMode, invert, usesLoca
lCoords); |
| 1224 } | 1223 } |
| 1225 return NULL; | 1224 return NULL; |
| 1226 } | 1225 } |
| 1227 | 1226 |
| 1228 ////////////////////////////////////////////////////////////////////////////////
///////////////// | 1227 ////////////////////////////////////////////////////////////////////////////////
///////////////// |
| 1229 | 1228 |
| 1230 #ifdef GR_TEST_UTILS | 1229 #ifdef GR_TEST_UTILS |
| 1231 | 1230 |
| 1232 BATCH_TEST_DEFINE(DashBatch) { | 1231 DRAW_BATCH_TEST_DEFINE(DashBatch) { |
| 1233 GrColor color = GrRandomColor(random); | 1232 GrColor color = GrRandomColor(random); |
| 1234 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random); | 1233 SkMatrix viewMatrix = GrTest::TestMatrixPreservesRightAngles(random); |
| 1235 bool useAA = random->nextBool(); | 1234 bool useAA = random->nextBool(); |
| 1236 bool msaaRT = random->nextBool(); | 1235 bool msaaRT = random->nextBool(); |
| 1237 | 1236 |
| 1238 // We can only dash either horizontal or vertical lines | 1237 // We can only dash either horizontal or vertical lines |
| 1239 SkPoint pts[2]; | 1238 SkPoint pts[2]; |
| 1240 if (random->nextBool()) { | 1239 if (random->nextBool()) { |
| 1241 // vertical | 1240 // vertical |
| 1242 pts[0].fX = 1.f; | 1241 pts[0].fX = 1.f; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 info.fIntervals = intervals; | 1297 info.fIntervals = intervals; |
| 1299 info.fCount = 2; | 1298 info.fCount = 2; |
| 1300 info.fPhase = phase; | 1299 info.fPhase = phase; |
| 1301 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1300 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
| 1302 SkASSERT(success); | 1301 SkASSERT(success); |
| 1303 | 1302 |
| 1304 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1303 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
| 1305 } | 1304 } |
| 1306 | 1305 |
| 1307 #endif | 1306 #endif |
| OLD | NEW |