blob: 643ef1757fccb3fc4b62d9ac1abe58d360e6abf9 [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);
Brian Osman12c5d292020-07-13 16:11:35 -040031 SkString _sample302 = this->invokeChild(0, _input302.c_str(), args);
John Stiles53ee0fc2020-07-09 15:29:33 -040032 fragBuilder->codeAppendf(
33 R"SkSL(half4 color = %s;
34half value;
35@if (sk_Caps.integerSupport) {
36 uint x = uint(sk_FragCoord.x);
37 uint y = uint(sk_FragCoord.y) ^ x;
38 uint m = (((((y & 1) << 5 | (x & 1) << 4) | (y & 2) << 2) | (x & 2) << 1) | (y & 4) >> 1) | (x & 4) >> 2;
39 value = half(m) / 64.0 - 0.4921875;
40} else {
41 half4 bits = mod(half4(sk_FragCoord.yxyx), half4(2.0, 2.0, 4.0, 4.0));
42 bits.zw = step(2.0, bits.zw);
43 bits.xz = abs(bits.xz - bits.yw);
44 value = dot(bits, half4(0.5, 0.25, 0.125, 0.0625)) - 0.46875;
45}
46%s = half4(clamp(color.xyz + value * %s, 0.0, color.w), color.w);
47)SkSL",
48 _sample302.c_str(), args.fOutputColor,
49 args.fUniformHandler->getUniformCStr(rangeVar));
50 }
51
52private:
53 void onSetData(const GrGLSLProgramDataManager& pdman,
54 const GrFragmentProcessor& _proc) override {
55 const GrDitherEffect& _outer = _proc.cast<GrDitherEffect>();
56 { pdman.set1f(rangeVar, (_outer.range)); }
57 }
58 UniformHandle rangeVar;
59};
60GrGLSLFragmentProcessor* GrDitherEffect::onCreateGLSLInstance() const {
61 return new GrGLSLDitherEffect();
62}
63void GrDitherEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
64 GrProcessorKeyBuilder* b) const {}
65bool GrDitherEffect::onIsEqual(const GrFragmentProcessor& other) const {
66 const GrDitherEffect& that = other.cast<GrDitherEffect>();
67 (void)that;
68 if (range != that.range) return false;
69 return true;
70}
71GrDitherEffect::GrDitherEffect(const GrDitherEffect& src)
72 : INHERITED(kGrDitherEffect_ClassID, src.optimizationFlags()), range(src.range) {
Brian Osman12c5d292020-07-13 16:11:35 -040073 this->cloneAndRegisterAllChildProcessors(src);
John Stiles53ee0fc2020-07-09 15:29:33 -040074}
75std::unique_ptr<GrFragmentProcessor> GrDitherEffect::clone() const {
76 return std::unique_ptr<GrFragmentProcessor>(new GrDitherEffect(*this));
77}
78GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDitherEffect);
79#if GR_TEST_UTILS
80std::unique_ptr<GrFragmentProcessor> GrDitherEffect::TestCreate(GrProcessorTestData* d) {
81 float range = d->fRandom->nextRangeF(0.0, 1.0);
82 return GrDitherEffect::Make(GrProcessorUnitTest::MakeChildFP(d), range);
83}
84#endif