Chromium Code Reviews| Index: dm/DMSrcSink.cpp |
| diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp |
| index 29886807a7117b412ddce12102d6433e7dc289cd..1fb9a393d22385daffd2c88827863d4115645cae 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"); |
| @@ -1233,6 +1237,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(); |
|
mtklein
2016/01/29 18:51:54
Just curious, is this a typedef for something like
|
| + 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 |
|
mtklein
2016/01/29 18:51:54
This comment is probably no longer useful.
|
| + 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. |