bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1 | /* |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 2 | * Copyright 2017 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 | 839872c | 2017-10-05 12:36:59 -0400 | [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" |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 12 | #if SK_SUPPORT_GPU |
| 13 | #include "glsl/GrGLSLColorSpaceXformHelper.h" |
egdaniel | 64c4728 | 2015-11-13 06:54:19 -0800 | [diff] [blame] | 14 | #include "glsl/GrGLSLFragmentProcessor.h" |
egdaniel | 2d721d3 | 2015-11-11 13:06:05 -0800 | [diff] [blame] | 15 | #include "glsl/GrGLSLFragmentShaderBuilder.h" |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 16 | #include "glsl/GrGLSLProgramBuilder.h" |
| 17 | #include "SkSLCPP.h" |
| 18 | #include "SkSLUtil.h" |
| 19 | class GrGLSLConfigConversionEffect : public GrGLSLFragmentProcessor { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 20 | public: |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 21 | GrGLSLConfigConversionEffect() {} |
robertphillips | 9cdb992 | 2016-02-03 12:25:40 -0800 | [diff] [blame] | 22 | void emitCode(EmitArgs& args) override { |
cdalton | 8528541 | 2016-02-18 12:37:07 -0800 | [diff] [blame] | 23 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 24 | const GrConfigConversionEffect& _outer = args.fFp.cast<GrConfigConversionEffect>(); |
| 25 | (void)_outer; |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 26 | |
Ethan Nicholas | f7b8820 | 2017-09-18 14:10:39 -0400 | [diff] [blame] | 27 | fragBuilder->forceHighPrecision(); |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 28 | fragBuilder->codeAppendf( |
| 29 | "%s = half4(floor(float4(float4(%s * 255.0) + 0.5)) / 255.0);\n@switch (%d) {\n " |
| 30 | "case 0:\n %s.xyz = half3(floor(float3(float3((%s.xyz * %s.w) * 255.0) + " |
| 31 | "0.5)) / 255.0);\n break;\n case 1:\n %s.xyz = float(%s.w) <= 0.0 " |
| 32 | "? half3(0.0) : half3(floor(float3(float3((%s.xyz / %s.w) * 255.0) + 0.5)) / " |
| 33 | "255.0);\n break;\n}\n", |
| 34 | args.fOutputColor, args.fInputColor ? args.fInputColor : "half4(1)", |
| 35 | _outer.pmConversion(), args.fOutputColor, args.fOutputColor, args.fOutputColor, |
| 36 | args.fOutputColor, args.fOutputColor, 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 { |
| 48 | b->add32(fPmConversion); |
| 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) |
| 57 | : INHERITED(src.optimizationFlags()), fPmConversion(src.fPmConversion) { |
Brian Osman | 31f96a6 | 2017-03-24 18:27:56 +0000 | [diff] [blame] | 58 | this->initClassID<GrConfigConversionEffect>(); |
Robert Phillips | 757914d | 2017-01-25 15:48:30 -0500 | [diff] [blame] | 59 | } |
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) { |
| 67 | PMConversion pmConv = static_cast<PMConversion>(data->fRandom->nextULessThan(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 |
Ethan Nicholas | 839872c | 2017-10-05 12:36:59 -0400 | [diff] [blame] | 71 | #endif |