Home | History | Annotate | Download | only in effects
      1 /*
      2  * Copyright 2017 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 GrSimpleTextureEffect.fp; do not modify.
     10  */
     11 #include "GrSimpleTextureEffect.h"
     12 #if SK_SUPPORT_GPU
     13 #include "glsl/GrGLSLColorSpaceXformHelper.h"
     14 #include "glsl/GrGLSLFragmentProcessor.h"
     15 #include "glsl/GrGLSLFragmentShaderBuilder.h"
     16 #include "glsl/GrGLSLProgramBuilder.h"
     17 #include "SkSLCPP.h"
     18 #include "SkSLUtil.h"
     19 class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor {
     20 public:
     21     GrGLSLSimpleTextureEffect() {}
     22     void emitCode(EmitArgs& args) override {
     23         GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
     24         const GrSimpleTextureEffect& _outer = args.fFp.cast<GrSimpleTextureEffect>();
     25         (void)_outer;
     26         fColorSpaceHelper.emitCode(args.fUniformHandler, _outer.colorXform().get());
     27         SkSL::String sk_TransformedCoords2D_0 =
     28                 fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
     29         fragBuilder->codeAppendf(
     30                 "vec4 _tmpVar1;%s = %s * %stexture(%s, %s).%s%s;\n", args.fOutputColor,
     31                 args.fInputColor ? args.fInputColor : "vec4(1)",
     32                 fColorSpaceHelper.isValid() ? "(_tmpVar1 = " : "",
     33                 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(),
     34                 sk_TransformedCoords2D_0.c_str(),
     35                 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str(),
     36                 fColorSpaceHelper.isValid()
     37                         ? SkStringPrintf(", vec4(clamp((%s * vec4(_tmpVar1.rgb, 1.0)).rgb, 0.0, "
     38                                          "_tmpVar1.a), _tmpVar1.a))",
     39                                          args.fUniformHandler->getUniformCStr(
     40                                                  fColorSpaceHelper.gamutXformUniform()))
     41                                   .c_str()
     42                         : "");
     43     }
     44 
     45 private:
     46     void onSetData(const GrGLSLProgramDataManager& pdman,
     47                    const GrFragmentProcessor& _proc) override {
     48         const GrSimpleTextureEffect& _outer = _proc.cast<GrSimpleTextureEffect>();
     49         {
     50             if (fColorSpaceHelper.isValid()) {
     51                 fColorSpaceHelper.setData(pdman, _outer.colorXform().get());
     52             }
     53         }
     54     }
     55     UniformHandle fImageVar;
     56     GrGLSLColorSpaceXformHelper fColorSpaceHelper;
     57 };
     58 GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const {
     59     return new GrGLSLSimpleTextureEffect();
     60 }
     61 void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
     62                                                   GrProcessorKeyBuilder* b) const {
     63     b->add32(GrColorSpaceXform::XformKey(fColorXform.get()));
     64 }
     65 bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const {
     66     const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>();
     67     (void)that;
     68     if (fImage != that.fImage) return false;
     69     if (fColorXform != that.fColorXform) return false;
     70     if (fMatrix != that.fMatrix) return false;
     71     return true;
     72 }
     73 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect);
     74 #if GR_TEST_UTILS
     75 sk_sp<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate(GrProcessorTestData* testData) {
     76     int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx
     77                                                : GrProcessorUnitTest::kAlphaTextureIdx;
     78     static const SkShader::TileMode kTileModes[] = {
     79             SkShader::kClamp_TileMode, SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode,
     80     };
     81     SkShader::TileMode tileModes[] = {
     82             kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
     83             kTileModes[testData->fRandom->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
     84     };
     85     GrSamplerParams params(tileModes,
     86                            testData->fRandom->nextBool() ? GrSamplerParams::kBilerp_FilterMode
     87                                                          : GrSamplerParams::kNone_FilterMode);
     88 
     89     const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom);
     90     sk_sp<GrColorSpaceXform> colorSpaceXform = GrTest::TestColorXform(testData->fRandom);
     91     return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), std::move(colorSpaceXform),
     92                                        matrix);
     93 }
     94 #endif
     95 #endif
     96