Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSLChildCall.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
15#include "src/sksl/SkSLString.h"
18
19using namespace skia_private;
20
21namespace SkSL {
22
23std::unique_ptr<Expression> ChildCall::clone(Position pos) const {
24 return std::make_unique<ChildCall>(pos, &this->type(), &this->child(),
25 this->arguments().clone());
26}
27
29 std::string result = std::string(this->child().name()) + ".eval(";
30 auto separator = SkSL::String::Separator();
31 for (const std::unique_ptr<Expression>& arg : this->arguments()) {
32 result += separator();
33 result += arg->description(OperatorPrecedence::kSequence);
34 }
35 result += ")";
36 return result;
37}
38
39[[maybe_unused]] static bool call_signature_is_valid(const Context& context,
40 const Variable& child,
41 const ExpressionArray& arguments) {
42 const Type* half4 = context.fTypes.fHalf4.get();
43 const Type* float2 = context.fTypes.fFloat2.get();
44
45 auto params = [&]() -> STArray<2, const Type*> {
46 switch (child.type().typeKind()) {
47 case Type::TypeKind::kBlender: return { half4, half4 };
48 case Type::TypeKind::kColorFilter: return { half4 };
49 case Type::TypeKind::kShader: return { float2 };
50 default:
52 }
53 }();
54
55 if (params.size() != arguments.size()) {
56 return false;
57 }
58 for (int i = 0; i < arguments.size(); i++) {
59 if (!arguments[i]->type().matches(*params[i])) {
60 return false;
61 }
62 }
63 return true;
64}
65
66std::unique_ptr<Expression> ChildCall::Make(const Context& context,
68 const Type* returnType,
69 const Variable& child,
70 ExpressionArray arguments) {
72 return std::make_unique<ChildCall>(pos, returnType, &child, std::move(arguments));
73}
74
75} // namespace SkSL
SkPoint pos
#define SkUNREACHABLE
Definition SkAssert.h:135
#define SkASSERT(cond)
Definition SkAssert.h:116
const std::unique_ptr< Type > fFloat2
const std::unique_ptr< Type > fHalf4
static std::unique_ptr< Expression > Make(const Context &context, Position pos, const Type *returnType, const Variable &child, ExpressionArray arguments)
ExpressionArray & arguments()
const Variable & child() const
const BuiltinTypes & fTypes
Definition SkSLContext.h:30
virtual const Type & type() const
std::unique_ptr< Expression > clone() const
std::string description() const final
const Type & type() const
Definition SkSLSymbol.h:42
TypeKind typeKind() const
Definition SkSLType.h:283
int size() const
Definition SkTArray.h:416
const EmbeddedViewParams * params
GAsyncResult * result
const char * name
Definition fuchsia.cc:50
std::string void void auto Separator()
Definition SkSLString.h:30
static bool call_signature_is_valid(const Context &context, const Variable &child, const ExpressionArray &arguments)
OperatorPrecedence