skia ID产生器

#include "include/core/SkTypes.h"

class SkNextID {
public:
    /**
     *  Shared between SkPixelRef's generationID and SkImage's uniqueID
     */
    static uint32_t ImageID();
};

/////////////////////////////////////////////////////////////////

#include <atomic>

uint32_t SkNextID::ImageID() {
    // We never set the low bit.... see SkPixelRef::genIDIsUnique().
    static std::atomic<uint32_t> nextID{2};

    uint32_t id;
    do {
        id = nextID.fetch_add(2, std::memory_order_relaxed);
    } while (id == 0);
    return id;
}

 

posted @ 2023-02-23 17:19  Bigben  阅读(32)  评论(0编辑  收藏  举报