| 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/SkIDChangeListener.h" |
| 16 |
#include "include/private/base/SkTemplates.h" |
| 17 |
#include "src/base/SkTInternalLList.h" |
| 18 |
#include "src/core/SkChecksum.h" |
| 19 |
#include "src/gpu/AtlasTypes.h" |
| 20 |
|
| 21 |
#include <cstdint> |
| 22 |
#include <cstring> |
| 23 |
|
| 24 |
class GrStyledShape; |
| 25 |
class SkMatrix; |
| 26 |
|
| 27 |
namespace skgpu::ganesh { |
| 28 |
|
| •29 |
class SmallPathIDChangeListener : public SkIDChangeListener { |
| 30 |
public: |
| 31 |
SmallPathIDChangeListener() : fHasChanged(false) {} |
| 32 |
|
| 33 |
bool hasChanged() const { return fHasChanged.load(std::memory_order_relaxed); } |
| 34 |
|
| 35 |
void changed() override { fHasChanged.store(true, std::memory_order_relaxed); } |
| 36 |
|
| 37 |
private: |
| 38 |
std::atomic<bool> fHasChanged; |
| 39 |
}; |
| 40 |
|
| 41 |
class SmallPathShapeDataKey { |
| 42 |
public: |
| 43 |
// TODO: add a move variant |
| 44 |
SmallPathShapeDataKey(const SmallPathShapeDataKey& that) { |
| 45 |
fKey.reset(that.fKey.count()); |
| 46 |
memcpy(fKey.get(), that.fKey.get(), fKey.count() * sizeof(uint32_t)); |
| 47 |
} |
| 48 |
|
| 49 |
SmallPathShapeDataKey& operator=(const SmallPathShapeDataKey&) = delete; |
| 50 |
|
| 51 |
// for SDF paths |
| 52 |
SmallPathShapeDataKey(const GrStyledShape&, uint32_t dim); |
| 53 |
|
| 54 |
// for bitmap paths |
| 55 |
SmallPathShapeDataKey(const GrStyledShape&, const SkMatrix& ctm); |
| 56 |
|
| 57 |
bool operator==(const SmallPathShapeDataKey & that) const { |
| 58 |
return fKey.count() == that.fKey.count() && |
| 59 |
0 == memcmp(fKey.get(), that.fKey.get(), sizeof(uint32_t) * fKey.count()); |
| 60 |
} |
| 61 |
|
| 62 |
int count32() const { return fKey.count(); } |
| 63 |
const uint32_t* data() const { return fKey.get(); } |
| 64 |
|
| 65 |
private: |
| 66 |
// The key is composed of the GrStyledShape's key, and either the dimensions of the DF |
| 67 |
// generated for the path (32x32 max, 64x64 max, 128x128 max) if an SDF image or |
| 68 |
// the matrix for the path with only fractional translation. |
| 69 |
skia_private::AutoSTArray<24, uint32_t> fKey; |
| 70 |
}; |
| 71 |
|
| 72 |
class SmallPathShapeData { |
| 73 |
public: |
| •74 |
SmallPathShapeData(const SmallPathShapeDataKey& key) |
| 75 |
: fKey(key), fIDChangeListener(sk_make_sp<SmallPathIDChangeListener>()) {} |
| 76 |
~SmallPathShapeData() { fIDChangeListener->markShouldDeregister(); } |
| 77 |
|
| 78 |
const SmallPathShapeDataKey fKey; |
| 79 |
SkRect fBounds; |
| 80 |
skgpu::AtlasLocator fAtlasLocator; |
| 81 |
|
| 82 |
SK_DECLARE_INTERNAL_LLIST_INTERFACE(SmallPathShapeData); |
| 83 |
|
| 84 |
static inline const SmallPathShapeDataKey& GetKey(const SmallPathShapeData& data) { |
| 85 |
return data.fKey; |
| 86 |
} |
| 87 |
|
| 88 |
static inline uint32_t Hash(const SmallPathShapeDataKey& key) { |
| 89 |
return SkChecksum::Hash32(key.data(), sizeof(uint32_t) * key.count32()); |
| 90 |
} |
| •91 |
|
| 92 |
sk_sp<SmallPathIDChangeListener> fIDChangeListener; |
| 93 |
}; |
| 94 |
|
| 95 |
} // namespace skgpu::ganesh |
| 96 |
|
| 97 |
#endif // SK_ENABLE_OPTIMIZE_SIZE |
| 98 |
|
| 99 |
#endif // SmallPathShapeData_DEFINED |