aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2016-02-03 11:53:18 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-03 11:53:19 -0800
commit7a76f9c8f4de11e51b3495eec0d76be88a12adfa (patch)
tree83c20c951d1268988cf4f2c9ba37dde0e29771be /dm
parent84de5c86f9189bef758118dc12e1d6e62d06cd38 (diff)
SkMojo: test linking Skia against the Mojo SDK
TODO: build on systems other than Linux. Add mojo_skd to the DEPS. Add a DM::Via called `mojo-`. everything is hidden behind the gyp variable `skia_mojo`. GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1644043003 Review URL: https://codereview.chromium.org/1644043003
Diffstat (limited to 'dm')
-rw-r--r--dm/DM.cpp1
-rw-r--r--dm/DMSrcSink.cpp53
-rw-r--r--dm/DMSrcSink.h6
3 files changed, 60 insertions, 0 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index cdd53c6be4..538e2f6dc6 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -691,6 +691,7 @@ static Sink* create_via(const SkString& tag, Sink* wrapped) {
VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
VIA("remote", ViaRemote, false, wrapped);
VIA("remote_cache", ViaRemote, true, wrapped);
+ VIA("mojo", ViaMojo, wrapped);
if (FLAGS_matrix.count() == 4) {
SkMatrix m;
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 9712fd73a0..f5a00b5600 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.
diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h
index a719bd154a..3a7d4ee516 100644
--- a/dm/DMSrcSink.h
+++ b/dm/DMSrcSink.h
@@ -357,6 +357,12 @@ public:
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
};
+class ViaMojo : public Via {
+public:
+ explicit ViaMojo(Sink* sink) : Via(sink) {}
+ Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
+};
+
} // namespace DM
#endif//DMSrcSink_DEFINED