blob: 411452c3e945a123212e6f24b6baf0eafca05038 [file] [log] [blame]
Ethan Nicholas8f7e28f2018-03-26 14:24:27 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/sksl/ir/SkSLVariableReference.h"
Ethan Nicholas8f7e28f2018-03-26 14:24:27 -04009
Mike Kleinc0bd9f92019-04-23 12:05:21 -050010#include "src/sksl/SkSLIRGenerator.h"
11#include "src/sksl/ir/SkSLConstructor.h"
John Stiles7591d4b2021-09-13 13:32:06 -040012#include "src/sksl/ir/SkSLLiteral.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "src/sksl/ir/SkSLSetting.h"
Ethan Nicholas8f7e28f2018-03-26 14:24:27 -040014
15namespace SkSL {
16
Brian Osmancc914522021-09-24 18:58:37 +000017VariableReference::VariableReference(int offset, const Variable* variable, RefKind refKind)
18 : INHERITED(offset, kExpressionKind, &variable->type())
John Stiles2d4f9592020-10-30 10:29:12 -040019 , fVariable(variable)
20 , fRefKind(refKind) {
Ethan Nicholas78686922020-10-08 06:46:27 -040021 SkASSERT(this->variable());
Ethan Nicholas78686922020-10-08 06:46:27 -040022}
23
Ethan Nicholas041fd0a2020-10-07 16:42:04 -040024bool VariableReference::hasProperty(Property property) const {
25 switch (property) {
26 case Property::kSideEffects: return false;
Ethan Nicholas78686922020-10-08 06:46:27 -040027 case Property::kContainsRTAdjust: return this->variable()->name() == "sk_RTAdjust";
Ethan Nicholas041fd0a2020-10-07 16:42:04 -040028 default:
29 SkASSERT(false);
30 return false;
Ethan Nicholas8f7e28f2018-03-26 14:24:27 -040031 }
32}
33
Ethan Nicholas041fd0a2020-10-07 16:42:04 -040034bool VariableReference::isConstantOrUniform() const {
Ethan Nicholas78686922020-10-08 06:46:27 -040035 return (this->variable()->modifiers().fFlags & Modifiers::kUniform_Flag) != 0;
Ethan Nicholas041fd0a2020-10-07 16:42:04 -040036}
37
38String VariableReference::description() const {
Ethan Nicholasd2e09602021-06-10 11:21:59 -040039 return String(this->variable()->name());
Ethan Nicholas8f7e28f2018-03-26 14:24:27 -040040}
41
42void VariableReference::setRefKind(RefKind refKind) {
John Stiles2d4f9592020-10-30 10:29:12 -040043 fRefKind = refKind;
Ethan Nicholas8f7e28f2018-03-26 14:24:27 -040044}
45
Brian Osman8e2ef022020-09-30 13:26:43 -040046void VariableReference::setVariable(const Variable* variable) {
John Stiles2d4f9592020-10-30 10:29:12 -040047 fVariable = variable;
Brian Osman8e2ef022020-09-30 13:26:43 -040048}
49
John Stilesa6841be2020-08-06 14:11:56 -040050} // namespace SkSL