From b7e8d69fc21a3043348fd9b76876471e0a6ae7fe Mon Sep 17 00:00:00 2001 From: mtklein Date: Tue, 7 Apr 2015 08:30:32 -0700 Subject: Add a Via to DM that records into two pictures and draws using the second. I'm going to start hacking on SkCanvas a bit to allow a fast reset method, and I want to have some testing checking me. BUG=skia: Review URL: https://codereview.chromium.org/1062043004 --- dm/DM.cpp | 1 + dm/DMSrcSink.cpp | 35 ++++++++++++++++++++++++++++++++++- dm/DMSrcSink.h | 11 +++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/dm/DM.cpp b/dm/DM.cpp index 3ad82262c4..5d85e22b3a 100644 --- a/dm/DM.cpp +++ b/dm/DM.cpp @@ -320,6 +320,7 @@ static Sink* create_via(const char* tag, Sink* wrapped) { #define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); } VIA("pipe", ViaPipe, wrapped); VIA("serialize", ViaSerialization, wrapped); + VIA("2ndpic", ViaSecondPicture, wrapped); VIA("tiles", ViaTiles, 256, 256, NULL, wrapped); VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 3db7582aa1..de9ee76c80 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -589,7 +589,7 @@ Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri if (!err.isEmpty()) { return err; } - SkAutoTUnref pic(recorder.endRecording()); + SkAutoTUnref pic(recorder.endRecordingAsPicture()); // Turn that picture into a Src that draws into our Sink via tiles + MPD. struct ProxySrc : public Src { @@ -638,4 +638,37 @@ Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri return fSink->draw(proxy, bitmap, stream, log); } +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ + +ViaSecondPicture::ViaSecondPicture(Sink* sink) : fSink(sink) {} + +// Draw the Src into two pictures, then draw the second picture into the wrapped Sink. +// This tests that any shortcuts we may take while recording that second picture are legal. +Error ViaSecondPicture::draw( + const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { + struct ProxySrc : public Src { + const Src& fSrc; + ProxySrc(const Src& src) : fSrc(src) {} + + Error draw(SkCanvas* canvas) const override { + SkSize size; + size = fSrc.size(); + SkPictureRecorder recorder; + SkAutoTUnref pic; + for (int i = 0; i < 2; i++) { + Error err = fSrc.draw(recorder.beginRecording(size.width(), size.height())); + if (!err.isEmpty()) { + return err; + } + pic.reset(recorder.endRecordingAsPicture()); + } + canvas->drawPicture(pic); + return ""; + } + SkISize size() const override { return fSrc.size(); } + Name name() const override { sk_throw(); return ""; } // No one should be calling this. + } proxy(src); + return fSink->draw(proxy, bitmap, stream, log); +} + } // namespace DM diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h index 2c21e87ef6..57af911062 100644 --- a/dm/DMSrcSink.h +++ b/dm/DMSrcSink.h @@ -266,6 +266,17 @@ private: SkAutoTDelete fSink; }; +class ViaSecondPicture : public Sink { +public: + explicit ViaSecondPicture(Sink*); + + Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; + int enclave() const override { return fSink->enclave(); } + const char* fileExtension() const override { return fSink->fileExtension(); } +private: + SkAutoTDelete fSink; +}; + } // namespace DM #endif//DMSrcSink_DEFINED -- cgit v1.2.3