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

Unified Diff: dm/DMSrcSink.cpp

Issue 1644043003: SkMojo: test linking Skia against the Mojo SDK (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix Created 4 years, 11 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') | experimental/mojo/.gitignore » ('j') | 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 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.
« no previous file with comments | « dm/DMSrcSink.h ('k') | experimental/mojo/.gitignore » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698