xref: /aosp_15_r20/external/skia/src/gpu/graphite/RecorderPriv.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_RecorderPriv_DEFINED
9 #define skgpu_graphite_RecorderPriv_DEFINED
10 
11 #include <functional>
12 
13 #include "include/gpu/graphite/Recorder.h"
14 #include "src/gpu/graphite/ResourceCache.h"
15 #include "src/gpu/graphite/ResourceProvider.h"
16 #include "src/gpu/graphite/SharedContext.h"
17 
18 class SkBitmap;
19 class SkImage;
20 
21 namespace skgpu::graphite {
22 
23 class ShaderCodeDictionary;
24 class TextureProxy;
25 class UploadList;
26 
27 class RecorderPriv {
28 public:
29     void add(sk_sp<Task>);
30     void flushTrackedDevices();
31 
caps()32     const Caps* caps() const { return fRecorder->fSharedContext->caps(); }
33 
resourceProvider()34     ResourceProvider* resourceProvider() { return fRecorder->fResourceProvider; }
35 
runtimeEffectDictionary()36     const RuntimeEffectDictionary* runtimeEffectDictionary() const {
37         return fRecorder->fRuntimeEffectDict.get();
38     }
runtimeEffectDictionary()39     RuntimeEffectDictionary* runtimeEffectDictionary() {
40         return fRecorder->fRuntimeEffectDict.get();
41     }
shaderCodeDictionary()42     const ShaderCodeDictionary* shaderCodeDictionary() const {
43         return fRecorder->fSharedContext->shaderCodeDictionary();
44     }
shaderCodeDictionary()45     ShaderCodeDictionary* shaderCodeDictionary() {
46         return fRecorder->fSharedContext->shaderCodeDictionary();
47     }
48 
rendererProvider()49     const RendererProvider* rendererProvider() const {
50         return fRecorder->fSharedContext->rendererProvider();
51     }
52 
isProtected()53     Protected isProtected() const {
54         return fRecorder->fSharedContext->isProtected();
55     }
56 
rootUploadList()57     UploadList* rootUploadList() { return fRecorder->fRootUploads.get(); }
textureDataCache()58     TextureDataCache* textureDataCache() { return fRecorder->fTextureDataCache.get(); }
drawBufferManager()59     DrawBufferManager* drawBufferManager() { return fRecorder->fDrawBufferManager.get(); }
uploadBufferManager()60     UploadBufferManager* uploadBufferManager() { return fRecorder->fUploadBufferManager.get(); }
61 
atlasProvider()62     AtlasProvider* atlasProvider() { return fRecorder->fAtlasProvider.get(); }
tokenTracker()63     TokenTracker* tokenTracker() { return fRecorder->fTokenTracker.get(); }
strikeCache()64     sktext::gpu::StrikeCache* strikeCache() { return fRecorder->fStrikeCache.get(); }
textBlobCache()65     sktext::gpu::TextBlobRedrawCoordinator* textBlobCache() {
66         return fRecorder->fTextBlobCache.get();
67     }
proxyCache()68     ProxyCache* proxyCache() { return this->resourceProvider()->proxyCache(); }
69 
70     // NOTE: Temporary access for DrawTask to manipulate pending read counts.
71     void addPendingRead(const TextureProxy*);
72 
73     static sk_sp<TextureProxy> CreateCachedProxy(Recorder*,
74                                                  const SkBitmap&,
75                                                  std::string_view label);
76 
uniqueID()77     uint32_t uniqueID() const { return fRecorder->fUniqueID; }
78 
79 #if defined(SK_DEBUG)
nextRecordingID()80     uint32_t nextRecordingID() const { return fRecorder->fNextRecordingID; }
81 #endif
82 
83     size_t getResourceCacheLimit() const;
84 
85 #if defined(GPU_TEST_UTILS)
86     bool deviceIsRegistered(Device*) const;
resourceCache()87     ResourceCache* resourceCache() { return fRecorder->fResourceProvider->resourceCache(); }
sharedContext()88     SharedContext* sharedContext() { return fRecorder->fSharedContext.get(); }
89     // used by the Context that created this Recorder to set a back pointer
90     void setContext(Context*);
context()91     Context* context() { return fRecorder->fContext; }
92     void issueFlushToken();
93 #endif
94 
95 private:
RecorderPriv(Recorder * recorder)96     explicit RecorderPriv(Recorder* recorder) : fRecorder(recorder) {}
97     RecorderPriv& operator=(const RecorderPriv&) = delete;
98 
99     // No taking addresses of this type.
100     const RecorderPriv* operator&() const = delete;
101     RecorderPriv* operator&() = delete;
102 
103     Recorder* fRecorder;
104 
105     friend class Recorder;  // to construct/copy this type.
106 };
107 
priv()108 inline RecorderPriv Recorder::priv() {
109     return RecorderPriv(this);
110 }
111 
priv()112 inline const RecorderPriv Recorder::priv() const {  // NOLINT(readability-const-return-type)
113     return RecorderPriv(const_cast<Recorder*>(this));
114 }
115 
116 } // namespace skgpu::graphite
117 
118 #endif // skgpu_graphite_RecorderPriv_DEFINED
119