| 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 parser class. | 5 // This file contains the command parser class. |
| 6 | 6 |
| 7 #ifndef GPU_COMMAND_BUFFER_SERVICE_CMD_PARSER_H_ | 7 #ifndef GPU_COMMAND_BUFFER_SERVICE_CMD_PARSER_H_ |
| 8 #define GPU_COMMAND_BUFFER_SERVICE_CMD_PARSER_H_ | 8 #define GPU_COMMAND_BUFFER_SERVICE_CMD_PARSER_H_ |
| 9 | 9 |
| 10 #include "gpu/command_buffer/common/constants.h" | 10 #include "gpu/command_buffer/common/constants.h" |
| 11 #include "gpu/command_buffer/common/cmd_buffer_common.h" | 11 #include "gpu/command_buffer/common/cmd_buffer_common.h" |
| 12 | 12 |
| 13 namespace gpu { | 13 namespace gpu { |
| 14 | 14 |
| 15 class AsyncAPIInterface; | 15 class AsyncAPIInterface; |
| 16 | 16 |
| 17 // Command parser class. This class parses commands from a shared memory | 17 // Command parser class. This class parses commands from a shared memory |
| 18 // buffer, to implement some asynchronous RPC mechanism. | 18 // buffer, to implement some asynchronous RPC mechanism. |
| 19 class CommandParser { | 19 class CommandParser { |
| 20 public: | 20 public: |
| 21 CommandParser(void *shm_address, | 21 explicit CommandParser(AsyncAPIInterface* handler); |
| 22 size_t shm_size, | 22 |
| 23 ptrdiff_t offset, | 23 // Sets the buffer to read commands from. |
| 24 size_t size, | 24 void SetBuffer( |
| 25 CommandBufferOffset start_get, | 25 void* shm_address, |
| 26 AsyncAPIInterface *handler); | 26 size_t shm_size, |
| 27 ptrdiff_t offset, |
| 28 size_t size); |
| 27 | 29 |
| 28 // Gets the "get" pointer. The get pointer is an index into the command | 30 // Gets the "get" pointer. The get pointer is an index into the command |
| 29 // buffer considered as an array of CommandBufferEntry. | 31 // buffer considered as an array of CommandBufferEntry. |
| 30 CommandBufferOffset get() const { return get_; } | 32 CommandBufferOffset get() const { return get_; } |
| 31 | 33 |
| 32 // Sets the "get" pointer. The get pointer is an index into the command buffer | 34 // Sets the "get" pointer. The get pointer is an index into the command buffer |
| 33 // considered as an array of CommandBufferEntry. | 35 // considered as an array of CommandBufferEntry. |
| 34 bool set_get(CommandBufferOffset get) { | 36 bool set_get(CommandBufferOffset get) { |
| 35 if (get >= 0 && get < entry_count_) { | 37 if (get >= 0 && get < entry_count_) { |
| 36 get_ = get; | 38 get_ = get; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 56 | 58 |
| 57 // Processes all commands until get == put. | 59 // Processes all commands until get == put. |
| 58 error::Error ProcessAllCommands(); | 60 error::Error ProcessAllCommands(); |
| 59 | 61 |
| 60 // Reports an error. | 62 // Reports an error. |
| 61 void ReportError(unsigned int command_id, error::Error result); | 63 void ReportError(unsigned int command_id, error::Error result); |
| 62 | 64 |
| 63 private: | 65 private: |
| 64 CommandBufferOffset get_; | 66 CommandBufferOffset get_; |
| 65 CommandBufferOffset put_; | 67 CommandBufferOffset put_; |
| 66 CommandBufferEntry *buffer_; | 68 CommandBufferEntry* buffer_; |
| 67 int32 entry_count_; | 69 int32 entry_count_; |
| 68 AsyncAPIInterface *handler_; | 70 AsyncAPIInterface* handler_; |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 // This class defines the interface for an asynchronous API handler, that | 73 // This class defines the interface for an asynchronous API handler, that |
| 72 // is responsible for de-multiplexing commands and their arguments. | 74 // is responsible for de-multiplexing commands and their arguments. |
| 73 class AsyncAPIInterface { | 75 class AsyncAPIInterface { |
| 74 public: | 76 public: |
| 75 AsyncAPIInterface() {} | 77 AsyncAPIInterface() {} |
| 76 virtual ~AsyncAPIInterface() {} | 78 virtual ~AsyncAPIInterface() {} |
| 77 | 79 |
| 78 // Executes a command. | 80 // Executes a command. |
| 79 // Parameters: | 81 // Parameters: |
| 80 // command: the command index. | 82 // command: the command index. |
| 81 // arg_count: the number of CommandBufferEntry arguments. | 83 // arg_count: the number of CommandBufferEntry arguments. |
| 82 // cmd_data: the command data. | 84 // cmd_data: the command data. |
| 83 // Returns: | 85 // Returns: |
| 84 // error::kNoError if no error was found, one of | 86 // error::kNoError if no error was found, one of |
| 85 // error::Error otherwise. | 87 // error::Error otherwise. |
| 86 virtual error::Error DoCommand( | 88 virtual error::Error DoCommand( |
| 87 unsigned int command, | 89 unsigned int command, |
| 88 unsigned int arg_count, | 90 unsigned int arg_count, |
| 89 const void* cmd_data) = 0; | 91 const void* cmd_data) = 0; |
| 90 | 92 |
| 91 // Returns a name for a command. Useful for logging / debuging. | 93 // Returns a name for a command. Useful for logging / debuging. |
| 92 virtual const char* GetCommandName(unsigned int command_id) const = 0; | 94 virtual const char* GetCommandName(unsigned int command_id) const = 0; |
| 93 }; | 95 }; |
| 94 | 96 |
| 95 } // namespace gpu | 97 } // namespace gpu |
| 96 | 98 |
| 97 #endif // GPU_COMMAND_BUFFER_SERVICE_CMD_PARSER_H_ | 99 #endif // GPU_COMMAND_BUFFER_SERVICE_CMD_PARSER_H_ |
| OLD | NEW |