SkArithmeticMode_gpu.h revision bb106b5f6ee18f7453b63f3a95f421b60a957f39
1/*
2 * Copyright 2015 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 SkArithmeticMode_gpu_DEFINED
9#define SkArithmeticMode_gpu_DEFINED
10
11#include "SkTypes.h"
12
13#if SK_SUPPORT_GPU
14
15#include "GrCaps.h"
16#include "GrCoordTransform.h"
17#include "GrFragmentProcessor.h"
18#include "GrTextureAccess.h"
19#include "GrTypes.h"
20#include "GrXferProcessor.h"
21
22class GrInvariantOutput;
23class GrProcOptInfo;
24class GrTexture;
25
26///////////////////////////////////////////////////////////////////////////////
27// Fragment Processor
28///////////////////////////////////////////////////////////////////////////////
29
30class GrGLArtithmeticFP;
31
32class GrArithmeticFP : public GrFragmentProcessor {
33public:
34    static GrFragmentProcessor* Create(float k1, float k2, float k3, float k4, bool enforcePMColor,
35                               GrTexture* background) {
36        return SkNEW_ARGS(GrArithmeticFP, (k1, k2, k3, k4, enforcePMColor, background));
37    }
38
39    ~GrArithmeticFP() override {};
40
41    const char* name() const override { return "Arithmetic"; }
42
43    void getGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override;
44
45    GrGLFragmentProcessor* createGLInstance() const override;
46
47    float k1() const { return fK1; }
48    float k2() const { return fK2; }
49    float k3() const { return fK3; }
50    float k4() const { return fK4; }
51    bool enforcePMColor() const { return fEnforcePMColor; }
52
53private:
54    bool onIsEqual(const GrFragmentProcessor&) const override;
55
56    void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
57
58    GrArithmeticFP(float k1, float k2, float k3, float k4, bool enforcePMColor,
59                   GrTexture* background);
60
61    float                       fK1, fK2, fK3, fK4;
62    bool                        fEnforcePMColor;
63    GrCoordTransform            fBackgroundTransform;
64    GrTextureAccess             fBackgroundAccess;
65
66    GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
67    typedef GrFragmentProcessor INHERITED;
68};
69
70///////////////////////////////////////////////////////////////////////////////
71// Xfer Processor
72///////////////////////////////////////////////////////////////////////////////
73
74class GrArithmeticXPFactory : public GrXPFactory {
75public:
76    static GrXPFactory* Create(float k1, float k2, float k3, float k4, bool enforcePMColor) {
77        return SkNEW_ARGS(GrArithmeticXPFactory, (k1, k2, k3, k4, enforcePMColor));
78    }
79
80    bool supportsRGBCoverage(GrColor knownColor, uint32_t knownColorFlags) const override {
81        return true;
82    }
83
84    void getInvariantOutput(const GrProcOptInfo& colorPOI, const GrProcOptInfo& coveragePOI,
85                            GrXPFactory::InvariantOutput*) const override;
86
87private:
88    GrArithmeticXPFactory(float k1, float k2, float k3, float k4, bool enforcePMColor);
89
90    GrXferProcessor* onCreateXferProcessor(const GrCaps& caps,
91                                           const GrProcOptInfo& colorPOI,
92                                           const GrProcOptInfo& coveragePOI,
93                                           const DstTexture*) const override;
94
95    bool willReadDstColor(const GrCaps& caps,
96                          const GrProcOptInfo& colorPOI,
97                          const GrProcOptInfo& coveragePOI) const override {
98        return true;
99    }
100
101    bool onIsEqual(const GrXPFactory& xpfBase) const override {
102        const GrArithmeticXPFactory& xpf = xpfBase.cast<GrArithmeticXPFactory>();
103        if (fK1 != xpf.fK1 ||
104            fK2 != xpf.fK2 ||
105            fK3 != xpf.fK3 ||
106            fK4 != xpf.fK4 ||
107            fEnforcePMColor != xpf.fEnforcePMColor) {
108            return false;
109        }
110        return true;
111    }
112
113    GR_DECLARE_XP_FACTORY_TEST;
114
115    float                       fK1, fK2, fK3, fK4;
116    bool                        fEnforcePMColor;
117
118    typedef GrXPFactory INHERITED;
119};
120
121#endif
122#endif
123