bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1 | /* |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 2 | * Copyright 2018 Google Inc. |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 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 | |
Ethan Nicholas | 130fb3f | 2018-02-01 12:14:34 -0500 | [diff] [blame] | 8 | /************************************************************************************************** |
| 9 | *** This file was autogenerated from GrConfigConversionEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 11 | #include "GrConfigConversionEffect.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 12 | #include "glsl/GrGLSLFragmentProcessor.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 13 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 14 | #include "glsl/GrGLSLProgramBuilder.h" |
Ethan Nicholas | 2d5f9b3 | 2017-12-13 14:36:14 -0500 | [diff] [blame] | 15 | #include "GrTexture.h" |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 16 | #include "SkSLCPP.h" |
| 17 | #include "SkSLUtil.h" |
| 18 | class GrGLSLConfigConversionEffect : public GrGLSLFragmentProcessor { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 19 | public: |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 20 | GrGLSLConfigConversionEffect() {} |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 21 | void emitCode(EmitArgs& args) override { |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 22 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 23 | const GrConfigConversionEffect& _outer = args.fFp.cast<GrConfigConversionEffect>(); |
| 24 | (void)_outer; |
Ethan Nicholas | 8239946 | 2017-10-16 12:35:44 -0400 | [diff] [blame] | 25 | auto pmConversion = _outer.pmConversion(); |
| 26 | (void)pmConversion; |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 27 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 28 | fragBuilder->forceHighPrecision(); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 29 | fragBuilder->codeAppendf( |
Ethan Nicholas | e1f5502 | 2019-02-05 17:17:40 -0500 | [diff] [blame^] | 30 | "%s = floor(%s * 255.0 + 0.5) / 255.0;\n@switch (%d) {\n case 0:\n " |
| 31 | "%s.xyz = floor((%s.xyz * %s.w) * 255.0 + 0.5) / 255.0;\n break;\n case " |
| 32 | "1:\n %s.xyz = %s.w <= 0.0 ? half3(0.0) : floor((%s.xyz / %s.w) * 255.0 + " |
| 33 | "0.5) / 255.0;\n break;\n}\n", |
Michael Ludwig | 231de03 | 2018-08-30 14:33:01 -0400 | [diff] [blame] | 34 | args.fOutputColor, args.fInputColor, (int)_outer.pmConversion(), args.fOutputColor, |
| 35 | args.fOutputColor, args.fOutputColor, args.fOutputColor, args.fOutputColor, |
| 36 | args.fOutputColor, args.fOutputColor); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | private: |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 40 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 41 | const GrFragmentProcessor& _proc) override {} |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 42 | }; |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 43 | GrGLSLFragmentProcessor* GrConfigConversionEffect::onCreateGLSLInstance() const { |
| 44 | return new GrGLSLConfigConversionEffect(); |
| 45 | } |
| 46 | void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 47 | GrProcessorKeyBuilder* b) const { |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 48 | b->add32((int32_t)fPmConversion); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 49 | } |
| 50 | bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 51 | const GrConfigConversionEffect& that = other.cast<GrConfigConversionEffect>(); |
| 52 | (void)that; |
| 53 | if (fPmConversion != that.fPmConversion) return false; |
| 54 | return true; |
| 55 | } |
| 56 | GrConfigConversionEffect::GrConfigConversionEffect(const GrConfigConversionEffect& src) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 57 | : INHERITED(kGrConfigConversionEffect_ClassID, src.optimizationFlags()) |
| 58 | , fPmConversion(src.fPmConversion) {} |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 59 | std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::clone() const { |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 60 | return std::unique_ptr<GrFragmentProcessor>(new GrConfigConversionEffect(*this)); |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 61 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 62 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect); |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 63 | #if GR_TEST_UTILS |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 64 | std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::TestCreate( |
| 65 | GrProcessorTestData* data) { |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 66 | PMConversion pmConv = static_cast<PMConversion>( |
| 67 | data->fRandom->nextULessThan((int)PMConversion::kPMConversionCnt)); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 68 | return std::unique_ptr<GrFragmentProcessor>(new GrConfigConversionEffect(pmConv)); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 69 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 70 | #endif |