| 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 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 #endif | 1443 #endif |
| 1444 | 1444 |
| 1445 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ | 1445 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~*/ |
| 1446 | 1446 |
| 1447 // This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canv
as. | 1447 // 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. | 1448 // 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. | 1449 // This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pic
tures. |
| 1450 struct DrawsAsSingletonPictures { | 1450 struct DrawsAsSingletonPictures { |
| 1451 SkCanvas* fCanvas; | 1451 SkCanvas* fCanvas; |
| 1452 const SkDrawableList& fDrawables; | 1452 const SkDrawableList& fDrawables; |
| 1453 SkRect fBounds; |
| 1453 | 1454 |
| 1454 template <typename T> | 1455 template <typename T> |
| 1455 void draw(const T& op, SkCanvas* canvas) { | 1456 void draw(const T& op, SkCanvas* canvas) { |
| 1456 // We must pass SkMatrix::I() as our initial matrix. | 1457 // We must pass SkMatrix::I() as our initial matrix. |
| 1457 // By default SkRecords::Draw() uses the canvas' matrix as its initial m
atrix, | 1458 // By default SkRecords::Draw() uses the canvas' matrix as its initial m
atrix, |
| 1458 // which would have the funky effect of applying transforms over and ove
r. | 1459 // which would have the funky effect of applying transforms over and ove
r. |
| 1459 SkRecords::Draw d(canvas, nullptr, fDrawables.begin(), fDrawables.count(
), &SkMatrix::I()); | 1460 SkRecords::Draw d(canvas, nullptr, fDrawables.begin(), fDrawables.count(
), &SkMatrix::I()); |
| 1460 d(op); | 1461 d(op); |
| 1461 } | 1462 } |
| 1462 | 1463 |
| 1463 // Draws get their own picture. | 1464 // Draws get their own picture. |
| 1464 template <typename T> | 1465 template <typename T> |
| 1465 SK_WHEN(T::kTags & SkRecords::kDraw_Tag, void) operator()(const T& op) { | 1466 SK_WHEN(T::kTags & SkRecords::kDraw_Tag, void) operator()(const T& op) { |
| 1466 SkPictureRecorder rec; | 1467 SkPictureRecorder rec; |
| 1467 this->draw(op, rec.beginRecording(SkRect::MakeLargest())); | 1468 this->draw(op, rec.beginRecording(fBounds)); |
| 1468 sk_sp<SkPicture> pic(rec.finishRecordingAsPicture()); | 1469 sk_sp<SkPicture> pic(rec.finishRecordingAsPicture()); |
| 1469 fCanvas->drawPicture(pic); | 1470 fCanvas->drawPicture(pic); |
| 1470 } | 1471 } |
| 1471 | 1472 |
| 1472 // We'll just issue non-draws directly. | 1473 // We'll just issue non-draws directly. |
| 1473 template <typename T> | 1474 template <typename T> |
| 1474 skstd::enable_if_t<!(T::kTags & SkRecords::kDraw_Tag), void> operator()(cons
t T& op) { | 1475 skstd::enable_if_t<!(T::kTags & SkRecords::kDraw_Tag), void> operator()(cons
t T& op) { |
| 1475 this->draw(op, fCanvas); | 1476 this->draw(op, fCanvas); |
| 1476 } | 1477 } |
| 1477 }; | 1478 }; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1494 SkPictureRecorder macroRec; | 1495 SkPictureRecorder macroRec; |
| 1495 SkCanvas* macroCanvas = macroRec.beginRecording(SkIntToScalar(size.width
()), | 1496 SkCanvas* macroCanvas = macroRec.beginRecording(SkIntToScalar(size.width
()), |
| 1496 SkIntToScalar(size.heigh
t())); | 1497 SkIntToScalar(size.heigh
t())); |
| 1497 | 1498 |
| 1498 SkAutoTDelete<SkDrawableList> drawables(recorder.detachDrawableList()); | 1499 SkAutoTDelete<SkDrawableList> drawables(recorder.detachDrawableList()); |
| 1499 const SkDrawableList empty; | 1500 const SkDrawableList empty; |
| 1500 | 1501 |
| 1501 DrawsAsSingletonPictures drawsAsSingletonPictures = { | 1502 DrawsAsSingletonPictures drawsAsSingletonPictures = { |
| 1502 macroCanvas, | 1503 macroCanvas, |
| 1503 drawables ? *drawables : empty, | 1504 drawables ? *drawables : empty, |
| 1505 SkRect::MakeWH((SkScalar)size.width(), (SkScalar)size.height()), |
| 1504 }; | 1506 }; |
| 1505 for (int i = 0; i < skr.count(); i++) { | 1507 for (int i = 0; i < skr.count(); i++) { |
| 1506 skr.visit(i, drawsAsSingletonPictures); | 1508 skr.visit(i, drawsAsSingletonPictures); |
| 1507 } | 1509 } |
| 1508 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); | 1510 sk_sp<SkPicture> macroPic(macroRec.finishRecordingAsPicture()); |
| 1509 | 1511 |
| 1510 canvas->drawPicture(macroPic); | 1512 canvas->drawPicture(macroPic); |
| 1511 return check_against_reference(bitmap, src, fSink); | 1513 return check_against_reference(bitmap, src, fSink); |
| 1512 }); | 1514 }); |
| 1513 } | 1515 } |
| 1514 | 1516 |
| 1515 } // namespace DM | 1517 } // namespace DM |
| OLD | NEW |