Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: src/gpu/effects/GrDashingEffect.cpp

Issue 815553003: Move ViewMatrix off of drawstate (Closed) Base URL: https://skia.googlesource.com/skia.git@remove-fragment-stage
Patch Set: more claenup Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "../GrAARectRenderer.h" 10 #include "../GrAARectRenderer.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 static void setup_dashed_rect_pos(const SkRect& rect, int idx, const SkMatrix& m atrix, 158 static void setup_dashed_rect_pos(const SkRect& rect, int idx, const SkMatrix& m atrix,
159 SkPoint* verts) { 159 SkPoint* verts) {
160 verts[idx] = SkPoint::Make(rect.fLeft, rect.fTop); 160 verts[idx] = SkPoint::Make(rect.fLeft, rect.fTop);
161 verts[idx + 1] = SkPoint::Make(rect.fLeft, rect.fBottom); 161 verts[idx + 1] = SkPoint::Make(rect.fLeft, rect.fBottom);
162 verts[idx + 2] = SkPoint::Make(rect.fRight, rect.fBottom); 162 verts[idx + 2] = SkPoint::Make(rect.fRight, rect.fBottom);
163 verts[idx + 3] = SkPoint::Make(rect.fRight, rect.fTop); 163 verts[idx + 3] = SkPoint::Make(rect.fRight, rect.fTop);
164 matrix.mapPoints(&verts[idx], 4); 164 matrix.mapPoints(&verts[idx], 4);
165 } 165 }
166 166
167 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, GrDrawState * drawState, 167 bool GrDashingEffect::DrawDashLine(GrGpu* gpu, GrDrawTarget* target, GrDrawState * drawState,
168 GrColor color, const SkPoint pts[2], const Gr Paint& paint, 168 GrColor color, const SkMatrix& viewMatrix, co nst SkPoint pts[2],
169 const GrStrokeInfo& strokeInfo) { 169 const GrPaint& paint, const GrStrokeInfo& str okeInfo) {
170 const SkMatrix& vm = drawState->getViewMatrix(); 170 if (!can_fast_path_dash(pts, strokeInfo, *target, *drawState, viewMatrix)) {
171
172 if (!can_fast_path_dash(pts, strokeInfo, *target, *drawState, vm)) {
173 return false; 171 return false;
174 } 172 }
175 173
176 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); 174 const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo();
177 175
178 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap(); 176 SkPaint::Cap cap = strokeInfo.getStrokeRec().getCap();
179 177
180 SkScalar srcStrokeWidth = strokeInfo.getStrokeRec().getWidth(); 178 SkScalar srcStrokeWidth = strokeInfo.getStrokeRec().getWidth();
181 179
182 // the phase should be normalized to be [0, sum of all intervals) 180 // the phase should be normalized to be [0, sum of all intervals)
(...skipping 14 matching lines...) Expand all
197 } else { 195 } else {
198 srcRotInv.reset(); 196 srcRotInv.reset();
199 memcpy(ptsRot, pts, 2 * sizeof(SkPoint)); 197 memcpy(ptsRot, pts, 2 * sizeof(SkPoint));
200 } 198 }
201 199
202 bool useAA = paint.isAntiAlias(); 200 bool useAA = paint.isAntiAlias();
203 201
204 // Scale corrections of intervals and stroke from view matrix 202 // Scale corrections of intervals and stroke from view matrix
205 SkScalar parallelScale; 203 SkScalar parallelScale;
206 SkScalar perpScale; 204 SkScalar perpScale;
207 calc_dash_scaling(&parallelScale, &perpScale, vm, ptsRot); 205 calc_dash_scaling(&parallelScale, &perpScale, viewMatrix, ptsRot);
208 206
209 bool hasCap = SkPaint::kButt_Cap != cap && 0 != srcStrokeWidth; 207 bool hasCap = SkPaint::kButt_Cap != cap && 0 != srcStrokeWidth;
210 208
211 // We always want to at least stroke out half a pixel on each side in device space 209 // We always want to at least stroke out half a pixel on each side in device space
212 // so 0.5f / perpScale gives us this min in src space 210 // so 0.5f / perpScale gives us this min in src space
213 SkScalar halfSrcStroke = SkMaxScalar(srcStrokeWidth * 0.5f, 0.5f / perpScale ); 211 SkScalar halfSrcStroke = SkMaxScalar(srcStrokeWidth * 0.5f, 0.5f / perpScale );
214 212
215 SkScalar strokeAdj; 213 SkScalar strokeAdj;
216 if (!hasCap) { 214 if (!hasCap) {
217 strokeAdj = 0.f; 215 strokeAdj = 0.f;
218 } else { 216 } else {
219 strokeAdj = halfSrcStroke; 217 strokeAdj = halfSrcStroke;
220 } 218 }
221 219
222 SkScalar startAdj = 0; 220 SkScalar startAdj = 0;
223 221
224 SkMatrix combinedMatrix = srcRotInv; 222 SkMatrix combinedMatrix = srcRotInv;
225 combinedMatrix.postConcat(vm); 223 combinedMatrix.postConcat(viewMatrix);
226 224
227 bool lineDone = false; 225 bool lineDone = false;
228 SkRect startRect; 226 SkRect startRect;
229 bool hasStartRect = false; 227 bool hasStartRect = false;
230 // If we are using AA, check to see if we are drawing a partial dash at the start. If so 228 // If we are using AA, check to see if we are drawing a partial dash at the start. If so
231 // draw it separately here and adjust our start point accordingly 229 // draw it separately here and adjust our start point accordingly
232 if (useAA) { 230 if (useAA) {
233 if (srcPhase > 0 && srcPhase < info.fIntervals[0]) { 231 if (srcPhase > 0 && srcPhase < info.fIntervals[0]) {
234 SkPoint startPts[2]; 232 SkPoint startPts[2];
235 startPts[0] = ptsRot[0]; 233 startPts[0] = ptsRot[0];
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // one giant dash 319 // one giant dash
322 ptsRot[0].fX -= hasStartRect ? startAdj : 0; 320 ptsRot[0].fX -= hasStartRect ? startAdj : 0;
323 ptsRot[1].fX += hasEndRect ? endAdj : 0; 321 ptsRot[1].fX += hasEndRect ? endAdj : 0;
324 startRect.set(ptsRot, 2); 322 startRect.set(ptsRot, 2);
325 startRect.outset(strokeAdj, halfSrcStroke); 323 startRect.outset(strokeAdj, halfSrcStroke);
326 hasStartRect = true; 324 hasStartRect = true;
327 hasEndRect = false; 325 hasEndRect = false;
328 lineDone = true; 326 lineDone = true;
329 327
330 SkPoint devicePts[2]; 328 SkPoint devicePts[2];
331 vm.mapPoints(devicePts, ptsRot, 2); 329 viewMatrix.mapPoints(devicePts, ptsRot, 2);
332 SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]); 330 SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]);
333 if (hasCap) { 331 if (hasCap) {
334 lineLength += 2.f * halfDevStroke; 332 lineLength += 2.f * halfDevStroke;
335 } 333 }
336 devIntervals[0] = lineLength; 334 devIntervals[0] = lineLength;
337 } 335 }
338 336
339 // reset to device coordinates 337 // reset to device coordinates
340 SkMatrix invert; 338 SkMatrix invert;
341 if (!vm.invert(&invert)) { 339 if (!viewMatrix.invert(&invert)) {
342 SkDebugf("Failed to invert\n"); 340 SkDebugf("Failed to invert\n");
343 return false; 341 return false;
344 } 342 }
345 343
346 GrDrawState::AutoViewMatrixRestore avmr(drawState);
347
348 SkAutoTUnref<const GrGeometryProcessor> gp; 344 SkAutoTUnref<const GrGeometryProcessor> gp;
349 bool fullDash = devIntervals[1] > 0.f || useAA; 345 bool fullDash = devIntervals[1] > 0.f || useAA;
350 if (fullDash) { 346 if (fullDash) {
351 SkPathEffect::DashInfo devInfo; 347 SkPathEffect::DashInfo devInfo;
352 devInfo.fPhase = devPhase; 348 devInfo.fPhase = devPhase;
353 devInfo.fCount = 2; 349 devInfo.fCount = 2;
354 devInfo.fIntervals = devIntervals; 350 devInfo.fIntervals = devIntervals;
355 GrPrimitiveEdgeType edgeType= useAA ? kFillAA_GrProcessorEdgeType : 351 GrPrimitiveEdgeType edgeType= useAA ? kFillAA_GrProcessorEdgeType :
356 kFillBW_GrProcessorEdgeType; 352 kFillBW_GrProcessorEdgeType;
357 bool isRoundCap = SkPaint::kRound_Cap == cap; 353 bool isRoundCap = SkPaint::kRound_Cap == cap;
358 GrDashingEffect::DashCap capType = isRoundCap ? GrDashingEffect::kRound_ DashCap : 354 GrDashingEffect::DashCap capType = isRoundCap ? GrDashingEffect::kRound_ DashCap :
359 GrDashingEffect::kNonRou nd_DashCap; 355 GrDashingEffect::kNonRou nd_DashCap;
360 gp.reset(GrDashingEffect::Create(color, edgeType, devInfo, strokeWidth, capType, invert)); 356 gp.reset(GrDashingEffect::Create(color, SkMatrix::I(), edgeType, devInfo , strokeWidth,
bsalomon 2014/12/29 18:35:46 For GPs that are only ever instantiated with I() s
joshualitt 2014/12/29 19:23:38 Acknowledged.
357 capType, invert));
361 } else { 358 } else {
362 // Set up the vertex data for the line and start/end dashes 359 // Set up the vertex data for the line and start/end dashes
363 gp.reset(GrDefaultGeoProcFactory::Create(color, GrDefaultGeoProcFactory: :kPosition_GPType, 360 gp.reset(GrDefaultGeoProcFactory::Create(GrDefaultGeoProcFactory::kPosit ion_GPType,
361 color,
362 SkMatrix::I(),
364 invert)); 363 invert));
365 } 364 }
366 365
367 int totalRectCnt = 0; 366 int totalRectCnt = 0;
368 367
369 totalRectCnt += !lineDone ? 1 : 0; 368 totalRectCnt += !lineDone ? 1 : 0;
370 totalRectCnt += hasStartRect ? 1 : 0; 369 totalRectCnt += hasStartRect ? 1 : 0;
371 totalRectCnt += hasEndRect ? 1 : 0; 370 totalRectCnt += hasEndRect ? 1 : 0;
372 371
373 GrDrawTarget::AutoReleaseGeometry geo(target, 372 GrDrawTarget::AutoReleaseGeometry geo(target,
374 totalRectCnt * 4, 373 totalRectCnt * 4,
375 gp->getVertexStride(), 0); 374 gp->getVertexStride(), 0);
376 if (!geo.succeeded()) { 375 if (!geo.succeeded()) {
377 SkDebugf("Failed to get space for vertices!\n"); 376 SkDebugf("Failed to get space for vertices!\n");
378 return false; 377 return false;
379 } 378 }
380 379
381 int curVIdx = 0; 380 int curVIdx = 0;
382 381
383 if (SkPaint::kRound_Cap == cap && 0 != srcStrokeWidth) { 382 if (SkPaint::kRound_Cap == cap && 0 != srcStrokeWidth) {
384 // need to adjust this for round caps to correctly set the dashPos attri b on vertices 383 // need to adjust this for round caps to correctly set the dashPos attri b on vertices
385 startOffset -= halfDevStroke; 384 startOffset -= halfDevStroke;
386 } 385 }
387 386
388 // Draw interior part of dashed line 387 // Draw interior part of dashed line
389 if (!lineDone) { 388 if (!lineDone) {
390 SkPoint devicePts[2]; 389 SkPoint devicePts[2];
391 vm.mapPoints(devicePts, ptsRot, 2); 390 viewMatrix.mapPoints(devicePts, ptsRot, 2);
392 SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]); 391 SkScalar lineLength = SkPoint::Distance(devicePts[0], devicePts[1]);
393 if (hasCap) { 392 if (hasCap) {
394 lineLength += 2.f * halfDevStroke; 393 lineLength += 2.f * halfDevStroke;
395 } 394 }
396 395
397 SkRect bounds; 396 SkRect bounds;
398 bounds.set(ptsRot[0].fX, ptsRot[0].fY, ptsRot[1].fX, ptsRot[1].fY); 397 bounds.set(ptsRot[0].fX, ptsRot[0].fY, ptsRot[1].fX, ptsRot[1].fY);
399 bounds.outset(bloatX + strokeAdj, bloatY + halfSrcStroke); 398 bounds.outset(bloatX + strokeAdj, bloatY + halfSrcStroke);
400 if (fullDash) { 399 if (fullDash) {
401 DashLineVertex* verts = reinterpret_cast<DashLineVertex*>(geo.vertic es()); 400 DashLineVertex* verts = reinterpret_cast<DashLineVertex*>(geo.vertic es());
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 * a vec2 vertex attribute for the the four corners of the bounding rect. This a ttribute is the 465 * a vec2 vertex attribute for the the four corners of the bounding rect. This a ttribute is the
467 * "dash position" of each vertex. In other words it is the vertex coords (in de vice space) if we 466 * "dash position" of each vertex. In other words it is the vertex coords (in de vice space) if we
468 * transform the line to be horizontal, with the start of line at the origin the n shifted to the 467 * transform the line to be horizontal, with the start of line at the origin the n shifted to the
469 * right by half the off interval. The line then goes in the positive x directio n. 468 * right by half the off interval. The line then goes in the positive x directio n.
470 */ 469 */
471 class DashingCircleEffect : public GrGeometryProcessor { 470 class DashingCircleEffect : public GrGeometryProcessor {
472 public: 471 public:
473 typedef SkPathEffect::DashInfo DashInfo; 472 typedef SkPathEffect::DashInfo DashInfo;
474 473
475 static GrGeometryProcessor* Create(GrColor, 474 static GrGeometryProcessor* Create(GrColor,
475 const SkMatrix& viewMatrix,
476 GrPrimitiveEdgeType edgeType, 476 GrPrimitiveEdgeType edgeType,
477 const DashInfo& info, 477 const DashInfo& info,
478 SkScalar radius, 478 SkScalar radius,
479 const SkMatrix& localMatrix); 479 const SkMatrix& localMatrix);
480 480
481 virtual ~DashingCircleEffect(); 481 virtual ~DashingCircleEffect();
482 482
483 virtual const char* name() const SK_OVERRIDE { return "DashingCircleEffect"; } 483 virtual const char* name() const SK_OVERRIDE { return "DashingCircleEffect"; }
484 484
485 const GrAttribute* inPosition() const { return fInPosition; } 485 const GrAttribute* inPosition() const { return fInPosition; }
(...skipping 14 matching lines...) Expand all
500 500
501 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker&) const SK_OVERRIDE; 501 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker&) const SK_OVERRIDE;
502 502
503 void initBatchTracker(GrBatchTracker* bt, const InitBT& init) const SK_OVERR IDE; 503 void initBatchTracker(GrBatchTracker* bt, const InitBT& init) const SK_OVERR IDE;
504 504
505 bool onCanMakeEqual(const GrBatchTracker&, 505 bool onCanMakeEqual(const GrBatchTracker&,
506 const GrGeometryProcessor&, 506 const GrGeometryProcessor&,
507 const GrBatchTracker&) const SK_OVERRIDE; 507 const GrBatchTracker&) const SK_OVERRIDE;
508 508
509 private: 509 private:
510 DashingCircleEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& i nfo, 510 DashingCircleEffect(GrColor, const SkMatrix& viewMatrix, GrPrimitiveEdgeType edgeType,
511 SkScalar radius, const SkMatrix& localMatrix); 511 const DashInfo& info, SkScalar radius, const SkMatrix& l ocalMatrix);
512 512
513 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; 513 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE;
514 514
515 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O VERRIDE; 515 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O VERRIDE;
516 516
517 GrPrimitiveEdgeType fEdgeType; 517 GrPrimitiveEdgeType fEdgeType;
518 const GrAttribute* fInPosition; 518 const GrAttribute* fInPosition;
519 const GrAttribute* fInCoord; 519 const GrAttribute* fInCoord;
520 SkScalar fIntervalLength; 520 SkScalar fIntervalLength;
521 SkScalar fRadius; 521 SkScalar fRadius;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 GrProcessorKeyBuilder* b) { 636 GrProcessorKeyBuilder* b) {
637 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>( ); 637 const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>( );
638 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>(); 638 const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
639 b->add32(local.fUsesLocalCoords && processor.localMatrix().hasPerspective()) ; 639 b->add32(local.fUsesLocalCoords && processor.localMatrix().hasPerspective()) ;
640 b->add32(dce.getEdgeType() << 16 | local.fInputColorType); 640 b->add32(dce.getEdgeType() << 16 | local.fInputColorType);
641 } 641 }
642 642
643 ////////////////////////////////////////////////////////////////////////////// 643 //////////////////////////////////////////////////////////////////////////////
644 644
645 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color, 645 GrGeometryProcessor* DashingCircleEffect::Create(GrColor color,
646 const SkMatrix& viewMatrix,
646 GrPrimitiveEdgeType edgeType, 647 GrPrimitiveEdgeType edgeType,
647 const DashInfo& info, 648 const DashInfo& info,
648 SkScalar radius, 649 SkScalar radius,
649 const SkMatrix& localMatrix) { 650 const SkMatrix& localMatrix) {
650 if (info.fCount != 2 || info.fIntervals[0] != 0) { 651 if (info.fCount != 2 || info.fIntervals[0] != 0) {
651 return NULL; 652 return NULL;
652 } 653 }
653 654
654 return SkNEW_ARGS(DashingCircleEffect, (color, edgeType, info, radius, local Matrix)); 655 return SkNEW_ARGS(DashingCircleEffect, (color, viewMatrix, edgeType, info, r adius,
656 localMatrix));
655 } 657 }
656 658
657 DashingCircleEffect::~DashingCircleEffect() {} 659 DashingCircleEffect::~DashingCircleEffect() {}
658 660
659 void DashingCircleEffect::onGetInvariantOutputCoverage(GrInitInvariantOutput* ou t) const { 661 void DashingCircleEffect::onGetInvariantOutputCoverage(GrInitInvariantOutput* ou t) const {
660 out->setUnknownSingleComponent(); 662 out->setUnknownSingleComponent();
661 } 663 }
662 664
663 void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt, 665 void DashingCircleEffect::getGLProcessorKey(const GrBatchTracker& bt,
664 const GrGLCaps& caps, 666 const GrGLCaps& caps,
665 GrProcessorKeyBuilder* b) const { 667 GrProcessorKeyBuilder* b) const {
666 GLDashingCircleEffect::GenKey(*this, bt, caps, b); 668 GLDashingCircleEffect::GenKey(*this, bt, caps, b);
667 } 669 }
668 670
669 GrGLGeometryProcessor* DashingCircleEffect::createGLInstance(const GrBatchTracke r& bt) const { 671 GrGLGeometryProcessor* DashingCircleEffect::createGLInstance(const GrBatchTracke r& bt) const {
670 return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt)); 672 return SkNEW_ARGS(GLDashingCircleEffect, (*this, bt));
671 } 673 }
672 674
673 DashingCircleEffect::DashingCircleEffect(GrColor color, 675 DashingCircleEffect::DashingCircleEffect(GrColor color,
676 const SkMatrix& viewMatrix,
674 GrPrimitiveEdgeType edgeType, 677 GrPrimitiveEdgeType edgeType,
675 const DashInfo& info, 678 const DashInfo& info,
676 SkScalar radius, 679 SkScalar radius,
677 const SkMatrix& localMatrix) 680 const SkMatrix& localMatrix)
678 : INHERITED(color, false, localMatrix), fEdgeType(edgeType) { 681 : INHERITED(color, viewMatrix, localMatrix), fEdgeType(edgeType) {
679 this->initClassID<DashingCircleEffect>(); 682 this->initClassID<DashingCircleEffect>();
680 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert exAttribType)); 683 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert exAttribType));
681 fInCoord = &this->addVertexAttrib(GrAttribute("inCoord", kVec2f_GrVertexAttr ibType)); 684 fInCoord = &this->addVertexAttrib(GrAttribute("inCoord", kVec2f_GrVertexAttr ibType));
682 SkScalar onLen = info.fIntervals[0]; 685 SkScalar onLen = info.fIntervals[0];
683 SkScalar offLen = info.fIntervals[1]; 686 SkScalar offLen = info.fIntervals[1];
684 fIntervalLength = onLen + offLen; 687 fIntervalLength = onLen + offLen;
685 fRadius = radius; 688 fRadius = radius;
686 fCenterX = SkScalarHalf(offLen); 689 fCenterX = SkScalarHalf(offLen);
687 } 690 }
688 691
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 kGrProcessorEdgeTypeCnt)); 724 kGrProcessorEdgeTypeCnt));
722 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); 725 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f);
723 DashInfo info; 726 DashInfo info;
724 info.fCount = 2; 727 info.fCount = 2;
725 SkAutoTArray<SkScalar> intervals(info.fCount); 728 SkAutoTArray<SkScalar> intervals(info.fCount);
726 info.fIntervals = intervals.get(); 729 info.fIntervals = intervals.get();
727 info.fIntervals[0] = 0; 730 info.fIntervals[0] = 0;
728 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); 731 info.fIntervals[1] = random->nextRangeScalar(0, 10.f);
729 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]); 732 info.fPhase = random->nextRangeScalar(0, info.fIntervals[1]);
730 733
731 return DashingCircleEffect::Create(GrRandomColor(random), edgeType, info, st rokeWidth, 734 return DashingCircleEffect::Create(GrRandomColor(random),
735 GrProcessorUnitTest::TestMatrix(random),
736 edgeType, info, strokeWidth,
732 GrProcessorUnitTest::TestMatrix(random)); 737 GrProcessorUnitTest::TestMatrix(random));
733 } 738 }
734 739
735 ////////////////////////////////////////////////////////////////////////////// 740 //////////////////////////////////////////////////////////////////////////////
736 741
737 class GLDashingLineEffect; 742 class GLDashingLineEffect;
738 743
739 struct DashingLineBatchTracker { 744 struct DashingLineBatchTracker {
740 GrGPInput fInputColorType; 745 GrGPInput fInputColorType;
741 GrColor fColor; 746 GrColor fColor;
742 bool fUsesLocalCoords; 747 bool fUsesLocalCoords;
743 }; 748 };
744 749
745 /* 750 /*
746 * This effect will draw a dashed line. The width of the dash is given by the st rokeWidth and the 751 * This effect will draw a dashed line. The width of the dash is given by the st rokeWidth and the
747 * length and spacing by the DashInfo. Both of the previous two parameters are i n device space. 752 * length and spacing by the DashInfo. Both of the previous two parameters are i n device space.
748 * This effect also requires the setting of a vec2 vertex attribute for the the four corners of the 753 * This effect also requires the setting of a vec2 vertex attribute for the the four corners of the
749 * bounding rect. This attribute is the "dash position" of each vertex. In other words it is the 754 * bounding rect. This attribute is the "dash position" of each vertex. In other words it is the
750 * vertex coords (in device space) if we transform the line to be horizontal, wi th the start of 755 * vertex coords (in device space) if we transform the line to be horizontal, wi th the start of
751 * line at the origin then shifted to the right by half the off interval. The li ne then goes in the 756 * line at the origin then shifted to the right by half the off interval. The li ne then goes in the
752 * positive x direction. 757 * positive x direction.
753 */ 758 */
754 class DashingLineEffect : public GrGeometryProcessor { 759 class DashingLineEffect : public GrGeometryProcessor {
755 public: 760 public:
756 typedef SkPathEffect::DashInfo DashInfo; 761 typedef SkPathEffect::DashInfo DashInfo;
757 762
758 static GrGeometryProcessor* Create(GrColor, 763 static GrGeometryProcessor* Create(GrColor,
764 const SkMatrix& viewMatrix,
759 GrPrimitiveEdgeType edgeType, 765 GrPrimitiveEdgeType edgeType,
760 const DashInfo& info, 766 const DashInfo& info,
761 SkScalar strokeWidth, 767 SkScalar strokeWidth,
762 const SkMatrix& localMatrix); 768 const SkMatrix& localMatrix);
763 769
764 virtual ~DashingLineEffect(); 770 virtual ~DashingLineEffect();
765 771
766 virtual const char* name() const SK_OVERRIDE { return "DashingEffect"; } 772 virtual const char* name() const SK_OVERRIDE { return "DashingEffect"; }
767 773
768 const GrAttribute* inPosition() const { return fInPosition; } 774 const GrAttribute* inPosition() const { return fInPosition; }
(...skipping 12 matching lines...) Expand all
781 787
782 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co nst SK_OVERRIDE; 788 virtual GrGLGeometryProcessor* createGLInstance(const GrBatchTracker& bt) co nst SK_OVERRIDE;
783 789
784 void initBatchTracker(GrBatchTracker* bt, const InitBT& init) const SK_OVERR IDE; 790 void initBatchTracker(GrBatchTracker* bt, const InitBT& init) const SK_OVERR IDE;
785 791
786 bool onCanMakeEqual(const GrBatchTracker&, 792 bool onCanMakeEqual(const GrBatchTracker&,
787 const GrGeometryProcessor&, 793 const GrGeometryProcessor&,
788 const GrBatchTracker&) const SK_OVERRIDE; 794 const GrBatchTracker&) const SK_OVERRIDE;
789 795
790 private: 796 private:
791 DashingLineEffect(GrColor, GrPrimitiveEdgeType edgeType, const DashInfo& inf o, 797 DashingLineEffect(GrColor, const SkMatrix& viewMatrix, GrPrimitiveEdgeType e dgeType,
792 SkScalar strokeWidth, const SkMatrix& localMatrix); 798 const DashInfo& info, SkScalar strokeWidth, const SkMatrix & localMatrix);
793 799
794 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE; 800 virtual bool onIsEqual(const GrGeometryProcessor& other) const SK_OVERRIDE;
795 801
796 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O VERRIDE; 802 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const SK_O VERRIDE;
797 803
798 GrPrimitiveEdgeType fEdgeType; 804 GrPrimitiveEdgeType fEdgeType;
799 const GrAttribute* fInPosition; 805 const GrAttribute* fInPosition;
800 const GrAttribute* fInCoord; 806 const GrAttribute* fInCoord;
801 SkRect fRect; 807 SkRect fRect;
802 SkScalar fIntervalLength; 808 SkScalar fIntervalLength;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 GrProcessorKeyBuilder* b) { 936 GrProcessorKeyBuilder* b) {
931 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>(); 937 const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>();
932 const DashingLineEffect& de = processor.cast<DashingLineEffect>(); 938 const DashingLineEffect& de = processor.cast<DashingLineEffect>();
933 b->add32(local.fUsesLocalCoords && processor.localMatrix().hasPerspective()) ; 939 b->add32(local.fUsesLocalCoords && processor.localMatrix().hasPerspective()) ;
934 b->add32(de.getEdgeType() << 16 | local.fInputColorType); 940 b->add32(de.getEdgeType() << 16 | local.fInputColorType);
935 } 941 }
936 942
937 ////////////////////////////////////////////////////////////////////////////// 943 //////////////////////////////////////////////////////////////////////////////
938 944
939 GrGeometryProcessor* DashingLineEffect::Create(GrColor color, 945 GrGeometryProcessor* DashingLineEffect::Create(GrColor color,
946 const SkMatrix& viewMatrix,
940 GrPrimitiveEdgeType edgeType, 947 GrPrimitiveEdgeType edgeType,
941 const DashInfo& info, 948 const DashInfo& info,
942 SkScalar strokeWidth, 949 SkScalar strokeWidth,
943 const SkMatrix& localMatrix) { 950 const SkMatrix& localMatrix) {
944 if (info.fCount != 2) { 951 if (info.fCount != 2) {
945 return NULL; 952 return NULL;
946 } 953 }
947 954
948 return SkNEW_ARGS(DashingLineEffect, (color, edgeType, info, strokeWidth, lo calMatrix)); 955 return SkNEW_ARGS(DashingLineEffect, (color, viewMatrix, edgeType, info, str okeWidth,
956 localMatrix));
949 } 957 }
950 958
951 DashingLineEffect::~DashingLineEffect() {} 959 DashingLineEffect::~DashingLineEffect() {}
952 960
953 void DashingLineEffect::onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const { 961 void DashingLineEffect::onGetInvariantOutputCoverage(GrInitInvariantOutput* out) const {
954 out->setUnknownSingleComponent(); 962 out->setUnknownSingleComponent();
955 } 963 }
956 964
957 void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt, 965 void DashingLineEffect::getGLProcessorKey(const GrBatchTracker& bt,
958 const GrGLCaps& caps, 966 const GrGLCaps& caps,
959 GrProcessorKeyBuilder* b) const { 967 GrProcessorKeyBuilder* b) const {
960 GLDashingLineEffect::GenKey(*this, bt, caps, b); 968 GLDashingLineEffect::GenKey(*this, bt, caps, b);
961 } 969 }
962 970
963 GrGLGeometryProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker& bt) const { 971 GrGLGeometryProcessor* DashingLineEffect::createGLInstance(const GrBatchTracker& bt) const {
964 return SkNEW_ARGS(GLDashingLineEffect, (*this, bt)); 972 return SkNEW_ARGS(GLDashingLineEffect, (*this, bt));
965 } 973 }
966 974
967 DashingLineEffect::DashingLineEffect(GrColor color, 975 DashingLineEffect::DashingLineEffect(GrColor color,
976 const SkMatrix& viewMatrix,
968 GrPrimitiveEdgeType edgeType, 977 GrPrimitiveEdgeType edgeType,
969 const DashInfo& info, 978 const DashInfo& info,
970 SkScalar strokeWidth, 979 SkScalar strokeWidth,
971 const SkMatrix& localMatrix) 980 const SkMatrix& localMatrix)
972 : INHERITED(color, false, localMatrix), fEdgeType(edgeType) { 981 : INHERITED(color, viewMatrix, localMatrix), fEdgeType(edgeType) {
973 this->initClassID<DashingLineEffect>(); 982 this->initClassID<DashingLineEffect>();
974 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert exAttribType)); 983 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert exAttribType));
975 fInCoord = &this->addVertexAttrib(GrAttribute("inCoord", kVec2f_GrVertexAttr ibType)); 984 fInCoord = &this->addVertexAttrib(GrAttribute("inCoord", kVec2f_GrVertexAttr ibType));
976 SkScalar onLen = info.fIntervals[0]; 985 SkScalar onLen = info.fIntervals[0];
977 SkScalar offLen = info.fIntervals[1]; 986 SkScalar offLen = info.fIntervals[1];
978 SkScalar halfOffLen = SkScalarHalf(offLen); 987 SkScalar halfOffLen = SkScalarHalf(offLen);
979 SkScalar halfStroke = SkScalarHalf(strokeWidth); 988 SkScalar halfStroke = SkScalarHalf(strokeWidth);
980 fIntervalLength = onLen + offLen; 989 fIntervalLength = onLen + offLen;
981 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke); 990 fRect.set(halfOffLen, -halfStroke, halfOffLen + onLen, halfStroke);
982 } 991 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 kGrProcessorEdgeTypeCnt)); 1024 kGrProcessorEdgeTypeCnt));
1016 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f); 1025 SkScalar strokeWidth = random->nextRangeScalar(0, 100.f);
1017 DashInfo info; 1026 DashInfo info;
1018 info.fCount = 2; 1027 info.fCount = 2;
1019 SkAutoTArray<SkScalar> intervals(info.fCount); 1028 SkAutoTArray<SkScalar> intervals(info.fCount);
1020 info.fIntervals = intervals.get(); 1029 info.fIntervals = intervals.get();
1021 info.fIntervals[0] = random->nextRangeScalar(0, 10.f); 1030 info.fIntervals[0] = random->nextRangeScalar(0, 10.f);
1022 info.fIntervals[1] = random->nextRangeScalar(0, 10.f); 1031 info.fIntervals[1] = random->nextRangeScalar(0, 10.f);
1023 info.fPhase = random->nextRangeScalar(0, info.fIntervals[0] + info.fInterval s[1]); 1032 info.fPhase = random->nextRangeScalar(0, info.fIntervals[0] + info.fInterval s[1]);
1024 1033
1025 return DashingLineEffect::Create(GrRandomColor(random), edgeType, info, stro keWidth, 1034 return DashingLineEffect::Create(GrRandomColor(random),
1035 GrProcessorUnitTest::TestMatrix(random),
1036 edgeType, info, strokeWidth,
1026 GrProcessorUnitTest::TestMatrix(random)); 1037 GrProcessorUnitTest::TestMatrix(random));
1027 } 1038 }
1028 1039
1029 ////////////////////////////////////////////////////////////////////////////// 1040 //////////////////////////////////////////////////////////////////////////////
1030 1041
1031 GrGeometryProcessor* GrDashingEffect::Create(GrColor color, 1042 GrGeometryProcessor* GrDashingEffect::Create(GrColor color,
1043 const SkMatrix& viewMatrix,
1032 GrPrimitiveEdgeType edgeType, 1044 GrPrimitiveEdgeType edgeType,
1033 const SkPathEffect::DashInfo& info, 1045 const SkPathEffect::DashInfo& info,
1034 SkScalar strokeWidth, 1046 SkScalar strokeWidth,
1035 GrDashingEffect::DashCap cap, 1047 GrDashingEffect::DashCap cap,
1036 const SkMatrix& localMatrix) { 1048 const SkMatrix& localMatrix) {
1037 switch (cap) { 1049 switch (cap) {
1038 case GrDashingEffect::kRound_DashCap: 1050 case GrDashingEffect::kRound_DashCap:
1039 return DashingCircleEffect::Create(color, edgeType, info, SkScalarHa lf(strokeWidth), 1051 return DashingCircleEffect::Create(color, viewMatrix, edgeType, info ,
1052 SkScalarHalf(strokeWidth),
1040 localMatrix); 1053 localMatrix);
1041 case GrDashingEffect::kNonRound_DashCap: 1054 case GrDashingEffect::kNonRound_DashCap:
1042 return DashingLineEffect::Create(color, edgeType, info, strokeWidth, localMatrix); 1055 return DashingLineEffect::Create(color, viewMatrix, edgeType, info, strokeWidth,
1056 localMatrix);
1043 default: 1057 default:
1044 SkFAIL("Unexpected dashed cap."); 1058 SkFAIL("Unexpected dashed cap.");
1045 } 1059 }
1046 return NULL; 1060 return NULL;
1047 } 1061 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698