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 "GrBatchAtlas.h"
13 #include "GrPathRenderer.h"
14 #include "GrRect.h"
15 
16 #include "SkChecksum.h"
17 #include "SkTDynamicHash.h"
18 
19 class GrContext;
20 
21 class GrAADistanceFieldPathRenderer : public GrPathRenderer {
22 public:
23     GrAADistanceFieldPathRenderer(GrContext* context);
24     virtual ~GrAADistanceFieldPathRenderer();
25 
26     virtual bool canDrawPath(const GrDrawTarget*,
27                              const GrPipelineBuilder*,
28                              const SkMatrix& viewMatrix,
29                              const SkPath&,
30                              const GrStrokeInfo&,
31                              bool antiAlias) const override;
32 
33 protected:
34     virtual StencilSupport onGetStencilSupport(const GrDrawTarget*,
35                                                const GrPipelineBuilder*,
36                                                const SkPath&,
37                                                const GrStrokeInfo&) const override;
38 
39     virtual bool onDrawPath(GrDrawTarget*,
40                             GrPipelineBuilder*,
41                             GrColor,
42                             const SkMatrix& viewMatrix,
43                             const SkPath&,
44                             const GrStrokeInfo&,
45                             bool antiAlias) override;
46 
47 private:
48     struct PathData {
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         };
57         Key                   fKey;
58         SkScalar              fScale;
59         GrBatchAtlas::AtlasID fID;
60         SkRect                fBounds;
61         SkIPoint16            fAtlasLocation;
62         SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData);
63 
GetKeyPathData64         static inline const Key& GetKey(const PathData& data) {
65             return data.fKey;
66         }
67 
HashPathData68         static inline uint32_t Hash(Key key) {
69             return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(key));
70         }
71     };
72 
73     static void HandleEviction(GrBatchAtlas::AtlasID, void*);
74 
75     typedef SkTDynamicHash<PathData, PathData::Key> PathCache;
76     typedef SkTInternalLList<PathData> PathDataList;
77 
78     GrContext*                         fContext;
79     GrBatchAtlas*                      fAtlas;
80     PathCache                          fPathCache;
81     PathDataList                       fPathList;
82 
83     typedef GrPathRenderer INHERITED;
84 
85     friend class AADistanceFieldPathBatch;
86     friend struct PathTestStruct;
87 };
88 
89 #endif
90