blob: 40430bbd2ff47a403eda93881f2dd8c380d19748 [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"
18
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
27 virtual bool canDrawPath(const SkPath& path,
28 const SkStrokeRec& stroke,
29 const GrDrawTarget* target,
30 bool antiAlias) const SK_OVERRIDE;
31
32protected:
33 virtual StencilSupport onGetStencilSupport(const SkPath&,
34 const SkStrokeRec&,
35 const GrDrawTarget*) const SK_OVERRIDE;
36
37 virtual bool onDrawPath(const SkPath& path,
38 const SkStrokeRec& stroke,
39 GrDrawTarget* target,
40 bool antiAlias) SK_OVERRIDE;
41
42private:
43 struct PathData {
44 uint32_t fGenID;
45 GrPlot* fPlot;
46 SkRect fBounds;
47 SkIPoint16 fAtlasLocation;
48 SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData);
49
50 static inline const uint32_t& GetKey(const PathData& data) {
51 return data.fGenID;
52 }
53
54 static inline uint32_t Hash(uint32_t key) {
55 return SkChecksum::Murmur3(&key, sizeof(key));
56 }
57 };
58 typedef SkTInternalLList<PathData> PathDataList;
59
60 GrContext* fContext;
61 GrAtlas* fAtlas;
jvanverth6d22eca2014-10-28 11:10:48 -070062 SkAutoTUnref<GrGeometryProcessor> fCachedGeometryProcessor;
63 // current set of flags used to create the cached geometry processor
64 uint32_t fEffectFlags;
jvanverthfa38a302014-10-06 05:59:05 -070065 GrAtlas::ClientPlotUsage fPlotUsage;
66 SkTDynamicHash<PathData, uint32_t> fPathCache;
67 PathDataList fPathList;
68
69 bool internalDrawPath(const SkPath& path, const PathData* pathData, GrDrawTarget* target);
70 PathData* addPathToAtlas(const SkPath& path, const SkStrokeRec& stroke, bool antiAlias);
71 bool freeUnusedPlot();
72
73 typedef GrPathRenderer INHERITED;
74};
75
76#endif