Index: dm/DMSrcSink.cpp |
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp |
index 9811f9e4268ee7eb95014d6a67fea09faa700583..7501fba7e49abd8873c790ead1e1f279f224af6c 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 { |
robertphillips
2015/05/05 14:45:42
update comment
reed1
2015/05/05 14:55:25
Done.
|
+ // We turn ourselves into another Src that draws our argument into bitmap/stream via pipe. |
mtklein
2015/05/05 14:45:30
update / delete?
reed1
2015/05/05 14:55:25
Done.
|
+ struct ProxySrc : public Src { |
+ const Src& fSrc; |
+ ProxySrc(const Src& src) : fSrc(src) {} |
+ |
+ Error draw(SkCanvas* canvas) const override { |
+ SkISize size = this->size(); |
+ SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.height()); |
mtklein
2015/05/05 14:45:30
Is it useful to have the deferred canvas match the
reed1
2015/05/05 14:55:25
Good point, I think I can use the same "info"
|
+ SkAutoTUnref<SkSurface> surface(canvas->newSurface(info)); |
+ if (!surface.get()) { |
+ return Error("can make surface for deferred canvas"); |
mtklein
2015/05/05 14:45:30
can -> can't?
reed1
2015/05/05 14:55:25
Done.
|
+ } |
+ SkAutoTDelete<SkDeferredCanvas> defcan(SkDeferredCanvas::Create(surface)); |
+ Error err = fSrc.draw(defcan); |
+ if (err.isEmpty()) { |
mtklein
2015/05/05 14:45:30
Seems like you're swallowing the error when it's n
reed1
2015/05/05 14:55:25
Done.
|
+ SkAutoTUnref<SkImage> image(defcan->newImageSnapshot()); |
+ if (image) { |
+ canvas->drawImage(image, 0, 0, NULL); |
+ } else { |
+ return Error("failed to create deferred image snapshot"); |
mtklein
2015/05/05 14:45:30
FYI, you can just write
return "Failed to create
reed1
2015/05/05 14:55:25
Acknowledged.
|
+ } |
+ } |
+ 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) {} |