Index: src/utils/mac/SkStream_mac.cpp |
diff --git a/src/utils/mac/SkStream_mac.cpp b/src/utils/mac/SkStream_mac.cpp |
index 64d2dbb2cae1767d1195487601145e5cb6638ab9..26884711ed3976621c6beefe00291f63b94e19bd 100644 |
--- a/src/utils/mac/SkStream_mac.cpp |
+++ b/src/utils/mac/SkStream_mac.cpp |
@@ -8,13 +8,21 @@ |
#include "SkCGUtils.h" |
#include "SkStream.h" |
-// This is used by CGDataProviderCreateWithData |
+// These are used by CGDataProviderCreateWithData |
static void unref_proc(void* info, const void* addr, size_t size) { |
SkASSERT(info); |
((SkRefCnt*)info)->unref(); |
} |
+static void delete_stream_proc(void* info, const void* addr, size_t size) { |
+ SkASSERT(info); |
+ SkStream* stream = (SkStream*)info; |
+ SkASSERT(stream->getMemoryBase() == addr); |
+ SkASSERT(stream->getLength() == size); |
+ SkDELETE(stream); |
+} |
+ |
// These are used by CGDataProviderSequentialCallbacks |
static size_t get_bytes_proc(void* info, void* buffer, size_t bytes) { |
@@ -31,19 +39,20 @@ static void rewind_proc(void* info) { |
((SkStream*)info)->rewind(); |
} |
+// Used when info is an SkStream. |
static void release_info_proc(void* info) { |
SkASSERT(info); |
- ((SkStream*)info)->unref(); |
+ SkDELETE((SkStream*)info); |
} |
CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) { |
- stream->ref(); // unref will be called when the provider is deleted |
- |
+ // TODO: Replace with SkStream::getData() when that is added. Then we only |
+ // have one version of CGDataProviderCreateWithData (i.e. same release proc) |
const void* addr = stream->getMemoryBase(); |
if (addr) { |
// special-case when the stream is just a block of ram |
return CGDataProviderCreateWithData(stream, addr, stream->getLength(), |
- unref_proc); |
+ delete_stream_proc); |
} |
CGDataProviderSequentialCallbacks rec; |