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

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: fix 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
« no previous file with comments | « dm/DMSrcSink.h ('k') | experimental/mojo/.gitignore » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 if (err.isEmpty()) { 1227 if (err.isEmpty()) {
1224 return err; 1228 return err;
1225 } 1229 }
1226 } 1230 }
1227 return check_against_reference(bitmap, src, fSink); 1231 return check_against_reference(bitmap, src, fSink);
1228 }); 1232 });
1229 } 1233 }
1230 1234
1231 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 1235 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1232 1236
1237 #ifdef SK_MOJO
1238 Error ViaMojo::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkS tring* log) const {
1239 SkPictureRecorder recorder;
1240 SkRect size = SkRect::Make(SkIRect::MakeSize(src.size()));
1241 Error err = src.draw(recorder.beginRecording(size));
1242 if (!err.isEmpty()) {
1243 return err;
1244 }
1245 SkAutoTUnref<SkPicture> skPicture(recorder.endRecording());
1246
1247 SkASSERT(skPicture);
1248 SkDynamicMemoryWStream buffer;
1249 skPicture->serialize(&buffer);
1250 skPicture.reset();
1251 SkMojo::FlattenedPicturePtr mojoPicture = SkMojo::FlattenedPicture::New( );
1252 mojoPicture->data.resize(buffer.bytesWritten());
1253 buffer.copyTo(mojoPicture->data.data());
1254 buffer.reset();
1255 SkASSERT(mojoPicture.get() && mojoPicture->data);
1256
1257 size_t flatSize = mojoPicture->GetSerializedSize();
1258 SkAutoMalloc storage(flatSize);
1259 if (!mojoPicture->Serialize(storage.get(), flatSize)) {
1260 return "SkMojo::FlattenedPicture::Serialize failed";
1261 }
1262 mojoPicture = SkMojo::FlattenedPicture::New();
1263 mojoPicture->Deserialize(storage.get());
1264 storage.free();
1265 if (!mojoPicture) {
1266 return "SkMojo::FlattenedPicture::Deserialize failed";
1267 }
1268 SkMemoryStream tmpStream(mojoPicture->data.data(),
1269 mojoPicture->data.size());
1270 skPicture.reset(SkPicture::CreateFromStream(&tmpStream));
1271 mojoPicture.reset();
1272 auto fn = [&](SkCanvas* canvas) -> Error {
1273 canvas->drawPicture(skPicture.get());
1274 return check_against_reference(bitmap, src, fSink);
1275 };
1276 return draw_to_canvas(fSink, bitmap, stream, log, src.size(), fn);
1277 }
1278 #else // not SK_MOJO
1279 Error ViaMojo::draw(const Src&, SkBitmap*, SkWStream*, SkString*) const {
1280 return "Mojo is missing!";
1281 }
1282 #endif
1283
1284 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
1285
1233 // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canv as. 1286 // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canv as.
1234 // Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-ty pe op. 1287 // Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-ty pe op.
1235 // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pic tures. 1288 // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pic tures.
1236 struct DrawsAsSingletonPictures { 1289 struct DrawsAsSingletonPictures {
1237 SkCanvas* fCanvas; 1290 SkCanvas* fCanvas;
1238 const SkDrawableList& fDrawables; 1291 const SkDrawableList& fDrawables;
1239 1292
1240 template <typename T> 1293 template <typename T>
1241 void draw(const T& op, SkCanvas* canvas) { 1294 void draw(const T& op, SkCanvas* canvas) {
1242 // We must pass SkMatrix::I() as our initial matrix. 1295 // We must pass SkMatrix::I() as our initial matrix.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 skr.visit<void>(i, drawsAsSingletonPictures); 1345 skr.visit<void>(i, drawsAsSingletonPictures);
1293 } 1346 }
1294 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); 1347 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
1295 1348
1296 canvas->drawPicture(macroPic); 1349 canvas->drawPicture(macroPic);
1297 return check_against_reference(bitmap, src, fSink); 1350 return check_against_reference(bitmap, src, fSink);
1298 }); 1351 });
1299 } 1352 }
1300 1353
1301 } // namespace DM 1354 } // namespace DM
OLDNEW
« 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