blob: c0e68268dedfe0def5ad98f7daedf3385d95f263 [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:
bsalomon0aff2fa2015-07-31 06:48:27 -070023 GrAADistanceFieldPathRenderer();
jvanverthfa38a302014-10-06 05:59:05 -070024 virtual ~GrAADistanceFieldPathRenderer();
jvanverthfa38a302014-10-06 05:59:05 -070025
26private:
robertphillipse7d4b2f2015-08-13 07:57:10 -070027 StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const override {
28 return GrPathRenderer::kNoSupport_StencilSupport;
29 }
bsalomon0aff2fa2015-07-31 06:48:27 -070030
31 bool onCanDrawPath(const CanDrawPathArgs&) const override;
32
33 bool onDrawPath(const DrawPathArgs&) override;
34
jvanverthfa38a302014-10-06 05:59:05 -070035 struct PathData {
jvanverth512e4372015-11-23 11:50:02 -080036 class Key {
37 public:
38 // default ctor needed for new of uninitialized PathData
39 // since fStroke has no default ctor
40 Key()
41 : fGenID(0)
42 , fDimension(0)
43 , fStroke(SkStrokeRec::kFill_InitStyle) {}
44 Key(uint32_t genID, uint32_t dim, const SkStrokeRec& stroke)
45 : fGenID(genID)
46 , fDimension(dim)
47 , fStroke(stroke) {}
48
49 bool operator==(const Key& other) const {
50 return other.fGenID == fGenID && other.fDimension == fDimension &&
51 fStroke.hasEqualEffect(other.fStroke);
52 }
53
54 private:
jvanverthb61283f2014-10-30 05:57:21 -070055 uint32_t fGenID;
56 // rendered size for stored path (32x32 max, 64x64 max, 128x128 max)
57 uint32_t fDimension;
jvanverth512e4372015-11-23 11:50:02 -080058 // stroking information
59 SkStrokeRec fStroke;
jvanverthb61283f2014-10-30 05:57:21 -070060 };
joshualitt5bf99f12015-03-13 11:47:42 -070061 Key fKey;
62 SkScalar fScale;
63 GrBatchAtlas::AtlasID fID;
64 SkRect fBounds;
65 SkIPoint16 fAtlasLocation;
jvanverthfa38a302014-10-06 05:59:05 -070066 SK_DECLARE_INTERNAL_LLIST_INTERFACE(PathData);
67
jvanverthb61283f2014-10-30 05:57:21 -070068 static inline const Key& GetKey(const PathData& data) {
69 return data.fKey;
jvanverthfa38a302014-10-06 05:59:05 -070070 }
71
jvanverthb61283f2014-10-30 05:57:21 -070072 static inline uint32_t Hash(Key key) {
73 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(&key), sizeof(key));
jvanverthfa38a302014-10-06 05:59:05 -070074 }
75 };
joshualitt5bf99f12015-03-13 11:47:42 -070076
77 static void HandleEviction(GrBatchAtlas::AtlasID, void*);
78
joshualitt21279c72015-05-11 07:21:37 -070079 typedef SkTDynamicHash<PathData, PathData::Key> PathCache;
jvanverthfa38a302014-10-06 05:59:05 -070080 typedef SkTInternalLList<PathData> PathDataList;
81
joshualitt5bf99f12015-03-13 11:47:42 -070082 GrBatchAtlas* fAtlas;
joshualitt21279c72015-05-11 07:21:37 -070083 PathCache fPathCache;
jvanverthfa38a302014-10-06 05:59:05 -070084 PathDataList fPathList;
85
jvanverthfa38a302014-10-06 05:59:05 -070086 typedef GrPathRenderer INHERITED;
joshualitt5bf99f12015-03-13 11:47:42 -070087
88 friend class AADistanceFieldPathBatch;
joshualitt21279c72015-05-11 07:21:37 -070089 friend struct PathTestStruct;
jvanverthfa38a302014-10-06 05:59:05 -070090};
91
92#endif