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