| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 parser. | 5 // This file contains the implementation of the command parser. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/service/cmd_parser.h" | 7 #include "gpu/command_buffer/service/cmd_parser.h" |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 return error; | 69 return error; |
| 70 } | 70 } |
| 71 return error::kNoError; | 71 return error::kNoError; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Decode multiple commands, and call the corresponding GL functions. | 74 // Decode multiple commands, and call the corresponding GL functions. |
| 75 // NOTE: buffer is a pointer to the command buffer. As such, it could be | 75 // NOTE: buffer is a pointer to the command buffer. As such, it could be |
| 76 // changed by a (malicious) client at any time, so if validation has to happen, | 76 // changed by a (malicious) client at any time, so if validation has to happen, |
| 77 // it should operate on a copy of them. | 77 // it should operate on a copy of them. |
| 78 error::Error AsyncAPIInterface::DoCommands(unsigned int num_commands, | 78 error::Error AsyncAPIInterface::DoCommands(unsigned int num_commands, |
| 79 const void* buffer, | 79 const volatile void* buffer, |
| 80 int num_entries, | 80 int num_entries, |
| 81 int* entries_processed) { | 81 int* entries_processed) { |
| 82 int commands_to_process = num_commands; | 82 int commands_to_process = num_commands; |
| 83 error::Error result = error::kNoError; | 83 error::Error result = error::kNoError; |
| 84 const CommandBufferEntry* cmd_data = | 84 const volatile CommandBufferEntry* cmd_data = |
| 85 static_cast<const CommandBufferEntry*>(buffer); | 85 static_cast<const volatile CommandBufferEntry*>(buffer); |
| 86 int process_pos = 0; | 86 int process_pos = 0; |
| 87 | 87 |
| 88 while (process_pos < num_entries && result == error::kNoError && | 88 while (process_pos < num_entries && result == error::kNoError && |
| 89 commands_to_process--) { | 89 commands_to_process--) { |
| 90 CommandHeader header = cmd_data->value_header; | 90 CommandHeader header = CommandHeader::FromVolatile(cmd_data->value_header); |
| 91 if (header.size == 0) { | 91 if (header.size == 0) { |
| 92 DVLOG(1) << "Error: zero sized command in command buffer"; | 92 DVLOG(1) << "Error: zero sized command in command buffer"; |
| 93 return error::kInvalidSize; | 93 return error::kInvalidSize; |
| 94 } | 94 } |
| 95 | 95 |
| 96 if (static_cast<int>(header.size) + process_pos > num_entries) { | 96 if (static_cast<int>(header.size) + process_pos > num_entries) { |
| 97 DVLOG(1) << "Error: get offset out of bounds"; | 97 DVLOG(1) << "Error: get offset out of bounds"; |
| 98 return error::kOutOfBounds; | 98 return error::kOutOfBounds; |
| 99 } | 99 } |
| 100 | 100 |
| 101 const unsigned int command = header.command; | 101 const unsigned int command = header.command; |
| 102 const unsigned int arg_count = header.size - 1; | 102 const unsigned int arg_count = header.size - 1; |
| 103 | 103 |
| 104 result = DoCommand(command, arg_count, cmd_data); | 104 result = DoCommand(command, arg_count, cmd_data); |
| 105 | 105 |
| 106 if (result != error::kDeferCommandUntilLater) { | 106 if (result != error::kDeferCommandUntilLater) { |
| 107 process_pos += header.size; | 107 process_pos += header.size; |
| 108 cmd_data += header.size; | 108 cmd_data += header.size; |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (entries_processed) | 112 if (entries_processed) |
| 113 *entries_processed = process_pos; | 113 *entries_processed = process_pos; |
| 114 | 114 |
| 115 return result; | 115 return result; |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace gpu | 118 } // namespace gpu |
| OLD | NEW |