Index: src/core/SkData.cpp |
diff --git a/src/core/SkData.cpp b/src/core/SkData.cpp |
index 5bf833e1f37292ec30fcb488bdce3c0feff54eb4..4b2194973bbff2013596208d7f7f4e8891b16471 100644 |
--- a/src/core/SkData.cpp |
+++ b/src/core/SkData.cpp |
@@ -59,9 +59,9 @@ size_t SkData::copyRange(size_t offset, size_t length, void* buffer) const { |
return length; |
} |
-SkData* SkData::PrivateNewWithCopy(const void* srcOrNull, size_t length) { |
+sk_sp<SkData> SkData::PrivateNewWithCopy(const void* srcOrNull, size_t length) { |
if (0 == length) { |
- return SkData::NewEmpty(); |
+ return SkData::MakeEmpty(); |
} |
const size_t actualLength = length + sizeof(SkData); |
@@ -75,14 +75,15 @@ SkData* SkData::PrivateNewWithCopy(const void* srcOrNull, size_t length) { |
if (srcOrNull) { |
memcpy(data->writable_data(), srcOrNull, length); |
} |
- return data; |
+ return sk_sp<SkData>(data); |
} |
/////////////////////////////////////////////////////////////////////////////// |
SK_DECLARE_STATIC_ONCE_PTR(SkData, gEmpty); |
-SkData* SkData::NewEmpty() { |
- return SkRef(gEmpty.get([]{return new SkData(nullptr, 0, nullptr, nullptr); })); |
+sk_sp<SkData> SkData::MakeEmpty() { |
+ SkData* data = SkRef(gEmpty.get([]{return new SkData(nullptr, 0, nullptr, nullptr); })); |
+ return sk_sp<SkData>(data); |
} |
// assumes fPtr was allocated via sk_malloc |
@@ -90,21 +91,21 @@ static void sk_free_releaseproc(const void* ptr, void*) { |
sk_free((void*)ptr); |
} |
-SkData* SkData::NewFromMalloc(const void* data, size_t length) { |
- return new SkData(data, length, sk_free_releaseproc, nullptr); |
+sk_sp<SkData> SkData::MakeFromMalloc(const void* data, size_t length) { |
+ return sk_sp<SkData>(new SkData(data, length, sk_free_releaseproc, nullptr)); |
} |
-SkData* SkData::NewWithCopy(const void* src, size_t length) { |
+sk_sp<SkData> SkData::MakeWithCopy(const void* src, size_t length) { |
SkASSERT(src); |
return PrivateNewWithCopy(src, length); |
} |
-SkData* SkData::NewUninitialized(size_t length) { |
+sk_sp<SkData> SkData::MakeUninitialized(size_t length) { |
return PrivateNewWithCopy(nullptr, length); |
} |
-SkData* SkData::NewWithProc(const void* ptr, size_t length, ReleaseProc proc, void* context) { |
- return new SkData(ptr, length, proc, context); |
+sk_sp<SkData> SkData::MakeWithProc(const void* ptr, size_t length, ReleaseProc proc, void* ctx) { |
+ return sk_sp<SkData>(new SkData(ptr, length, proc, ctx)); |
} |
// assumes fPtr was allocated with sk_fmmap |
@@ -113,34 +114,34 @@ static void sk_mmap_releaseproc(const void* addr, void* ctx) { |
sk_fmunmap(addr, length); |
} |
-SkData* SkData::NewFromFILE(FILE* f) { |
+sk_sp<SkData> SkData::MakeFromFILE(FILE* f) { |
size_t size; |
void* addr = sk_fmmap(f, &size); |
if (nullptr == addr) { |
return nullptr; |
} |
- return SkData::NewWithProc(addr, size, sk_mmap_releaseproc, reinterpret_cast<void*>(size)); |
+ return SkData::MakeWithProc(addr, size, sk_mmap_releaseproc, reinterpret_cast<void*>(size)); |
} |
-SkData* SkData::NewFromFileName(const char path[]) { |
+sk_sp<SkData> SkData::MakeFromFileName(const char path[]) { |
FILE* f = path ? sk_fopen(path, kRead_SkFILE_Flag) : nullptr; |
if (nullptr == f) { |
return nullptr; |
} |
- SkData* data = NewFromFILE(f); |
+ auto data = MakeFromFILE(f); |
sk_fclose(f); |
return data; |
} |
-SkData* SkData::NewFromFD(int fd) { |
+sk_sp<SkData> SkData::MakeFromFD(int fd) { |
size_t size; |
void* addr = sk_fdmmap(fd, &size); |
if (nullptr == addr) { |
return nullptr; |
} |
- return SkData::NewWithProc(addr, size, sk_mmap_releaseproc, nullptr); |
+ return SkData::MakeWithProc(addr, size, sk_mmap_releaseproc, nullptr); |
} |
// assumes context is a SkData |
@@ -149,7 +150,7 @@ static void sk_dataref_releaseproc(const void*, void* context) { |
src->unref(); |
} |
-SkData* SkData::NewSubset(const SkData* src, size_t offset, size_t length) { |
+sk_sp<SkData> SkData::MakeSubset(const SkData* src, size_t offset, size_t length) { |
/* |
We could, if we wanted/need to, just make a deep copy of src's data, |
rather than referencing it. This would duplicate the storage (of the |
@@ -158,7 +159,7 @@ SkData* SkData::NewSubset(const SkData* src, size_t offset, size_t length) { |
size_t available = src->size(); |
if (offset >= available || 0 == length) { |
- return SkData::NewEmpty(); |
+ return SkData::MakeEmpty(); |
} |
available -= offset; |
if (length > available) { |
@@ -167,11 +168,11 @@ SkData* SkData::NewSubset(const SkData* src, size_t offset, size_t length) { |
SkASSERT(length > 0); |
src->ref(); // this will be balanced in sk_dataref_releaseproc |
- return new SkData(src->bytes() + offset, length, sk_dataref_releaseproc, |
- const_cast<SkData*>(src)); |
+ return sk_sp<SkData>(new SkData(src->bytes() + offset, length, sk_dataref_releaseproc, |
+ const_cast<SkData*>(src))); |
} |
-SkData* SkData::NewWithCString(const char cstr[]) { |
+sk_sp<SkData> SkData::MakeWithCString(const char cstr[]) { |
size_t size; |
if (nullptr == cstr) { |
cstr = ""; |
@@ -179,16 +180,16 @@ SkData* SkData::NewWithCString(const char cstr[]) { |
} else { |
size = strlen(cstr) + 1; |
} |
- return NewWithCopy(cstr, size); |
+ return MakeWithCopy(cstr, size); |
} |
/////////////////////////////////////////////////////////////////////////////// |
-SkData* SkData::NewFromStream(SkStream* stream, size_t size) { |
- SkAutoDataUnref data(SkData::NewUninitialized(size)); |
+sk_sp<SkData> SkData::MakeFromStream(SkStream* stream, size_t size) { |
+ sk_sp<SkData> data(SkData::MakeUninitialized(size)); |
if (stream->read(data->writable_data(), size) != size) { |
return nullptr; |
} |
- return data.detach(); |
+ return data; |
} |