Flutter Engine
The Flutter Engine
SkSLConstructorSplat.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
11
12namespace SkSL {
13
14std::unique_ptr<Expression> ConstructorSplat::Make(const Context& context,
16 const Type& type,
17 std::unique_ptr<Expression> arg) {
20 SkASSERT(arg->type().scalarTypeForLiteral().matches(
22 SkASSERT(arg->type().isScalar());
23
24 // A "splat" to a scalar type is a no-op and can be eliminated.
25 if (type.isScalar()) {
26 arg->fPosition = pos;
27 return arg;
28 }
29
30 // Replace constant variables with their corresponding values, so `float3(five)` can compile
31 // down to `float3(5.0)` (the latter is a compile-time constant).
33
35 return std::make_unique<ConstructorSplat>(pos, type, std::move(arg));
36}
37
38} // 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)
const Type & type() const
virtual bool isVector() const
Definition: SkSLType.h:524
bool isAllowedInES2(const Context &context) const
virtual const Type & componentType() const
Definition: SkSLType.h:404
virtual bool isScalar() const
Definition: SkSLType.h:512
virtual const Type & scalarTypeForLiteral() const
Definition: SkSLType.h:520