diff options
author | 2012-02-24 15:29:00 +0000 | |
---|---|---|
committer | 2012-02-24 15:29:00 +0000 | |
commit | 61c22047dcc04be9fe7342f7e557996566f7f289 (patch) | |
tree | 36e56f848c7f3baa1644b79a03445069b000af32 /src/utils | |
parent | 3a2b35f0af0c079187c36087fe6dd279f69a80b7 (diff) |
add SkCreateDataProviderFromStream to SkCGUtils
implement SkFontHost create_from_file/stream using SkCGUtils
git-svn-id: http://skia.googlecode.com/svn/trunk@3249 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/mac/SkStream_mac.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/utils/mac/SkStream_mac.cpp b/src/utils/mac/SkStream_mac.cpp new file mode 100644 index 0000000000..97df43055c --- /dev/null +++ b/src/utils/mac/SkStream_mac.cpp @@ -0,0 +1,59 @@ +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkCGUtils.h" +#include "SkStream.h" + +// This is used by CGDataProviderCreateWithData + +static void unref_data_proc(void* info, const void* addr, size_t size) { + SkASSERT(info); + ((SkRefCnt*)info)->unref(); +} + +// These are used by CGDataProviderSequentialCallbacks + +size_t get_bytes_proc(void* info, void* buffer, size_t bytes) { + SkASSERT(info); + return ((SkStream*)info)->read(buffer, bytes); +} + +static off_t skip_forward_proc(void* info, off_t bytes) { + return ((SkStream*)info)->skip(bytes); +} + +static void rewind_proc(void* info) { + SkASSERT(info); + ((SkStream*)info)->rewind(); +} + +static void release_info_proc(void* info) { + SkASSERT(info); + ((SkStream*)info)->unref(); +} + +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); + } + + CGDataProviderSequentialCallbacks rec; + sk_bzero(&rec, sizeof(rec)); + rec.version = 0; + rec.getBytes = get_bytes_proc; + rec.skipForward = skip_forward_proc; + rec.rewind = rewind_proc; + rec.releaseInfo = release_info_proc; + return CGDataProviderCreateSequential(stream, &rec); +} + + |