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