xref: /aosp_15_r20/external/skia/include/gpu/graphite/Recording.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/core/SkSize.h"
13 #include "include/private/base/SkTArray.h"
14 
15 #include <memory>
16 #include <unordered_set>
17 #include <vector>
18 
19 namespace skgpu {
20 class RefCntedCallback;
21 }
22 
23 namespace skgpu::graphite {
24 
25 class Caps;
26 class CommandBuffer;
27 class RecordingPriv;
28 class Resource;
29 class ResourceProvider;
30 class TaskList;
31 class Texture;
32 class TextureInfo;
33 class TextureProxy;
34 
35 class SK_API Recording final {
36 public:
37     ~Recording();
38 
39     RecordingPriv priv();
40 
41 private:
42     friend class Recorder;  // for ctor and LazyProxyData
43     friend class RecordingPriv;
44 
45     // LazyProxyData is used if this recording should be replayed to a target that is provided on
46     // replay, and it handles the target proxy's instantiation with the provided target.
47     class LazyProxyData {
48     public:
49         LazyProxyData(const Caps*, SkISize dimensions, const TextureInfo&);
50 
51         TextureProxy* lazyProxy();
52         sk_sp<TextureProxy> refLazyProxy();
53 
54         bool lazyInstantiate(ResourceProvider*, sk_sp<Texture>);
55 
56     private:
57         sk_sp<Texture> fTarget;
58         sk_sp<TextureProxy> fTargetProxy;
59     };
60 
61     struct ProxyHash {
62         std::size_t operator()(const sk_sp<TextureProxy>& proxy) const;
63     };
64 
65     Recording(uint32_t uniqueID,
66               uint32_t recorderID,
67               std::unordered_set<sk_sp<TextureProxy>, ProxyHash>&& nonVolatileLazyProxies,
68               std::unordered_set<sk_sp<TextureProxy>, ProxyHash>&& volatileLazyProxies,
69               std::unique_ptr<LazyProxyData> targetProxyData,
70               skia_private::TArray<sk_sp<RefCntedCallback>>&& finishedProcs);
71 
72     bool addCommands(CommandBuffer*, ResourceProvider*);
73     void addResourceRef(sk_sp<Resource>);
74 
75     // Used to verify ordering
76     uint32_t fUniqueID;
77     uint32_t fRecorderID;
78 
79     // This is held by a pointer instead of being inline to allow TaskList to be forward declared.
80     std::unique_ptr<TaskList> fRootTaskList;
81     // We don't always take refs to all resources used by specific Tasks (e.g. a common buffer used
82     // for uploads). Instead we'll just hold onto one ref for those Resources outside the Tasks.
83     // Those refs are stored in the array here and will eventually be passed onto a CommandBuffer
84     // when the Recording adds its commands.
85     std::vector<sk_sp<Resource>> fExtraResourceRefs;
86 
87     std::unordered_set<sk_sp<TextureProxy>, ProxyHash> fNonVolatileLazyProxies;
88     std::unordered_set<sk_sp<TextureProxy>, ProxyHash> fVolatileLazyProxies;
89 
90     std::unique_ptr<LazyProxyData> fTargetProxyData;
91 
92     skia_private::TArray<sk_sp<RefCntedCallback>> fFinishedProcs;
93 };
94 
95 } // namespace skgpu::graphite
96 
97 #endif // skgpu_graphite_Recording_DEFINED
98