| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "gpu/command_buffer/service/precompile.h" | 5 #include "gpu/command_buffer/service/precompile.h" |
| 6 #include "gpu/command_buffer/service/common_decoder.h" | 6 #include "gpu/command_buffer/service/common_decoder.h" |
| 7 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 7 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 8 | 8 |
| 9 namespace gpu { | 9 namespace gpu { |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 Buffer buffer = engine_->GetSharedMemoryBuffer(shm_id); | 38 Buffer buffer = engine_->GetSharedMemoryBuffer(shm_id); |
| 39 if (!buffer.ptr) | 39 if (!buffer.ptr) |
| 40 return NULL; | 40 return NULL; |
| 41 unsigned int end = offset + size; | 41 unsigned int end = offset + size; |
| 42 if (end > buffer.size || end < offset) { | 42 if (end > buffer.size || end < offset) { |
| 43 return NULL; | 43 return NULL; |
| 44 } | 44 } |
| 45 return static_cast<int8*>(buffer.ptr) + offset; | 45 return static_cast<int8*>(buffer.ptr) + offset; |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool CommonDecoder::PushAddress(uint32 offset) { |
| 49 if (call_stack_.size() < kMaxStackDepth) { |
| 50 CommandAddress return_address(engine_->GetGetOffset()); |
| 51 if (engine_->SetGetOffset(offset)) { |
| 52 call_stack_.push(return_address); |
| 53 return true; |
| 54 } |
| 55 } |
| 56 return false; |
| 57 } |
| 58 |
| 48 const char* CommonDecoder::GetCommonCommandName( | 59 const char* CommonDecoder::GetCommonCommandName( |
| 49 cmd::CommandId command_id) const { | 60 cmd::CommandId command_id) const { |
| 50 return cmd::GetCommandName(command_id); | 61 return cmd::GetCommandName(command_id); |
| 51 } | 62 } |
| 52 | 63 |
| 53 CommonDecoder::Bucket* CommonDecoder::GetBucket(uint32 bucket_id) const { | 64 CommonDecoder::Bucket* CommonDecoder::GetBucket(uint32 bucket_id) const { |
| 54 BucketMap::const_iterator iter(buckets_.find(bucket_id)); | 65 BucketMap::const_iterator iter(buckets_.find(bucket_id)); |
| 55 return iter != buckets_.end() ? &(*iter->second) : NULL; | 66 return iter != buckets_.end() ? &(*iter->second) : NULL; |
| 56 } | 67 } |
| 57 | 68 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 parse_error::ParseError CommonDecoder::HandleSetToken( | 142 parse_error::ParseError CommonDecoder::HandleSetToken( |
| 132 uint32 immediate_data_size, | 143 uint32 immediate_data_size, |
| 133 const cmd::SetToken& args) { | 144 const cmd::SetToken& args) { |
| 134 engine_->set_token(args.token); | 145 engine_->set_token(args.token); |
| 135 return parse_error::kParseNoError; | 146 return parse_error::kParseNoError; |
| 136 } | 147 } |
| 137 | 148 |
| 138 parse_error::ParseError CommonDecoder::HandleJump( | 149 parse_error::ParseError CommonDecoder::HandleJump( |
| 139 uint32 immediate_data_size, | 150 uint32 immediate_data_size, |
| 140 const cmd::Jump& args) { | 151 const cmd::Jump& args) { |
| 141 DCHECK(false); // TODO(gman): Implement. | 152 if (!engine_->SetGetOffset(args.offset)) { |
| 153 return parse_error::kParseInvalidArguments; |
| 154 } |
| 142 return parse_error::kParseNoError; | 155 return parse_error::kParseNoError; |
| 143 } | 156 } |
| 144 | 157 |
| 145 parse_error::ParseError CommonDecoder::HandleJumpRelative( | 158 parse_error::ParseError CommonDecoder::HandleJumpRelative( |
| 146 uint32 immediate_data_size, | 159 uint32 immediate_data_size, |
| 147 const cmd::JumpRelative& args) { | 160 const cmd::JumpRelative& args) { |
| 148 DCHECK(false); // TODO(gman): Implement. | 161 if (!engine_->SetGetOffset(engine_->GetGetOffset() + args.offset)) { |
| 162 return parse_error::kParseInvalidArguments; |
| 163 } |
| 149 return parse_error::kParseNoError; | 164 return parse_error::kParseNoError; |
| 150 } | 165 } |
| 151 | 166 |
| 152 parse_error::ParseError CommonDecoder::HandleCall( | 167 parse_error::ParseError CommonDecoder::HandleCall( |
| 153 uint32 immediate_data_size, | 168 uint32 immediate_data_size, |
| 154 const cmd::Call& args) { | 169 const cmd::Call& args) { |
| 155 DCHECK(false); // TODO(gman): Implement. | 170 if (!PushAddress(args.offset)) { |
| 171 return parse_error::kParseInvalidArguments; |
| 172 } |
| 156 return parse_error::kParseNoError; | 173 return parse_error::kParseNoError; |
| 157 } | 174 } |
| 158 | 175 |
| 159 parse_error::ParseError CommonDecoder::HandleCallRelative( | 176 parse_error::ParseError CommonDecoder::HandleCallRelative( |
| 160 uint32 immediate_data_size, | 177 uint32 immediate_data_size, |
| 161 const cmd::CallRelative& args) { | 178 const cmd::CallRelative& args) { |
| 162 DCHECK(false); // TODO(gman): Implement. | 179 if (!PushAddress(engine_->GetGetOffset() + args.offset)) { |
| 180 return parse_error::kParseInvalidArguments; |
| 181 } |
| 163 return parse_error::kParseNoError; | 182 return parse_error::kParseNoError; |
| 164 } | 183 } |
| 165 | 184 |
| 166 parse_error::ParseError CommonDecoder::HandleReturn( | 185 parse_error::ParseError CommonDecoder::HandleReturn( |
| 167 uint32 immediate_data_size, | 186 uint32 immediate_data_size, |
| 168 const cmd::Return& args) { | 187 const cmd::Return& args) { |
| 169 DCHECK(false); // TODO(gman): Implement. | 188 if (call_stack_.empty()) { |
| 189 return parse_error::kParseInvalidArguments; |
| 190 } |
| 191 CommandAddress return_address = call_stack_.top(); |
| 192 call_stack_.pop(); |
| 193 if (!engine_->SetGetOffset(return_address.offset)) { |
| 194 return parse_error::kParseInvalidArguments; |
| 195 } |
| 170 return parse_error::kParseNoError; | 196 return parse_error::kParseNoError; |
| 171 } | 197 } |
| 172 | 198 |
| 173 parse_error::ParseError CommonDecoder::HandleSetBucketSize( | 199 parse_error::ParseError CommonDecoder::HandleSetBucketSize( |
| 174 uint32 immediate_data_size, | 200 uint32 immediate_data_size, |
| 175 const cmd::SetBucketSize& args) { | 201 const cmd::SetBucketSize& args) { |
| 176 uint32 bucket_id = args.bucket_id; | 202 uint32 bucket_id = args.bucket_id; |
| 177 uint32 size = args.size; | 203 uint32 size = args.size; |
| 178 | 204 |
| 179 Bucket* bucket = GetBucket(bucket_id); | 205 Bucket* bucket = GetBucket(bucket_id); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 288 } |
| 263 const void* src = bucket->GetData(offset, size); | 289 const void* src = bucket->GetData(offset, size); |
| 264 if (!src) { | 290 if (!src) { |
| 265 return parse_error::kParseInvalidArguments; | 291 return parse_error::kParseInvalidArguments; |
| 266 } | 292 } |
| 267 memcpy(data, src, size); | 293 memcpy(data, src, size); |
| 268 return parse_error::kParseNoError; | 294 return parse_error::kParseNoError; |
| 269 } | 295 } |
| 270 | 296 |
| 271 } // namespace gpu | 297 } // namespace gpu |
| OLD | NEW |