blob: 7b40d945987e21d2c80c92dd03c2b10b5b23464b [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
jvanverthfa38a302014-10-06 05:59:05 -070012#include "GrAtlas.h"
13#include "GrPathRenderer.h"
14#include "GrRect.h"
15
16#include "SkChecksum.h"
bsalomon71cb0c22014-11-14 12:10:14 -080017#include "SkTDynamicHash.h"
jvanverthfa38a302014-10-06 05:59:05 -070018
19class GrContext;
20class GrPlot;
21
22class GrAADistanceFieldPathRenderer : public GrPathRenderer {
23public:
jvanverth6d22eca2014-10-28 11:10:48 -070024 GrAADistanceFieldPathRenderer(GrContext* context);
jvanverthfa38a302014-10-06 05:59:05 -070025 virtual ~GrAADistanceFieldPathRenderer();
26
joshualitt9853cce2014-11-17 14:22:48 -080027 virtual bool canDrawPath(const GrDrawTarget*,
28 const GrDrawState*,
29 const SkPath&,
30 const SkStrokeRec&,
jvanverthfa38a302014-10-06 05:59:05 -070031 bool antiAlias) const SK_OVERRIDE;
32
33protected:
joshualitt9853cce2014-11-17 14:22:48 -080034 virtual StencilSupport onGetStencilSupport(const GrDrawTarget*,
35 const GrDrawState*,
36 const SkPath&,
37 const SkStrokeRec&) const SK_OVERRIDE;
jvanverthfa38a302014-10-06 05:59:05 -070038
joshualitt9853cce2014-11-17 14:22:48 -080039 virtual bool onDrawPath(GrDrawTarget*,
40 GrDrawState*,
joshualitt2e3b3e32014-12-09 13:31:14 -080041 GrColor,
joshualitt9853cce2014-11-17 14:22:48 -080042 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
joshualitt2e3b3e32014-12-09 13:31:14 -080082 bool internalDrawPath(GrDrawTarget*, GrDrawState*, GrColor, const SkPath& path,
joshualitt9853cce2014-11-17 14:22:48 -080083 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