blob: f2fc6784a2b333306fda36d1cb22555ef2a03cbe [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>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040025 (void)_outer;
26 fragBuilder->codeAppendf(
27 "float value;\nfloat range;\n@switch (%d) {\n case 0:\n range = "
28 "0.0039215686274509803;\n break;\n case 1:\n range = "
29 "0.015873015873015872;\n break;\n default:\n range = "
Eric Karle1fc9ac2017-08-07 15:55:13 -070030 "0.066666666666666666;\n break;\n}\n@if (sk_Caps.integerSupport) {\n "
Ethan Nicholasdcba08e2017-08-02 10:52:54 -040031 "uint x = uint(sk_FragCoord.x);\n uint y = uint(sk_FragCoord.y);\n uint m = "
32 "(((((y & 1) << 5 | (x & 1) << 4) | (y & 2) << 2) | (x & 2) << 1) | (y & 4) >> 1) "
Eric Karle1fc9ac2017-08-07 15:55:13 -070033 "| (x & 4) >> 2;\n value = float(m) / 64.0 - 0.4921875;\n} else {\n float4 "
34 "modValues = mod(sk_FragCoord.xyxy, float4(2.0, 2.0, 4.0, 4.0));\n float4 "
35 "stepValues = step(modValues, float4(1.0, 1.0, 2.0, 2.0));\n value = "
36 "dot(stepValues, float4(0.5, 0.25, 0.125, 0.0625)) - 0.46875;\n}\n%s = "
37 "float4(clamp(%s.xyz + value * range, 0.0, %s.w), %s.w);\n",
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040038 _outer.rangeType(), args.fOutputColor,
Ethan Nicholas5af9ea32017-07-28 15:19:46 -040039 args.fInputColor ? args.fInputColor : "float4(1)",
40 args.fInputColor ? args.fInputColor : "float4(1)",
41 args.fInputColor ? args.fInputColor : "float4(1)");
krajcevskif461a8f2014-06-19 14:14:06 -070042 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040043
krajcevskif461a8f2014-06-19 14:14:06 -070044private:
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040045 void onSetData(const GrGLSLProgramDataManager& pdman,
46 const GrFragmentProcessor& _proc) override {}
krajcevskif461a8f2014-06-19 14:14:06 -070047};
Ethan Nicholas762466e2017-06-29 10:03:38 -040048GrGLSLFragmentProcessor* GrDitherEffect::onCreateGLSLInstance() const {
49 return new GrGLSLDitherEffect();
50}
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040051void GrDitherEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
52 GrProcessorKeyBuilder* b) const {
Brian Salomon0c15ae82017-07-19 15:39:56 +000053 b->add32(fRangeType);
Ethan Nicholas762466e2017-06-29 10:03:38 -040054}
55bool GrDitherEffect::onIsEqual(const GrFragmentProcessor& other) const {
56 const GrDitherEffect& that = other.cast<GrDitherEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040057 (void)that;
Brian Salomon0c15ae82017-07-19 15:39:56 +000058 if (fRangeType != that.fRangeType) return false;
Ethan Nicholas762466e2017-06-29 10:03:38 -040059 return true;
60}
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040061GrDitherEffect::GrDitherEffect(const GrDitherEffect& src)
62 : INHERITED(src.optimizationFlags()), fRangeType(src.fRangeType) {
63 this->initClassID<GrDitherEffect>();
64}
65sk_sp<GrFragmentProcessor> GrDitherEffect::clone() const {
66 return sk_sp<GrFragmentProcessor>(new GrDitherEffect(*this));
67}
Ethan Nicholas762466e2017-06-29 10:03:38 -040068GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDitherEffect);
Hal Canary6f6961e2017-01-31 13:50:44 -050069#if GR_TEST_UTILS
Ethan Nicholas762466e2017-06-29 10:03:38 -040070sk_sp<GrFragmentProcessor> GrDitherEffect::TestCreate(GrProcessorTestData* testData) {
Brian Salomon0c15ae82017-07-19 15:39:56 +000071 float range = testData->fRandom->nextRangeF(0.001f, 0.05f);
72 return sk_sp<GrFragmentProcessor>(new GrDitherEffect(range));
krajcevskif461a8f2014-06-19 14:14:06 -070073}
Hal Canary6f6961e2017-01-31 13:50:44 -050074#endif
Ethan Nicholasceb4d482017-07-10 15:40:20 -040075#endif