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 std::string& str) { | 38 void CommonDecoder::Bucket::SetFromString(const char* 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 SetSize(str.size() + 1); | 41 if (!str) { |
42 SetData(str.c_str(), 0, str.size() + 1); | 42 SetSize(0); |
| 43 } else { |
| 44 size_t size = strlen(str) + 1; |
| 45 SetSize(size); |
| 46 SetData(str, 0, size); |
| 47 } |
43 } | 48 } |
44 | 49 |
45 bool CommonDecoder::Bucket::GetAsString(std::string* str) { | 50 bool CommonDecoder::Bucket::GetAsString(std::string* str) { |
46 DCHECK(str); | 51 DCHECK(str); |
47 if (size_ == 0) { | 52 if (size_ == 0) { |
48 return false; | 53 return false; |
49 } | 54 } |
50 str->assign(GetDataAs<const char*>(0, size_ - 1), size_ - 1); | 55 str->assign(GetDataAs<const char*>(0, size_ - 1), size_ - 1); |
51 return true; | 56 return true; |
52 } | 57 } |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 324 } |
320 const void* src = bucket->GetData(offset, size); | 325 const void* src = bucket->GetData(offset, size); |
321 if (!src) { | 326 if (!src) { |
322 return error::kInvalidArguments; | 327 return error::kInvalidArguments; |
323 } | 328 } |
324 memcpy(data, src, size); | 329 memcpy(data, src, size); |
325 return error::kNoError; | 330 return error::kNoError; |
326 } | 331 } |
327 | 332 |
328 } // namespace gpu | 333 } // namespace gpu |
OLD | NEW |