| 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 // 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 "gpu/common/gpu_trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 | 10 |
| 11 namespace gpu { | 11 namespace gpu { |
| 12 | 12 |
| 13 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) | 13 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) |
| 14 : command_buffer_(command_buffer), | 14 : command_buffer_(command_buffer), |
| 15 entries_(NULL), | 15 entries_(NULL), |
| 16 total_entry_count_(0), | 16 total_entry_count_(0), |
| 17 usable_entry_count_(0), | 17 usable_entry_count_(0), |
| 18 token_(0), | 18 token_(0), |
| 19 last_token_read_(-1), | 19 last_token_read_(-1), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // space may not be available. | 116 // space may not be available. |
| 117 void CommandBufferHelper::WaitForAvailableEntries(int32 count) { | 117 void CommandBufferHelper::WaitForAvailableEntries(int32 count) { |
| 118 GPU_CHECK(count < usable_entry_count_); | 118 GPU_CHECK(count < usable_entry_count_); |
| 119 if (put_ + count > usable_entry_count_) { | 119 if (put_ + count > usable_entry_count_) { |
| 120 // There's not enough room between the current put and the end of the | 120 // There's not enough room between the current put and the end of the |
| 121 // buffer, so we need to wrap. We will add a jump back to the start, but we | 121 // buffer, so we need to wrap. We will add a jump back to the start, but we |
| 122 // need to make sure get wraps first, actually that get is 1 or more (since | 122 // need to make sure get wraps first, actually that get is 1 or more (since |
| 123 // put will wrap to 0 after we add the jump). | 123 // put will wrap to 0 after we add the jump). |
| 124 GPU_DCHECK_LE(1, put_); | 124 GPU_DCHECK_LE(1, put_); |
| 125 if (get_ > put_ || get_ == 0) { | 125 if (get_ > put_ || get_ == 0) { |
| 126 GPU_TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForAvailableEntries"); | 126 TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForAvailableEntries"); |
| 127 while (get_ > put_ || get_ == 0) { | 127 while (get_ > put_ || get_ == 0) { |
| 128 // Do not loop forever if the flush fails, meaning the command buffer | 128 // Do not loop forever if the flush fails, meaning the command buffer |
| 129 // reader has shutdown. | 129 // reader has shutdown. |
| 130 if (!FlushSync()) | 130 if (!FlushSync()) |
| 131 return; | 131 return; |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 // Insert a jump back to the beginning. | 134 // Insert a jump back to the beginning. |
| 135 cmd::Jump::Set(&entries_[put_], 0); | 135 cmd::Jump::Set(&entries_[put_], 0); |
| 136 put_ = 0; | 136 put_ = 0; |
| 137 } | 137 } |
| 138 if (AvailableEntries() < count) { | 138 if (AvailableEntries() < count) { |
| 139 GPU_TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForAvailableEntries1"); | 139 TRACE_EVENT0("gpu", "CommandBufferHelper::WaitForAvailableEntries1"); |
| 140 while (AvailableEntries() < count) { | 140 while (AvailableEntries() < count) { |
| 141 // Do not loop forever if the flush fails, meaning the command buffer | 141 // Do not loop forever if the flush fails, meaning the command buffer |
| 142 // reader has shutdown. | 142 // reader has shutdown. |
| 143 if (!FlushSync()) | 143 if (!FlushSync()) |
| 144 return; | 144 return; |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 // Force a flush if the buffer is getting half full, or even earlier if the | 147 // Force a flush if the buffer is getting half full, or even earlier if the |
| 148 // reader is known to be idle. | 148 // reader is known to be idle. |
| 149 int32 pending = | 149 int32 pending = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 171 SynchronizeState(state); | 171 SynchronizeState(state); |
| 172 return static_cast<error::Error>(state.error); | 172 return static_cast<error::Error>(state.error); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void CommandBufferHelper::SynchronizeState(CommandBuffer::State state) { | 175 void CommandBufferHelper::SynchronizeState(CommandBuffer::State state) { |
| 176 get_ = state.get_offset; | 176 get_ = state.get_offset; |
| 177 last_token_read_ = state.token; | 177 last_token_read_ = state.token; |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace gpu | 180 } // namespace gpu |
| OLD | NEW |