| 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 |
// |
| 23 |
// Each runtime effect dictionary lives for just one Recording. While recording, |
| 24 |
// it is filled with runtime effects. In snap(), ownership of it is assumed by the |
| 25 |
// PipelineCreationTasks that could require its contents and a new one takes its place |
| 26 |
// in the Recorder. |
| 27 |
class RuntimeEffectDictionary : public SkRefCnt { |
| 28 |
public: |
| 29 |
const SkRuntimeEffect* find(int codeSnippetID) const { |
| 30 |
sk_sp<const SkRuntimeEffect>* effect = fDict.find(codeSnippetID); |
| 31 |
return effect ? effect->get() : nullptr; |
| 32 |
} |
| 33 |
|
| 34 |
void set(int codeSnippetID, sk_sp<const SkRuntimeEffect> effect); |
| 35 |
|
| 36 |
bool empty() const { return fDict.empty(); } |
| 37 |
|
| 38 |
private: |
| 39 |
skia_private::THashMap<int, sk_sp<const SkRuntimeEffect>> fDict; |
| 40 |
}; |
| 41 |
|
| 42 |
} // namespace skgpu::graphite |
| 43 |
|
| 44 |
#endif // skgpu_graphite_RuntimeEffectDictionary_DEFINED |