Chromium Code Reviews| 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" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 13 #include "gpu/command_buffer/service/logger.h" | 13 #include "gpu/command_buffer/service/logger.h" |
| 14 #include "ui/gl/gl_bindings.h" | 14 #include "ui/gl/gl_bindings.h" |
| 15 #include "ui/gl/gl_fence.h" | 15 #include "ui/gl/gl_fence.h" |
| 16 #include "ui/gl/gl_switches.h" | 16 #include "ui/gl/gl_switches.h" |
| 17 | 17 |
| 18 #if defined(OS_WIN) | |
| 19 #include "base/win/windows_version.h" | |
| 20 #endif | |
| 21 | |
| 22 using ::base::SharedMemory; | 18 using ::base::SharedMemory; |
| 23 | 19 |
| 24 namespace gpu { | 20 namespace gpu { |
| 25 | 21 |
| 26 #if defined(OS_WIN) | 22 #if defined(OS_WIN) |
| 27 const int64 kRescheduleTimeOutDelay = 1000; | 23 const int64 kRescheduleTimeOutDelay = 1000; |
| 28 #endif | 24 #endif |
| 29 | 25 |
| 30 GpuScheduler::GpuScheduler(CommandBufferServiceBase* command_buffer, | 26 GpuScheduler::GpuScheduler(CommandBufferServiceBase* command_buffer, |
| 31 AsyncAPIInterface* handler, | 27 AsyncAPIInterface* handler, |
| 32 gles2::GLES2Decoder* decoder) | 28 gles2::GLES2Decoder* decoder) |
| 33 : command_buffer_(command_buffer), | 29 : command_buffer_(command_buffer), |
| 34 handler_(handler), | 30 handler_(handler), |
| 35 decoder_(decoder), | 31 decoder_(decoder), |
| 36 unscheduled_count_(0), | 32 unscheduled_count_(0), |
|
piman
2015/09/16 23:48:42
You still need an initializer for scheduled_.
sunnyps
2015/09/17 00:04:53
Done.
| |
| 37 rescheduled_count_(0), | 33 was_preempted_(false) {} |
| 38 was_preempted_(false), | |
| 39 reschedule_task_factory_(this) {} | |
| 40 | 34 |
| 41 GpuScheduler::~GpuScheduler() { | 35 GpuScheduler::~GpuScheduler() {} |
| 42 } | |
| 43 | 36 |
| 44 void GpuScheduler::PutChanged() { | 37 void GpuScheduler::PutChanged() { |
| 45 TRACE_EVENT1( | 38 TRACE_EVENT1( |
| 46 "gpu", "GpuScheduler:PutChanged", | 39 "gpu", "GpuScheduler:PutChanged", |
| 47 "decoder", decoder_ ? decoder_->GetLogger()->GetLogPrefix() : "None"); | 40 "decoder", decoder_ ? decoder_->GetLogger()->GetLogPrefix() : "None"); |
| 48 | 41 |
| 49 CommandBuffer::State state = command_buffer_->GetLastState(); | 42 CommandBuffer::State state = command_buffer_->GetLastState(); |
| 50 | 43 |
| 51 // If there is no parser, exit. | 44 // If there is no parser, exit. |
| 52 if (!parser_.get()) { | 45 if (!parser_.get()) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 decoder_->EndDecoding(); | 98 decoder_->EndDecoding(); |
| 106 decoder_->AddProcessingCommandsTime(base::TimeTicks::Now() - begin_time); | 99 decoder_->AddProcessingCommandsTime(base::TimeTicks::Now() - begin_time); |
| 107 } | 100 } |
| 108 } | 101 } |
| 109 | 102 |
| 110 void GpuScheduler::SetScheduled(bool scheduled) { | 103 void GpuScheduler::SetScheduled(bool scheduled) { |
| 111 TRACE_EVENT2("gpu", "GpuScheduler:SetScheduled", "this", this, | 104 TRACE_EVENT2("gpu", "GpuScheduler:SetScheduled", "this", this, |
| 112 "new unscheduled_count_", | 105 "new unscheduled_count_", |
| 113 unscheduled_count_ + (scheduled? -1 : 1)); | 106 unscheduled_count_ + (scheduled? -1 : 1)); |
| 114 if (scheduled) { | 107 if (scheduled) { |
| 115 // If the scheduler was rescheduled after a timeout, ignore the subsequent | 108 --unscheduled_count_; |
| 116 // calls to SetScheduled when they eventually arrive until they are all | 109 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); | 110 scheduling_changed_callback_.Run(true); |
| 136 } | |
| 137 } else { | 111 } else { |
| 138 ++unscheduled_count_; | 112 ++unscheduled_count_; |
| 139 if (unscheduled_count_ == 1) { | 113 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 | |
| 154 if (!scheduling_changed_callback_.is_null()) | |
| 155 scheduling_changed_callback_.Run(false); | 114 scheduling_changed_callback_.Run(false); |
| 156 } | |
| 157 } | 115 } |
| 116 DCHECK_GE(unscheduled_count_, 0); | |
| 158 } | 117 } |
| 159 | 118 |
| 160 bool GpuScheduler::IsScheduled() { | 119 bool GpuScheduler::IsScheduled() { |
| 161 return unscheduled_count_ == 0; | 120 return unscheduled_count_ == 0; |
| 162 } | 121 } |
| 163 | 122 |
| 164 bool GpuScheduler::HasMoreWork() { | 123 bool GpuScheduler::HasMoreWork() { |
| 165 return (decoder_ && decoder_->ProcessPendingQueries(false)) || | 124 return (decoder_ && decoder_->ProcessPendingQueries(false)) || |
| 166 HasMoreIdleWork(); | 125 HasMoreIdleWork(); |
| 167 } | 126 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 bool GpuScheduler::HasMoreIdleWork() { | 191 bool GpuScheduler::HasMoreIdleWork() { |
| 233 return (decoder_ && decoder_->HasMoreIdleWork()); | 192 return (decoder_ && decoder_->HasMoreIdleWork()); |
| 234 } | 193 } |
| 235 | 194 |
| 236 void GpuScheduler::PerformIdleWork() { | 195 void GpuScheduler::PerformIdleWork() { |
| 237 if (!decoder_) | 196 if (!decoder_) |
| 238 return; | 197 return; |
| 239 decoder_->PerformIdleWork(); | 198 decoder_->PerformIdleWork(); |
| 240 } | 199 } |
| 241 | 200 |
| 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 | 201 } // namespace gpu |
| OLD | NEW |