Convert Clamped and Tiled gradient effects to GrSkSLFP

Change-Id: If9a3a2e71fada81447ad697b2dc9efd4dec77a28
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/423019
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
Brian Osman 2021-06-29 11:11:49 -04:00
parent c3ded43e92
commit c6804edbae
10 changed files with 153 additions and 569 deletions

View File

@ -382,10 +382,6 @@ skia_gpu_sources = [
"$_src/gpu/gradients/GrGradientBitmapCache.h",
"$_src/gpu/gradients/GrGradientShader.cpp",
"$_src/gpu/gradients/GrGradientShader.h",
"$_src/gpu/gradients/generated/GrClampedGradientEffect.cpp",
"$_src/gpu/gradients/generated/GrClampedGradientEffect.h",
"$_src/gpu/gradients/generated/GrTiledGradientEffect.cpp",
"$_src/gpu/gradients/generated/GrTiledGradientEffect.h",
"$_src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.cpp",
"$_src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.h",

View File

@ -213,7 +213,5 @@ skia_gpu_processor_sources = [
"$_src/gpu/effects/GrDitherEffect.fp",
"$_src/gpu/effects/GrRRectBlurEffect.fp",
"$_src/gpu/effects/GrRectBlurEffect.fp",
"$_src/gpu/gradients/GrClampedGradientEffect.fp",
"$_src/gpu/gradients/GrTiledGradientEffect.fp",
"$_src/gpu/gradients/GrUnrolledBinaryGradientColorizer.fp",
]

View File

@ -56,7 +56,6 @@ public:
kGrBicubicEffect_ClassID,
kGrBitmapTextGeoProc_ClassID,
kGrCircleBlurFragmentProcessor_ClassID,
kGrClampedGradientEffect_ClassID,
kGrColorSpaceXformEffect_ClassID,
kGrConfigConversionEffect_ClassID,
kGrConicEffect_ClassID,
@ -89,7 +88,6 @@ public:
kGrSkSLFP_ClassID,
kGrSpecularLightingEffect_ClassID,
kGrTextureEffect_ClassID,
kGrTiledGradientEffect_ClassID,
kGrUnrolledBinaryGradientColorizer_ClassID,
kGrYUVtoRGBEffect_ClassID,
kLatticeGP_ClassID,

View File

@ -1,77 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// This top-level effect implements clamping on the layout coordinate and requires specifying the
// border colors that are used when outside the clamped boundary. Gradients with the
// SkShader::kClamp_TileMode should use the colors at their first and last stop (after adding
// default stops for t=0,t=1) as the border color. This will automatically replicate the edge color,
// even if when there is a hard stop.
//
// The SkShader::kDecal_TileMode can be produced by specifying transparent black as the border
// colors, regardless of the gradient's stop colors.
in fragmentProcessor colorizer;
in fragmentProcessor gradLayout;
layout(ctype=SkPMColor4f) in uniform half4 leftBorderColor; // t < 0.0
layout(ctype=SkPMColor4f) in uniform half4 rightBorderColor; // t > 1.0
layout(key) in bool makePremul;
// Trust the creator that this matches the color spec of the gradient
in bool colorsAreOpaque;
layout(key) in bool layoutPreservesOpacity;
half4 main() {
half4 t = sample(gradLayout);
half4 outColor;
// If t.x is below 0, use the left border color without invoking the child processor. If any t.x
// is above 1, use the right border color. Otherwise, t is in the [0, 1] range assumed by the
// colorizer FP, so delegate to the child processor.
if (!layoutPreservesOpacity && t.y < 0) {
// layout has rejected this fragment (rely on sksl to remove this branch if the layout FP
// preserves opacity is false)
outColor = half4(0);
} else if (t.x < 0) {
outColor = leftBorderColor;
} else if (t.x > 1.0) {
outColor = rightBorderColor;
} else {
// Always sample from (x, 0), discarding y, since the layout FP can use y as a side-channel.
outColor = sample(colorizer, t.x0);
}
@if (makePremul) {
outColor.rgb *= outColor.a;
}
return outColor;
}
//////////////////////////////////////////////////////////////////////////////
// If the layout does not preserve opacity, remove the opaque optimization,
// but otherwise respect the provided color opacity state (which should take
// into account the opacity of the border colors).
@optimizationFlags {
kCompatibleWithCoverageAsAlpha_OptimizationFlag |
(colorsAreOpaque && layoutPreservesOpacity ? kPreservesOpaqueInput_OptimizationFlag
: kNone_OptimizationFlags)
}
@make{
static std::unique_ptr<GrFragmentProcessor> Make(
std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
SkPMColor4f leftBorderColor,
SkPMColor4f rightBorderColor,
bool makePremul,
bool colorsAreOpaque) {
bool layoutPreservesOpacity = gradLayout->preservesOpaqueInput();
return std::unique_ptr<GrFragmentProcessor>(new GrClampedGradientEffect(
std::move(colorizer), std::move(gradLayout), leftBorderColor, rightBorderColor,
makePremul, colorsAreOpaque, layoutPreservesOpacity));
}
}

View File

@ -7,9 +7,6 @@
#include "src/gpu/gradients/GrGradientShader.h"
#include "src/gpu/gradients/generated/GrClampedGradientEffect.h"
#include "src/gpu/gradients/generated/GrTiledGradientEffect.h"
#include "src/gpu/gradients/GrGradientBitmapCache.h"
#include "src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.h"
@ -215,6 +212,149 @@ static std::unique_ptr<GrFragmentProcessor> make_colorizer(const SkPMColor4f* co
return make_textured_colorizer(colors + offset, positions + offset, count, premul, args);
}
// This top-level effect implements clamping on the layout coordinate and requires specifying the
// border colors that are used when outside the clamped boundary. Gradients with the
// SkTileMode::kClamp should use the colors at their first and last stop (after adding default stops
// for t=0,t=1) as the border color. This will automatically replicate the edge color, even when
// there is a hard stop.
//
// The SkTileMode::kDecal can be produced by specifying transparent black as the border colors,
// regardless of the gradient's stop colors.
static std::unique_ptr<GrFragmentProcessor> make_clamped_gradient(
std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
SkPMColor4f leftBorderColor,
SkPMColor4f rightBorderColor,
bool makePremul,
bool colorsAreOpaque) {
static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForShader, R"(
uniform shader colorizer;
uniform shader gradLayout;
uniform half4 leftBorderColor; // t < 0.0
uniform half4 rightBorderColor; // t > 1.0
uniform int makePremul; // specialized
uniform int layoutPreservesOpacity; // specialized
half4 main(float2 coord) {
half4 t = sample(gradLayout, coord);
half4 outColor;
// If t.x is below 0, use the left border color without invoking the child processor.
// If any t.x is above 1, use the right border color. Otherwise, t is in the [0, 1]
// range assumed by the colorizer FP, so delegate to the child processor.
if (!bool(layoutPreservesOpacity) && t.y < 0) {
// layout has rejected this fragment (rely on sksl to remove this branch if the
// layout FP preserves opacity is false)
outColor = half4(0);
} else if (t.x < 0) {
outColor = leftBorderColor;
} else if (t.x > 1.0) {
outColor = rightBorderColor;
} else {
// Always sample from (x, 0), discarding y, since the layout FP can use y as a
// side-channel.
outColor = sample(colorizer, t.x0);
}
if (bool(makePremul)) {
outColor.rgb *= outColor.a;
}
return outColor;
}
)");
// If the layout does not preserve opacity, remove the opaque optimization,
// but otherwise respect the provided color opacity state (which should take
// into account the opacity of the border colors).
bool layoutPreservesOpacity = gradLayout->preservesOpaqueInput();
GrSkSLFP::OptFlags optFlags = GrSkSLFP::OptFlags::kCompatibleWithCoverageAsAlpha;
if (colorsAreOpaque && layoutPreservesOpacity) {
optFlags |= GrSkSLFP::OptFlags::kPreservesOpaqueInput;
}
return GrSkSLFP::Make(effect, "ClampedGradient", /*inputFP=*/nullptr, optFlags,
"colorizer", GrSkSLFP::IgnoreOptFlags(std::move(colorizer)),
"gradLayout", GrSkSLFP::IgnoreOptFlags(std::move(gradLayout)),
"leftBorderColor", leftBorderColor,
"rightBorderColor", rightBorderColor,
"makePremul", GrSkSLFP::Specialize<int>(makePremul),
"layoutPreservesOpacity",
GrSkSLFP::Specialize<int>(layoutPreservesOpacity));
}
static std::unique_ptr<GrFragmentProcessor> make_tiled_gradient(
const GrFPArgs& args,
std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
bool mirror,
bool makePremul,
bool colorsAreOpaque) {
static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForShader, R"(
uniform shader colorizer;
uniform shader gradLayout;
uniform int mirror; // specialized
uniform int makePremul; // specialized
uniform int layoutPreservesOpacity; // specialized
uniform int useFloorAbsWorkaround; // specialized
half4 main(float2 coord) {
half4 t = sample(gradLayout, coord);
if (!bool(layoutPreservesOpacity) && t.y < 0) {
// layout has rejected this fragment (rely on sksl to remove this branch if the
// layout FP preserves opacity is false)
return half4(0);
} else {
if (bool(mirror)) {
half t_1 = t.x - 1;
half tiled_t = t_1 - 2 * floor(t_1 * 0.5) - 1;
if (bool(useFloorAbsWorkaround)) {
// At this point the expected value of tiled_t should between -1 and 1, so
// this clamp has no effect other than to break up the floor and abs calls
// and make sure the compiler doesn't merge them back together.
tiled_t = clamp(tiled_t, -1, 1);
}
t.x = abs(tiled_t);
} else {
// Simple repeat mode
t.x = fract(t.x);
}
// Always sample from (x, 0), discarding y, since the layout FP can use y as a
// side-channel.
half4 outColor = sample(colorizer, t.x0);
if (bool(makePremul)) {
outColor.rgb *= outColor.a;
}
return outColor;
}
}
)");
// If the layout does not preserve opacity, remove the opaque optimization,
// but otherwise respect the provided color opacity state (which should take
// into account the opacity of the border colors).
bool layoutPreservesOpacity = gradLayout->preservesOpaqueInput();
GrSkSLFP::OptFlags optFlags = GrSkSLFP::OptFlags::kCompatibleWithCoverageAsAlpha;
if (colorsAreOpaque && layoutPreservesOpacity) {
optFlags |= GrSkSLFP::OptFlags::kPreservesOpaqueInput;
}
const bool useFloorAbsWorkaround =
args.fContext->priv().caps()->shaderCaps()->mustDoOpBetweenFloorAndAbs();
return GrSkSLFP::Make(effect, "TiledGradient", /*inputFP=*/nullptr, optFlags,
"colorizer", GrSkSLFP::IgnoreOptFlags(std::move(colorizer)),
"gradLayout", GrSkSLFP::IgnoreOptFlags(std::move(gradLayout)),
"mirror", GrSkSLFP::Specialize<int>(mirror),
"makePremul", GrSkSLFP::Specialize<int>(makePremul),
"layoutPreservesOpacity",
GrSkSLFP::Specialize<int>(layoutPreservesOpacity),
"useFloorAbsWorkaround",
GrSkSLFP::Specialize<int>(useFloorAbsWorkaround));
}
// Combines the colorizer and layout with an appropriately configured top-level effect based on the
// gradient's tile mode
static std::unique_ptr<GrFragmentProcessor> make_gradient(
@ -288,29 +428,28 @@ static std::unique_ptr<GrFragmentProcessor> make_gradient(
std::unique_ptr<GrFragmentProcessor> gradient;
switch(shader.getTileMode()) {
case SkTileMode::kRepeat:
gradient = GrTiledGradientEffect::Make(std::move(colorizer), std::move(layout),
/* mirror */ false, makePremul, allOpaque);
gradient = make_tiled_gradient(args, std::move(colorizer), std::move(layout),
/* mirror */ false, makePremul, allOpaque);
break;
case SkTileMode::kMirror:
gradient = GrTiledGradientEffect::Make(std::move(colorizer), std::move(layout),
/* mirror */ true, makePremul, allOpaque);
gradient = make_tiled_gradient(args, std::move(colorizer), std::move(layout),
/* mirror */ true, makePremul, allOpaque);
break;
case SkTileMode::kClamp:
// For the clamped mode, the border colors are the first and last colors, corresponding
// to t=0 and t=1, because SkGradientShaderBase enforces that by adding color stops as
// appropriate. If there is a hard stop, this grabs the expected outer colors for the
// border.
gradient = GrClampedGradientEffect::Make(std::move(colorizer), std::move(layout),
colors[0], colors[shader.fColorCount - 1],
makePremul, allOpaque);
gradient = make_clamped_gradient(std::move(colorizer), std::move(layout),
colors[0], colors[shader.fColorCount - 1],
makePremul, allOpaque);
break;
case SkTileMode::kDecal:
// Even if the gradient colors are opaque, the decal borders are transparent so
// disable that optimization
gradient = GrClampedGradientEffect::Make(std::move(colorizer), std::move(layout),
SK_PMColor4fTRANSPARENT,
SK_PMColor4fTRANSPARENT,
makePremul, /* colorsAreOpaque */ false);
gradient = make_clamped_gradient(std::move(colorizer), std::move(layout),
SK_PMColor4fTRANSPARENT, SK_PMColor4fTRANSPARENT,
makePremul, /* colorsAreOpaque */ false);
break;
}

View File

@ -1,74 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
// Provides tiling for the repeat or mirror modes.
in fragmentProcessor colorizer;
in fragmentProcessor gradLayout;
layout(key) in bool mirror;
layout(key) in bool makePremul;
// Trust the creator that this matches the color spec of the gradient
in bool colorsAreOpaque;
layout(key) in bool layoutPreservesOpacity;
half4 main() {
half4 t = sample(gradLayout);
if (!layoutPreservesOpacity && t.y < 0) {
// layout has rejected this fragment (rely on sksl to remove this branch if the layout FP
// preserves opacity is false)
return half4(0);
} else {
@if (mirror) {
half t_1 = t.x - 1;
half tiled_t = t_1 - 2 * floor(t_1 * 0.5) - 1;
if (sk_Caps.mustDoOpBetweenFloorAndAbs) {
// At this point the expected value of tiled_t should between -1 and 1, so this
// clamp has no effect other than to break up the floor and abs calls and make sure
// the compiler doesn't merge them back together.
tiled_t = clamp(tiled_t, -1, 1);
}
t.x = abs(tiled_t);
} else {
// Simple repeat mode
t.x = fract(t.x);
}
// Always sample from (x, 0), discarding y, since the layout FP can use y as a side-channel.
@if (!makePremul) {
return sample(colorizer, t.x0);
} else {
half4 outColor = sample(colorizer, t.x0);
return outColor * outColor.aaa1;
}
}
}
//////////////////////////////////////////////////////////////////////////////
// If the layout does not preserve opacity, remove the opaque optimization,
// but otherwise respect the provided color opacity state.
@optimizationFlags {
kCompatibleWithCoverageAsAlpha_OptimizationFlag |
(colorsAreOpaque && layoutPreservesOpacity ? kPreservesOpaqueInput_OptimizationFlag
: kNone_OptimizationFlags)
}
@make{
static std::unique_ptr<GrFragmentProcessor> Make(
std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
bool mirror,
bool makePremul,
bool colorsAreOpaque) {
bool layoutPreservesOpacity = gradLayout->preservesOpaqueInput();
return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(
std::move(colorizer), std::move(gradLayout), mirror, makePremul, colorsAreOpaque,
layoutPreservesOpacity));
}
}

View File

@ -1,130 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* 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 GrClampedGradientEffect.fp; do not modify.
**************************************************************************************************/
#include "GrClampedGradientEffect.h"
#include "src/core/SkUtils.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 GrGLSLClampedGradientEffect : public GrGLSLFragmentProcessor {
public:
GrGLSLClampedGradientEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrClampedGradientEffect& _outer = args.fFp.cast<GrClampedGradientEffect>();
(void)_outer;
auto leftBorderColor = _outer.leftBorderColor;
(void)leftBorderColor;
auto rightBorderColor = _outer.rightBorderColor;
(void)rightBorderColor;
auto makePremul = _outer.makePremul;
(void)makePremul;
auto colorsAreOpaque = _outer.colorsAreOpaque;
(void)colorsAreOpaque;
auto layoutPreservesOpacity = _outer.layoutPreservesOpacity;
(void)layoutPreservesOpacity;
leftBorderColorVar = args.fUniformHandler->addUniform(
&_outer, kFragment_GrShaderFlag, kHalf4_GrSLType, "leftBorderColor");
rightBorderColorVar = args.fUniformHandler->addUniform(
&_outer, kFragment_GrShaderFlag, kHalf4_GrSLType, "rightBorderColor");
SkString _sample0 = this->invokeChild(1, args);
fragBuilder->codeAppendf(
R"SkSL(half4 t = %s;
half4 outColor;
if (!%s && t.y < 0.0) {
outColor = half4(0.0);
} else if (t.x < 0.0) {
outColor = %s;
} else if (t.x > 1.0) {
outColor = %s;
} else {)SkSL",
_sample0.c_str(),
(_outer.layoutPreservesOpacity ? "true" : "false"),
args.fUniformHandler->getUniformCStr(leftBorderColorVar),
args.fUniformHandler->getUniformCStr(rightBorderColorVar));
SkString _coords1("float2(half2(t.x, 0.0))");
SkString _sample1 = this->invokeChild(0, args, _coords1.c_str());
fragBuilder->codeAppendf(
R"SkSL(
outColor = %s;
}
@if (%s) {
outColor.xyz *= outColor.w;
}
return outColor;
)SkSL",
_sample1.c_str(),
(_outer.makePremul ? "true" : "false"));
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrClampedGradientEffect& _outer = _proc.cast<GrClampedGradientEffect>();
{
pdman.set4fv(leftBorderColorVar, 1, _outer.leftBorderColor.vec());
pdman.set4fv(rightBorderColorVar, 1, _outer.rightBorderColor.vec());
}
}
UniformHandle leftBorderColorVar;
UniformHandle rightBorderColorVar;
};
std::unique_ptr<GrGLSLFragmentProcessor> GrClampedGradientEffect::onMakeProgramImpl() const {
return std::make_unique<GrGLSLClampedGradientEffect>();
}
void GrClampedGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->addBool(makePremul, "makePremul");
b->addBool(layoutPreservesOpacity, "layoutPreservesOpacity");
}
bool GrClampedGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrClampedGradientEffect& that = other.cast<GrClampedGradientEffect>();
(void)that;
if (leftBorderColor != that.leftBorderColor) return false;
if (rightBorderColor != that.rightBorderColor) return false;
if (makePremul != that.makePremul) return false;
if (colorsAreOpaque != that.colorsAreOpaque) return false;
if (layoutPreservesOpacity != that.layoutPreservesOpacity) return false;
return true;
}
GrClampedGradientEffect::GrClampedGradientEffect(const GrClampedGradientEffect& src)
: INHERITED(kGrClampedGradientEffect_ClassID, src.optimizationFlags())
, leftBorderColor(src.leftBorderColor)
, rightBorderColor(src.rightBorderColor)
, makePremul(src.makePremul)
, colorsAreOpaque(src.colorsAreOpaque)
, layoutPreservesOpacity(src.layoutPreservesOpacity) {
this->cloneAndRegisterAllChildProcessors(src);
}
std::unique_ptr<GrFragmentProcessor> GrClampedGradientEffect::clone() const {
return std::make_unique<GrClampedGradientEffect>(*this);
}
#if GR_TEST_UTILS
SkString GrClampedGradientEffect::onDumpInfo() const {
return SkStringPrintf(
"(leftBorderColor=half4(%f, %f, %f, %f), rightBorderColor=half4(%f, %f, %f, %f), "
"makePremul=%s, colorsAreOpaque=%s, layoutPreservesOpacity=%s)",
leftBorderColor.fR,
leftBorderColor.fG,
leftBorderColor.fB,
leftBorderColor.fA,
rightBorderColor.fR,
rightBorderColor.fG,
rightBorderColor.fB,
rightBorderColor.fA,
(makePremul ? "true" : "false"),
(colorsAreOpaque ? "true" : "false"),
(layoutPreservesOpacity ? "true" : "false"));
}
#endif

