blob: 6bdb808c28ad26d803659539306b3ea6e5107836 [file] [log] [blame]
John Stiles53ee0fc2020-07-09 15:29:33 -04001/*
2 * Copyright 2020 Google Inc.
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
8/**************************************************************************************************
9 *** This file was autogenerated from GrDitherEffect.fp; do not modify.
10 **************************************************************************************************/
11#include "GrDitherEffect.h"
12
13#include "src/gpu/GrTexture.h"
14#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
15#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
16#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
17#include "src/sksl/SkSLCPP.h"
18#include "src/sksl/SkSLUtil.h"
19class GrGLSLDitherEffect : public GrGLSLFragmentProcessor {
20public:
21 GrGLSLDitherEffect() {}
22 void emitCode(EmitArgs& args) override {
23 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
24 const GrDitherEffect& _outer = args.fFp.cast<GrDitherEffect>();
25 (void)_outer;
26 auto range = _outer.range;
27 (void)range;
28 rangeVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, kHalf_GrSLType,
29 "range");
30 SkString _input302(args.fInputColor);
31 SkString _sample302;
32 _sample302 = this->invokeChild(_outer.inputFP_index, _input302.c_str(), args);
33 fragBuilder->codeAppendf(
34 R"SkSL(half4 color = %s;
35half value;
36@if (sk_Caps.integerSupport) {
37 uint x = uint(sk_FragCoord.x);
38 uint y = uint(sk_FragCoord.y) ^ x;
39 uint m = (((((y & 1) << 5 | (x & 1) << 4) | (y & 2) << 2) | (x & 2) << 1) | (y & 4) >> 1) | (x & 4) >> 2;
40 value = half(m) / 64.0 - 0.4921875;
41} else {
42 half4 bits = mod(half4(sk_FragCoord.yxyx), half4(2.0, 2.0, 4.0, 4.0));
43 bits.zw = step(2.0, bits.zw);
44 bits.xz = abs(bits.xz - bits.yw);
45 value = dot(bits, half4(0.5, 0.25, 0.125, 0.0625)) - 0.46875;
46}
47%s = half4(clamp(color.xyz + value * %s, 0.0, color.w), color.w);
48)SkSL",
49 _sample302.c_str(), args.fOutputColor,
50 args.fUniformHandler->getUniformCStr(rangeVar));
51 }
52
53private:
54 void onSetData(const GrGLSLProgramDataManager& pdman,
55 const GrFragmentProcessor& _proc) override {
56 const GrDitherEffect& _outer = _proc.cast<GrDitherEffect>();
57 { pdman.set1f(rangeVar, (_outer.range)); }
58 }
59 UniformHandle rangeVar;
60};
61GrGLSLFragmentProcessor* GrDitherEffect::onCreateGLSLInstance() const {
62 return new GrGLSLDitherEffect();
63}
64void GrDitherEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
65 GrProcessorKeyBuilder* b) const {}
66bool GrDitherEffect::onIsEqual(const GrFragmentProcessor& other) const {
67 const GrDitherEffect& that = other.cast<GrDitherEffect>();
68 (void)that;
69 if (range != that.range) return false;
70 return true;
71}
72GrDitherEffect::GrDitherEffect(const GrDitherEffect& src)
73 : INHERITED(kGrDitherEffect_ClassID, src.optimizationFlags()), range(src.range) {
74 { inputFP_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.inputFP_index)); }
75}
76std::unique_ptr<GrFragmentProcessor> GrDitherEffect::clone() const {
77 return std::unique_ptr<GrFragmentProcessor>(new GrDitherEffect(*this));
78}
79GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDitherEffect);
80#if GR_TEST_UTILS
81std::unique_ptr<GrFragmentProcessor> GrDitherEffect::TestCreate(GrProcessorTestData* d) {
82 float range = d->fRandom->nextRangeF(0.0, 1.0);
83 return GrDitherEffect::Make(GrProcessorUnitTest::MakeChildFP(d), range);
84}
85#endif