1 /* 2 * Copyright 2021 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_Recording_DEFINED 9 #define skgpu_graphite_Recording_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/private/SkChecksum.h" 13 14 #include <memory> 15 #include <unordered_set> 16 #include <vector> 17 18 namespace skgpu::graphite { 19 20 class CommandBuffer; 21 class RecordingPriv; 22 class Resource; 23 class ResourceProvider; 24 class TaskGraph; 25 class Texture; 26 class TextureInfo; 27 class TextureProxy; 28 29 class Recording final { 30 public: 31 ~Recording(); 32 33 RecordingPriv priv(); 34 35 #if GRAPHITE_TEST_UTILS 36 bool isTargetProxyInstantiated() const; 37 #endif 38 39 private: 40 friend class Recorder; // for ctor and LazyProxyData 41 friend class RecordingPriv; 42 43 // LazyProxyData is used if this recording should be replayed to a target that is provided on 44 // replay, and it handles the target proxy's instantiation with the provided target. 45 class LazyProxyData { 46 public: 47 LazyProxyData(const TextureInfo&); 48 49 TextureProxy* lazyProxy(); 50 sk_sp<TextureProxy> refLazyProxy(); 51 52 bool lazyInstantiate(ResourceProvider*, sk_sp<Texture>); 53 54 private: 55 sk_sp<Texture> fTarget; 56 sk_sp<TextureProxy> fTargetProxy; 57 }; 58 59 struct ProxyHash { operatorProxyHash60 std::size_t operator()(const sk_sp<TextureProxy>& proxy) const { 61 return SkGoodHash()(proxy.get()); 62 } 63 }; 64 65 Recording(std::unique_ptr<TaskGraph>, 66 std::unordered_set<sk_sp<TextureProxy>, ProxyHash>&& nonVolatileLazyProxies, 67 std::unordered_set<sk_sp<TextureProxy>, ProxyHash>&& volatileLazyProxies, 68 std::unique_ptr<LazyProxyData> targetProxyData); 69 70 bool addCommands(CommandBuffer*, ResourceProvider*); 71 void addResourceRef(sk_sp<Resource>); 72 73 std::unique_ptr<TaskGraph> fGraph; 74 // We don't always take refs to all resources used by specific Tasks (e.g. a common buffer used 75 // for uploads). Instead we'll just hold onto one ref for those Resources outside the Tasks. 76 // Those refs are stored in the array here and will eventually be passed onto a CommandBuffer 77 // when the Recording adds its commands. 78 std::vector<sk_sp<Resource>> fExtraResourceRefs; 79 80 std::unordered_set<sk_sp<TextureProxy>, ProxyHash> fNonVolatileLazyProxies; 81 std::unordered_set<sk_sp<TextureProxy>, ProxyHash> fVolatileLazyProxies; 82 83 std::unique_ptr<LazyProxyData> fTargetProxyData; 84 }; 85 86 } // namespace skgpu::graphite 87 88 #endif // skgpu_graphite_Recording_DEFINED 89