View File

@ -1,77 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* 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 GrClampedGradientEffect.fp; do not modify.
**************************************************************************************************/
#ifndef GrClampedGradientEffect_DEFINED
#define GrClampedGradientEffect_DEFINED
#include "include/core/SkM44.h"
#include "include/core/SkTypes.h"
#include "src/gpu/GrFragmentProcessor.h"
class GrClampedGradientEffect : public GrFragmentProcessor {
public:
static std::unique_ptr<GrFragmentProcessor> Make(
std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
SkPMColor4f leftBorderColor,
SkPMColor4f rightBorderColor,
bool makePremul,
bool colorsAreOpaque) {
bool layoutPreservesOpacity = gradLayout->preservesOpaqueInput();
return std::unique_ptr<GrFragmentProcessor>(
new GrClampedGradientEffect(std::move(colorizer),
std::move(gradLayout),
leftBorderColor,
rightBorderColor,
makePremul,
colorsAreOpaque,
layoutPreservesOpacity));
}
GrClampedGradientEffect(const GrClampedGradientEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "ClampedGradientEffect"; }
SkPMColor4f leftBorderColor;
SkPMColor4f rightBorderColor;
bool makePremul;
bool colorsAreOpaque;
bool layoutPreservesOpacity;
private:
GrClampedGradientEffect(std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
SkPMColor4f leftBorderColor,
SkPMColor4f rightBorderColor,
bool makePremul,
bool colorsAreOpaque,
bool layoutPreservesOpacity)
: INHERITED(kGrClampedGradientEffect_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag |
(colorsAreOpaque && layoutPreservesOpacity
? kPreservesOpaqueInput_OptimizationFlag
: kNone_OptimizationFlags))
, leftBorderColor(leftBorderColor)
, rightBorderColor(rightBorderColor)
, makePremul(makePremul)
, colorsAreOpaque(colorsAreOpaque)
, layoutPreservesOpacity(layoutPreservesOpacity) {
this->registerChild(std::move(colorizer), SkSL::SampleUsage::Explicit());
this->registerChild(std::move(gradLayout), SkSL::SampleUsage::PassThrough());
}
std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
#if GR_TEST_UTILS
SkString onDumpInfo() const override;
#endif
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
using INHERITED = GrFragmentProcessor;
};
#endif

