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 | |
| 12 | #include "GrAllocPool.h" |
| 13 | #include "GrAtlas.h" |
| 14 | #include "GrPathRenderer.h" |
| 15 | #include "GrRect.h" |
| 16 | |
| 17 | #include "SkChecksum.h" |
| 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 | |
| 27 | virtual bool canDrawPath(const SkPath& path, |
| 28 | const SkStrokeRec& stroke, |
| 29 | const GrDrawTarget* target, |
| 30 | bool antiAlias) const SK_OVERRIDE; |
| 31 | |
| 32 | protected: |
| 33 | virtual StencilSupport onGetStencilSupport(const SkPath&, |
| 34 | const SkStrokeRec&, |
| 35 | const GrDrawTarget*) const SK_OVERRIDE; |
| 36 | |
| 37 | virtual bool onDrawPath(const SkPath& path, |
| 38 | const SkStrokeRec& stroke, |
| 39 | GrDrawTarget* target, |
| 40 | bool antiAlias) SK_OVERRIDE; |
| 41 | |
| 42 | private: |
| 43 | struct PathData { |
| 44 | uint32_t fGenID; |
| 45 | GrPlot* fPlot; |
| 46 | SkRect fBounds; |
| 47 | SkIPoint16 fAtlasLocation; |
| 48 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData); |
| 49 | |
| 50 | static inline const uint32_t& GetKey(const PathData& data) { |
| 51 | return data.fGenID; |
| 52 | } |
| 53 | |
| 54 | static inline uint32_t Hash(uint32_t key) { |
| 55 | return SkChecksum::Murmur3(&key, sizeof(key)); |
| 56 | } |
| 57 | }; |
| 58 | typedef SkTInternalLList<PathData> PathDataList; |
| 59 | |
| 60 | GrContext* fContext; |
| 61 | GrAtlas* fAtlas; |
jvanverth | 6d22eca | 2014-10-28 11:10:48 -0700 | [diff] [blame^] | 62 | SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor; |
| 63 | // current set of flags used to create the cached geometry processor |
| 64 | uint32_t fEffectFlags; |
jvanverth | fa38a30 | 2014-10-06 05:59:05 -0700 | [diff] [blame] | 65 | GrAtlas::ClientPlotUsage fPlotUsage; |
| 66 | SkTDynamicHash<PathData, uint32_t> fPathCache; |
| 67 | PathDataList fPathList; |
| 68 | |
| 69 | bool internalDrawPath(const SkPath& path, const PathData* pathData, GrDrawTarget* target); |
| 70 | PathData* addPathToAtlas(const SkPath& path, const SkStrokeRec& stroke, bool antiAlias); |
| 71 | bool freeUnusedPlot(); |
| 72 | |
| 73 | typedef GrPathRenderer INHERITED; |
| 74 | }; |
| 75 | |
| 76 | #endif |