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 #ifndef SmallPathShapeData_DEFINED 8 #define SmallPathShapeData_DEFINED 9 10 #include "include/core/SkTypes.h" 11 12 #if !defined(SK_ENABLE_OPTIMIZE_SIZE) 13 14 #include "include/core/SkRect.h" 15 #include "include/private/base/SkTemplates.h" 16 #include "src/base/SkTInternalLList.h" 17 #include "src/core/SkChecksum.h" 18 #include "src/gpu/AtlasTypes.h" 19 20 #include <cstdint> 21 #include <cstring> 22 23 class GrStyledShape; 24 class SkMatrix; 25 26 namespace skgpu::ganesh { 27 28 class SmallPathShapeDataKey { 29 public: 30 // TODO: add a move variant SmallPathShapeDataKey(const SmallPathShapeDataKey & that)31 SmallPathShapeDataKey(const SmallPathShapeDataKey& that) { 32 fKey.reset(that.fKey.count()); 33 memcpy(fKey.get(), that.fKey.get(), fKey.count() * sizeof(uint32_t)); 34 } 35 36 SmallPathShapeDataKey& operator=(const SmallPathShapeDataKey&) = delete; 37 38 // for SDF paths 39 SmallPathShapeDataKey(const GrStyledShape&, uint32_t dim); 40 41 // for bitmap paths 42 SmallPathShapeDataKey(const GrStyledShape&, const SkMatrix& ctm); 43 44 bool operator==(const SmallPathShapeDataKey & that) const { 45 return fKey.count() == that.fKey.count() && 46 0 == memcmp(fKey.get(), that.fKey.get(), sizeof(uint32_t) * fKey.count()); 47 } 48 count32()49 int count32() const { return fKey.count(); } data()50 const uint32_t* data() const { return fKey.get(); } 51 52 private: 53 // The key is composed of the GrStyledShape's key, and either the dimensions of the DF 54 // generated for the path (32x32 max, 64x64 max, 128x128 max) if an SDF image or 55 // the matrix for the path with only fractional translation. 56 skia_private::AutoSTArray<24, uint32_t> fKey; 57 }; 58 59 class SmallPathShapeData { 60 public: SmallPathShapeData(const SmallPathShapeDataKey & key)61 SmallPathShapeData(const SmallPathShapeDataKey& key) : fKey(key) {} 62 63 const SmallPathShapeDataKey fKey; 64 SkRect fBounds; 65 skgpu::AtlasLocator fAtlasLocator; 66 67 SK_DECLARE_INTERNAL_LLIST_INTERFACE(SmallPathShapeData); 68 GetKey(const SmallPathShapeData & data)69 static inline const SmallPathShapeDataKey& GetKey(const SmallPathShapeData& data) { 70 return data.fKey; 71 } 72 Hash(const SmallPathShapeDataKey & key)73 static inline uint32_t Hash(const SmallPathShapeDataKey& key) { 74 return SkChecksum::Hash32(key.data(), sizeof(uint32_t) * key.count32()); 75 } 76 }; 77 78 } // namespace skgpu::ganesh 79 80 #endif // SK_ENABLE_OPTIMIZE_SIZE 81 82 #endif // SmallPathShapeData_DEFINED 83