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

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: fix build 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> deserialize(sk_sp<SkData> encoded, const SkIRect* subset) ove rride {
33 SkBitmap bitmap;
34 if (fProc(encoded->data(), encoded->size(), &bitmap)) {
35 bitmap.setImmutable();
36 return SkImage::MakeFromBitmap(bitmap);
37 }
38 return nullptr;
39 }
40 };
41
26 /* SkPicture impl. This handles generic responsibilities like unique IDs and se rialization. */ 42 /* SkPicture impl. This handles generic responsibilities like unique IDs and se rialization. */
27 43
28 SkPicture::SkPicture() : fUniqueID(0) {} 44 SkPicture::SkPicture() : fUniqueID(0) {}
29 45
30 SkPicture::~SkPicture() { 46 SkPicture::~SkPicture() {
31 // TODO: move this to ~SkBigPicture() only? 47 // TODO: move this to ~SkBigPicture() only?
32 48
33 // If the ID is still zero, no one has read it, so no need to send this mess age. 49 // 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); 50 uint32_t id = sk_atomic_load(&fUniqueID, sk_memory_order_relaxed);
35 if (id != 0) { 51 if (id != 0) {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 const SkReadBuffer* buffer) { 150 const SkReadBuffer* buffer) {
135 if (!data) { 151 if (!data) {
136 return nullptr; 152 return nullptr;
137 } 153 }
138 SkPicturePlayback playback(data); 154 SkPicturePlayback playback(data);
139 SkPictureRecorder r; 155 SkPictureRecorder r;
140 playback.draw(r.beginRecording(info.fCullRect), nullptr/*no callback*/, buff er); 156 playback.draw(r.beginRecording(info.fCullRect), nullptr/*no callback*/, buff er);
141 return r.finishRecordingAsPicture(); 157 return r.finishRecordingAsPicture();
142 } 158 }
143 159
160 #ifdef SK_SUPPORT_LEGACY_PICTUREINSTALLPIXELREF
144 static bool default_install(const void* src, size_t length, SkBitmap* dst) { 161 static bool default_install(const void* src, size_t length, SkBitmap* dst) {
145 sk_sp<SkData> encoded(SkData::MakeWithCopy(src, length)); 162 sk_sp<SkData> encoded(SkData::MakeWithCopy(src, length));
146 return encoded && SkDEPRECATED_InstallDiscardablePixelRef( 163 return encoded && SkDEPRECATED_InstallDiscardablePixelRef(
147 SkImageGenerator::NewFromEncoded(encoded.get()), dst); 164 SkImageGenerator::NewFromEncoded(encoded.get()), dst);
148 } 165 }
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) { 166 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc) {
155 return MakeFromStream(stream, proc, nullptr); 167 return MakeFromStream(stream, proc, nullptr);
156 } 168 }
169 #endif
157 170
158 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc, 171 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer * factory) {
172 return MakeFromStream(stream, factory, nullptr);
173 }
174
175 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream) {
176 SkImageDeserializer factory;
177 return MakeFromStream(stream, &factory);
178 }
179
180 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer * factory,
159 SkTypefacePlayback* typefaces) { 181 SkTypefacePlayback* typefaces) {
160 SkPictInfo info; 182 SkPictInfo info;
161 if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) { 183 if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) {
162 return nullptr; 184 return nullptr;
163 } 185 }
164 SkAutoTDelete<SkPictureData> data( 186 SkAutoTDelete<SkPictureData> data(
165 SkPictureData::CreateFromStream(stream, info, proc, typefaces)); 187 SkPictureData::CreateFromStream(stream, info, factory, typefaces));
166 return Forwardport(info, data, nullptr); 188 return Forwardport(info, data, nullptr);
167 } 189 }
168 190
169 sk_sp<SkPicture> SkPicture::MakeFromBuffer(SkReadBuffer& buffer) { 191 sk_sp<SkPicture> SkPicture::MakeFromBuffer(SkReadBuffer& buffer) {
170 SkPictInfo info; 192 SkPictInfo info;
171 if (!InternalOnly_BufferIsSKP(&buffer, &info) || !buffer.readBool()) { 193 if (!InternalOnly_BufferIsSKP(&buffer, &info) || !buffer.readBool()) {
172 return nullptr; 194 return nullptr;
173 } 195 }
174 SkAutoTDelete<SkPictureData> data(SkPictureData::CreateFromBuffer(buffer, in fo)); 196 SkAutoTDelete<SkPictureData> data(SkPictureData::CreateFromBuffer(buffer, in fo));
175 return Forwardport(info, data, &buffer); 197 return Forwardport(info, data, &buffer);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 #endif 252 #endif
231 253
232 // Global setting to disable security precautions for serialization. 254 // Global setting to disable security precautions for serialization.
233 void SkPicture::SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set) { 255 void SkPicture::SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set) {
234 g_AllPictureIOSecurityPrecautionsEnabled = set; 256 g_AllPictureIOSecurityPrecautionsEnabled = set;
235 } 257 }
236 258
237 bool SkPicture::PictureIOSecurityPrecautionsEnabled() { 259 bool SkPicture::PictureIOSecurityPrecautionsEnabled() {
238 return g_AllPictureIOSecurityPrecautionsEnabled; 260 return g_AllPictureIOSecurityPrecautionsEnabled;
239 } 261 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698