| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 | 32 |
| 33 // This file contains the command buffer helper class. | 33 // This file contains the command buffer helper class. |
| 34 | 34 |
| 35 #ifndef GPU_COMMAND_BUFFER_CLIENT_CROSS_CMD_BUFFER_HELPER_H_ | 35 #ifndef GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ |
| 36 #define GPU_COMMAND_BUFFER_CLIENT_CROSS_CMD_BUFFER_HELPER_H_ | 36 #define GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ |
| 37 | 37 |
| 38 #include "gpu/command_buffer/common/logging.h" | 38 #include "gpu/command_buffer/common/logging.h" |
| 39 #include "gpu/command_buffer/common/constants.h" | 39 #include "gpu/command_buffer/common/constants.h" |
| 40 #include "gpu/command_buffer/common/cmd_buffer_common.h" | 40 #include "gpu/command_buffer/common/cmd_buffer_common.h" |
| 41 #include "gpu/command_buffer/common/command_buffer.h" | 41 #include "gpu/command_buffer/common/command_buffer.h" |
| 42 | 42 |
| 43 namespace command_buffer { | 43 namespace gpu { |
| 44 | 44 |
| 45 // Command buffer helper class. This class simplifies ring buffer management: | 45 // Command buffer helper class. This class simplifies ring buffer management: |
| 46 // it will allocate the buffer, give it to the buffer interface, and let the | 46 // it will allocate the buffer, give it to the buffer interface, and let the |
| 47 // user add commands to it, while taking care of the synchronization (put and | 47 // user add commands to it, while taking care of the synchronization (put and |
| 48 // get). It also provides a way to ensure commands have been executed, through | 48 // get). It also provides a way to ensure commands have been executed, through |
| 49 // the token mechanism: | 49 // the token mechanism: |
| 50 // | 50 // |
| 51 // helper.AddCommand(...); | 51 // helper.AddCommand(...); |
| 52 // helper.AddCommand(...); | 52 // helper.AddCommand(...); |
| 53 // int32 token = helper.InsertToken(); | 53 // int32 token = helper.InsertToken(); |
| 54 // helper.AddCommand(...); | 54 // helper.AddCommand(...); |
| 55 // helper.AddCommand(...); | 55 // helper.AddCommand(...); |
| 56 // [...] | 56 // [...] |
| 57 // | 57 // |
| 58 // helper.WaitForToken(token); // this doesn't return until the first two | 58 // helper.WaitForToken(token); // this doesn't return until the first two |
| 59 // // commands have been executed. | 59 // // commands have been executed. |
| 60 class CommandBufferHelper { | 60 class CommandBufferHelper { |
| 61 public: | 61 public: |
| 62 explicit CommandBufferHelper(command_buffer::CommandBuffer* command_buffer); | 62 explicit CommandBufferHelper(gpu::CommandBuffer* command_buffer); |
| 63 virtual ~CommandBufferHelper(); | 63 virtual ~CommandBufferHelper(); |
| 64 | 64 |
| 65 bool Initialize(); | 65 bool Initialize(); |
| 66 | 66 |
| 67 // Flushes the commands, setting the put pointer to let the buffer interface | 67 // Flushes the commands, setting the put pointer to let the buffer interface |
| 68 // know that new commands have been added. After a flush returns, the command | 68 // know that new commands have been added. After a flush returns, the command |
| 69 // buffer service is aware of all pending commands and it is guaranteed to | 69 // buffer service is aware of all pending commands and it is guaranteed to |
| 70 // have made some progress in processing them. Returns whether the flush was | 70 // have made some progress in processing them. Returns whether the flush was |
| 71 // successful. The flush will fail if the command buffer service has | 71 // successful. The flush will fail if the command buffer service has |
| 72 // disconnected. | 72 // disconnected. |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 191 |
| 192 private: | 192 private: |
| 193 // Waits until get changes, updating the value of get_. | 193 // Waits until get changes, updating the value of get_. |
| 194 void WaitForGetChange(); | 194 void WaitForGetChange(); |
| 195 | 195 |
| 196 // Returns the number of available entries (they may not be contiguous). | 196 // Returns the number of available entries (they may not be contiguous). |
| 197 int32 AvailableEntries() { | 197 int32 AvailableEntries() { |
| 198 return (get_ - put_ - 1 + entry_count_) % entry_count_; | 198 return (get_ - put_ - 1 + entry_count_) % entry_count_; |
| 199 } | 199 } |
| 200 | 200 |
| 201 command_buffer::CommandBuffer* command_buffer_; | 201 gpu::CommandBuffer* command_buffer_; |
| 202 ::base::SharedMemory* ring_buffer_; | 202 ::base::SharedMemory* ring_buffer_; |
| 203 CommandBufferEntry *entries_; | 203 CommandBufferEntry *entries_; |
| 204 int32 entry_count_; | 204 int32 entry_count_; |
| 205 int32 token_; | 205 int32 token_; |
| 206 int32 last_token_read_; | 206 int32 last_token_read_; |
| 207 int32 get_; | 207 int32 get_; |
| 208 int32 put_; | 208 int32 put_; |
| 209 | 209 |
| 210 friend class CommandBufferHelperTest; | 210 friend class CommandBufferHelperTest; |
| 211 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); | 211 DISALLOW_COPY_AND_ASSIGN(CommandBufferHelper); |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 } // namespace command_buffer | 214 } // namespace gpu |
| 215 | 215 |
| 216 #endif // GPU_COMMAND_BUFFER_CLIENT_CROSS_CMD_BUFFER_HELPER_H_ | 216 #endif // GPU_COMMAND_BUFFER_CLIENT_CMD_BUFFER_HELPER_H_ |
| OLD | NEW |