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 "SkCGUtils.h" | 8 #include "SkCGUtils.h" |
9 #include "SkStream.h" | 9 #include "SkStream.h" |
10 | 10 |
11 // These are used by CGDataProviderCreateWithData | 11 // These are used by CGDataProviderCreateWithData |
12 | 12 |
13 static void unref_proc(void* info, const void* addr, size_t size) { | 13 static void unref_proc(void* info, const void* addr, size_t size) { |
14 SkASSERT(info); | 14 SkASSERT(info); |
15 ((SkRefCnt*)info)->unref(); | 15 ((SkRefCnt*)info)->unref(); |
16 } | 16 } |
17 | 17 |
18 static void delete_stream_proc(void* info, const void* addr, size_t size) { | 18 static void delete_stream_proc(void* info, const void* addr, size_t size) { |
19 SkASSERT(info); | 19 SkASSERT(info); |
20 SkStream* stream = (SkStream*)info; | 20 SkStream* stream = (SkStream*)info; |
21 SkASSERT(stream->getMemoryBase() == addr); | 21 SkASSERT(stream->getMemoryBase() == addr); |
22 SkASSERT(stream->getLength() == size); | 22 SkASSERT(stream->getLength() == size); |
23 SkDELETE(stream); | 23 delete stream; |
24 } | 24 } |
25 | 25 |
26 // These are used by CGDataProviderSequentialCallbacks | 26 // These are used by CGDataProviderSequentialCallbacks |
27 | 27 |
28 static size_t get_bytes_proc(void* info, void* buffer, size_t bytes) { | 28 static size_t get_bytes_proc(void* info, void* buffer, size_t bytes) { |
29 SkASSERT(info); | 29 SkASSERT(info); |
30 return ((SkStream*)info)->read(buffer, bytes); | 30 return ((SkStream*)info)->read(buffer, bytes); |
31 } | 31 } |
32 | 32 |
33 static off_t skip_forward_proc(void* info, off_t bytes) { | 33 static off_t skip_forward_proc(void* info, off_t bytes) { |
34 return ((SkStream*)info)->skip((size_t) bytes); | 34 return ((SkStream*)info)->skip((size_t) bytes); |
35 } | 35 } |
36 | 36 |
37 static void rewind_proc(void* info) { | 37 static void rewind_proc(void* info) { |
38 SkASSERT(info); | 38 SkASSERT(info); |
39 ((SkStream*)info)->rewind(); | 39 ((SkStream*)info)->rewind(); |
40 } | 40 } |
41 | 41 |
42 // Used when info is an SkStream. | 42 // Used when info is an SkStream. |
43 static void release_info_proc(void* info) { | 43 static void release_info_proc(void* info) { |
44 SkASSERT(info); | 44 SkASSERT(info); |
45 SkDELETE((SkStream*)info); | 45 delete (SkStream*)info; |
46 } | 46 } |
47 | 47 |
48 CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) { | 48 CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) { |
49 // TODO: Replace with SkStream::getData() when that is added. Then we only | 49 // TODO: Replace with SkStream::getData() when that is added. Then we only |
50 // have one version of CGDataProviderCreateWithData (i.e. same release proc) | 50 // have one version of CGDataProviderCreateWithData (i.e. same release proc) |
51 const void* addr = stream->getMemoryBase(); | 51 const void* addr = stream->getMemoryBase(); |
52 if (addr) { | 52 if (addr) { |
53 // special-case when the stream is just a block of ram | 53 // special-case when the stream is just a block of ram |
54 return CGDataProviderCreateWithData(stream, addr, stream->getLength(), | 54 return CGDataProviderCreateWithData(stream, addr, stream->getLength(), |
55 delete_stream_proc); | 55 delete_stream_proc); |
(...skipping 11 matching lines...) Expand all Loading... |
67 | 67 |
68 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
69 | 69 |
70 #include "SkData.h" | 70 #include "SkData.h" |
71 | 71 |
72 CGDataProviderRef SkCreateDataProviderFromData(SkData* data) { | 72 CGDataProviderRef SkCreateDataProviderFromData(SkData* data) { |
73 data->ref(); | 73 data->ref(); |
74 return CGDataProviderCreateWithData(data, data->data(), data->size(), | 74 return CGDataProviderCreateWithData(data, data->data(), data->size(), |
75 unref_proc); | 75 unref_proc); |
76 } | 76 } |
OLD | NEW |