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