| 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 // This file contains the implementation of the command buffer helper class. | 5 // This file contains the implementation of the command buffer helper class. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 7 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/time/time.h" |
| 10 #include "gpu/command_buffer/common/command_buffer.h" | 11 #include "gpu/command_buffer/common/command_buffer.h" |
| 11 #include "gpu/command_buffer/common/trace_event.h" | 12 #include "gpu/command_buffer/common/trace_event.h" |
| 12 | 13 |
| 13 namespace gpu { | 14 namespace gpu { |
| 14 | 15 |
| 15 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) | 16 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) |
| 16 : command_buffer_(command_buffer), | 17 : command_buffer_(command_buffer), |
| 17 ring_buffer_id_(-1), | 18 ring_buffer_id_(-1), |
| 18 ring_buffer_size_(0), | 19 ring_buffer_size_(0), |
| 19 entries_(NULL), | 20 entries_(NULL), |
| 20 total_entry_count_(0), | 21 total_entry_count_(0), |
| 21 immediate_entry_count_(0), | 22 immediate_entry_count_(0), |
| 22 token_(0), | 23 token_(0), |
| 23 put_(0), | 24 put_(0), |
| 24 last_put_sent_(0), | 25 last_put_sent_(0), |
| 25 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) | 26 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) |
| 26 commands_issued_(0), | 27 commands_issued_(0), |
| 27 #endif | 28 #endif |
| 28 usable_(true), | 29 usable_(true), |
| 29 context_lost_(false), | 30 context_lost_(false), |
| 30 flush_automatically_(true), | 31 flush_automatically_(true), |
| 31 last_flush_time_(0), | |
| 32 flush_generation_(0) { | 32 flush_generation_(0) { |
| 33 } | 33 } |
| 34 | 34 |
| 35 void CommandBufferHelper::SetAutomaticFlushes(bool enabled) { | 35 void CommandBufferHelper::SetAutomaticFlushes(bool enabled) { |
| 36 flush_automatically_ = enabled; | 36 flush_automatically_ = enabled; |
| 37 CalcImmediateEntries(0); | 37 CalcImmediateEntries(0); |
| 38 } | 38 } |
| 39 | 39 |
| 40 bool CommandBufferHelper::IsContextLost() { | 40 bool CommandBufferHelper::IsContextLost() { |
| 41 if (!context_lost_) { | 41 if (!context_lost_) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 command_buffer_->WaitForGetOffsetInRange(start, end); | 144 command_buffer_->WaitForGetOffsetInRange(start, end); |
| 145 return command_buffer_->GetLastError() == gpu::error::kNoError; | 145 return command_buffer_->GetLastError() == gpu::error::kNoError; |
| 146 } | 146 } |
| 147 | 147 |
| 148 void CommandBufferHelper::Flush() { | 148 void CommandBufferHelper::Flush() { |
| 149 // Wrap put_ before flush. | 149 // Wrap put_ before flush. |
| 150 if (put_ == total_entry_count_) | 150 if (put_ == total_entry_count_) |
| 151 put_ = 0; | 151 put_ = 0; |
| 152 | 152 |
| 153 if (usable() && last_put_sent_ != put_) { | 153 if (usable() && last_put_sent_ != put_) { |
| 154 last_flush_time_ = clock(); | 154 last_flush_time_ = base::TimeTicks::Now(); |
| 155 last_put_sent_ = put_; | 155 last_put_sent_ = put_; |
| 156 command_buffer_->Flush(put_); | 156 command_buffer_->Flush(put_); |
| 157 ++flush_generation_; | 157 ++flush_generation_; |
| 158 CalcImmediateEntries(0); | 158 CalcImmediateEntries(0); |
| 159 } | 159 } |
| 160 } | 160 } |
| 161 | 161 |
| 162 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) | 162 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) |
| 163 void CommandBufferHelper::PeriodicFlushCheck() { | 163 void CommandBufferHelper::PeriodicFlushCheck() { |
| 164 clock_t current_time = clock(); | 164 base::TimeTicks current_time = base::TimeTicks::Now(); |
| 165 if (current_time - last_flush_time_ > kPeriodicFlushDelay * CLOCKS_PER_SEC) | 165 if (current_time - last_flush_time_ > |
| 166 base::TimeDelta::FromMicroseconds(kPeriodicFlushDelayInMicroseconds)) { |
| 166 Flush(); | 167 Flush(); |
| 168 } |
| 167 } | 169 } |
| 168 #endif | 170 #endif |
| 169 | 171 |
| 170 // Calls Flush() and then waits until the buffer is empty. Break early if the | 172 // Calls Flush() and then waits until the buffer is empty. Break early if the |
| 171 // error is set. | 173 // error is set. |
| 172 bool CommandBufferHelper::Finish() { | 174 bool CommandBufferHelper::Finish() { |
| 173 TRACE_EVENT0("gpu", "CommandBufferHelper::Finish"); | 175 TRACE_EVENT0("gpu", "CommandBufferHelper::Finish"); |
| 174 if (!usable()) { | 176 if (!usable()) { |
| 175 return false; | 177 return false; |
| 176 } | 178 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 if (!WaitForGetOffsetInRange(put_ + count + 1, put_)) | 284 if (!WaitForGetOffsetInRange(put_ + count + 1, put_)) |
| 283 return; | 285 return; |
| 284 CalcImmediateEntries(count); | 286 CalcImmediateEntries(count); |
| 285 DCHECK_GE(immediate_entry_count_, count); | 287 DCHECK_GE(immediate_entry_count_, count); |
| 286 } | 288 } |
| 287 } | 289 } |
| 288 } | 290 } |
| 289 | 291 |
| 290 | 292 |
| 291 } // namespace gpu | 293 } // namespace gpu |
| OLD | NEW |