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

Unified Diff: dm/DMSrcSink.cpp

Issue 1113273006: add deferred config to DM (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update dox, use orig colortype Created 5 years, 7 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 | « dm/DMSrcSink.h ('k') | 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 9811f9e4268ee7eb95014d6a67fea09faa700583..b33ba14b66dc2b97fb2abbbdecb478c401e551e8 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -10,6 +10,7 @@
#include "SkCommonFlags.h"
#include "SkCodec.h"
#include "SkData.h"
+#include "SkDeferredCanvas.h"
#include "SkDocument.h"
#include "SkError.h"
#include "SkImageGenerator.h"
@@ -590,6 +591,41 @@ Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+ViaDeferred::ViaDeferred(Sink* sink) : fSink(sink) {}
+
+Error ViaDeferred::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
+ // We turn ourselves into another Src that draws our argument into a deferred canvas,
+ // via a surface created by the original canvas. We then draw a snapped image from that
+ // surface back into the original canvas.
+ struct ProxySrc : public Src {
+ const Src& fSrc;
+ ProxySrc(const Src& src) : fSrc(src) {}
+
+ Error draw(SkCanvas* canvas) const override {
+ SkAutoTUnref<SkSurface> surface(canvas->newSurface(canvas->imageInfo()));
+ if (!surface.get()) {
+ return "can't make surface for deferred canvas";
+ }
+ SkAutoTDelete<SkDeferredCanvas> defcan(SkDeferredCanvas::Create(surface));
+ Error err = fSrc.draw(defcan);
+ if (!err.isEmpty()) {
+ return err;
+ }
+ SkAutoTUnref<SkImage> image(defcan->newImageSnapshot());
+ if (!image) {
+ return "failed to create deferred image snapshot";
+ }
+ canvas->drawImage(image, 0, 0, NULL);
+ 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);
+}
+
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
ViaSerialization::ViaSerialization(Sink* sink) : fSink(sink) {}
« no previous file with comments | « dm/DMSrcSink.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698