Flutter Engine
The Flutter Engine
SkSLSwizzle.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
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_SWIZZLE
9#define SKSL_SWIZZLE
10
17
18#include <cstdint>
19#include <initializer_list>
20#include <memory>
21#include <string>
22#include <string_view>
23#include <utility>
24
25namespace SkSL {
26
27class Context;
28enum class OperatorPrecedence : uint8_t;
29
30namespace SwizzleComponent {
31
32enum Type : int8_t {
33 X = 0, Y = 1, Z = 2, W = 3,
34 R = 4, G = 5, B = 6, A = 7,
35 S = 8, T = 9, P = 10, Q = 11,
36 UL = 12, UT = 13, UR = 14, UB = 15,
38 ONE
39};
40
41} // namespace SwizzleComponent
42
43/**
44 * Represents the components of a vector swizzle.
45 */
47
48/**
49 * Represents a vector swizzle operation such as 'float3(1, 2, 3).zyx'.
50 */
51class Swizzle final : public Expression {
52public:
53 inline static constexpr Kind kIRNodeKind = Kind::kSwizzle;
54
56
57 Swizzle(const Context& context, Position pos, std::unique_ptr<Expression> base,
60 &base->type().componentType().toCompound(context, components.size(), 1))
61 , fBase(std::move(base))
62 , fComponents(components) {
63 SkASSERT(this->components().size() >= 1 && this->components().size() <= 4);
64 }
65
66 // Swizzle::Convert permits component strings containing ZERO or ONE, does typechecking, reports
67 // errors via ErrorReporter, and returns an expression that combines constructors and native
68 // swizzles (comprised solely of X/Y/W/Z).
69 static std::unique_ptr<Expression> Convert(const Context& context,
71 Position maskPos,
72 std::unique_ptr<Expression> base,
73 std::string_view componentString);
74
75 // Swizzle::Make does not permit ZERO or ONE in the component array, just X/Y/Z/W; errors are
76 // reported via ASSERT.
77 static std::unique_ptr<Expression> Make(const Context& context,
79 std::unique_ptr<Expression> expr,
80 ComponentArray inComponents);
81
82 std::unique_ptr<Expression>& base() {
83 return fBase;
84 }
85
86 const std::unique_ptr<Expression>& base() const {
87 return fBase;
88 }
89
90 const ComponentArray& components() const {
91 return fComponents;
92 }
93
94 std::unique_ptr<Expression> clone(Position pos) const override {
95 return std::unique_ptr<Expression>(new Swizzle(pos, &this->type(), this->base()->clone(),
96 this->components()));
97 }
98
99 std::string description(OperatorPrecedence) const override;
100
101 // Converts an array of swizzle components into a string.
102 static std::string MaskString(const ComponentArray& inComponents);
103
104 // Returns true if a swizzle keeps each component in its original position.
105 static bool IsIdentity(const ComponentArray& components);
106
107private:
108 Swizzle(Position pos, const Type* type, std::unique_ptr<Expression> base,
110 : INHERITED(pos, kIRNodeKind, type)
111 , fBase(std::move(base))
112 , fComponents(components) {
113 SkASSERT(this->components().size() >= 1 && this->components().size() <= 4);
114 }
115
116 std::unique_ptr<Expression> fBase;
117 ComponentArray fComponents;
118
119 using INHERITED = Expression;
120};
121
122} // namespace SkSL
123
124#endif
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
std::unique_ptr< Expression > clone() const
Expression(Position pos, Kind kind, const Type *type)
const Type & type() const
std::string description() const final
Swizzle(const Context &context, Position pos, std::unique_ptr< Expression > base, const ComponentArray &components)
Definition: SkSLSwizzle.h:57
std::unique_ptr< Expression > & base()
Definition: SkSLSwizzle.h:82
std::unique_ptr< Expression > clone(Position pos) const override
Definition: SkSLSwizzle.h:94
static bool IsIdentity(const ComponentArray &components)
const std::unique_ptr< Expression > & base() const
Definition: SkSLSwizzle.h:86
static constexpr Kind kIRNodeKind
Definition: SkSLSwizzle.h:53
const ComponentArray & components() const
Definition: SkSLSwizzle.h:90
static std::unique_ptr< Expression > Make(const Context &context, Position pos, std::unique_ptr< Expression > expr, ComponentArray inComponents)
static std::string MaskString(const ComponentArray &inComponents)
static std::unique_ptr< Expression > Convert(const Context &context, Position pos, Position maskPos, std::unique_ptr< Expression > base, std::string_view componentString)
OperatorPrecedence
Definition: SkSLOperator.h:57
skia_private::FixedArray< 4, int8_t > ComponentArray
Definition: SkSLSwizzle.h:46
ExpressionKind
Definition: SkSLIRNode.h:62
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: ref_ptr.h:256
Definition: SkMD5.cpp:125