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 #include "glsl/GrGLSLFragmentProcessor.h"
13 #include "glsl/GrGLSLFragmentShaderBuilder.h"
14 #include "glsl/GrGLSLProgramBuilder.h"
15 #include "GrTexture.h"
16 #include "SkSLCPP.h"
17 #include "SkSLUtil.h"
18 class GrGLSLConfigConversionEffect : public GrGLSLFragmentProcessor {
19 public:
GrGLSLConfigConversionEffect()20 GrGLSLConfigConversionEffect() {}
emitCode(EmitArgs & args)21 void emitCode(EmitArgs& args) override {
22 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
23 const GrConfigConversionEffect& _outer = args.fFp.cast<GrConfigConversionEffect>();
24 (void)_outer;
25 auto pmConversion = _outer.pmConversion();
26 (void)pmConversion;
27
28 fragBuilder->forceHighPrecision();
29 fragBuilder->codeAppendf(
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",
34 args.fOutputColor, args.fInputColor, (int)_outer.pmConversion(), args.fOutputColor,
35 args.fOutputColor, args.fOutputColor, args.fOutputColor, args.fOutputColor,
36 args.fOutputColor, args.fOutputColor);
37 }
38
39 private:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)40 void onSetData(const GrGLSLProgramDataManager& pdman,
41 const GrFragmentProcessor& _proc) override {}
42 };
onCreateGLSLInstance() const43 GrGLSLFragmentProcessor* GrConfigConversionEffect::onCreateGLSLInstance() const {
44 return new GrGLSLConfigConversionEffect();
45 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const46 void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
47 GrProcessorKeyBuilder* b) const {
48 b->add32((int32_t)fPmConversion);
49 }
onIsEqual(const GrFragmentProcessor & other) const50 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 }
GrConfigConversionEffect(const GrConfigConversionEffect & src)56 GrConfigConversionEffect::GrConfigConversionEffect(const GrConfigConversionEffect& src)
57 : INHERITED(kGrConfigConversionEffect_ClassID, src.optimizationFlags())
58 , fPmConversion(src.fPmConversion) {}
clone() const59 std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::clone() const {
60 return std::unique_ptr<GrFragmentProcessor>(new GrConfigConversionEffect(*this));
61 }
62 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrConfigConversionEffect);
63 #if GR_TEST_UTILS
TestCreate(GrProcessorTestData * data)64 std::unique_ptr<GrFragmentProcessor> GrConfigConversionEffect::TestCreate(
65 GrProcessorTestData* data) {
66 PMConversion pmConv = static_cast<PMConversion>(
67 data->fRandom->nextULessThan((int)PMConversion::kPMConversionCnt));
68 return std::unique_ptr<GrFragmentProcessor>(new GrConfigConversionEffect(pmConv));
69 }
70 #endif
71