blob: e9a32dc07b6d0a8ff6dad29b4219f1d2e0d7fff1 [file] [log] [blame]
jvanverthfa38a302014-10-06 05:59:05 -07001
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"
bsalomon71cb0c22014-11-14 12:10:14 -080018#include "SkTDynamicHash.h"
jvanverthfa38a302014-10-06 05:59:05 -070019
20class GrContext;
21class GrPlot;
22
23class GrAADistanceFieldPathRenderer : public GrPathRenderer {
24public:
jvanverth6d22eca2014-10-28 11:10:48 -070025 GrAADistanceFieldPathRenderer(GrContext* context);
jvanverthfa38a302014-10-06 05:59:05 -070026 virtual ~GrAADistanceFieldPathRenderer();
27
joshualitt9853cce2014-11-17 14:22:48 -080028 virtual bool canDrawPath(const GrDrawTarget*,
29 const GrDrawState*,
30 const SkPath&,
31 const SkStrokeRec&,
jvanverthfa38a302014-10-06 05:59:05 -070032 bool antiAlias) const SK_OVERRIDE;
33
34protected:
joshualitt9853cce2014-11-17 14:22:48 -080035 virtual StencilSupport onGetStencilSupport(const GrDrawTarget*,
36 const GrDrawState*,
37 const SkPath&,
38 const SkStrokeRec&) const SK_OVERRIDE;
jvanverthfa38a302014-10-06 05:59:05 -070039
joshualitt9853cce2014-11-17 14:22:48 -080040 virtual bool onDrawPath(GrDrawTarget*,
41 GrDrawState*,
42 const SkPath&,
43 const SkStrokeRec&,
jvanverthfa38a302014-10-06 05:59:05 -070044 bool antiAlias) SK_OVERRIDE;
45
46private:
47 struct PathData {
jvanverthb61283f2014-10-30 05:57:21 -070048 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;
jvanverthfa38a302014-10-06 05:59:05 -070058 GrPlot* fPlot;
59 SkRect fBounds;
60 SkIPoint16 fAtlasLocation;
61 SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData);
62
jvanverthb61283f2014-10-30 05:57:21 -070063 static inline const Key& GetKey(const PathData& data) {
64 return data.fKey;
jvanverthfa38a302014-10-06 05:59:05 -070065 }
66
jvanverthb61283f2014-10-30 05:57:21 -070067 static inline uint32_t Hash(Key key) {
68 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(key));
jvanverthfa38a302014-10-06 05:59:05 -070069 }
70 };
71 typedef SkTInternalLList<PathData> PathDataList;
72
73 GrContext* fContext;
74 GrAtlas* fAtlas;
jvanverth6d22eca2014-10-28 11:10:48 -070075 SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor;
76 // current set of flags used to create the cached geometry processor
77 uint32_t fEffectFlags;
jvanverthfa38a302014-10-06 05:59:05 -070078 GrAtlas::ClientPlotUsage fPlotUsage;
jvanverthb61283f2014-10-30 05:57:21 -070079 SkTDynamicHash<PathData, PathData::Key> fPathCache;
jvanverthfa38a302014-10-06 05:59:05 -070080 PathDataList fPathList;
81
joshualitt9853cce2014-11-17 14:22:48 -080082 bool internalDrawPath(GrDrawTarget*, GrDrawState*, const SkPath& path,
83 const PathData* pathData);
jvanverthb61283f2014-10-30 05:57:21 -070084 PathData* addPathToAtlas(const SkPath& path, const SkStrokeRec& stroke, bool antiAlias,
85 uint32_t dimension, SkScalar scale);
jvanverthfa38a302014-10-06 05:59:05 -070086 bool freeUnusedPlot();
87
88 typedef GrPathRenderer INHERITED;
89};
90
91#endif