1/*
2 * Copyright 2014 Google Inc.
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 GrCoverageSetOpXP_DEFINED
9#define GrCoverageSetOpXP_DEFINED
10
11#include "GrTypes.h"
12#include "GrXferProcessor.h"
13#include "SkRegion.h"
14
15class GrProcOptInfo;
16
17/**
18 * This xfer processor directly blends the the src coverage with the dst using a set operator. It is
19 * useful for rendering coverage masks using CSG. It can optionally invert the src coverage before
20 * applying the set operator.
21 */
22class GrCoverageSetOpXPFactory : public GrXPFactory {
23public:
24    static GrXPFactory* Create(SkRegion::Op regionOp, bool invertCoverage = false);
25
26    void getInvariantBlendedColor(const GrProcOptInfo& colorPOI,
27                                  GrXPFactory::InvariantBlendedColor*) const override;
28
29private:
30    GrCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage);
31
32    GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
33                                           const GrPipelineOptimizations& optimizations,
34                                           bool hasMixedSamples,
35                                           const DstTexture*) const override;
36
37    bool onWillReadDstColor(const GrCaps& /*caps*/,
38                            const GrPipelineOptimizations& /*optimizations*/,
39                            bool /*hasMixedSamples*/) const override {
40        return false;
41    }
42
43    bool onIsEqual(const GrXPFactory& xpfBase) const override {
44        const GrCoverageSetOpXPFactory& xpf = xpfBase.cast<GrCoverageSetOpXPFactory>();
45        return fRegionOp == xpf.fRegionOp;
46    }
47
48    GR_DECLARE_XP_FACTORY_TEST;
49
50    SkRegion::Op fRegionOp;
51    bool         fInvertCoverage;
52
53    typedef GrXPFactory INHERITED;
54};
55#endif
56
57