blob: 73ab1812a9c0a5783d8c6afe8a1cae117d7c612f [file] [log] [blame]
krajcevskif461a8f2014-06-19 14:14:06 -07001/*
Ethan Nicholas762466e2017-06-29 10:03:38 -04002 * Copyright 2017 Google Inc.
krajcevskif461a8f2014-06-19 14:14:06 -07003 *
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 Nicholas762466e2017-06-29 10:03:38 -04008/*
9 * This file was autogenerated from GrDitherEffect.fp; do not modify.
10 */
krajcevskif461a8f2014-06-19 14:14:06 -070011#include "GrDitherEffect.h"
Ethan Nicholasceb4d482017-07-10 15:40:20 -040012#if SK_SUPPORT_GPU
Ethan Nicholas762466e2017-06-29 10:03:38 -040013#include "glsl/GrGLSLColorSpaceXformHelper.h"
egdaniel64c47282015-11-13 06:54:19 -080014#include "glsl/GrGLSLFragmentProcessor.h"
egdaniel2d721d32015-11-11 13:06:05 -080015#include "glsl/GrGLSLFragmentShaderBuilder.h"
Ethan Nicholas762466e2017-06-29 10:03:38 -040016#include "glsl/GrGLSLProgramBuilder.h"
Ethan Nicholas762466e2017-06-29 10:03:38 -040017#include "SkSLCPP.h"
18#include "SkSLUtil.h"
19class GrGLSLDitherEffect : public GrGLSLFragmentProcessor {
krajcevskif461a8f2014-06-19 14:14:06 -070020public:
Ethan Nicholas762466e2017-06-29 10:03:38 -040021 GrGLSLDitherEffect() {}
22 void emitCode(EmitArgs& args) override {
23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24 const GrDitherEffect& _outer = args.fFp.cast<GrDitherEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040025 (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 "
34 "value = fract(sin(dot(sk_FragCoord.xy, vec2(12.989800000000001, "
35 "78.233000000000004))) * 43758.545299999998) - 0.5;\n}\n%s = vec4(clamp(%s.xyz + "
36 "value * range, 0.0, %s.w), %s.w);\n",
37 _outer.rangeType(), args.fOutputColor,
38 args.fInputColor ? args.fInputColor : "vec4(1)",
39 args.fInputColor ? args.fInputColor : "vec4(1)",
40 args.fInputColor ? args.fInputColor : "vec4(1)");
krajcevskif461a8f2014-06-19 14:14:06 -070041 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040042
krajcevskif461a8f2014-06-19 14:14:06 -070043private:
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040044 void onSetData(const GrGLSLProgramDataManager& pdman,
45 const GrFragmentProcessor& _proc) override {}
krajcevskif461a8f2014-06-19 14:14:06 -070046};
Ethan Nicholas762466e2017-06-29 10:03:38 -040047GrGLSLFragmentProcessor* GrDitherEffect::onCreateGLSLInstance() const {
48 return new GrGLSLDitherEffect();
49}
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040050void GrDitherEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
51 GrProcessorKeyBuilder* b) const {
Brian Salomon0c15ae82017-07-19 15:39:56 +000052 b->add32(fRangeType);
Ethan Nicholas762466e2017-06-29 10:03:38 -040053}
54bool GrDitherEffect::onIsEqual(const GrFragmentProcessor& other) const {
55 const GrDitherEffect& that = other.cast<GrDitherEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040056 (void)that;
Brian Salomon0c15ae82017-07-19 15:39:56 +000057 if (fRangeType != that.fRangeType) return false;
Ethan Nicholas762466e2017-06-29 10:03:38 -040058 return true;
59}
60GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDitherEffect);
Hal Canary6f6961e2017-01-31 13:50:44 -050061#if GR_TEST_UTILS
Ethan Nicholas762466e2017-06-29 10:03:38 -040062sk_sp<GrFragmentProcessor> GrDitherEffect::TestCreate(GrProcessorTestData* testData) {
Brian Salomon0c15ae82017-07-19 15:39:56 +000063 float range = testData->fRandom->nextRangeF(0.001f, 0.05f);
64 return sk_sp<GrFragmentProcessor>(new GrDitherEffect(range));
krajcevskif461a8f2014-06-19 14:14:06 -070065}
Hal Canary6f6961e2017-01-31 13:50:44 -050066#endif
Ethan Nicholasceb4d482017-07-10 15:40:20 -040067#endif