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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1123743007: DM: add draw_to_canvas() to trim some boilerplate for Vias. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Don't mess with Android. Created 5 years, 7 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 | « no previous file | no next file » | 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 "SamplePipeControllers.h" 9 #include "SamplePipeControllers.h"
10 #include "SkCodec.h"
10 #include "SkCommonFlags.h" 11 #include "SkCommonFlags.h"
11 #include "SkCodec.h"
12 #include "SkData.h" 12 #include "SkData.h"
13 #include "SkDeferredCanvas.h" 13 #include "SkDeferredCanvas.h"
14 #include "SkDocument.h" 14 #include "SkDocument.h"
15 #include "SkError.h" 15 #include "SkError.h"
16 #include "SkImageGenerator.h" 16 #include "SkImageGenerator.h"
17 #include "SkMultiPictureDraw.h" 17 #include "SkMultiPictureDraw.h"
18 #include "SkNullCanvas.h" 18 #include "SkNullCanvas.h"
19 #include "SkOSFile.h" 19 #include "SkOSFile.h"
20 #include "SkPictureData.h" 20 #include "SkPictureData.h"
21 #include "SkPictureRecorder.h" 21 #include "SkPictureRecorder.h"
22 #include "SkRandom.h" 22 #include "SkRandom.h"
23 #include "SkSVGCanvas.h"
23 #include "SkScanlineDecoder.h" 24 #include "SkScanlineDecoder.h"
24 #include "SkSVGCanvas.h"
25 #include "SkStream.h" 25 #include "SkStream.h"
26 #include "SkXMLWriter.h" 26 #include "SkXMLWriter.h"
27 27
28 DEFINE_bool(multiPage, false, "For document-type backends, render the source" 28 DEFINE_bool(multiPage, false, "For document-type backends, render the source"
29 " into multiple pages"); 29 " into multiple pages");
30 30
31 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) { 31 static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
32 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size)); 32 SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
33 return encoded && SkInstallDiscardablePixelRef(encoded, dst); 33 return encoded && SkInstallDiscardablePixelRef(encoded, dst);
34 } 34 }
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); 495 (void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType);
496 496
497 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType, alphaType)); 497 dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType, alphaType));
498 dst->eraseColor(SK_ColorTRANSPARENT); 498 dst->eraseColor(SK_ColorTRANSPARENT);
499 SkCanvas canvas(*dst); 499 SkCanvas canvas(*dst);
500 return src.draw(&canvas); 500 return src.draw(&canvas);
501 } 501 }
502 502
503 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 503 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
504 504
505 // Handy for front-patching a Src. Do whatever up-front work you need, then cal l draw_to_canvas(),
506 // passing the Sink draw() arguments, a size, and a lambda that takes SkCanvas* and returns Error.
507 // Several examples below.
508
509 template <typename DrawFn>
510 static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkS tring* log,
511 SkISize size, DrawFn draw) {
512 class ProxySrc : public Src {
513 public:
514 ProxySrc(SkISize size, DrawFn draw) : fSize(size), fDraw(draw) {}
515 Error draw(SkCanvas* canvas) const override { return fDraw(canvas); }
516 Name name() const override { sk_throw(); return ""; } // Won't be called.
517 SkISize size() const override { return fSize; }
518 private:
519 SkISize fSize;
520 DrawFn fDraw;
521 };
522 return sink->draw(ProxySrc(size, draw), bitmap, stream, log);
523 }
524
525 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
526
505 static SkISize auto_compute_translate(SkMatrix* matrix, int srcW, int srcH) { 527 static SkISize auto_compute_translate(SkMatrix* matrix, int srcW, int srcH) {
506 SkRect bounds = SkRect::MakeIWH(srcW, srcH); 528 SkRect bounds = SkRect::MakeIWH(srcW, srcH);
507 matrix->mapRect(&bounds); 529 matrix->mapRect(&bounds);
508 matrix->postTranslate(-bounds.x(), -bounds.y()); 530 matrix->postTranslate(-bounds.x(), -bounds.y());
509 return SkISize::Make(SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt( bounds.height())); 531 return SkISize::Make(SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt( bounds.height()));
510 } 532 }
511 533
512 ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sink) {} 534 ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sink) {}
513 535
514 Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStr ing* log) const { 536 Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStr ing* log) const {
515 // We turn our arguments into a Src, then draw that Src into our Sink to fil l bitmap or stream. 537 SkMatrix matrix = fMatrix;
516 struct ProxySrc : public Src { 538 SkISize size = auto_compute_translate(&matrix, src.size().width(), src.size( ).height());
517 const Src& fSrc; 539 return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas ) {
518 SkMatrix fMatrix; 540 canvas->concat(matrix);
519 SkISize fSize; 541 return src.draw(canvas);
520 542 });
521 ProxySrc(const Src& src, SkMatrix matrix) : fSrc(src), fMatrix(matrix) {
522 fSize = auto_compute_translate(&fMatrix, src.size().width(), src.siz e().height());
523 }
524
525 Error draw(SkCanvas* canvas) const override {
526 canvas->concat(fMatrix);
527 return fSrc.draw(canvas);
528 }
529 SkISize size() const override { return fSize; }
530 Name name() const override { sk_throw(); return ""; } // No one should be calling this.
531 } proxy(src, fMatrix);
532 return fSink->draw(proxy, bitmap, stream, log);
533 } 543 }
534 544
535 // Undoes any flip or 90 degree rotate without changing the scale of the bitmap. 545 // Undoes any flip or 90 degree rotate without changing the scale of the bitmap.
536 // This should be pixel-preserving. 546 // This should be pixel-preserving.
537 ViaUpright::ViaUpright(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sin k) {} 547 ViaUpright::ViaUpright(SkMatrix matrix, Sink* sink) : fMatrix(matrix), fSink(sin k) {}
538 548
539 Error ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt ring* log) const { 549 Error ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt ring* log) const {
540 Error err = fSink->draw(src, bitmap, stream, log); 550 Error err = fSink->draw(src, bitmap, stream, log);
541 if (!err.isEmpty()) { 551 if (!err.isEmpty()) {
542 return err; 552 return err;
(...skipping 22 matching lines...) Expand all
565 *bitmap = uprighted; 575 *bitmap = uprighted;
566 bitmap->lockPixels(); 576 bitmap->lockPixels();
567 return ""; 577 return "";
568 } 578 }
569 579
570 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 580 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
571 581
572 ViaPipe::ViaPipe(Sink* sink) : fSink(sink) {} 582 ViaPipe::ViaPipe(Sink* sink) : fSink(sink) {}
573 583
574 Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin g* log) const { 584 Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStrin g* log) const {
575 // We turn ourselves into another Src that draws our argument into bitmap/st ream via pipe. 585 auto size = src.size();
576 struct ProxySrc : public Src { 586 return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas ) {
577 const Src& fSrc; 587 PipeController controller(canvas, &SkImageDecoder::DecodeMemory);
578 ProxySrc(const Src& src) : fSrc(src) {} 588 SkGPipeWriter pipe;
579 589 const uint32_t kFlags = 0; // We mirror SkDeferredCanvas, which doesn't use any flags.
580 Error draw(SkCanvas* canvas) const override { 590 return src.draw(pipe.startRecording(&controller, kFlags, size.width(), s ize.height()));
581 SkISize size = this->size(); 591 });
582 PipeController controller(canvas, &SkImageDecoder::DecodeMemory);
583 SkGPipeWriter pipe;
584 const uint32_t kFlags = 0; // We mirror SkDeferredCanvas, which does n't use any flags.
585 return fSrc.draw(pipe.startRecording(&controller, kFlags, size.width (), size.height()));
586 }
587 SkISize size() const override { return fSrc.size(); }
588 Name name() const override { sk_throw(); return ""; } // No one should be calling this.
589 } proxy(src);
590 return fSink->draw(proxy, bitmap, stream, log);
591 } 592 }
592 593
593 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 594 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
594 595
595 ViaDeferred::ViaDeferred(Sink* sink) : fSink(sink) {} 596 ViaDeferred::ViaDeferred(Sink* sink) : fSink(sink) {}
596 597
597 Error ViaDeferred::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkS tring* log) const { 598 Error ViaDeferred::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkS tring* log) const {
598 // We turn ourselves into another Src that draws our argument into a deferre d canvas, 599 // We draw via a deferred canvas into a surface that's compatible with the o riginal canvas,
599 // via a surface created by the original canvas. We then draw a snapped imag e from that 600 // then snap that surface as an image and draw it into the original canvas.
600 // surface back into the original canvas. 601 return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) -> Error {
601 struct ProxySrc : public Src { 602 SkAutoTUnref<SkSurface> surface(canvas->newSurface(canvas->imageInfo())) ;
602 const Src& fSrc; 603 if (!surface.get()) {
603 ProxySrc(const Src& src) : fSrc(src) {} 604 return "can't make surface for deferred canvas";
605 }
606 SkAutoTDelete<SkDeferredCanvas> defcan(SkDeferredCanvas::Create(surface) );
607 Error err = src.draw(defcan);
608 if (!err.isEmpty()) {
609 return err;
610 }
611 SkAutoTUnref<SkImage> image(defcan->newImageSnapshot());
612 if (!image) {
613 return "failed to create deferred image snapshot";
614 }
615 canvas->drawImage(image, 0, 0, NULL);
616 return "";
617 });
618 }
604 619
605 Error draw(SkCanvas* canvas) const override {
606 SkAutoTUnref<SkSurface> surface(canvas->newSurface(canvas->imageInfo ()));
607 if (!surface.get()) {
608 return "can't make surface for deferred canvas";
609 }
610 SkAutoTDelete<SkDeferredCanvas> defcan(SkDeferredCanvas::Create(surf ace));
611 Error err = fSrc.draw(defcan);
612 if (!err.isEmpty()) {
613 return err;
614 }
615 SkAutoTUnref<SkImage> image(defcan->newImageSnapshot());
616 if (!image) {
617 return "failed to create deferred image snapshot";
618 }
619 canvas->drawImage(image, 0, 0, NULL);
620 return "";
621 }
622 SkISize size() const override { return fSrc.size(); }
623 Name name() const override { sk_throw(); return ""; } // No one should be calling this.
624 } proxy(src);
625 return fSink->draw(proxy, bitmap, stream, log);
626 }
627
628 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 620 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
629 621
630 ViaSerialization::ViaSerialization(Sink* sink) : fSink(sink) {} 622 ViaSerialization::ViaSerialization(Sink* sink) : fSink(sink) {}
631 623
632 Error ViaSerialization::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream , SkString* log) 624 Error ViaSerialization::draw(
633 const { 625 const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) cons t {
634 // Record our Src into a picture. 626 // Record our Src into a picture.
635 SkSize size; 627 auto size = src.size();
636 size = src.size();
637 SkPictureRecorder recorder; 628 SkPictureRecorder recorder;
638 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); 629 Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
630 SkIntToScalar(size.height())));
639 if (!err.isEmpty()) { 631 if (!err.isEmpty()) {
640 return err; 632 return err;
641 } 633 }
642 SkAutoTUnref<SkPicture> pic(recorder.endRecording()); 634 SkAutoTUnref<SkPicture> pic(recorder.endRecording());
643 635
644 // Serialize it and then deserialize it. 636 // Serialize it and then deserialize it.
645 SkDynamicMemoryWStream wStream; 637 SkDynamicMemoryWStream wStream;
646 pic->serialize(&wStream); 638 pic->serialize(&wStream);
647 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream()); 639 SkAutoTDelete<SkStream> rStream(wStream.detachAsStream());
648 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream, &l azy_decode_bitmap)); 640 SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream, &l azy_decode_bitmap));
649 641
650 // Turn that deserialized picture into a Src, draw it into our Sink to fill bitmap or stream. 642 return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas ) {
651 struct ProxySrc : public Src { 643 canvas->drawPicture(deserialized);
652 const SkPicture* fPic; 644 return "";
653 const SkISize fSize; 645 });
654 ProxySrc(const SkPicture* pic, SkISize size) : fPic(pic), fSize(size) {}
655
656 Error draw(SkCanvas* canvas) const override {
657 canvas->drawPicture(fPic);
658 return "";
659 }
660 SkISize size() const override { return fSize; }
661 Name name() const override { sk_throw(); return ""; } // No one should be calling this.
662 } proxy(deserialized, src.size());
663 return fSink->draw(proxy, bitmap, stream, log);
664 } 646 }
665 647
666 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 648 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
667 649
668 ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink) 650 ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink)
669 : fW(w) 651 : fW(w)
670 , fH(h) 652 , fH(h)
671 , fFactory(factory) 653 , fFactory(factory)
672 , fSink(sink) {} 654 , fSink(sink) {}
673 655
674 Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri ng* log) const { 656 Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkStri ng* log) const {
675 // Record our Src into a picture. 657 auto size = src.size();
676 SkSize size;
677 size = src.size();
678 SkPictureRecorder recorder; 658 SkPictureRecorder recorder;
679 Error err = src.draw(recorder.beginRecording(size.width(), size.height(), fF actory.get())); 659 Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
660 SkIntToScalar(size.height()),
661 fFactory.get()));
680 if (!err.isEmpty()) { 662 if (!err.isEmpty()) {
681 return err; 663 return err;
682 } 664 }
683 SkAutoTUnref<SkPicture> pic(recorder.endRecordingAsPicture()); 665 SkAutoTUnref<SkPicture> pic(recorder.endRecordingAsPicture());
684 666
685 // Turn that picture into a Src that draws into our Sink via tiles + MPD. 667 return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) {
686 struct ProxySrc : public Src { 668 const int xTiles = (size.width() + fW - 1) / fW,
687 const int fW, fH; 669 yTiles = (size.height() + fH - 1) / fH;
688 const SkPicture* fPic; 670 SkMultiPictureDraw mpd(xTiles*yTiles);
689 const SkISize fSize; 671 SkTDArray<SkSurface*> surfaces;
690 ProxySrc(int w, int h, const SkPicture* pic, SkISize size) 672 surfaces.setReserve(xTiles*yTiles);
691 : fW(w), fH(h), fPic(pic), fSize(size) {}
692 673
693 Error draw(SkCanvas* canvas) const override { 674 SkImageInfo info = canvas->imageInfo().makeWH(fW, fH);
694 const int xTiles = (fSize.width() + fW - 1) / fW, 675 for (int j = 0; j < yTiles; j++) {
695 yTiles = (fSize.height() + fH - 1) / fH; 676 for (int i = 0; i < xTiles; i++) {
696 SkMultiPictureDraw mpd(xTiles*yTiles); 677 // This lets our ultimate Sink determine the best kind of surfac e.
697 SkTDArray<SkSurface*> surfaces; 678 // E.g., if it's a GpuSink, the surfaces and images are textures .
698 surfaces.setReserve(xTiles*yTiles); 679 SkSurface* s = canvas->newSurface(info);
699 680 if (!s) {
700 SkImageInfo info = canvas->imageInfo().makeWH(fW, fH); 681 s = SkSurface::NewRaster(info); // Some canvases can't crea te surfaces.
701 for (int j = 0; j < yTiles; j++) {
702 for (int i = 0; i < xTiles; i++) {
703 // This lets our ultimate Sink determine the best kind of su rface.
704 // E.g., if it's a GpuSink, the surfaces and images are text ures.
705 SkSurface* s = canvas->newSurface(info);
706 if (!s) {
707 s = SkSurface::NewRaster(info); // Some canvases can't create surfaces.
708 }
709 surfaces.push(s);
710 SkCanvas* c = s->getCanvas();
711 c->translate(SkIntToScalar(-i * fW),
712 SkIntToScalar(-j * fH)); // Line up the canvas with this tile.
713 mpd.add(c, fPic);
714 } 682 }
683 surfaces.push(s);
684 SkCanvas* c = s->getCanvas();
685 c->translate(SkIntToScalar(-i * fW),
686 SkIntToScalar(-j * fH)); // Line up the canvas wit h this tile.
687 mpd.add(c, pic);
715 } 688 }
716 mpd.draw(); 689 }
717 for (int j = 0; j < yTiles; j++) { 690 mpd.draw();
718 for (int i = 0; i < xTiles; i++) { 691 for (int j = 0; j < yTiles; j++) {
719 SkAutoTUnref<SkImage> image(surfaces[i+xTiles*j]->newImageSn apshot()); 692 for (int i = 0; i < xTiles; i++) {
720 canvas->drawImage(image, SkIntToScalar(i*fW), SkIntToScalar( j*fH)); 693 SkAutoTUnref<SkImage> image(surfaces[i+xTiles*j]->newImageSnapsh ot());
721 } 694 canvas->drawImage(image, SkIntToScalar(i*fW), SkIntToScalar(j*fH ));
722 } 695 }
723 surfaces.unrefAll();
724 return "";
725 } 696 }
726 SkISize size() const override { return fSize; } 697 surfaces.unrefAll();
727 Name name() const override { sk_throw(); return ""; } // No one should be calling this. 698 return "";
728 } proxy(fW, fH, pic, src.size()); 699 });
729 return fSink->draw(proxy, bitmap, stream, log);
730 } 700 }
731 701
732 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 702 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
733 703
734 ViaSecondPicture::ViaSecondPicture(Sink* sink) : fSink(sink) {} 704 ViaSecondPicture::ViaSecondPicture(Sink* sink) : fSink(sink) {}
735 705
736 // Draw the Src into two pictures, then draw the second picture into the wrapped Sink. 706 // Draw the Src into two pictures, then draw the second picture into the wrapped Sink.
737 // This tests that any shortcuts we may take while recording that second picture are legal. 707 // This tests that any shortcuts we may take while recording that second picture are legal.
738 Error ViaSecondPicture::draw( 708 Error ViaSecondPicture::draw(
739 const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) cons t { 709 const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) cons t {
740 struct ProxySrc : public Src { 710 auto size = src.size();
741 const Src& fSrc; 711 return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas ) -> Error {
742 ProxySrc(const Src& src) : fSrc(src) {} 712 SkPictureRecorder recorder;
743 713 SkAutoTUnref<SkPicture> pic;
744 Error draw(SkCanvas* canvas) const override { 714 for (int i = 0; i < 2; i++) {
745 SkSize size; 715 Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.widt h()),
746 size = fSrc.size(); 716 SkIntToScalar(size.heig ht())));
747 SkPictureRecorder recorder; 717 if (!err.isEmpty()) {
748 SkAutoTUnref<SkPicture> pic; 718 return err;
749 for (int i = 0; i < 2; i++) {
750 Error err = fSrc.draw(recorder.beginRecording(size.width(), size .height()));
751 if (!err.isEmpty()) {
752 return err;
753 }
754 pic.reset(recorder.endRecordingAsPicture());
755 } 719 }
756 canvas->drawPicture(pic); 720 pic.reset(recorder.endRecordingAsPicture());
757 return "";
758 } 721 }
759 SkISize size() const override { return fSrc.size(); } 722 canvas->drawPicture(pic);
760 Name name() const override { sk_throw(); return ""; } // No one should be calling this. 723 return "";
761 } proxy(src); 724 });
762 return fSink->draw(proxy, bitmap, stream, log);
763 } 725 }
764 726
765 } // namespace DM 727 } // namespace DM
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698