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: |
jvanverth | 6d22eca | 2014-10-28 11:10:48 -0700 | [diff] [blame] | 23 | GrAADistanceFieldPathRenderer(GrContext* context); |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 24 | virtual ~GrAADistanceFieldPathRenderer(); |
| 25 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 26 | virtual bool canDrawPath(const GrDrawTarget*, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 27 | const GrPipelineBuilder*, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 28 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 29 | const SkPath&, |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 30 | const GrStrokeInfo&, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 31 | bool antiAlias) const override; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 32 | |
| 33 | protected: |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 34 | virtual StencilSupport onGetStencilSupport(const GrDrawTarget*, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 35 | const GrPipelineBuilder*, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 36 | const SkPath&, |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 37 | const GrStrokeInfo&) const override; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 38 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 39 | virtual bool onDrawPath(GrDrawTarget*, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 40 | GrPipelineBuilder*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 41 | GrColor, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 42 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 43 | const SkPath&, |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 44 | const GrStrokeInfo&, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 45 | bool antiAlias) override; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | struct PathData { |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 49 | struct Key { |
| 50 | uint32_t fGenID; |
| 51 | // rendered size for stored path (32x32 max, 64x64 max, 128x128 max) |
| 52 | uint32_t fDimension; |
| 53 | bool operator==(const Key& other) const { |
| 54 | return other.fGenID == fGenID && other.fDimension == fDimension; |
| 55 | } |
| 56 | }; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 57 | Key fKey; |
| 58 | SkScalar fScale; |
| 59 | GrBatchAtlas::AtlasID fID; |
| 60 | SkRect fBounds; |
| 61 | SkIPoint16 fAtlasLocation; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 62 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData); |
| 63 | |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 64 | static inline const Key& GetKey(const PathData& data) { |
| 65 | return data.fKey; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 66 | } |
| 67 | |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 68 | static inline uint32_t Hash(Key key) { |
| 69 | return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(key)); |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 70 | } |
| 71 | }; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 72 | |
| 73 | static void HandleEviction(GrBatchAtlas::AtlasID, void*); |
| 74 | |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 75 | typedef SkTDynamicHash<PathData, PathData::Key> PathCache; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 76 | typedef SkTInternalLList<PathData> PathDataList; |
| 77 | |
| 78 | GrContext* fContext; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 79 | GrBatchAtlas* fAtlas; |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 80 | PathCache fPathCache; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 81 | PathDataList fPathList; |
| 82 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 83 | typedef GrPathRenderer INHERITED; |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 84 | |
| 85 | friend class AADistanceFieldPathBatch; |
joshualitt | 21279c7 | 2015-05-11 07:21:37 -0700 | [diff] [blame] | 86 | friend struct PathTestStruct; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | #endif |