| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | |
| 9 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 11 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 12 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 13 #include "base/time.h" | 12 #include "base/time.h" |
| 14 #include "ui/gfx/gl/gl_context.h" | 13 #include "ui/gfx/gl/gl_context.h" |
| 15 #include "ui/gfx/gl/gl_bindings.h" | 14 #include "ui/gfx/gl/gl_bindings.h" |
| 16 #include "ui/gfx/gl/gl_surface.h" | 15 #include "ui/gfx/gl/gl_surface.h" |
| 17 #include "ui/gfx/gl/gl_switches.h" | 16 #include "ui/gfx/gl/gl_switches.h" |
| 18 | 17 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // to needlessly complex update logic. It should be possible to simply | 103 // to needlessly complex update logic. It should be possible to simply |
| 105 // share the state across all of them. | 104 // share the state across all of them. |
| 106 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); | 105 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); |
| 107 | 106 |
| 108 if (error::IsError(error)) { | 107 if (error::IsError(error)) { |
| 109 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); | 108 command_buffer_->SetContextLostReason(decoder_->GetContextLostReason()); |
| 110 command_buffer_->SetParseError(error); | 109 command_buffer_->SetParseError(error); |
| 111 return; | 110 return; |
| 112 } | 111 } |
| 113 | 112 |
| 114 if (command_processed_callback_.get()) | 113 if (!command_processed_callback_.is_null()) |
| 115 command_processed_callback_->Run(); | 114 command_processed_callback_.Run(); |
| 116 | 115 |
| 117 if (unscheduled_count_ > 0) | 116 if (unscheduled_count_ > 0) |
| 118 return; | 117 return; |
| 119 } | 118 } |
| 120 } | 119 } |
| 121 | 120 |
| 122 void GpuScheduler::SetScheduled(bool scheduled) { | 121 void GpuScheduler::SetScheduled(bool scheduled) { |
| 123 TRACE_EVENT2("gpu", "GpuScheduler:SetScheduled", "this", this, | 122 TRACE_EVENT2("gpu", "GpuScheduler:SetScheduled", "this", this, |
| 124 "new unscheduled_count_", | 123 "new unscheduled_count_", |
| 125 unscheduled_count_ + (scheduled? -1 : 1)); | 124 unscheduled_count_ + (scheduled? -1 : 1)); |
| 126 if (scheduled) { | 125 if (scheduled) { |
| 127 --unscheduled_count_; | 126 --unscheduled_count_; |
| 128 DCHECK_GE(unscheduled_count_, 0); | 127 DCHECK_GE(unscheduled_count_, 0); |
| 129 | 128 |
| 130 if (unscheduled_count_ == 0 && scheduled_callback_.get()) | 129 if (unscheduled_count_ == 0 && !scheduled_callback_.is_null()) |
| 131 scheduled_callback_->Run(); | 130 scheduled_callback_.Run(); |
| 132 } else { | 131 } else { |
| 133 ++unscheduled_count_; | 132 ++unscheduled_count_; |
| 134 } | 133 } |
| 135 } | 134 } |
| 136 | 135 |
| 137 bool GpuScheduler::IsScheduled() { | 136 bool GpuScheduler::IsScheduled() { |
| 138 return unscheduled_count_ == 0; | 137 return unscheduled_count_ == 0; |
| 139 } | 138 } |
| 140 | 139 |
| 141 void GpuScheduler::SetScheduledCallback(Callback0::Type* scheduled_callback) { | 140 void GpuScheduler::SetScheduledCallback( |
| 142 scheduled_callback_.reset(scheduled_callback); | 141 const base::Closure& scheduled_callback) { |
| 142 scheduled_callback_ = scheduled_callback; |
| 143 } | 143 } |
| 144 | 144 |
| 145 Buffer GpuScheduler::GetSharedMemoryBuffer(int32 shm_id) { | 145 Buffer GpuScheduler::GetSharedMemoryBuffer(int32 shm_id) { |
| 146 return command_buffer_->GetTransferBuffer(shm_id); | 146 return command_buffer_->GetTransferBuffer(shm_id); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void GpuScheduler::set_token(int32 token) { | 149 void GpuScheduler::set_token(int32 token) { |
| 150 command_buffer_->SetToken(token); | 150 command_buffer_->SetToken(token); |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool GpuScheduler::SetGetOffset(int32 offset) { | 153 bool GpuScheduler::SetGetOffset(int32 offset) { |
| 154 if (parser_->set_get(offset)) { | 154 if (parser_->set_get(offset)) { |
| 155 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); | 155 command_buffer_->SetGetOffset(static_cast<int32>(parser_->get())); |
| 156 return true; | 156 return true; |
| 157 } | 157 } |
| 158 return false; | 158 return false; |
| 159 } | 159 } |
| 160 | 160 |
| 161 int32 GpuScheduler::GetGetOffset() { | 161 int32 GpuScheduler::GetGetOffset() { |
| 162 return parser_->get(); | 162 return parser_->get(); |
| 163 } | 163 } |
| 164 | 164 |
| 165 void GpuScheduler::SetCommandProcessedCallback( | 165 void GpuScheduler::SetCommandProcessedCallback( |
| 166 Callback0::Type* callback) { | 166 const base::Closure& callback) { |
| 167 command_processed_callback_.reset(callback); | 167 command_processed_callback_ = callback; |
| 168 } | 168 } |
| 169 | 169 |
| 170 void GpuScheduler::DeferToFence(base::Closure task) { | 170 void GpuScheduler::DeferToFence(base::Closure task) { |
| 171 UnscheduleFence fence; | 171 UnscheduleFence fence; |
| 172 | 172 |
| 173 // What if either of these GL calls fails? TestFenceNV will return true and | 173 // What if either of these GL calls fails? TestFenceNV will return true and |
| 174 // PutChanged will treat the fence as having been crossed and thereby not | 174 // PutChanged will treat the fence as having been crossed and thereby not |
| 175 // poll indefinately. See spec: | 175 // poll indefinately. See spec: |
| 176 // http://www.opengl.org/registry/specs/NV/fence.txt | 176 // http://www.opengl.org/registry/specs/NV/fence.txt |
| 177 // | 177 // |
| (...skipping 15 matching lines...) Expand all Loading... |
| 193 unschedule_fences_.push(fence); | 193 unschedule_fences_.push(fence); |
| 194 } | 194 } |
| 195 | 195 |
| 196 GpuScheduler::UnscheduleFence::UnscheduleFence() : fence(0) { | 196 GpuScheduler::UnscheduleFence::UnscheduleFence() : fence(0) { |
| 197 } | 197 } |
| 198 | 198 |
| 199 GpuScheduler::UnscheduleFence::~UnscheduleFence() { | 199 GpuScheduler::UnscheduleFence::~UnscheduleFence() { |
| 200 } | 200 } |
| 201 | 201 |
| 202 } // namespace gpu | 202 } // namespace gpu |
| OLD | NEW |