aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/ir/SkSLSetting.h
blob: cc1c551077b5826031a8d6522aff6dac3a4f7045 (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
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SKSL_SETTING
#define SKSL_SETTING

#include "SkSLContext.h"
#include "SkSLExpression.h"

namespace SkSL {

/**
 * Represents a compile-time constant setting, such as sk_Caps.fbFetchSupport. These are generally
 * collapsed down to their constant representations during the compilation process.
 */
struct Setting : public Expression {
    Setting(int offset, String name, std::unique_ptr<Expression> value)
    : INHERITED(offset, kSetting_Kind, value->fType)
    , fName(std::move(name))
    , fValue(std::move(value)) {
        SkASSERT(fValue->isConstant());
    }

    std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator,
                                                  const DefinitionMap& definitions) override;

    std::unique_ptr<Expression> clone() const override {
        return std::unique_ptr<Expression>(new Setting(fOffset, fName, fValue->clone()));
    }

    String description() const override {
        return fName;
    }

    bool hasSideEffects() const override {
        return false;
    }

    bool isConstant() const override {
        return true;
    }

    const String fName;
    std::unique_ptr<Expression> fValue;

    typedef Expression INHERITED;
};

} // namespace

#endif