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 #if SK_SUPPORT_GPU
13 #include "glsl/GrGLSLFragmentProcessor.h"
14 #include "glsl/GrGLSLFragmentShaderBuilder.h"
15 #include "glsl/GrGLSLProgramBuilder.h"
16 #include "GrTexture.h"
17 #include "SkSLCPP.h"
18 #include "SkSLUtil.h"
19 class GrGLSLConfigConversionEffect : public GrGLSLFragmentProcessor {
20 public:
GrGLSLConfigConversionEffect()21 GrGLSLConfigConversionEffect() {}
emitCode(EmitArgs & args)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 = half4(floor(float4(float4(%s * 255.0) + 0.5)) / 255.0);\n@switch (%d) {\n "
32 "case 0:\n %s.xyz = half3(floor(float3(float3((%s.xyz * %s.w) * 255.0) + "
33 "0.5)) / 255.0);\n break;\n case 1:\n %s.xyz = float(%s.w) <= 0.0 "
34 "? half3(0.0) : half3(floor(float3(float3((%s.xyz / %s.w) * 255.0) + 0.5)) / "
35 "255.0);\n break;\n}\n",
36 args.fOutputColor, args.fInputColor ? args.fInputColor : "half4(1)",
37 (int)_outer.pmConversion(), args.fOutputColor, args.fOutputColor, args.fOutputColor,
38 args.fOutputColor, args.fOutputColor, args.fOutputColor, args.fOutputColor);
39 }
40
41 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)42 void onSetData(const GrGLSLProgramDataManager& pdman,
43 const GrFragmentProcessor& _proc) override {}
44 };
onCreateGLSLInstance() const45 GrGLSLFragmentProcessor* GrConfigConversionEffect::onCreateGLSLInstance() const {
46 return new GrGLSLConfigConversionEffect();
47 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const48 void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
49 GrProcessorKeyBuilder* b) const {
50 b->add32((int32_t)fPmConversion);
51 }
onIsEqual(const GrFragmentProcessor & other) const52 bool GrConfigConversionEffect::onIsEqual(const GrFragmentProcessor& other) const {
53 const GrConfigConversionEffect& that = other.cast<GrConfigConversionEffect>();
54 (void)that;
55 if (fPmConversion != that.fPmConversion) return false;
56 return true;
57 }
GrConfigConversionEffect(const GrConfigConversionEffect & src)58 GrConfigConversionEffect::GrConfigConversionEffect(const GrConfigConversionEffect& src)
59 : INHERITED(kGrConfigConversionEffect_ClassID, src.optimizationFlags())
60 , fPmConversion(src.fPmConversion) {}
clone() const61 std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::clone() const {
62 return std::unique_ptr<GrFragmentProcessor>(new GrConfigConversionEffect(*this));
63 }
64 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect);
65 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * data)66 std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::TestCreate(
67 GrProcessorTestData* data) {
68 PMConversion pmConv = static_cast<PMConversion>(
69 data->fRandom->nextULessThan((int)PMConversion::kPMConversionCnt));
70 return std::unique_ptr<GrFragmentProcessor>(new GrConfigConversionEffect(pmConv));
71 }
72 #endif
73 #endif
74