| OLD | NEW |
| 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) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |