1 | /* |
2 | * Copyright 2016 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 SKSL_SETTING |
9 | #define SKSL_SETTING |
10 | |
11 | #include "src/sksl/SkSLContext.h" |
12 | #include "src/sksl/ir/SkSLExpression.h" |
13 | |
14 | namespace SkSL { |
15 | |
16 | /** |
17 | * Represents a compile-time constant setting, such as sk_Caps.fbFetchSupport. These are generally |
18 | * collapsed down to their constant representations during the compilation process. |
19 | */ |
20 | struct Setting : public Expression { |
21 | Setting(int offset, String name, std::unique_ptr<Expression> value) |
22 | : INHERITED(offset, kSetting_Kind, value->fType) |
23 | , fName(std::move(name)) |
24 | , fValue(std::move(value)) { |
25 | SkASSERT(fValue->isConstant()); |
26 | } |
27 | |
28 | std::unique_ptr<Expression> constantPropagate(const IRGenerator& irGenerator, |
29 | const DefinitionMap& definitions) override; |
30 | |
31 | std::unique_ptr<Expression> clone() const override { |
32 | return std::unique_ptr<Expression>(new Setting(fOffset, fName, fValue->clone())); |
33 | } |
34 | |
35 | #ifdef SK_DEBUG |
36 | String description() const override { |
37 | return fName; |
38 | } |
39 | #endif |
40 | |
41 | bool hasProperty(Property property) const override { |
42 | return false; |
43 | } |
44 | |
45 | bool isConstant() const override { |
46 | return true; |
47 | } |
48 | |
49 | const String fName; |
50 | std::unique_ptr<Expression> fValue; |
51 | |
52 | typedef Expression INHERITED; |
53 | }; |
54 | |
55 | } // namespace |
56 | |
57 | #endif |
58 | |