OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkData.h" | 8 #include "SkData.h" |
9 #include "SkOSFile.h" | 9 #include "SkOSFile.h" |
10 #include "SkOncePtr.h" | 10 #include "SkOncePtr.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 SkData* SkData::NewWithProc(const void* ptr, size_t length, ReleaseProc proc, vo
id* context) { | 106 SkData* SkData::NewWithProc(const void* ptr, size_t length, ReleaseProc proc, vo
id* context) { |
107 return new SkData(ptr, length, proc, context); | 107 return new SkData(ptr, length, proc, context); |
108 } | 108 } |
109 | 109 |
110 // assumes fPtr was allocated with sk_fmmap | 110 // assumes fPtr was allocated with sk_fmmap |
111 static void sk_mmap_releaseproc(const void* addr, void* ctx) { | 111 static void sk_mmap_releaseproc(const void* addr, void* ctx) { |
112 size_t length = reinterpret_cast<size_t>(ctx); | 112 size_t length = reinterpret_cast<size_t>(ctx); |
113 sk_fmunmap(addr, length); | 113 sk_fmunmap(addr, length); |
114 } | 114 } |
115 | 115 |
116 SkData* SkData::NewFromFILE(SkFILE* f) { | 116 SkData* SkData::NewFromFILE(FILE* f) { |
117 size_t size; | 117 size_t size; |
118 void* addr = sk_fmmap(f, &size); | 118 void* addr = sk_fmmap(f, &size); |
119 if (nullptr == addr) { | 119 if (nullptr == addr) { |
120 return nullptr; | 120 return nullptr; |
121 } | 121 } |
122 | 122 |
123 return SkData::NewWithProc(addr, size, sk_mmap_releaseproc, reinterpret_cast
<void*>(size)); | 123 return SkData::NewWithProc(addr, size, sk_mmap_releaseproc, reinterpret_cast
<void*>(size)); |
124 } | 124 } |
125 | 125 |
126 SkData* SkData::NewFromFileName(const char path[]) { | 126 SkData* SkData::NewFromFileName(const char path[]) { |
127 SkFILE* f = path ? sk_fopen(path, kRead_SkFILE_Flag) : nullptr; | 127 FILE* f = path ? sk_fopen(path, kRead_SkFILE_Flag) : nullptr; |
128 if (nullptr == f) { | 128 if (nullptr == f) { |
129 return nullptr; | 129 return nullptr; |
130 } | 130 } |
131 SkData* data = NewFromFILE(f); | 131 SkData* data = NewFromFILE(f); |
132 sk_fclose(f); | 132 sk_fclose(f); |
133 return data; | 133 return data; |
134 } | 134 } |
135 | 135 |
136 SkData* SkData::NewFromFD(int fd) { | 136 SkData* SkData::NewFromFD(int fd) { |
137 size_t size; | 137 size_t size; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 /////////////////////////////////////////////////////////////////////////////// | 185 /////////////////////////////////////////////////////////////////////////////// |
186 | 186 |
187 SkData* SkData::NewFromStream(SkStream* stream, size_t size) { | 187 SkData* SkData::NewFromStream(SkStream* stream, size_t size) { |
188 SkAutoDataUnref data(SkData::NewUninitialized(size)); | 188 SkAutoDataUnref data(SkData::NewUninitialized(size)); |
189 if (stream->read(data->writable_data(), size) != size) { | 189 if (stream->read(data->writable_data(), size) != size) { |
190 return nullptr; | 190 return nullptr; |
191 } | 191 } |
192 return data.detach(); | 192 return data.detach(); |
193 } | 193 } |
194 | 194 |
OLD | NEW |