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

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

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
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 #include "gpu/command_buffer/service/command_executor.h" 5 #include "gpu/command_buffer/service/command_executor.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "gpu/command_buffer/service/logger.h" 15 #include "gpu/command_buffer/service/logger.h"
16 #include "ui/gl/gl_bindings.h" 16 #include "ui/gl/gl_bindings.h"
17 #include "ui/gl/gl_fence.h" 17 #include "ui/gl/gl_fence.h"
18 #include "ui/gl/gl_switches.h" 18 #include "ui/gl/gl_switches.h"
19 19
20 using ::base::SharedMemory; 20 using ::base::SharedMemory;
21 21
22 namespace gpu { 22 namespace gpu {
23 23
24 CommandExecutor::CommandExecutor(CommandBufferServiceBase* command_buffer, 24 CommandExecutor::CommandExecutor(CommandBufferServiceBase* command_buffer,
25 AsyncAPIInterface* handler, 25 AsyncAPIInterface* handler,
26 gles2::GLES2Decoder* decoder) 26 gles2::GLES2Decoder* decoder)
27 : command_buffer_(command_buffer), 27 : command_buffer_(command_buffer), handler_(handler), decoder_(decoder) {}
28 handler_(handler),
29 decoder_(decoder),
30 scheduled_(true),
31 was_preempted_(false) {}
32 28
33 CommandExecutor::~CommandExecutor() {} 29 CommandExecutor::~CommandExecutor() {}
34 30
35 void CommandExecutor::PutChanged() { 31 void CommandExecutor::PutChanged() {
36 TRACE_EVENT1("gpu", "CommandExecutor:PutChanged", "decoder", 32 TRACE_EVENT1("gpu", "CommandExecutor:PutChanged", "decoder",
37 decoder_ ? decoder_->GetLogger()->GetLogPrefix() : "None"); 33 decoder_ ? decoder_->GetLogger()->GetLogPrefix() : "None");
38 34
39 CommandBuffer::State state = command_buffer_->GetLastState(); 35 CommandBuffer::State state = command_buffer_->GetLastState();
40 36
41 // If there is no parser, exit. 37 // If there is no parser, exit.
42 if (!parser_.get()) { 38 if (!parser_.get()) {
43 DCHECK_EQ(state.get_offset, command_buffer_->GetPutOffset()); 39 DCHECK_EQ(state.get_offset, command_buffer_->GetPutOffset());
44 return; 40 return;
45 } 41 }
46 42
47 parser_->set_put(command_buffer_->GetPutOffset()); 43 parser_->set_put(command_buffer_->GetPutOffset());
48 if (state.error != error::kNoError) 44 if (state.error != error::kNoError)
49 return; 45 return;
50 46
51 base::TimeTicks begin_time(base::TimeTicks::Now()); 47 base::TimeTicks begin_time(base::TimeTicks::Now());
52 error::Error error = error::kNoError; 48 error::Error error = error::kNoError;
53 if (decoder_) 49 if (decoder_)
54 decoder_->BeginDecoding(); 50 decoder_->BeginDecoding();
55 while (!parser_->IsEmpty()) { 51 while (!parser_->IsEmpty()) {
56 if (IsPreempted()) 52 if (PauseExecution())
57 break; 53 break;
58 54
59 DCHECK(scheduled()); 55 DCHECK(scheduled());
60 56
61 error = parser_->ProcessCommands(CommandParser::kParseCommandsSlice); 57 error = parser_->ProcessCommands(CommandParser::kParseCommandsSlice);
62 58
63 if (error == error::kDeferCommandUntilLater) { 59 if (error == error::kDeferCommandUntilLater) {
64 DCHECK(!scheduled()); 60 DCHECK(!scheduled());
65 break; 61 break;
66 } 62 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 141
146 int32_t CommandExecutor::GetGetOffset() { 142 int32_t CommandExecutor::GetGetOffset() {
147 return parser_->get(); 143 return parser_->get();
148 } 144 }
149 145
150 void CommandExecutor::SetCommandProcessedCallback( 146 void CommandExecutor::SetCommandProcessedCallback(
151 const base::Closure& callback) { 147 const base::Closure& callback) {
152 command_processed_callback_ = callback; 148 command_processed_callback_ = callback;
153 } 149 }
154 150
155 bool CommandExecutor::IsPreempted() { 151 void CommandExecutor::SetPauseExecutionCallback(
156 if (!preemption_flag_.get()) 152 const PauseExecutionCallback& callback) {
153 pause_execution_callback_ = callback;
154 }
155
156 bool CommandExecutor::PauseExecution() {
157 if (pause_execution_callback_.is_null())
157 return false; 158 return false;
158 159
159 if (!was_preempted_ && preemption_flag_->IsSet()) { 160 bool pause = pause_execution_callback_.Run();
160 TRACE_COUNTER_ID1("gpu", "CommandExecutor::Preempted", this, 1); 161 if (paused_ != pause) {
161 was_preempted_ = true; 162 TRACE_COUNTER_ID1("gpu", "CommandExecutor::Paused", this, pause);
162 } else if (was_preempted_ && !preemption_flag_->IsSet()) { 163 paused_ = pause;
163 TRACE_COUNTER_ID1("gpu", "CommandExecutor::Preempted", this, 0);
164 was_preempted_ = false;
165 } 164 }
166 165 return pause;
167 return preemption_flag_->IsSet();
168 } 166 }
169 167
170 bool CommandExecutor::HasMoreIdleWork() const { 168 bool CommandExecutor::HasMoreIdleWork() const {
171 return (decoder_ && decoder_->HasMoreIdleWork()); 169 return (decoder_ && decoder_->HasMoreIdleWork());
172 } 170 }
173 171
174 void CommandExecutor::PerformIdleWork() { 172 void CommandExecutor::PerformIdleWork() {
175 if (!decoder_) 173 if (!decoder_)
176 return; 174 return;
177 decoder_->PerformIdleWork(); 175 decoder_->PerformIdleWork();
178 } 176 }
179 177
180 bool CommandExecutor::HasPollingWork() const { 178 bool CommandExecutor::HasPollingWork() const {
181 return (decoder_ && decoder_->HasPollingWork()); 179 return (decoder_ && decoder_->HasPollingWork());
182 } 180 }
183 181
184 void CommandExecutor::PerformPollingWork() { 182 void CommandExecutor::PerformPollingWork() {
185 if (!decoder_) 183 if (!decoder_)
186 return; 184 return;
187 decoder_->PerformPollingWork(); 185 decoder_->PerformPollingWork();
188 } 186 }
189 187
190 } // namespace gpu 188 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/command_executor.h ('k') | gpu/command_buffer/service/preemption_flag.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698