blob: 753bbce185a3f982a8cd43f4f8ff4fe4627a6b80 [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>();
25 (void) _outer;
Brian Salomon0c15ae82017-07-19 15:39:56 +000026 fragBuilder->codeAppendf("float value;\nfloat range;\n@switch (%d) {\n case 0:\n range = 0.0039215686274509803;\n break;\n case 1:\n range = 0.015873015873015872;\n break;\n default:\n range = 0.0083333333333333332;\n break;\n}\n@if (sk_Caps.integerSupport) {\n int x = int(sk_FragCoord.x);\n int y = int(sk_FragCoord.y);\n uint m = uint((((((y & 1) << 5 | (x & 1) << 4) | (y & 2) << 2) | (x & 2) << 1) | (y & 4) >> 1) | (x & 4) >> 2);\n value = float(m) / 64.0 - 0.4921875;\n} else {\n value = fract(sin(dot(sk_FragCoord.xy, vec2(12.989800000000001, 78.233000000000004))) * 43758.545299999998) - 0.5;\n}\n%s = vec4(clamp(%s.xyz + value * range, 0.0, %s.w), %s.w);\n", _outer.rangeType(), args.fOutputColor, args.fInputColor ? args.fInputColor : "vec4(1)", args.fInputColor ? args.fInputColor : "vec4(1)", args.fInputColor ? args.fInputColor : "vec4(1)");
krajcevskif461a8f2014-06-19 14:14:06 -070027 }
krajcevskif461a8f2014-06-19 14:14:06 -070028private:
Ethan Nicholas762466e2017-06-29 10:03:38 -040029 void onSetData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& _proc) override {
30 }
krajcevskif461a8f2014-06-19 14:14:06 -070031};
Ethan Nicholas762466e2017-06-29 10:03:38 -040032GrGLSLFragmentProcessor* GrDitherEffect::onCreateGLSLInstance() const {
33 return new GrGLSLDitherEffect();
34}
35void GrDitherEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
Brian Salomon0c15ae82017-07-19 15:39:56 +000036 b->add32(fRangeType);
Ethan Nicholas762466e2017-06-29 10:03:38 -040037}
38bool GrDitherEffect::onIsEqual(const GrFragmentProcessor& other) const {
39 const GrDitherEffect& that = other.cast<GrDitherEffect>();
40 (void) that;
Brian Salomon0c15ae82017-07-19 15:39:56 +000041 if (fRangeType != that.fRangeType) return false;
Ethan Nicholas762466e2017-06-29 10:03:38 -040042 return true;
43}
44GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDitherEffect);
Hal Canary6f6961e2017-01-31 13:50:44 -050045#if GR_TEST_UTILS
Ethan Nicholas762466e2017-06-29 10:03:38 -040046sk_sp<GrFragmentProcessor> GrDitherEffect::TestCreate(GrProcessorTestData* testData) {
47
Brian Salomon0c15ae82017-07-19 15:39:56 +000048 float range = testData->fRandom->nextRangeF(0.001f, 0.05f);
49 return sk_sp<GrFragmentProcessor>(new GrDitherEffect(range));
krajcevskif461a8f2014-06-19 14:14:06 -070050}
Hal Canary6f6961e2017-01-31 13:50:44 -050051#endif
Ethan Nicholasceb4d482017-07-10 15:40:20 -040052#endif