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

Side by Side Diff: src/core/SkBlitter.cpp

Issue 1772463002: use Make instead of Create to return a shared shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: partial update of skia call-sites Created 4 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkBlitter.h" 8 #include "SkBlitter.h"
9 #include "SkAntiRun.h" 9 #include "SkAntiRun.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 return blitter; 577 return blitter;
578 } 578 }
579 579
580 /////////////////////////////////////////////////////////////////////////////// 580 ///////////////////////////////////////////////////////////////////////////////
581 581
582 #include "SkColorShader.h" 582 #include "SkColorShader.h"
583 #include "SkColorPriv.h" 583 #include "SkColorPriv.h"
584 584
585 class Sk3DShader : public SkShader { 585 class Sk3DShader : public SkShader {
586 public: 586 public:
587 Sk3DShader(SkShader* proxy) : fProxy(proxy) { 587 Sk3DShader(sk_sp<SkShader> proxy) : fProxy(std::move(proxy)) {}
588 SkSafeRef(proxy);
589 }
590
591 virtual ~Sk3DShader() {
592 SkSafeUnref(fProxy);
593 }
594 588
595 size_t onContextSize(const ContextRec& rec) const override { 589 size_t onContextSize(const ContextRec& rec) const override {
596 size_t size = sizeof(Sk3DShaderContext); 590 size_t size = sizeof(Sk3DShaderContext);
597 if (fProxy) { 591 if (fProxy) {
598 size += fProxy->contextSize(rec); 592 size += fProxy->contextSize(rec);
599 } 593 }
600 return size; 594 return size;
601 } 595 }
602 596
603 Context* onCreateContext(const ContextRec& rec, void* storage) const overrid e { 597 Context* onCreateContext(const ContextRec& rec, void* storage) const overrid e {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 this->INHERITED::toString(str); 714 this->INHERITED::toString(str);
721 715
722 str->append(")"); 716 str->append(")");
723 } 717 }
724 #endif 718 #endif
725 719
726 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk3DShader) 720 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(Sk3DShader)
727 721
728 protected: 722 protected:
729 void flatten(SkWriteBuffer& buffer) const override { 723 void flatten(SkWriteBuffer& buffer) const override {
730 buffer.writeFlattenable(fProxy); 724 buffer.writeFlattenable(fProxy.get());
731 } 725 }
732 726
733 private: 727 private:
734 SkShader* fProxy; 728 sk_sp<SkShader> fProxy;
735 729
736 typedef SkShader INHERITED; 730 typedef SkShader INHERITED;
737 }; 731 };
738 732
739 SkFlattenable* Sk3DShader::CreateProc(SkReadBuffer& buffer) { 733 SkFlattenable* Sk3DShader::CreateProc(SkReadBuffer& buffer) {
740 SkAutoTUnref<SkShader> shader(buffer.readShader()); 734 return new Sk3DShader(buffer.readShader());
741 return new Sk3DShader(shader);
742 } 735 }
743 736
744 class Sk3DBlitter : public SkBlitter { 737 class Sk3DBlitter : public SkBlitter {
745 public: 738 public:
746 Sk3DBlitter(SkBlitter* proxy, SkShader::Context* shaderContext) 739 Sk3DBlitter(SkBlitter* proxy, SkShader::Context* shaderContext)
747 : fProxy(proxy) 740 : fProxy(proxy)
748 , fShaderContext(shaderContext) 741 , fShaderContext(shaderContext)
749 {} 742 {}
750 743
751 void blitH(int x, int y, int width) override { 744 void blitH(int x, int y, int width) override {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 808
816 SkShader* shader = origPaint.getShader(); 809 SkShader* shader = origPaint.getShader();
817 SkColorFilter* cf = origPaint.getColorFilter(); 810 SkColorFilter* cf = origPaint.getColorFilter();
818 SkXfermode* mode = origPaint.getXfermode(); 811 SkXfermode* mode = origPaint.getXfermode();
819 Sk3DShader* shader3D = nullptr; 812 Sk3DShader* shader3D = nullptr;
820 813
821 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); 814 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
822 815
823 if (origPaint.getMaskFilter() != nullptr && 816 if (origPaint.getMaskFilter() != nullptr &&
824 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { 817 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) {
825 shader3D = new Sk3DShader(shader); 818 shader3D = new Sk3DShader(sk_sp<SkShader>(SkSafeRef(shader)));
826 // we know we haven't initialized lazyPaint yet, so just do it 819 // we know we haven't initialized lazyPaint yet, so just do it
827 paint.writable()->setShader(shader3D)->unref(); 820 paint.writable()->setShader(shader3D)->unref();
828 shader = shader3D; 821 shader = shader3D;
829 } 822 }
830 823
831 if (mode) { 824 if (mode) {
832 bool deviceIsOpaque = kRGB_565_SkColorType == device.colorType(); 825 bool deviceIsOpaque = kRGB_565_SkColorType == device.colorType();
833 switch (SkInterpretXfermode(*paint, deviceIsOpaque)) { 826 switch (SkInterpretXfermode(*paint, deviceIsOpaque)) {
834 case kSrcOver_SkXfermodeInterpretation: 827 case kSrcOver_SkXfermodeInterpretation:
835 mode = nullptr; 828 mode = nullptr;
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 fShaderContext->~Context(); 1002 fShaderContext->~Context();
1010 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); 1003 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext);
1011 if (nullptr == ctx) { 1004 if (nullptr == ctx) {
1012 // Need a valid context in fShaderContext's storage, so we can later (or our caller) call 1005 // Need a valid context in fShaderContext's storage, so we can later (or our caller) call
1013 // the in-place destructor. 1006 // the in-place destructor.
1014 new (fShaderContext) SkZeroShaderContext(*fShader, rec); 1007 new (fShaderContext) SkZeroShaderContext(*fShader, rec);
1015 return false; 1008 return false;
1016 } 1009 }
1017 return true; 1010 return true;
1018 } 1011 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698