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/GrGLSLFragmentProcessor.h" 14#include "glsl/GrGLSLFragmentShaderBuilder.h" 15#include "glsl/GrGLSLProgramBuilder.h" 16#include "GrTexture.h" 17#include "SkSLCPP.h" 18#include "SkSLUtil.h" 19class GrGLSLSimpleTextureEffect : public GrGLSLFragmentProcessor { 20public: 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 auto matrix = _outer.matrix(); 27 (void)matrix; 28 SkString sk_TransformedCoords2D_0 = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]); 29 fragBuilder->codeAppendf( 30 "%s = %s * texture(%s, %s).%s;\n", args.fOutputColor, 31 args.fInputColor ? args.fInputColor : "half4(1)", 32 fragBuilder->getProgramBuilder()->samplerVariable(args.fTexSamplers[0]).c_str(), 33 sk_TransformedCoords2D_0.c_str(), 34 fragBuilder->getProgramBuilder()->samplerSwizzle(args.fTexSamplers[0]).c_str()); 35 } 36 37private: 38 void onSetData(const GrGLSLProgramDataManager& pdman, 39 const GrFragmentProcessor& _proc) override {} 40}; 41GrGLSLFragmentProcessor* GrSimpleTextureEffect::onCreateGLSLInstance() const { 42 return new GrGLSLSimpleTextureEffect(); 43} 44void GrSimpleTextureEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, 45 GrProcessorKeyBuilder* b) const {} 46bool GrSimpleTextureEffect::onIsEqual(const GrFragmentProcessor& other) const { 47 const GrSimpleTextureEffect& that = other.cast<GrSimpleTextureEffect>(); 48 (void)that; 49 if (fImage != that.fImage) return false; 50 if (fMatrix != that.fMatrix) return false; 51 return true; 52} 53GrSimpleTextureEffect::GrSimpleTextureEffect(const GrSimpleTextureEffect& src) 54 : INHERITED(kGrSimpleTextureEffect_ClassID, src.optimizationFlags()) 55 , fImage(src.fImage) 56 , fMatrix(src.fMatrix) 57 , fImageCoordTransform(src.fImageCoordTransform) { 58 this->addTextureSampler(&fImage); 59 this->addCoordTransform(&fImageCoordTransform); 60} 61std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::clone() const { 62 return std::unique_ptr<GrFragmentProcessor>(new GrSimpleTextureEffect(*this)); 63} 64GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrSimpleTextureEffect); 65#if GR_TEST_UTILS 66std::unique_ptr<GrFragmentProcessor> GrSimpleTextureEffect::TestCreate( 67 GrProcessorTestData* testData) { 68 int texIdx = testData->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx 69 : GrProcessorUnitTest::kAlphaTextureIdx; 70 GrSamplerState::WrapMode wrapModes[2]; 71 GrTest::TestWrapModes(testData->fRandom, wrapModes); 72 if (!testData->caps()->npotTextureTileSupport()) { 73 // Performing repeat sampling on npot textures will cause asserts on HW 74 // that lacks support. 75 wrapModes[0] = GrSamplerState::WrapMode::kClamp; 76 wrapModes[1] = GrSamplerState::WrapMode::kClamp; 77 } 78 79 GrSamplerState params(wrapModes, testData->fRandom->nextBool() 80 ? GrSamplerState::Filter::kBilerp 81 : GrSamplerState::Filter::kNearest); 82 83 const SkMatrix& matrix = GrTest::TestMatrix(testData->fRandom); 84 return GrSimpleTextureEffect::Make(testData->textureProxy(texIdx), matrix, params); 85} 86#endif 87#endif 88