Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLConstructor.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_CONSTRUCTOR
9#define SKSL_CONSTRUCTOR
10
11#include "include/core/SkSpan.h"
16
17#include <cstdint>
18#include <memory>
19#include <optional>
20#include <string>
21#include <utility>
22
23namespace SkSL {
24
25class Context;
26enum class OperatorPrecedence : uint8_t;
27
28/**
29 * Base class representing a constructor with unknown arguments.
30 */
31class AnyConstructor : public Expression {
32public:
35
38
39 std::string description(OperatorPrecedence) const override;
40
41 const Type& componentType() const {
42 return this->type().componentType();
43 }
44
45 bool supportsConstantValues() const override { return true; }
46 std::optional<double> getConstantValue(int n) const override;
47
48 ComparisonResult compareConstant(const Expression& other) const override;
49
50private:
51 using INHERITED = Expression;
52};
53
54/**
55 * Base class representing a constructor that takes a single argument.
56 */
58public:
60 std::unique_ptr<Expression> argument)
62 , fArgument(std::move(argument)) {}
63
64 std::unique_ptr<Expression>& argument() {
65 return fArgument;
66 }
67
68 const std::unique_ptr<Expression>& argument() const {
69 return fArgument;
70 }
71
73 return {&fArgument, 1};
74 }
75
77 return {&fArgument, 1};
78 }
79
80private:
81 std::unique_ptr<Expression> fArgument;
82
83 using INHERITED = AnyConstructor;
84};
85
86/**
87 * Base class representing a constructor that takes an array of arguments.
88 */
90public:
95
97 return fArguments;
98 }
99
100 const ExpressionArray& arguments() const {
101 return fArguments;
102 }
103
105 return {&fArguments.front(), fArguments.size()};
106 }
107
109 return {&fArguments.front(), fArguments.size()};
110 }
111
112private:
113 ExpressionArray fArguments;
114
115 using INHERITED = AnyConstructor;
116};
117
118/**
119 * Converts any GLSL constructor, such as `float2(x, y)` or `mat3x3(otherMat)` or `int[2](0, i)`, to
120 * an SkSL expression.
121 *
122 * Vector constructors must always consist of either exactly 1 scalar, or a collection of vectors
123 * and scalars totaling exactly the right number of scalar components.
124 *
125 * Matrix constructors must always consist of either exactly 1 scalar, exactly 1 matrix, or a
126 * collection of vectors and scalars totaling exactly the right number of scalar components.
127 *
128 * Array constructors must always contain the proper number of array elements (matching the Type).
129 */
130namespace Constructor {
131 // Creates, typechecks and simplifies constructor expressions. Reports errors via the
132 // ErrorReporter. This can return null on error, so be careful. There are several different
133 // Constructor expression types; this class chooses the proper one based on context, e.g.
134 // `ConstructorCompound`, `ConstructorScalarCast`, or `ConstructorMatrixResize`.
135 std::unique_ptr<Expression> Convert(const Context& context,
137 const Type& type,
139}
140
141} // namespace SkSL
142
143#endif
SkPoint pos
std::optional< double > getConstantValue(int n) const override
ComparisonResult compareConstant(const Expression &other) const override
virtual SkSpan< const std::unique_ptr< Expression > > argumentSpan() const =0
bool supportsConstantValues() const override
AnyConstructor(Position pos, Kind kind, const Type *type)
virtual SkSpan< std::unique_ptr< Expression > > argumentSpan()=0
const Type & componentType() const
Kind kind() const
virtual const Type & type() const
std::string description() const final
SkSpan< const std::unique_ptr< Expression > > argumentSpan() const final
MultiArgumentConstructor(Position pos, Kind kind, const Type *type, ExpressionArray arguments)
SkSpan< std::unique_ptr< Expression > > argumentSpan() final
const ExpressionArray & arguments() const
SkSpan< std::unique_ptr< Expression > > argumentSpan() final
SkSpan< const std::unique_ptr< Expression > > argumentSpan() const final
SingleArgumentConstructor(Position pos, Kind kind, const Type *type, std::unique_ptr< Expression > argument)
const std::unique_ptr< Expression > & argument() const
std::unique_ptr< Expression > & argument()
virtual const Type & componentType() const
Definition SkSLType.h:404
int size() const
Definition SkTArray.h:416
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
OperatorPrecedence
ExpressionKind
Definition SkSLIRNode.h:62
Definition ref_ptr.h:256