Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_EXPERIMENT | |
| 35 #include "SkMojo.mojom.h" | |
|
mtklein
2016/01/29 18:09:40
Indent this #include a bit?
hal.canary
2016/01/29 18:44:50
done
| |
| 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 Loading... | |
| 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_EXPERIMENT | |
| 1241 | |
| 1242 Error ViaMojo::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin g* log) const { | |
|
mtklein
2016/01/29 18:09:40
Let's indent the bits inside the #ifdef / #else
hal.canary
2016/01/29 18:44:50
done
| |
| 1243 SkPictureRecorder recorder; | |
| 1244 SkRect size = SkRect::Make(SkIRect::MakeSize(src.size())); | |
| 1245 Error err = src.draw(recorder.beginRecording(size)); | |
| 1246 if (!err.isEmpty()) { | |
| 1247 return err; | |
| 1248 } | |
| 1249 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); | |
| 1250 | |
| 1251 SkASSERT(picture); | |
| 1252 SkDynamicMemoryWStream buffer; | |
| 1253 picture->serialize(&buffer); | |
| 1254 auto mojoPicture = SkMojo::FlattenedPicture::New(); | |
|
mtklein
2016/01/29 18:09:40
While we're getting used to the types, let's write
hal.canary
2016/01/29 18:44:50
done
| |
| 1255 mojoPicture->data.resize(buffer.bytesWritten()); | |
| 1256 buffer.copyTo(mojoPicture->data.data()); | |
| 1257 SkASSERT(mojoPicture.get() && mojoPicture->data); | |
|
mtklein
2016/01/29 18:09:40
// TODO: serialize + deserialize FlattenedPicture
hal.canary
2016/01/29 18:44:50
the todo is done.
| |
| 1258 SkMemoryStream tmpStream(mojoPicture->data.data(), mojoPicture->data.size()) ; | |
| 1259 picture.reset(SkPicture::CreateFromStream(&tmpStream)); | |
| 1260 auto fn = [&](SkCanvas* canvas) -> Error { | |
| 1261 canvas->drawPicture(picture.get()); | |
| 1262 return check_against_reference(bitmap, src, fSink); | |
| 1263 }; | |
| 1264 return draw_to_canvas(fSink, bitmap, stream, log, src.size(), fn); | |
| 1265 } | |
| 1266 #else // not SK_MOJO_EXPERIMENT | |
| 1267 Error ViaMojo::draw(const Src&, SkBitmap*, SkWStream*, SkString*) const { | |
| 1268 return "Mojo is missing!"; | |
| 1269 } | |
| 1270 #endif | |
| 1271 | |
| 1272 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ | |
| 1273 | |
| 1236 // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canv as. | 1274 // 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. | 1275 // 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. | 1276 // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pic tures. |
| 1239 struct DrawsAsSingletonPictures { | 1277 struct DrawsAsSingletonPictures { |
| 1240 SkCanvas* fCanvas; | 1278 SkCanvas* fCanvas; |
| 1241 const SkDrawableList& fDrawables; | 1279 const SkDrawableList& fDrawables; |
| 1242 | 1280 |
| 1243 template <typename T> | 1281 template <typename T> |
| 1244 void draw(const T& op, SkCanvas* canvas) { | 1282 void draw(const T& op, SkCanvas* canvas) { |
| 1245 // We must pass SkMatrix::I() as our initial matrix. | 1283 // We must pass SkMatrix::I() as our initial matrix. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1295 skr.visit<void>(i, drawsAsSingletonPictures); | 1333 skr.visit<void>(i, drawsAsSingletonPictures); |
| 1296 } | 1334 } |
| 1297 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); | 1335 SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture()); |
| 1298 | 1336 |
| 1299 canvas->drawPicture(macroPic); | 1337 canvas->drawPicture(macroPic); |
| 1300 return check_against_reference(bitmap, src, fSink); | 1338 return check_against_reference(bitmap, src, fSink); |
| 1301 }); | 1339 }); |
| 1302 } | 1340 } |
| 1303 | 1341 |
| 1304 } // namespace DM | 1342 } // namespace DM |
| OLD | NEW |