Index: dm/DMSrcSink.cpp |
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp |
index 9712fd73a024d2723dd3fa30d0c7956fdbd0f823..f5a00b5600df277a8f54ed16ecf2211c266a8cef 100644 |
--- a/dm/DMSrcSink.cpp |
+++ b/dm/DMSrcSink.cpp |
@@ -31,6 +31,10 @@ |
#include "SkSwizzler.h" |
#include <functional> |
+#ifdef SK_MOJO |
+ #include "SkMojo.mojom.h" |
+#endif |
+ |
DEFINE_bool(multiPage, false, "For document-type backends, render the source" |
" into multiple pages"); |
@@ -1230,6 +1234,55 @@ Error ViaTwice::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri |
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
+#ifdef SK_MOJO |
+ Error ViaMojo::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const { |
+ SkPictureRecorder recorder; |
+ SkRect size = SkRect::Make(SkIRect::MakeSize(src.size())); |
+ Error err = src.draw(recorder.beginRecording(size)); |
+ if (!err.isEmpty()) { |
+ return err; |
+ } |
+ SkAutoTUnref<SkPicture> skPicture(recorder.endRecording()); |
+ |
+ SkASSERT(skPicture); |
+ SkDynamicMemoryWStream buffer; |
+ skPicture->serialize(&buffer); |
+ skPicture.reset(); |
+ SkMojo::FlattenedPicturePtr mojoPicture = SkMojo::FlattenedPicture::New(); |
+ mojoPicture->data.resize(buffer.bytesWritten()); |
+ buffer.copyTo(mojoPicture->data.data()); |
+ buffer.reset(); |
+ SkASSERT(mojoPicture.get() && mojoPicture->data); |
+ |
+ size_t flatSize = mojoPicture->GetSerializedSize(); |
+ SkAutoMalloc storage(flatSize); |
+ if (!mojoPicture->Serialize(storage.get(), flatSize)) { |
+ return "SkMojo::FlattenedPicture::Serialize failed"; |
+ } |
+ mojoPicture = SkMojo::FlattenedPicture::New(); |
+ mojoPicture->Deserialize(storage.get()); |
+ storage.free(); |
+ if (!mojoPicture) { |
+ return "SkMojo::FlattenedPicture::Deserialize failed"; |
+ } |
+ SkMemoryStream tmpStream(mojoPicture->data.data(), |
+ mojoPicture->data.size()); |
+ skPicture.reset(SkPicture::CreateFromStream(&tmpStream)); |
+ mojoPicture.reset(); |
+ auto fn = [&](SkCanvas* canvas) -> Error { |
+ canvas->drawPicture(skPicture.get()); |
+ return check_against_reference(bitmap, src, fSink); |
+ }; |
+ return draw_to_canvas(fSink, bitmap, stream, log, src.size(), fn); |
+ } |
+#else // not SK_MOJO |
+ Error ViaMojo::draw(const Src&, SkBitmap*, SkWStream*, SkString*) const { |
+ return "Mojo is missing!"; |
+ } |
+#endif |
+ |
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
+ |
// This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canvas. |
// Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-type op. |
// This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pictures. |