6d7c38d6c3cfc5a68d3da8d8556522e57f4a9990
[platform/upstream/libSkiaSharp.git] / src / gpu / GrAADistanceFieldPathRenderer.h
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 SkStrokeRec&,
31                              bool antiAlias) const SK_OVERRIDE;
32
33 protected:
34     virtual StencilSupport onGetStencilSupport(const GrDrawTarget*,
35                                                const GrPipelineBuilder*,
36                                                const SkPath&,
37                                                const SkStrokeRec&) const SK_OVERRIDE;
38     
39     virtual bool onDrawPath(GrDrawTarget*,
40                             GrPipelineBuilder*,
41                             GrColor,
42                             const SkMatrix& viewMatrix,
43                             const SkPath&,
44                             const SkStrokeRec&,
45                             bool antiAlias) SK_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         
64         static inline const Key& GetKey(const PathData& data) {
65             return data.fKey;
66         }
67         
68         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 SkTInternalLList<PathData> PathDataList;
76     
77     GrContext*                         fContext;
78     GrBatchAtlas*                      fAtlas;
79     SkTDynamicHash<PathData, PathData::Key> fPathCache;
80     PathDataList                       fPathList;
81     
82     typedef GrPathRenderer INHERITED;
83
84     friend class AADistanceFieldPathBatch;
85 };
86
87 #endif