| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrAADistanceFieldPathRenderer.h" | 9 #include "GrAADistanceFieldPathRenderer.h" |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 GrAADistanceFieldPathRenderer* dfpr = (GrAADistanceFieldPathRenderer*)pr; | 46 GrAADistanceFieldPathRenderer* dfpr = (GrAADistanceFieldPathRenderer*)pr; |
| 47 // remove any paths that use this plot | 47 // remove any paths that use this plot |
| 48 PathDataList::Iter iter; | 48 PathDataList::Iter iter; |
| 49 iter.init(dfpr->fPathList, PathDataList::Iter::kHead_IterStart); | 49 iter.init(dfpr->fPathList, PathDataList::Iter::kHead_IterStart); |
| 50 PathData* pathData; | 50 PathData* pathData; |
| 51 while ((pathData = iter.get())) { | 51 while ((pathData = iter.get())) { |
| 52 iter.next(); | 52 iter.next(); |
| 53 if (id == pathData->fID) { | 53 if (id == pathData->fID) { |
| 54 dfpr->fPathCache.remove(pathData->fKey); | 54 dfpr->fPathCache.remove(pathData->fKey); |
| 55 dfpr->fPathList.remove(pathData); | 55 dfpr->fPathList.remove(pathData); |
| 56 SkDELETE(pathData); | 56 delete pathData; |
| 57 #ifdef DF_PATH_TRACKING | 57 #ifdef DF_PATH_TRACKING |
| 58 ++g_NumFreedPaths; | 58 ++g_NumFreedPaths; |
| 59 #endif | 59 #endif |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 //////////////////////////////////////////////////////////////////////////////// | 64 //////////////////////////////////////////////////////////////////////////////// |
| 65 GrAADistanceFieldPathRenderer::GrAADistanceFieldPathRenderer() : fAtlas(NULL) {} | 65 GrAADistanceFieldPathRenderer::GrAADistanceFieldPathRenderer() : fAtlas(NULL) {} |
| 66 | 66 |
| 67 GrAADistanceFieldPathRenderer::~GrAADistanceFieldPathRenderer() { | 67 GrAADistanceFieldPathRenderer::~GrAADistanceFieldPathRenderer() { |
| 68 PathDataList::Iter iter; | 68 PathDataList::Iter iter; |
| 69 iter.init(fPathList, PathDataList::Iter::kHead_IterStart); | 69 iter.init(fPathList, PathDataList::Iter::kHead_IterStart); |
| 70 PathData* pathData; | 70 PathData* pathData; |
| 71 while ((pathData = iter.get())) { | 71 while ((pathData = iter.get())) { |
| 72 iter.next(); | 72 iter.next(); |
| 73 fPathList.remove(pathData); | 73 fPathList.remove(pathData); |
| 74 SkDELETE(pathData); | 74 delete pathData; |
| 75 } | 75 } |
| 76 SkDELETE(fAtlas); | 76 delete fAtlas; |
| 77 | 77 |
| 78 #ifdef DF_PATH_TRACKING | 78 #ifdef DF_PATH_TRACKING |
| 79 SkDebugf("Cached paths: %d, freed paths: %d\n", g_NumCachedPaths, g_NumFreed
Paths); | 79 SkDebugf("Cached paths: %d, freed paths: %d\n", g_NumCachedPaths, g_NumFreed
Paths); |
| 80 #endif | 80 #endif |
| 81 } | 81 } |
| 82 | 82 |
| 83 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
| 84 bool GrAADistanceFieldPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c
onst { | 84 bool GrAADistanceFieldPathRenderer::onCanDrawPath(const CanDrawPathArgs& args) c
onst { |
| 85 | 85 |
| 86 // TODO: Support inverse fill | 86 // TODO: Support inverse fill |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 struct Geometry { | 118 struct Geometry { |
| 119 Geometry(const SkStrokeRec& stroke) : fStroke(stroke) {} | 119 Geometry(const SkStrokeRec& stroke) : fStroke(stroke) {} |
| 120 SkPath fPath; | 120 SkPath fPath; |
| 121 SkStrokeRec fStroke; | 121 SkStrokeRec fStroke; |
| 122 bool fAntiAlias; | 122 bool fAntiAlias; |
| 123 PathData* fPathData; | 123 PathData* fPathData; |
| 124 }; | 124 }; |
| 125 | 125 |
| 126 static GrDrawBatch* Create(const Geometry& geometry, GrColor color, const Sk
Matrix& viewMatrix, | 126 static GrDrawBatch* Create(const Geometry& geometry, GrColor color, const Sk
Matrix& viewMatrix, |
| 127 GrBatchAtlas* atlas, PathCache* pathCache, PathDa
taList* pathList) { | 127 GrBatchAtlas* atlas, PathCache* pathCache, PathDa
taList* pathList) { |
| 128 return SkNEW_ARGS(AADistanceFieldPathBatch, (geometry, color, viewMatrix
, | 128 return new AADistanceFieldPathBatch(geometry, color, viewMatrix, atlas,
pathCache, |
| 129 atlas, pathCache, pathList)
); | 129 pathList); |
| 130 } | 130 } |
| 131 | 131 |
| 132 const char* name() const override { return "AADistanceFieldPathBatch"; } | 132 const char* name() const override { return "AADistanceFieldPathBatch"; } |
| 133 | 133 |
| 134 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 134 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 135 out->setKnownFourComponents(fBatch.fColor); | 135 out->setKnownFourComponents(fBatch.fColor); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 138 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 139 out->setUnknownSingleComponent(); | 139 out->setUnknownSingleComponent(); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 // check to see if path is cached | 225 // check to see if path is cached |
| 226 // TODO: handle stroked vs. filled version of same path | 226 // TODO: handle stroked vs. filled version of same path |
| 227 PathData::Key key = { args.fPath.getGenerationID(), desiredDimension
}; | 227 PathData::Key key = { args.fPath.getGenerationID(), desiredDimension
}; |
| 228 args.fPathData = fPathCache->find(key); | 228 args.fPathData = fPathCache->find(key); |
| 229 if (NULL == args.fPathData || !atlas->hasID(args.fPathData->fID)) { | 229 if (NULL == args.fPathData || !atlas->hasID(args.fPathData->fID)) { |
| 230 // Remove the stale cache entry | 230 // Remove the stale cache entry |
| 231 if (args.fPathData) { | 231 if (args.fPathData) { |
| 232 fPathCache->remove(args.fPathData->fKey); | 232 fPathCache->remove(args.fPathData->fKey); |
| 233 fPathList->remove(args.fPathData); | 233 fPathList->remove(args.fPathData); |
| 234 SkDELETE(args.fPathData); | 234 delete args.fPathData; |
| 235 } | 235 } |
| 236 SkScalar scale = desiredDimension/maxDim; | 236 SkScalar scale = desiredDimension/maxDim; |
| 237 args.fPathData = SkNEW(PathData); | 237 args.fPathData = new PathData; |
| 238 if (!this->addPathToAtlas(target, | 238 if (!this->addPathToAtlas(target, |
| 239 dfProcessor, | 239 dfProcessor, |
| 240 this->pipeline(), | 240 this->pipeline(), |
| 241 &flushInfo, | 241 &flushInfo, |
| 242 atlas, | 242 atlas, |
| 243 args.fPathData, | 243 args.fPathData, |
| 244 args.fPath, | 244 args.fPath, |
| 245 args.fStroke, | 245 args.fStroke, |
| 246 args.fAntiAlias, | 246 args.fAntiAlias, |
| 247 desiredDimension, | 247 desiredDimension, |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 PathTestStruct() : fContextID(SK_InvalidGenID), fAtlas(NULL) {} | 561 PathTestStruct() : fContextID(SK_InvalidGenID), fAtlas(NULL) {} |
| 562 ~PathTestStruct() { this->reset(); } | 562 ~PathTestStruct() { this->reset(); } |
| 563 | 563 |
| 564 void reset() { | 564 void reset() { |
| 565 PathDataList::Iter iter; | 565 PathDataList::Iter iter; |
| 566 iter.init(fPathList, PathDataList::Iter::kHead_IterStart); | 566 iter.init(fPathList, PathDataList::Iter::kHead_IterStart); |
| 567 PathData* pathData; | 567 PathData* pathData; |
| 568 while ((pathData = iter.get())) { | 568 while ((pathData = iter.get())) { |
| 569 iter.next(); | 569 iter.next(); |
| 570 fPathList.remove(pathData); | 570 fPathList.remove(pathData); |
| 571 SkDELETE(pathData); | 571 delete pathData; |
| 572 } | 572 } |
| 573 SkDELETE(fAtlas); | 573 delete fAtlas; |
| 574 fPathCache.reset(); | 574 fPathCache.reset(); |
| 575 } | 575 } |
| 576 | 576 |
| 577 static void HandleEviction(GrBatchAtlas::AtlasID id, void* pr) { | 577 static void HandleEviction(GrBatchAtlas::AtlasID id, void* pr) { |
| 578 PathTestStruct* dfpr = (PathTestStruct*)pr; | 578 PathTestStruct* dfpr = (PathTestStruct*)pr; |
| 579 // remove any paths that use this plot | 579 // remove any paths that use this plot |
| 580 PathDataList::Iter iter; | 580 PathDataList::Iter iter; |
| 581 iter.init(dfpr->fPathList, PathDataList::Iter::kHead_IterStart); | 581 iter.init(dfpr->fPathList, PathDataList::Iter::kHead_IterStart); |
| 582 PathData* pathData; | 582 PathData* pathData; |
| 583 while ((pathData = iter.get())) { | 583 while ((pathData = iter.get())) { |
| 584 iter.next(); | 584 iter.next(); |
| 585 if (id == pathData->fID) { | 585 if (id == pathData->fID) { |
| 586 dfpr->fPathCache.remove(pathData->fKey); | 586 dfpr->fPathCache.remove(pathData->fKey); |
| 587 dfpr->fPathList.remove(pathData); | 587 dfpr->fPathList.remove(pathData); |
| 588 SkDELETE(pathData); | 588 delete pathData; |
| 589 } | 589 } |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| 593 uint32_t fContextID; | 593 uint32_t fContextID; |
| 594 GrBatchAtlas* fAtlas; | 594 GrBatchAtlas* fAtlas; |
| 595 PathCache fPathCache; | 595 PathCache fPathCache; |
| 596 PathDataList fPathList; | 596 PathDataList fPathList; |
| 597 }; | 597 }; |
| 598 | 598 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 617 geometry.fPath = GrTest::TestPath(random); | 617 geometry.fPath = GrTest::TestPath(random); |
| 618 geometry.fAntiAlias = random->nextBool(); | 618 geometry.fAntiAlias = random->nextBool(); |
| 619 | 619 |
| 620 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, | 620 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, |
| 621 gTestStruct.fAtlas, | 621 gTestStruct.fAtlas, |
| 622 &gTestStruct.fPathCache, | 622 &gTestStruct.fPathCache, |
| 623 &gTestStruct.fPathList); | 623 &gTestStruct.fPathList); |
| 624 } | 624 } |
| 625 | 625 |
| 626 #endif | 626 #endif |
| OLD | NEW |