zl程序教程

您现在的位置是:首页 >  其它

当前栏目

skia ID产生器

ID
2023-09-14 09:08:23 时间
#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;
}