• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 = 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",
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:
onSetData(const GrGLSLProgramDataManager & pdman,const GrFragmentProcessor & _proc)41     void onSetData(const GrGLSLProgramDataManager& pdman,
42                    const GrFragmentProcessor& _proc) override {}
43 };
onCreateGLSLInstance() const44 GrGLSLFragmentProcessor* GrConfigConversionEffect::onCreateGLSLInstance() const {
45     return new GrGLSLConfigConversionEffect();
46 }
onGetGLSLProcessorKey(const GrShaderCaps & caps,GrProcessorKeyBuilder * b) const47 void GrConfigConversionEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
48                                                      GrProcessorKeyBuilder* b) const {
49     b->add32((int32_t)fPmConversion);
50 }
onIsEqual(const GrFragmentProcessor & other) const51 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 }
GrConfigConversionEffect(const GrConfigConversionEffect & src)57 GrConfigConversionEffect::GrConfigConversionEffect(const GrConfigConversionEffect& src)
58         : INHERITED(kGrConfigConversionEffect_ClassID, src.optimizationFlags())
59         , fPmConversion(src.fPmConversion) {}
clone() const60 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
TestCreate(GrProcessorTestData * data)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