Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "SkImageGenerator.h" | 9 #include "SkImageGenerator.h" |
| 10 #include "SkMessageBus.h" | 10 #include "SkMessageBus.h" |
| 11 #include "SkPicture.h" | 11 #include "SkPicture.h" |
| 12 #include "SkPictureData.h" | 12 #include "SkPictureData.h" |
| 13 #include "SkPicturePlayback.h" | 13 #include "SkPicturePlayback.h" |
| 14 #include "SkPictureRecord.h" | 14 #include "SkPictureRecord.h" |
| 15 #include "SkPictureRecorder.h" | 15 #include "SkPictureRecorder.h" |
| 16 | 16 |
| 17 #if defined(SK_DISALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS) || \ | 17 #if defined(SK_DISALLOW_CROSSPROCESS_PICTUREIMAGEFILTERS) || \ |
| 18 defined(SK_ENABLE_PICTURE_IO_SECURITY_PRECAUTIONS) | 18 defined(SK_ENABLE_PICTURE_IO_SECURITY_PRECAUTIONS) |
| 19 static bool g_AllPictureIOSecurityPrecautionsEnabled = true; | 19 static bool g_AllPictureIOSecurityPrecautionsEnabled = true; |
| 20 #else | 20 #else |
| 21 static bool g_AllPictureIOSecurityPrecautionsEnabled = false; | 21 static bool g_AllPictureIOSecurityPrecautionsEnabled = false; |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 DECLARE_SKMESSAGEBUS_MESSAGE(SkPicture::DeletionMessage); | 24 DECLARE_SKMESSAGEBUS_MESSAGE(SkPicture::DeletionMessage); |
| 25 | 25 |
| 26 class DefaultImageDeserializer : public SkImageDeserializer { | |
| 27 public: | |
| 28 sk_sp<SkImage> deserialize(sk_sp<SkData> encoded, const SkIRect* subset) ove rride { | |
| 29 return SkImage::MakeFromEncoded(std::move(encoded), subset); | |
| 30 } | |
| 31 }; | |
| 32 | |
| 33 class InstallProcImageDeserializer : public SkImageDeserializer { | |
| 34 SkPicture::InstallPixelRefProc fProc; | |
| 35 public: | |
| 36 InstallProcImageDeserializer(SkPicture::InstallPixelRefProc proc) : fProc(pr oc) {} | |
| 37 | |
| 38 sk_sp<SkImage> deserialize(sk_sp<SkData> encoded, const SkIRect* subset) ove rride { | |
| 39 SkBitmap bitmap; | |
| 40 if (fProc(encoded->data(), encoded->size(), &bitmap)) { | |
| 41 return SkImage::MakeFromBitmap(bitmap); | |
|
f(malita)
2016/07/26 21:29:43
bitmap.setImmutable first to avoid a copy?
reed1
2016/07/29 13:12:04
Done.
| |
| 42 } | |
| 43 return nullptr; | |
| 44 } | |
| 45 }; | |
| 46 | |
| 26 /* SkPicture impl. This handles generic responsibilities like unique IDs and se rialization. */ | 47 /* SkPicture impl. This handles generic responsibilities like unique IDs and se rialization. */ |
| 27 | 48 |
| 28 SkPicture::SkPicture() : fUniqueID(0) {} | 49 SkPicture::SkPicture() : fUniqueID(0) {} |
| 29 | 50 |
| 30 SkPicture::~SkPicture() { | 51 SkPicture::~SkPicture() { |
| 31 // TODO: move this to ~SkBigPicture() only? | 52 // TODO: move this to ~SkBigPicture() only? |
| 32 | 53 |
| 33 // If the ID is still zero, no one has read it, so no need to send this mess age. | 54 // 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); | 55 uint32_t id = sk_atomic_load(&fUniqueID, sk_memory_order_relaxed); |
| 35 if (id != 0) { | 56 if (id != 0) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 const SkReadBuffer* buffer) { | 155 const SkReadBuffer* buffer) { |
| 135 if (!data) { | 156 if (!data) { |
| 136 return nullptr; | 157 return nullptr; |
| 137 } | 158 } |
| 138 SkPicturePlayback playback(data); | 159 SkPicturePlayback playback(data); |
| 139 SkPictureRecorder r; | 160 SkPictureRecorder r; |
| 140 playback.draw(r.beginRecording(info.fCullRect), nullptr/*no callback*/, buff er); | 161 playback.draw(r.beginRecording(info.fCullRect), nullptr/*no callback*/, buff er); |
| 141 return r.finishRecordingAsPicture(); | 162 return r.finishRecordingAsPicture(); |
| 142 } | 163 } |
| 143 | 164 |
| 165 #ifdef SK_SUPPORT_LEGACY_PICTUREINSTALLPIXELREF | |
| 144 static bool default_install(const void* src, size_t length, SkBitmap* dst) { | 166 static bool default_install(const void* src, size_t length, SkBitmap* dst) { |
| 145 sk_sp<SkData> encoded(SkData::MakeWithCopy(src, length)); | 167 sk_sp<SkData> encoded(SkData::MakeWithCopy(src, length)); |
| 146 return encoded && SkDEPRECATED_InstallDiscardablePixelRef( | 168 return encoded && SkDEPRECATED_InstallDiscardablePixelRef( |
| 147 SkImageGenerator::NewFromEncoded(encoded.get()), dst); | 169 SkImageGenerator::NewFromEncoded(encoded.get()), dst); |
| 148 } | 170 } |
| 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) { | 171 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc) { |
| 155 return MakeFromStream(stream, proc, nullptr); | 172 return MakeFromStream(stream, proc, nullptr); |
| 156 } | 173 } |
| 174 #endif | |
| 157 | 175 |
| 158 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, InstallPixelRefProc proc, | 176 sk_sp<SkPicture> SkPicture::MakeFromStreamWithDeserializer(SkStream* stream, |
| 177 SkImageDeserializer* factory) { | |
| 178 return MakeFromStream(stream, factory, nullptr); | |
| 179 } | |
| 180 | |
| 181 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream) { | |
| 182 DefaultImageDeserializer factory; | |
| 183 return MakeFromStreamWithDeserializer(stream, &factory); | |
| 184 } | |
| 185 | |
| 186 sk_sp<SkPicture> SkPicture::MakeFromStream(SkStream* stream, SkImageDeserializer * factory, | |
| 159 SkTypefacePlayback* typefaces) { | 187 SkTypefacePlayback* typefaces) { |
| 160 SkPictInfo info; | 188 SkPictInfo info; |
| 161 if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) { | 189 if (!InternalOnly_StreamIsSKP(stream, &info) || !stream->readBool()) { |
| 162 return nullptr; | 190 return nullptr; |
| 163 } | 191 } |
| 164 SkAutoTDelete<SkPictureData> data( | 192 SkAutoTDelete<SkPictureData> data( |
| 165 SkPictureData::CreateFromStream(stream, info, proc, typefaces)); | 193 SkPictureData::CreateFromStream(stream, info, factory, typefaces)); |
| 166 return Forwardport(info, data, nullptr); | 194 return Forwardport(info, data, nullptr); |
| 167 } | 195 } |
| 168 | 196 |
| 169 sk_sp<SkPicture> SkPicture::MakeFromBuffer(SkReadBuffer& buffer) { | 197 sk_sp<SkPicture> SkPicture::MakeFromBuffer(SkReadBuffer& buffer) { |
| 170 SkPictInfo info; | 198 SkPictInfo info; |
| 171 if (!InternalOnly_BufferIsSKP(&buffer, &info) || !buffer.readBool()) { | 199 if (!InternalOnly_BufferIsSKP(&buffer, &info) || !buffer.readBool()) { |
| 172 return nullptr; | 200 return nullptr; |
| 173 } | 201 } |
| 174 SkAutoTDelete<SkPictureData> data(SkPictureData::CreateFromBuffer(buffer, in fo)); | 202 SkAutoTDelete<SkPictureData> data(SkPictureData::CreateFromBuffer(buffer, in fo)); |
| 175 return Forwardport(info, data, &buffer); | 203 return Forwardport(info, data, &buffer); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 #endif | 258 #endif |
| 231 | 259 |
| 232 // Global setting to disable security precautions for serialization. | 260 // Global setting to disable security precautions for serialization. |
| 233 void SkPicture::SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set) { | 261 void SkPicture::SetPictureIOSecurityPrecautionsEnabled_Dangerous(bool set) { |
| 234 g_AllPictureIOSecurityPrecautionsEnabled = set; | 262 g_AllPictureIOSecurityPrecautionsEnabled = set; |
| 235 } | 263 } |
| 236 | 264 |
| 237 bool SkPicture::PictureIOSecurityPrecautionsEnabled() { | 265 bool SkPicture::PictureIOSecurityPrecautionsEnabled() { |
| 238 return g_AllPictureIOSecurityPrecautionsEnabled; | 266 return g_AllPictureIOSecurityPrecautionsEnabled; |
| 239 } | 267 } |
| OLD | NEW |