Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1156)

Side by Side Diff: src/sksl/ir/SkSLSwizzle.h

Issue 2131223002: SkSL performance improvements (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: went back to pointers on global types Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SKSL_SWIZZLE 8 #ifndef SKSL_SWIZZLE
9 #define SKSL_SWIZZLE 9 #define SKSL_SWIZZLE
10 10
11 #include "SkSLExpression.h" 11 #include "SkSLExpression.h"
12 #include "SkSLUtil.h" 12 #include "SkSLUtil.h"
13 13
14 namespace SkSL { 14 namespace SkSL {
15 15
16 /** 16 /**
17 * Given a type and a swizzle component count, returns the type that will result from swizzling. For 17 * Given a type and a swizzle component count, returns the type that will result from swizzling. For
18 * instance, swizzling a vec3 with two components will result in a vec2. It is p ossible to swizzle 18 * instance, swizzling a vec3 with two components will result in a vec2. It is p ossible to swizzle
19 * with more components than the source vector, as in 'vec2(1).xxxx'. 19 * with more components than the source vector, as in 'vec2(1).xxxx'.
20 */ 20 */
21 static std::shared_ptr<Type> get_type(Expression& value, 21 static const Type& get_type(Expression& value, size_t count) {
22 size_t count) { 22 const Type& base = value.fType.componentType();
23 std::shared_ptr<Type> base = value.fType->componentType();
24 if (count == 1) { 23 if (count == 1) {
25 return base; 24 return base;
26 } 25 }
27 if (base == kFloat_Type) { 26 if (base == *kFloat_Type) {
28 switch (count) { 27 switch (count) {
29 case 2: return kVec2_Type; 28 case 2: return *kVec2_Type;
30 case 3: return kVec3_Type; 29 case 3: return *kVec3_Type;
31 case 4: return kVec4_Type; 30 case 4: return *kVec4_Type;
32 } 31 }
33 } else if (base == kDouble_Type) { 32 } else if (base == *kDouble_Type) {
34 switch (count) { 33 switch (count) {
35 case 2: return kDVec2_Type; 34 case 2: return *kDVec2_Type;
36 case 3: return kDVec3_Type; 35 case 3: return *kDVec3_Type;
37 case 4: return kDVec4_Type; 36 case 4: return *kDVec4_Type;
38 } 37 }
39 } else if (base == kInt_Type) { 38 } else if (base == *kInt_Type) {
40 switch (count) { 39 switch (count) {
41 case 2: return kIVec2_Type; 40 case 2: return *kIVec2_Type;
42 case 3: return kIVec3_Type; 41 case 3: return *kIVec3_Type;
43 case 4: return kIVec4_Type; 42 case 4: return *kIVec4_Type;
44 } 43 }
45 } else if (base == kUInt_Type) { 44 } else if (base == *kUInt_Type) {
46 switch (count) { 45 switch (count) {
47 case 2: return kUVec2_Type; 46 case 2: return *kUVec2_Type;
48 case 3: return kUVec3_Type; 47 case 3: return *kUVec3_Type;
49 case 4: return kUVec4_Type; 48 case 4: return *kUVec4_Type;
50 } 49 }
51 } else if (base == kBool_Type) { 50 } else if (base == *kBool_Type) {
52 switch (count) { 51 switch (count) {
53 case 2: return kBVec2_Type; 52 case 2: return *kBVec2_Type;
54 case 3: return kBVec3_Type; 53 case 3: return *kBVec3_Type;
55 case 4: return kBVec4_Type; 54 case 4: return *kBVec4_Type;
56 } 55 }
57 } 56 }
58 ABORT("cannot swizzle %s\n", value.description().c_str()); 57 ABORT("cannot swizzle %s\n", value.description().c_str());
59 } 58 }
60 59
61 /** 60 /**
62 * Represents a vector swizzle operation such as 'vec2(1, 2, 3).zyx'. 61 * Represents a vector swizzle operation such as 'vec2(1, 2, 3).zyx'.
63 */ 62 */
64 struct Swizzle : public Expression { 63 struct Swizzle : public Expression {
65 Swizzle(std::unique_ptr<Expression> base, std::vector<int> components) 64 Swizzle(std::unique_ptr<Expression> base, std::vector<int> components)
(...skipping 13 matching lines...) Expand all
79 78
80 const std::unique_ptr<Expression> fBase; 79 const std::unique_ptr<Expression> fBase;
81 const std::vector<int> fComponents; 80 const std::vector<int> fComponents;
82 81
83 typedef Expression INHERITED; 82 typedef Expression INHERITED;
84 }; 83 };
85 84
86 } // namespace 85 } // namespace
87 86
88 #endif 87 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698