View File

@ -1,117 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* 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 GrTiledGradientEffect.fp; do not modify.
**************************************************************************************************/
#include "GrTiledGradientEffect.h"
#include "src/core/SkUtils.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 GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor {
public:
GrGLSLTiledGradientEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>();
(void)_outer;
auto mirror = _outer.mirror;
(void)mirror;
auto makePremul = _outer.makePremul;
(void)makePremul;
auto colorsAreOpaque = _outer.colorsAreOpaque;
(void)colorsAreOpaque;
auto layoutPreservesOpacity = _outer.layoutPreservesOpacity;
(void)layoutPreservesOpacity;
SkString _sample0 = this->invokeChild(1, args);
fragBuilder->codeAppendf(
R"SkSL(half4 t = %s;
if (!%s && t.y < 0.0) {
return half4(0.0);
} else {
@if (%s) {
half t_1 = t.x - 1.0;
half tiled_t = (t_1 - 2.0 * floor(t_1 * 0.5)) - 1.0;
if (sk_Caps.mustDoOpBetweenFloorAndAbs) {
tiled_t = clamp(tiled_t, -1.0, 1.0);
}
t.x = abs(tiled_t);
} else {
t.x = fract(t.x);
}
@if (!%s) {)SkSL",
_sample0.c_str(),
(_outer.layoutPreservesOpacity ? "true" : "false"),
(_outer.mirror ? "true" : "false"),
(_outer.makePremul ? "true" : "false"));
SkString _coords1("float2(half2(t.x, 0.0))");
SkString _sample1 = this->invokeChild(0, args, _coords1.c_str());
fragBuilder->codeAppendf(
R"SkSL(
return %s;
} else {)SkSL",
_sample1.c_str());
SkString _coords2("float2(half2(t.x, 0.0))");
SkString _sample2 = this->invokeChild(0, args, _coords2.c_str());
fragBuilder->codeAppendf(
R"SkSL(
half4 outColor = %s;
return outColor * half4(outColor.www, 1.0);
}
}
)SkSL",
_sample2.c_str());
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
};
std::unique_ptr<GrGLSLFragmentProcessor> GrTiledGradientEffect::onMakeProgramImpl() const {
return std::make_unique<GrGLSLTiledGradientEffect>();
}
void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->addBool(mirror, "mirror");
b->addBool(makePremul, "makePremul");
b->addBool(layoutPreservesOpacity, "layoutPreservesOpacity");
}
bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
(void)that;
if (mirror != that.mirror) return false;
if (makePremul != that.makePremul) return false;
if (colorsAreOpaque != that.colorsAreOpaque) return false;
if (layoutPreservesOpacity != that.layoutPreservesOpacity) return false;
return true;
}
GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)
: INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags())
, mirror(src.mirror)
, makePremul(src.makePremul)
, colorsAreOpaque(src.colorsAreOpaque)
, layoutPreservesOpacity(src.layoutPreservesOpacity) {
this->cloneAndRegisterAllChildProcessors(src);
}
std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
return std::make_unique<GrTiledGradientEffect>(*this);
}
#if GR_TEST_UTILS
SkString GrTiledGradientEffect::onDumpInfo() const {
return SkStringPrintf(
"(mirror=%s, makePremul=%s, colorsAreOpaque=%s, layoutPreservesOpacity=%s)",
(mirror ? "true" : "false"),
(makePremul ? "true" : "false"),
(colorsAreOpaque ? "true" : "false"),
(layoutPreservesOpacity ? "true" : "false"));
}
#endif

