1 | /* |
2 | * Copyright 2020 Google Inc. |
3 | * |
4 | * Use of this source code is governed by a BSD-style license that can be |
5 | * found in the LICENSE file. |
6 | */ |
7 | |
8 | #ifndef GrSmallPathShapeData_DEFINED |
9 | #define GrSmallPathShapeData_DEFINED |
10 | |
11 | #include "src/core/SkOpts.h" |
12 | #include "src/gpu/GrDrawOpAtlas.h" |
13 | |
14 | class GrStyledShape; |
15 | |
16 | class GrSmallPathShapeDataKey { |
17 | public: |
18 | // TODO: add a move variant |
19 | GrSmallPathShapeDataKey(const GrSmallPathShapeDataKey& that) { |
20 | fKey.reset(that.fKey.count()); |
21 | memcpy(fKey.get(), that.fKey.get(), fKey.count() * sizeof(uint32_t)); |
22 | } |
23 | |
24 | GrSmallPathShapeDataKey& operator=(const GrSmallPathShapeDataKey&) = delete; |
25 | |
26 | // for SDF paths |
27 | GrSmallPathShapeDataKey(const GrStyledShape&, uint32_t dim); |
28 | |
29 | // for bitmap paths |
30 | GrSmallPathShapeDataKey(const GrStyledShape&, const SkMatrix& ctm); |
31 | |
32 | bool operator==(const GrSmallPathShapeDataKey & that) const { |
33 | return fKey.count() == that.fKey.count() && |
34 | 0 == memcmp(fKey.get(), that.fKey.get(), sizeof(uint32_t) * fKey.count()); |
35 | } |
36 | |
37 | int count32() const { return fKey.count(); } |
38 | const uint32_t* data() const { return fKey.get(); } |
39 | |
40 | private: |
41 | // The key is composed of the GrStyledShape's key, and either the dimensions of the DF |
42 | // generated for the path (32x32 max, 64x64 max, 128x128 max) if an SDF image or |
43 | // the matrix for the path with only fractional translation. |
44 | SkAutoSTArray<24, uint32_t> fKey; |
45 | }; |
46 | |
47 | class GrSmallPathShapeData { |
48 | public: |
49 | GrSmallPathShapeData(const GrSmallPathShapeDataKey& key) : fKey(key) {} |
50 | |
51 | const GrSmallPathShapeDataKey fKey; |
52 | SkRect fBounds; |
53 | GrDrawOpAtlas::AtlasLocator fAtlasLocator; |
54 | |
55 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrSmallPathShapeData); |
56 | |
57 | static inline const GrSmallPathShapeDataKey& GetKey(const GrSmallPathShapeData& data) { |
58 | return data.fKey; |
59 | } |
60 | |
61 | static inline uint32_t Hash(const GrSmallPathShapeDataKey& key) { |
62 | return SkOpts::hash(key.data(), sizeof(uint32_t) * key.count32()); |
63 | } |
64 | }; |
65 | |
66 | #endif |
67 | |