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 "GrBatch.h" | 10 #include "GrBatch.h" |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 struct Geometry { | 249 struct Geometry { |
250 GrColor fColor; | 250 GrColor fColor; |
251 SkMatrix fViewMatrix; | 251 SkMatrix fViewMatrix; |
252 SkMatrix fSrcRotInv; | 252 SkMatrix fSrcRotInv; |
253 SkPoint fPtsRot[2]; | 253 SkPoint fPtsRot[2]; |
254 SkScalar fSrcStrokeWidth; | 254 SkScalar fSrcStrokeWidth; |
255 SkScalar fPhase; | 255 SkScalar fPhase; |
256 SkScalar fIntervals[2]; | 256 SkScalar fIntervals[2]; |
257 SkScalar fParallelScale; | 257 SkScalar fParallelScale; |
258 SkScalar fPerpendicularScale; | 258 SkScalar fPerpendicularScale; |
259 SkDEBUGCODE(SkRect fDevBounds;) | |
260 }; | 259 }; |
261 | 260 |
262 static GrBatch* Create(const Geometry& geometry, SkPaint::Cap cap, DashAAMod
e aaMode, | 261 static GrBatch* Create(const Geometry& geometry, SkPaint::Cap cap, DashAAMod
e aaMode, |
263 bool fullDash) { | 262 bool fullDash) { |
264 return SkNEW_ARGS(DashBatch, (geometry, cap, aaMode, fullDash)); | 263 return SkNEW_ARGS(DashBatch, (geometry, cap, aaMode, fullDash)); |
265 } | 264 } |
266 | 265 |
267 const char* name() const override { return "DashBatch"; } | 266 const char* name() const override { return "DashBatch"; } |
268 | 267 |
269 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 268 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 | 359 |
361 SkScalar strokeAdj; | 360 SkScalar strokeAdj; |
362 if (!hasCap) { | 361 if (!hasCap) { |
363 strokeAdj = 0.f; | 362 strokeAdj = 0.f; |
364 } else { | 363 } else { |
365 strokeAdj = halfSrcStroke; | 364 strokeAdj = halfSrcStroke; |
366 } | 365 } |
367 | 366 |
368 SkScalar startAdj = 0; | 367 SkScalar startAdj = 0; |
369 | 368 |
370 SkMatrix& combinedMatrix = args.fSrcRotInv; | |
371 combinedMatrix.postConcat(args.fViewMatrix); | |
372 | |
373 bool lineDone = false; | 369 bool lineDone = false; |
374 | 370 |
375 // Too simplify the algorithm, we always push back rects for start a
nd end rect. | 371 // Too simplify the algorithm, we always push back rects for start a
nd end rect. |
376 // Otherwise we'd have to track start / end rects for each individua
l geometry | 372 // Otherwise we'd have to track start / end rects for each individua
l geometry |
377 rects.push_back(); | 373 rects.push_back(); |
378 rects.push_back(); | 374 rects.push_back(); |
379 rects.push_back(); | 375 rects.push_back(); |
380 SkRect& bounds = rects[rectOffset++]; | 376 SkRect& bounds = rects[rectOffset++]; |
381 SkRect& startRect = rects[rectOffset++]; | 377 SkRect& startRect = rects[rectOffset++]; |
382 SkRect& endRect = rects[rectOffset++]; | 378 SkRect& endRect = rects[rectOffset++]; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 635 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
640 | 636 |
641 private: | 637 private: |
642 DashBatch(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, boo
l fullDash) { | 638 DashBatch(const Geometry& geometry, SkPaint::Cap cap, DashAAMode aaMode, boo
l fullDash) { |
643 this->initClassID<DashBatch>(); | 639 this->initClassID<DashBatch>(); |
644 fGeoData.push_back(geometry); | 640 fGeoData.push_back(geometry); |
645 | 641 |
646 fBatch.fAAMode = aaMode; | 642 fBatch.fAAMode = aaMode; |
647 fBatch.fCap = cap; | 643 fBatch.fCap = cap; |
648 fBatch.fFullDash = fullDash; | 644 fBatch.fFullDash = fullDash; |
| 645 |
| 646 // compute bounds |
| 647 SkScalar halfStrokeWidth = 0.5f * geometry.fSrcStrokeWidth; |
| 648 SkScalar xBloat = SkPaint::kButt_Cap == cap ? 0 : halfStrokeWidth; |
| 649 fBounds.set(geometry.fPtsRot[0], geometry.fPtsRot[1]); |
| 650 fBounds.outset(xBloat, halfStrokeWidth); |
| 651 |
| 652 // Note, we actually create the combined matrix here, and save the work |
| 653 SkMatrix& combinedMatrix = fGeoData[0].fSrcRotInv; |
| 654 combinedMatrix.postConcat(geometry.fViewMatrix); |
| 655 combinedMatrix.mapRect(&fBounds); |
649 } | 656 } |
650 | 657 |
651 bool onCombineIfPossible(GrBatch* t) override { | 658 bool onCombineIfPossible(GrBatch* t) override { |
652 DashBatch* that = t->cast<DashBatch>(); | 659 DashBatch* that = t->cast<DashBatch>(); |
653 | 660 |
654 if (this->aaMode() != that->aaMode()) { | 661 if (this->aaMode() != that->aaMode()) { |
655 return false; | 662 return false; |
656 } | 663 } |
657 | 664 |
658 if (this->fullDash() != that->fullDash()) { | 665 if (this->fullDash() != that->fullDash()) { |
659 return false; | 666 return false; |
660 } | 667 } |
661 | 668 |
662 if (this->cap() != that->cap()) { | 669 if (this->cap() != that->cap()) { |
663 return false; | 670 return false; |
664 } | 671 } |
665 | 672 |
666 // TODO vertex color | 673 // TODO vertex color |
667 if (this->color() != that->color()) { | 674 if (this->color() != that->color()) { |
668 return false; | 675 return false; |
669 } | 676 } |
670 | 677 |
671 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 678 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
672 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { | 679 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { |
673 return false; | 680 return false; |
674 } | 681 } |
675 | 682 |
676 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 683 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; |
| 684 this->joinBounds(that->bounds()); |
677 return true; | 685 return true; |
678 } | 686 } |
679 | 687 |
680 GrColor color() const { return fBatch.fColor; } | 688 GrColor color() const { return fBatch.fColor; } |
681 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 689 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
682 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 690 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
683 DashAAMode aaMode() const { return fBatch.fAAMode; } | 691 DashAAMode aaMode() const { return fBatch.fAAMode; } |
684 bool fullDash() const { return fBatch.fFullDash; } | 692 bool fullDash() const { return fBatch.fFullDash; } |
685 SkPaint::Cap cap() const { return fBatch.fCap; } | 693 SkPaint::Cap cap() const { return fBatch.fCap; } |
686 | 694 |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 info.fIntervals = intervals; | 1372 info.fIntervals = intervals; |
1365 info.fCount = 2; | 1373 info.fCount = 2; |
1366 info.fPhase = phase; | 1374 info.fPhase = phase; |
1367 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); | 1375 SkDEBUGCODE(bool success = ) strokeInfo.setDashInfo(info); |
1368 SkASSERT(success); | 1376 SkASSERT(success); |
1369 | 1377 |
1370 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); | 1378 return create_batch(color, viewMatrix, pts, useAA, strokeInfo, msaaRT); |
1371 } | 1379 } |
1372 | 1380 |
1373 #endif | 1381 #endif |
OLD | NEW |