| 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 "../common/trace_event.h" | 9 #include "../common/trace_event.h" |
| 10 | 10 |
| 11 namespace gpu { | 11 namespace gpu { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 const int kCommandsPerFlushCheck = 100; | 14 const int kCommandsPerFlushCheck = 100; |
| 15 const double kFlushDelay = 1.0 / (5.0 * 60.0); | 15 const double kFlushDelay = 1.0 / (5.0 * 60.0); |
| 16 } | 16 } |
| 17 | 17 |
| 18 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) | 18 CommandBufferHelper::CommandBufferHelper(CommandBuffer* command_buffer) |
| 19 : command_buffer_(command_buffer), | 19 : command_buffer_(command_buffer), |
| 20 ring_buffer_id_(-1), | |
| 21 ring_buffer_size_(0), | |
| 22 entries_(NULL), | 20 entries_(NULL), |
| 23 total_entry_count_(0), | 21 total_entry_count_(0), |
| 24 usable_entry_count_(0), | 22 usable_entry_count_(0), |
| 25 token_(0), | 23 token_(0), |
| 26 put_(0), | 24 put_(0), |
| 27 last_put_sent_(0), | 25 last_put_sent_(0), |
| 28 commands_issued_(0), | 26 commands_issued_(0), |
| 29 last_flush_time_(0) { | 27 last_flush_time_(0) { |
| 30 } | 28 } |
| 31 | 29 |
| 32 bool CommandBufferHelper::AllocateRingBuffer() { | 30 bool CommandBufferHelper::Initialize(int32 ring_buffer_size) { |
| 33 int32 id = command_buffer_->CreateTransferBuffer(ring_buffer_size_, -1); | 31 ring_buffer_ = command_buffer_->GetRingBuffer(); |
| 34 if (id < 0) { | |
| 35 return false; | |
| 36 } | |
| 37 | |
| 38 ring_buffer_ = command_buffer_->GetTransferBuffer(id); | |
| 39 if (!ring_buffer_.ptr) | 32 if (!ring_buffer_.ptr) |
| 40 return false; | 33 return false; |
| 41 | 34 |
| 42 ring_buffer_id_ = id; | |
| 43 command_buffer_->SetGetBuffer(id); | |
| 44 | |
| 45 // TODO(gman): Do we really need to call GetState here? We know get & put = 0 | |
| 46 // Also do we need to check state.num_entries? | |
| 47 CommandBuffer::State state = command_buffer_->GetState(); | 35 CommandBuffer::State state = command_buffer_->GetState(); |
| 48 entries_ = static_cast<CommandBufferEntry*>(ring_buffer_.ptr); | 36 entries_ = static_cast<CommandBufferEntry*>(ring_buffer_.ptr); |
| 49 int32 num_ring_buffer_entries = | 37 int32 num_ring_buffer_entries = ring_buffer_size / sizeof(CommandBufferEntry); |
| 50 ring_buffer_size_ / sizeof(CommandBufferEntry); | |
| 51 if (num_ring_buffer_entries > state.num_entries) { | 38 if (num_ring_buffer_entries > state.num_entries) { |
| 52 return false; | 39 return false; |
| 53 } | 40 } |
| 54 | 41 |
| 55 const int32 kJumpEntries = | 42 const int32 kJumpEntries = |
| 56 sizeof(cmd::Jump) / sizeof(*entries_); // NOLINT | 43 sizeof(cmd::Jump) / sizeof(*entries_); // NOLINT |
| 57 | 44 |
| 58 total_entry_count_ = num_ring_buffer_entries; | 45 total_entry_count_ = num_ring_buffer_entries; |
| 59 usable_entry_count_ = total_entry_count_ - kJumpEntries; | 46 usable_entry_count_ = total_entry_count_ - kJumpEntries; |
| 60 put_ = state.put_offset; | 47 put_ = state.put_offset; |
| 61 return true; | 48 return true; |
| 62 } | 49 } |
| 63 | 50 |
| 64 bool CommandBufferHelper::Initialize(int32 ring_buffer_size) { | |
| 65 ring_buffer_size_ = ring_buffer_size; | |
| 66 return AllocateRingBuffer(); | |
| 67 } | |
| 68 | |
| 69 CommandBufferHelper::~CommandBufferHelper() { | 51 CommandBufferHelper::~CommandBufferHelper() { |
| 70 } | 52 } |
| 71 | 53 |
| 72 bool CommandBufferHelper::FlushSync() { | 54 bool CommandBufferHelper::FlushSync() { |
| 73 last_flush_time_ = clock(); | 55 last_flush_time_ = clock(); |
| 74 last_put_sent_ = put_; | 56 last_put_sent_ = put_; |
| 75 CommandBuffer::State state = command_buffer_->FlushSync(put_, get_offset()); | 57 CommandBuffer::State state = command_buffer_->FlushSync(put_, get_offset()); |
| 76 return state.error == error::kNoError; | 58 return state.error == error::kNoError; |
| 77 } | 59 } |
| 78 | 60 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 } | 181 } |
| 200 return space; | 182 return space; |
| 201 } | 183 } |
| 202 | 184 |
| 203 error::Error CommandBufferHelper::GetError() { | 185 error::Error CommandBufferHelper::GetError() { |
| 204 CommandBuffer::State state = command_buffer_->GetState(); | 186 CommandBuffer::State state = command_buffer_->GetState(); |
| 205 return static_cast<error::Error>(state.error); | 187 return static_cast<error::Error>(state.error); |
| 206 } | 188 } |
| 207 | 189 |
| 208 } // namespace gpu | 190 } // namespace gpu |
| OLD | NEW |