• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_QueueManager_DEFINED
9 #define skgpu_graphite_QueueManager_DEFINED
10 
11 #include "include/core/SkRefCnt.h"
12 #include "include/gpu/graphite/GraphiteTypes.h"
13 #include "include/private/base/SkDeque.h"
14 
15 #include <memory>
16 #include <vector>
17 
18 namespace skgpu::graphite {
19 
20 class CommandBuffer;
21 class Context;
22 class GpuWorkSubmission;
23 struct InsertRecordingInfo;
24 class ResourceProvider;
25 class SharedContext;
26 class Task;
27 
28 class QueueManager {
29 public:
30     virtual ~QueueManager();
31 
32     // Adds the commands from the passed in Recording to the current CommandBuffer
33     bool SK_WARN_UNUSED_RESULT addRecording(const InsertRecordingInfo&, Context*);
34 
35     // Adds the commands from the passed in Task to the current CommandBuffer
36     bool SK_WARN_UNUSED_RESULT addTask(Task*, Context*);
37 
38     // Adds the commands from the passed in Task to the current CommandBuffer
39     bool SK_WARN_UNUSED_RESULT addFinishInfo(const InsertFinishInfo&, ResourceProvider*);
40 
41     bool SK_WARN_UNUSED_RESULT submitToGpu();
42     void checkForFinishedWork(SyncToCpu);
43 
44 #if GRAPHITE_TEST_UTILS
startCapture()45     virtual void startCapture() {}
stopCapture()46     virtual void stopCapture() {}
47 #endif
48 
49     void returnCommandBuffer(std::unique_ptr<CommandBuffer>);
50 
51 protected:
52     QueueManager(const SharedContext* sharedContext);
53 
54     using OutstandingSubmission = std::unique_ptr<GpuWorkSubmission>;
55 
56     const SharedContext* fSharedContext;
57     std::unique_ptr<CommandBuffer> fCurrentCommandBuffer;
58 
59 private:
60     virtual std::unique_ptr<CommandBuffer> getNewCommandBuffer(ResourceProvider*) = 0;
61     virtual OutstandingSubmission onSubmitToGpu() = 0;
62 
63     bool setupCommandBuffer(ResourceProvider*);
64 
65     SkDeque fOutstandingSubmissions;
66 
67     std::vector<std::unique_ptr<CommandBuffer>> fAvailableCommandBuffers;
68 };
69 
70 } // namespace skgpu::graphite
71 
72 #endif // skgpu_graphite_QueueManager_DEFINED
73