Chromium Code Reviews| 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 #ifndef GrAADistanceFieldPathRenderer_DEFINED | 8 #ifndef GrAADistanceFieldPathRenderer_DEFINED |
| 9 #define GrAADistanceFieldPathRenderer_DEFINED | 9 #define GrAADistanceFieldPathRenderer_DEFINED |
| 10 | 10 |
| 11 #include "GrBatchAtlas.h" | 11 #include "GrBatchAtlas.h" |
| 12 #include "GrPathRenderer.h" | 12 #include "GrPathRenderer.h" |
| 13 #include "GrRect.h" | 13 #include "GrRect.h" |
| 14 #include "GrShape.h" | |
| 14 | 15 |
| 15 #include "SkChecksum.h" | 16 #include "SkChecksum.h" |
| 16 #include "SkTDynamicHash.h" | 17 #include "SkTDynamicHash.h" |
| 17 | 18 |
| 18 class GrContext; | 19 class GrContext; |
| 19 | 20 |
| 20 class GrAADistanceFieldPathRenderer : public GrPathRenderer { | 21 class GrAADistanceFieldPathRenderer : public GrPathRenderer { |
| 21 public: | 22 public: |
| 22 GrAADistanceFieldPathRenderer(); | 23 GrAADistanceFieldPathRenderer(); |
| 23 virtual ~GrAADistanceFieldPathRenderer(); | 24 virtual ~GrAADistanceFieldPathRenderer(); |
| 24 | 25 |
| 25 private: | 26 private: |
| 26 StencilSupport onGetStencilSupport(const GrShape&) const override { | 27 StencilSupport onGetStencilSupport(const GrShape&) const override { |
| 27 return GrPathRenderer::kNoSupport_StencilSupport; | 28 return GrPathRenderer::kNoSupport_StencilSupport; |
| 28 } | 29 } |
| 29 | 30 |
| 30 bool onCanDrawPath(const CanDrawPathArgs&) const override; | 31 bool onCanDrawPath(const CanDrawPathArgs&) const override; |
| 31 | 32 |
| 32 bool onDrawPath(const DrawPathArgs&) override; | 33 bool onDrawPath(const DrawPathArgs&) override; |
| 33 | 34 |
| 34 struct PathData { | 35 struct ShapeData { |
| 35 class Key { | 36 class Key { |
| 36 public: | 37 public: |
| 37 // default ctor needed for new of uninitialized PathData | 38 Key() {} |
| 38 // since fStroke has no default ctor | 39 Key(const Key& that) { *this = that; } |
| 39 Key() | 40 Key(const GrShape& shape, uint32_t dim) { this->set(shape, dim); } |
| 40 : fGenID(0) | |
| 41 , fDimension(0) | |
| 42 , fStroke(SkStrokeRec::kFill_InitStyle) {} | |
| 43 Key(uint32_t genID, uint32_t dim, const SkStrokeRec& stroke) | |
| 44 : fGenID(genID) | |
| 45 , fDimension(dim) | |
| 46 , fStroke(stroke) {} | |
| 47 | 41 |
| 48 bool operator==(const Key& other) const { | 42 Key& operator=(const Key& that) { |
| 49 return other.fGenID == fGenID && other.fDimension == fDimension && | 43 fKey.reset(that.fKey.count()); |
| 50 fStroke.hasEqualEffect(other.fStroke); | 44 memcpy(fKey.get(), that.fKey.get(), fKey.count() * sizeof(uint32 _t)); |
| 45 return *this; | |
| 51 } | 46 } |
| 52 | 47 |
| 48 void set(const GrShape& shape, uint32_t dim) { | |
| 49 SkASSERT(shape.hasUnstyledKey()); | |
| 50 int shapeCnt = shape.unstyledKeySize(); | |
|
egdaniel
2016/06/27 13:16:58
shapeCnt? maybe keySize or unstyledKeySize?
| |
| 51 fKey.reset(1 + shapeCnt); | |
| 52 fKey[0] = dim; | |
| 53 shape.writeUnstyledKey(&fKey[1]); | |
| 54 } | |
| 55 | |
| 56 bool operator==(const Key& that) const { | |
| 57 return fKey.count() == that.fKey.count() && | |
| 58 0 == memcmp(fKey.get(), that.fKey.get(), sizeof(uint32_t ) * fKey.count()); | |
| 59 } | |
| 60 | |
| 61 int count32() const { return fKey.count(); } | |
| 62 const uint32_t* data() const { return fKey.get(); } | |
| 63 | |
| 53 private: | 64 private: |
| 54 uint32_t fGenID; | |
| 55 // rendered size for stored path (32x32 max, 64x64 max, 128x128 max) | 65 // rendered size for stored path (32x32 max, 64x64 max, 128x128 max) |
|
egdaniel
2016/06/27 13:16:58
I don't think this comment is clear that it refers
bsalomon
2016/06/27 13:37:52
Done.
| |
| 56 uint32_t fDimension; | 66 SkAutoSTArray<24, uint32_t> fKey; |
| 57 // stroking information | |
| 58 SkStrokeRec fStroke; | |
| 59 }; | 67 }; |
| 60 Key fKey; | 68 Key fKey; |
| 61 SkScalar fScale; | 69 SkScalar fScale; |
| 62 GrBatchAtlas::AtlasID fID; | 70 GrBatchAtlas::AtlasID fID; |
| 63 SkRect fBounds; | 71 SkRect fBounds; |
| 64 SkIPoint16 fAtlasLocation; | 72 SkIPoint16 fAtlasLocation; |
| 65 SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData); | 73 SK_DECLARE_INTERNAL_LLIST_INTERFACE(ShapeData); |
| 66 | 74 |
| 67 static inline const Key& GetKey(const PathData& data) { | 75 static inline const Key& GetKey(const ShapeData& data) { |
| 68 return data.fKey; | 76 return data.fKey; |
| 69 } | 77 } |
| 70 | 78 |
| 71 static inline uint32_t Hash(Key key) { | 79 static inline uint32_t Hash(Key key) { |
| 72 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(key)); | 80 return SkChecksum::Murmur3(key.data(), sizeof(uint32_t) * key.count3 2()); |
| 73 } | 81 } |
| 74 }; | 82 }; |
| 75 | 83 |
| 76 static void HandleEviction(GrBatchAtlas::AtlasID, void*); | 84 static void HandleEviction(GrBatchAtlas::AtlasID, void*); |
| 77 | 85 |
| 78 typedef SkTDynamicHash<PathData, PathData::Key> PathCache; | 86 typedef SkTDynamicHash<ShapeData, ShapeData::Key> ShapeCache; |
| 79 typedef SkTInternalLList<PathData> PathDataList; | 87 typedef SkTInternalLList<ShapeData> ShapeDataList; |
| 80 | 88 |
| 81 GrBatchAtlas* fAtlas; | 89 GrBatchAtlas* fAtlas; |
| 82 PathCache fPathCache; | 90 ShapeCache fShapeCache; |
| 83 PathDataList fPathList; | 91 ShapeDataList fShapeList; |
| 84 | 92 |
| 85 typedef GrPathRenderer INHERITED; | 93 typedef GrPathRenderer INHERITED; |
| 86 | 94 |
| 87 friend class AADistanceFieldPathBatch; | 95 friend class AADistanceFieldPathBatch; |
| 88 friend struct PathTestStruct; | 96 friend struct PathTestStruct; |
| 89 }; | 97 }; |
| 90 | 98 |
| 91 #endif | 99 #endif |
| OLD | NEW |