diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-06-29 10:03:38 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-29 14:57:47 +0000 |
commit | 762466e9fe0478bcf11fba532998e81e33b3069e (patch) | |
tree | 8934a152b11007d7d530db05f7ba731bb05aa5c0 /src/gpu | |
parent | e78c8ed9cba31ebb970d3002270ddb03f4d6baae (diff) |
Re-re-land sksl fragment processor support
This reverts commit 5ce397205528f82084fc650c2ce27d246c01da33.
Bug: skia:
Change-Id: I88260c90004610a1cf8ad1a87c2b4b222525bbb6
Reviewed-on: https://skia-review.googlesource.com/21108
Reviewed-by: Ben Wagner <benjaminwagner@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/effects/GrDitherEffect.cpp | 103 | ||||
-rw-r--r-- | src/gpu/effects/GrDitherEffect.fp | 17 | ||||
-rw-r--r-- | src/gpu/effects/GrDitherEffect.h | 37 |
3 files changed, 70 insertions, 87 deletions
diff --git a/src/gpu/effects/GrDitherEffect.cpp b/src/gpu/effects/GrDitherEffect.cpp index 0686750196..de04c8cf20 100644 --- a/src/gpu/effects/GrDitherEffect.cpp +++ b/src/gpu/effects/GrDitherEffect.cpp @@ -1,91 +1,48 @@ /* - * Copyright 2014 Google Inc. + * 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 GrDitherEffect.fp; do not modify. + */ #include "GrDitherEffect.h" -#include "GrFragmentProcessor.h" -#include "SkRect.h" +#include "glsl/GrGLSLColorSpaceXformHelper.h" #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLFragmentShaderBuilder.h" -#include "../private/GrGLSL.h" - -////////////////////////////////////////////////////////////////////////////// - -class DitherEffect : public GrFragmentProcessor { +#include "glsl/GrGLSLProgramBuilder.h" +#include "GrResourceProvider.h" +#include "SkSLCPP.h" +#include "SkSLUtil.h" +class GrGLSLDitherEffect : public GrGLSLFragmentProcessor { public: - static sk_sp<GrFragmentProcessor> Make() { - return sk_sp<GrFragmentProcessor>(new DitherEffect); + GrGLSLDitherEffect() {} + void emitCode(EmitArgs& args) override { + GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; + const GrDitherEffect& _outer = args.fFp.cast<GrDitherEffect>(); + (void) _outer; + fragBuilder->codeAppendf("float r = fract(sin(dot(sk_FragCoord.xy, vec2(12.989800000000001, 78.233000000000004))) * 43758.545299999998);\n%s = clamp(0.0039215686274509803 * vec4(r) + %s, 0.0, 1.0);\n", args.fOutputColor, args.fInputColor ? args.fInputColor : "vec4(1)"); } - - ~DitherEffect() override {} - - const char* name() const override { return "Dither"; } - private: - DitherEffect() : INHERITED(kNone_OptimizationFlags) { this->initClassID<DitherEffect>(); } - - GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; - - void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; - - // All dither effects are equal - bool onIsEqual(const GrFragmentProcessor&) const override { return true; } - - GR_DECLARE_FRAGMENT_PROCESSOR_TEST; - - typedef GrFragmentProcessor INHERITED; + void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override { + } }; - -////////////////////////////////////////////////////////////////////////////// - -GR_DEFINE_FRAGMENT_PROCESSOR_TEST(DitherEffect); - -#if GR_TEST_UTILS -sk_sp<GrFragmentProcessor> DitherEffect::TestCreate(GrProcessorTestData*) { - return DitherEffect::Make(); +GrGLSLFragmentProcessor* GrDitherEffect::onCreateGLSLInstance() const { + return new GrGLSLDitherEffect(); } -#endif - -////////////////////////////////////////////////////////////////////////////// - -class GLDitherEffect : public GrGLSLFragmentProcessor { -public: - void emitCode(EmitArgs& args) override; - -private: - typedef GrGLSLFragmentProcessor INHERITED; -}; - -void GLDitherEffect::emitCode(EmitArgs& args) { - GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; - // Generate a random number based on the fragment position. For this - // random number generator, we use the "GLSL rand" function - // that seems to be floating around on the internet. It works under - // the assumption that sin(<big number>) oscillates with high frequency - // and sampling it will generate "randomness". Since we're using this - // for rendering and not cryptography it should be OK. - - // For each channel c, add the random offset to the pixel to either bump - // it up or let it remain constant during quantization. - fragBuilder->codeAppendf("\t\tfloat r = " - "fract(sin(dot(sk_FragCoord.xy, vec2(12.9898,78.233))) * " - "43758.5453);\n"); - fragBuilder->codeAppendf("\t\t%s = clamp((1.0/255.0) * vec4(r, r, r, r) + %s, 0, 1);\n", - args.fOutputColor, args.fInputColor); +void GrDitherEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const { } - -////////////////////////////////////////////////////////////////////////////// - -void DitherEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, - GrProcessorKeyBuilder* b) const { - GLDitherEffect::GenKey(*this, caps, b); +bool GrDitherEffect::onIsEqual(const GrFragmentProcessor& other) const { + const GrDitherEffect& that = other.cast<GrDitherEffect>(); + (void) that; + return true; } +GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDitherEffect); +#if GR_TEST_UTILS +sk_sp<GrFragmentProcessor> GrDitherEffect::TestCreate(GrProcessorTestData* testData) { -GrGLSLFragmentProcessor* DitherEffect::onCreateGLSLInstance() const { - return new GLDitherEffect; + return GrDitherEffect::Make(); } - -sk_sp<GrFragmentProcessor> GrDitherEffect::Make() { return DitherEffect::Make(); } +#endif diff --git a/src/gpu/effects/GrDitherEffect.fp b/src/gpu/effects/GrDitherEffect.fp new file mode 100644 index 0000000000..77ff009113 --- /dev/null +++ b/src/gpu/effects/GrDitherEffect.fp @@ -0,0 +1,17 @@ +void main() { + // Generate a random number based on the fragment position. For this + // random number generator, we use the "GLSL rand" function + // that seems to be floating around on the internet. It works under + // the assumption that sin(<big number>) oscillates with high frequency + // and sampling it will generate "randomness". Since we're using this + // for rendering and not cryptography it should be OK. + + // For each channel c, add the random offset to the pixel to either bump + // it up or let it remain constant during quantization. + float r = fract(sin(dot(sk_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453); + sk_OutColor = clamp(1.0 / 255.0 * vec4(r) + sk_InColor, 0, 1); +} + +@test(testData) { + return GrDitherEffect::Make(); +}
\ No newline at end of file diff --git a/src/gpu/effects/GrDitherEffect.h b/src/gpu/effects/GrDitherEffect.h index b92723d339..32cb87259d 100644 --- a/src/gpu/effects/GrDitherEffect.h +++ b/src/gpu/effects/GrDitherEffect.h @@ -1,24 +1,33 @@ /* - * Copyright 2014 Google Inc. + * 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 GrDitherEffect.fp; do not modify. + */ #ifndef GrDitherEffect_DEFINED #define GrDitherEffect_DEFINED - -#include "GrTypes.h" -#include "GrTypesPriv.h" -#include "SkRefCnt.h" - -class GrFragmentProcessor; - -namespace GrDitherEffect { - /** - * Creates an effect that dithers the resulting color to an RGBA8 framebuffer - */ - sk_sp<GrFragmentProcessor> Make(); +#include "GrFragmentProcessor.h" +#include "GrCoordTransform.h" +#include "effects/GrProxyMove.h" +class GrDitherEffect : public GrFragmentProcessor { +public: + static sk_sp<GrFragmentProcessor> Make() { + return sk_sp<GrFragmentProcessor>(new GrDitherEffect()); + } + const char* name() const override { return "DitherEffect"; } +private: + GrDitherEffect() + : INHERITED(kNone_OptimizationFlags) { + this->initClassID<GrDitherEffect>(); + } + 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 |