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