| 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 "SkFlattenableBuffers.h" | 9 #include "SkFlattenableBuffers.h" |
| 10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 length = available; | 41 length = available; |
| 42 } | 42 } |
| 43 SkASSERT(length > 0); | 43 SkASSERT(length > 0); |
| 44 | 44 |
| 45 memcpy(buffer, this->bytes() + offset, length); | 45 memcpy(buffer, this->bytes() + offset, length); |
| 46 return length; | 46 return length; |
| 47 } | 47 } |
| 48 | 48 |
| 49 /////////////////////////////////////////////////////////////////////////////// | 49 /////////////////////////////////////////////////////////////////////////////// |
| 50 | 50 |
| 51 void SkData::NewEmptyImpl(SkData** empty) { | 51 static SkData* gEmptyDataRef = NULL; |
| 52 *empty = new SkData(NULL, 0, NULL, NULL); | 52 static void cleanup_gEmptyDataRef() { gEmptyDataRef->unref(); } |
| 53 |
| 54 void SkData::NewEmptyImpl(int) { |
| 55 gEmptyDataRef = new SkData(NULL, 0, NULL, NULL); |
| 53 } | 56 } |
| 54 | 57 |
| 55 SkData* SkData::NewEmpty() { | 58 SkData* SkData::NewEmpty() { |
| 56 static SkData* gEmptyRef; | |
| 57 SK_DECLARE_STATIC_ONCE(once); | 59 SK_DECLARE_STATIC_ONCE(once); |
| 58 SkOnce(&once, SkData::NewEmptyImpl, &gEmptyRef); | 60 SkOnce(&once, SkData::NewEmptyImpl, 0, cleanup_gEmptyDataRef); |
| 59 gEmptyRef->ref(); | 61 gEmptyDataRef->ref(); |
| 60 return gEmptyRef; | 62 return gEmptyDataRef; |
| 61 } | 63 } |
| 62 | 64 |
| 63 // assumes fPtr was allocated via sk_malloc | 65 // assumes fPtr was allocated via sk_malloc |
| 64 static void sk_free_releaseproc(const void* ptr, size_t, void*) { | 66 static void sk_free_releaseproc(const void* ptr, size_t, void*) { |
| 65 sk_free((void*)ptr); | 67 sk_free((void*)ptr); |
| 66 } | 68 } |
| 67 | 69 |
| 68 SkData* SkData::NewFromMalloc(const void* data, size_t length) { | 70 SkData* SkData::NewFromMalloc(const void* data, size_t length) { |
| 69 return new SkData(data, length, sk_free_releaseproc, NULL); | 71 return new SkData(data, length, sk_free_releaseproc, NULL); |
| 70 } | 72 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 SkData* SkData::NewWithCString(const char cstr[]) { | 152 SkData* SkData::NewWithCString(const char cstr[]) { |
| 151 size_t size; | 153 size_t size; |
| 152 if (NULL == cstr) { | 154 if (NULL == cstr) { |
| 153 cstr = ""; | 155 cstr = ""; |
| 154 size = 1; | 156 size = 1; |
| 155 } else { | 157 } else { |
| 156 size = strlen(cstr) + 1; | 158 size = strlen(cstr) + 1; |
| 157 } | 159 } |
| 158 return NewWithCopy(cstr, size); | 160 return NewWithCopy(cstr, size); |
| 159 } | 161 } |
| OLD | NEW |