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

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

Issue 2131223002: SkSL performance improvements (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: 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
« no previous file with comments | « src/sksl/ir/SkSLFunctionReference.h ('k') | src/sksl/ir/SkSLIntLiteral.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_INDEX 8 #ifndef SKSL_INDEX
9 #define SKSL_INDEX 9 #define SKSL_INDEX
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, returns the type that will result from extracting an array valu e from it. 17 * Given a type, returns the type that will result from extracting an array valu e from it.
18 */ 18 */
19 static std::shared_ptr<Type> index_type(const Type& type) { 19 static const Type& index_type(const Context& context, const Type& type) {
20 if (type.kind() == Type::kMatrix_Kind) { 20 if (type.kind() == Type::kMatrix_Kind) {
21 if (type.componentType() == kFloat_Type) { 21 if (type.componentType() == *context.fFloat_Type) {
22 switch (type.columns()) { 22 switch (type.columns()) {
23 case 2: return kVec2_Type; 23 case 2: return *context.fVec2_Type;
24 case 3: return kVec3_Type; 24 case 3: return *context.fVec3_Type;
25 case 4: return kVec4_Type; 25 case 4: return *context.fVec4_Type;
26 default: ASSERT(false); 26 default: ASSERT(false);
27 } 27 }
28 } else { 28 } else {
29 ASSERT(type.componentType() == kDouble_Type); 29 ASSERT(type.componentType() == *context.fDouble_Type);
30 switch (type.columns()) { 30 switch (type.columns()) {
31 case 2: return kDVec2_Type; 31 case 2: return *context.fDVec2_Type;
32 case 3: return kDVec3_Type; 32 case 3: return *context.fDVec3_Type;
33 case 4: return kDVec4_Type; 33 case 4: return *context.fDVec4_Type;
34 default: ASSERT(false); 34 default: ASSERT(false);
35 } 35 }
36 } 36 }
37 } 37 }
38 return type.componentType(); 38 return type.componentType();
39 } 39 }
40 40
41 /** 41 /**
42 * An expression which extracts a value from an array or matrix, as in 'm[2]'. 42 * An expression which extracts a value from an array or matrix, as in 'm[2]'.
43 */ 43 */
44 struct IndexExpression : public Expression { 44 struct IndexExpression : public Expression {
45 IndexExpression(std::unique_ptr<Expression> base, std::unique_ptr<Expression > index) 45 IndexExpression(const Context& context, std::unique_ptr<Expression> base,
46 : INHERITED(base->fPosition, kIndex_Kind, index_type(*base->fType)) 46 std::unique_ptr<Expression> index)
47 : INHERITED(base->fPosition, kIndex_Kind, index_type(context, base->fType))
47 , fBase(std::move(base)) 48 , fBase(std::move(base))
48 , fIndex(std::move(index)) { 49 , fIndex(std::move(index)) {
49 ASSERT(fIndex->fType == kInt_Type); 50 ASSERT(fIndex->fType == *context.fInt_Type);
50 } 51 }
51 52
52 std::string description() const override { 53 std::string description() const override {
53 return fBase->description() + "[" + fIndex->description() + "]"; 54 return fBase->description() + "[" + fIndex->description() + "]";
54 } 55 }
55 56
56 const std::unique_ptr<Expression> fBase; 57 const std::unique_ptr<Expression> fBase;
57 const std::unique_ptr<Expression> fIndex; 58 const std::unique_ptr<Expression> fIndex;
58 59
59 typedef Expression INHERITED; 60 typedef Expression INHERITED;
60 }; 61 };
61 62
62 } // namespace 63 } // namespace
63 64
64 #endif 65 #endif
OLDNEW
« no previous file with comments | « src/sksl/ir/SkSLFunctionReference.h ('k') | src/sksl/ir/SkSLIntLiteral.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698