blob: ec6b3b834071a06561b86e60aeb545cdd558a812 [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");
Brian Osman6b5dbb42020-07-15 15:31:05 -040030 SkString _sample302 = this->invokeChild(0, args);
John Stiles53ee0fc2020-07-09 15:29:33 -040031 fragBuilder->codeAppendf(
32 R"SkSL(half4 color = %s;
33half value;
34@if (sk_Caps.integerSupport) {
35 uint x = uint(sk_FragCoord.x);
36 uint y = uint(sk_FragCoord.y) ^ x;
37 uint m = (((((y & 1) << 5 | (x & 1) << 4) | (y & 2) << 2) | (x & 2) << 1) | (y & 4) >> 1) | (x & 4) >> 2;
38 value = half(m) / 64.0 - 0.4921875;
39} else {
40 half4 bits = mod(half4(sk_FragCoord.yxyx), half4(2.0, 2.0, 4.0, 4.0));
41 bits.zw = step(2.0, bits.zw);
42 bits.xz = abs(bits.xz - bits.yw);
43 value = dot(bits, half4(0.5, 0.25, 0.125, 0.0625)) - 0.46875;
44}
45%s = half4(clamp(color.xyz + value * %s, 0.0, color.w), color.w);
46)SkSL",
47 _sample302.c_str(), args.fOutputColor,
48 args.fUniformHandler->getUniformCStr(rangeVar));
49 }
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}
70GrDitherEffect::GrDitherEffect(const GrDitherEffect& src)
71 : INHERITED(kGrDitherEffect_ClassID, src.optimizationFlags()), range(src.range) {
Brian Osman12c5d292020-07-13 16:11:35 -040072 this->cloneAndRegisterAllChildProcessors(src);
John Stiles53ee0fc2020-07-09 15:29:33 -040073}
74std::unique_ptr<GrFragmentProcessor> GrDitherEffect::clone() const {
75 return std::unique_ptr<GrFragmentProcessor>(new GrDitherEffect(*this));
76}
77GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDitherEffect);
78#if GR_TEST_UTILS
79std::unique_ptr<GrFragmentProcessor> GrDitherEffect::TestCreate(GrProcessorTestData* d) {
80 float range = d->fRandom->nextRangeF(0.0, 1.0);
81 return GrDitherEffect::Make(GrProcessorUnitTest::MakeChildFP(d), range);
82}
83#endif