• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 IRNodes should
18  * only exist in a dehydrated module. These nodes are replaced with the value of the setting during
19  * rehydration or compilation (i.e., whenever fReplaceSettings is true).
20  */
21 class Setting final : public Expression {
22 public:
23     inline static constexpr Kind kExpressionKind = Kind::kSetting;
24 
Setting(int line,skstd::string_view name,const Type * type)25     Setting(int line, skstd::string_view name, const Type* type)
26         : INHERITED(line, kExpressionKind, type)
27         , fName(std::move(name)) {}
28 
29     // Creates an SkSL setting expression if `fReplaceSettings` is false, or the current value of
30     // the setting when it is true. Reports errors via the ErrorReporter.
31     // (There's no failsafe Make equivalent, because there really isn't a good fallback expression
32     // to produce when the `name` lookup fails. We wouldn't even know the expected type.)
33     static std::unique_ptr<Expression> Convert(const Context& context, int line,
34                                                const skstd::string_view& name);
35 
clone()36     std::unique_ptr<Expression> clone() const override {
37         return std::make_unique<Setting>(fLine, this->name(), &this->type());
38     }
39 
name()40     const skstd::string_view& name() const {
41         return fName;
42     }
43 
description()44     String description() const override {
45         return String(this->name());
46     }
47 
hasProperty(Property property)48     bool hasProperty(Property property) const override {
49         return false;
50     }
51 
52 private:
53     skstd::string_view fName;
54 
55     using INHERITED = Expression;
56 };
57 
58 }  // namespace SkSL
59 
60 #endif
61