jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 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 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 12 | #include "GrBatchAtlas.h" |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 13 | #include "GrPathRenderer.h" |
| 14 | #include "GrRect.h" |
| 15 | |
| 16 | #include "SkChecksum.h" |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 17 | #include "SkTDynamicHash.h" |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 18 | |
| 19 | class GrContext; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 20 | |
| 21 | class GrAADistanceFieldPathRenderer : public GrPathRenderer { |
| 22 | public: |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 23 | GrAADistanceFieldPathRenderer(); |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 24 | virtual ~GrAADistanceFieldPathRenderer(); |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 25 | |
| 26 | private: |
robertphillips | e7d4b2f | 2015-08-13 07:57:10 -0700 | [diff] [blame] | 27 | StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const override { |
| 28 | return GrPathRenderer::kNoSupport_StencilSupport; |
| 29 | } |
bsalomon | 0aff2fa | 2015-07-31 06:48:27 -0700 | [diff] [blame] | 30 | |
| 31 | bool onCanDrawPath(const CanDrawPathArgs&) const override; |
| 32 | |
| 33 | bool onDrawPath(const DrawPathArgs&) override; |
| 34 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 35 | struct PathData { |
jvanverth | 512e437 | 2015-11-23 11:50:02 -0800 | [diff] [blame] | 36 | class Key { |
| 37 | public: |
| 38 | // default ctor needed for new of uninitialized PathData |
| 39 | // since fStroke has no default ctor |
| 40 | Key() |
| 41 | : fGenID(0) |
| 42 | , fDimension(0) |
| 43 | , fStroke(SkStrokeRec::kFill_InitStyle) {} |
| 44 | 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: |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 55 | uint32_t fGenID; |
| 56 | // rendered size for stored path (32x32 max, 64x64 max, 128x128 max) |
| 57 | uint32_t fDimension; |
jvanverth | 512e437 | 2015-11-23 11:50:02 -0800 | [diff] [blame] | 58 | // stroking information |
| 59 | SkStrokeRec fStroke; |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 60 | }; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 61 | Key fKey; |
| 62 | SkScalar fScale; |
| 63 | GrBatchAtlas::AtlasID fID; |
| 64 | SkRect fBounds; |
| 65 | SkIPoint16 fAtlasLocation; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 66 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData); |
| 67 | |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 68 | static inline const Key& GetKey(const PathData& data) { |
| 69 | return data.fKey; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 70 | } |
| 71 | |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 72 | static inline uint32_t Hash(Key key) { |
| 73 | return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(key)); |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 74 | } |
| 75 | }; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 76 | |
| 77 | static void HandleEviction(GrBatchAtlas::AtlasID, void*); |
| 78 | |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 79 | typedef SkTDynamicHash<PathData, PathData::Key> PathCache; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 80 | typedef SkTInternalLList<PathData> PathDataList; |
| 81 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 82 | GrBatchAtlas* fAtlas; |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 83 | PathCache fPathCache; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 84 | PathDataList fPathList; |
| 85 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 86 | typedef GrPathRenderer INHERITED; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 87 | |
| 88 | friend class AADistanceFieldPathBatch; |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 89 | friend struct PathTestStruct; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | #endif |