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 "../client/cmd_buffer_helper.h" | 7 #include "../client/cmd_buffer_helper.h" |
8 #include "../common/command_buffer.h" | 8 #include "../common/command_buffer.h" |
9 #include "../common/trace_event.h" | 9 #include "../common/trace_event.h" |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 ring_buffer_size_(0), | 21 ring_buffer_size_(0), |
22 entries_(NULL), | 22 entries_(NULL), |
23 total_entry_count_(0), | 23 total_entry_count_(0), |
24 usable_entry_count_(0), | 24 usable_entry_count_(0), |
25 token_(0), | 25 token_(0), |
26 put_(0), | 26 put_(0), |
27 last_put_sent_(0), | 27 last_put_sent_(0), |
28 commands_issued_(0), | 28 commands_issued_(0), |
29 usable_(true), | 29 usable_(true), |
30 context_lost_(false), | 30 context_lost_(false), |
| 31 flush_automatically_(true), |
31 last_flush_time_(0) { | 32 last_flush_time_(0) { |
32 } | 33 } |
33 | 34 |
| 35 void CommandBufferHelper::SetAutomaticFlushes(bool enabled) { |
| 36 flush_automatically_ = enabled; |
| 37 } |
| 38 |
34 bool CommandBufferHelper::IsContextLost() { | 39 bool CommandBufferHelper::IsContextLost() { |
35 if (!context_lost_) { | 40 if (!context_lost_) { |
36 context_lost_ = error::IsError(command_buffer()->GetLastError()); | 41 context_lost_ = error::IsError(command_buffer()->GetLastError()); |
37 } | 42 } |
38 return context_lost_; | 43 return context_lost_; |
39 } | 44 } |
40 | 45 |
41 bool CommandBufferHelper::AllocateRingBuffer() { | 46 bool CommandBufferHelper::AllocateRingBuffer() { |
42 if (!usable()) { | 47 if (!usable()) { |
43 return false; | 48 return false; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 239 } |
235 } | 240 } |
236 // Force a flush if the buffer is getting half full, or even earlier if the | 241 // Force a flush if the buffer is getting half full, or even earlier if the |
237 // reader is known to be idle. | 242 // reader is known to be idle. |
238 int32 pending = | 243 int32 pending = |
239 (put_ + usable_entry_count_ - last_put_sent_) % usable_entry_count_; | 244 (put_ + usable_entry_count_ - last_put_sent_) % usable_entry_count_; |
240 int32 limit = usable_entry_count_ / | 245 int32 limit = usable_entry_count_ / |
241 ((get_offset() == last_put_sent_) ? 16 : 2); | 246 ((get_offset() == last_put_sent_) ? 16 : 2); |
242 if (pending > limit) { | 247 if (pending > limit) { |
243 Flush(); | 248 Flush(); |
244 } else if (commands_issued_ % kCommandsPerFlushCheck == 0) { | 249 } else if (flush_automatically_ && |
245 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 250 (commands_issued_ % kCommandsPerFlushCheck == 0)) { |
| 251 #if !defined(OS_ANDROID) |
246 // Allow this command buffer to be pre-empted by another if a "reasonable" | 252 // Allow this command buffer to be pre-empted by another if a "reasonable" |
247 // amount of work has been done. On highend machines, this reduces the | 253 // amount of work has been done. On highend machines, this reduces the |
248 // latency of GPU commands. However, on Android, this can cause the | 254 // latency of GPU commands. However, on Android, this can cause the |
249 // kernel to thrash between generating GPU commands and executing them. | 255 // kernel to thrash between generating GPU commands and executing them. |
250 clock_t current_time = clock(); | 256 clock_t current_time = clock(); |
251 if (current_time - last_flush_time_ > kFlushDelay * CLOCKS_PER_SEC) | 257 if (current_time - last_flush_time_ > kFlushDelay * CLOCKS_PER_SEC) |
252 Flush(); | 258 Flush(); |
253 #endif | 259 #endif |
254 } | 260 } |
255 } | 261 } |
(...skipping 15 matching lines...) Expand all Loading... |
271 } | 277 } |
272 return space; | 278 return space; |
273 } | 279 } |
274 | 280 |
275 error::Error CommandBufferHelper::GetError() { | 281 error::Error CommandBufferHelper::GetError() { |
276 CommandBuffer::State state = command_buffer_->GetState(); | 282 CommandBuffer::State state = command_buffer_->GetState(); |
277 return static_cast<error::Error>(state.error); | 283 return static_cast<error::Error>(state.error); |
278 } | 284 } |
279 | 285 |
280 } // namespace gpu | 286 } // namespace gpu |
OLD | NEW |