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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章