| 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 "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // conditions). This function only validates the header, leaving the arguments | 44 // conditions). This function only validates the header, leaving the arguments |
| 45 // validation to the handler, so it can pass a reference to them. | 45 // validation to the handler, so it can pass a reference to them. |
| 46 // - get_ is modified *after* the command has been executed. | 46 // - get_ is modified *after* the command has been executed. |
| 47 error::Error CommandParser::ProcessCommand() { | 47 error::Error CommandParser::ProcessCommand() { |
| 48 CommandBufferOffset get = get_; | 48 CommandBufferOffset get = get_; |
| 49 if (get == put_) | 49 if (get == put_) |
| 50 return error::kNoError; | 50 return error::kNoError; |
| 51 | 51 |
| 52 CommandHeader header = buffer_[get].value_header; | 52 CommandHeader header = buffer_[get].value_header; |
| 53 if (header.size == 0) { | 53 if (header.size == 0) { |
| 54 DVLOG(1) << "Error: zero sized command in command buffer"; | 54 LOG(ERROR) << "Parse error: zero sized command in command buffer"; |
| 55 return error::kInvalidSize; | 55 return error::kInvalidSize; |
| 56 } | 56 } |
| 57 | 57 |
| 58 if (static_cast<int>(header.size) + get > entry_count_) { | 58 if (static_cast<int>(header.size) + get > entry_count_) { |
| 59 DVLOG(1) << "Error: get offset out of bounds"; | 59 LOG(ERROR) << "Parse error: get offset out of bounds"; |
| 60 return error::kOutOfBounds; | 60 return error::kOutOfBounds; |
| 61 } | 61 } |
| 62 | 62 |
| 63 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cb_command"), | 63 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cb_command"), |
| 64 handler_->GetCommandName(header.command)); | 64 handler_->GetCommandName(header.command)); |
| 65 | 65 |
| 66 error::Error result = handler_->DoCommand( | 66 error::Error result = handler_->DoCommand( |
| 67 header.command, header.size - 1, buffer_ + get); | 67 header.command, header.size - 1, buffer_ + get); |
| 68 | 68 |
| 69 // TODO(gman): If you want to log errors this is the best place to catch them. | |
| 70 // It seems like we need an official way to turn on a debug mode and | |
| 71 // get these errors. | |
| 72 if (error::IsError(result)) { | 69 if (error::IsError(result)) { |
| 73 ReportError(header.command, result); | 70 ReportError(header.command, result); |
| 74 } | 71 } |
| 75 | 72 |
| 76 // If get was not set somewhere else advance it. | 73 // If get was not set somewhere else advance it. |
| 77 if (get == get_ && result != error::kDeferCommandUntilLater) | 74 if (get == get_ && result != error::kDeferCommandUntilLater) |
| 78 get_ = (get + header.size) % entry_count_; | 75 get_ = (get + header.size) % entry_count_; |
| 79 | 76 |
| 80 return result; | 77 return result; |
| 81 } | 78 } |
| 82 | 79 |
| 83 void CommandParser::ReportError(unsigned int command_id, | 80 void CommandParser::ReportError(unsigned int command_id, |
| 84 error::Error result) { | 81 error::Error result) { |
| 85 DVLOG(1) << "Error: " << result << " for Command " | 82 LOG(ERROR) << "Error: " << result << " for Command " |
| 86 << handler_->GetCommandName(command_id); | 83 << handler_->GetCommandName(command_id); |
| 87 } | 84 } |
| 88 | 85 |
| 89 // Processes all the commands, while the buffer is not empty. Stop if an error | 86 // Processes all the commands, while the buffer is not empty. Stop if an error |
| 90 // is encountered. | 87 // is encountered. |
| 91 error::Error CommandParser::ProcessAllCommands() { | 88 error::Error CommandParser::ProcessAllCommands() { |
| 92 while (!IsEmpty()) { | 89 while (!IsEmpty()) { |
| 93 error::Error error = ProcessCommand(); | 90 error::Error error = ProcessCommand(); |
| 94 if (error) | 91 if (error) |
| 95 return error; | 92 return error; |
| 96 } | 93 } |
| 97 return error::kNoError; | 94 return error::kNoError; |
| 98 } | 95 } |
| 99 | 96 |
| 100 } // namespace gpu | 97 } // namespace gpu |
| OLD | NEW |