xref: /aosp_15_r20/external/skia/src/gpu/graphite/RuntimeEffectDictionary.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef skgpu_graphite_RuntimeEffectDictionary_DEFINED
9 #define skgpu_graphite_RuntimeEffectDictionary_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/effects/SkRuntimeEffect.h"
13 #include "src/core/SkTHash.h"
14 
15 class SkRuntimeEffect;
16 
17 namespace skgpu::graphite {
18 
19 // We keep track of all SkRuntimeEffects that are used by a recording, along with their code
20 // snippet ID. This ensures that we have a live reference to every effect that we're going to
21 // paint, and gives us a way to retrieve their shader text when we see their code-snippet ID.
22 class RuntimeEffectDictionary {
23 public:
find(int codeSnippetID)24     const SkRuntimeEffect* find(int codeSnippetID) const {
25         sk_sp<const SkRuntimeEffect>* effect = fDict.find(codeSnippetID);
26         return effect ? effect->get() : nullptr;
27     }
28 
29     void set(int codeSnippetID, sk_sp<const SkRuntimeEffect> effect);
30 
reset()31     void reset() { fDict.reset(); }
32 
33 private:
34     skia_private::THashMap<int, sk_sp<const SkRuntimeEffect>> fDict;
35 };
36 
37 } // namespace skgpu::graphite
38 
39 #endif // skgpu_graphite_RuntimeEffectDictionary_DEFINED
40