Debian Codegraph @

src/gpu/graphite/RecorderPriv.h

raw
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_RecorderPriv_DEFINED
9 #define skgpu_graphite_RecorderPriv_DEFINED
10
11 #include "include/core/SkRecorder.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/gpu/graphite/Recorder.h"
14 #include "include/private/base/SkDebug.h"
15 #include "src/gpu/graphite/DebugUtils.h"
16 #include "src/gpu/graphite/PipelineData.h"
17 #include "src/gpu/graphite/ResourceProvider.h"
18 #include "src/gpu/graphite/SharedContext.h"
19
20 #include <cstddef>
21 #include <cstdint>
22 #include <memory>
23 #include <string_view>
24
25 class SkBitmap;
26
27 namespace skgpu {
28 class TokenTracker;
29 enum class Protected : bool;
30 }
31
32 namespace sktext::gpu {
33 class StrikeCache;
34 class TextBlobRedrawCoordinator;
35 }
36
37 namespace skgpu::graphite {
38
39 class AtlasProvider;
40 class Caps;
41 class Context;
42 class Device;
43 class DrawBufferManager;
44 class ProxyCache;
45 class RendererProvider;
46 class ResourceCache;
47 class RuntimeEffectDictionary;
48 class ShaderCodeDictionary;
49 class Task;
50 class TextureProxy;
51 class UploadBufferManager;
52 class UploadList;
53
54 class RecorderPriv {
55 public:
56 void add(sk_sp<Task>);
57 // Flush *all* tracked devices created by this Recorder
58 void flushTrackedDevices(SK_DUMP_TASKS_CODE(const char* flushSource));
59 // Flush tracked devices that have pending reads from `dependency`.
60 void flushTrackedDevices(const TextureProxy* dependency);
61
62 std::unique_ptr<KeyAndDataBuilder> popOrCreateKeyAndDataBuilder();
63 void pushKeyAndDataBuilder(std::unique_ptr<KeyAndDataBuilder> keyDB);
64
65 const Caps* caps() const { return fRecorder->fSharedContext->caps(); }
66
67 ResourceProvider* resourceProvider() { return fRecorder->fResourceProvider; }
68
69 sk_sp<RuntimeEffectDictionary> runtimeEffectDictionary();
70
71 const ShaderCodeDictionary* shaderCodeDictionary() const {
72 return fRecorder->fSharedContext->shaderCodeDictionary();
73 }
74 ShaderCodeDictionary* shaderCodeDictionary() {
75 return fRecorder->fSharedContext->shaderCodeDictionary();
76 }
77
78 const RendererProvider* rendererProvider() const {
79 return fRecorder->fSharedContext->rendererProvider();
80 }
81
82 Protected isProtected() const {
83 return fRecorder->fSharedContext->isProtected();
84 }
85
86 UploadList* rootUploadList() { return fRecorder->fRootUploads.get(); }
87 DrawBufferManager* drawBufferManager() { return fRecorder->fDrawBufferManager.get(); }
88 UploadBufferManager* uploadBufferManager() { return fRecorder->fUploadBufferManager.get(); }
89 FloatStorageManager* floatStorageManager() { return fRecorder->fFloatStorageManager.get(); }
90 sk_sp<FloatStorageManager> refFloatStorageManager() { return fRecorder->fFloatStorageManager; }
91
92 AtlasProvider* atlasProvider() { return fRecorder->fAtlasProvider.get(); }
93 TokenTracker* tokenTracker() { return fRecorder->fTokenTracker.get(); }
94 sktext::gpu::StrikeCache* strikeCache() { return fRecorder->fStrikeCache.get(); }
95 sktext::gpu::TextBlobRedrawCoordinator* textBlobCache() {
96 return fRecorder->fTextBlobCache.get();
97 }
98 ProxyCache* proxyCache() { return this->resourceProvider()->proxyCache(); }
99
100 // NOTE: Temporary access for DrawTask to manipulate pending read counts.
101 void addPendingRead(const TextureProxy*);
102
103 static sk_sp<TextureProxy> CreateCachedProxy(Recorder*,
104 const SkBitmap&,
105 std::string_view label);
106
107 uint32_t uniqueID() const { return fRecorder->fUniqueID; }
108
109 #if defined(SK_DEBUG)
110 uint32_t nextRecordingID() const { return fRecorder->fNextRecordingID; }
111 #endif
112
113 size_t getResourceCacheLimit() const;
114
115 #if defined(GPU_TEST_UTILS)
116 bool deviceIsRegistered(Device*) const;
117 ResourceCache* resourceCache() { return fRecorder->fResourceProvider->resourceCache(); }
118 SharedContext* sharedContext() { return fRecorder->fSharedContext.get(); }
119 // used by the Context that created this Recorder to set a back pointer
120 void setContext(Context*);
121 Context* context() { return fRecorder->fContext; }
122 void issueFlushToken();
123 #endif
124
125 private:
126 explicit RecorderPriv(Recorder* recorder) : fRecorder(recorder) {}
127 RecorderPriv& operator=(const RecorderPriv&) = delete;
128
129 // No taking addresses of this type.
130 const RecorderPriv* operator&() const = delete;
131 RecorderPriv* operator&() = delete;
132
133 Recorder* fRecorder;
134
135 friend class Recorder; // to construct/copy this type.
136 };
137
138 inline RecorderPriv Recorder::priv() {
139 return RecorderPriv(this);
140 }
141
142 inline const RecorderPriv Recorder::priv() const { // NOLINT(readability-const-return-type)
143 return RecorderPriv(const_cast<Recorder*>(this));
144 }
145
146 inline Recorder* AsGraphiteRecorder(SkRecorder* recorder) {
147 if (!recorder) {
148 return nullptr;
149 }
150 if (recorder->type() != SkRecorder::Type::kGraphite) {
151 return nullptr;
152 }
153 return static_cast<Recorder*>(recorder);
154 }
155
156 } // namespace skgpu::graphite
157
158 #endif // skgpu_graphite_RecorderPriv_DEFINED