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 19 matching lines...) Expand all Loading... |
30 #include "SkStream.h" | 30 #include "SkStream.h" |
31 #include "SkTLogic.h" | 31 #include "SkTLogic.h" |
32 #include "SkXMLWriter.h" | 32 #include "SkXMLWriter.h" |
33 #include "SkSwizzler.h" | 33 #include "SkSwizzler.h" |
34 #include <functional> | 34 #include <functional> |
35 | 35 |
36 #if defined(SK_BUILD_FOR_WIN) | 36 #if defined(SK_BUILD_FOR_WIN) |
37 #include "SkAutoCoInitialize.h" | 37 #include "SkAutoCoInitialize.h" |
38 #endif | 38 #endif |
39 | 39 |
40 #ifdef SK_MOJO | |
41 #include "SkMojo.mojom.h" | |
42 #endif | |
43 | |
44 DEFINE_bool(multiPage, false, "For document-type backends, render the source" | 40 DEFINE_bool(multiPage, false, "For document-type backends, render the source" |
45 " into multiple pages"); | 41 " into multiple pages"); |
46 DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?"
); | 42 DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?"
); |
47 | 43 |
48 using sk_gpu_test::GrContextFactory; | 44 using sk_gpu_test::GrContextFactory; |
49 | 45 |
50 namespace DM { | 46 namespace DM { |
51 | 47 |
52 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} | 48 GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {} |
53 | 49 |
(...skipping 1334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1388 if (err.isEmpty()) { | 1384 if (err.isEmpty()) { |
1389 return err; | 1385 return err; |
1390 } | 1386 } |
1391 } | 1387 } |
1392 return check_against_reference(bitmap, src, fSink); | 1388 return check_against_reference(bitmap, src, fSink); |
1393 }); | 1389 }); |
1394 } | 1390 } |
1395 | 1391 |
1396 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 1392 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
1397 | 1393 |
1398 #ifdef SK_MOJO | |
1399 Error ViaMojo::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkS
tring* log) const { | |
1400 SkPictureRecorder recorder; | |
1401 SkRect size = SkRect::Make(SkIRect::MakeSize(src.size())); | |
1402 Error err = src.draw(recorder.beginRecording(size)); | |
1403 if (!err.isEmpty()) { | |
1404 return err; | |
1405 } | |
1406 sk_sp<SkPicture> skPicture(recorder.finishRecordingAsPicture()); | |
1407 | |
1408 SkASSERT(skPicture); | |
1409 SkDynamicMemoryWStream buffer; | |
1410 skPicture->serialize(&buffer); | |
1411 skPicture.reset(); | |
1412 SkMojo::FlattenedPicturePtr mojoPicture = SkMojo::FlattenedPicture::New(
); | |
1413 mojoPicture->data.resize(buffer.bytesWritten()); | |
1414 buffer.copyTo(mojoPicture->data.data()); | |
1415 buffer.reset(); | |
1416 SkASSERT(mojoPicture.get() && mojoPicture->data); | |
1417 | |
1418 size_t flatSize = mojoPicture->GetSerializedSize(); | |
1419 SkAutoMalloc storage(flatSize); | |
1420 if (!mojoPicture->Serialize(storage.get(), flatSize)) { | |
1421 return "SkMojo::FlattenedPicture::Serialize failed"; | |
1422 } | |
1423 mojoPicture = SkMojo::FlattenedPicture::New(); | |
1424 mojoPicture->Deserialize(storage.get()); | |
1425 storage.reset(); | |
1426 if (!mojoPicture) { | |
1427 return "SkMojo::FlattenedPicture::Deserialize failed"; | |
1428 } | |
1429 SkMemoryStream tmpStream(mojoPicture->data.data(), | |
1430 mojoPicture->data.size()); | |
1431 skPicture = SkPicture::MakeFromStream(&tmpStream); | |
1432 mojoPicture.reset(); | |
1433 auto fn = [&](SkCanvas* canvas) -> Error { | |
1434 canvas->drawPicture(skPicture.get()); | |
1435 return check_against_reference(bitmap, src, fSink); | |
1436 }; | |
1437 return draw_to_canvas(fSink, bitmap, stream, log, src.size(), fn); | |
1438 } | |
1439 #else // not SK_MOJO | |
1440 Error ViaMojo::draw(const Src&, SkBitmap*, SkWStream*, SkString*) const { | |
1441 return "Mojo is missing!"; | |
1442 } | |
1443 #endif | |
1444 | |
1445 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | |
1446 | |
1447 // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canv
as. | 1394 // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canv
as. |
1448 // Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-ty
pe op. | 1395 // Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-ty
pe op. |
1449 // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pic
tures. | 1396 // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pic
tures. |
1450 struct DrawsAsSingletonPictures { | 1397 struct DrawsAsSingletonPictures { |
1451 SkCanvas* fCanvas; | 1398 SkCanvas* fCanvas; |
1452 const SkDrawableList& fDrawables; | 1399 const SkDrawableList& fDrawables; |
1453 SkRect fBounds; | 1400 SkRect fBounds; |
1454 | 1401 |
1455 template <typename T> | 1402 template <typename T> |
1456 void draw(const T& op, SkCanvas* canvas) { | 1403 void draw(const T& op, SkCanvas* canvas) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 skr.visit(i, drawsAsSingletonPictures); | 1455 skr.visit(i, drawsAsSingletonPictures); |
1509 } | 1456 } |
1510 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1457 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
1511 | 1458 |
1512 canvas->drawPicture(macroPic); | 1459 canvas->drawPicture(macroPic); |
1513 return check_against_reference(bitmap, src, fSink); | 1460 return check_against_reference(bitmap, src, fSink); |
1514 }); | 1461 }); |
1515 } | 1462 } |
1516 | 1463 |
1517 } // namespace DM | 1464 } // namespace DM |
OLD | NEW |