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

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: update dox, use orig colortype 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 {
598 // We turn ourselves into another Src that draws our argument into a deferre d canvas,
599 // via a surface created by the original canvas. We then draw a snapped imag e from that
600 // surface back into the original canvas.
601 struct ProxySrc : public Src {
602 const Src& fSrc;
603 ProxySrc(const Src& src) : fSrc(src) {}
604
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 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~*/
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