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_MATRIX_RESIZE 9 #define SKSL_CONSTRUCTOR_MATRIX_RESIZE 10 11 #include "src/sksl/SkSLContext.h" 12 #include "src/sksl/ir/SkSLConstructor.h" 13 #include "src/sksl/ir/SkSLExpression.h" 14 #include "src/sksl/ir/SkSLFloatLiteral.h" 15 16 #include <memory> 17 18 namespace SkSL { 19 20 /** 21 * Represents the construction of a matrix resize operation, such as `mat4x4(myMat2x2)`. 22 * 23 * These always contain exactly 1 matrix of non-matching size. Cells that aren't present in the 24 * input matrix are populated with the identity matrix. 25 */ 26 class ConstructorMatrixResize final : public SingleArgumentConstructor { 27 public: 28 static constexpr Kind kExpressionKind = Kind::kConstructorMatrixResize; 29 ConstructorMatrixResize(int offset,const Type & type,std::unique_ptr<Expression> arg)30 ConstructorMatrixResize(int offset, const Type& type, std::unique_ptr<Expression> arg) 31 : INHERITED(offset, kExpressionKind, &type, std::move(arg)) 32 , fZeroLiteral(offset, /*value=*/0.0f, &type.componentType()) 33 , fOneLiteral(offset, /*value=*/1.0f, &type.componentType()) {} 34 35 static std::unique_ptr<Expression> Make(const Context& context, 36 int offset, 37 const Type& type, 38 std::unique_ptr<Expression> arg); 39 clone()40 std::unique_ptr<Expression> clone() const override { 41 return std::make_unique<ConstructorMatrixResize>(fOffset, this->type(), 42 argument()->clone()); 43 } 44 45 const Expression* getConstantSubexpression(int n) const override; 46 47 private: 48 using INHERITED = SingleArgumentConstructor; 49 const FloatLiteral fZeroLiteral; 50 const FloatLiteral fOneLiteral; 51 }; 52 53 } // namespace SkSL 54 55 #endif 56