Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: src/utils/mac/SkStream_mac.cpp

Issue 849103004: Make SkStream *not* ref counted. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase, just in case. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/utils/SkPDFRasterizer.cpp ('k') | src/utils/win/SkDWriteFontFileStream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // This is 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) {
19 SkASSERT(info);
20 SkStream* stream = (SkStream*)info;
21 SkASSERT(stream->getMemoryBase() == addr);
22 SkASSERT(stream->getLength() == size);
23 SkDELETE(stream);
24 }
25
18 // These are used by CGDataProviderSequentialCallbacks 26 // These are used by CGDataProviderSequentialCallbacks
19 27
20 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) {
21 SkASSERT(info); 29 SkASSERT(info);
22 return ((SkStream*)info)->read(buffer, bytes); 30 return ((SkStream*)info)->read(buffer, bytes);
23 } 31 }
24 32
25 static off_t skip_forward_proc(void* info, off_t bytes) { 33 static off_t skip_forward_proc(void* info, off_t bytes) {
26 return ((SkStream*)info)->skip((size_t) bytes); 34 return ((SkStream*)info)->skip((size_t) bytes);
27 } 35 }
28 36
29 static void rewind_proc(void* info) { 37 static void rewind_proc(void* info) {
30 SkASSERT(info); 38 SkASSERT(info);
31 ((SkStream*)info)->rewind(); 39 ((SkStream*)info)->rewind();
32 } 40 }
33 41
42 // Used when info is an SkStream.
34 static void release_info_proc(void* info) { 43 static void release_info_proc(void* info) {
35 SkASSERT(info); 44 SkASSERT(info);
36 ((SkStream*)info)->unref(); 45 SkDELETE((SkStream*)info);
37 } 46 }
38 47
39 CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) { 48 CGDataProviderRef SkCreateDataProviderFromStream(SkStream* stream) {
40 stream->ref(); // unref will be called when the provider is deleted 49 // TODO: Replace with SkStream::getData() when that is added. Then we only
41 50 // have one version of CGDataProviderCreateWithData (i.e. same release proc)
42 const void* addr = stream->getMemoryBase(); 51 const void* addr = stream->getMemoryBase();
43 if (addr) { 52 if (addr) {
44 // special-case when the stream is just a block of ram 53 // special-case when the stream is just a block of ram
45 return CGDataProviderCreateWithData(stream, addr, stream->getLength(), 54 return CGDataProviderCreateWithData(stream, addr, stream->getLength(),
46 unref_proc); 55 delete_stream_proc);
47 } 56 }
48 57
49 CGDataProviderSequentialCallbacks rec; 58 CGDataProviderSequentialCallbacks rec;
50 sk_bzero(&rec, sizeof(rec)); 59 sk_bzero(&rec, sizeof(rec));
51 rec.version = 0; 60 rec.version = 0;
52 rec.getBytes = get_bytes_proc; 61 rec.getBytes = get_bytes_proc;
53 rec.skipForward = skip_forward_proc; 62 rec.skipForward = skip_forward_proc;
54 rec.rewind = rewind_proc; 63 rec.rewind = rewind_proc;
55 rec.releaseInfo = release_info_proc; 64 rec.releaseInfo = release_info_proc;
56 return CGDataProviderCreateSequential(stream, &rec); 65 return CGDataProviderCreateSequential(stream, &rec);
57 } 66 }
58 67
59 /////////////////////////////////////////////////////////////////////////////// 68 ///////////////////////////////////////////////////////////////////////////////
60 69
61 #include "SkData.h" 70 #include "SkData.h"
62 71
63 CGDataProviderRef SkCreateDataProviderFromData(SkData* data) { 72 CGDataProviderRef SkCreateDataProviderFromData(SkData* data) {
64 data->ref(); 73 data->ref();
65 return CGDataProviderCreateWithData(data, data->data(), data->size(), 74 return CGDataProviderCreateWithData(data, data->data(), data->size(),
66 unref_proc); 75 unref_proc);
67 } 76 }
OLDNEW
« no previous file with comments | « src/utils/SkPDFRasterizer.cpp ('k') | src/utils/win/SkDWriteFontFileStream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698