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

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

Issue 2187613002: Deserialize pictures with custom image-deserializer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: move nullptr_t alias behind guard Created 4 years, 4 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
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 "SkImageGenerator.h" 10 #include "SkImageGenerator.h"
10 #include "SkMessageBus.h" 11 #include "SkMessageBus.h"
11 #include "SkPicture.h" 12 #include "SkPicture.h"
12 #include "SkPictureData.h" 13 #include "SkPictureData.h"
13 #include "SkPicturePlayback.h" 14 #include "SkPicturePlayback.h"
14 #include "SkPictureRecord.h" 15 #include "SkPictureRecord.h"
15 #include "SkPictureRecorder.h" 16 #include "SkPictureRecorder.h"
16 17
17 #if defined(SK_DISALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS) || \ 18 #if defined(SK_DISALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS) || \
18 defined(SK_ENABLE_PICTURE_IO_SECURITY_PRECAUTIONS) 19 defined(SK_ENABLE_PICTURE_IO_SECURITY_PRECAUTIONS)
19 static bool g_AllPictureIOSecurityPrecautionsEnabled = true; 20 static bool g_AllPictureIOSecurityPrecautionsEnabled = true;
20 #else 21 #else
21 static bool g_AllPictureIOSecurityPrecautionsEnabled = false; 22 static bool g_AllPictureIOSecurityPrecautionsEnabled = false;
22 #endif 23 #endif
23 24
24 DECLARE_SKMESSAGEBUS_MESSAGE(SkPicture::DeletionMessage); 25 DECLARE_SKMESSAGEBUS_MESSAGE(SkPicture::DeletionMessage);
25 26
27 class InstallProcImageDeserializer : public SkImageDeserializer {
28 SkPicture::InstallPixelRefProc fProc;
29 public:
30 InstallProcImageDeserializer(SkPicture::InstallPixelRefProc proc) : fProc(pr oc) {}
31
32 sk_sp<SkImage> makeFromMemory(const void* data, size_t length, const SkIRect * subset) override {
33 SkBitmap bitmap;
34 if (fProc(data, length, &bitmap)) {
35 bitmap.setImmutable();
36 return SkImage::MakeFromBitmap(bitmap);
37 }
38 return nullptr;
39 }
40 sk_sp<SkImage> makeFromData(SkData* data, const SkIRect* subset) override {
41 return this->makeFromMemory(data->data(), data->size(), subset);
42 }
43 };
44
26 /* SkPicture impl. This handles generic responsibilities like unique IDs and se rialization. */ 45 /* SkPicture impl. This handles generic responsibilities like unique IDs and se rialization. */
27 46
28 SkPicture::SkPicture() : fUniqueID(0) {} 47 SkPicture::SkPicture() : fUniqueID(0) {}
29 48
30 SkPicture::~SkPicture() { 49 SkPicture::~SkPicture() {
31 // TODO: move this to ~SkBigPicture() only? 50 // TODO: move this to ~SkBigPicture() only?
32 51
33 // If the ID is still zero, no one has read it, so no need to send this mess age. 52 // If the ID is still zero, no one has read it, so no need to send this mess age.
34 uint32_t id = sk_atomic_load(&fUniqueID, sk_memory_order_relaxed); 53 uint32_t id = sk_atomic_load(&fUniqueID, sk_memory_order_relaxed);
35 if (id != 0) { 54 if (id != 0) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 const SkReadBuffer* buffer) { 153 const SkReadBuffer* buffer) {
135 if (!data) { 154 if (!data) {
136 return nullptr; 155 return nullptr;
137 } 156 }
138 SkPicturePlayback playback(data); 157 SkPicturePlayback playback(data);
139 SkPictureRecorder r; 158 SkPictureRecorder r;
140 playback.draw(r.beginRecording(info.fCullRect), nullptr/*no callback*/, buff er); 159 playback.draw(r.beginRecording(info.fCullRect), nullptr/*no callback*/, buff er);
141 return r.finishRecordingAsPicture(); 160 return r.finishRecordingAsPicture();
142 } 161 }
143 162
163 #ifdef SK_SUPPORT_LEGACY_PICTUREINSTALLPIXELREF
144 static bool default_install(const void* src, size_t length, SkBitmap* dst) { 164 static bool default_install(const void* src, size_t length, SkBitmap* dst) {
145 sk_sp<SkData> encoded(SkData::MakeWithCopy(src, length)); 165 sk_sp<SkData> encoded(SkData::MakeWithCopy(src, length));
146 return encoded && SkDEPRECATED_InstallDiscardablePixelRef( 166 return encoded && SkDEPRECATED_InstallDiscardablePixelRef(
147 SkImageGenerator::NewFromEncoded(encoded.get()), dst); 167 SkImageGenerator::NewFromEncoded(encoded.get()), dst);
148 } 168 }
149
150 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream) {
151 return MakeFromStream(stream, &default_install, nullptr);
152 }
153
154 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc) { 169 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc) {
155 return MakeFromStream(stream, proc, nullptr); 170 return MakeFromStream(stream, proc, nullptr);
156 } 171 }
172 #endif
157 173
158 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc, 174 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer * factory) {
175 return MakeFromStream(stream, factory, nullptr);
176 }
177
178 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream) {
179 SkImageDeserializer factory;
180 return MakeFromStream(stream, &factory);
181 }
182
183 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer * factory,
159 SkTypefacePlayback* typefaces) { 184 SkTypefacePlayback* typefaces) {
160 SkPictInfo info; 185 SkPictInfo info;
161 if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) { 186 if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) {
162 return nullptr; 187 return nullptr;
163 } 188 }
164 SkAutoTDelete<SkPictureData> data( 189 SkAutoTDelete<SkPictureData> data(
165 SkPictureData::CreateFromStream(stream, info, proc, typefaces)); 190 SkPictureData::CreateFromStream(stream, info, factory, typefaces));
166 return Forwardport(info, data, nullptr); 191 return Forwardport(info, data, nullptr);
167 } 192 }
168 193
169 sk_sp<SkPicture> SkPicture::MakeFromBuffer(SkReadBuffer& buffer) { 194 sk_sp<SkPicture> SkPicture::MakeFromBuffer(SkReadBuffer& buffer) {
170 SkPictInfo info; 195 SkPictInfo info;
171 if (!InternalOnly_BufferIsSKP(&buffer, &info) || !buffer.readBool()) { 196 if (!InternalOnly_BufferIsSKP(&buffer, &info) || !buffer.readBool()) {
172 return nullptr; 197 return nullptr;
173 } 198 }
174 SkAutoTDelete<SkPictureData> data(SkPictureData::CreateFromBuffer(buffer, in fo)); 199 SkAutoTDelete<SkPictureData> data(SkPictureData::CreateFromBuffer(buffer, in fo));
175 return Forwardport(info, data, &buffer); 200 return Forwardport(info, data, &buffer);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 #endif 255 #endif
231 256
232 // Global setting to disable security precautions for serialization. 257 // Global setting to disable security precautions for serialization.
233 void SkPicture::SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set) { 258 void SkPicture::SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set) {
234 g_AllPictureIOSecurityPrecautionsEnabled = set; 259 g_AllPictureIOSecurityPrecautionsEnabled = set;
235 } 260 }
236 261
237 bool SkPicture::PictureIOSecurityPrecautionsEnabled() { 262 bool SkPicture::PictureIOSecurityPrecautionsEnabled() {
238 return g_AllPictureIOSecurityPrecautionsEnabled; 263 return g_AllPictureIOSecurityPrecautionsEnabled;
239 } 264 }
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkPictureData.h » ('j') | src/core/SkReadBuffer.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698