OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrAARectRenderer.h" | 8 #include "GrAARectRenderer.h" |
9 #include "GrBatch.h" | 9 #include "GrBatch.h" |
10 #include "GrBatchTarget.h" | 10 #include "GrBatchTarget.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 182 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
183 | 183 |
184 private: | 184 private: |
185 AAFillRectBatch(const Geometry& geometry, const GrIndexBuffer* indexBuffer) | 185 AAFillRectBatch(const Geometry& geometry, const GrIndexBuffer* indexBuffer) |
186 : fIndexBuffer(indexBuffer) { | 186 : fIndexBuffer(indexBuffer) { |
187 this->initClassID<AAFillRectBatch>(); | 187 this->initClassID<AAFillRectBatch>(); |
188 fGeoData.push_back(geometry); | 188 fGeoData.push_back(geometry); |
| 189 |
| 190 this->setBounds(geometry.fDevRect); |
189 } | 191 } |
190 | 192 |
191 GrColor color() const { return fBatch.fColor; } | 193 GrColor color() const { return fBatch.fColor; } |
192 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 194 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
193 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } | 195 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } |
194 bool colorIgnored() const { return fBatch.fColorIgnored; } | 196 bool colorIgnored() const { return fBatch.fColorIgnored; } |
195 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 197 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
196 | 198 |
197 bool onCombineIfPossible(GrBatch* t) override { | 199 bool onCombineIfPossible(GrBatch* t) override { |
198 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); | 200 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); |
(...skipping 10 matching lines...) Expand all Loading... |
209 fBatch.fColor = GrColor_ILLEGAL; | 211 fBatch.fColor = GrColor_ILLEGAL; |
210 } | 212 } |
211 | 213 |
212 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to | 214 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to |
213 // not tweaking | 215 // not tweaking |
214 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()
) { | 216 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()
) { |
215 fBatch.fCanTweakAlphaForCoverage = false; | 217 fBatch.fCanTweakAlphaForCoverage = false; |
216 } | 218 } |
217 | 219 |
218 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 220 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; |
| 221 this->joinBounds(that->bounds()); |
219 return true; | 222 return true; |
220 } | 223 } |
221 | 224 |
222 void generateAAFillRectGeometry(void* vertices, | 225 void generateAAFillRectGeometry(void* vertices, |
223 size_t offset, | 226 size_t offset, |
224 size_t vertexStride, | 227 size_t vertexStride, |
225 GrColor color, | 228 GrColor color, |
226 const SkMatrix& viewMatrix, | 229 const SkMatrix& viewMatrix, |
227 const SkRect& rect, | 230 const SkRect& rect, |
228 const SkRect& devRect, | 231 const SkRect& devRect, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 return; | 472 return; |
470 } | 473 } |
471 | 474 |
472 AAFillRectBatch::Geometry geometry; | 475 AAFillRectBatch::Geometry geometry; |
473 geometry.fRect = rect; | 476 geometry.fRect = rect; |
474 geometry.fViewMatrix = viewMatrix; | 477 geometry.fViewMatrix = viewMatrix; |
475 geometry.fDevRect = devRect; | 478 geometry.fDevRect = devRect; |
476 geometry.fColor = color; | 479 geometry.fColor = color; |
477 | 480 |
478 SkAutoTUnref<GrBatch> batch(AAFillRectBatch::Create(geometry, fAAFillRectInd
exBuffer)); | 481 SkAutoTUnref<GrBatch> batch(AAFillRectBatch::Create(geometry, fAAFillRectInd
exBuffer)); |
479 target->drawBatch(pipelineBuilder, batch, &devRect); | 482 target->drawBatch(pipelineBuilder, batch); |
480 } | 483 } |
481 | 484 |
482 void GrAARectRenderer::strokeAARect(GrDrawTarget* target, | 485 void GrAARectRenderer::strokeAARect(GrDrawTarget* target, |
483 GrPipelineBuilder* pipelineBuilder, | 486 GrPipelineBuilder* pipelineBuilder, |
484 GrColor color, | 487 GrColor color, |
485 const SkMatrix& viewMatrix, | 488 const SkMatrix& viewMatrix, |
486 const SkRect& rect, | 489 const SkRect& rect, |
487 const SkRect& devRect, | 490 const SkRect& devRect, |
488 const SkStrokeRec& stroke) { | 491 const SkStrokeRec& stroke) { |
489 SkVector devStrokeSize; | 492 SkVector devStrokeSize; |
490 SkScalar width = stroke.getWidth(); | 493 SkScalar width = stroke.getWidth(); |
491 if (width > 0) { | 494 if (width > 0) { |
492 devStrokeSize.set(width, width); | 495 devStrokeSize.set(width, width); |
493 viewMatrix.mapVectors(&devStrokeSize, 1); | 496 viewMatrix.mapVectors(&devStrokeSize, 1); |
494 devStrokeSize.setAbs(devStrokeSize); | 497 devStrokeSize.setAbs(devStrokeSize); |
495 } else { | 498 } else { |
496 devStrokeSize.set(SK_Scalar1, SK_Scalar1); | 499 devStrokeSize.set(SK_Scalar1, SK_Scalar1); |
497 } | 500 } |
498 | 501 |
499 const SkScalar dx = devStrokeSize.fX; | 502 const SkScalar dx = devStrokeSize.fX; |
500 const SkScalar dy = devStrokeSize.fY; | 503 const SkScalar dy = devStrokeSize.fY; |
501 const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf); | 504 const SkScalar rx = SkScalarMul(dx, SK_ScalarHalf); |
502 const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf); | 505 const SkScalar ry = SkScalarMul(dy, SK_ScalarHalf); |
503 | 506 |
504 // Temporarily #if'ed out. We don't want to pass in the devRect but | |
505 // right now it is computed in GrContext::apply_aa_to_rect and we don't | |
506 // want to throw away the work | |
507 #if 0 | |
508 SkRect devRect; | |
509 combinedMatrix.mapRect(&devRect, rect); | |
510 #endif | |
511 | |
512 SkScalar spare; | 507 SkScalar spare; |
513 { | 508 { |
514 SkScalar w = devRect.width() - dx; | 509 SkScalar w = devRect.width() - dx; |
515 SkScalar h = devRect.height() - dy; | 510 SkScalar h = devRect.height() - dy; |
516 spare = SkTMin(w, h); | 511 spare = SkTMin(w, h); |
517 } | 512 } |
518 | 513 |
519 SkRect devOutside(devRect); | 514 SkRect devOutside(devRect); |
520 devOutside.outset(rx, ry); | 515 devOutside.outset(rx, ry); |
521 | 516 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 | 681 |
687 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 682 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
688 | 683 |
689 private: | 684 private: |
690 AAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix, | 685 AAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix, |
691 const GrIndexBuffer* indexBuffer) | 686 const GrIndexBuffer* indexBuffer) |
692 : fIndexBuffer(indexBuffer) { | 687 : fIndexBuffer(indexBuffer) { |
693 this->initClassID<AAStrokeRectBatch>(); | 688 this->initClassID<AAStrokeRectBatch>(); |
694 fBatch.fViewMatrix = viewMatrix; | 689 fBatch.fViewMatrix = viewMatrix; |
695 fGeoData.push_back(geometry); | 690 fGeoData.push_back(geometry); |
| 691 |
| 692 // If we have miterstroke then we inset devOutside and outset devOutside
Assist, so we need |
| 693 // the join for proper bounds |
| 694 fBounds = geometry.fDevOutside; |
| 695 fBounds.join(geometry.fDevOutsideAssist); |
696 } | 696 } |
697 | 697 |
698 GrColor color() const { return fBatch.fColor; } | 698 GrColor color() const { return fBatch.fColor; } |
699 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 699 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
700 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } | 700 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } |
701 bool colorIgnored() const { return fBatch.fColorIgnored; } | 701 bool colorIgnored() const { return fBatch.fColorIgnored; } |
702 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 702 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
703 bool miterStroke() const { return fBatch.fMiterStroke; } | 703 bool miterStroke() const { return fBatch.fMiterStroke; } |
704 | 704 |
705 bool onCombineIfPossible(GrBatch* t) override { | 705 bool onCombineIfPossible(GrBatch* t) override { |
(...skipping 14 matching lines...) Expand all Loading... |
720 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to | 720 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to |
721 // not tweaking | 721 // not tweaking |
722 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()
) { | 722 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()
) { |
723 fBatch.fCanTweakAlphaForCoverage = false; | 723 fBatch.fCanTweakAlphaForCoverage = false; |
724 } | 724 } |
725 | 725 |
726 if (this->color() != that->color()) { | 726 if (this->color() != that->color()) { |
727 fBatch.fColor = GrColor_ILLEGAL; | 727 fBatch.fColor = GrColor_ILLEGAL; |
728 } | 728 } |
729 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 729 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; |
| 730 this->joinBounds(that->bounds()); |
730 return true; | 731 return true; |
731 } | 732 } |
732 | 733 |
733 void generateAAStrokeRectGeometry(void* vertices, | 734 void generateAAStrokeRectGeometry(void* vertices, |
734 size_t offset, | 735 size_t offset, |
735 size_t vertexStride, | 736 size_t vertexStride, |
736 int outerVertexNum, | 737 int outerVertexNum, |
737 int innerVertexNum, | 738 int innerVertexNum, |
738 GrColor color, | 739 GrColor color, |
739 const SkRect& devOutside, | 740 const SkRect& devOutside, |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 geo.fColor = GrRandomColor(random); | 956 geo.fColor = GrRandomColor(random); |
956 geo.fDevOutside = outside; | 957 geo.fDevOutside = outside; |
957 geo.fDevOutsideAssist = outsideAssist; | 958 geo.fDevOutsideAssist = outsideAssist; |
958 geo.fDevInside = inside; | 959 geo.fDevInside = inside; |
959 geo.fMiterStroke = miterStroke; | 960 geo.fMiterStroke = miterStroke; |
960 | 961 |
961 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random), indexBuffe
r); | 962 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random), indexBuffe
r); |
962 } | 963 } |
963 | 964 |
964 #endif | 965 #endif |
OLD | NEW |