diff --git a/include/utils/mac/SkCGUtils.h b/include/utils/mac/SkCGUtils.h index 46f89960f8..84b95a4aac 100644 --- a/include/utils/mac/SkCGUtils.h +++ b/include/utils/mac/SkCGUtils.h @@ -19,6 +19,7 @@ #endif class SkBitmap; +class SkData; class SkStream; /** @@ -60,5 +61,6 @@ bool SkPDFDocumentToBitmap(SkStream* stream, SkBitmap* output); * Now when the provider is finally deleted, it will delete the stream. */ CGDataProviderRef SkCreateDataProviderFromStream(SkStream*); +CGDataProviderRef SkCreateDataProviderFromStream(SkData*); #endif diff --git a/src/utils/mac/SkStream_mac.cpp b/src/utils/mac/SkStream_mac.cpp index afb87fb5d7..3482a6b01c 100644 --- a/src/utils/mac/SkStream_mac.cpp +++ b/src/utils/mac/SkStream_mac.cpp @@ -10,7 +10,7 @@ // This is used by CGDataProviderCreateWithData -static void unref_data_proc(void* info, const void* addr, size_t size) { +static void unref_proc(void* info, const void* addr, size_t size) { SkASSERT(info); ((SkRefCnt*)info)->unref(); } @@ -38,14 +38,14 @@ static void release_info_proc(void* info) { CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) { stream->ref(); // unref will be called when the provider is deleted - + 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_data_proc); + unref_proc); } - + CGDataProviderSequentialCallbacks rec; sk_bzero(&rec, sizeof(rec)); rec.version = 0; @@ -55,3 +55,14 @@ CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) { rec.releaseInfo = release_info_proc; return CGDataProviderCreateSequential(stream, &rec); } + +/////////////////////////////////////////////////////////////////////////////// + +#include "SkData.h" + +CGDataProviderRef SkCreateDataProviderFromStream(SkData* data) { + data->ref(); + return CGDataProviderCreateWithData(data, data->data(), data->size(), + unref_proc); +} +