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

Side by Side Diff: dm/DMSrcSink.cpp

Issue 1113273006: add deferred config to DM (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « dm/DMSrcSink.h ('k') | 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 "SkCommonFlags.h" 10 #include "SkCommonFlags.h"
11 #include "SkCodec.h" 11 #include "SkCodec.h"
12 #include "SkData.h" 12 #include "SkData.h"
13 #include "SkDeferredCanvas.h"
13 #include "SkDocument.h" 14 #include "SkDocument.h"
14 #include "SkError.h" 15 #include "SkError.h"
15 #include "SkImageGenerator.h" 16 #include "SkImageGenerator.h"
16 #include "SkMultiPictureDraw.h" 17 #include "SkMultiPictureDraw.h"
17 #include "SkNullCanvas.h" 18 #include "SkNullCanvas.h"
18 #include "SkOSFile.h" 19 #include "SkOSFile.h"
19 #include "SkPictureData.h" 20 #include "SkPictureData.h"
20 #include "SkPictureRecorder.h" 21 #include "SkPictureRecorder.h"
21 #include "SkRandom.h" 22 #include "SkRandom.h"
22 #include "SkScanlineDecoder.h" 23 #include "SkScanlineDecoder.h"
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 const uint32_t kFlags = 0; // We mirror SkDeferredCanvas, which does n't use any flags. 584 const uint32_t kFlags = 0; // We mirror SkDeferredCanvas, which does n't use any flags.
584 return fSrc.draw(pipe.startRecording(&controller, kFlags, size.width (), size.height())); 585 return fSrc.draw(pipe.startRecording(&controller, kFlags, size.width (), size.height()));
585 } 586 }
586 SkISize size() const override { return fSrc.size(); } 587 SkISize size() const override { return fSrc.size(); }
587 Name name() const override { sk_throw(); return ""; } // No one should be calling this. 588 Name name() const override { sk_throw(); return ""; } // No one should be calling this.
588 } proxy(src); 589 } proxy(src);
589 return fSink->draw(proxy, bitmap, stream, log); 590 return fSink->draw(proxy, bitmap, stream, log);
590 } 591 }
591 592
592 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/ 593 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
594
595 ViaDeferred::ViaDeferred(Sink* sink) : fSink(sink) {}
596
597 Error ViaDeferred::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkS tring* log) const {
robertphillips 2015/05/05 14:45:42 update comment
reed1 2015/05/05 14:55:25 Done.
598 // We turn ourselves into another Src that draws our argument into bitmap/st ream via pipe.
mtklein 2015/05/05 14:45:30 update / delete?
reed1 2015/05/05 14:55:25 Done.
599 struct ProxySrc : public Src {
600 const Src& fSrc;
601 ProxySrc(const Src& src) : fSrc(src) {}
602
603 Error draw(SkCanvas* canvas) const override {
604 SkISize size = this->size();
605 SkImageInfo info = SkImageInfo::MakeN32Premul(size.width(), size.hei ght());
mtklein 2015/05/05 14:45:30 Is it useful to have the deferred canvas match the
reed1 2015/05/05 14:55:25 Good point, I think I can use the same "info"
606 SkAutoTUnref<SkSurface> surface(canvas->newSurface(info));
607 if (!surface.get()) {
608 return Error("can make surface for deferred canvas");
mtklein 2015/05/05 14:45:30 can -> can't?
reed1 2015/05/05 14:55:25 Done.
609 }
610 SkAutoTDelete<SkDeferredCanvas> defcan(SkDeferredCanvas::Create(surf ace));
611 Error err = fSrc.draw(defcan);
612 if (err.isEmpty()) {
mtklein 2015/05/05 14:45:30 Seems like you're swallowing the error when it's n
reed1 2015/05/05 14:55:25 Done.
613 SkAutoTUnref<SkImage> image(defcan->newImageSnapshot());
614 if (image) {
615 canvas->drawImage(image, 0, 0, NULL);
616 } else {
617 return Error("failed to create deferred image snapshot");
mtklein 2015/05/05 14:45:30 FYI, you can just write return "Failed to create
reed1 2015/05/05 14:55:25 Acknowledged.
618 }
619 }
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 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
593 629
594 ViaSerialization::ViaSerialization(Sink* sink) : fSink(sink) {} 630 ViaSerialization::ViaSerialization(Sink* sink) : fSink(sink) {}
595 631
596 Error ViaSerialization::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream , SkString* log) 632 Error ViaSerialization::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream , SkString* log)
597 const { 633 const {
598 // Record our Src into a picture. 634 // Record our Src into a picture.
599 SkSize size; 635 SkSize size;
600 size = src.size(); 636 size = src.size();
601 SkPictureRecorder recorder; 637 SkPictureRecorder recorder;
602 Error err = src.draw(recorder.beginRecording(size.width(), size.height())); 638 Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 canvas->drawPicture(pic); 756 canvas->drawPicture(pic);
721 return ""; 757 return "";
722 } 758 }
723 SkISize size() const override { return fSrc.size(); } 759 SkISize size() const override { return fSrc.size(); }
724 Name name() const override { sk_throw(); return ""; } // No one should be calling this. 760 Name name() const override { sk_throw(); return ""; } // No one should be calling this.
725 } proxy(src); 761 } proxy(src);
726 return fSink->draw(proxy, bitmap, stream, log); 762 return fSink->draw(proxy, bitmap, stream, log);
727 } 763 }
728 764
729 } // namespace DM 765 } // namespace DM
OLDNEW
« no previous file with comments | « dm/DMSrcSink.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698