GrTiledGradientEffect.cpp 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. *** This file was autogenerated from GrTiledGradientEffect.fp; do not modify.
  9. **************************************************************************************************/
  10. #include "GrTiledGradientEffect.h"
  11. #include "include/gpu/GrTexture.h"
  12. #include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
  13. #include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
  14. #include "src/gpu/glsl/GrGLSLProgramBuilder.h"
  15. #include "src/sksl/SkSLCPP.h"
  16. #include "src/sksl/SkSLUtil.h"
  17. class GrGLSLTiledGradientEffect : public GrGLSLFragmentProcessor {
  18. public:
  19. GrGLSLTiledGradientEffect() {}
  20. void emitCode(EmitArgs& args) override {
  21. GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
  22. const GrTiledGradientEffect& _outer = args.fFp.cast<GrTiledGradientEffect>();
  23. (void)_outer;
  24. auto mirror = _outer.mirror;
  25. (void)mirror;
  26. auto makePremul = _outer.makePremul;
  27. (void)makePremul;
  28. auto colorsAreOpaque = _outer.colorsAreOpaque;
  29. (void)colorsAreOpaque;
  30. SkString _child1("_child1");
  31. this->emitChild(_outer.gradLayout_index, &_child1, args);
  32. fragBuilder->codeAppendf(
  33. "half4 t = %s;\nif (!%s && t.y < 0.0) {\n %s = half4(0.0);\n} else {\n @if "
  34. "(%s) {\n half t_1 = t.x - 1.0;\n half tiled_t = (t_1 - 2.0 * "
  35. "floor(t_1 * 0.5)) - 1.0;\n if (sk_Caps.mustDoOpBetweenFloorAndAbs) {\n "
  36. " tiled_t = clamp(tiled_t, -1.0, 1.0);\n }\n t.x = "
  37. "abs(tiled_t);\n } else {\n t.x = fract(t.x);\n }",
  38. _child1.c_str(),
  39. (_outer.childProcessor(_outer.gradLayout_index).preservesOpaqueInput() ? "true"
  40. : "false"),
  41. args.fOutputColor, (_outer.mirror ? "true" : "false"));
  42. SkString _input0("t");
  43. SkString _child0("_child0");
  44. this->emitChild(_outer.colorizer_index, _input0.c_str(), &_child0, args);
  45. fragBuilder->codeAppendf("\n %s = %s;\n}\n@if (%s) {\n %s.xyz *= %s.w;\n}\n",
  46. args.fOutputColor, _child0.c_str(),
  47. (_outer.makePremul ? "true" : "false"), args.fOutputColor,
  48. args.fOutputColor);
  49. }
  50. private:
  51. void onSetData(const GrGLSLProgramDataManager& pdman,
  52. const GrFragmentProcessor& _proc) override {}
  53. };
  54. GrGLSLFragmentProcessor* GrTiledGradientEffect::onCreateGLSLInstance() const {
  55. return new GrGLSLTiledGradientEffect();
  56. }
  57. void GrTiledGradientEffect::onGetGLSLProcessorKey(const GrShaderCaps& caps,
  58. GrProcessorKeyBuilder* b) const {
  59. b->add32((int32_t)mirror);
  60. b->add32((int32_t)makePremul);
  61. }
  62. bool GrTiledGradientEffect::onIsEqual(const GrFragmentProcessor& other) const {
  63. const GrTiledGradientEffect& that = other.cast<GrTiledGradientEffect>();
  64. (void)that;
  65. if (mirror != that.mirror) return false;
  66. if (makePremul != that.makePremul) return false;
  67. if (colorsAreOpaque != that.colorsAreOpaque) return false;
  68. return true;
  69. }
  70. GrTiledGradientEffect::GrTiledGradientEffect(const GrTiledGradientEffect& src)
  71. : INHERITED(kGrTiledGradientEffect_ClassID, src.optimizationFlags())
  72. , colorizer_index(src.colorizer_index)
  73. , gradLayout_index(src.gradLayout_index)
  74. , mirror(src.mirror)
  75. , makePremul(src.makePremul)
  76. , colorsAreOpaque(src.colorsAreOpaque) {
  77. this->registerChildProcessor(src.childProcessor(colorizer_index).clone());
  78. this->registerChildProcessor(src.childProcessor(gradLayout_index).clone());
  79. }
  80. std::unique_ptr<GrFragmentProcessor> GrTiledGradientEffect::clone() const {
  81. return std::unique_ptr<GrFragmentProcessor>(new GrTiledGradientEffect(*this));
  82. }