diff --git a/gm/mixercolorfilter.cpp b/gm/mixercolorfilter.cpp index 0c88cf9f19..7132f46cab 100644 --- a/gm/mixercolorfilter.cpp +++ b/gm/mixercolorfilter.cpp @@ -123,84 +123,3 @@ private: } // namespace DEF_GM( return new MixerCFGM(SkSize::Make(200, 250), 5); ) - -static sk_sp make_resource_shader(const char path[], int size) { - auto img = GetResourceAsImage(path); - if (!img) { - return nullptr; - } - SkRect src = SkRect::MakeIWH(img->width(), img->height()); - SkRect dst = SkRect::MakeIWH(size, size); - SkMatrix m; - m.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); - return img->makeShader(&m); -} - -static sk_sp make_grad(int size, float t) { - SkASSERT(t >= 0 && t <= 1); - unsigned r = SkScalarRoundToInt(t * 255); - SkColor c = SkColorSetARGB(r, r, 0, 0); - - SkColor colors[] = { 0, c, SK_ColorRED }; - SkPoint pts[] = {{0, 0}, {size*1.0f, size*1.0f}}; - SkScalar pos[] = {0, 1 - t, 1.0f}; - return SkGradientShader::MakeLinear(pts, colors, pos, SK_ARRAY_COUNT(colors), - SkTileMode::kClamp); -} - -class ShaderMixerGM final : public skiagm::GM { - enum { SIZE = 256 }; - float fPos = 0.5f; - sk_sp fS0, fS1; - -public: - ShaderMixerGM() {} - -protected: - SkString onShortName() override { - return SkString("mixershader_shadermixer"); - } - - void onOnceBeforeDraw() override { - fS0 = make_resource_shader("images/mandrill_256.png", SIZE); - fS1 = make_resource_shader("images/baby_tux.png", SIZE); - } - - SkISize onISize() override { return {542, 542}; } - - void onDraw(SkCanvas* canvas) override { - SkRect r = SkRect::MakeIWH(SIZE, SIZE); - - SkPaint paint; - - canvas->translate(10, 10); - - canvas->save(); - paint.setShader(fS0); - canvas->drawRect(r, paint); - canvas->translate(SIZE + 10.0f, 0); - paint.setShader(fS1); - canvas->drawRect(r, paint); - canvas->restore(); - - auto sh2 = make_grad(SIZE, fPos); - - canvas->translate(0, SIZE + 10.0f); - paint.setShader(sh2); - canvas->drawRect(r, paint); - - auto sh = SkShaders::Lerp(sh2, fS0, fS1); - canvas->translate(SIZE + 10.0f, 0); - paint.setShader(sh); - canvas->drawRect(r, paint); - } - - bool onAnimate(double nanos) override { - fPos = (sin(1e-9 * nanos) + 1) * 0.5f; - return true; - } - -private: - using INHERITED = skiagm::GM; -}; -DEF_GM( return new ShaderMixerGM; ) diff --git a/gn/gpu.gni b/gn/gpu.gni index 75cd2124b0..bcb522d5f0 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -370,8 +370,6 @@ skia_gpu_sources = [ "$_src/gpu/effects/generated/GrColorMatrixFragmentProcessor.h", "$_src/gpu/effects/generated/GrComposeLerpEffect.cpp", "$_src/gpu/effects/generated/GrComposeLerpEffect.h", - "$_src/gpu/effects/generated/GrComposeLerpRedEffect.cpp", - "$_src/gpu/effects/generated/GrComposeLerpRedEffect.h", "$_src/gpu/effects/generated/GrConfigConversionEffect.cpp", "$_src/gpu/effects/generated/GrConfigConversionEffect.h", "$_src/gpu/effects/generated/GrConstColorProcessor.cpp", diff --git a/gn/sksl.gni b/gn/sksl.gni index 7ad737a33d..33e4125090 100644 --- a/gn/sksl.gni +++ b/gn/sksl.gni @@ -43,7 +43,6 @@ skia_gpu_processor_sources = [ "$_src/gpu/effects/GrCircleEffect.fp", "$_src/gpu/effects/GrClampFragmentProcessor.fp", "$_src/gpu/effects/GrComposeLerpEffect.fp", - "$_src/gpu/effects/GrComposeLerpRedEffect.fp", "$_src/gpu/effects/GrConfigConversionEffect.fp", "$_src/gpu/effects/GrConstColorProcessor.fp", "$_src/gpu/effects/GrColorMatrixFragmentProcessor.fp", diff --git a/include/core/SkShader.h b/include/core/SkShader.h index ef6ba1bdb7..45f9db010d 100644 --- a/include/core/SkShader.h +++ b/include/core/SkShader.h @@ -144,9 +144,6 @@ public: static sk_sp Lerp(float t, sk_sp dst, sk_sp src, const SkMatrix* localMatrix = nullptr); - static sk_sp Lerp(sk_sp red, sk_sp dst, sk_sp src, - const SkMatrix* localMatrix = nullptr); - private: SkShaders() = delete; }; diff --git a/samplecode/SampleMixer.cpp b/samplecode/SampleMixer.cpp index 7e39ab1740..cde0155860 100644 --- a/samplecode/SampleMixer.cpp +++ b/samplecode/SampleMixer.cpp @@ -88,91 +88,3 @@ private: typedef Sample INHERITED; }; DEF_SAMPLE( return new MixerView; ) - -////////////////////////////////////////////////////////////////////////////// - -#include "include/core/SkMaskFilter.h" -#include "include/core/SkSurface.h" - -static sk_sp make_resource_shader(const char path[], int size) { - auto img = GetResourceAsImage(path); - if (!img) { - return nullptr; - } - SkRect src = SkRect::MakeIWH(img->width(), img->height()); - SkRect dst = SkRect::MakeIWH(size, size); - SkMatrix m; - m.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); - return img->makeShader(&m); -} - -class ShaderMixerView : public Sample { - sk_sp fSH0; - sk_sp fSH1; - sk_sp fSurface; - SkBlendMode fMode = SkBlendMode::kClear; - - enum { SIZE = 256 }; - - const SkRect fRect = SkRect::MakeXYWH(10, 10 + SIZE + 10, SIZE, SIZE); - -public: - ShaderMixerView() {} - - void onOnceBeforeDraw() override { - fSH0 = make_resource_shader("images/mandrill_256.png", SIZE); - fSH1 = make_resource_shader("images/baby_tux.png", SIZE); - } - -protected: - SkString name() override { return SkString("ShaderMixer"); } - - void onDrawContent(SkCanvas* canvas) override { - if (!fSurface) { - fSurface = canvas->makeSurface(SkImageInfo::MakeN32Premul(SIZE, SIZE)); - } - - SkPaint paint; - const SkRect r = SkRect::MakeIWH(SIZE, SIZE); - - canvas->translate(10, 10); - - canvas->save(); - paint.setShader(fSH0); canvas->drawRect(r, paint); - canvas->translate(SIZE + 10.f, 0); - paint.setShader(fSH1); canvas->drawRect(r, paint); - canvas->restore(); - - canvas->translate(0, SIZE + 10.f); - - auto sh = fSurface->makeImageSnapshot()->makeShader(); - - canvas->save(); - paint.setShader(sh); canvas->drawRect(r, paint); - canvas->translate(SIZE + 10.f, 0); - paint.setShader(SkShaders::Lerp(sh, fSH0, fSH1)); canvas->drawRect(r, paint); - canvas->restore(); - } - - virtual Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override { - fMode = (fMode == SkBlendMode::kSrcOver) ? SkBlendMode::kClear : SkBlendMode::kSrcOver; - return fRect.contains(SkScalarRoundToInt(x), - SkScalarRoundToInt(y)) ? new Click() : nullptr; - } - - bool onClick(Click* click) override { - SkPaint p; - p.setAntiAlias(true); - p.setColor(SK_ColorRED); - p.setBlendMode(fMode); - p.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 12)); - SkScalar x = click->fCurr.fX - fRect.fLeft; - SkScalar y = click->fCurr.fY - fRect.fTop; - fSurface->getCanvas()->drawCircle(x, y, 10, p); - return true; - } - -private: - typedef Sample INHERITED; -}; -DEF_SAMPLE( return new ShaderMixerView; ) diff --git a/src/gpu/GrProcessor.h b/src/gpu/GrProcessor.h index 40693446b3..73abbafa60 100644 --- a/src/gpu/GrProcessor.h +++ b/src/gpu/GrProcessor.h @@ -96,7 +96,6 @@ public: kGrColorMatrixFragmentProcessor_ClassID, kGrColorSpaceXformEffect_ClassID, kGrComposeLerpEffect_ClassID, - kGrComposeLerpRedEffect_ClassID, kGrConfigConversionEffect_ClassID, kGrConicEffect_ClassID, kGrConstColorProcessor_ClassID, diff --git a/src/gpu/effects/GrComposeLerpRedEffect.fp b/src/gpu/effects/GrComposeLerpRedEffect.fp deleted file mode 100644 index e0f7486c4e..0000000000 --- a/src/gpu/effects/GrComposeLerpRedEffect.fp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright 2019 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -in fragmentProcessor? child1; -in fragmentProcessor? child2; -in fragmentProcessor lerp; - -void main() { - sk_OutColor = mix(child1 != null ? sample(child1) : sk_InColor, - child2 != null ? sample(child2) : sk_InColor, - sample(lerp).r); -} diff --git a/src/gpu/effects/generated/GrComposeLerpRedEffect.cpp b/src/gpu/effects/generated/GrComposeLerpRedEffect.cpp deleted file mode 100644 index 4b9b496e67..0000000000 --- a/src/gpu/effects/generated/GrComposeLerpRedEffect.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2019 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/************************************************************************************************** - *** This file was autogenerated from GrComposeLerpRedEffect.fp; do not modify. - **************************************************************************************************/ -#include "GrComposeLerpRedEffect.h" - -#include "src/gpu/GrTexture.h" -#include "src/gpu/glsl/GrGLSLFragmentProcessor.h" -#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" -#include "src/gpu/glsl/GrGLSLProgramBuilder.h" -#include "src/sksl/SkSLCPP.h" -#include "src/sksl/SkSLUtil.h" -class GrGLSLComposeLerpRedEffect : public GrGLSLFragmentProcessor { -public: - GrGLSLComposeLerpRedEffect() {} - void emitCode(EmitArgs& args) override { - GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; - const GrComposeLerpRedEffect& _outer = args.fFp.cast(); - (void)_outer; - SkString _sample292; - if (_outer.child1_index >= 0) { - _sample292 = this->invokeChild(_outer.child1_index, args); - } else { - _sample292 = "half4(1)"; - } - SkString _sample360; - if (_outer.child2_index >= 0) { - _sample360 = this->invokeChild(_outer.child2_index, args); - } else { - _sample360 = "half4(1)"; - } - SkString _sample411; - _sample411 = this->invokeChild(_outer.lerp_index, args); - fragBuilder->codeAppendf("%s = mix(%s ? %s : %s, %s ? %s : %s, %s.x);\n", args.fOutputColor, - _outer.child1_index >= 0 ? "true" : "false", _sample292.c_str(), - args.fInputColor, _outer.child2_index >= 0 ? "true" : "false", - _sample360.c_str(), args.fInputColor, _sample411.c_str()); - } - -private: - void onSetData(const GrGLSLProgramDataManager& pdman, - const GrFragmentProcessor& _proc) override {} -}; -GrGLSLFragmentProcessor* GrComposeLerpRedEffect::onCreateGLSLInstance() const { - return new GrGLSLComposeLerpRedEffect(); -} -void GrComposeLerpRedEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, - GrProcessorKeyBuilder* b) const {} -bool GrComposeLerpRedEffect::onIsEqual(const GrFragmentProcessor& other) const { - const GrComposeLerpRedEffect& that = other.cast(); - (void)that; - return true; -} -GrComposeLerpRedEffect::GrComposeLerpRedEffect(const GrComposeLerpRedEffect& src) - : INHERITED(kGrComposeLerpRedEffect_ClassID, src.optimizationFlags()) - , child1_index(src.child1_index) - , child2_index(src.child2_index) - , lerp_index(src.lerp_index) { - if (child1_index >= 0) { - auto clone = src.childProcessor(child1_index).clone(); - clone->setSampledWithExplicitCoords( - src.childProcessor(child1_index).isSampledWithExplicitCoords()); - this->registerChildProcessor(std::move(clone)); - } - if (child2_index >= 0) { - auto clone = src.childProcessor(child2_index).clone(); - clone->setSampledWithExplicitCoords( - src.childProcessor(child2_index).isSampledWithExplicitCoords()); - this->registerChildProcessor(std::move(clone)); - } - { - auto clone = src.childProcessor(lerp_index).clone(); - clone->setSampledWithExplicitCoords( - src.childProcessor(lerp_index).isSampledWithExplicitCoords()); - this->registerChildProcessor(std::move(clone)); - } -} -std::unique_ptr GrComposeLerpRedEffect::clone() const { - return std::unique_ptr(new GrComposeLerpRedEffect(*this)); -} diff --git a/src/gpu/effects/generated/GrComposeLerpRedEffect.h b/src/gpu/effects/generated/GrComposeLerpRedEffect.h deleted file mode 100644 index dd9e65eaab..0000000000 --- a/src/gpu/effects/generated/GrComposeLerpRedEffect.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2019 Google LLC. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -/************************************************************************************************** - *** This file was autogenerated from GrComposeLerpRedEffect.fp; do not modify. - **************************************************************************************************/ -#ifndef GrComposeLerpRedEffect_DEFINED -#define GrComposeLerpRedEffect_DEFINED -#include "include/core/SkTypes.h" -#include "include/core/SkM44.h" - -#include "src/gpu/GrCoordTransform.h" -#include "src/gpu/GrFragmentProcessor.h" -class GrComposeLerpRedEffect : public GrFragmentProcessor { -public: - static std::unique_ptr Make(std::unique_ptr child1, - std::unique_ptr child2, - std::unique_ptr lerp) { - return std::unique_ptr( - new GrComposeLerpRedEffect(std::move(child1), std::move(child2), std::move(lerp))); - } - GrComposeLerpRedEffect(const GrComposeLerpRedEffect& src); - std::unique_ptr clone() const override; - const char* name() const override { return "ComposeLerpRedEffect"; } - int child1_index = -1; - int child2_index = -1; - int lerp_index = -1; - -private: - GrComposeLerpRedEffect(std::unique_ptr child1, - std::unique_ptr child2, - std::unique_ptr lerp) - : INHERITED(kGrComposeLerpRedEffect_ClassID, kNone_OptimizationFlags) { - if (child1) { - child1_index = this->numChildProcessors(); - this->registerChildProcessor(std::move(child1)); - } - if (child2) { - child2_index = this->numChildProcessors(); - this->registerChildProcessor(std::move(child2)); - } - SkASSERT(lerp); - lerp_index = this->numChildProcessors(); - this->registerChildProcessor(std::move(lerp)); - } - GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; - void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; - bool onIsEqual(const GrFragmentProcessor&) const override; - GR_DECLARE_FRAGMENT_PROCESSOR_TEST - typedef GrFragmentProcessor INHERITED; -}; -#endif diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp index 7ef7c31bd4..c45167b071 100644 --- a/src/ports/SkGlobalInitialization_default.cpp +++ b/src/ports/SkGlobalInitialization_default.cpp @@ -66,7 +66,6 @@ SK_REGISTER_FLATTENABLE(SkColorShader); SK_REGISTER_FLATTENABLE(SkShader_Blend); SK_REGISTER_FLATTENABLE(SkShader_Lerp); - SK_REGISTER_FLATTENABLE(SkShader_LerpRed); SK_REGISTER_FLATTENABLE(SkEmptyShader); SK_REGISTER_FLATTENABLE(SkLocalMatrixShader); SK_REGISTER_FLATTENABLE(SkPictureShader); diff --git a/src/shaders/SkComposeShader.cpp b/src/shaders/SkComposeShader.cpp index ca14341798..ae7ffecb10 100644 --- a/src/shaders/SkComposeShader.cpp +++ b/src/shaders/SkComposeShader.cpp @@ -68,18 +68,6 @@ sk_sp SkShaders::Lerp(float weight, sk_sp dst, sk_sp(new SkShader_Lerp(weight, std::move(dst), std::move(src), lm)); } -sk_sp SkShaders::Lerp(sk_sp red, sk_sp dst, sk_sp src, - const SkMatrix* lm) { - if (!red) { - return nullptr; - } - if (dst == src) { - return wrap_lm(std::move(dst), lm); - } - return sk_sp(new SkShader_LerpRed(std::move(red), std::move(dst), std::move(src), - lm)); -} - /////////////////////////////////////////////////////////////////////////////// static bool append_shader_or_paint(const SkStageRec& rec, SkShader* shader) { @@ -170,49 +158,11 @@ bool SkShader_Lerp::onAppendStages(const SkStageRec& orig_rec) const { return true; } -sk_sp SkShader_LerpRed::CreateProc(SkReadBuffer& buffer) { - sk_sp dst(buffer.readShader()); - sk_sp src(buffer.readShader()); - sk_sp red(buffer.readShader()); - return buffer.isValid() ? - SkShaders::Lerp(std::move(red), std::move(dst), std::move(src)) : nullptr; -} - -void SkShader_LerpRed::flatten(SkWriteBuffer& buffer) const { - buffer.writeFlattenable(fDst.get()); - buffer.writeFlattenable(fSrc.get()); - buffer.writeFlattenable(fRed.get()); -} - -bool SkShader_LerpRed::onAppendStages(const SkStageRec& orig_rec) const { - const LocalMatrixStageRec rec(orig_rec, this->getLocalMatrix()); - - struct Storage { - float fRed[4 * SkRasterPipeline_kMaxStride]; - }; - auto storage = rec.fAlloc->make(); - if (!as_SB(fRed)->appendStages(rec)) { - return false; - } - // actually, we just need the first (red) channel, but for now we store rgba - rec.fPipeline->append(SkRasterPipeline::store_src, storage->fRed); - - float* res0 = append_two_shaders(rec, fDst.get(), fSrc.get()); - if (!res0) { - return false; - } - - rec.fPipeline->append(SkRasterPipeline::load_dst, res0); - rec.fPipeline->append(SkRasterPipeline::lerp_native, &storage->fRed[0]); - return true; -} - #if SK_SUPPORT_GPU #include "include/private/GrRecordingContext.h" #include "src/gpu/effects/GrXfermodeFragmentProcessor.h" #include "src/gpu/effects/generated/GrComposeLerpEffect.h" -#include "src/gpu/effects/generated/GrComposeLerpRedEffect.h" #include "src/gpu/effects/generated/GrConstColorProcessor.h" static std::unique_ptr as_fp(const GrFPArgs& args, SkShader* shader) { @@ -241,16 +191,4 @@ std::unique_ptr SkShader_Lerp::asFragmentProcessor( auto fpB = as_fp(args, fSrc.get()); return GrComposeLerpEffect::Make(std::move(fpA), std::move(fpB), fWeight); } - -std::unique_ptr SkShader_LerpRed::asFragmentProcessor( - const GrFPArgs& orig_args) const { - const GrFPArgs::WithPreLocalMatrix args(orig_args, this->getLocalMatrix()); - auto fpA = as_fp(args, fDst.get()); - auto fpB = as_fp(args, fSrc.get()); - auto red = as_SB(fRed)->asFragmentProcessor(args); - if (!red) { - return nullptr; - } - return GrComposeLerpRedEffect::Make(std::move(fpA), std::move(fpB), std::move(red)); -} #endif diff --git a/src/shaders/SkComposeShader.h b/src/shaders/SkComposeShader.h index 4ea44cff8b..d5c3a2f1cb 100644 --- a/src/shaders/SkComposeShader.h +++ b/src/shaders/SkComposeShader.h @@ -69,33 +69,4 @@ private: typedef SkShaderBase INHERITED; }; -class SkShader_LerpRed final : public SkShaderBase { -public: - SkShader_LerpRed(sk_sp red, sk_sp dst, sk_sp src, - const SkMatrix* lm) - : INHERITED(lm) - , fDst(std::move(dst)) - , fSrc(std::move(src)) - , fRed(std::move(red)) - {} - -#if SK_SUPPORT_GPU - std::unique_ptr asFragmentProcessor(const GrFPArgs&) const override; -#endif - -protected: - SkShader_LerpRed(SkReadBuffer&); - void flatten(SkWriteBuffer&) const override; - bool onAppendStages(const SkStageRec&) const override; - -private: - SK_FLATTENABLE_HOOKS(SkShader_LerpRed) - - sk_sp fDst; - sk_sp fSrc; - sk_sp fRed; - - typedef SkShaderBase INHERITED; -}; - #endif