Index: include/core/SkData.h |
diff --git a/include/core/SkData.h b/include/core/SkData.h |
index 60a98e00f0049c8e0d08678a21b7418f77d8c22a..628029f82b9f409488ee8bba0926c1033394a9f7 100644 |
--- a/include/core/SkData.h |
+++ b/include/core/SkData.h |
@@ -14,6 +14,8 @@ |
class SkStream; |
+#define SK_SUPPORT_LEGACY_DATA_FACTORIES |
+ |
/** |
* SkData holds an immutable data buffer. Not only is the data immutable, |
* but the actual ptr that is returned (by data() or bytes()) is guaranteed |
@@ -67,6 +69,7 @@ public: |
* effectively returning 0 == memcmp(...) |
*/ |
bool equals(const SkData* other) const; |
+ bool equals(sk_sp<const SkData>& other) const { return this->equals(other.get()); } |
/** |
* Function that, if provided, will be called when the SkData goes out |
@@ -77,13 +80,14 @@ public: |
/** |
* Create a new dataref by copying the specified data |
*/ |
- static SkData* NewWithCopy(const void* data, size_t length); |
+ static sk_sp<SkData> MakeWithCopy(const void* data, size_t length); |
+ |
/** |
* Create a new data with uninitialized contents. The caller should call writable_data() |
* to write into the buffer, but this must be done before another ref() is made. |
*/ |
- static SkData* NewUninitialized(size_t length); |
+ static sk_sp<SkData> MakeUninitialized(size_t length); |
/** |
* Create a new dataref by copying the specified c-string |
@@ -91,33 +95,33 @@ public: |
* equal to strlen(cstr) + 1. If cstr is NULL, it will be treated the same |
* as "". |
*/ |
- static SkData* NewWithCString(const char cstr[]); |
+ static sk_sp<SkData> MakeWithCString(const char cstr[]); |
/** |
* Create a new dataref, taking the ptr as is, and using the |
* releaseproc to free it. The proc may be NULL. |
*/ |
- static SkData* NewWithProc(const void* ptr, size_t length, ReleaseProc proc, void* context); |
+ static sk_sp<SkData> MakeWithProc(const void* ptr, size_t length, ReleaseProc proc, void* ctx); |
/** |
* Call this when the data parameter is already const and will outlive the lifetime of the |
* SkData. Suitable for with const globals. |
*/ |
- static SkData* NewWithoutCopy(const void* data, size_t length) { |
- return NewWithProc(data, length, DummyReleaseProc, NULL); |
+ static sk_sp<SkData> MakeWithoutCopy(const void* data, size_t length) { |
+ return MakeWithProc(data, length, DummyReleaseProc, nullptr); |
} |
/** |
* Create a new dataref from a pointer allocated by malloc. The Data object |
* takes ownership of that allocation, and will handling calling sk_free. |
*/ |
- static SkData* NewFromMalloc(const void* data, size_t length); |
+ static sk_sp<SkData> MakeFromMalloc(const void* data, size_t length); |
/** |
* Create a new dataref the file with the specified path. |
* If the file cannot be opened, this returns NULL. |
*/ |
- static SkData* NewFromFileName(const char path[]); |
+ static sk_sp<SkData> MakeFromFileName(const char path[]); |
/** |
* Create a new dataref from a stdio FILE. |
@@ -126,7 +130,7 @@ public: |
* The FILE must be open for reading only. |
* Returns NULL on failure. |
*/ |
- static SkData* NewFromFILE(FILE* f); |
+ static sk_sp<SkData> MakeFromFILE(FILE* f); |
/** |
* Create a new dataref from a file descriptor. |
@@ -135,26 +139,57 @@ public: |
* The file descriptor must be open for reading only. |
* Returns NULL on failure. |
*/ |
- static SkData* NewFromFD(int fd); |
+ static sk_sp<SkData> MakeFromFD(int fd); |
/** |
* Attempt to read size bytes into a SkData. If the read succeeds, return the data, |
* else return NULL. Either way the stream's cursor may have been changed as a result |
* of calling read(). |
*/ |
- static SkData* NewFromStream(SkStream*, size_t size); |
+ static sk_sp<SkData> MakeFromStream(SkStream*, size_t size); |
/** |
* Create a new dataref using a subset of the data in the specified |
* src dataref. |
*/ |
- static SkData* NewSubset(const SkData* src, size_t offset, size_t length); |
+ static sk_sp<SkData> MakeSubset(const SkData* src, size_t offset, size_t length); |
/** |
* Returns a new empty dataref (or a reference to a shared empty dataref). |
* New or shared, the caller must see that unref() is eventually called. |
*/ |
- static SkData* NewEmpty(); |
+ static sk_sp<SkData> MakeEmpty(); |
+ |
+#ifdef SK_SUPPORT_LEGACY_DATA_FACTORIES |
+ static SkData* NewWithCopy(const void* data, size_t length) { |
+ return MakeWithCopy(data, length).release(); |
+ } |
+ static SkData* NewUninitialized(size_t length) { |
+ return MakeUninitialized(length).release(); |
+ } |
+ static SkData* NewWithCString(const char cstr[]) { |
+ return MakeWithCString(cstr).release(); |
+ } |
+ static SkData* NewWithProc(const void* ptr, size_t length, ReleaseProc proc, void* context) { |
+ return MakeWithProc(ptr, length, proc, context).release(); |
+ } |
+ static SkData* NewWithoutCopy(const void* data, size_t length) { |
+ return MakeWithoutCopy(data, length).release(); |
+ } |
+ static SkData* NewFromMalloc(const void* data, size_t length) { |
+ return MakeFromMalloc(data, length).release(); |
+ } |
+ static SkData* NewFromFileName(const char path[]) { return MakeFromFileName(path).release(); } |
+ static SkData* NewFromFILE(FILE* f) { return MakeFromFILE(f).release(); } |
+ static SkData* NewFromFD(int fd) { return MakeFromFD(fd).release(); } |
+ static SkData* NewFromStream(SkStream* stream, size_t size) { |
+ return MakeFromStream(stream, size).release(); |
+ } |
+ static SkData* NewSubset(const SkData* src, size_t offset, size_t length) { |
+ return MakeSubset(src, offset, length).release(); |
+ } |
+ static SkData* NewEmpty() { return MakeEmpty().release(); } |
+#endif |
private: |
ReleaseProc fReleaseProc; |
@@ -179,14 +214,16 @@ private: |
friend SkData* sk_new_empty_data(); |
// shared internal factory |
- static SkData* PrivateNewWithCopy(const void* srcOrNull, size_t length); |
+ static sk_sp<SkData> PrivateNewWithCopy(const void* srcOrNull, size_t length); |
static void DummyReleaseProc(const void*, void*) {} |
typedef SkRefCnt INHERITED; |
}; |
+#ifdef SK_SUPPORT_LEGACY_DATA_FACTORIES |
/** Typedef of SkAutoTUnref<SkData> for automatically unref-ing a SkData. */ |
typedef SkAutoTUnref<SkData> SkAutoDataUnref; |
+#endif |
#endif |