| 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 "GrAADistanceFieldPathRenderer.h" | 8 #include "GrAADistanceFieldPathRenderer.h" |
| 9 | 9 |
| 10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 SkPath fPath; | 141 SkPath fPath; |
| 142 // The unique ID of the path involved in this draw. This may be differen
t than the ID | 142 // The unique ID of the path involved in this draw. This may be differen
t than the ID |
| 143 // in fPath since that path may have resulted from a SkStrokeRec::applyT
oPath call. | 143 // in fPath since that path may have resulted from a SkStrokeRec::applyT
oPath call. |
| 144 uint32_t fGenID; | 144 uint32_t fGenID; |
| 145 SkStrokeRec fStroke; | 145 SkStrokeRec fStroke; |
| 146 GrColor fColor; | 146 GrColor fColor; |
| 147 bool fAntiAlias; | 147 bool fAntiAlias; |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMat
rix, | 150 static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMat
rix, |
| 151 GrBatchAtlas* atlas, PathCache* pathCache, PathDa
taList* pathList) { | 151 GrBatchAtlas* atlas, PathCache* pathCache, PathDa
taList* pathList, |
| 152 return new AADistanceFieldPathBatch(geometry, viewMatrix, atlas, pathCac
he, pathList); | 152 bool gammaCorrect) { |
| 153 return new AADistanceFieldPathBatch(geometry, viewMatrix, atlas, pathCac
he, pathList, |
| 154 gammaCorrect); |
| 153 } | 155 } |
| 154 | 156 |
| 155 const char* name() const override { return "AADistanceFieldPathBatch"; } | 157 const char* name() const override { return "AADistanceFieldPathBatch"; } |
| 156 | 158 |
| 157 void computePipelineOptimizations(GrInitInvariantOutput* color, | 159 void computePipelineOptimizations(GrInitInvariantOutput* color, |
| 158 GrInitInvariantOutput* coverage, | 160 GrInitInvariantOutput* coverage, |
| 159 GrBatchToXPOverrides* overrides) const ove
rride { | 161 GrBatchToXPOverrides* overrides) const ove
rride { |
| 160 color->setKnownFourComponents(fGeoData[0].fColor); | 162 color->setKnownFourComponents(fGeoData[0].fColor); |
| 161 coverage->setUnknownSingleComponent(); | 163 coverage->setUnknownSingleComponent(); |
| 162 } | 164 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 189 SkMatrix invert; | 191 SkMatrix invert; |
| 190 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { | 192 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { |
| 191 SkDebugf("Could not invert viewmatrix\n"); | 193 SkDebugf("Could not invert viewmatrix\n"); |
| 192 return; | 194 return; |
| 193 } | 195 } |
| 194 | 196 |
| 195 const SkMatrix& ctm = this->viewMatrix(); | 197 const SkMatrix& ctm = this->viewMatrix(); |
| 196 uint32_t flags = 0; | 198 uint32_t flags = 0; |
| 197 flags |= ctm.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0
; | 199 flags |= ctm.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0
; |
| 198 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; | 200 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; |
| 201 flags |= fGammaCorrect ? kGammaCorrect_DistanceFieldEffectFlag : 0; |
| 199 | 202 |
| 200 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil
erp_FilterMode); | 203 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil
erp_FilterMode); |
| 201 | 204 |
| 202 FlushInfo flushInfo; | 205 FlushInfo flushInfo; |
| 203 | 206 |
| 204 // Setup GrGeometryProcessor | 207 // Setup GrGeometryProcessor |
| 205 GrBatchAtlas* atlas = fAtlas; | 208 GrBatchAtlas* atlas = fAtlas; |
| 206 flushInfo.fGeometryProcessor.reset( | 209 flushInfo.fGeometryProcessor.reset( |
| 207 GrDistanceFieldPathGeoProc::Create(this->color(), | 210 GrDistanceFieldPathGeoProc::Create(this->color(), |
| 208 this->viewMatrix(), | 211 this->viewMatrix(), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 } | 292 } |
| 290 | 293 |
| 291 this->flush(target, &flushInfo); | 294 this->flush(target, &flushInfo); |
| 292 } | 295 } |
| 293 | 296 |
| 294 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 297 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 295 | 298 |
| 296 AADistanceFieldPathBatch(const Geometry& geometry, | 299 AADistanceFieldPathBatch(const Geometry& geometry, |
| 297 const SkMatrix& viewMatrix, | 300 const SkMatrix& viewMatrix, |
| 298 GrBatchAtlas* atlas, | 301 GrBatchAtlas* atlas, |
| 299 PathCache* pathCache, PathDataList* pathList) | 302 PathCache* pathCache, PathDataList* pathList, |
| 303 bool gammaCorrect) |
| 300 : INHERITED(ClassID()) { | 304 : INHERITED(ClassID()) { |
| 301 fBatch.fViewMatrix = viewMatrix; | 305 fBatch.fViewMatrix = viewMatrix; |
| 302 fGeoData.push_back(geometry); | 306 fGeoData.push_back(geometry); |
| 303 | 307 |
| 304 fAtlas = atlas; | 308 fAtlas = atlas; |
| 305 fPathCache = pathCache; | 309 fPathCache = pathCache; |
| 306 fPathList = pathList; | 310 fPathList = pathList; |
| 311 fGammaCorrect = gammaCorrect; |
| 307 | 312 |
| 308 // Compute bounds | 313 // Compute bounds |
| 309 fBounds = geometry.fPath.getBounds(); | 314 fBounds = geometry.fPath.getBounds(); |
| 310 viewMatrix.mapRect(&fBounds); | 315 viewMatrix.mapRect(&fBounds); |
| 311 } | 316 } |
| 312 | 317 |
| 313 bool addPathToAtlas(GrVertexBatch::Target* target, | 318 bool addPathToAtlas(GrVertexBatch::Target* target, |
| 314 FlushInfo* flushInfo, | 319 FlushInfo* flushInfo, |
| 315 GrBatchAtlas* atlas, | 320 GrBatchAtlas* atlas, |
| 316 PathData* pathData, | 321 PathData* pathData, |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 bool fUsesLocalCoords; | 522 bool fUsesLocalCoords; |
| 518 bool fColorIgnored; | 523 bool fColorIgnored; |
| 519 bool fCoverageIgnored; | 524 bool fCoverageIgnored; |
| 520 }; | 525 }; |
| 521 | 526 |
| 522 BatchTracker fBatch; | 527 BatchTracker fBatch; |
| 523 SkSTArray<1, Geometry, true> fGeoData; | 528 SkSTArray<1, Geometry, true> fGeoData; |
| 524 GrBatchAtlas* fAtlas; | 529 GrBatchAtlas* fAtlas; |
| 525 PathCache* fPathCache; | 530 PathCache* fPathCache; |
| 526 PathDataList* fPathList; | 531 PathDataList* fPathList; |
| 532 bool fGammaCorrect; |
| 527 | 533 |
| 528 typedef GrVertexBatch INHERITED; | 534 typedef GrVertexBatch INHERITED; |
| 529 }; | 535 }; |
| 530 | 536 |
| 531 bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) { | 537 bool GrAADistanceFieldPathRenderer::onDrawPath(const DrawPathArgs& args) { |
| 532 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), | 538 GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), |
| 533 "GrAADistanceFieldPathRenderer::onDrawPath"); | 539 "GrAADistanceFieldPathRenderer::onDrawPath"); |
| 534 // we've already bailed on inverse filled paths, so this is safe | 540 // we've already bailed on inverse filled paths, so this is safe |
| 535 if (args.fPath->isEmpty()) { | 541 if (args.fPath->isEmpty()) { |
| 536 return true; | 542 return true; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 555 } | 561 } |
| 556 geometry.fColor = args.fColor; | 562 geometry.fColor = args.fColor; |
| 557 geometry.fAntiAlias = args.fAntiAlias; | 563 geometry.fAntiAlias = args.fAntiAlias; |
| 558 // Note: this is the generation ID of the _original_ path. When a new path i
s | 564 // Note: this is the generation ID of the _original_ path. When a new path i
s |
| 559 // generated due to stroking it is important that the original path's id is
used | 565 // generated due to stroking it is important that the original path's id is
used |
| 560 // for caching. | 566 // for caching. |
| 561 geometry.fGenID = args.fPath->getGenerationID(); | 567 geometry.fGenID = args.fPath->getGenerationID(); |
| 562 | 568 |
| 563 SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, | 569 SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, |
| 564 *args.fView
Matrix, fAtlas, | 570 *args.fView
Matrix, fAtlas, |
| 565 &fPathCache
, &fPathList)); | 571 &fPathCache
, &fPathList, |
| 572 args.fGamma
Correct)); |
| 566 args.fTarget->drawBatch(*args.fPipelineBuilder, batch); | 573 args.fTarget->drawBatch(*args.fPipelineBuilder, batch); |
| 567 | 574 |
| 568 return true; | 575 return true; |
| 569 } | 576 } |
| 570 | 577 |
| 571 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 578 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 572 | 579 |
| 573 #ifdef GR_TEST_UTILS | 580 #ifdef GR_TEST_UTILS |
| 574 | 581 |
| 575 struct PathTestStruct { | 582 struct PathTestStruct { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 gTestStruct.fAtlas = | 630 gTestStruct.fAtlas = |
| 624 context->resourceProvider()->createAtlas(kAlpha_8_GrPixelConfig, | 631 context->resourceProvider()->createAtlas(kAlpha_8_GrPixelConfig, |
| 625 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, | 632 ATLAS_TEXTURE_WIDTH, ATLAS_
TEXTURE_HEIGHT, |
| 626 NUM_PLOTS_X, NUM_PLOTS_Y, | 633 NUM_PLOTS_X, NUM_PLOTS_Y, |
| 627 &PathTestStruct::HandleEvic
tion, | 634 &PathTestStruct::HandleEvic
tion, |
| 628 (void*)&gTestStruct); | 635 (void*)&gTestStruct); |
| 629 } | 636 } |
| 630 | 637 |
| 631 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 638 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
| 632 GrColor color = GrRandomColor(random); | 639 GrColor color = GrRandomColor(random); |
| 640 bool gammaCorrect = random->nextBool(); |
| 633 | 641 |
| 634 AADistanceFieldPathBatch::Geometry geometry(GrTest::TestStrokeRec(random)); | 642 AADistanceFieldPathBatch::Geometry geometry(GrTest::TestStrokeRec(random)); |
| 635 geometry.fColor = color; | 643 geometry.fColor = color; |
| 636 geometry.fPath = GrTest::TestPath(random); | 644 geometry.fPath = GrTest::TestPath(random); |
| 637 geometry.fAntiAlias = random->nextBool(); | 645 geometry.fAntiAlias = random->nextBool(); |
| 638 geometry.fGenID = random->nextU(); | 646 geometry.fGenID = random->nextU(); |
| 639 | 647 |
| 640 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, | 648 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, |
| 641 gTestStruct.fAtlas, | 649 gTestStruct.fAtlas, |
| 642 &gTestStruct.fPathCache, | 650 &gTestStruct.fPathCache, |
| 643 &gTestStruct.fPathList); | 651 &gTestStruct.fPathList, |
| 652 gammaCorrect); |
| 644 } | 653 } |
| 645 | 654 |
| 646 #endif | 655 #endif |
| OLD | NEW |