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( |
| 30 | "%s = half4(floor(float4(float4(%s * 255.0) + 0.5)) / 255.0);\n@switch (%d) {\n " |
| 31 | "case 0:\n %s.xyz = half3(floor(float3(float3((%s.xyz * %s.w) * 255.0) + " |
| 32 | "0.5)) / 255.0);\n break;\n case 1:\n %s.xyz = float(%s.w) <= 0.0 " |
| 33 | "? half3(0.0) : half3(floor(float3(float3((%s.xyz / %s.w) * 255.0) + 0.5)) / " |
| 34 | "255.0);\n break;\n}\n", |
Michael Ludwig | 231de03 | 2018-08-30 14:33:01 -0400 | [diff] [blame] | 35 | args.fOutputColor, args.fInputColor, (int)_outer.pmConversion(), args.fOutputColor, |
| 36 | args.fOutputColor, args.fOutputColor, args.fOutputColor, args.fOutputColor, |
| 37 | args.fOutputColor, args.fOutputColor); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | private: |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 41 | void onSetData(const GrGLSLProgramDataManager& pdman, |
| 42 | const GrFragmentProcessor& _proc) override {} |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 43 | }; |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 44 | GrGLSLFragmentProcessor* GrConfigConversionEffect::onCreateGLSLInstance() const { |
| 45 | return new GrGLSLConfigConversionEffect(); |
| 46 | } |
| 47 | void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| 48 | GrProcessorKeyBuilder* b) const { |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 49 | b->add32((int32_t)fPmConversion); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 50 | } |
| 51 | bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| 52 | const GrConfigConversionEffect& that = other.cast<GrConfigConversionEffect>(); |
| 53 | (void)that; |
| 54 | if (fPmConversion != that.fPmConversion) return false; |
| 55 | return true; |
| 56 | } |
| 57 | GrConfigConversionEffect::GrConfigConversionEffect(const GrConfigConversionEffect& src) |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 58 | : INHERITED(kGrConfigConversionEffect_ClassID, src.optimizationFlags()) |
| 59 | , fPmConversion(src.fPmConversion) {} |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 60 | std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::clone() const { |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 61 | return std::unique_ptr<GrFragmentProcessor>(new GrConfigConversionEffect(*this)); |
Brian Salomon | fcc527b | 2017-07-26 12:21:21 -0400 | [diff] [blame] | 62 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 63 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect); |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 64 | #if GR_TEST_UTILS |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 65 | std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::TestCreate( |
| 66 | GrProcessorTestData* data) { |
Ethan Nicholas | aae47c8 | 2017-11-10 15:34:03 -0500 | [diff] [blame] | 67 | PMConversion pmConv = static_cast<PMConversion>( |
| 68 | data->fRandom->nextULessThan((int)PMConversion::kPMConversionCnt)); |
Brian Salomon | aff329b | 2017-08-11 09:40:37 -0400 | [diff] [blame] | 69 | return std::unique_ptr<GrFragmentProcessor>(new GrConfigConversionEffect(pmConv)); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 70 | } |
Hal Canary | 6f6961e | 2017-01-31 13:50:44 -0500 | [diff] [blame] | 71 | #endif |