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
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 3db7582..de9ee76 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -589,7 +589,7 @@
if (!err.isEmpty()) {
return err;
}
- SkAutoTUnref<SkPicture> pic(recorder.endRecording());
+ SkAutoTUnref<SkPicture> 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 @@
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<SkPicture> 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