diff options
-rw-r--r-- | gn/gpu.gni | 4 | ||||
-rw-r--r-- | gn/sksl.gni | 2 | ||||
-rw-r--r-- | src/gpu/GrFragmentProcessor.cpp | 97 | ||||
-rw-r--r-- | src/gpu/GrProcessor.h | 4 | ||||
-rw-r--r-- | src/gpu/effects/GrPremulInputFragmentProcessor.cpp | 52 | ||||
-rw-r--r-- | src/gpu/effects/GrPremulInputFragmentProcessor.fp | 14 | ||||
-rw-r--r-- | src/gpu/effects/GrPremulInputFragmentProcessor.h | 41 | ||||
-rw-r--r-- | src/gpu/effects/GrUnpremulInputFragmentProcessor.cpp | 53 | ||||
-rw-r--r-- | src/gpu/effects/GrUnpremulInputFragmentProcessor.fp | 15 | ||||
-rw-r--r-- | src/gpu/effects/GrUnpremulInputFragmentProcessor.h | 41 |
10 files changed, 229 insertions, 94 deletions
diff --git a/gn/gpu.gni b/gn/gpu.gni index e283a9f12f..e584bf5187 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -360,6 +360,8 @@ skia_gpu_sources = [ "$_src/gpu/effects/GrOvalEffect.h", "$_src/gpu/effects/GrPorterDuffXferProcessor.cpp", "$_src/gpu/effects/GrPorterDuffXferProcessor.h", + "$_src/gpu/effects/GrPremulInputFragmentProcessor.cpp", + "$_src/gpu/effects/GrPremulInputFragmentProcessor.h", "$_src/gpu/effects/GrRectBlurEffect.cpp", "$_src/gpu/effects/GrRectBlurEffect.h", "$_src/gpu/effects/GrRRectEffect.cpp", @@ -373,6 +375,8 @@ skia_gpu_sources = [ "$_src/gpu/effects/GrTextureDomain.cpp", "$_src/gpu/effects/GrTextureDomain.h", "$_src/gpu/effects/GrTextureStripAtlas.cpp", + "$_src/gpu/effects/GrUnpremulInputFragmentProcessor.cpp", + "$_src/gpu/effects/GrUnpremulInputFragmentProcessor.h", "$_src/gpu/effects/GrXfermodeFragmentProcessor.cpp", "$_src/gpu/effects/GrXfermodeFragmentProcessor.h", "$_src/gpu/effects/GrYUVEffect.cpp", diff --git a/gn/sksl.gni b/gn/sksl.gni index 6eec537ebe..3bc0a1dd1a 100644 --- a/gn/sksl.gni +++ b/gn/sksl.gni @@ -36,7 +36,9 @@ skia_gpu_processor_sources = [ "$_src/gpu/effects/GrDitherEffect.fp", "$_src/gpu/effects/GrEllipseEffect.fp", "$_src/gpu/effects/GrLumaColorFilterEffect.fp", + "$_src/gpu/effects/GrPremulInputFragmentProcessor.fp", "$_src/gpu/effects/GrRectBlurEffect.fp", "$_src/gpu/effects/GrOverdrawFragmentProcessor.fp", "$_src/gpu/effects/GrSimpleTextureEffect.fp", + "$_src/gpu/effects/GrUnpremulInputFragmentProcessor.fp", ] diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp index 90bbb33e60..a50be79872 100644 --- a/src/gpu/GrFragmentProcessor.cpp +++ b/src/gpu/GrFragmentProcessor.cpp @@ -10,7 +10,9 @@ #include "GrPipeline.h" #include "GrProcessorAnalysis.h" #include "effects/GrConstColorProcessor.h" +#include "effects/GrPremulInputFragmentProcessor.h" #include "effects/GrXfermodeFragmentProcessor.h" +#include "effects/GrUnpremulInputFragmentProcessor.h" #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" #include "glsl/GrGLSLProgramDataManager.h" @@ -109,101 +111,12 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::MulOutputByInputAlpha( return GrXfermodeFragmentProcessor::MakeFromDstProcessor(std::move(fp), SkBlendMode::kDstIn); } -namespace { - -class PremulInputFragmentProcessor : public GrFragmentProcessor { -public: - static std::unique_ptr<GrFragmentProcessor> Make() { - return std::unique_ptr<GrFragmentProcessor>(new PremulInputFragmentProcessor); - } - - const char* name() const override { return "PremultiplyInput"; } - - std::unique_ptr<GrFragmentProcessor> clone() const override { return Make(); } - -private: - PremulInputFragmentProcessor() - : INHERITED(kPremulInputFragmentProcessor_ClassID, - kPreservesOpaqueInput_OptimizationFlag | - kConstantOutputForConstantInput_OptimizationFlag) { - } - - GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { - class GLFP : public GrGLSLFragmentProcessor { - public: - void emitCode(EmitArgs& args) override { - GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; - - fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args.fInputColor); - fragBuilder->codeAppendf("%s.rgb *= %s.a;", - args.fOutputColor, args.fInputColor); - } - }; - return new GLFP; - } - - void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} - - bool onIsEqual(const GrFragmentProcessor&) const override { return true; } - - GrColor4f constantOutputForConstantInput(GrColor4f input) const override { - return input.premul(); - } - - typedef GrFragmentProcessor INHERITED; -}; - -class UnpremulInputFragmentProcessor : public GrFragmentProcessor { -public: - static std::unique_ptr<GrFragmentProcessor> Make() { - return std::unique_ptr<GrFragmentProcessor>(new UnpremulInputFragmentProcessor); - } - - const char* name() const override { return "UnpremultiplyInput"; } - - std::unique_ptr<GrFragmentProcessor> clone() const override { return Make(); } - -private: - UnpremulInputFragmentProcessor() - : INHERITED(kUnpremulInputFragmentProcessor_ClassID, - kPreservesOpaqueInput_OptimizationFlag | - kConstantOutputForConstantInput_OptimizationFlag) { - } - - GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { - class GLFP : public GrGLSLFragmentProcessor { - public: - void emitCode(EmitArgs& args) override { - GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; - - fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, args.fInputColor); - fragBuilder->codeAppendf("half invAlpha = %s.a <= 0.0 ? 0.0 : 1.0 / %s.a;", - args.fInputColor, args.fInputColor); - fragBuilder->codeAppendf("%s.rgb *= invAlpha;", args.fOutputColor); - } - }; - return new GLFP; - } - - void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {} - - bool onIsEqual(const GrFragmentProcessor&) const override { return true; } - - GrColor4f constantOutputForConstantInput(GrColor4f input) const override { - return input.unpremul(); - } - - typedef GrFragmentProcessor INHERITED; -}; - -} - std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::PremulInput( std::unique_ptr<GrFragmentProcessor> fp) { if (!fp) { return nullptr; } - std::unique_ptr<GrFragmentProcessor> fpPipeline[] = { PremulInputFragmentProcessor::Make(), + std::unique_ptr<GrFragmentProcessor> fpPipeline[] = { GrPremulInputFragmentProcessor::Make(), std::move(fp) }; return GrFragmentProcessor::RunInSeries(fpPipeline, 2); } @@ -214,7 +127,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::PremulOutput( return nullptr; } std::unique_ptr<GrFragmentProcessor> fpPipeline[] = { std::move(fp), - PremulInputFragmentProcessor::Make() }; + GrPremulInputFragmentProcessor::Make() }; return GrFragmentProcessor::RunInSeries(fpPipeline, 2); } @@ -224,7 +137,7 @@ std::unique_ptr<GrFragmentProcessor> GrFragmentProcessor::UnpremulOutput( return nullptr; } std::unique_ptr<GrFragmentProcessor> fpPipeline[] = { std::move(fp), - UnpremulInputFragmentProcessor::Make() }; + GrUnpremulInputFragmentProcessor::Make() }; return GrFragmentProcessor::RunInSeries(fpPipeline, 2); } diff --git a/src/gpu/GrProcessor.h b/src/gpu/GrProcessor.h index adb5df3a42..69372b1ca7 100644 --- a/src/gpu/GrProcessor.h +++ b/src/gpu/GrProcessor.h @@ -126,6 +126,7 @@ public: kGrPathProcessor_ClassID, kGrPerlinNoise2Effect_ClassID, kGrPipelineDynamicStateTestProcessor_ClassID, + kGrPremulInputFragmentProcessor_ClassID, kGrQuadEffect_ClassID, kGrRadialGradient_ClassID, kGrRectBlurEffect_ClassID, @@ -136,6 +137,7 @@ public: kGrSRGBEffect_ClassID, kGrSweepGradient_ClassID, kGrTextureDomainEffect_ClassID, + kGrUnpremulInputFragmentProcessor_ClassID, kHighContrastFilterEffect_ClassID, kInstanceProcessor_ClassID, kLumaColorFilterEffect_ClassID, @@ -143,7 +145,6 @@ public: kPDLCDXferProcessor_ClassID, kPorterDuffXferProcessor_ClassID, kPremulFragmentProcessor_ClassID, - kPremulInputFragmentProcessor_ClassID, kQuadEdgeEffect_ClassID, kReplaceInputFragmentProcessor_ClassID, kRRectsGaussianEdgeFP_ClassID, @@ -152,7 +153,6 @@ public: kSwizzleFragmentProcessor_ClassID, kTestFP_ClassID, kTextureGeometryProcessor_ClassID, - kUnpremulInputFragmentProcessor_ClassID, kYUVtoRGBEffect_ClassID }; diff --git a/src/gpu/effects/GrPremulInputFragmentProcessor.cpp b/src/gpu/effects/GrPremulInputFragmentProcessor.cpp new file mode 100644 index 0000000000..a90f52944e --- /dev/null +++ b/src/gpu/effects/GrPremulInputFragmentProcessor.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2017 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 GrPremulInputFragmentProcessor.fp; do not modify. + */ +#include "GrPremulInputFragmentProcessor.h" +#if SK_SUPPORT_GPU +#include "glsl/GrGLSLFragmentProcessor.h" +#include "glsl/GrGLSLFragmentShaderBuilder.h" +#include "glsl/GrGLSLProgramBuilder.h" +#include "SkSLCPP.h" +#include "SkSLUtil.h" +class GrGLSLPremulInputFragmentProcessor : public GrGLSLFragmentProcessor { +public: + GrGLSLPremulInputFragmentProcessor() {} + void emitCode(EmitArgs& args) override { + GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; + const GrPremulInputFragmentProcessor& _outer = + args.fFp.cast<GrPremulInputFragmentProcessor>(); + (void)_outer; + fragBuilder->codeAppendf("%s = %s;\n%s.xyz *= %s.w;\n", args.fOutputColor, + args.fInputColor ? args.fInputColor : "half4(1)", + args.fOutputColor, + args.fInputColor ? args.fInputColor : "half4(1)"); + } + +private: + void onSetData(const GrGLSLProgramDataManager& pdman, + const GrFragmentProcessor& _proc) override {} +}; +GrGLSLFragmentProcessor* GrPremulInputFragmentProcessor::onCreateGLSLInstance() const { + return new GrGLSLPremulInputFragmentProcessor(); +} +void GrPremulInputFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, + GrProcessorKeyBuilder* b) const {} +bool GrPremulInputFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const { + const GrPremulInputFragmentProcessor& that = other.cast<GrPremulInputFragmentProcessor>(); + (void)that; + return true; +} +GrPremulInputFragmentProcessor::GrPremulInputFragmentProcessor( + const GrPremulInputFragmentProcessor& src) + : INHERITED(kGrPremulInputFragmentProcessor_ClassID, src.optimizationFlags()) {} +std::unique_ptr<GrFragmentProcessor> GrPremulInputFragmentProcessor::clone() const { + return std::unique_ptr<GrFragmentProcessor>(new GrPremulInputFragmentProcessor(*this)); +} +#endif diff --git a/src/gpu/effects/GrPremulInputFragmentProcessor.fp b/src/gpu/effects/GrPremulInputFragmentProcessor.fp new file mode 100644 index 0000000000..5a0d6c5f96 --- /dev/null +++ b/src/gpu/effects/GrPremulInputFragmentProcessor.fp @@ -0,0 +1,14 @@ +@optimizationFlags { + kPreservesOpaqueInput_OptimizationFlag | kConstantOutputForConstantInput_OptimizationFlag +} + +void main() { + sk_OutColor = sk_InColor; + sk_OutColor.rgb *= sk_InColor.a; +} + +@class { + GrColor4f constantOutputForConstantInput(GrColor4f input) const override { + return input.premul(); + } +}
\ No newline at end of file diff --git a/src/gpu/effects/GrPremulInputFragmentProcessor.h b/src/gpu/effects/GrPremulInputFragmentProcessor.h new file mode 100644 index 0000000000..cc74e7e544 --- /dev/null +++ b/src/gpu/effects/GrPremulInputFragmentProcessor.h @@ -0,0 +1,41 @@ +/* + * Copyright 2017 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 GrPremulInputFragmentProcessor.fp; do not modify. + */ +#ifndef GrPremulInputFragmentProcessor_DEFINED +#define GrPremulInputFragmentProcessor_DEFINED +#include "SkTypes.h" +#if SK_SUPPORT_GPU +#include "GrFragmentProcessor.h" +#include "GrCoordTransform.h" +class GrPremulInputFragmentProcessor : public GrFragmentProcessor { +public: + GrColor4f constantOutputForConstantInput(GrColor4f input) const override { + return input.premul(); + } + static std::unique_ptr<GrFragmentProcessor> Make() { + return std::unique_ptr<GrFragmentProcessor>(new GrPremulInputFragmentProcessor()); + } + GrPremulInputFragmentProcessor(const GrPremulInputFragmentProcessor& src); + std::unique_ptr<GrFragmentProcessor> clone() const override; + const char* name() const override { return "PremulInputFragmentProcessor"; } + +private: + GrPremulInputFragmentProcessor() + : INHERITED(kGrPremulInputFragmentProcessor_ClassID, + (OptimizationFlags)kPreservesOpaqueInput_OptimizationFlag | + kConstantOutputForConstantInput_OptimizationFlag) {} + 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 +#endif diff --git a/src/gpu/effects/GrUnpremulInputFragmentProcessor.cpp b/src/gpu/effects/GrUnpremulInputFragmentProcessor.cpp new file mode 100644 index 0000000000..273643f78d --- /dev/null +++ b/src/gpu/effects/GrUnpremulInputFragmentProcessor.cpp @@ -0,0 +1,53 @@ +/* + * Copyright 2017 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 GrUnpremulInputFragmentProcessor.fp; do not modify. + */ +#include "GrUnpremulInputFragmentProcessor.h" +#if SK_SUPPORT_GPU +#include "glsl/GrGLSLFragmentProcessor.h" +#include "glsl/GrGLSLFragmentShaderBuilder.h" +#include "glsl/GrGLSLProgramBuilder.h" +#include "SkSLCPP.h" +#include "SkSLUtil.h" +class GrGLSLUnpremulInputFragmentProcessor : public GrGLSLFragmentProcessor { +public: + GrGLSLUnpremulInputFragmentProcessor() {} + void emitCode(EmitArgs& args) override { + GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; + const GrUnpremulInputFragmentProcessor& _outer = + args.fFp.cast<GrUnpremulInputFragmentProcessor>(); + (void)_outer; + fragBuilder->codeAppendf( + "%s = %s;\nhalf invAlpha = %s.w <= 0.0 ? 0.0 : 1.0 / %s.w;\n%s.xyz *= invAlpha;\n", + args.fOutputColor, args.fInputColor ? args.fInputColor : "half4(1)", + args.fInputColor ? args.fInputColor : "half4(1)", + args.fInputColor ? args.fInputColor : "half4(1)", args.fOutputColor); + } + +private: + void onSetData(const GrGLSLProgramDataManager& pdman, + const GrFragmentProcessor& _proc) override {} +}; +GrGLSLFragmentProcessor* GrUnpremulInputFragmentProcessor::onCreateGLSLInstance() const { + return new GrGLSLUnpremulInputFragmentProcessor(); +} +void GrUnpremulInputFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps, + GrProcessorKeyBuilder* b) const {} +bool GrUnpremulInputFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const { + const GrUnpremulInputFragmentProcessor& that = other.cast<GrUnpremulInputFragmentProcessor>(); + (void)that; + return true; +} +GrUnpremulInputFragmentProcessor::GrUnpremulInputFragmentProcessor( + const GrUnpremulInputFragmentProcessor& src) + : INHERITED(kGrUnpremulInputFragmentProcessor_ClassID, src.optimizationFlags()) {} +std::unique_ptr<GrFragmentProcessor> GrUnpremulInputFragmentProcessor::clone() const { + return std::unique_ptr<GrFragmentProcessor>(new GrUnpremulInputFragmentProcessor(*this)); +} +#endif diff --git a/src/gpu/effects/GrUnpremulInputFragmentProcessor.fp b/src/gpu/effects/GrUnpremulInputFragmentProcessor.fp new file mode 100644 index 0000000000..65395f34fc --- /dev/null +++ b/src/gpu/effects/GrUnpremulInputFragmentProcessor.fp @@ -0,0 +1,15 @@ +@optimizationFlags { + kPreservesOpaqueInput_OptimizationFlag | kConstantOutputForConstantInput_OptimizationFlag +} + +void main() { + sk_OutColor = sk_InColor; + half invAlpha = sk_InColor.a <= 0 ? 0 : 1 / sk_InColor.a; + sk_OutColor.rgb *= invAlpha; +} + +@class { + GrColor4f constantOutputForConstantInput(GrColor4f input) const override { + return input.unpremul(); + } +}
\ No newline at end of file diff --git a/src/gpu/effects/GrUnpremulInputFragmentProcessor.h b/src/gpu/effects/GrUnpremulInputFragmentProcessor.h new file mode 100644 index 0000000000..2e61f8b68b --- /dev/null +++ b/src/gpu/effects/GrUnpremulInputFragmentProcessor.h @@ -0,0 +1,41 @@ +/* + * Copyright 2017 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 GrUnpremulInputFragmentProcessor.fp; do not modify. + */ +#ifndef GrUnpremulInputFragmentProcessor_DEFINED +#define GrUnpremulInputFragmentProcessor_DEFINED +#include "SkTypes.h" +#if SK_SUPPORT_GPU +#include "GrFragmentProcessor.h" +#include "GrCoordTransform.h" +class GrUnpremulInputFragmentProcessor : public GrFragmentProcessor { +public: + GrColor4f constantOutputForConstantInput(GrColor4f input) const override { + return input.unpremul(); + } + static std::unique_ptr<GrFragmentProcessor> Make() { + return std::unique_ptr<GrFragmentProcessor>(new GrUnpremulInputFragmentProcessor()); + } + GrUnpremulInputFragmentProcessor(const GrUnpremulInputFragmentProcessor& src); + std::unique_ptr<GrFragmentProcessor> clone() const override; + const char* name() const override { return "UnpremulInputFragmentProcessor"; } + +private: + GrUnpremulInputFragmentProcessor() + : INHERITED(kGrUnpremulInputFragmentProcessor_ClassID, + (OptimizationFlags)kPreservesOpaqueInput_OptimizationFlag | + kConstantOutputForConstantInput_OptimizationFlag) {} + 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 +#endif |