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 clone()34 std::unique_ptr<GrFragmentProcessor> clone() const override { 35 return std::make_unique<GrModulateAtlasCoverageEffect>(*this); 36 } 37 38 private: 39 void onAddToKey(const GrShaderCaps&, skgpu::KeyBuilder* b) const override; 40 onIsEqual(const GrFragmentProcessor & that)41 bool onIsEqual(const GrFragmentProcessor& that) const override { 42 auto fp = that.cast<GrModulateAtlasCoverageEffect>(); 43 return fFlags == fp.fFlags && fBounds == fp.fBounds; 44 } 45 std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override; 46 47 const Flags fFlags; 48 const SkIRect fBounds; 49 }; 50 51 GR_MAKE_BITFIELD_CLASS_OPS(GrModulateAtlasCoverageEffect::Flags) 52 53 #endif 54