| /* |
| * Copyright 2020 Google Inc. |
| * |
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| */ |
| |
| /************************************************************************************************** |
| *** This file was autogenerated from GrModulateAlphaEffect.fp; do not modify. |
| **************************************************************************************************/ |
| #include "GrModulateAlphaEffect.h" |
| |
| #include "src/gpu/GrTexture.h" |
| #include "src/gpu/glsl/GrGLSLFragmentProcessor.h" |
| #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h" |
| #include "src/gpu/glsl/GrGLSLProgramBuilder.h" |
| #include "src/sksl/SkSLCPP.h" |
| #include "src/sksl/SkSLUtil.h" |
| class GrGLSLModulateAlphaEffect : public GrGLSLFragmentProcessor { |
| public: |
| GrGLSLModulateAlphaEffect() {} |
| void emitCode(EmitArgs& args) override { |
| GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| const GrModulateAlphaEffect& _outer = args.fFp.cast<GrModulateAlphaEffect>(); |
| (void)_outer; |
| auto color = _outer.color; |
| (void)color; |
| colorVar = args.fUniformHandler->addUniform(&_outer, kFragment_GrShaderFlag, |
| kHalf4_GrSLType, "color"); |
| SkString _input618(args.fInputColor); |
| SkString _sample618; |
| if (_outer.inputFP_index >= 0) { |
| _sample618 = this->invokeChild(_outer.inputFP_index, _input618.c_str(), args); |
| } else { |
| _sample618.swap(_input618); |
| } |
| fragBuilder->codeAppendf( |
| R"SkSL(%s = %s * %s.w; |
| )SkSL", |
| args.fOutputColor, args.fUniformHandler->getUniformCStr(colorVar), |
| _sample618.c_str()); |
| } |
| |
| private: |
| void onSetData(const GrGLSLProgramDataManager& pdman, |
| const GrFragmentProcessor& _proc) override { |
| const GrModulateAlphaEffect& _outer = _proc.cast<GrModulateAlphaEffect>(); |
| { |
| const SkPMColor4f& colorValue = _outer.color; |
| if (colorPrev != colorValue) { |
| colorPrev = colorValue; |
| pdman.set4fv(colorVar, 1, colorValue.vec()); |
| } |
| } |
| } |
| SkPMColor4f colorPrev = {SK_FloatNaN, SK_FloatNaN, SK_FloatNaN, SK_FloatNaN}; |
| UniformHandle colorVar; |
| }; |
| GrGLSLFragmentProcessor* GrModulateAlphaEffect::onCreateGLSLInstance() const { |
| return new GrGLSLModulateAlphaEffect(); |
| } |
| void GrModulateAlphaEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps, |
| GrProcessorKeyBuilder* b) const {} |
| bool GrModulateAlphaEffect::onIsEqual(const GrFragmentProcessor& other) const { |
| const GrModulateAlphaEffect& that = other.cast<GrModulateAlphaEffect>(); |
| (void)that; |
| if (color != that.color) return false; |
| return true; |
| } |
| GrModulateAlphaEffect::GrModulateAlphaEffect(const GrModulateAlphaEffect& src) |
| : INHERITED(kGrModulateAlphaEffect_ClassID, src.optimizationFlags()), color(src.color) { |
| if (src.inputFP_index >= 0) { |
| inputFP_index = this->cloneAndRegisterChildProcessor(src.childProcessor(src.inputFP_index)); |
| } |
| } |
| std::unique_ptr<GrFragmentProcessor> GrModulateAlphaEffect::clone() const { |
| return std::unique_ptr<GrFragmentProcessor>(new GrModulateAlphaEffect(*this)); |
| } |
| GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrModulateAlphaEffect); |
| #if GR_TEST_UTILS |
| std::unique_ptr<GrFragmentProcessor> GrModulateAlphaEffect::TestCreate(GrProcessorTestData* d) { |
| SkPMColor4f color; |
| int colorPicker = d->fRandom->nextULessThan(3); |
| switch (colorPicker) { |
| case 0: { |
| uint32_t a = d->fRandom->nextULessThan(0x100); |
| uint32_t r = d->fRandom->nextULessThan(a + 1); |
| uint32_t g = d->fRandom->nextULessThan(a + 1); |
| uint32_t b = d->fRandom->nextULessThan(a + 1); |
| color = SkPMColor4f::FromBytes_RGBA(GrColorPackRGBA(r, g, b, a)); |
| break; |
| } |
| case 1: |
| color = SK_PMColor4fTRANSPARENT; |
| break; |
| case 2: |
| uint32_t c = d->fRandom->nextULessThan(0x100); |
| color = SkPMColor4f::FromBytes_RGBA(c | (c << 8) | (c << 16) | (c << 24)); |
| break; |
| } |
| return GrModulateAlphaEffect::Make(/*inputFP=*/nullptr, color); |
| } |
| #endif |