1 /* 2 * Copyright 2021 Google LLC. 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 #ifndef GrGrModulateAtlasCoverageEffect_DEFINED 9 #define GrGrModulateAtlasCoverageEffect_DEFINED 10 11 #include "src/gpu/GrFragmentProcessor.h" 12 13 // Multiplies 'inputFP' by the coverage value in an atlas, optionally inverting or clamping to 0. 14 class GrModulateAtlasCoverageEffect : public GrFragmentProcessor { 15 public: 16 enum class Flags { 17 kNone = 0, 18 kInvertCoverage = 1 << 0, // Return inputColor * (1 - atlasCoverage). 19 kCheckBounds = 1 << 1 // Clamp atlasCoverage to 0 if outside the path's valid atlas bounds. 20 }; 21 22 GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags); 23 24 GrModulateAtlasCoverageEffect(Flags flags, std::unique_ptr<GrFragmentProcessor> inputFP, 25 GrSurfaceProxyView atlasView, const SkMatrix& devToAtlasMatrix, 26 const SkIRect& devIBounds); 27 28 GrModulateAtlasCoverageEffect(const GrModulateAtlasCoverageEffect& that); 29 name()30 const char* name() const override { 31 return "GrModulateAtlasCoverageFP"; 32 } 33 getShaderDfxInfo()34 SkString getShaderDfxInfo() const override { 35 SkString format; 36 format.printf("ShaderDfx_GrModulateAtlasCoverageEffect_%d", fFlags); 37 return format; 38 } 39 clone()40 std::unique_ptr<GrFragmentProcessor> clone() const override { 41 return std::make_unique<GrModulateAtlasCoverageEffect>(*this); 42 } 43 44 private: onAddToKey(const GrShaderCaps &,GrProcessorKeyBuilder * b)45 void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override { 46 b->add32(fFlags & Flags::kCheckBounds); 47 } onIsEqual(const GrFragmentProcessor & that)48 bool onIsEqual(const GrFragmentProcessor& that) const override { 49 auto fp = that.cast<GrModulateAtlasCoverageEffect>(); 50 return fFlags == fp.fFlags && fBounds == fp.fBounds; 51 } 52 std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override; 53 54 const Flags fFlags; 55 const SkIRect fBounds; 56 }; 57 58 GR_MAKE_BITFIELD_CLASS_OPS(GrModulateAtlasCoverageEffect::Flags) 59 60 #endif 61