• 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 "include/private/SkSLIRNode.h"
12 #include "include/sksl/SkSLPosition.h"
13 #include "src/sksl/SkSLUtil.h"
14 #include "src/sksl/ir/SkSLExpression.h"
15 
16 #include <cstdint>
17 #include <memory>
18 #include <string>
19 #include <string_view>
20 
21 
22 namespace SkSL {
23 
24 class Context;
25 class Type;
26 enum class OperatorPrecedence : uint8_t;
27 
28 /**
29  * Represents a compile-time constant setting, such as sk_Caps.integerSupport. These IRNodes are
30  * used when assembling a module. These nodes are replaced with the value of the setting during
31  * compilation when ShaderCaps are available.
32  */
33 class Setting final : public Expression {
34 public:
35     inline static constexpr Kind kIRNodeKind = Kind::kSetting;
36 
37     using CapsPtr = const bool ShaderCaps::*;
38 
Setting(Position pos,CapsPtr capsPtr,const Type * type)39     Setting(Position pos, CapsPtr capsPtr, const Type* type)
40         : INHERITED(pos, kIRNodeKind, type)
41         , fCapsPtr(capsPtr) {}
42 
43     // Creates the current value of the associated caps bit as a Literal if ShaderCaps are
44     // available, or a Setting IRNode when ShaderCaps are not known. Reports errors via the
45     // ErrorReporter.
46     static std::unique_ptr<Expression> Convert(const Context& context,
47                                                Position pos,
48                                                const std::string_view& name);
49 
50     // Creates the current value of the passed-in caps bit as a Literal if ShaderCaps are
51     // available, or a Setting IRNode when ShaderCaps are not known.
52     static std::unique_ptr<Expression> Make(const Context& context, Position pos, CapsPtr capsPtr);
53 
54     // Converts a Setting expression to its actual ShaderCaps value (boolean true/false).
55     std::unique_ptr<Expression> toLiteral(const Context& context) const;
56 
clone(Position pos)57     std::unique_ptr<Expression> clone(Position pos) const override {
58         return std::make_unique<Setting>(pos, fCapsPtr, &this->type());
59     }
60 
61     std::string_view name() const;
62 
description(OperatorPrecedence)63     std::string description(OperatorPrecedence) const override {
64         return "sk_Caps." + std::string(this->name());
65     }
66 
67 private:
68     CapsPtr fCapsPtr;
69 
70     using INHERITED = Expression;
71 };
72 
73 }  // namespace SkSL
74 
75 #endif
76