| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 static GrBatch* Create(const Geometry& geometry, const GrIndexBuffer* indexB
uffer) { | 65 static GrBatch* Create(const Geometry& geometry, const GrIndexBuffer* indexB
uffer) { |
| 66 return SkNEW_ARGS(AAFillRectBatch, (geometry, indexBuffer)); | 66 return SkNEW_ARGS(AAFillRectBatch, (geometry, indexBuffer)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 const char* name() const SK_OVERRIDE { return "AAFillRectBatch"; } | 69 const char* name() const SK_OVERRIDE { return "AAFillRectBatch"; } |
| 70 | 70 |
| 71 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE { | 71 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE { |
| 72 // When this is called on a batch, there is only one geometry bundle | 72 // When this is called on a batch, there is only one geometry bundle |
| 73 if (!this->canTweakAlphaForCoverage() && GrColorIsOpaque(fGeoData[0].fCo
lor)) { | 73 out->setKnownFourComponents(fGeoData[0].fColor); |
| 74 out->setUnknownOpaqueFourComponents(); | |
| 75 } else { | |
| 76 out->setUnknownFourComponents(); | |
| 77 } | |
| 78 } | 74 } |
| 79 | 75 |
| 80 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E { | 76 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E { |
| 81 if (this->canTweakAlphaForCoverage()) { | 77 out->setUnknownSingleComponent(); |
| 82 // uniform coverage | |
| 83 out->setKnownSingleComponent(0xff); | |
| 84 } else { | |
| 85 out->setUnknownSingleComponent(); | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 void initBatchOpt(const GrBatchOpt& batchOpt) { | |
| 90 fBatchOpt = batchOpt; | |
| 91 } | 78 } |
| 92 | 79 |
| 93 void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE { | 80 void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE { |
| 94 // Handle any color overrides | 81 // Handle any color overrides |
| 95 if (init.fColorIgnored) { | 82 if (init.fColorIgnored) { |
| 96 fGeoData[0].fColor = GrColor_ILLEGAL; | 83 fGeoData[0].fColor = GrColor_ILLEGAL; |
| 97 } else if (GrColor_ILLEGAL != init.fOverrideColor) { | 84 } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 98 fGeoData[0].fColor = init.fOverrideColor; | 85 fGeoData[0].fColor = init.fOverrideColor; |
| 99 } | 86 } |
| 100 | 87 |
| 101 // setup batch properties | 88 // setup batch properties |
| 102 fBatch.fColorIgnored = init.fColorIgnored; | 89 fBatch.fColorIgnored = init.fColorIgnored; |
| 103 fBatch.fColor = fGeoData[0].fColor; | 90 fBatch.fColor = fGeoData[0].fColor; |
| 104 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; | 91 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 105 fBatch.fCoverageIgnored = init.fCoverageIgnored; | 92 fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 93 fBatch.fCanTweakAlphaForCoverage = init.fCanTweakAlphaForCoverage; |
| 106 } | 94 } |
| 107 | 95 |
| 108 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) SK_OVERRIDE { | 96 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) SK_OVERRIDE { |
| 109 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 97 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 110 | 98 |
| 111 SkMatrix localMatrix; | 99 SkMatrix localMatrix; |
| 112 if (!this->viewMatrix().invert(&localMatrix)) { | 100 if (!this->viewMatrix().invert(&localMatrix)) { |
| 113 SkDebugf("Cannot invert\n"); | 101 SkDebugf("Cannot invert\n"); |
| 114 return; | 102 return; |
| 115 } | 103 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 175 |
| 188 private: | 176 private: |
| 189 AAFillRectBatch(const Geometry& geometry, const GrIndexBuffer* indexBuffer) | 177 AAFillRectBatch(const Geometry& geometry, const GrIndexBuffer* indexBuffer) |
| 190 : fIndexBuffer(indexBuffer) { | 178 : fIndexBuffer(indexBuffer) { |
| 191 this->initClassID<AAFillRectBatch>(); | 179 this->initClassID<AAFillRectBatch>(); |
| 192 fGeoData.push_back(geometry); | 180 fGeoData.push_back(geometry); |
| 193 } | 181 } |
| 194 | 182 |
| 195 GrColor color() const { return fBatch.fColor; } | 183 GrColor color() const { return fBatch.fColor; } |
| 196 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 184 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 197 bool canTweakAlphaForCoverage() const { return fBatchOpt.fCanTweakAlphaForCo
verage; } | 185 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } |
| 198 bool colorIgnored() const { return fBatch.fColorIgnored; } | 186 bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 199 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 187 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 200 | 188 |
| 201 bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { | 189 bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { |
| 202 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); | 190 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); |
| 203 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()
) { | |
| 204 return false; | |
| 205 } | |
| 206 | |
| 207 if (this->colorIgnored() != that->colorIgnored()) { | |
| 208 return false; | |
| 209 } | |
| 210 | 191 |
| 211 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 192 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 212 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses | 193 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses |
| 213 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix | 194 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix |
| 214 // using vertex attributes in these cases, but haven't investigated that | 195 // using vertex attributes in these cases, but haven't investigated that |
| 215 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { | 196 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { |
| 216 return false; | 197 return false; |
| 217 } | 198 } |
| 218 | 199 |
| 219 if (this->color() != that->color()) { | 200 if (this->color() != that->color()) { |
| 220 fBatch.fColor = GrColor_ILLEGAL; | 201 fBatch.fColor = GrColor_ILLEGAL; |
| 221 } | 202 } |
| 203 |
| 204 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to |
| 205 // not tweaking |
| 206 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()
) { |
| 207 fBatch.fCanTweakAlphaForCoverage = false; |
| 208 } |
| 209 |
| 222 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 210 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; |
| 223 return true; | 211 return true; |
| 224 } | 212 } |
| 225 | 213 |
| 226 void generateAAFillRectGeometry(void* vertices, | 214 void generateAAFillRectGeometry(void* vertices, |
| 227 size_t offset, | 215 size_t offset, |
| 228 size_t vertexStride, | 216 size_t vertexStride, |
| 229 GrColor color, | 217 GrColor color, |
| 230 const SkMatrix& viewMatrix, | 218 const SkMatrix& viewMatrix, |
| 231 const SkRect& rect, | 219 const SkRect& rect, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 sizeof(GrColor)) = innerCoverage; | 302 sizeof(GrColor)) = innerCoverage; |
| 315 } | 303 } |
| 316 } | 304 } |
| 317 } | 305 } |
| 318 | 306 |
| 319 struct BatchTracker { | 307 struct BatchTracker { |
| 320 GrColor fColor; | 308 GrColor fColor; |
| 321 bool fUsesLocalCoords; | 309 bool fUsesLocalCoords; |
| 322 bool fColorIgnored; | 310 bool fColorIgnored; |
| 323 bool fCoverageIgnored; | 311 bool fCoverageIgnored; |
| 312 bool fCanTweakAlphaForCoverage; |
| 324 }; | 313 }; |
| 325 | 314 |
| 326 GrBatchOpt fBatchOpt; | |
| 327 BatchTracker fBatch; | 315 BatchTracker fBatch; |
| 328 const GrIndexBuffer* fIndexBuffer; | 316 const GrIndexBuffer* fIndexBuffer; |
| 329 SkSTArray<1, Geometry, true> fGeoData; | 317 SkSTArray<1, Geometry, true> fGeoData; |
| 330 }; | 318 }; |
| 331 | 319 |
| 332 namespace { | 320 namespace { |
| 333 // Should the coverage be multiplied into the color attrib or use a separate att
rib. | 321 // Should the coverage be multiplied into the color attrib or use a separate att
rib. |
| 334 enum CoverageAttribType { | 322 enum CoverageAttribType { |
| 335 kUseColor_CoverageAttribType, | 323 kUseColor_CoverageAttribType, |
| 336 kUseCoverage_CoverageAttribType, | 324 kUseCoverage_CoverageAttribType, |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 | 708 |
| 721 if (devInside.isEmpty()) { | 709 if (devInside.isEmpty()) { |
| 722 this->fillAARect(target, pipelineBuilder, color, viewMatrix, devOutside, | 710 this->fillAARect(target, pipelineBuilder, color, viewMatrix, devOutside, |
| 723 devOutside); | 711 devOutside); |
| 724 return; | 712 return; |
| 725 } | 713 } |
| 726 | 714 |
| 727 this->geometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOu
tside, | 715 this->geometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOu
tside, |
| 728 devOutsideAssist, devInside, true); | 716 devOutsideAssist, devInside, true); |
| 729 } | 717 } |
| OLD | NEW |