21 static std::atomic<uint32_t> nextID{2};
25 id = nextID.fetch_add(2, std::memory_order_relaxed);
37 , fAddedToCache(
false)
39 this->needsNewGenID();
40 fMutability = kMutable;
44 this->callGenIDChangeListeners();
58void SkPixelRef::needsNewGenID() {
59 fTaggedGenID.store(0);
64 uint32_t
id = fTaggedGenID.load();
67 if (fTaggedGenID.compare_exchange_strong(
id,
next)) {
79 if (!listener || !this->genIDIsUnique()) {
83 SkASSERT(!listener->shouldDeregister());
84 fGenIDChangeListeners.
add(std::move(listener));
88void SkPixelRef::callGenIDChangeListeners() {
90 if (this->genIDIsUnique()) {
91 fGenIDChangeListeners.
changed();
92 if (fAddedToCache.exchange(
false)) {
98 fGenIDChangeListeners.
reset();
105 SkDebugf(
"========== notifyPixelsChanged called on immutable pixelref");
108 this->callGenIDChangeListeners();
109 this->needsNewGenID();
113 fMutability = kImmutable;
116void SkPixelRef::setImmutableWithID(uint32_t genID) {
123 fMutability = kImmutable;
124 fTaggedGenID.store(genID);
127void SkPixelRef::setTemporarilyImmutable() {
128 SkASSERT(fMutability != kImmutable);
129 fMutability = kTemporarilyImmutable;
132void SkPixelRef::restoreMutability() {
133 SkASSERT(fMutability != kImmutable);
134 fMutability = kMutable;
144 void (*fReleaseProc)(
void*,
void*);
145 void* fReleaseProcContext;
146 PixelRef(
int w,
int h,
void*
s,
size_t r,
void (*proc)(
void*,
void*),
void* ctx)
147 :
SkPixelRef(
w,
h,
s, r), fReleaseProc(proc), fReleaseProcContext(ctx) {}
148 ~PixelRef()
override { fReleaseProc(this->
pixels(), fReleaseProcContext); }
static float next(float f)
void SkNotifyBitmapGenIDIsStale(uint32_t bitmapGenID)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static void releaseProc(const void *ptr, void *context)
sk_sp< SkPixelRef > SkMakePixelRefWithProc(int width, int height, size_t rowBytes, void *addr, void(*releaseProc)(void *addr, void *ctx), void *ctx)
void reset() SK_EXCLUDES(fMutex)
void changed() SK_EXCLUDES(fMutex)
void add(sk_sp< SkIDChangeListener > listener) SK_EXCLUDES(fMutex)
static uint32_t ImageID()
void notifyPixelsChanged()
uint32_t getGenerationID() const
void addGenIDChangeListener(sk_sp< SkIDChangeListener > listener)
SkPixelRef(int width, int height, void *addr, size_t rowBytes)
void android_only_reset(int width, int height, size_t rowBytes)