OLD | NEW |
---|---|
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/gpu_scheduler.h" | 5 #include "gpu/command_buffer/service/gpu_scheduler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
27 const int64 kRescheduleTimeOutDelay = 1000; | 27 const int64 kRescheduleTimeOutDelay = 1000; |
28 #endif | 28 #endif |
29 | 29 |
30 GpuScheduler::GpuScheduler(CommandBufferServiceBase* command_buffer, | 30 GpuScheduler::GpuScheduler(CommandBufferServiceBase* command_buffer, |
31 AsyncAPIInterface* handler, | 31 AsyncAPIInterface* handler, |
32 gles2::GLES2Decoder* decoder) | 32 gles2::GLES2Decoder* decoder) |
33 : command_buffer_(command_buffer), | 33 : command_buffer_(command_buffer), |
34 handler_(handler), | 34 handler_(handler), |
35 decoder_(decoder), | 35 decoder_(decoder), |
36 unscheduled_count_(0), | 36 unscheduled_count_(0), |
37 rescheduled_count_(0), | 37 was_preempted_(false) {} |
38 was_preempted_(false), | |
39 reschedule_task_factory_(this) {} | |
40 | 38 |
41 GpuScheduler::~GpuScheduler() { | 39 GpuScheduler::~GpuScheduler() {} |
42 } | |
43 | 40 |
44 void GpuScheduler::PutChanged() { | 41 void GpuScheduler::PutChanged() { |
45 TRACE_EVENT1( | 42 TRACE_EVENT1( |
46 "gpu", "GpuScheduler:PutChanged", | 43 "gpu", "GpuScheduler:PutChanged", |
47 "decoder", decoder_ ? decoder_->GetLogger()->GetLogPrefix() : "None"); | 44 "decoder", decoder_ ? decoder_->GetLogger()->GetLogPrefix() : "None"); |
48 | 45 |
49 CommandBuffer::State state = command_buffer_->GetLastState(); | 46 CommandBuffer::State state = command_buffer_->GetLastState(); |
50 | 47 |
51 // If there is no parser, exit. | 48 // If there is no parser, exit. |
52 if (!parser_.get()) { | 49 if (!parser_.get()) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 decoder_->EndDecoding(); | 102 decoder_->EndDecoding(); |
106 decoder_->AddProcessingCommandsTime(base::TimeTicks::Now() - begin_time); | 103 decoder_->AddProcessingCommandsTime(base::TimeTicks::Now() - begin_time); |
107 } | 104 } |
108 } | 105 } |
109 | 106 |
110 void GpuScheduler::SetScheduled(bool scheduled) { | 107 void GpuScheduler::SetScheduled(bool scheduled) { |
111 TRACE_EVENT2("gpu", "GpuScheduler:SetScheduled", "this", this, | 108 TRACE_EVENT2("gpu", "GpuScheduler:SetScheduled", "this", this, |
112 "new unscheduled_count_", | 109 "new unscheduled_count_", |
113 unscheduled_count_ + (scheduled? -1 : 1)); | 110 unscheduled_count_ + (scheduled? -1 : 1)); |
114 if (scheduled) { | 111 if (scheduled) { |
115 // If the scheduler was rescheduled after a timeout, ignore the subsequent | 112 --unscheduled_count_; |
116 // calls to SetScheduled when they eventually arrive until they are all | 113 if (unscheduled_count_ == 0 && !scheduling_changed_callback_.is_null()) |
117 // accounted for. | |
118 if (rescheduled_count_ > 0) { | |
119 --rescheduled_count_; | |
120 return; | |
121 } else { | |
122 --unscheduled_count_; | |
123 } | |
124 | |
125 DCHECK_GE(unscheduled_count_, 0); | |
126 | |
127 if (unscheduled_count_ == 0) { | |
128 TRACE_EVENT_ASYNC_END1("gpu", "ProcessingSwap", this, | |
129 "GpuScheduler", this); | |
130 // When the scheduler transitions from the unscheduled to the scheduled | |
131 // state, cancel the task that would reschedule it after a timeout. | |
132 reschedule_task_factory_.InvalidateWeakPtrs(); | |
133 | |
134 if (!scheduling_changed_callback_.is_null()) | |
135 scheduling_changed_callback_.Run(true); | 114 scheduling_changed_callback_.Run(true); |
136 } | |
137 } else { | 115 } else { |
138 ++unscheduled_count_; | 116 ++unscheduled_count_; |
139 if (unscheduled_count_ == 1) { | 117 if (unscheduled_count_ == 1 && !scheduling_changed_callback_.is_null()) |
140 TRACE_EVENT_ASYNC_BEGIN1("gpu", "ProcessingSwap", this, | |
141 "GpuScheduler", this); | |
142 #if defined(OS_WIN) | |
143 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | |
144 // When the scheduler transitions from scheduled to unscheduled, post a | |
145 // delayed task that it will force it back into a scheduled state after | |
146 // a timeout. This should only be necessary on pre-Vista. | |
147 base::MessageLoop::current()->PostDelayedTask( | |
148 FROM_HERE, | |
149 base::Bind(&GpuScheduler::RescheduleTimeOut, | |
150 reschedule_task_factory_.GetWeakPtr()), | |
151 base::TimeDelta::FromMilliseconds(kRescheduleTimeOutDelay)); | |
152 } | |
153 #endif | |
piman
2015/09/16 21:46:29
What is the reason this is not needed any more? Is
sunnyps
2015/09/16 23:08:31
I do not know what everything else looked like whe
| |
154 if (!scheduling_changed_callback_.is_null()) | |
155 scheduling_changed_callback_.Run(false); | 118 scheduling_changed_callback_.Run(false); |
156 } | |
157 } | 119 } |
120 DCHECK_GE(unscheduled_count_, 0); | |
158 } | 121 } |
159 | 122 |
160 bool GpuScheduler::IsScheduled() { | 123 bool GpuScheduler::IsScheduled() { |
161 return unscheduled_count_ == 0; | 124 return unscheduled_count_ == 0; |
162 } | 125 } |
163 | 126 |
164 bool GpuScheduler::HasMoreWork() { | 127 bool GpuScheduler::HasMoreWork() { |
165 return (decoder_ && decoder_->ProcessPendingQueries(false)) || | 128 return (decoder_ && decoder_->ProcessPendingQueries(false)) || |
166 HasMoreIdleWork(); | 129 HasMoreIdleWork(); |
167 } | 130 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 bool GpuScheduler::HasMoreIdleWork() { | 195 bool GpuScheduler::HasMoreIdleWork() { |
233 return (decoder_ && decoder_->HasMoreIdleWork()); | 196 return (decoder_ && decoder_->HasMoreIdleWork()); |
234 } | 197 } |
235 | 198 |
236 void GpuScheduler::PerformIdleWork() { | 199 void GpuScheduler::PerformIdleWork() { |
237 if (!decoder_) | 200 if (!decoder_) |
238 return; | 201 return; |
239 decoder_->PerformIdleWork(); | 202 decoder_->PerformIdleWork(); |
240 } | 203 } |
241 | 204 |
242 void GpuScheduler::RescheduleTimeOut() { | |
243 int new_count = unscheduled_count_ + rescheduled_count_; | |
244 | |
245 rescheduled_count_ = 0; | |
246 | |
247 while (unscheduled_count_) | |
248 SetScheduled(true); | |
249 | |
250 rescheduled_count_ = new_count; | |
251 } | |
252 | |
253 } // namespace gpu | 205 } // namespace gpu |
OLD | NEW |