blob: 6f5266e738f4bfa4846049eb435a1220a6863320 [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(
Ethan Nicholasf7b88202017-09-18 14:10:39 -040027 "half value;\nhalf range;\n@switch (%d) {\n case 0:\n range = "
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040028 "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) "
Ethan Nicholasf7b88202017-09-18 14:10:39 -040033 "| (x & 4) >> 2;\n value = highfloat(highfloat(half(m)) / 64.0) - 0.4921875;\n} "
34 "else {\n half4 modValues = half4(mod(sk_FragCoord.xyxy, highfloat4(half4(2.0, "
35 "2.0, 4.0, 4.0))));\n half4 stepValues = half4(step(highfloat4(modValues), "
36 "highfloat4(half4(1.0, 1.0, 2.0, 2.0))));\n value = highfloat(dot(stepValues, "
37 "half4(0.5, 0.25, 0.125, 0.0625))) - 0.46875;\n}\n%s = "
38 "half4(clamp(highfloat3(%s.xyz + value * range), 0.0, highfloat(%s.w)), %s.w);\n",
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040039 _outer.rangeType(), args.fOutputColor,
Ethan Nicholasf7b88202017-09-18 14:10:39 -040040 args.fInputColor ? args.fInputColor : "half4(1)",
41 args.fInputColor ? args.fInputColor : "half4(1)",
42 args.fInputColor ? args.fInputColor : "half4(1)");
krajcevskif461a8f2014-06-19 14:14:06 -070043 }
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040044
krajcevskif461a8f2014-06-19 14:14:06 -070045private:
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040046 void onSetData(const GrGLSLProgramDataManager& pdman,
47 const GrFragmentProcessor& _proc) override {}
krajcevskif461a8f2014-06-19 14:14:06 -070048};
Ethan Nicholas762466e2017-06-29 10:03:38 -040049GrGLSLFragmentProcessor* GrDitherEffect::onCreateGLSLInstance() const {
50 return new GrGLSLDitherEffect();
51}
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040052void GrDitherEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
53 GrProcessorKeyBuilder* b) const {
Brian Salomon0c15ae82017-07-19 15:39:56 +000054 b->add32(fRangeType);
Ethan Nicholas762466e2017-06-29 10:03:38 -040055}
56bool GrDitherEffect::onIsEqual(const GrFragmentProcessor& other) const {
57 const GrDitherEffect& that = other.cast<GrDitherEffect>();
Ethan Nicholasb7e8c3b2017-07-19 13:54:20 -040058 (void)that;
Brian Salomon0c15ae82017-07-19 15:39:56 +000059 if (fRangeType != that.fRangeType) return false;
Ethan Nicholas762466e2017-06-29 10:03:38 -040060 return true;
61}
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040062GrDitherEffect::GrDitherEffect(const GrDitherEffect& src)
63 : INHERITED(src.optimizationFlags()), fRangeType(src.fRangeType) {
64 this->initClassID<GrDitherEffect>();
65}
Brian Salomonaff329b2017-08-11 09:40:37 -040066std::unique_ptr<GrFragmentProcessor> GrDitherEffect::clone() const {
67 return std::unique_ptr<GrFragmentProcessor>(new GrDitherEffect(*this));
Ethan Nicholasf57c0d62017-07-31 11:18:22 -040068}
Ethan Nicholas762466e2017-06-29 10:03:38 -040069GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDitherEffect);
Hal Canary6f6961e2017-01-31 13:50:44 -050070#if GR_TEST_UTILS
Brian Salomonaff329b2017-08-11 09:40:37 -040071std::unique_ptr<GrFragmentProcessor> GrDitherEffect::TestCreate(GrProcessorTestData* testData) {
Brian Salomon0c15ae82017-07-19 15:39:56 +000072 float range = testData->fRandom->nextRangeF(0.001f, 0.05f);
Brian Salomonaff329b2017-08-11 09:40:37 -040073 return std::unique_ptr<GrFragmentProcessor>(new GrDitherEffect(range));
krajcevskif461a8f2014-06-19 14:14:06 -070074}
Hal Canary6f6961e2017-01-31 13:50:44 -050075#endif
Ethan Nicholasceb4d482017-07-10 15:40:20 -040076#endif