1 /* 2 * Copyright 2021 Google LLC 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_VECTOR 9 #define SKSL_CONSTRUCTOR_VECTOR 10 11 #include "src/sksl/SkSLContext.h" 12 #include "src/sksl/ir/SkSLConstructor.h" 13 #include "src/sksl/ir/SkSLExpression.h" 14 15 #include <memory> 16 17 namespace SkSL { 18 19 /** 20 * Represents a vector or matrix that is composed from other expressions, such as 21 * `half3(pos.xy, 1)` or `mat3(a.xyz, b.xyz, 0, 0, 1)` 22 * 23 * These can contain a mix of scalars and aggregates. The total number of scalar values inside the 24 * constructor must always match the type's slot count. (e.g. `pos.xy` consumes two slots.) 25 * The inner values must have the same component type as the vector/matrix. 26 */ 27 class ConstructorCompound final : public MultiArgumentConstructor { 28 public: 29 static constexpr Kind kExpressionKind = Kind::kConstructorCompound; 30 ConstructorCompound(int offset,const Type & type,ExpressionArray args)31 ConstructorCompound(int offset, const Type& type, ExpressionArray args) 32 : INHERITED(offset, kExpressionKind, &type, std::move(args)) {} 33 34 static std::unique_ptr<Expression> Make(const Context& context, 35 int offset, 36 const Type& type, 37 ExpressionArray args); 38 clone()39 std::unique_ptr<Expression> clone() const override { 40 return std::make_unique<ConstructorCompound>(fOffset, this->type(), this->cloneArguments()); 41 } 42 43 private: 44 using INHERITED = MultiArgumentConstructor; 45 }; 46 47 } // namespace SkSL 48 49 #endif 50