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