| 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 "base/time/time.h" |
| 11 #include "gpu/command_buffer/common/command_buffer.h" | 11 #include "gpu/command_buffer/common/command_buffer.h" |
| 12 #include "gpu/command_buffer/common/trace_event.h" | 12 #include "gpu/command_buffer/common/trace_event.h" |
| 13 | 13 |
| 14 namespace gpu { | 14 namespace gpu { |
| 15 | 15 |
| 16 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) | 16 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) |
| 17 : command_buffer_(command_buffer), | 17 : command_buffer_(command_buffer), |
| 18 ring_buffer_id_(-1), | 18 ring_buffer_id_(-1), |
| 19 ring_buffer_size_(0), | 19 ring_buffer_size_(0), |
| 20 entries_(NULL), | 20 entries_(NULL), |
| 21 total_entry_count_(0), | 21 total_entry_count_(0), |
| 22 immediate_entry_count_(0), | 22 immediate_entry_count_(0), |
| 23 token_(0), | 23 token_(0), |
| 24 put_(0), | 24 put_(0), |
| 25 last_put_sent_(0), | 25 last_put_sent_(0), |
| 26 safe_put_point_(0), |
| 26 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) | 27 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) |
| 27 commands_issued_(0), | 28 commands_issued_(0), |
| 28 #endif | 29 #endif |
| 29 usable_(true), | 30 usable_(true), |
| 30 context_lost_(false), | 31 context_lost_(false), |
| 31 flush_automatically_(true), | 32 flush_automatically_(true), |
| 32 flush_generation_(0) { | 33 flush_generation_(0) { |
| 33 } | 34 } |
| 34 | 35 |
| 35 void CommandBufferHelper::SetAutomaticFlushes(bool enabled) { | 36 void CommandBufferHelper::SetAutomaticFlushes(bool enabled) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 57 const int32 curr_get = get_offset(); | 58 const int32 curr_get = get_offset(); |
| 58 if (curr_get > put_) { | 59 if (curr_get > put_) { |
| 59 immediate_entry_count_ = curr_get - put_ - 1; | 60 immediate_entry_count_ = curr_get - put_ - 1; |
| 60 } else { | 61 } else { |
| 61 immediate_entry_count_ = | 62 immediate_entry_count_ = |
| 62 total_entry_count_ - put_ - (curr_get == 0 ? 1 : 0); | 63 total_entry_count_ - put_ - (curr_get == 0 ? 1 : 0); |
| 63 } | 64 } |
| 64 | 65 |
| 65 // Limit entry count to force early flushing. | 66 // Limit entry count to force early flushing. |
| 66 if (flush_automatically_) { | 67 if (flush_automatically_) { |
| 68 // Cache last_put_sent, as it may change via SafeFlush(). |
| 69 int32 last_put_sent = last_put_sent_; |
| 67 int32 limit = | 70 int32 limit = |
| 68 total_entry_count_ / | 71 total_entry_count_ / |
| 69 ((curr_get == last_put_sent_) ? kAutoFlushSmall : kAutoFlushBig); | 72 ((curr_get == last_put_sent) ? kAutoFlushSmall : kAutoFlushBig); |
| 70 | 73 |
| 71 int32 pending = | 74 int32 pending = |
| 72 (put_ + total_entry_count_ - last_put_sent_) % total_entry_count_; | 75 (put_ + total_entry_count_ - last_put_sent) % total_entry_count_; |
| 73 | 76 |
| 74 if (pending > 0 && pending >= limit) { | 77 if (pending > 0 && pending >= limit) { |
| 75 // Time to force flush. | 78 // Time to force flush. |
| 76 immediate_entry_count_ = 0; | 79 immediate_entry_count_ = 0; |
| 77 } else { | 80 } else { |
| 78 // Limit remaining entries, but not lower than waiting_count entries to | 81 // Limit remaining entries, but not lower than waiting_count entries to |
| 79 // prevent deadlock when command size is greater than the flush limit. | 82 // prevent deadlock when command size is greater than the flush limit. |
| 80 limit -= pending; | 83 limit -= pending; |
| 81 limit = limit < waiting_count ? waiting_count : limit; | 84 limit = limit < waiting_count ? waiting_count : limit; |
| 82 immediate_entry_count_ = | 85 immediate_entry_count_ = |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 142 |
| 140 bool CommandBufferHelper::WaitForGetOffsetInRange(int32 start, int32 end) { | 143 bool CommandBufferHelper::WaitForGetOffsetInRange(int32 start, int32 end) { |
| 141 if (!usable()) { | 144 if (!usable()) { |
| 142 return false; | 145 return false; |
| 143 } | 146 } |
| 144 command_buffer_->WaitForGetOffsetInRange(start, end); | 147 command_buffer_->WaitForGetOffsetInRange(start, end); |
| 145 return command_buffer_->GetLastError() == gpu::error::kNoError; | 148 return command_buffer_->GetLastError() == gpu::error::kNoError; |
| 146 } | 149 } |
| 147 | 150 |
| 148 void CommandBufferHelper::Flush() { | 151 void CommandBufferHelper::Flush() { |
| 152 base::AutoLock scoped_lock(flush_lock_); |
| 149 // Wrap put_ before flush. | 153 // Wrap put_ before flush. |
| 150 if (put_ == total_entry_count_) | 154 if (put_ == total_entry_count_) |
| 151 put_ = 0; | 155 put_ = 0; |
| 152 | 156 |
| 153 if (usable() && last_put_sent_ != put_) { | 157 if (usable() && last_put_sent_ != put_) { |
| 154 last_flush_time_ = base::TimeTicks::Now(); | 158 last_flush_time_ = base::TimeTicks::Now(); |
| 155 last_put_sent_ = put_; | 159 last_put_sent_ = put_; |
| 160 safe_put_point_ = put_; |
| 156 command_buffer_->Flush(put_); | 161 command_buffer_->Flush(put_); |
| 157 ++flush_generation_; | 162 ++flush_generation_; |
| 158 CalcImmediateEntries(0); | 163 CalcImmediateEntries(0); |
| 159 } | 164 } |
| 160 } | 165 } |
| 161 | 166 |
| 167 void CommandBufferHelper::SetSafeFlushPoint() { |
| 168 base::AutoLock scoped_lock(flush_lock_); |
| 169 safe_put_point_ = put_; |
| 170 if (safe_put_point_ == total_entry_count_) |
| 171 safe_put_point_ = 0; |
| 172 } |
| 173 |
| 174 void CommandBufferHelper::SafeFlush() { |
| 175 base::AutoLock scoped_lock(flush_lock_); |
| 176 if (usable() && last_put_sent_ != safe_put_point_) { |
| 177 last_flush_time_ = base::TimeTicks::Now(); |
| 178 last_put_sent_ = safe_put_point_; |
| 179 command_buffer_->Flush(safe_put_point_); |
| 180 //++flush_generation_; |
| 181 } |
| 182 } |
| 183 |
| 162 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) | 184 #if defined(CMD_HELPER_PERIODIC_FLUSH_CHECK) |
| 163 void CommandBufferHelper::PeriodicFlushCheck() { | 185 void CommandBufferHelper::PeriodicFlushCheck() { |
| 164 base::TimeTicks current_time = base::TimeTicks::Now(); | 186 base::TimeTicks current_time = base::TimeTicks::Now(); |
| 165 if (current_time - last_flush_time_ > | 187 if (current_time - last_flush_time_ > |
| 166 base::TimeDelta::FromMicroseconds(kPeriodicFlushDelayInMicroseconds)) { | 188 base::TimeDelta::FromMicroseconds(kPeriodicFlushDelayInMicroseconds)) { |
| 167 Flush(); | 189 Flush(); |
| 168 } | 190 } |
| 169 } | 191 } |
| 170 #endif | 192 #endif |
| 171 | 193 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 if (!WaitForGetOffsetInRange(put_ + count + 1, put_)) | 306 if (!WaitForGetOffsetInRange(put_ + count + 1, put_)) |
| 285 return; | 307 return; |
| 286 CalcImmediateEntries(count); | 308 CalcImmediateEntries(count); |
| 287 DCHECK_GE(immediate_entry_count_, count); | 309 DCHECK_GE(immediate_entry_count_, count); |
| 288 } | 310 } |
| 289 } | 311 } |
| 290 } | 312 } |
| 291 | 313 |
| 292 | 314 |
| 293 } // namespace gpu | 315 } // namespace gpu |
| OLD | NEW |