remove LerpRed shader

Seems very one-off (esp. given SkSL). No one seems to use it.

Change-Id: Iaded54c5b4183fa4aa9c318b5dbe1d410cca539a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276617
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2020-03-11 21:46:35 -04:00 committed by Skia Commit-Bot
parent 5929535315
commit 019385eb1d
12 changed files with 0 additions and 426 deletions

View File

@ -123,84 +123,3 @@ private:
} // namespace
DEF_GM( return new MixerCFGM(SkSize::Make(200, 250), 5); )
static sk_sp<SkShader> 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<SkShader> 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<SkShader> 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; )

View File

@ -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",

View File

@ -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",

View File

@ -144,9 +144,6 @@ public:
static sk_sp<SkShader> Lerp(float t, sk_sp<SkShader> dst, sk_sp<SkShader> src,
const SkMatrix* localMatrix = nullptr);
static sk_sp<SkShader> Lerp(sk_sp<SkShader> red, sk_sp<SkShader> dst, sk_sp<SkShader> src,
const SkMatrix* localMatrix = nullptr);
private:
SkShaders() = delete;
};

View File

@ -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<SkShader> 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<SkShader> fSH0;
sk_sp<SkShader> fSH1;
sk_sp<SkSurface> 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; )

View File

@ -96,7 +96,6 @@ public:
kGrColorMatrixFragmentProcessor_ClassID,
kGrColorSpaceXformEffect_ClassID,
kGrComposeLerpEffect_ClassID,
kGrComposeLerpRedEffect_ClassID,
kGrConfigConversionEffect_ClassID,
kGrConicEffect_ClassID,
kGrConstColorProcessor_ClassID,

View File

@ -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);
}

View File

@ -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<GrComposeLerpRedEffect>();
(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<GrComposeLerpRedEffect>();
(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<GrFragmentProcessor> GrComposeLerpRedEffect::clone() const {
return std::unique_ptr<GrFragmentProcessor>(new GrComposeLerpRedEffect(*this));
}

View File

@ -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<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child1,
std::unique_ptr<GrFragmentProcessor> child2,
std::unique_ptr<GrFragmentProcessor> lerp) {
return std::unique_ptr<GrFragmentProcessor>(
new GrComposeLerpRedEffect(std::move(child1), std::move(child2), std::move(lerp)));
}
GrComposeLerpRedEffect(const GrComposeLerpRedEffect& src);
std::unique_ptr<GrFragmentProcessor> 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<GrFragmentProcessor> child1,
std::unique_ptr<GrFragmentProcessor> child2,
std::unique_ptr<GrFragmentProcessor> 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

View File

@ -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);

View File

@ -68,18 +68,6 @@ sk_sp<SkShader> SkShaders::Lerp(float weight, sk_sp<SkShader> dst, sk_sp<SkShade
return sk_sp<SkShader>(new SkShader_Lerp(weight, std::move(dst), std::move(src), lm));
}
sk_sp<SkShader> SkShaders::Lerp(sk_sp<SkShader> red, sk_sp<SkShader> dst, sk_sp<SkShader> src,
const SkMatrix* lm) {
if (!red) {
return nullptr;
}
if (dst == src) {
return wrap_lm(std::move(dst), lm);
}
return sk_sp<SkShader>(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<SkFlattenable> SkShader_LerpRed::CreateProc(SkReadBuffer& buffer) {
sk_sp<SkShader> dst(buffer.readShader());
sk_sp<SkShader> src(buffer.readShader());
sk_sp<SkShader> 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<Storage>();
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<GrFragmentProcessor> as_fp(const GrFPArgs& args, SkShader* shader) {
@ -241,16 +191,4 @@ std::unique_ptr<GrFragmentProcessor> SkShader_Lerp::asFragmentProcessor(
auto fpB = as_fp(args, fSrc.get());
return GrComposeLerpEffect::Make(std::move(fpA), std::move(fpB), fWeight);
}
std::unique_ptr<GrFragmentProcessor> 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

View File

@ -69,33 +69,4 @@ private:
typedef SkShaderBase INHERITED;
};
class SkShader_LerpRed final : public SkShaderBase {
public:
SkShader_LerpRed(sk_sp<SkShader> red, sk_sp<SkShader> dst, sk_sp<SkShader> 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<GrFragmentProcessor> 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<SkShader> fDst;
sk_sp<SkShader> fSrc;
sk_sp<SkShader> fRed;
typedef SkShaderBase INHERITED;
};
#endif