blob: 88c9d328cce0bb933bffc1255237a4f4664b1612 [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*,
41 const SkPath&,
42 const SkStrokeRec&,
jvanverthfa38a302014-10-06 05:59:05 -070043 bool antiAlias) SK_OVERRIDE;
44
45private:
46 struct PathData {
jvanverthb61283f2014-10-30 05:57:21 -070047 struct Key {
48 uint32_t fGenID;
49 // rendered size for stored path (32x32 max, 64x64 max, 128x128 max)
50 uint32_t fDimension;
51 bool operator==(const Key& other) const {
52 return other.fGenID == fGenID && other.fDimension == fDimension;
53 }
54 };
55 Key fKey;
56 SkScalar fScale;
jvanverthfa38a302014-10-06 05:59:05 -070057 GrPlot* fPlot;
58 SkRect fBounds;
59 SkIPoint16 fAtlasLocation;
60 SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData);
61
jvanverthb61283f2014-10-30 05:57:21 -070062 static inline const Key& GetKey(const PathData& data) {
63 return data.fKey;
jvanverthfa38a302014-10-06 05:59:05 -070064 }
65
jvanverthb61283f2014-10-30 05:57:21 -070066 static inline uint32_t Hash(Key key) {
67 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(key));
jvanverthfa38a302014-10-06 05:59:05 -070068 }
69 };
70 typedef SkTInternalLList<PathData> PathDataList;
71
72 GrContext* fContext;
73 GrAtlas* fAtlas;
jvanverth6d22eca2014-10-28 11:10:48 -070074 SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor;
75 // current set of flags used to create the cached geometry processor
76 uint32_t fEffectFlags;
jvanverthfa38a302014-10-06 05:59:05 -070077 GrAtlas::ClientPlotUsage fPlotUsage;
jvanverthb61283f2014-10-30 05:57:21 -070078 SkTDynamicHash<PathData, PathData::Key> fPathCache;
jvanverthfa38a302014-10-06 05:59:05 -070079 PathDataList fPathList;
80
joshualitt9853cce2014-11-17 14:22:48 -080081 bool internalDrawPath(GrDrawTarget*, GrDrawState*, const SkPath& path,
82 const PathData* pathData);
jvanverthb61283f2014-10-30 05:57:21 -070083 PathData* addPathToAtlas(const SkPath& path, const SkStrokeRec& stroke, bool antiAlias,
84 uint32_t dimension, SkScalar scale);
jvanverthfa38a302014-10-06 05:59:05 -070085 bool freeUnusedPlot();
86
87 typedef GrPathRenderer INHERITED;
88};
89
90#endif