Robert Phillips | de60d7a | 2021-09-13 17:17:45 -0400 | [diff] [blame] | 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 SmallPathShapeData_DEFINED |
| 9 | #define SmallPathShapeData_DEFINED |
| 10 | |
| 11 | #include "src/core/SkOpts.h" |
| 12 | #include "src/gpu/GrDrawOpAtlas.h" |
| 13 | |
| 14 | class GrStyledShape; |
| 15 | |
| 16 | namespace skgpu::v1 { |
| 17 | |
| 18 | class SmallPathShapeDataKey { |
| 19 | public: |
| 20 | // TODO: add a move variant |
| 21 | SmallPathShapeDataKey(const SmallPathShapeDataKey& that) { |
| 22 | fKey.reset(that.fKey.count()); |
| 23 | memcpy(fKey.get(), that.fKey.get(), fKey.count() * sizeof(uint32_t)); |
| 24 | } |
| 25 | |
| 26 | SmallPathShapeDataKey& operator=(const SmallPathShapeDataKey&) = delete; |
| 27 | |
| 28 | // for SDF paths |
| 29 | SmallPathShapeDataKey(const GrStyledShape&, uint32_t dim); |
| 30 | |
| 31 | // for bitmap paths |
| 32 | SmallPathShapeDataKey(const GrStyledShape&, const SkMatrix& ctm); |
| 33 | |
| 34 | bool operator==(const SmallPathShapeDataKey & that) const { |
| 35 | return fKey.count() == that.fKey.count() && |
| 36 | 0 == memcmp(fKey.get(), that.fKey.get(), sizeof(uint32_t) * fKey.count()); |
| 37 | } |
| 38 | |
| 39 | int count32() const { return fKey.count(); } |
| 40 | const uint32_t* data() const { return fKey.get(); } |
| 41 | |
| 42 | private: |
| 43 | // The key is composed of the GrStyledShape's key, and either the dimensions of the DF |
| 44 | // generated for the path (32x32 max, 64x64 max, 128x128 max) if an SDF image or |
| 45 | // the matrix for the path with only fractional translation. |
| 46 | SkAutoSTArray<24, uint32_t> fKey; |
| 47 | }; |
| 48 | |
| 49 | class SmallPathShapeData { |
| 50 | public: |
| 51 | SmallPathShapeData(const SmallPathShapeDataKey& key) : fKey(key) {} |
| 52 | |
| 53 | const SmallPathShapeDataKey fKey; |
| 54 | SkRect fBounds; |
| 55 | GrDrawOpAtlas::AtlasLocator fAtlasLocator; |
| 56 | |
| 57 | SK_DECLARE_INTERNAL_LLIST_INTERFACE(SmallPathShapeData); |
| 58 | |
| 59 | static inline const SmallPathShapeDataKey& GetKey(const SmallPathShapeData& data) { |
| 60 | return data.fKey; |
| 61 | } |
| 62 | |
| 63 | static inline uint32_t Hash(const SmallPathShapeDataKey& key) { |
| 64 | return SkOpts::hash(key.data(), sizeof(uint32_t) * key.count32()); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | } // namespace skgpu::v1 |
| 69 | |
| 70 | #endif // SmallPathShapeData_DEFINED |