clean up SK_SUPPORT_LEGACY_RUNTIME_EFFECTS

Cq-Include-Trybots: luci.chromium.try:linux-blink-rel
Change-Id: I4475982f0a5b17bcc4bae4b3f75557969cc70fd2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/369856
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2021-02-12 09:34:58 -06:00 committed by Skia Commit-Bot
parent 554aabbaa8
commit 7a2ff98ce6
14 changed files with 5 additions and 827 deletions

View File

@ -355,10 +355,6 @@ skia_gpu_sources = [
"$_src/gpu/effects/generated/GrEllipseEffect.h",
"$_src/gpu/effects/generated/GrHSLToRGBFilterEffect.cpp",
"$_src/gpu/effects/generated/GrHSLToRGBFilterEffect.h",
"$_src/gpu/effects/generated/GrHighContrastFilterEffect.cpp",
"$_src/gpu/effects/generated/GrHighContrastFilterEffect.h",
"$_src/gpu/effects/generated/GrLumaColorFilterEffect.cpp",
"$_src/gpu/effects/generated/GrLumaColorFilterEffect.h",
"$_src/gpu/effects/generated/GrMagnifierEffect.cpp",
"$_src/gpu/effects/generated/GrMagnifierEffect.h",
"$_src/gpu/effects/generated/GrMixerEffect.cpp",

View File

@ -182,8 +182,6 @@ skia_gpu_processor_sources = [
"$_src/gpu/effects/GrDitherEffect.fp",
"$_src/gpu/effects/GrEllipseEffect.fp",
"$_src/gpu/effects/GrHSLToRGBFilterEffect.fp",
"$_src/gpu/effects/GrHighContrastFilterEffect.fp",
"$_src/gpu/effects/GrLumaColorFilterEffect.fp",
"$_src/gpu/effects/GrMagnifierEffect.fp",
"$_src/gpu/effects/GrMixerEffect.fp",
"$_src/gpu/effects/GrOverrideInputFragmentProcessor.fp",

View File

@ -9,7 +9,6 @@
#define SkHighContrastFilter_DEFINED
#include "include/core/SkColorFilter.h"
#include "include/core/SkPaint.h"
/**
* Configuration struct for SkHighContrastFilter.
@ -73,12 +72,9 @@ struct SkHighContrastConfig {
* -1.0 to 1.0.
*/
class SK_API SkHighContrastFilter {
public:
struct SK_API SkHighContrastFilter {
// Returns the filter, or nullptr if the config is invalid.
static sk_sp<SkColorFilter> Make(const SkHighContrastConfig& config);
static void RegisterFlattenables();
};
#endif

View File

@ -9,9 +9,6 @@
#define SkLumaColorFilter_DEFINED
#include "include/core/SkColorFilter.h"
#include "include/core/SkRefCnt.h"
class SkRasterPipeline;
/**
* SkLumaColorFilter multiplies the luma of its input into the alpha channel,
@ -30,14 +27,8 @@ class SkRasterPipeline;
* not luminance, a dot-product of linear color channels. So at least
* SkLumaColorFilter and feColorMatrix+luminanceToAlpha agree there.)
*/
class SK_API SkLumaColorFilter {
public:
struct SK_API SkLumaColorFilter {
static sk_sp<SkColorFilter> Make();
private:
friend class SkFlattenable;
static void RegisterFlattenable();
};
#endif

View File

@ -8,195 +8,7 @@
#include "include/core/SkString.h"
#include "include/effects/SkHighContrastFilter.h"
#include "include/effects/SkRuntimeEffect.h"
#include "include/private/SkColorData.h"
#include "include/private/SkTPin.h"
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkColorFilterBase.h"
#include "src/core/SkColorSpacePriv.h"
#include "src/core/SkEffectPriv.h"
#include "src/core/SkRasterPipeline.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkVM.h"
#include "src/core/SkWriteBuffer.h"
#if SK_SUPPORT_GPU
#include "src/gpu/GrColorInfo.h"
#include "src/gpu/effects/generated/GrHighContrastFilterEffect.h"
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
#endif
using InvertStyle = SkHighContrastConfig::InvertStyle;
class SkHighContrast_Filter : public SkColorFilterBase {
public:
SkHighContrast_Filter(const SkHighContrastConfig& config) : fConfig(config) {}
~SkHighContrast_Filter() override {}
#if SK_SUPPORT_GPU
GrFPResult asFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP,
GrRecordingContext*, const GrColorInfo&) const override;
#endif
bool onAppendStages(const SkStageRec& rec, bool shaderIsOpaque) const override;
skvm::Color onProgram(skvm::Builder*, skvm::Color, SkColorSpace*, skvm::Uniforms*,
SkArenaAlloc*) const override;
protected:
void flatten(SkWriteBuffer&) const override;
private:
SK_FLATTENABLE_HOOKS(SkHighContrast_Filter)
SkHighContrastConfig fConfig;
friend class SkHighContrastFilter;
using INHERITED = SkColorFilter;
};
bool SkHighContrast_Filter::onAppendStages(const SkStageRec& rec, bool shaderIsOpaque) const {
SkRasterPipeline* p = rec.fPipeline;
SkArenaAlloc* alloc = rec.fAlloc;
if (!shaderIsOpaque) {
p->append(SkRasterPipeline::unpremul);
}
// Linearize before applying high-contrast filter.
auto tf = alloc->make<skcms_TransferFunction>();
if (rec.fDstCS) {
rec.fDstCS->transferFn(tf);
} else {
// Historically we approximate untagged destinations as gamma 2.
// TODO: sRGB?
*tf = {2,1, 0,0,0,0,0};
}
p->append_transfer_function(*tf);
if (fConfig.fGrayscale) {
float r = SK_LUM_COEFF_R;
float g = SK_LUM_COEFF_G;
float b = SK_LUM_COEFF_B;
float* matrix = alloc->makeArray<float>(12);
matrix[0] = matrix[1] = matrix[2] = r;
matrix[3] = matrix[4] = matrix[5] = g;
matrix[6] = matrix[7] = matrix[8] = b;
p->append(SkRasterPipeline::matrix_3x4, matrix);
}
if (fConfig.fInvertStyle == InvertStyle::kInvertBrightness) {
float* matrix = alloc->makeArray<float>(12);
matrix[0] = matrix[4] = matrix[8] = -1;
matrix[9] = matrix[10] = matrix[11] = 1;
p->append(SkRasterPipeline::matrix_3x4, matrix);
} else if (fConfig.fInvertStyle == InvertStyle::kInvertLightness) {
p->append(SkRasterPipeline::rgb_to_hsl);
float* matrix = alloc->makeArray<float>(12);
matrix[0] = matrix[4] = matrix[11] = 1;
matrix[8] = -1;
p->append(SkRasterPipeline::matrix_3x4, matrix);
p->append(SkRasterPipeline::hsl_to_rgb);
}
if (fConfig.fContrast != 0.0) {
float* matrix = alloc->makeArray<float>(12);
float c = fConfig.fContrast;
float m = (1 + c) / (1 - c);
float b = (-0.5f * m + 0.5f);
matrix[0] = matrix[4] = matrix[8] = m;
matrix[9] = matrix[10] = matrix[11] = b;
p->append(SkRasterPipeline::matrix_3x4, matrix);
}
p->append(SkRasterPipeline::clamp_0);
p->append(SkRasterPipeline::clamp_1);
// Re-encode back from linear.
auto invTF = alloc->make<skcms_TransferFunction>();
if (rec.fDstCS) {
rec.fDstCS->invTransferFn(invTF);
} else {
// See above... historically untagged == gamma 2 in this filter.
*invTF ={0.5f,1, 0,0,0,0,0};
}
p->append_transfer_function(*invTF);
if (!shaderIsOpaque) {
p->append(SkRasterPipeline::premul);
}
return true;
}
skvm::Color SkHighContrast_Filter::onProgram(skvm::Builder* p, skvm::Color c, SkColorSpace* dstCS,
skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const {
c = p->unpremul(c);
// Linearize before applying high-contrast filter.
skcms_TransferFunction tf;
if (dstCS) {
dstCS->transferFn(&tf);
} else {
//sk_srgb_singleton()->transferFn(&tf);
tf = {2,1, 0,0,0,0,0};
}
c = sk_program_transfer_fn(p, uniforms, tf, c);
if (fConfig.fGrayscale) {
skvm::F32 gray = c.r * SK_LUM_COEFF_R
+ c.g * SK_LUM_COEFF_G
+ c.b * SK_LUM_COEFF_B;
c = {gray, gray, gray, c.a};
}
if (fConfig.fInvertStyle == InvertStyle::kInvertBrightness) {
c = {1-c.r, 1-c.g, 1-c.b, c.a};
} else if (fConfig.fInvertStyle == InvertStyle::kInvertLightness) {
auto [h, s, l, a] = p->to_hsla(c);
c = p->to_rgba({h, s, 1-l, a});
}
if (fConfig.fContrast != 0.0) {
const float m = (1 + fConfig.fContrast) / (1 - fConfig.fContrast);
const float b = (-0.5f * m + 0.5f);
skvm::F32 M = p->uniformF(uniforms->pushF(m));
skvm::F32 B = p->uniformF(uniforms->pushF(b));
c.r = c.r * M + B;
c.g = c.g * M + B;
c.b = c.b * M + B;
}
c.r = clamp01(c.r);
c.g = clamp01(c.g);
c.b = clamp01(c.b);
// Re-encode back from linear.
if (dstCS) {
dstCS->invTransferFn(&tf);
} else {
//sk_srgb_singleton()->invTransferFn(&tf);
tf = {0.5f,1, 0,0,0,0,0};
}
c = sk_program_transfer_fn(p, uniforms, tf, c);
return p->premul(c);
}
void SkHighContrast_Filter::flatten(SkWriteBuffer& buffer) const {
buffer.writeBool(fConfig.fGrayscale);
buffer.writeInt(static_cast<int>(fConfig.fInvertStyle));
buffer.writeScalar(fConfig.fContrast);
}
sk_sp<SkFlattenable> SkHighContrast_Filter::CreateProc(SkReadBuffer& buffer) {
SkHighContrastConfig config;
config.fGrayscale = buffer.readBool();
config.fInvertStyle = buffer.read32LE(InvertStyle::kLast);
config.fContrast = buffer.readScalar();
return SkHighContrastFilter::Make(config);
}
sk_sp<SkColorFilter> SkHighContrastFilter::Make(const SkHighContrastConfig& userConfig) {
if (!userConfig.isValid()) {
@ -210,9 +22,6 @@ sk_sp<SkColorFilter> SkHighContrastFilter::Make(const SkHighContrastConfig& user
-1.0f + FLT_EPSILON,
+1.0f - FLT_EPSILON);
#if defined(SK_SUPPORT_LEGACY_RUNTIME_EFFECTS)
return sk_make_sp<SkHighContrast_Filter>(config);
#else
struct { float M; } uniforms;
SkString code{
"uniform shader input;"
@ -257,10 +66,10 @@ sk_sp<SkColorFilter> SkHighContrastFilter::Make(const SkHighContrastConfig& user
if (config.fGrayscale) {
code += "c.rgb = dot(half3(0.2126, 0.7152, 0.0722), c.rgb).rrr;";
}
if (config.fInvertStyle == InvertStyle::kInvertBrightness) {
if (config.fInvertStyle == SkHighContrastConfig::InvertStyle::kInvertBrightness) {
code += "c.rgb = 1 - c.rgb;";
}
if (config.fInvertStyle == InvertStyle::kInvertLightness) {
if (config.fInvertStyle == SkHighContrastConfig::InvertStyle::kInvertLightness) {
code += "c.rgb = rgb_to_hsl(c.rgb);";
code += "c.b = 1 - c.b;";
code += "c.rgb = hsl_to_rgb(c.rgb);";
@ -286,18 +95,5 @@ sk_sp<SkColorFilter> SkHighContrastFilter::Make(const SkHighContrastConfig& user
return SkColorFilters::WithWorkingFormat(
effect->makeColorFilter(SkData::MakeWithCopy(&uniforms,sizeof(uniforms)), &input, 1),
&linear, nullptr/*use dst gamut*/, &unpremul);
#endif
}
void SkHighContrastFilter::RegisterFlattenables() {
SK_REGISTER_FLATTENABLE(SkHighContrast_Filter);
}
#if SK_SUPPORT_GPU
GrFPResult SkHighContrast_Filter::asFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP,
GrRecordingContext*,
const GrColorInfo& csi) const {
bool linearize = !csi.isLinearlyBlended();
return GrFPSuccess(GrHighContrastFilterEffect::Make(std::move(inputFP), fConfig, linearize));
}
#endif

View File

@ -8,62 +8,8 @@
#include "include/core/SkString.h"
#include "include/effects/SkLumaColorFilter.h"
#include "include/effects/SkRuntimeEffect.h"
#include "include/private/SkColorData.h"
#include "src/core/SkColorFilterBase.h"
#include "src/core/SkEffectPriv.h"
#include "src/core/SkRasterPipeline.h"
#include "src/core/SkVM.h"
#if SK_SUPPORT_GPU
#include "src/gpu/effects/generated/GrLumaColorFilterEffect.h"
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
#endif
class SkLumaColorFilterImpl : public SkColorFilterBase {
public:
#if SK_SUPPORT_GPU
GrFPResult asFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP,
GrRecordingContext*, const GrColorInfo&) const override {
return GrFPSuccess(GrLumaColorFilterEffect::Make(std::move(inputFP)));
}
#endif
static sk_sp<SkFlattenable> CreateProc(SkReadBuffer&) {
return SkLumaColorFilter::Make();
}
protected:
void flatten(SkWriteBuffer&) const override {}
private:
Factory getFactory() const override { return CreateProc; }
const char* getTypeName() const override { return "SkLumaColorFilter"; }
bool onAppendStages(const SkStageRec& rec, bool shaderIsOpaque) const override {
rec.fPipeline->append(SkRasterPipeline::bt709_luminance_or_luma_to_alpha);
rec.fPipeline->append(SkRasterPipeline::clamp_0);
rec.fPipeline->append(SkRasterPipeline::clamp_1);
return true;
}
skvm::Color onProgram(skvm::Builder* p, skvm::Color c, SkColorSpace*, skvm::Uniforms*,
SkArenaAlloc*) const override {
return {
p->splat(0.0f),
p->splat(0.0f),
p->splat(0.0f),
clamp01(c.r * 0.2126f + c.g * 0.7152f + c.b * 0.0722f),
};
}
using INHERITED = SkColorFilterBase;
};
sk_sp<SkColorFilter> SkLumaColorFilter::Make() {
#if defined(SK_SUPPORT_LEGACY_RUNTIME_EFFECTS)
return sk_sp<SkColorFilter>(new SkLumaColorFilterImpl);
#else
static SkRuntimeEffect* effect = []{
const char* code =
"uniform shader input;"
@ -77,9 +23,4 @@ sk_sp<SkColorFilter> SkLumaColorFilter::Make() {
sk_sp<SkColorFilter> input = nullptr;
return effect->makeColorFilter(SkData::MakeEmpty(), &input, 1);
#endif
}
void SkLumaColorFilter::RegisterFlattenable() {
SkFlattenable::Register("SkLumaColorFilter", SkLumaColorFilterImpl::CreateProc);
}

View File

@ -147,7 +147,7 @@ SkTArray<GrXPFactoryTestFactory*, true>* GrXPFactoryTestFactory::GetFactories()
* we verify the count is as expected. If a new factory is added, then these numbers must be
* manually adjusted.
*/
static constexpr int kFPFactoryCount = 36;
static constexpr int kFPFactoryCount = 35;
static constexpr int kGPFactoryCount = 14;
static constexpr int kXPFactoryCount = 4;

View File

@ -1,133 +0,0 @@
/*
* Copyright 2020 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@header {
#include "include/effects/SkHighContrastFilter.h"
}
in fragmentProcessor inputFP;
in uniform half contrastMod;
layout(key) in bool hasContrast;
layout(key) in bool grayscale;
// invertBrightness and invertLightness are intended to be mutually exclusive.
layout(key) in bool invertBrightness;
layout(key) in bool invertLightness;
layout(key) in bool linearize;
half HSLToRGB(half p, half q, half t) {
if (t < 0)
t += 1;
if (t > 1)
t -= 1;
return (t < 1/6.) ? p + (q - p) * 6 * t :
(t < 3/6.) ? q :
(t < 4/6.) ? p + (q - p) * (2/3. - t) * 6 :
p;
}
half4 main() {
const half3 SK_ITU_BT709_LUM_COEFF = half3(0.2126, 0.7152, 0.0722);
half4 inColor = sample(inputFP);
half4 color = unpremul(inColor);
@if (linearize) {
// We approximate the transfer function as gamma 2.0.
color.rgb = color.rgb * color.rgb;
}
@if (grayscale) {
color = half4(half3(dot(color.rgb, SK_ITU_BT709_LUM_COEFF)), 0);
}
@if (invertBrightness) {
color = half4(1) - color;
}
@if (invertLightness) {
half fmax = max(color.r, max(color.g, color.b));
half fmin = min(color.r, min(color.g, color.b));
half l = fmax + fmin;
half h;
half s;
if (fmax == fmin) {
h = 0;
s = 0;
} else {
half d = fmax - fmin;
s = (l > 1) ? d / (2 - l) : d / l;
// We'd like to just write "if (color.r == fmax) { ... }". On many GPUs, running the
// angle_d3d9_es2 config, that failed. It seems that max(x, y) is not necessarily equal
// to either x or y. Tried several ways to fix it, but this was the only reasonable fix.
if (color.r >= color.g && color.r >= color.b) {
h = (color.g - color.b) / d + (color.g < color.b ? 6 : 0);
} else if (color.g >= color.b) {
h = (color.b - color.r) / d + 2;
} else {
h = (color.r - color.g) / d + 4;
}
h *= 1/6.;
}
l = 1.0 + (l * -0.5);
if (s == 0) {
color = half4(l, l, l, 0);
} else {
half q = l < 0.5 ? l * (1 + s) : l + s - l * s;
half p = 2 * l - q;
color.r = HSLToRGB(p, q, h + 1/3.);
color.g = HSLToRGB(p, q, h);
color.b = HSLToRGB(p, q, h - 1/3.);
}
}
@if (hasContrast) {
half off = (-0.5 * contrastMod) + 0.5;
color = contrastMod * color + off;
}
color = saturate(color);
@if (linearize) {
color.rgb = sqrt(color.rgb);
}
return color.rgb1 * inColor.a;
}
@optimizationFlags {
kNone_OptimizationFlags
}
@make {
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP,
const SkHighContrastConfig& config,
bool linearize) {
float contrastMod = (1 + config.fContrast) / (1 - config.fContrast);
return std::unique_ptr<GrFragmentProcessor>(new GrHighContrastFilterEffect(
std::move(inputFP),
contrastMod,
contrastMod != 1.0,
config.fGrayscale,
config.fInvertStyle == SkHighContrastConfig::InvertStyle::kInvertBrightness,
config.fInvertStyle == SkHighContrastConfig::InvertStyle::kInvertLightness,
linearize));
}
}
@test(d) {
using InvertStyle = SkHighContrastConfig::InvertStyle;
SkHighContrastConfig config{/*grayscale=*/d->fRandom->nextBool(),
InvertStyle(d->fRandom->nextRangeU(0, int(InvertStyle::kLast))),
/*contrast=*/d->fRandom->nextF()};
return GrHighContrastFilterEffect::Make(d->inputFP(), config,
/*linearize=*/d->fRandom->nextBool());
}

View File

@ -1,32 +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.
*/
in fragmentProcessor inputFP;
@optimizationFlags {
(inputFP ? ProcessorOptimizationFlags(inputFP.get()) : kAll_OptimizationFlags) &
kConstantOutputForConstantInput_OptimizationFlag
}
@class {
#include "include/private/SkColorData.h"
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override {
SkPMColor4f input = ConstantOutputForConstantInput(this->childProcessor(0), inColor);
float luma = SK_ITU_BT709_LUM_COEFF_R * input.fR +
SK_ITU_BT709_LUM_COEFF_G * input.fG +
SK_ITU_BT709_LUM_COEFF_B * input.fB;
return { 0, 0, 0, SkTPin(luma, 0.0f, 1.0f) };
}
}
half4 main() {
half4 inputColor = sample(inputFP);
const half3 SK_ITU_BT709_LUM_COEFF = half3(0.2126, 0.7152, 0.0722);
half luma = saturate(dot(SK_ITU_BT709_LUM_COEFF, inputColor.rgb));
return luma.000x;
}

View File

@ -1,183 +0,0 @@
/*
* Copyright 2020 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 GrHighContrastFilterEffect.fp; do not modify.
**************************************************************************************************/
#include "GrHighContrastFilterEffect.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 GrGLSLHighContrastFilterEffect : public GrGLSLFragmentProcessor {
public:
GrGLSLHighContrastFilterEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrHighContrastFilterEffect& _outer = args.fFp.cast<GrHighContrastFilterEffect>();
(void)_outer;
auto contrastMod = _outer.contrastMod;
(void)contrastMod;
auto hasContrast = _outer.hasContrast;
(void)hasContrast;
auto grayscale = _outer.grayscale;
(void)grayscale;
auto invertBrightness = _outer.invertBrightness;
(void)invertBrightness;
auto invertLightness = _outer.invertLightness;
(void)invertLightness;
auto linearize = _outer.linearize;
(void)linearize;
contrastModVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag,
kHalf_GrSLType, "contrastMod");
SkString HSLToRGB_name = fragBuilder->getMangledFunctionName("HSLToRGB");
const GrShaderVar HSLToRGB_args[] = {GrShaderVar("p", kHalf_GrSLType),
GrShaderVar("q", kHalf_GrSLType),
GrShaderVar("t", kHalf_GrSLType)};
fragBuilder->emitFunction(kHalf_GrSLType, HSLToRGB_name.c_str(), {HSLToRGB_args, 3},
R"SkSL(if (t < 0.0) t += 1.0;
if (t > 1.0) t -= 1.0;
return t < 0.1666666716337204 ? p + ((q - p) * 6.0) * t : (t < 0.5 ? q : (t < 0.66666668653488159 ? p + ((q - p) * (0.66666668653488159 - t)) * 6.0 : p));
)SkSL");
fragBuilder->codeAppendf(
R"SkSL(;)SkSL");
SkString _sample0 = this->invokeChild(0, args);
fragBuilder->codeAppendf(
R"SkSL(
half4 inColor = %s;
half4 color = half4(inColor.xyz / max(inColor.w, 9.9999997473787516e-05), inColor.w);
@if (%s) {
color.xyz = color.xyz * color.xyz;
}
@if (%s) {
color = half4(half3(dot(color.xyz, half3(0.2125999927520752, 0.71520000696182251, 0.072200000286102295))), 0.0);
}
@if (%s) {
color = half4(1.0) - color;
}
@if (%s) {
half fmax = max(color.x, max(color.y, color.z));
half fmin = min(color.x, min(color.y, color.z));
half l = fmax + fmin;
half h;
half s;
if (fmax == fmin) {
h = 0.0;
s = 0.0;
} else {
half d = fmax - fmin;
s = l > 1.0 ? d / (2.0 - l) : d / l;
if (color.x >= color.y && color.x >= color.z) {
h = (color.y - color.z) / d + half(color.y < color.z ? 6 : 0);
} else if (color.y >= color.z) {
h = (color.z - color.x) / d + 2.0;
} else {
h = (color.x - color.y) / d + 4.0;
}
h *= 0.1666666716337204;
}
l = 1.0 + l * -0.5;
if (s == 0.0) {
color = half4(l, l, l, 0.0);
} else {
half q = l < 0.5 ? l * (1.0 + s) : (l + s) - l * s;
half p = 2.0 * l - q;
color.x = %s(p, q, h + 0.3333333432674408);
color.y = %s(p, q, h);
color.z = %s(p, q, h - 0.3333333432674408);
}
}
@if (%s) {
half off = -0.5 * %s + 0.5;
color = %s * color + off;
}
color = clamp(color, 0.0, 1.0);
@if (%s) {
color.xyz = sqrt(color.xyz);
}
return half4(color.xyz, 1.0) * inColor.w;
)SkSL",
_sample0.c_str(), (_outer.linearize ? "true" : "false"),
(_outer.grayscale ? "true" : "false"), (_outer.invertBrightness ? "true" : "false"),
(_outer.invertLightness ? "true" : "false"), HSLToRGB_name.c_str(),
HSLToRGB_name.c_str(), HSLToRGB_name.c_str(),
(_outer.hasContrast ? "true" : "false"),
args.fUniformHandler->getUniformCStr(contrastModVar),
args.fUniformHandler->getUniformCStr(contrastModVar),
(_outer.linearize ? "true" : "false"));
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {
const GrHighContrastFilterEffect& _outer = _proc.cast<GrHighContrastFilterEffect>();
{ pdman.set1f(contrastModVar, (_outer.contrastMod)); }
}
UniformHandle contrastModVar;
};
GrGLSLFragmentProcessor* GrHighContrastFilterEffect::onCreateGLSLInstance() const {
return new GrGLSLHighContrastFilterEffect();
}
void GrHighContrastFilterEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {
b->add32((uint32_t)hasContrast);
b->add32((uint32_t)grayscale);
b->add32((uint32_t)invertBrightness);
b->add32((uint32_t)invertLightness);
b->add32((uint32_t)linearize);
}
bool GrHighContrastFilterEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrHighContrastFilterEffect& that = other.cast<GrHighContrastFilterEffect>();
(void)that;
if (contrastMod != that.contrastMod) return false;
if (hasContrast != that.hasContrast) return false;
if (grayscale != that.grayscale) return false;
if (invertBrightness != that.invertBrightness) return false;
if (invertLightness != that.invertLightness) return false;
if (linearize != that.linearize) return false;
return true;
}
GrHighContrastFilterEffect::GrHighContrastFilterEffect(const GrHighContrastFilterEffect& src)
: INHERITED(kGrHighContrastFilterEffect_ClassID, src.optimizationFlags())
, contrastMod(src.contrastMod)
, hasContrast(src.hasContrast)
, grayscale(src.grayscale)
, invertBrightness(src.invertBrightness)
, invertLightness(src.invertLightness)
, linearize(src.linearize) {
this->cloneAndRegisterAllChildProcessors(src);
}
std::unique_ptr<GrFragmentProcessor> GrHighContrastFilterEffect::clone() const {
return std::make_unique<GrHighContrastFilterEffect>(*this);
}
#if GR_TEST_UTILS
SkString GrHighContrastFilterEffect::onDumpInfo() const {
return SkStringPrintf(
"(contrastMod=%f, hasContrast=%s, grayscale=%s, invertBrightness=%s, "
"invertLightness=%s, linearize=%s)",
contrastMod, (hasContrast ? "true" : "false"), (grayscale ? "true" : "false"),
(invertBrightness ? "true" : "false"), (invertLightness ? "true" : "false"),
(linearize ? "true" : "false"));
}
#endif
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrHighContrastFilterEffect);
#if GR_TEST_UTILS
std::unique_ptr<GrFragmentProcessor> GrHighContrastFilterEffect::TestCreate(
GrProcessorTestData* d) {
using InvertStyle = SkHighContrastConfig::InvertStyle;
SkHighContrastConfig config{/*grayscale=*/d->fRandom->nextBool(),
InvertStyle(d->fRandom->nextRangeU(0, int(InvertStyle::kLast))),
/*contrast=*/d->fRandom->nextF()};
return GrHighContrastFilterEffect::Make(d->inputFP(), config,
/*linearize=*/d->fRandom->nextBool());
}
#endif

View File

@ -1,74 +0,0 @@
/*
* Copyright 2020 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 GrHighContrastFilterEffect.fp; do not modify.
**************************************************************************************************/
#ifndef GrHighContrastFilterEffect_DEFINED
#define GrHighContrastFilterEffect_DEFINED
#include "include/core/SkM44.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkHighContrastFilter.h"
#include "src/gpu/GrFragmentProcessor.h"
class GrHighContrastFilterEffect : public GrFragmentProcessor {
public:
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP,
const SkHighContrastConfig& config,
bool linearize) {
float contrastMod = (1 + config.fContrast) / (1 - config.fContrast);
return std::unique_ptr<GrFragmentProcessor>(new GrHighContrastFilterEffect(
std::move(inputFP),
contrastMod,
contrastMod != 1.0,
config.fGrayscale,
config.fInvertStyle == SkHighContrastConfig::InvertStyle::kInvertBrightness,
config.fInvertStyle == SkHighContrastConfig::InvertStyle::kInvertLightness,
linearize));
}
GrHighContrastFilterEffect(const GrHighContrastFilterEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "HighContrastFilterEffect"; }
float contrastMod;
bool hasContrast;
bool grayscale;
bool invertBrightness;
bool invertLightness;
bool linearize;
private:
GrHighContrastFilterEffect(std::unique_ptr<GrFragmentProcessor> inputFP,
float contrastMod,
bool hasContrast,
bool grayscale,
bool invertBrightness,
bool invertLightness,
bool linearize)
: INHERITED(kGrHighContrastFilterEffect_ClassID,
(OptimizationFlags)kNone_OptimizationFlags)
, contrastMod(contrastMod)
, hasContrast(hasContrast)
, grayscale(grayscale)
, invertBrightness(invertBrightness)
, invertLightness(invertLightness)
, linearize(linearize) {
this->registerChild(std::move(inputFP), SkSL::SampleUsage::PassThrough());
}
GrGLSLFragmentProcessor* onCreateGLSLInstance() 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,60 +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 GrLumaColorFilterEffect.fp; do not modify.
**************************************************************************************************/
#include "GrLumaColorFilterEffect.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 GrGLSLLumaColorFilterEffect : public GrGLSLFragmentProcessor {
public:
GrGLSLLumaColorFilterEffect() {}
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrLumaColorFilterEffect& _outer = args.fFp.cast<GrLumaColorFilterEffect>();
(void)_outer;
SkString _sample0 = this->invokeChild(0, args);
fragBuilder->codeAppendf(
R"SkSL(half4 inputColor = %s;
;
half luma = clamp(dot(half3(0.2125999927520752, 0.71520000696182251, 0.072200000286102295), inputColor.xyz), 0.0, 1.0);
return half4(0.0, 0.0, 0.0, luma);
)SkSL",
_sample0.c_str());
}
private:
void onSetData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& _proc) override {}
};
GrGLSLFragmentProcessor* GrLumaColorFilterEffect::onCreateGLSLInstance() const {
return new GrGLSLLumaColorFilterEffect();
}
void GrLumaColorFilterEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
GrProcessorKeyBuilder* b) const {}
bool GrLumaColorFilterEffect::onIsEqual(const GrFragmentProcessor& other) const {
const GrLumaColorFilterEffect& that = other.cast<GrLumaColorFilterEffect>();
(void)that;
return true;
}
GrLumaColorFilterEffect::GrLumaColorFilterEffect(const GrLumaColorFilterEffect& src)
: INHERITED(kGrLumaColorFilterEffect_ClassID, src.optimizationFlags()) {
this->cloneAndRegisterAllChildProcessors(src);
}
std::unique_ptr<GrFragmentProcessor> GrLumaColorFilterEffect::clone() const {
return std::make_unique<GrLumaColorFilterEffect>(*this);
}
#if GR_TEST_UTILS
SkString GrLumaColorFilterEffect::onDumpInfo() const { return SkString(); }
#endif

