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/common_decoder.h" | 5 #include "gpu/command_buffer/service/common_decoder.h" |
6 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 6 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
7 | 7 |
8 namespace gpu { | 8 namespace gpu { |
9 | 9 |
10 CommonDecoder::Bucket::Bucket() : size_(0) {} | 10 CommonDecoder::Bucket::Bucket() : size_(0) {} |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 bool CommonDecoder::Bucket::SetData( | 29 bool CommonDecoder::Bucket::SetData( |
30 const void* src, size_t offset, size_t size) { | 30 const void* src, size_t offset, size_t size) { |
31 if (OffsetSizeValid(offset, size)) { | 31 if (OffsetSizeValid(offset, size)) { |
32 memcpy(data_.get() + offset, src, size); | 32 memcpy(data_.get() + offset, src, size); |
33 return true; | 33 return true; |
34 } | 34 } |
35 return false; | 35 return false; |
36 } | 36 } |
37 | 37 |
38 void CommonDecoder::Bucket::SetFromString(const char* str) { | 38 void CommonDecoder::Bucket::SetFromString(const std::string& str) { |
39 // Strings are passed NULL terminated to distinguish between empty string | 39 // Strings are passed NULL terminated to distinguish between empty string |
40 // and no string. | 40 // and no string. |
41 if (!str) { | 41 SetSize(str.size() + 1); |
42 SetSize(0); | 42 SetData(str.c_str(), 0, str.size() + 1); |
43 } else { | |
44 size_t size = strlen(str) + 1; | |
45 SetSize(size); | |
46 SetData(str, 0, size); | |
47 } | |
48 } | 43 } |
49 | 44 |
50 bool CommonDecoder::Bucket::GetAsString(std::string* str) { | 45 bool CommonDecoder::Bucket::GetAsString(std::string* str) { |
51 DCHECK(str); | 46 DCHECK(str); |
52 if (size_ == 0) { | 47 if (size_ == 0) { |
53 return false; | 48 return false; |
54 } | 49 } |
55 str->assign(GetDataAs<const char*>(0, size_ - 1), size_ - 1); | 50 str->assign(GetDataAs<const char*>(0, size_ - 1), size_ - 1); |
56 return true; | 51 return true; |
57 } | 52 } |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 319 } |
325 const void* src = bucket->GetData(offset, size); | 320 const void* src = bucket->GetData(offset, size); |
326 if (!src) { | 321 if (!src) { |
327 return error::kInvalidArguments; | 322 return error::kInvalidArguments; |
328 } | 323 } |
329 memcpy(data, src, size); | 324 memcpy(data, src, size); |
330 return error::kNoError; | 325 return error::kNoError; |
331 } | 326 } |
332 | 327 |
333 } // namespace gpu | 328 } // namespace gpu |
OLD | NEW |