Ethan Nicholas | 8f7e28f | 2018-03-26 14:24:27 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/sksl/ir/SkSLVariableReference.h" |
Ethan Nicholas | 8f7e28f | 2018-03-26 14:24:27 -0400 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "src/sksl/SkSLIRGenerator.h" |
| 11 | #include "src/sksl/ir/SkSLConstructor.h" |
John Stiles | 7591d4b | 2021-09-13 13:32:06 -0400 | [diff] [blame] | 12 | #include "src/sksl/ir/SkSLLiteral.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/sksl/ir/SkSLSetting.h" |
Ethan Nicholas | 8f7e28f | 2018-03-26 14:24:27 -0400 | [diff] [blame] | 14 | |
| 15 | namespace SkSL { |
| 16 | |
Brian Osman | cc91452 | 2021-09-24 18:58:37 +0000 | [diff] [blame] | 17 | VariableReference::VariableReference(int offset, const Variable* variable, RefKind refKind) |
| 18 | : INHERITED(offset, kExpressionKind, &variable->type()) |
John Stiles | 2d4f959 | 2020-10-30 10:29:12 -0400 | [diff] [blame] | 19 | , fVariable(variable) |
| 20 | , fRefKind(refKind) { |
Ethan Nicholas | 7868692 | 2020-10-08 06:46:27 -0400 | [diff] [blame] | 21 | SkASSERT(this->variable()); |
Ethan Nicholas | 7868692 | 2020-10-08 06:46:27 -0400 | [diff] [blame] | 22 | } |
| 23 | |
Ethan Nicholas | 041fd0a | 2020-10-07 16:42:04 -0400 | [diff] [blame] | 24 | bool VariableReference::hasProperty(Property property) const { |
| 25 | switch (property) { |
| 26 | case Property::kSideEffects: return false; |
Ethan Nicholas | 7868692 | 2020-10-08 06:46:27 -0400 | [diff] [blame] | 27 | case Property::kContainsRTAdjust: return this->variable()->name() == "sk_RTAdjust"; |
Ethan Nicholas | 041fd0a | 2020-10-07 16:42:04 -0400 | [diff] [blame] | 28 | default: |
| 29 | SkASSERT(false); |
| 30 | return false; |
Ethan Nicholas | 8f7e28f | 2018-03-26 14:24:27 -0400 | [diff] [blame] | 31 | } |
| 32 | } |
| 33 | |
Ethan Nicholas | 041fd0a | 2020-10-07 16:42:04 -0400 | [diff] [blame] | 34 | bool VariableReference::isConstantOrUniform() const { |
Ethan Nicholas | 7868692 | 2020-10-08 06:46:27 -0400 | [diff] [blame] | 35 | return (this->variable()->modifiers().fFlags & Modifiers::kUniform_Flag) != 0; |
Ethan Nicholas | 041fd0a | 2020-10-07 16:42:04 -0400 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | String VariableReference::description() const { |
Ethan Nicholas | d2e0960 | 2021-06-10 11:21:59 -0400 | [diff] [blame] | 39 | return String(this->variable()->name()); |
Ethan Nicholas | 8f7e28f | 2018-03-26 14:24:27 -0400 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void VariableReference::setRefKind(RefKind refKind) { |
John Stiles | 2d4f959 | 2020-10-30 10:29:12 -0400 | [diff] [blame] | 43 | fRefKind = refKind; |
Ethan Nicholas | 8f7e28f | 2018-03-26 14:24:27 -0400 | [diff] [blame] | 44 | } |
| 45 | |
Brian Osman | 8e2ef02 | 2020-09-30 13:26:43 -0400 | [diff] [blame] | 46 | void VariableReference::setVariable(const Variable* variable) { |
John Stiles | 2d4f959 | 2020-10-30 10:29:12 -0400 | [diff] [blame] | 47 | fVariable = variable; |
Brian Osman | 8e2ef02 | 2020-09-30 13:26:43 -0400 | [diff] [blame] | 48 | } |
| 49 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 50 | } // namespace SkSL |