1 2 /* 3 * Copyright 2014 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 #ifndef GrAADistanceFieldPathRenderer_DEFINED 10 #define GrAADistanceFieldPathRenderer_DEFINED 11 12 #include "GrBatchAtlas.h" 13 #include "GrPathRenderer.h" 14 #include "GrRect.h" 15 16 #include "SkChecksum.h" 17 #include "SkTDynamicHash.h" 18 19 class GrContext; 20 21 class GrAADistanceFieldPathRenderer : public GrPathRenderer { 22 public: 23 GrAADistanceFieldPathRenderer(); 24 virtual ~GrAADistanceFieldPathRenderer(); 25 26 private: onGetStencilSupport(const SkPath &,const GrStrokeInfo &)27 StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const override { 28 return GrPathRenderer::kNoSupport_StencilSupport; 29 } 30 31 bool onCanDrawPath(const CanDrawPathArgs&) const override; 32 33 bool onDrawPath(const DrawPathArgs&) override; 34 35 struct PathData { 36 class Key { 37 public: 38 // default ctor needed for new of uninitialized PathData 39 // since fStroke has no default ctor KeyPathData40 Key() 41 : fGenID(0) 42 , fDimension(0) 43 , fStroke(SkStrokeRec::kFill_InitStyle) {} KeyPathData44 Key(uint32_t genID, uint32_t dim, const SkStrokeRec& stroke) 45 : fGenID(genID) 46 , fDimension(dim) 47 , fStroke(stroke) {} 48 49 bool operator==(const Key& other) const { 50 return other.fGenID == fGenID && other.fDimension == fDimension && 51 fStroke.hasEqualEffect(other.fStroke); 52 } 53 54 private: 55 uint32_t fGenID; 56 // rendered size for stored path (32x32 max, 64x64 max, 128x128 max) 57 uint32_t fDimension; 58 // stroking information 59 SkStrokeRec fStroke; 60 }; 61 Key fKey; 62 SkScalar fScale; 63 GrBatchAtlas::AtlasID fID; 64 SkRect fBounds; 65 SkIPoint16 fAtlasLocation; 66 SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData); 67 GetKeyPathData68 static inline const Key& GetKey(const PathData& data) { 69 return data.fKey; 70 } 71 HashPathData72 static inline uint32_t Hash(Key key) { 73 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(key)); 74 } 75 }; 76 77 static void HandleEviction(GrBatchAtlas::AtlasID, void*); 78 79 typedef SkTDynamicHash<PathData, PathData::Key> PathCache; 80 typedef SkTInternalLList<PathData> PathDataList; 81 82 GrBatchAtlas* fAtlas; 83 PathCache fPathCache; 84 PathDataList fPathList; 85 86 typedef GrPathRenderer INHERITED; 87 88 friend class AADistanceFieldPathBatch; 89 friend struct PathTestStruct; 90 }; 91 92 #endif 93