blob: fee39f1794539de9b581acd6d0ef04a7021049d8 [file] [log] [blame]
Chris Daltonabed2672021-06-17 16:54:28 -06001/*
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
Chris Daltonc3176002021-07-23 15:33:09 -06008#ifndef GrGrModulateAtlasCoverageEffect_DEFINED
9#define GrGrModulateAtlasCoverageEffect_DEFINED
Chris Daltonabed2672021-06-17 16:54:28 -060010
11#include "src/gpu/GrFragmentProcessor.h"
12
13// Multiplies 'inputFP' by the coverage value in an atlas, optionally inverting or clamping to 0.
Chris Daltonc3176002021-07-23 15:33:09 -060014class GrModulateAtlasCoverageEffect : public GrFragmentProcessor {
Chris Daltonabed2672021-06-17 16:54:28 -060015public:
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
Chris Daltonc3176002021-07-23 15:33:09 -060024 GrModulateAtlasCoverageEffect(Flags flags, std::unique_ptr<GrFragmentProcessor> inputFP,
25 GrSurfaceProxyView atlasView, const SkMatrix& devToAtlasMatrix,
26 const SkIRect& devIBounds);
Chris Daltonabed2672021-06-17 16:54:28 -060027
Chris Daltonc3176002021-07-23 15:33:09 -060028 GrModulateAtlasCoverageEffect(const GrModulateAtlasCoverageEffect& that);
Chris Daltonabed2672021-06-17 16:54:28 -060029
30 const char* name() const override {
31 return "GrModulateAtlasCoverageFP";
32 }
33 void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const override {
34 b->add32(fFlags & Flags::kCheckBounds);
35 }
36 std::unique_ptr<GrFragmentProcessor> clone() const override {
Chris Daltonc3176002021-07-23 15:33:09 -060037 return std::make_unique<GrModulateAtlasCoverageEffect>(*this);
Chris Daltonabed2672021-06-17 16:54:28 -060038 }
39 bool onIsEqual(const GrFragmentProcessor& that) const override {
Chris Daltonc3176002021-07-23 15:33:09 -060040 auto fp = that.cast<GrModulateAtlasCoverageEffect>();
Chris Daltonabed2672021-06-17 16:54:28 -060041 return fFlags == fp.fFlags && fBounds == fp.fBounds;
42 }
43 std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
44
45private:
46 const Flags fFlags;
47 const SkIRect fBounds;
48};
49
Chris Daltonc3176002021-07-23 15:33:09 -060050GR_MAKE_BITFIELD_CLASS_OPS(GrModulateAtlasCoverageEffect::Flags)
Chris Daltonabed2672021-06-17 16:54:28 -060051
52#endif