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