Flutter Engine
The Flutter Engine
Functions
SkSL::Constructor Namespace Reference

Functions

std::unique_ptr< ExpressionConvert (const Context &context, Position pos, const Type &type, ExpressionArray args)
 

Detailed Description

Converts any GLSL constructor, such as float2(x, y) or mat3x3(otherMat) or int[2](0, i), to an SkSL expression.

Vector constructors must always consist of either exactly 1 scalar, or a collection of vectors and scalars totaling exactly the right number of scalar components.

Matrix constructors must always consist of either exactly 1 scalar, exactly 1 matrix, or a collection of vectors and scalars totaling exactly the right number of scalar components.

Array constructors must always contain the proper number of array elements (matching the Type).

Function Documentation

◆ Convert()

std::unique_ptr< Expression > SkSL::Constructor::Convert ( const Context context,
Position  pos,
const Type type,
ExpressionArray  args 
)

Definition at line 151 of file SkSLConstructor.cpp.

154 {
155 if (args.size() == 1 && args[0]->type().matches(type) && !type.componentType().isOpaque()) {
156 // Don't generate redundant casts; if the expression is already of the correct type, just
157 // return it as-is.
158 args[0]->fPosition = pos;
159 return std::move(args[0]);
160 }
161 if (type.isScalar()) {
162 return ConstructorScalarCast::Convert(context, pos, type, std::move(args));
163 }
164 if (type.isVector() || type.isMatrix()) {
165 return convert_compound_constructor(context, pos, type, std::move(args));
166 }
167 if (type.isArray() && type.columns() > 0) {
168 return ConstructorArray::Convert(context, pos, type, std::move(args));
169 }
170 if (type.isStruct() && type.fields().size() > 0) {
171 return ConstructorStruct::Convert(context, pos, type, std::move(args));
172 }
173
174 context.fErrors->error(pos, "cannot construct '" + type.displayName() + "'");
175 return nullptr;
176}
SkPoint pos
GLenum type
ErrorReporter * fErrors
Definition: SkSLContext.h:36
void error(Position position, std::string_view msg)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
std::unique_ptr< Expression > Convert(const Context &context, Position pos, const Type &type, ExpressionArray args)
static std::unique_ptr< Expression > convert_compound_constructor(const Context &context, Position pos, const Type &type, ExpressionArray args)