1 | /* |
2 | * Copyright 2018 Google Inc. |
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 | |
8 | /************************************************************************************************** |
9 | *** This file was autogenerated from GrConfigConversionEffect.fp; do not modify. |
10 | **************************************************************************************************/ |
11 | #include "GrConfigConversionEffect.h" |
12 | |
13 | #include "src/gpu/GrTexture.h" |
14 | #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
15 | #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
16 | #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
17 | #include "src/sksl/SkSLCPP.h" |
18 | #include "src/sksl/SkSLUtil.h" |
19 | class GrGLSLConfigConversionEffect : public GrGLSLFragmentProcessor { |
20 | public: |
21 | GrGLSLConfigConversionEffect() {} |
22 | void emitCode(EmitArgs& args) override { |
23 | GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
24 | const GrConfigConversionEffect& _outer = args.fFp.cast<GrConfigConversionEffect>(); |
25 | (void)_outer; |
26 | auto pmConversion = _outer.pmConversion; |
27 | (void)pmConversion; |
28 | |
29 | fragBuilder->forceHighPrecision(); |
30 | fragBuilder->codeAppendf( |
31 | "%s = floor(%s * 255.0 + 0.5) / 255.0;\n@switch (%d) {\n case 0:\n " |
32 | "%s.xyz = floor((%s.xyz * %s.w) * 255.0 + 0.5) / 255.0;\n break;\n case " |
33 | "1:\n %s.xyz = %s.w <= 0.0 ? half3(0.0) : floor((%s.xyz / %s.w) * 255.0 + " |
34 | "0.5) / 255.0;\n break;\n}\n" , |
35 | args.fOutputColor, args.fInputColor, (int)_outer.pmConversion, args.fOutputColor, |
36 | args.fOutputColor, args.fOutputColor, args.fOutputColor, args.fOutputColor, |
37 | args.fOutputColor, args.fOutputColor); |
38 | } |
39 | |
40 | private: |
41 | void onSetData(const GrGLSLProgramDataManager& pdman, |
42 | const GrFragmentProcessor& _proc) override {} |
43 | }; |
44 | GrGLSLFragmentProcessor* GrConfigConversionEffect::onCreateGLSLInstance() const { |
45 | return new GrGLSLConfigConversionEffect(); |
46 | } |
47 | void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
48 | GrProcessorKeyBuilder* b) const { |
49 | b->add32((int32_t)pmConversion); |
50 | } |
51 | bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& other) const { |
52 | const GrConfigConversionEffect& that = other.cast<GrConfigConversionEffect>(); |
53 | (void)that; |
54 | if (pmConversion != that.pmConversion) return false; |
55 | return true; |
56 | } |
57 | GrConfigConversionEffect::GrConfigConversionEffect(const GrConfigConversionEffect& src) |
58 | : INHERITED(kGrConfigConversionEffect_ClassID, src.optimizationFlags()) |
59 | , pmConversion(src.pmConversion) {} |
60 | std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::clone() const { |
61 | return std::unique_ptr<GrFragmentProcessor>(new GrConfigConversionEffect(*this)); |
62 | } |
63 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect); |
64 | #if GR_TEST_UTILS |
65 | std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::TestCreate( |
66 | GrProcessorTestData* data) { |
67 | PMConversion pmConv = static_cast<PMConversion>( |
68 | data->fRandom->nextULessThan((int)PMConversion::kPMConversionCnt)); |
69 | return std::unique_ptr<GrFragmentProcessor>(new GrConfigConversionEffect(pmConv)); |
70 | } |
71 | #endif |
72 | |