aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/gpu/effects/GrConstColorProcessor.h
blob: 73ea9eb196cb1ed4fd358acff641761412f2b2f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef GrColorProcessor_DEFINED
#define GrColorProcessor_DEFINED

#include "GrFragmentProcessor.h"

/**
 * This is a simple GrFragmentProcessor that outputs a constant color. It may do one of the
 * following with its input color: ignore it, or multiply it by the constant color, multiply its
 * alpha by the constant color and ignore the input color's r, g, and b.
 */
class GrConstColorProcessor : public GrFragmentProcessor {
public:
    enum InputMode {
        kIgnore_InputMode,
        kModulateRGBA_InputMode,
        kModulateA_InputMode,

        kLastInputMode = kModulateA_InputMode
    };
    static const int kInputModeCnt = kLastInputMode + 1;

    static sk_sp<GrFragmentProcessor> Make(GrColor4f color, InputMode mode) {
        return sk_sp<GrFragmentProcessor>(new GrConstColorProcessor(color, mode));
    }

    const char* name() const override { return "Color"; }

    SkString dumpInfo() const override {
        SkString str;
        str.appendf("Color: 0x%08x", fColor.toGrColor());
        return str;
    }

    GrColor4f color() const { return fColor; }

    InputMode inputMode() const { return fMode; }

private:
    GrConstColorProcessor(GrColor4f color, InputMode mode) : fColor(color), fMode(mode) {
        this->initClassID<GrConstColorProcessor>();
    }

    GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;

    void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;

    bool onIsEqual(const GrFragmentProcessor&) const override;

    void onComputeInvariantOutput(GrInvariantOutput* inout) const override;

    GR_DECLARE_FRAGMENT_PROCESSOR_TEST;

    GrColor4f   fColor;
    InputMode   fMode;

    typedef GrFragmentProcessor INHERITED;
};

#endif