/src/skia/src/sksl/ir/SkSLSwizzle.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
11 | | #include "include/private/SkSLDefines.h" |
12 | | #include "src/sksl/SkSLContext.h" |
13 | | #include "src/sksl/SkSLIRGenerator.h" |
14 | | #include "src/sksl/SkSLUtil.h" |
15 | | #include "src/sksl/ir/SkSLConstructor.h" |
16 | | #include "src/sksl/ir/SkSLExpression.h" |
17 | | |
18 | | namespace SkSL { |
19 | | |
20 | | /** |
21 | | * Represents a vector swizzle operation such as 'float3(1, 2, 3).zyx'. |
22 | | */ |
23 | | struct Swizzle final : public Expression { |
24 | | static constexpr Kind kExpressionKind = Kind::kSwizzle; |
25 | | |
26 | | Swizzle(const Context& context, std::unique_ptr<Expression> base, |
27 | | const ComponentArray& components) |
28 | | : INHERITED(base->fOffset, kExpressionKind, |
29 | | &base->type().componentType().toCompound(context, components.size(), 1)) |
30 | | , fBase(std::move(base)) |
31 | 10.0M | , fComponents(components) { |
32 | 10.0M | SkASSERT(this->components().size() >= 1 && this->components().size() <= 4); |
33 | 10.0M | } SkSL::Swizzle::Swizzle(SkSL::Context const&, std::__1::unique_ptr<SkSL::Expression, std::__1::default_delete<SkSL::Expression> >, SkSTArray<4, signed char, false> const&) Line | Count | Source | 31 | 360 | , fComponents(components) { | 32 | 360 | SkASSERT(this->components().size() >= 1 && this->components().size() <= 4); | 33 | 360 | } |
SkSL::Swizzle::Swizzle(SkSL::Context const&, std::__1::unique_ptr<SkSL::Expression, std::__1::default_delete<SkSL::Expression> >, SkSTArray<4, signed char, false> const&) Line | Count | Source | 31 | 10.0M | , fComponents(components) { | 32 | 10.0M | SkASSERT(this->components().size() >= 1 && this->components().size() <= 4); | 33 | 10.0M | } |
|
34 | | |
35 | | // Swizzle::Convert permits component arrays containing ZERO or ONE, does typechecking, reports |
36 | | // errors via ErrorReporter, and returns an expression that combines constructors and native |
37 | | // swizzles (comprised solely of X/Y/W/Z). |
38 | | static std::unique_ptr<Expression> Convert(const Context& context, |
39 | | std::unique_ptr<Expression> base, |
40 | | ComponentArray inComponents); |
41 | | |
42 | | static std::unique_ptr<Expression> Convert(const Context& context, |
43 | | std::unique_ptr<Expression> base, |
44 | | skstd::string_view maskString); |
45 | | |
46 | | // Swizzle::Make does not permit ZERO or ONE in the component array, just X/Y/Z/W; errors are |
47 | | // reported via ASSERT. |
48 | | static std::unique_ptr<Expression> Make(const Context& context, |
49 | | std::unique_ptr<Expression> expr, |
50 | | ComponentArray inComponents); |
51 | | |
52 | 18.9M | std::unique_ptr<Expression>& base() { |
53 | 18.9M | return fBase; |
54 | 18.9M | } |
55 | | |
56 | 50.7M | const std::unique_ptr<Expression>& base() const { |
57 | 50.7M | return fBase; |
58 | 50.7M | } |
59 | | |
60 | 35.1M | const ComponentArray& components() const { |
61 | 35.1M | return fComponents; |
62 | 35.1M | } |
63 | | |
64 | 1.25M | bool hasProperty(Property property) const override { |
65 | 1.25M | return this->base()->hasProperty(property); |
66 | 1.25M | } |
67 | | |
68 | 2.11M | std::unique_ptr<Expression> clone() const override { |
69 | 2.11M | return std::unique_ptr<Expression>(new Swizzle(&this->type(), this->base()->clone(), |
70 | 2.11M | this->components())); |
71 | 2.11M | } |
72 | | |
73 | 0 | String description() const override { |
74 | 0 | String result = this->base()->description() + "."; |
75 | 0 | for (int x : this->components()) { |
76 | 0 | result += "xyzw"[x]; |
77 | 0 | } |
78 | 0 | return result; |
79 | 0 | } |
80 | | |
81 | | private: |
82 | | static std::unique_ptr<Expression> Convert(const Context& context, |
83 | | std::unique_ptr<Expression> base, |
84 | | ComponentArray inComponents, |
85 | | skstd::string_view maskString); |
86 | | |
87 | | Swizzle(const Type* type, std::unique_ptr<Expression> base, const ComponentArray& components) |
88 | | : INHERITED(base->fOffset, kExpressionKind, type) |
89 | | , fBase(std::move(base)) |
90 | 2.11M | , fComponents(components) { |
91 | 2.11M | SkASSERT(this->components().size() >= 1 && this->components().size() <= 4); |
92 | 2.11M | } SkSL::Swizzle::Swizzle(SkSL::Type const*, std::__1::unique_ptr<SkSL::Expression, std::__1::default_delete<SkSL::Expression> >, SkSTArray<4, signed char, false> const&) Line | Count | Source | 90 | 12 | , fComponents(components) { | 91 | 12 | SkASSERT(this->components().size() >= 1 && this->components().size() <= 4); | 92 | 12 | } |
SkSL::Swizzle::Swizzle(SkSL::Type const*, std::__1::unique_ptr<SkSL::Expression, std::__1::default_delete<SkSL::Expression> >, SkSTArray<4, signed char, false> const&) Line | Count | Source | 90 | 2.11M | , fComponents(components) { | 91 | 2.11M | SkASSERT(this->components().size() >= 1 && this->components().size() <= 4); | 92 | 2.11M | } |
|
93 | | |
94 | | std::unique_ptr<Expression> fBase; |
95 | | ComponentArray fComponents; |
96 | | |
97 | | using INHERITED = Expression; |
98 | | }; |
99 | | |
100 | | } // namespace SkSL |
101 | | |
102 | | #endif |