| 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" |
| 11 #include "SkOnce.h" |
| 11 | 12 |
| 12 SK_DEFINE_INST_COUNT(SkData) | 13 SK_DEFINE_INST_COUNT(SkData) |
| 13 | 14 |
| 14 SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) { | 15 SkData::SkData(const void* ptr, size_t size, ReleaseProc proc, void* context) { |
| 15 fPtr = ptr; | 16 fPtr = ptr; |
| 16 fSize = size; | 17 fSize = size; |
| 17 fReleaseProc = proc; | 18 fReleaseProc = proc; |
| 18 fReleaseProcContext = context; | 19 fReleaseProcContext = context; |
| 19 } | 20 } |
| 20 | 21 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 length = available; | 43 length = available; |
| 43 } | 44 } |
| 44 SkASSERT(length > 0); | 45 SkASSERT(length > 0); |
| 45 | 46 |
| 46 memcpy(buffer, this->bytes() + offset, length); | 47 memcpy(buffer, this->bytes() + offset, length); |
| 47 return length; | 48 return length; |
| 48 } | 49 } |
| 49 | 50 |
| 50 /////////////////////////////////////////////////////////////////////////////// | 51 /////////////////////////////////////////////////////////////////////////////// |
| 51 | 52 |
| 53 void SkData::NewEmptyImpl(SkData** empty) { |
| 54 *empty = new SkData(NULL, 0, NULL, NULL); |
| 55 } |
| 56 |
| 52 SkData* SkData::NewEmpty() { | 57 SkData* SkData::NewEmpty() { |
| 53 static SkData* gEmptyRef; | 58 static SkData* gEmptyRef; |
| 54 if (NULL == gEmptyRef) { | 59 SK_DECLARE_STATIC_ONCE(once); |
| 55 gEmptyRef = new SkData(NULL, 0, NULL, NULL); | 60 SkOnce(&once, SkData::NewEmptyImpl, &gEmptyRef); |
| 56 } | |
| 57 gEmptyRef->ref(); | 61 gEmptyRef->ref(); |
| 58 return gEmptyRef; | 62 return gEmptyRef; |
| 59 } | 63 } |
| 60 | 64 |
| 61 // assumes fPtr was allocated via sk_malloc | 65 // assumes fPtr was allocated via sk_malloc |
| 62 static void sk_free_releaseproc(const void* ptr, size_t, void*) { | 66 static void sk_free_releaseproc(const void* ptr, size_t, void*) { |
| 63 sk_free((void*)ptr); | 67 sk_free((void*)ptr); |
| 64 } | 68 } |
| 65 | 69 |
| 66 SkData* SkData::NewFromMalloc(const void* data, size_t length) { | 70 SkData* SkData::NewFromMalloc(const void* data, size_t length) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 SkData* SkData::NewWithCString(const char cstr[]) { | 152 SkData* SkData::NewWithCString(const char cstr[]) { |
| 149 size_t size; | 153 size_t size; |
| 150 if (NULL == cstr) { | 154 if (NULL == cstr) { |
| 151 cstr = ""; | 155 cstr = ""; |
| 152 size = 1; | 156 size = 1; |
| 153 } else { | 157 } else { |
| 154 size = strlen(cstr) + 1; | 158 size = strlen(cstr) + 1; |
| 155 } | 159 } |
| 156 return NewWithCopy(cstr, size); | 160 return NewWithCopy(cstr, size); |
| 157 } | 161 } |
| OLD | NEW |