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