View File

@ -1,72 +0,0 @@
/*
* Copyright 2018 Google Inc.
*
* 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 GrTiledGradientEffect.fp; do not modify.
**************************************************************************************************/
#ifndef GrTiledGradientEffect_DEFINED
#define GrTiledGradientEffect_DEFINED
#include "include/core/SkM44.h"
#include "include/core/SkTypes.h"
#include "src/gpu/GrFragmentProcessor.h"
class GrTiledGradientEffect : public GrFragmentProcessor {
public:
static std::unique_ptr<GrFragmentProcessor> Make(
std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
bool mirror,
bool makePremul,
bool colorsAreOpaque) {
bool layoutPreservesOpacity = gradLayout->preservesOpaqueInput();
return std::unique_ptr<GrFragmentProcessor>(
new GrTiledGradientEffect(std::move(colorizer),
std::move(gradLayout),
mirror,
makePremul,
colorsAreOpaque,
layoutPreservesOpacity));
}
GrTiledGradientEffect(const GrTiledGradientEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "TiledGradientEffect"; }
bool mirror;
bool makePremul;
bool colorsAreOpaque;
bool layoutPreservesOpacity;
private:
GrTiledGradientEffect(std::unique_ptr<GrFragmentProcessor> colorizer,
std::unique_ptr<GrFragmentProcessor> gradLayout,
bool mirror,
bool makePremul,
bool colorsAreOpaque,
bool layoutPreservesOpacity)
: INHERITED(kGrTiledGradientEffect_ClassID,
(OptimizationFlags)kCompatibleWithCoverageAsAlpha_OptimizationFlag |
(colorsAreOpaque && layoutPreservesOpacity
? kPreservesOpaqueInput_OptimizationFlag
: kNone_OptimizationFlags))
, mirror(mirror)
, makePremul(makePremul)
, colorsAreOpaque(colorsAreOpaque)
, layoutPreservesOpacity(layoutPreservesOpacity) {
this->registerChild(std::move(colorizer), SkSL::SampleUsage::Explicit());
this->registerChild(std::move(gradLayout), SkSL::SampleUsage::PassThrough());
}
std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
bool onIsEqual(const GrFragmentProcessor&) const override;
#if GR_TEST_UTILS
SkString onDumpInfo() const override;
#endif
GR_DECLARE_FRAGMENT_PROCESSOR_TEST
using INHERITED = GrFragmentProcessor;
};
#endif