From a87508008dfa1604baf2d4e39bf44704c00f261c Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 3 Apr 2022 16:34:10 -0700 Subject: skia WIP --- .../skia/include/private/SkShaderCodeDictionary.h | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/deps/skia/include/private/SkShaderCodeDictionary.h (limited to 'src/deps/skia/include/private/SkShaderCodeDictionary.h') diff --git a/src/deps/skia/include/private/SkShaderCodeDictionary.h b/src/deps/skia/include/private/SkShaderCodeDictionary.h new file mode 100644 index 000000000..1eb86fb87 --- /dev/null +++ b/src/deps/skia/include/private/SkShaderCodeDictionary.h @@ -0,0 +1,63 @@ +/* + * Copyright 2022 Google LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkShaderCodeDictionary_DEFINED +#define SkShaderCodeDictionary_DEFINED + +#include +#include "include/private/SkPaintParamsKey.h" +#include "include/private/SkSpinlock.h" +#include "include/private/SkUniquePaintParamsID.h" +#include "src/core/SkArenaAlloc.h" + +class SkShaderCodeDictionary { +public: + SkShaderCodeDictionary(); + + struct Entry { + public: + SkUniquePaintParamsID uniqueID() const { + SkASSERT(fUniqueID.isValid()); + return fUniqueID; + } + const SkPaintParamsKey& paintParamsKey() const { return fPaintParamsKey; } + + private: + friend class SkShaderCodeDictionary; + + Entry(const SkPaintParamsKey& paintParamsKey) : fPaintParamsKey(paintParamsKey) {} + + void setUniqueID(uint32_t newID) { + SkASSERT(!fUniqueID.isValid()); + fUniqueID = SkUniquePaintParamsID(newID); + } + + SkUniquePaintParamsID fUniqueID; // fixed-size (uint32_t) unique ID assigned to a key + SkPaintParamsKey fPaintParamsKey; // variable-length paint key descriptor + }; + + const Entry* findOrCreate(const SkPaintParamsKey&) SK_EXCLUDES(fSpinLock); + + const Entry* lookup(SkUniquePaintParamsID) const SK_EXCLUDES(fSpinLock); + +private: + Entry* makeEntry(const SkPaintParamsKey&); + + struct Hash { + size_t operator()(const SkPaintParamsKey&) const; + }; + + // TODO: can we do something better given this should have write-seldom/read-often behavior? + mutable SkSpinlock fSpinLock; + + std::unordered_map fHash SK_GUARDED_BY(fSpinLock); + std::vector fEntryVector SK_GUARDED_BY(fSpinLock); + + SkArenaAlloc fArena{256}; +}; + +#endif // SkShaderCodeDictionary_DEFINED -- cgit v1.2.3