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

Side by Side Diff: src/core/SkPicture.cpp

Issue 2341693004: add helpers for using SkData with picture serialization (Closed)
Patch Set: update sampleview Created 4 years, 3 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 | « samplecode/GMSampleView.cpp ('k') | no next file » | 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 2007 The Android Open Source Project 2 * Copyright 2007 The Android Open Source Project
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 "SkAtomics.h" 8 #include "SkAtomics.h"
9 #include "SkImageDeserializer.h" 9 #include "SkImageDeserializer.h"
10 #include "SkImageGenerator.h" 10 #include "SkImageGenerator.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer * factory) { 170 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer * factory) {
171 return MakeFromStream(stream, factory, nullptr); 171 return MakeFromStream(stream, factory, nullptr);
172 } 172 }
173 173
174 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream) { 174 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream) {
175 SkImageDeserializer factory; 175 SkImageDeserializer factory;
176 return MakeFromStream(stream, &factory); 176 return MakeFromStream(stream, &factory);
177 } 177 }
178 178
179 sk_sp<SkPicture> SkPicture::MakeFromData(const void* data, size_t size,
180 SkImageDeserializer* factory) {
181 SkMemoryStream stream(data, size);
182 return MakeFromStream(&stream, factory, nullptr);
183 }
184
185 sk_sp<SkPicture> SkPicture::MakeFromData(const SkData* data, SkImageDeserializer * factory) {
186 if (!data) {
187 return nullptr;
188 }
189 SkMemoryStream stream(data->data(), data->size());
190 return MakeFromStream(&stream, factory, nullptr);
191 }
192
179 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer * factory, 193 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer * factory,
180 SkTypefacePlayback* typefaces) { 194 SkTypefacePlayback* typefaces) {
181 SkPictInfo info; 195 SkPictInfo info;
182 if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) { 196 if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) {
183 return nullptr; 197 return nullptr;
184 } 198 }
185 SkAutoTDelete<SkPictureData> data( 199 SkAutoTDelete<SkPictureData> data(
186 SkPictureData::CreateFromStream(stream, info, factory, typefaces)); 200 SkPictureData::CreateFromStream(stream, info, factory, typefaces));
187 return Forwardport(info, data, nullptr); 201 return Forwardport(info, data, nullptr);
188 } 202 }
(...skipping 13 matching lines...) Expand all
202 rec.beginRecording(); 216 rec.beginRecording();
203 this->playback(&rec); 217 this->playback(&rec);
204 rec.endRecording(); 218 rec.endRecording();
205 return new SkPictureData(rec, info); 219 return new SkPictureData(rec, info);
206 } 220 }
207 221
208 void SkPicture::serialize(SkWStream* stream, SkPixelSerializer* pixelSerializer) const { 222 void SkPicture::serialize(SkWStream* stream, SkPixelSerializer* pixelSerializer) const {
209 this->serialize(stream, pixelSerializer, nullptr); 223 this->serialize(stream, pixelSerializer, nullptr);
210 } 224 }
211 225
226 sk_sp<SkData> SkPicture::serialize(SkPixelSerializer* pixelSerializer) const {
227 SkDynamicMemoryWStream stream;
228 this->serialize(&stream, pixelSerializer, nullptr);
229 return stream.detachAsData();
230 }
231
212 void SkPicture::serialize(SkWStream* stream, 232 void SkPicture::serialize(SkWStream* stream,
213 SkPixelSerializer* pixelSerializer, 233 SkPixelSerializer* pixelSerializer,
214 SkRefCntSet* typefaceSet) const { 234 SkRefCntSet* typefaceSet) const {
215 SkPictInfo info = this->createHeader(); 235 SkPictInfo info = this->createHeader();
216 SkAutoTDelete<SkPictureData> data(this->backport()); 236 SkAutoTDelete<SkPictureData> data(this->backport());
217 237
218 stream->write(&info, sizeof(info)); 238 stream->write(&info, sizeof(info));
219 if (data) { 239 if (data) {
220 stream->writeBool(true); 240 stream->writeBool(true);
221 data->serialize(stream, pixelSerializer, typefaceSet); 241 data->serialize(stream, pixelSerializer, typefaceSet);
(...skipping 29 matching lines...) Expand all
251 #endif 271 #endif
252 272
253 // Global setting to disable security precautions for serialization. 273 // Global setting to disable security precautions for serialization.
254 void SkPicture::SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set) { 274 void SkPicture::SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set) {
255 g_AllPictureIOSecurityPrecautionsEnabled = set; 275 g_AllPictureIOSecurityPrecautionsEnabled = set;
256 } 276 }
257 277
258 bool SkPicture::PictureIOSecurityPrecautionsEnabled() { 278 bool SkPicture::PictureIOSecurityPrecautionsEnabled() {
259 return g_AllPictureIOSecurityPrecautionsEnabled; 279 return g_AllPictureIOSecurityPrecautionsEnabled;
260 } 280 }
OLDNEW
« no previous file with comments | « samplecode/GMSampleView.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698