blob: 0c5afde6b5649737bbbf7eaca0044284998a5334 [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
John Stiles45f5b032020-07-27 17:31:29 -040013#include "src/core/SkUtils.h"
John Stiles53ee0fc2020-07-09 15:29:33 -040014#include "src/gpu/GrTexture.h"
15#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
16#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
17#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
18#include "src/sksl/SkSLCPP.h"
19#include "src/sksl/SkSLUtil.h"
20class GrGLSLDitherEffect : public GrGLSLFragmentProcessor {
21public:
22 GrGLSLDitherEffect() {}
23 void emitCode(EmitArgs& args) override {
24 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
25 const GrDitherEffect& _outer = args.fFp.cast<GrDitherEffect>();
26 (void)_outer;
27 auto range = _outer.range;
28 (void)range;
29 rangeVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, kHalf_GrSLType,
30 "range");
John Stiles5e7c0402020-10-20 19:43:18 -040031 SkString _sample303 = this->invokeChild(0, 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}
John Stiles5e7c0402020-10-20 19:43:18 -040046return half4(clamp(color.xyz + value * %s, 0.0, color.w), color.w);
John Stiles53ee0fc2020-07-09 15:29:33 -040047)SkSL",
John Stiles5e7c0402020-10-20 19:43:18 -040048 _sample303.c_str(), args.fUniformHandler->getUniformCStr(rangeVar));
John Stiles53ee0fc2020-07-09 15:29:33 -040049 }
50
51private:
52 void onSetData(const GrGLSLProgramDataManager& pdman,
53 const GrFragmentProcessor& _proc) override {
54 const GrDitherEffect& _outer = _proc.cast<GrDitherEffect>();
55 { pdman.set1f(rangeVar, (_outer.range)); }
56 }
57 UniformHandle rangeVar;
58};
59GrGLSLFragmentProcessor* GrDitherEffect::onCreateGLSLInstance() const {
60 return new GrGLSLDitherEffect();
61}
62void GrDitherEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
63 GrProcessorKeyBuilder* b) const {}
64bool GrDitherEffect::onIsEqual(const GrFragmentProcessor& other) const {
65 const GrDitherEffect& that = other.cast<GrDitherEffect>();
66 (void)that;
67 if (range != that.range) return false;
68 return true;
69}
John Stiles5e7c0402020-10-20 19:43:18 -040070bool GrDitherEffect::usesExplicitReturn() const { return true; }
John Stiles53ee0fc2020-07-09 15:29:33 -040071GrDitherEffect::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 {
John Stilesfbd050b2020-08-03 13:21:46 -040076 return std::make_unique<GrDitherEffect>(*this);
John Stiles53ee0fc2020-07-09 15:29:33 -040077}
John Stiles8d9bf642020-08-12 15:07:45 -040078#if GR_TEST_UTILS
John Stilescab58862020-08-12 15:47:06 -040079SkString GrDitherEffect::onDumpInfo() const { return SkStringPrintf("(range=%f)", range); }
John Stiles47b4e222020-08-12 09:56:50 -040080#endif
John Stiles53ee0fc2020-07-09 15:29:33 -040081GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDitherEffect);
82#if GR_TEST_UTILS
83std::unique_ptr<GrFragmentProcessor> GrDitherEffect::TestCreate(GrProcessorTestData* d) {
Brian Osmanc262a122020-08-06 16:34:34 -040084 float range = 1.0f - d->fRandom->nextRangeF(0.0f, 1.0f);
John Stiles53ee0fc2020-07-09 15:29:33 -040085 return GrDitherEffect::Make(GrProcessorUnitTest::MakeChildFP(d), range);
86}
87#endif