gfx/skia/trunk/src/utils/mac/SkStream_mac.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/utils/mac/SkStream_mac.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#include "SkCGUtils.h"
    1.12 +#include "SkStream.h"
    1.13 +
    1.14 +// This is used by CGDataProviderCreateWithData
    1.15 +
    1.16 +static void unref_proc(void* info, const void* addr, size_t size) {
    1.17 +    SkASSERT(info);
    1.18 +    ((SkRefCnt*)info)->unref();
    1.19 +}
    1.20 +
    1.21 +// These are used by CGDataProviderSequentialCallbacks
    1.22 +
    1.23 +static size_t get_bytes_proc(void* info, void* buffer, size_t bytes) {
    1.24 +    SkASSERT(info);
    1.25 +    return ((SkStream*)info)->read(buffer, bytes);
    1.26 +}
    1.27 +
    1.28 +static off_t skip_forward_proc(void* info, off_t bytes) {
    1.29 +    return ((SkStream*)info)->skip((size_t) bytes);
    1.30 +}
    1.31 +
    1.32 +static void rewind_proc(void* info) {
    1.33 +    SkASSERT(info);
    1.34 +    ((SkStream*)info)->rewind();
    1.35 +}
    1.36 +
    1.37 +static void release_info_proc(void* info) {
    1.38 +    SkASSERT(info);
    1.39 +    ((SkStream*)info)->unref();
    1.40 +}
    1.41 +
    1.42 +CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) {
    1.43 +    stream->ref();  // unref will be called when the provider is deleted
    1.44 +
    1.45 +    const void* addr = stream->getMemoryBase();
    1.46 +    if (addr) {
    1.47 +        // special-case when the stream is just a block of ram
    1.48 +        return CGDataProviderCreateWithData(stream, addr, stream->getLength(),
    1.49 +                                            unref_proc);
    1.50 +    }
    1.51 +
    1.52 +    CGDataProviderSequentialCallbacks rec;
    1.53 +    sk_bzero(&rec, sizeof(rec));
    1.54 +    rec.version = 0;
    1.55 +    rec.getBytes = get_bytes_proc;
    1.56 +    rec.skipForward = skip_forward_proc;
    1.57 +    rec.rewind = rewind_proc;
    1.58 +    rec.releaseInfo = release_info_proc;
    1.59 +    return CGDataProviderCreateSequential(stream, &rec);
    1.60 +}
    1.61 +
    1.62 +///////////////////////////////////////////////////////////////////////////////
    1.63 +
    1.64 +#include "SkData.h"
    1.65 +
    1.66 +CGDataProviderRef SkCreateDataProviderFromData(SkData* data) {
    1.67 +    data->ref();
    1.68 +    return CGDataProviderCreateWithData(data, data->data(), data->size(),
    1.69 +                                            unref_proc);
    1.70 +}

mercurial