| 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 |
| 11 const void* CommonDecoder::Bucket::GetData(size_t offset, size_t size) const { | 11 void* CommonDecoder::Bucket::GetData(size_t offset, size_t size) const { |
| 12 if (OffsetSizeValid(offset, size)) { | 12 if (OffsetSizeValid(offset, size)) { |
| 13 return data_.get() + offset; | 13 return data_.get() + offset; |
| 14 } | 14 } |
| 15 return NULL; | 15 return NULL; |
| 16 } | 16 } |
| 17 | 17 |
| 18 void CommonDecoder::Bucket::SetSize(size_t size) { | 18 void CommonDecoder::Bucket::SetSize(size_t size) { |
| 19 if (size != size_) { | 19 if (size != size_) { |
| 20 data_.reset(size ? new int8[size] : NULL); | 20 data_.reset(size ? new int8[size] : NULL); |
| 21 size_ = size; | 21 size_ = size; |
| 22 memset(data_.get(), 0, size); | 22 memset(data_.get(), 0, size); |
| 23 } | 23 } |
| 24 } | 24 } |
| 25 | 25 |
| 26 bool CommonDecoder::Bucket::SetData( | 26 bool CommonDecoder::Bucket::SetData( |
| 27 const void* src, size_t offset, size_t size) { | 27 const void* src, size_t offset, size_t size) { |
| 28 if (OffsetSizeValid(offset, size)) { | 28 if (OffsetSizeValid(offset, size)) { |
| 29 memcpy(data_.get() + offset, src, size); | 29 memcpy(data_.get() + offset, src, size); |
| 30 return true; | 30 return true; |
| 31 } | 31 } |
| 32 return false; | 32 return false; |
| 33 } | 33 } |
| 34 | 34 |
| 35 void CommonDecoder::Bucket::SetFromString(const std::string& str) { | 35 void CommonDecoder::Bucket::SetFromString(const std::string& str) { |
| 36 SetSize(str.size()); | 36 // Strings are passed NULL terminated to distinguish between empty string |
| 37 SetData(str.c_str(), 0, str.size()); | 37 // and no string. |
| 38 SetSize(str.size() + 1); |
| 39 SetData(str.c_str(), 0, str.size() + 1); |
| 38 } | 40 } |
| 39 | 41 |
| 40 void* CommonDecoder::GetAddressAndCheckSize(unsigned int shm_id, | 42 void* CommonDecoder::GetAddressAndCheckSize(unsigned int shm_id, |
| 41 unsigned int offset, | 43 unsigned int offset, |
| 42 unsigned int size) { | 44 unsigned int size) { |
| 43 Buffer buffer = engine_->GetSharedMemoryBuffer(shm_id); | 45 Buffer buffer = engine_->GetSharedMemoryBuffer(shm_id); |
| 44 if (!buffer.ptr) | 46 if (!buffer.ptr) |
| 45 return NULL; | 47 return NULL; |
| 46 unsigned int end = offset + size; | 48 unsigned int end = offset + size; |
| 47 if (end > buffer.size || end < offset) { | 49 if (end > buffer.size || end < offset) { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 } | 303 } |
| 302 const void* src = bucket->GetData(offset, size); | 304 const void* src = bucket->GetData(offset, size); |
| 303 if (!src) { | 305 if (!src) { |
| 304 return error::kInvalidArguments; | 306 return error::kInvalidArguments; |
| 305 } | 307 } |
| 306 memcpy(data, src, size); | 308 memcpy(data, src, size); |
| 307 return error::kNoError; | 309 return error::kNoError; |
| 308 } | 310 } |
| 309 | 311 |
| 310 } // namespace gpu | 312 } // namespace gpu |
| OLD | NEW |