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

Side by Side 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: more replies to mtklein@ Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "DMSrcSink.h" 8 #include "DMSrcSink.h"
9 #include "SkAndroidCodec.h" 9 #include "SkAndroidCodec.h"
10 #include "SkCodec.h" 10 #include "SkCodec.h"
(...skipping 13 matching lines...) Expand all
24 #include "SkRecordDraw.h" 24 #include "SkRecordDraw.h"
25 #include "SkRecorder.h" 25 #include "SkRecorder.h"
26 #include "SkRemote.h" 26 #include "SkRemote.h"
27 #include "SkSVGCanvas.h" 27 #include "SkSVGCanvas.h"
28 #include "SkStream.h" 28 #include "SkStream.h"
29 #include "SkTLogic.h" 29 #include "SkTLogic.h"
30 #include "SkXMLWriter.h" 30 #include "SkXMLWriter.h"
31 #include "SkSwizzler.h" 31 #include "SkSwizzler.h"
32 #include <functional> 32 #include <functional>
33 33
34 #ifdef SK_MOJO
35 #include "SkMojo.mojom.h"
36 #endif
37
34 DEFINE_bool(multiPage, false, "For document-type backends, render the source" 38 DEFINE_bool(multiPage, false, "For document-type backends, render the source"
35 " into multiple pages"); 39 " into multiple pages");
36 40
37 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { 41 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
38 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); 42 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
39 return encoded && SkDEPRECATED_InstallDiscardablePixelRef(encoded, dst); 43 return encoded && SkDEPRECATED_InstallDiscardablePixelRef(encoded, dst);
40 } 44 }
41 45
42 namespace DM { 46 namespace DM {
43 47
(...skipping 1182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 if (err.isEmpty()) { 1230 if (err.isEmpty()) {
1227 return err; 1231 return err;
1228 } 1232 }
1229 } 1233 }
1230 return check_against_reference(bitmap, src, fSink); 1234 return check_against_reference(bitmap, src, fSink);
1231 }); 1235 });
1232 } 1236 }
1233 1237
1234 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 1238 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1235 1239
1240 #ifdef SK_MOJO
1241 Error ViaMojo::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkS tring* log) const {
1242 SkPictureRecorder recorder;
1243 SkRect size = SkRect::Make(SkIRect::MakeSize(src.size()));
1244 Error err = src.draw(recorder.beginRecording(size));
1245 if (!err.isEmpty()) {
1246 return err;
1247 }
1248 SkAutoTUnref<SkPicture> skPicture(recorder.endRecording());
1249
1250 SkASSERT(skPicture);
1251 SkDynamicMemoryWStream buffer;
1252 skPicture->serialize(&buffer);
1253 skPicture.reset();
1254 SkMojo::FlattenedPicturePtr mojoPicture = SkMojo::FlattenedPicture::New( );
mtklein 2016/01/29 18:51:54 Just curious, is this a typedef for something like
1255 mojoPicture->data.resize(buffer.bytesWritten());
1256 buffer.copyTo(mojoPicture->data.data());
1257 buffer.reset();
1258 SkASSERT(mojoPicture.get() && mojoPicture->data);
1259
1260 size_t flatSize = mojoPicture->GetSerializedSize();
1261 SkAutoMalloc storage(flatSize);
1262 if (!mojoPicture->Serialize(storage.get(), flatSize)) {
1263 return "SkMojo::FlattenedPicture::Serialize failed";
1264 }
1265 mojoPicture = SkMojo::FlattenedPicture::New();
1266 mojoPicture->Deserialize(storage.get());
1267 storage.free();
1268 if (!mojoPicture) {
1269 return "SkMojo::FlattenedPicture::Deserialize failed";
1270 }
1271 SkMemoryStream tmpStream(mojoPicture->data.data(),
1272 mojoPicture->data.size());
1273 skPicture.reset(SkPicture::CreateFromStream(&tmpStream));
1274 mojoPicture.reset();
1275 auto fn = [&](SkCanvas* canvas) -> Error {
1276 canvas->drawPicture(skPicture.get());
1277 return check_against_reference(bitmap, src, fSink);
1278 };
1279 return draw_to_canvas(fSink, bitmap, stream, log, src.size(), fn);
1280 }
1281 #else // not SK_MOJO
mtklein 2016/01/29 18:51:54 This comment is probably no longer useful.
1282 Error ViaMojo::draw(const Src&, SkBitmap*, SkWStream*, SkString*) const {
1283 return "Mojo is missing!";
1284 }
1285 #endif
1286
1287 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1288
1236 // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canv as. 1289 // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canv as.
1237 // Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-ty pe op. 1290 // Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-ty pe op.
1238 // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pic tures. 1291 // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pic tures.
1239 struct DrawsAsSingletonPictures { 1292 struct DrawsAsSingletonPictures {
1240 SkCanvas* fCanvas; 1293 SkCanvas* fCanvas;
1241 const SkDrawableList& fDrawables; 1294 const SkDrawableList& fDrawables;
1242 1295
1243 template <typename T> 1296 template <typename T>
1244 void draw(const T& op, SkCanvas* canvas) { 1297 void draw(const T& op, SkCanvas* canvas) {
1245 // We must pass SkMatrix::I() as our initial matrix. 1298 // We must pass SkMatrix::I() as our initial matrix.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 skr.visit<void>(i, drawsAsSingletonPictures); 1348 skr.visit<void>(i, drawsAsSingletonPictures);
1296 } 1349 }
1297 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1350 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1298 1351
1299 canvas->drawPicture(macroPic); 1352 canvas->drawPicture(macroPic);
1300 return check_against_reference(bitmap, src, fSink); 1353 return check_against_reference(bitmap, src, fSink);
1301 }); 1354 });
1302 } 1355 }
1303 1356
1304 } // namespace DM 1357 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMSrcSink.h ('k') | experimental/mojo/.gitignore » ('j') | gyp/skmojo.gyp » ('J')

Powered by Google App Engine
This is Rietveld 408576698