Flutter Engine
The Flutter Engine
SkSLSetting.h
Go to the documentation of this file.
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
12#include "src/sksl/SkSLUtil.h"
15
16#include <cstdint>
17#include <memory>
18#include <string>
19#include <string_view>
20
21
22namespace SkSL {
23
24class Context;
25class Type;
26enum 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 */
33class Setting final : public Expression {
34public:
35 inline static constexpr Kind kIRNodeKind = Kind::kSetting;
36
37 using CapsPtr = const bool ShaderCaps::*;
38
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,
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 ShaderCaps& caps) const;
56
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
63 CapsPtr capsPtr() const { return fCapsPtr; }
64
65 std::string description(OperatorPrecedence) const override {
66 return "sk_Caps." + std::string(this->name());
67 }
68
69private:
70 CapsPtr fCapsPtr;
71
72 using INHERITED = Expression;
73};
74
75} // namespace SkSL
76
77#endif
SkPoint pos
Expression(Position pos, Kind kind, const Type *type)
const Type & type() const
Setting(Position pos, CapsPtr capsPtr, const Type *type)
Definition: SkSLSetting.h:39
std::string description(OperatorPrecedence) const override
Definition: SkSLSetting.h:65
std::unique_ptr< Expression > toLiteral(const ShaderCaps &caps) const
Definition: SkSLSetting.cpp:88
std::unique_ptr< Expression > clone(Position pos) const override
Definition: SkSLSetting.h:57
CapsPtr capsPtr() const
Definition: SkSLSetting.h:63
static std::unique_ptr< Expression > Convert(const Context &context, Position pos, const std::string_view &name)
Definition: SkSLSetting.cpp:63
const bool ShaderCaps::* CapsPtr
Definition: SkSLSetting.h:37
static constexpr Kind kIRNodeKind
Definition: SkSLSetting.h:35
static std::unique_ptr< Expression > Make(const Context &context, Position pos, CapsPtr capsPtr)
Definition: SkSLSetting.cpp:82
std::string_view name() const
Definition: SkSLSetting.cpp:54
OperatorPrecedence
Definition: SkSLOperator.h:57
ExpressionKind
Definition: SkSLIRNode.h:62