| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkLazyPtr.h" | 9 #include "SkLazyPtr.h" |
| 10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 char* storage = (char*)sk_malloc_throw(sizeof(SkData) + length); | 85 char* storage = (char*)sk_malloc_throw(sizeof(SkData) + length); |
| 86 SkData* data = new (storage) SkData(length); | 86 SkData* data = new (storage) SkData(length); |
| 87 if (srcOrNull) { | 87 if (srcOrNull) { |
| 88 memcpy(data->writable_data(), srcOrNull, length); | 88 memcpy(data->writable_data(), srcOrNull, length); |
| 89 } | 89 } |
| 90 return data; | 90 return data; |
| 91 } | 91 } |
| 92 | 92 |
| 93 /////////////////////////////////////////////////////////////////////////////// | 93 /////////////////////////////////////////////////////////////////////////////// |
| 94 | 94 |
| 95 SkData* SkData::NewEmptyImpl() { | 95 // As a template argument these must have external linkage. |
| 96 return new SkData(NULL, 0, NULL, NULL); | 96 SkData* sk_new_empty_data() { return new SkData(NULL, 0, NULL, NULL); } |
| 97 } | 97 namespace { void sk_unref_data(SkData* ptr) { return SkSafeUnref(ptr); } } |
| 98 | 98 |
| 99 void SkData::DeleteEmpty(SkData* ptr) { SkDELETE(ptr); } | 99 SK_DECLARE_STATIC_LAZY_PTR(SkData, empty, sk_new_empty_data, sk_unref_data); |
| 100 | 100 |
| 101 SkData* SkData::NewEmpty() { | 101 SkData* SkData::NewEmpty() { |
| 102 SK_DECLARE_STATIC_LAZY_PTR(SkData, empty, NewEmptyImpl, DeleteEmpty); | |
| 103 return SkRef(empty.get()); | 102 return SkRef(empty.get()); |
| 104 } | 103 } |
| 105 | 104 |
| 106 // assumes fPtr was allocated via sk_malloc | 105 // assumes fPtr was allocated via sk_malloc |
| 107 static void sk_free_releaseproc(const void* ptr, size_t, void*) { | 106 static void sk_free_releaseproc(const void* ptr, size_t, void*) { |
| 108 sk_free((void*)ptr); | 107 sk_free((void*)ptr); |
| 109 } | 108 } |
| 110 | 109 |
| 111 SkData* SkData::NewFromMalloc(const void* data, size_t length) { | 110 SkData* SkData::NewFromMalloc(const void* data, size_t length) { |
| 112 return new SkData(data, length, sk_free_releaseproc, NULL); | 111 return new SkData(data, length, sk_free_releaseproc, NULL); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 /////////////////////////////////////////////////////////////////////////////// | 202 /////////////////////////////////////////////////////////////////////////////// |
| 204 | 203 |
| 205 SkData* SkData::NewFromStream(SkStream* stream, size_t size) { | 204 SkData* SkData::NewFromStream(SkStream* stream, size_t size) { |
| 206 SkAutoDataUnref data(SkData::NewUninitialized(size)); | 205 SkAutoDataUnref data(SkData::NewUninitialized(size)); |
| 207 if (stream->read(data->writable_data(), size) != size) { | 206 if (stream->read(data->writable_data(), size) != size) { |
| 208 return NULL; | 207 return NULL; |
| 209 } | 208 } |
| 210 return data.detach(); | 209 return data.detach(); |
| 211 } | 210 } |
| 212 | 211 |
| OLD | NEW |