| 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 #ifndef SkData_DEFINED | 8 #ifndef SkData_DEFINED |
| 9 #define SkData_DEFINED | 9 #define SkData_DEFINED |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 * length to the size of the data. If buffer is NULL, it is ignored, and | 60 * length to the size of the data. If buffer is NULL, it is ignored, and |
| 61 * only the computed number of bytes is returned. | 61 * only the computed number of bytes is returned. |
| 62 */ | 62 */ |
| 63 size_t copyRange(size_t offset, size_t length, void* buffer) const; | 63 size_t copyRange(size_t offset, size_t length, void* buffer) const; |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * Returns true if these two objects have the same length and contents, | 66 * Returns true if these two objects have the same length and contents, |
| 67 * effectively returning 0 == memcmp(...) | 67 * effectively returning 0 == memcmp(...) |
| 68 */ | 68 */ |
| 69 bool equals(const SkData* other) const; | 69 bool equals(const SkData* other) const; |
| 70 #ifdef SK_SUPPORT_LEGACY_DATA_FACTORIES | |
| 71 bool equals(sk_sp<const SkData>& other) const { return this->equals(other.ge
t()); } | |
| 72 #endif | |
| 73 | 70 |
| 74 /** | 71 /** |
| 75 * Function that, if provided, will be called when the SkData goes out | 72 * Function that, if provided, will be called when the SkData goes out |
| 76 * of scope, allowing for custom allocation/freeing of the data's contents. | 73 * of scope, allowing for custom allocation/freeing of the data's contents. |
| 77 */ | 74 */ |
| 78 typedef void (*ReleaseProc)(const void* ptr, void* context); | 75 typedef void (*ReleaseProc)(const void* ptr, void* context); |
| 79 | 76 |
| 80 /** | 77 /** |
| 81 * Create a new dataref by copying the specified data | 78 * Create a new dataref by copying the specified data |
| 82 */ | 79 */ |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 * src dataref. | 150 * src dataref. |
| 154 */ | 151 */ |
| 155 static sk_sp<SkData> MakeSubset(const SkData* src, size_t offset, size_t len
gth); | 152 static sk_sp<SkData> MakeSubset(const SkData* src, size_t offset, size_t len
gth); |
| 156 | 153 |
| 157 /** | 154 /** |
| 158 * Returns a new empty dataref (or a reference to a shared empty dataref). | 155 * Returns a new empty dataref (or a reference to a shared empty dataref). |
| 159 * New or shared, the caller must see that unref() is eventually called. | 156 * New or shared, the caller must see that unref() is eventually called. |
| 160 */ | 157 */ |
| 161 static sk_sp<SkData> MakeEmpty(); | 158 static sk_sp<SkData> MakeEmpty(); |
| 162 | 159 |
| 163 #ifdef SK_SUPPORT_LEGACY_DATA_FACTORIES | |
| 164 static SkData* NewWithCopy(const void* data, size_t length) { | |
| 165 return MakeWithCopy(data, length).release(); | |
| 166 } | |
| 167 static SkData* NewUninitialized(size_t length) { | |
| 168 return MakeUninitialized(length).release(); | |
| 169 } | |
| 170 static SkData* NewWithCString(const char cstr[]) { | |
| 171 return MakeWithCString(cstr).release(); | |
| 172 } | |
| 173 static SkData* NewWithProc(const void* ptr, size_t length, ReleaseProc proc,
void* context) { | |
| 174 return MakeWithProc(ptr, length, proc, context).release(); | |
| 175 } | |
| 176 static SkData* NewWithoutCopy(const void* data, size_t length) { | |
| 177 return MakeWithoutCopy(data, length).release(); | |
| 178 } | |
| 179 static SkData* NewFromMalloc(const void* data, size_t length) { | |
| 180 return MakeFromMalloc(data, length).release(); | |
| 181 } | |
| 182 static SkData* NewFromFileName(const char path[]) { return MakeFromFileName(
path).release(); } | |
| 183 static SkData* NewFromFILE(FILE* f) { return MakeFromFILE(f).release(); } | |
| 184 static SkData* NewFromFD(int fd) { return MakeFromFD(fd).release(); } | |
| 185 static SkData* NewFromStream(SkStream* stream, size_t size) { | |
| 186 return MakeFromStream(stream, size).release(); | |
| 187 } | |
| 188 static SkData* NewSubset(const SkData* src, size_t offset, size_t length) { | |
| 189 return MakeSubset(src, offset, length).release(); | |
| 190 } | |
| 191 static SkData* NewEmpty() { return MakeEmpty().release(); } | |
| 192 #endif | |
| 193 | |
| 194 private: | 160 private: |
| 195 ReleaseProc fReleaseProc; | 161 ReleaseProc fReleaseProc; |
| 196 void* fReleaseProcContext; | 162 void* fReleaseProcContext; |
| 197 void* fPtr; | 163 void* fPtr; |
| 198 size_t fSize; | 164 size_t fSize; |
| 199 | 165 |
| 200 SkData(const void* ptr, size_t size, ReleaseProc, void* context); | 166 SkData(const void* ptr, size_t size, ReleaseProc, void* context); |
| 201 explicit SkData(size_t size); // inplace new/delete | 167 explicit SkData(size_t size); // inplace new/delete |
| 202 virtual ~SkData(); | 168 virtual ~SkData(); |
| 203 | 169 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 214 friend SkData* sk_new_empty_data(); | 180 friend SkData* sk_new_empty_data(); |
| 215 | 181 |
| 216 // shared internal factory | 182 // shared internal factory |
| 217 static sk_sp<SkData> PrivateNewWithCopy(const void* srcOrNull, size_t length
); | 183 static sk_sp<SkData> PrivateNewWithCopy(const void* srcOrNull, size_t length
); |
| 218 | 184 |
| 219 static void DummyReleaseProc(const void*, void*); // {} | 185 static void DummyReleaseProc(const void*, void*); // {} |
| 220 | 186 |
| 221 typedef SkRefCnt INHERITED; | 187 typedef SkRefCnt INHERITED; |
| 222 }; | 188 }; |
| 223 | 189 |
| 224 #ifdef SK_SUPPORT_LEGACY_DATA_FACTORIES | |
| 225 /** Typedef of SkAutoTUnref<SkData> for automatically unref-ing a SkData. */ | |
| 226 typedef SkAutoTUnref<SkData> SkAutoDataUnref; | |
| 227 #endif | 190 #endif |
| 228 | |
| 229 #endif | |
| OLD | NEW |