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

Unified Diff: dm/DMSrcSink.cpp

Issue 943383002: DM: lazy decoding on SKP playback (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-03-17 (Tuesday) 13:02:02 EDT Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dm/DMSrcSink.cpp
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 6f6664f27ce2266bd12156f1ae973cada399ec25..f678f41b61a0c10b17d666915edec61184073d17 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -2,8 +2,10 @@
#include "SamplePipeControllers.h"
#include "SkCommonFlags.h"
#include "SkCodec.h"
+#include "SkData.h"
#include "SkDocument.h"
#include "SkError.h"
+#include "SkImageGenerator.h"
#include "SkMultiPictureDraw.h"
#include "SkNullCanvas.h"
#include "SkOSFile.h"
@@ -15,6 +17,17 @@
#include "SkXMLWriter.h"
DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder");
+DEFINE_bool(deferDecode, false, "if true, defer decoding of bitmaps until they are locked.");
+
+static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
+ SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
+ return encoded && SkInstallDiscardablePixelRef(encoded, dst);
+}
+
+static SkPicture* create_picture_from_stream(SkStream* stream) {
+ return FLAGS_deferDecode ? SkPicture::CreateFromStream(stream, &lazy_decode_bitmap)
+ : SkPicture::CreateFromStream(stream);
+}
namespace DM {
@@ -83,6 +96,11 @@ Error ImageSrc::draw(SkCanvas* canvas) const {
// Everything else is considered a failure.
return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
}
+ } else if (FLAGS_deferDecode) {
+ if (!SkInstallDiscardablePixelRef(encoded, &bitmap)) {
+ return SkStringPrintf("SkInstallDiscardablePixelRef failed for %s.",
+ fPath.c_str());
+ }
} else {
if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
@@ -151,6 +169,10 @@ SkISize ImageSrc::size() const {
return SkISize::Make(0,0);
}
return info.dimensions();
+ } else if (FLAGS_deferDecode) {
+ SkAutoTDelete<SkImageGenerator> gen(SkImageGenerator::NewFromData(encoded));
+ SkImageInfo info;
+ return gen && gen->getInfo(&info) ? info.dimensions() : SkISize::Make(0,0);
} else {
SkBitmap bitmap;
if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(),
@@ -179,7 +201,7 @@ Error SKPSrc::draw(SkCanvas* canvas) const {
if (!stream) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
}
- SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream));
+ SkAutoTUnref<SkPicture> pic(create_picture_from_stream(stream));
if (!pic) {
return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str());
}
@@ -479,7 +501,7 @@ Error ViaSerialization::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream
SkDynamicMemoryWStream wStream;
pic->serialize(&wStream);
SkAutoTDelete<SkStream> rStream(wStream.detachAsStream());
- SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream));
+ SkAutoTUnref<SkPicture> deserialized(create_picture_from_stream(rStream));
// Turn that deserialized picture into a Src, draw it into our Sink to fill bitmap or stream.
struct ProxySrc : public Src {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698