aboutsummaryrefslogtreecommitdiff
path: root/src/deps/skia/include/private/SkShaderCodeDictionary.h
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-03 16:34:10 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-04-03 16:34:10 -0700
commita87508008dfa1604baf2d4e39bf44704c00f261c (patch)
tree0be2ade96772037a02803b30e157c367d931e3d9 /src/deps/skia/include/private/SkShaderCodeDictionary.h
parent4a19a3f07f1887903e5638a3be167f0c7b377ba3 (diff)
downloadbun-jarred/canvas.tar.gz
bun-jarred/canvas.tar.zst
bun-jarred/canvas.zip
Diffstat (limited to 'src/deps/skia/include/private/SkShaderCodeDictionary.h')
-rw-r--r--src/deps/skia/include/private/SkShaderCodeDictionary.h63
1 files changed, 63 insertions, 0 deletions
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 <unordered_map>
+#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<SkPaintParamsKey, Entry*, Hash> fHash SK_GUARDED_BY(fSpinLock);
+ std::vector<Entry*> fEntryVector SK_GUARDED_BY(fSpinLock);
+
+ SkArenaAlloc fArena{256};
+};
+
+#endif // SkShaderCodeDictionary_DEFINED