View File

@ -1,54 +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 GrLumaColorFilterEffect.fp; do not modify.
**************************************************************************************************/
#ifndef GrLumaColorFilterEffect_DEFINED
#define GrLumaColorFilterEffect_DEFINED
#include "include/core/SkM44.h"
#include "include/core/SkTypes.h"
#include "src/gpu/GrFragmentProcessor.h"
class GrLumaColorFilterEffect : public GrFragmentProcessor {
public:
#include "include/private/SkColorData.h"
SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& inColor) const override {
SkPMColor4f input = ConstantOutputForConstantInput(this->childProcessor(0), inColor);
float luma = SK_ITU_BT709_LUM_COEFF_R * input.fR + SK_ITU_BT709_LUM_COEFF_G * input.fG +
SK_ITU_BT709_LUM_COEFF_B * input.fB;
return {0, 0, 0, SkTPin(luma, 0.0f, 1.0f)};
}
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> inputFP) {
return std::unique_ptr<GrFragmentProcessor>(
new GrLumaColorFilterEffect(std::move(inputFP)));
}
GrLumaColorFilterEffect(const GrLumaColorFilterEffect& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
const char* name() const override { return "LumaColorFilterEffect"; }
private:
GrLumaColorFilterEffect(std::unique_ptr<GrFragmentProcessor> inputFP)
: INHERITED(kGrLumaColorFilterEffect_ClassID,
(OptimizationFlags)(inputFP ? ProcessorOptimizationFlags(inputFP.get())
: kAll_OptimizationFlags) &
kConstantOutputForConstantInput_OptimizationFlag) {
this->registerChild(std::move(inputFP), SkSL::SampleUsage::PassThrough());
}
GrGLSLFragmentProcessor* onCreateGLSLInstance() 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

@ -22,8 +22,6 @@
#include "include/effects/SkCornerPathEffect.h"
#include "include/effects/SkDiscretePathEffect.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkHighContrastFilter.h"
#include "include/effects/SkLumaColorFilter.h"
#include "include/effects/SkOverdrawColorFilter.h"
#include "include/effects/SkPerlinNoiseShader.h"
#include "include/effects/SkRuntimeEffect.h"
@ -77,9 +75,7 @@
// Color filters.
SkColorFilter_Matrix::RegisterFlattenables();
SkLumaColorFilter::RegisterFlattenable();
SkColorFilterBase::RegisterFlattenables();
SkHighContrastFilter::RegisterFlattenables();
SkTableColorFilter::RegisterFlattenables();
// Shader & color filter.