OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 9 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 SkASSERT(info); | 41 SkASSERT(info); |
42 ((SkStream*)info)->rewind(); | 42 ((SkStream*)info)->rewind(); |
43 } | 43 } |
44 | 44 |
45 // Used when info is an SkStream. | 45 // Used when info is an SkStream. |
46 static void release_info_proc(void* info) { | 46 static void release_info_proc(void* info) { |
47 SkASSERT(info); | 47 SkASSERT(info); |
48 delete (SkStream*)info; | 48 delete (SkStream*)info; |
49 } | 49 } |
50 | 50 |
51 CGDataProviderRef SkCreateDataProviderFromStream(std::unique_ptr<SkStream> strea
m) { | 51 CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) { |
52 // TODO: Replace with SkStream::getData() when that is added. Then we only | 52 // TODO: Replace with SkStream::getData() when that is added. Then we only |
53 // have one version of CGDataProviderCreateWithData (i.e. same release proc) | 53 // have one version of CGDataProviderCreateWithData (i.e. same release proc) |
54 const void* addr = stream->getMemoryBase(); | 54 const void* addr = stream->getMemoryBase(); |
55 if (addr) { | 55 if (addr) { |
56 // special-case when the stream is just a block of ram | 56 // special-case when the stream is just a block of ram |
57 return CGDataProviderCreateWithData(stream.release(), addr, stream->getL
ength(), | 57 return CGDataProviderCreateWithData(stream, addr, stream->getLength(), |
58 delete_stream_proc); | 58 delete_stream_proc); |
59 } | 59 } |
60 | 60 |
61 CGDataProviderSequentialCallbacks rec; | 61 CGDataProviderSequentialCallbacks rec; |
62 sk_bzero(&rec, sizeof(rec)); | 62 sk_bzero(&rec, sizeof(rec)); |
63 rec.version = 0; | 63 rec.version = 0; |
64 rec.getBytes = get_bytes_proc; | 64 rec.getBytes = get_bytes_proc; |
65 rec.skipForward = skip_forward_proc; | 65 rec.skipForward = skip_forward_proc; |
66 rec.rewind = rewind_proc; | 66 rec.rewind = rewind_proc; |
67 rec.releaseInfo = release_info_proc; | 67 rec.releaseInfo = release_info_proc; |
68 return CGDataProviderCreateSequential(stream.release(), &rec); | 68 return CGDataProviderCreateSequential(stream, &rec); |
69 } | 69 } |
70 | 70 |
71 /////////////////////////////////////////////////////////////////////////////// | 71 /////////////////////////////////////////////////////////////////////////////// |
72 | 72 |
73 #include "SkData.h" | 73 #include "SkData.h" |
74 | 74 |
75 CGDataProviderRef SkCreateDataProviderFromData(sk_sp<SkData> data) { | 75 CGDataProviderRef SkCreateDataProviderFromData(SkData* data) { |
76 return CGDataProviderCreateWithData(data.release(), data->data(), data->size
(), unref_proc); | 76 data->ref(); |
| 77 return CGDataProviderCreateWithData(data, data->data(), data->size(), |
| 78 unref_proc); |
77 } | 79 } |
78 | 80 |
79 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) | 81 #endif//defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) |
OLD | NEW |