• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/base/SkTArray.h"
13 
14 #include <memory>
15 #include <unordered_set>
16 #include <vector>
17 
18 namespace skgpu {
19 class RefCntedCallback;
20 }
21 
22 namespace skgpu::graphite {
23 
24 class CommandBuffer;
25 class RecordingPriv;
26 class Resource;
27 class ResourceProvider;
28 class TaskList;
29 class Texture;
30 class TextureInfo;
31 class TextureProxy;
32 
33 class SK_API Recording final {
34 public:
35     ~Recording();
36 
37     RecordingPriv priv();
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 {
60         std::size_t operator()(const sk_sp<TextureProxy>& proxy) const;
61     };
62 
63     Recording(uint32_t uniqueID,
64               uint32_t recorderID,
65               std::unordered_set<sk_sp<TextureProxy>, ProxyHash>&& nonVolatileLazyProxies,
66               std::unordered_set<sk_sp<TextureProxy>, ProxyHash>&& volatileLazyProxies,
67               std::unique_ptr<LazyProxyData> targetProxyData,
68               skia_private::TArray<sk_sp<RefCntedCallback>>&& finishedProcs);
69 
70     bool addCommands(CommandBuffer*, ResourceProvider*);
71     void addResourceRef(sk_sp<Resource>);
72 
73     // Used to verify ordering
74     uint32_t fUniqueID;
75     uint32_t fRecorderID;
76 
77     // This is held by a pointer instead of being inline to allow TaskList to be forward declared.
78     std::unique_ptr<TaskList> fRootTaskList;
79     // We don't always take refs to all resources used by specific Tasks (e.g. a common buffer used
80     // for uploads). Instead we'll just hold onto one ref for those Resources outside the Tasks.
81     // Those refs are stored in the array here and will eventually be passed onto a CommandBuffer
82     // when the Recording adds its commands.
83     std::vector<sk_sp<Resource>> fExtraResourceRefs;
84 
85     std::unordered_set<sk_sp<TextureProxy>, ProxyHash> fNonVolatileLazyProxies;
86     std::unordered_set<sk_sp<TextureProxy>, ProxyHash> fVolatileLazyProxies;
87 
88     std::unique_ptr<LazyProxyData> fTargetProxyData;
89 
90     skia_private::TArray<sk_sp<RefCntedCallback>> fFinishedProcs;
91 };
92 
93 } // namespace skgpu::graphite
94 
95 #endif // skgpu_graphite_Recording_DEFINED
96