krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 1 | /* |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 2 | * Copyright 2017 Google Inc. |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 8 | /* |
| 9 | * This file was autogenerated from GrDitherEffect.fp; do not modify. |
| 10 | */ |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 11 | #include "GrDitherEffect.h" |
Ethan Nicholas | ceb4d48 | 2017-07-10 15:40:20 -0400 | [diff] [blame] | 12 | #if SK_SUPPORT_GPU |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 13 | #include "glsl/GrGLSLColorSpaceXformHelper.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 14 | #include "glsl/GrGLSLFragmentProcessor.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 15 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 16 | #include "glsl/GrGLSLProgramBuilder.h" |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 17 | #include "SkSLCPP.h" |
| 18 | #include "SkSLUtil.h" |
| 19 | class GrGLSLDitherEffect : public GrGLSLFragmentProcessor { |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 20 | public: |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 21 | GrGLSLDitherEffect() {} |
| 22 | void emitCode(EmitArgs& args) override { |
| 23 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 24 | const GrDitherEffect& _outer = args.fFp.cast<GrDitherEffect>(); |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 25 | (void)_outer; |
| 26 | fragBuilder->codeAppendf( |
| 27 | "float value;\nfloat range;\n@switch (%d) {\n case 0:\n range = " |
| 28 | "0.0039215686274509803;\n break;\n case 1:\n range = " |
| 29 | "0.015873015873015872;\n break;\n default:\n range = " |
| 30 | "0.0083333333333333332;\n break;\n}\n@if (sk_Caps.integerSupport) {\n " |
| 31 | "int x = int(sk_FragCoord.x);\n int y = int(sk_FragCoord.y);\n uint m = " |
| 32 | "uint((((((y & 1) << 5 | (x & 1) << 4) | (y & 2) << 2) | (x & 2) << 1) | (y & 4) " |
| 33 | ">> 1) | (x & 4) >> 2);\n value = float(m) / 64.0 - 0.4921875;\n} else {\n " |
Ethan Nicholas | 5af9ea3 | 2017-07-28 15:19:46 -0400 | [diff] [blame] | 34 | "value = fract(sin(dot(sk_FragCoord.xy, float2(12.989800000000001, " |
| 35 | "78.233000000000004))) * 43758.545299999998) - 0.5;\n}\n%s = float4(clamp(%s.xyz + " |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 36 | "value * range, 0.0, %s.w), %s.w);\n", |
| 37 | _outer.rangeType(), args.fOutputColor, |
Ethan Nicholas | 5af9ea3 | 2017-07-28 15:19:46 -0400 | [diff] [blame] | 38 | args.fInputColor ? args.fInputColor : "float4(1)", |
| 39 | args.fInputColor ? args.fInputColor : "float4(1)", |
| 40 | args.fInputColor ? args.fInputColor : "float4(1)"); |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 41 | } |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 42 | |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 43 | private: |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 44 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 45 | const GrFragmentProcessor& _proc) override {} |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 46 | }; |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 47 | GrGLSLFragmentProcessor* GrDitherEffect::onCreateGLSLInstance() const { |
| 48 | return new GrGLSLDitherEffect(); |
| 49 | } |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 50 | void GrDitherEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 51 | GrProcessorKeyBuilder* b) const { |
Brian Salomon | 0c15ae8 | 2017-07-19 15:39:56 +0000 | [diff] [blame] | 52 | b->add32(fRangeType); |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 53 | } |
| 54 | bool GrDitherEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 55 | const GrDitherEffect& that = other.cast<GrDitherEffect>(); |
Ethan Nicholas | b7e8c3b | 2017-07-19 13:54:20 -0400 | [diff] [blame] | 56 | (void)that; |
Brian Salomon | 0c15ae8 | 2017-07-19 15:39:56 +0000 | [diff] [blame] | 57 | if (fRangeType != that.fRangeType) return false; |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 58 | return true; |
| 59 | } |
| 60 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDitherEffect); |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 61 | #if GR_TEST_UTILS |
Ethan Nicholas | 762466e | 2017-06-29 10:03:38 -0400 | [diff] [blame] | 62 | sk_sp<GrFragmentProcessor> GrDitherEffect::TestCreate(GrProcessorTestData* testData) { |
Brian Salomon | 0c15ae8 | 2017-07-19 15:39:56 +0000 | [diff] [blame] | 63 | float range = testData->fRandom->nextRangeF(0.001f, 0.05f); |
| 64 | return sk_sp<GrFragmentProcessor>(new GrDitherEffect(range)); |
krajcevski | f461a8f | 2014-06-19 14:14:06 -0700 | [diff] [blame] | 65 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 66 | #endif |
Ethan Nicholas | ceb4d48 | 2017-07-10 15:40:20 -0400 | [diff] [blame] | 67 | #endif |