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 | |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 12 | #include "GrAtlas.h" |
| 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; |
| 20 | class GrPlot; |
| 21 | |
| 22 | class GrAADistanceFieldPathRenderer : public GrPathRenderer { |
| 23 | public: |
jvanverth | 6d22eca | 2014-10-28 11:10:48 -0700 | [diff] [blame] | 24 | GrAADistanceFieldPathRenderer(GrContext* context); |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 25 | virtual ~GrAADistanceFieldPathRenderer(); |
| 26 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 27 | virtual bool canDrawPath(const GrDrawTarget*, |
| 28 | const GrDrawState*, |
| 29 | const SkPath&, |
| 30 | const SkStrokeRec&, |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 31 | bool antiAlias) const SK_OVERRIDE; |
| 32 | |
| 33 | protected: |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 34 | virtual StencilSupport onGetStencilSupport(const GrDrawTarget*, |
| 35 | const GrDrawState*, |
| 36 | const SkPath&, |
| 37 | const SkStrokeRec&) const SK_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*, |
| 40 | GrDrawState*, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 41 | GrColor, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 42 | const SkPath&, |
| 43 | const SkStrokeRec&, |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 44 | bool antiAlias) SK_OVERRIDE; |
| 45 | |
| 46 | private: |
| 47 | struct PathData { |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 48 | struct Key { |
| 49 | uint32_t fGenID; |
| 50 | // rendered size for stored path (32x32 max, 64x64 max, 128x128 max) |
| 51 | uint32_t fDimension; |
| 52 | bool operator==(const Key& other) const { |
| 53 | return other.fGenID == fGenID && other.fDimension == fDimension; |
| 54 | } |
| 55 | }; |
| 56 | Key fKey; |
| 57 | SkScalar fScale; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 58 | GrPlot* fPlot; |
| 59 | SkRect fBounds; |
| 60 | SkIPoint16 fAtlasLocation; |
| 61 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData); |
| 62 | |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 63 | static inline const Key& GetKey(const PathData& data) { |
| 64 | return data.fKey; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 65 | } |
| 66 | |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 67 | static inline uint32_t Hash(Key key) { |
| 68 | return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(key)); |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 69 | } |
| 70 | }; |
| 71 | typedef SkTInternalLList<PathData> PathDataList; |
| 72 | |
| 73 | GrContext* fContext; |
| 74 | GrAtlas* fAtlas; |
jvanverth | 6d22eca | 2014-10-28 11:10:48 -0700 | [diff] [blame] | 75 | SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor; |
| 76 | // current set of flags used to create the cached geometry processor |
| 77 | uint32_t fEffectFlags; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 78 | GrAtlas::ClientPlotUsage fPlotUsage; |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 79 | SkTDynamicHash<PathData, PathData::Key> fPathCache; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 80 | PathDataList fPathList; |
| 81 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame^] | 82 | bool internalDrawPath(GrDrawTarget*, GrDrawState*, GrColor, const SkPath& path, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 83 | const PathData* pathData); |
jvanverth | b61283f | 2014-10-30 05:57:21 -0700 | [diff] [blame] | 84 | PathData* addPathToAtlas(const SkPath& path, const SkStrokeRec& stroke, bool antiAlias, |
| 85 | uint32_t dimension, SkScalar scale); |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 86 | bool freeUnusedPlot(); |
| 87 | |
| 88 | typedef GrPathRenderer INHERITED; |
| 89 | }; |
| 90 | |
| 91 | #endif |