Flutter Engine
The Flutter Engine
SkSLConstructorSplat.h
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
8#ifndef SKSL_CONSTRUCTOR_SPLAT
9#define SKSL_CONSTRUCTOR_SPLAT
10
17
18#include <memory>
19#include <optional>
20#include <utility>
21
22namespace SkSL {
23
24class Context;
25
26/**
27 * Represents the construction of a vector splat, such as `half3(n)`.
28 *
29 * These always contain exactly 1 scalar.
30 */
32public:
33 inline static constexpr Kind kIRNodeKind = Kind::kConstructorSplat;
34
35 ConstructorSplat(Position pos, const Type& type, std::unique_ptr<Expression> arg)
36 : INHERITED(pos, kIRNodeKind, &type, std::move(arg)) {}
37
38 // The input argument must be scalar. A "splat" to a scalar type will be optimized into a no-op.
39 static std::unique_ptr<Expression> Make(const Context& context,
41 const Type& type,
42 std::unique_ptr<Expression> arg);
43
44 std::unique_ptr<Expression> clone(Position pos) const override {
45 return std::make_unique<ConstructorSplat>(pos, this->type(), argument()->clone());
46 }
47
48 bool supportsConstantValues() const override {
49 return true;
50 }
51
52 std::optional<double> getConstantValue(int n) const override {
53 SkASSERT(n >= 0 && n < this->type().columns());
54 return this->argument()->getConstantValue(0);
55 }
56
57private:
58 using INHERITED = SingleArgumentConstructor;
59};
60
61} // namespace SkSL
62
63#endif
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
std::unique_ptr< Expression > clone(Position pos) const override
ConstructorSplat(Position pos, const Type &type, std::unique_ptr< Expression > arg)
static std::unique_ptr< Expression > Make(const Context &context, Position pos, const Type &type, std::unique_ptr< Expression > arg)
bool supportsConstantValues() const override
static constexpr Kind kIRNodeKind
std::optional< double > getConstantValue(int n) const override
std::unique_ptr< Expression > clone() const
const Type & type() const
SingleArgumentConstructor(Position pos, Kind kind, const Type *type, std::unique_ptr< Expression > argument)
std::unique_ptr< Expression > & argument()
ExpressionKind
Definition: SkSLIRNode.h:62
Definition: ref_ptr.h:256