| 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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 DCHECK_GE(unscheduled_count_, 0); | 130 DCHECK_GE(unscheduled_count_, 0); |
| 131 | 131 |
| 132 if (unscheduled_count_ == 0) { | 132 if (unscheduled_count_ == 0) { |
| 133 TRACE_EVENT_ASYNC_END1("gpu", "ProcessingSwap", this, | 133 TRACE_EVENT_ASYNC_END1("gpu", "ProcessingSwap", this, |
| 134 "GpuScheduler", this); | 134 "GpuScheduler", this); |
| 135 // When the scheduler transitions from the unscheduled to the scheduled | 135 // When the scheduler transitions from the unscheduled to the scheduled |
| 136 // state, cancel the task that would reschedule it after a timeout. | 136 // state, cancel the task that would reschedule it after a timeout. |
| 137 reschedule_task_factory_.InvalidateWeakPtrs(); | 137 reschedule_task_factory_.InvalidateWeakPtrs(); |
| 138 | 138 |
| 139 if (!scheduled_callback_.is_null()) | 139 if (!scheduling_changed_callback_.is_null()) |
| 140 scheduled_callback_.Run(); | 140 scheduling_changed_callback_.Run(true); |
| 141 } | 141 } |
| 142 } else { | 142 } else { |
| 143 if (unscheduled_count_ == 0) { | 143 ++unscheduled_count_; |
| 144 if (unscheduled_count_ == 1) { |
| 144 TRACE_EVENT_ASYNC_BEGIN1("gpu", "ProcessingSwap", this, | 145 TRACE_EVENT_ASYNC_BEGIN1("gpu", "ProcessingSwap", this, |
| 145 "GpuScheduler", this); | 146 "GpuScheduler", this); |
| 146 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
| 147 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 148 if (base::win::GetVersion() < base::win::VERSION_VISTA) { |
| 148 // When the scheduler transitions from scheduled to unscheduled, post a | 149 // When the scheduler transitions from scheduled to unscheduled, post a |
| 149 // delayed task that it will force it back into a scheduled state after | 150 // delayed task that it will force it back into a scheduled state after |
| 150 // a timeout. This should only be necessary on pre-Vista. | 151 // a timeout. This should only be necessary on pre-Vista. |
| 151 MessageLoop::current()->PostDelayedTask( | 152 MessageLoop::current()->PostDelayedTask( |
| 152 FROM_HERE, | 153 FROM_HERE, |
| 153 base::Bind(&GpuScheduler::RescheduleTimeOut, | 154 base::Bind(&GpuScheduler::RescheduleTimeOut, |
| 154 reschedule_task_factory_.GetWeakPtr()), | 155 reschedule_task_factory_.GetWeakPtr()), |
| 155 base::TimeDelta::FromMilliseconds(kRescheduleTimeOutDelay)); | 156 base::TimeDelta::FromMilliseconds(kRescheduleTimeOutDelay)); |
| 156 } | 157 } |
| 157 #endif | 158 #endif |
| 159 if (!scheduling_changed_callback_.is_null()) |
| 160 scheduling_changed_callback_.Run(false); |
| 158 } | 161 } |
| 159 | |
| 160 ++unscheduled_count_; | |
| 161 } | 162 } |
| 162 } | 163 } |
| 163 | 164 |
| 164 bool GpuScheduler::IsScheduled() { | 165 bool GpuScheduler::IsScheduled() { |
| 165 return unscheduled_count_ == 0; | 166 return unscheduled_count_ == 0; |
| 166 } | 167 } |
| 167 | 168 |
| 168 bool GpuScheduler::HasMoreWork() { | 169 bool GpuScheduler::HasMoreWork() { |
| 169 return !unschedule_fences_.empty() || | 170 return !unschedule_fences_.empty() || |
| 170 (decoder_ && decoder_->ProcessPendingQueries()); | 171 (decoder_ && decoder_->ProcessPendingQueries()); |
| 171 } | 172 } |
| 172 | 173 |
| 173 void GpuScheduler::SetScheduledCallback( | 174 void GpuScheduler::SetSchedulingChangedCallback( |
| 174 const base::Closure& scheduled_callback) { | 175 const SchedulingChangedCallback& callback) { |
| 175 scheduled_callback_ = scheduled_callback; | 176 scheduling_changed_callback_ = callback; |
| 176 } | 177 } |
| 177 | 178 |
| 178 Buffer GpuScheduler::GetSharedMemoryBuffer(int32 shm_id) { | 179 Buffer GpuScheduler::GetSharedMemoryBuffer(int32 shm_id) { |
| 179 return command_buffer_->GetTransferBuffer(shm_id); | 180 return command_buffer_->GetTransferBuffer(shm_id); |
| 180 } | 181 } |
| 181 | 182 |
| 182 void GpuScheduler::set_token(int32 token) { | 183 void GpuScheduler::set_token(int32 token) { |
| 183 command_buffer_->SetToken(token); | 184 command_buffer_->SetToken(token); |
| 184 } | 185 } |
| 185 | 186 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 } | 281 } |
| 281 | 282 |
| 282 GpuScheduler::UnscheduleFence::UnscheduleFence( | 283 GpuScheduler::UnscheduleFence::UnscheduleFence( |
| 283 gfx::GLFence* fence_, base::Closure task_): fence(fence_), task(task_) { | 284 gfx::GLFence* fence_, base::Closure task_): fence(fence_), task(task_) { |
| 284 } | 285 } |
| 285 | 286 |
| 286 GpuScheduler::UnscheduleFence::~UnscheduleFence() { | 287 GpuScheduler::UnscheduleFence::~UnscheduleFence() { |
| 287 } | 288 } |
| 288 | 289 |
| 289 } // namespace gpu | 290 } // namespace gpu |
| OLD | NEW |