Flutter Engine
The Flutter Engine
SkSLConstructorDiagonalMatrix.cpp
Go to the documentation of this file.
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
9
13
14namespace SkSL {
15
16std::unique_ptr<Expression> ConstructorDiagonalMatrix::Make(const Context& context,
18 const Type& type,
19 std::unique_ptr<Expression> arg) {
22 SkASSERT(arg->type().isScalar());
23 SkASSERT(arg->type().matches(type.componentType()));
24
25 // Look up the value of constant variables. This allows constant-expressions like `mat4(five)`
26 // to be replaced with `mat4(5.0)`.
28
29 return std::make_unique<ConstructorDiagonalMatrix>(pos, type, std::move(arg));
30}
31
32std::optional<double> ConstructorDiagonalMatrix::getConstantValue(int n) const {
33 int rows = this->type().rows();
34 int row = n % rows;
35 int col = n / rows;
36
37 SkASSERT(col >= 0);
38 SkASSERT(row >= 0);
39 SkASSERT(col < this->type().columns());
40 SkASSERT(row < this->type().rows());
41
42 return (col == row) ? this->argument()->getConstantValue(0) : 0.0;
43}
44
45} // namespace SkSL
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
GLenum type
static std::unique_ptr< Expression > MakeConstantValueForVariable(Position pos, std::unique_ptr< Expression > expr)
static std::unique_ptr< Expression > Make(const Context &context, Position pos, const Type &type, std::unique_ptr< Expression > arg)
std::optional< double > getConstantValue(int n) const override
const Type & type() const
std::unique_ptr< Expression > & argument()
bool isAllowedInES2(const Context &context) const
virtual int rows() const
Definition: SkSLType.h:438
virtual const Type & componentType() const
Definition: SkSLType.h:404
virtual bool isMatrix() const
Definition: SkSLType.h:528