Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: gpu/command_buffer/service/command_executor.h

Issue 2763753002: gpu: Add callback for yielding command buffer execution. (Closed)
Patch Set: no need to !!pause Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gpu/command_buffer/service/BUILD.gn ('k') | gpu/command_buffer/service/command_executor.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef GPU_COMMAND_BUFFER_SERVICE_COMMAND_EXECUTOR_H_ 5 #ifndef GPU_COMMAND_BUFFER_SERVICE_COMMAND_EXECUTOR_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_COMMAND_EXECUTOR_H_ 6 #define GPU_COMMAND_BUFFER_SERVICE_COMMAND_EXECUTOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <queue> 11 #include <queue>
12 12
13 #include "base/atomic_ref_count.h"
14 #include "base/atomicops.h"
15 #include "base/callback.h" 13 #include "base/callback.h"
16 #include "base/macros.h" 14 #include "base/macros.h"
17 #include "base/memory/ref_counted.h"
18 #include "base/memory/shared_memory.h" 15 #include "base/memory/shared_memory.h"
19 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
20 #include "gpu/command_buffer/service/cmd_buffer_engine.h" 17 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
21 #include "gpu/command_buffer/service/cmd_parser.h" 18 #include "gpu/command_buffer/service/cmd_parser.h"
22 #include "gpu/command_buffer/service/command_buffer_service.h" 19 #include "gpu/command_buffer/service/command_buffer_service.h"
23 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 20 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
24 #include "gpu/gpu_export.h" 21 #include "gpu/gpu_export.h"
25 22
26 namespace gpu { 23 namespace gpu {
27 24
28 class PreemptionFlag : public base::RefCountedThreadSafe<PreemptionFlag> {
29 public:
30 PreemptionFlag() : flag_(0) {}
31
32 bool IsSet() { return !base::AtomicRefCountIsZero(&flag_); }
33 void Set() { base::AtomicRefCountInc(&flag_); }
34 void Reset() { base::subtle::NoBarrier_Store(&flag_, 0); }
35
36 private:
37 base::AtomicRefCount flag_;
38
39 ~PreemptionFlag() {}
40
41 friend class base::RefCountedThreadSafe<PreemptionFlag>;
42 };
43
44 // This class schedules commands that have been flushed. They are received via 25 // This class schedules commands that have been flushed. They are received via
45 // a command buffer and forwarded to a command parser. TODO(apatrick): This 26 // a command buffer and forwarded to a command parser. TODO(apatrick): This
46 // class should not know about the decoder. Do not add additional dependencies 27 // class should not know about the decoder. Do not add additional dependencies
47 // on it. 28 // on it.
48 class GPU_EXPORT CommandExecutor 29 class GPU_EXPORT CommandExecutor
49 : NON_EXPORTED_BASE(public CommandBufferEngine), 30 : NON_EXPORTED_BASE(public CommandBufferEngine),
50 public base::SupportsWeakPtr<CommandExecutor> { 31 public base::SupportsWeakPtr<CommandExecutor> {
51 public: 32 public:
52 CommandExecutor(CommandBufferServiceBase* command_buffer, 33 CommandExecutor(CommandBufferServiceBase* command_buffer,
53 AsyncAPIInterface* handler, 34 AsyncAPIInterface* handler,
54 gles2::GLES2Decoder* decoder); 35 gles2::GLES2Decoder* decoder);
55 36
56 ~CommandExecutor() override; 37 ~CommandExecutor() override;
57 38
58 void PutChanged(); 39 void PutChanged();
59 40
60 void SetPreemptByFlag(scoped_refptr<PreemptionFlag> flag) {
61 preemption_flag_ = flag;
62 }
63
64 // Sets whether commands should be processed by this scheduler. Setting to 41 // Sets whether commands should be processed by this scheduler. Setting to
65 // false unschedules. Setting to true reschedules. 42 // false unschedules. Setting to true reschedules.
66 void SetScheduled(bool scheduled); 43 void SetScheduled(bool scheduled);
67 44
68 bool scheduled() const { return scheduled_; } 45 bool scheduled() const { return scheduled_; }
69 46
70 // Returns whether the scheduler needs to be polled again in the future to 47 // Returns whether the scheduler needs to be polled again in the future to
71 // process pending queries. 48 // process pending queries.
72 bool HasPendingQueries() const; 49 bool HasPendingQueries() const;
73 50
74 // Process pending queries and return. HasPendingQueries() can be used to 51 // Process pending queries and return. HasPendingQueries() can be used to
75 // determine if there's more pending queries after this has been called. 52 // determine if there's more pending queries after this has been called.
76 void ProcessPendingQueries(); 53 void ProcessPendingQueries();
77 54
78 // Implementation of CommandBufferEngine. 55 // Implementation of CommandBufferEngine.
79 scoped_refptr<Buffer> GetSharedMemoryBuffer(int32_t shm_id) override; 56 scoped_refptr<Buffer> GetSharedMemoryBuffer(int32_t shm_id) override;
80 void set_token(int32_t token) override; 57 void set_token(int32_t token) override;
81 bool SetGetBuffer(int32_t transfer_buffer_id) override; 58 bool SetGetBuffer(int32_t transfer_buffer_id) override;
82 bool SetGetOffset(int32_t offset) override; 59 bool SetGetOffset(int32_t offset) override;
83 int32_t GetGetOffset() override; 60 int32_t GetGetOffset() override;
84 61
85 void SetCommandProcessedCallback(const base::Closure& callback); 62 void SetCommandProcessedCallback(const base::Closure& callback);
86 63
64 using PauseExecutionCallback = base::Callback<bool(void)>;
65 void SetPauseExecutionCallback(const PauseExecutionCallback& callback);
66
87 // Returns whether the scheduler needs to be polled again in the future to 67 // Returns whether the scheduler needs to be polled again in the future to
88 // process idle work. 68 // process idle work.
89 bool HasMoreIdleWork() const; 69 bool HasMoreIdleWork() const;
90 70
91 // Perform some idle work and return. HasMoreIdleWork() can be used to 71 // Perform some idle work and return. HasMoreIdleWork() can be used to
92 // determine if there's more idle work do be done after this has been called. 72 // determine if there's more idle work do be done after this has been called.
93 void PerformIdleWork(); 73 void PerformIdleWork();
94 74
95 // Whether there is state that needs to be regularly polled. 75 // Whether there is state that needs to be regularly polled.
96 bool HasPollingWork() const; 76 bool HasPollingWork() const;
97 void PerformPollingWork(); 77 void PerformPollingWork();
98 78
99 CommandParser* parser() const { return parser_.get(); } 79 CommandParser* parser() const { return parser_.get(); }
100 80
101 private: 81 private:
102 bool IsPreempted(); 82 bool PauseExecution();
103 83
104 // The CommandExecutor holds a weak reference to the CommandBuffer. The 84 // The CommandExecutor holds a weak reference to the CommandBuffer. The
105 // CommandBuffer owns the CommandExecutor and holds a strong reference to it 85 // CommandBuffer owns the CommandExecutor and holds a strong reference to it
106 // through the ProcessCommands callback. 86 // through the ProcessCommands callback.
107 CommandBufferServiceBase* command_buffer_; 87 CommandBufferServiceBase* command_buffer_;
108 88
109 // The parser uses this to execute commands. 89 // The parser uses this to execute commands.
110 AsyncAPIInterface* handler_; 90 AsyncAPIInterface* handler_;
111 91
112 // Does not own decoder. TODO(apatrick): The CommandExecutor shouldn't need a 92 // Does not own decoder. TODO(apatrick): The CommandExecutor shouldn't need a
113 // pointer to the decoder, it is only used to initialize the CommandParser, 93 // pointer to the decoder, it is only used to initialize the CommandParser,
114 // which could be an argument to the constructor, and to determine the 94 // which could be an argument to the constructor, and to determine the
115 // reason for context lost. 95 // reason for context lost.
116 gles2::GLES2Decoder* decoder_; 96 gles2::GLES2Decoder* decoder_;
117 97
118 // TODO(apatrick): The CommandExecutor currently creates and owns the parser. 98 // TODO(apatrick): The CommandExecutor currently creates and owns the parser.
119 // This should be an argument to the constructor. 99 // This should be an argument to the constructor.
120 std::unique_ptr<CommandParser> parser_; 100 std::unique_ptr<CommandParser> parser_;
121 101
122 // Whether the scheduler is currently able to process more commands. 102 // Whether the scheduler is currently able to process more commands.
123 bool scheduled_; 103 bool scheduled_ = true;
124 104
125 base::Closure command_processed_callback_; 105 base::Closure command_processed_callback_;
126 106
127 // If non-NULL and |preemption_flag_->IsSet()|, exit PutChanged early. 107 // If this callback returns true, exit PutChanged early.
128 scoped_refptr<PreemptionFlag> preemption_flag_; 108 PauseExecutionCallback pause_execution_callback_;
129 bool was_preempted_; 109 bool paused_ = false;
130 110
131 DISALLOW_COPY_AND_ASSIGN(CommandExecutor); 111 DISALLOW_COPY_AND_ASSIGN(CommandExecutor);
132 }; 112 };
133 113
134 } // namespace gpu 114 } // namespace gpu
135 115
136 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_EXECUTOR_H_ 116 #endif // GPU_COMMAND_BUFFER_SERVICE_COMMAND_EXECUTOR_H_
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/BUILD.gn ('k') | gpu/command_buffer/service/command_executor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698