| 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 command buffer helper class. | 5 // This file contains the command buffer helper class. |
| 6 | 6 |
| 7 #ifndef GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ | 7 #ifndef GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ |
| 8 #define GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ | 8 #define GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ |
| 9 | 9 |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // shutdown. | 75 // shutdown. |
| 76 int32 InsertToken(); | 76 int32 InsertToken(); |
| 77 | 77 |
| 78 // Waits until the token of a particular value has passed through the command | 78 // Waits until the token of a particular value has passed through the command |
| 79 // stream (i.e. commands inserted before that token have been executed). | 79 // stream (i.e. commands inserted before that token have been executed). |
| 80 // NOTE: This will call Flush if it needs to block. | 80 // NOTE: This will call Flush if it needs to block. |
| 81 // Parameters: | 81 // Parameters: |
| 82 // the value of the token to wait for. | 82 // the value of the token to wait for. |
| 83 void WaitForToken(int32 token); | 83 void WaitForToken(int32 token); |
| 84 | 84 |
| 85 // Inserts a yield command, signaling the scheduler that this is a good point | |
| 86 // to update the state and schedule other command buffers. This is | |
| 87 // particularly useful after inserting a token that will be waited on. | |
| 88 void YieldScheduler(); | |
| 89 | |
| 90 // Waits for a certain amount of space to be available. Returns address | 85 // Waits for a certain amount of space to be available. Returns address |
| 91 // of space. | 86 // of space. |
| 92 CommandBufferEntry* GetSpace(uint32 entries); | 87 CommandBufferEntry* GetSpace(uint32 entries); |
| 93 | 88 |
| 94 // Typed version of GetSpace. Gets enough room for the given type and returns | 89 // Typed version of GetSpace. Gets enough room for the given type and returns |
| 95 // a reference to it. | 90 // a reference to it. |
| 96 template <typename T> | 91 template <typename T> |
| 97 T& GetCmdSpace() { | 92 T& GetCmdSpace() { |
| 98 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); | 93 COMPILE_ASSERT(T::kArgFlags == cmd::kFixed, Cmd_kArgFlags_not_kFixed); |
| 99 uint32 space_needed = ComputeNumEntries(sizeof(T)); | 94 uint32 space_needed = ComputeNumEntries(sizeof(T)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 113 // Typed version of GetSpace for immediate commands. | 108 // Typed version of GetSpace for immediate commands. |
| 114 template <typename T> | 109 template <typename T> |
| 115 T& GetImmediateCmdSpaceTotalSize(size_t total_space) { | 110 T& GetImmediateCmdSpaceTotalSize(size_t total_space) { |
| 116 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); | 111 COMPILE_ASSERT(T::kArgFlags == cmd::kAtLeastN, Cmd_kArgFlags_not_kAtLeastN); |
| 117 uint32 space_needed = ComputeNumEntries(total_space); | 112 uint32 space_needed = ComputeNumEntries(total_space); |
| 118 void* data = GetSpace(space_needed); | 113 void* data = GetSpace(space_needed); |
| 119 return *reinterpret_cast<T*>(data); | 114 return *reinterpret_cast<T*>(data); |
| 120 } | 115 } |
| 121 | 116 |
| 122 int32 last_token_read() const { | 117 int32 last_token_read() const { |
| 123 return last_token_read_; | 118 return command_buffer_->GetLastState().token; |
| 119 } |
| 120 |
| 121 int32 get_offset() const { |
| 122 return command_buffer_->GetLastState().get_offset; |
| 124 } | 123 } |
| 125 | 124 |
| 126 error::Error GetError(); | 125 error::Error GetError(); |
| 127 | 126 |
| 128 // Common Commands | 127 // Common Commands |
| 129 void Noop(uint32 skip_count) { | 128 void Noop(uint32 skip_count) { |
| 130 cmd::Noop& cmd = GetImmediateCmdSpace<cmd::Noop>( | 129 cmd::Noop& cmd = GetImmediateCmdSpace<cmd::Noop>( |
| 131 skip_count * sizeof(CommandBufferEntry)); | 130 skip_count * sizeof(CommandBufferEntry)); |
| 132 cmd.Init(skip_count); | 131 cmd.Init(skip_count); |
| 133 } | 132 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 CommandBuffer* command_buffer() const { | 212 CommandBuffer* command_buffer() const { |
| 214 return command_buffer_; | 213 return command_buffer_; |
| 215 } | 214 } |
| 216 | 215 |
| 217 private: | 216 private: |
| 218 // Waits until get changes, updating the value of get_. | 217 // Waits until get changes, updating the value of get_. |
| 219 void WaitForGetChange(); | 218 void WaitForGetChange(); |
| 220 | 219 |
| 221 // Returns the number of available entries (they may not be contiguous). | 220 // Returns the number of available entries (they may not be contiguous). |
| 222 int32 AvailableEntries() { | 221 int32 AvailableEntries() { |
| 223 return (get_ - put_ - 1 + usable_entry_count_) % usable_entry_count_; | 222 return (get_offset() - put_ - 1 + usable_entry_count_) % |
| 223 usable_entry_count_; |
| 224 } | 224 } |
| 225 | 225 |
| 226 // Synchronize with current service state. | |
| 227 void SynchronizeState(const CommandBuffer::State& state); | |
| 228 | |
| 229 CommandBuffer* command_buffer_; | 226 CommandBuffer* command_buffer_; |
| 230 Buffer ring_buffer_; | 227 Buffer ring_buffer_; |
| 231 CommandBufferEntry *entries_; | 228 CommandBufferEntry *entries_; |
| 232 int32 total_entry_count_; // the total number of entries | 229 int32 total_entry_count_; // the total number of entries |
| 233 int32 usable_entry_count_; // the usable number (ie, minus space for jump) | 230 int32 usable_entry_count_; // the usable number (ie, minus space for jump) |
| 234 int32 token_; | 231 int32 token_; |
| 235 int32 last_token_read_; | |
| 236 int32 get_; | |
| 237 int32 put_; | 232 int32 put_; |
| 238 int32 last_put_sent_; | 233 int32 last_put_sent_; |
| 239 | 234 |
| 240 friend class CommandBufferHelperTest; | 235 friend class CommandBufferHelperTest; |
| 241 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); | 236 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); |
| 242 }; | 237 }; |
| 243 | 238 |
| 244 } // namespace gpu | 239 } // namespace gpu |
| 245 | 240 |
| 246 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ | 241 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ |
| OLD | NEW |