blob: ad296f0aa38f174636665cf045cb6a207fa360ad [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
joshualitt5bf99f12015-03-13 11:47:42 -070012#include "GrBatchAtlas.h"
jvanverthfa38a302014-10-06 05:59:05 -070013#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;
jvanverthfa38a302014-10-06 05:59:05 -070020
21class GrAADistanceFieldPathRenderer : public GrPathRenderer {
22public:
jvanverth6d22eca2014-10-28 11:10:48 -070023 GrAADistanceFieldPathRenderer(GrContext* context);
jvanverthfa38a302014-10-06 05:59:05 -070024 virtual ~GrAADistanceFieldPathRenderer();
25
joshualitt9853cce2014-11-17 14:22:48 -080026 virtual bool canDrawPath(const GrDrawTarget*,
egdaniel8dd688b2015-01-22 10:16:09 -080027 const GrPipelineBuilder*,
joshualitt8059eb92014-12-29 15:10:07 -080028 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -080029 const SkPath&,
30 const SkStrokeRec&,
mtklein36352bf2015-03-25 18:17:31 -070031 bool antiAlias) const override;
jvanverthfa38a302014-10-06 05:59:05 -070032
33protected:
joshualitt9853cce2014-11-17 14:22:48 -080034 virtual StencilSupport onGetStencilSupport(const GrDrawTarget*,
egdaniel8dd688b2015-01-22 10:16:09 -080035 const GrPipelineBuilder*,
joshualitt9853cce2014-11-17 14:22:48 -080036 const SkPath&,
mtklein36352bf2015-03-25 18:17:31 -070037 const SkStrokeRec&) const override;
jvanverthfa38a302014-10-06 05:59:05 -070038
joshualitt9853cce2014-11-17 14:22:48 -080039 virtual bool onDrawPath(GrDrawTarget*,
egdaniel8dd688b2015-01-22 10:16:09 -080040 GrPipelineBuilder*,
joshualitt2e3b3e32014-12-09 13:31:14 -080041 GrColor,
joshualitt8059eb92014-12-29 15:10:07 -080042 const SkMatrix& viewMatrix,
joshualitt9853cce2014-11-17 14:22:48 -080043 const SkPath&,
44 const SkStrokeRec&,
mtklein36352bf2015-03-25 18:17:31 -070045 bool antiAlias) override;
jvanverthfa38a302014-10-06 05:59:05 -070046
47private:
48 struct PathData {
jvanverthb61283f2014-10-30 05:57:21 -070049 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 };
joshualitt5bf99f12015-03-13 11:47:42 -070057 Key fKey;
58 SkScalar fScale;
59 GrBatchAtlas::AtlasID fID;
60 SkRect fBounds;
61 SkIPoint16 fAtlasLocation;
jvanverthfa38a302014-10-06 05:59:05 -070062 SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData);
63
jvanverthb61283f2014-10-30 05:57:21 -070064 static inline const Key& GetKey(const PathData& data) {
65 return data.fKey;
jvanverthfa38a302014-10-06 05:59:05 -070066 }
67
jvanverthb61283f2014-10-30 05:57:21 -070068 static inline uint32_t Hash(Key key) {
69 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(key));
jvanverthfa38a302014-10-06 05:59:05 -070070 }
71 };
joshualitt5bf99f12015-03-13 11:47:42 -070072
73 static void HandleEviction(GrBatchAtlas::AtlasID, void*);
74
jvanverthfa38a302014-10-06 05:59:05 -070075 typedef SkTInternalLList<PathData> PathDataList;
76
77 GrContext* fContext;
joshualitt5bf99f12015-03-13 11:47:42 -070078 GrBatchAtlas* fAtlas;
jvanverthb61283f2014-10-30 05:57:21 -070079 SkTDynamicHash<PathData, PathData::Key> fPathCache;
jvanverthfa38a302014-10-06 05:59:05 -070080 PathDataList fPathList;
81
jvanverthfa38a302014-10-06 05:59:05 -070082 typedef GrPathRenderer INHERITED;
joshualitt5bf99f12015-03-13 11:47:42 -070083
84 friend class AADistanceFieldPathBatch;
jvanverthfa38a302014-10-06 05:59:05 -070085};
86
87#endif