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

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

Issue 1829303002: move setshader to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: addressing comments from #8 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
« no previous file with comments | « src/c/sk_paint.cpp ('k') | src/core/SkLightingShader.h » ('j') | 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 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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 // which check, in case we're being called by a client with a dummy device 802 // which check, in case we're being called by a client with a dummy device
803 // (e.g. they have a bounder that always aborts the draw) 803 // (e.g. they have a bounder that always aborts the draw)
804 if (kUnknown_SkColorType == device.colorType() || 804 if (kUnknown_SkColorType == device.colorType() ||
805 (drawCoverage && (kAlpha_8_SkColorType != device.colorType()))) { 805 (drawCoverage && (kAlpha_8_SkColorType != device.colorType()))) {
806 return allocator->createT<SkNullBlitter>(); 806 return allocator->createT<SkNullBlitter>();
807 } 807 }
808 808
809 SkShader* shader = origPaint.getShader(); 809 SkShader* shader = origPaint.getShader();
810 SkColorFilter* cf = origPaint.getColorFilter(); 810 SkColorFilter* cf = origPaint.getColorFilter();
811 SkXfermode* mode = origPaint.getXfermode(); 811 SkXfermode* mode = origPaint.getXfermode();
812 Sk3DShader* shader3D = nullptr; 812 sk_sp<Sk3DShader> shader3D;
813 813
814 SkTCopyOnFirstWrite<SkPaint> paint(origPaint); 814 SkTCopyOnFirstWrite<SkPaint> paint(origPaint);
815 815
816 if (origPaint.getMaskFilter() != nullptr && 816 if (origPaint.getMaskFilter() != nullptr &&
817 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) { 817 origPaint.getMaskFilter()->getFormat() == SkMask::k3D_Format) {
818 shader3D = new Sk3DShader(sk_sp<SkShader>(SkSafeRef(shader))); 818 shader3D = sk_make_sp<Sk3DShader>(sk_ref_sp(shader));
819 // 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
820 paint.writable()->setShader(shader3D)->unref(); 820 paint.writable()->setShader(shader3D);
821 shader = shader3D; 821 shader = shader3D.get();
822 } 822 }
823 823
824 if (mode) { 824 if (mode) {
825 bool deviceIsOpaque = kRGB_565_SkColorType == device.colorType(); 825 bool deviceIsOpaque = kRGB_565_SkColorType == device.colorType();
826 switch (SkInterpretXfermode(*paint, deviceIsOpaque)) { 826 switch (SkInterpretXfermode(*paint, deviceIsOpaque)) {
827 case kSrcOver_SkXfermodeInterpretation: 827 case kSrcOver_SkXfermodeInterpretation:
828 mode = nullptr; 828 mode = nullptr;
829 paint.writable()->setXfermode(nullptr); 829 paint.writable()->setXfermode(nullptr);
830 break; 830 break;
831 case kSkipDrawing_SkXfermodeInterpretation:{ 831 case kSkipDrawing_SkXfermodeInterpretation:{
832 return allocator->createT<SkNullBlitter>(); 832 return allocator->createT<SkNullBlitter>();
833 } 833 }
834 default: 834 default:
835 break; 835 break;
836 } 836 }
837 } 837 }
838 838
839 /* 839 /*
840 * If the xfermode is CLEAR, then we can completely ignore the installed 840 * If the xfermode is CLEAR, then we can completely ignore the installed
841 * color/shader/colorfilter, and just pretend we're SRC + color==0. This 841 * color/shader/colorfilter, and just pretend we're SRC + color==0. This
842 * will fall into our optimizations for SRC mode. 842 * will fall into our optimizations for SRC mode.
843 */ 843 */
844 if (SkXfermode::IsMode(mode, SkXfermode::kClear_Mode)) { 844 if (SkXfermode::IsMode(mode, SkXfermode::kClear_Mode)) {
845 SkPaint* p = paint.writable(); 845 SkPaint* p = paint.writable();
846 shader = p->setShader(nullptr); 846 p->setShader(nullptr);
847 shader = nullptr;
847 p->setColorFilter(nullptr); 848 p->setColorFilter(nullptr);
848 cf = nullptr; 849 cf = nullptr;
849 mode = p->setXfermodeMode(SkXfermode::kSrc_Mode); 850 mode = p->setXfermodeMode(SkXfermode::kSrc_Mode);
850 p->setColor(0); 851 p->setColor(0);
851 } 852 }
852 853
853 if (nullptr == shader) { 854 if (nullptr == shader) {
854 if (mode) { 855 if (mode) {
855 // xfermodes (and filters) require shaders for our current blitters 856 // xfermodes (and filters) require shaders for our current blitters
856 shader = new SkColorShader(paint->getColor()); 857 paint.writable()->setShader(SkShader::MakeColorShader(paint->getColo r()));
857 paint.writable()->setShader(shader)->unref();
858 paint.writable()->setAlpha(0xFF); 858 paint.writable()->setAlpha(0xFF);
859 shader = paint->getShader();
859 } else if (cf) { 860 } else if (cf) {
860 // if no shader && no xfermode, we just apply the colorfilter to 861 // if no shader && no xfermode, we just apply the colorfilter to
861 // our color and move on. 862 // our color and move on.
862 SkPaint* writablePaint = paint.writable(); 863 SkPaint* writablePaint = paint.writable();
863 writablePaint->setColor(cf->filterColor(paint->getColor())); 864 writablePaint->setColor(cf->filterColor(paint->getColor()));
864 writablePaint->setColorFilter(nullptr); 865 writablePaint->setColorFilter(nullptr);
865 cf = nullptr; 866 cf = nullptr;
866 } 867 }
867 } 868 }
868 869
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 fShaderContext->~Context(); 1004 fShaderContext->~Context();
1004 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext); 1005 SkShader::Context* ctx = fShader->createContext(rec, (void*)fShaderContext);
1005 if (nullptr == ctx) { 1006 if (nullptr == ctx) {
1006 // Need a valid context in fShaderContext's storage, so we can later (or our caller) call 1007 // Need a valid context in fShaderContext's storage, so we can later (or our caller) call
1007 // the in-place destructor. 1008 // the in-place destructor.
1008 new (fShaderContext) SkZeroShaderContext(*fShader, rec); 1009 new (fShaderContext) SkZeroShaderContext(*fShader, rec);
1009 return false; 1010 return false;
1010 } 1011 }
1011 return true; 1012 return true;
1012 } 1013 }
OLDNEW
« no previous file with comments | « src/c/sk_paint.cpp ('k') | src/core/SkLightingShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698