Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 Google LLC |
| 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 | |
| 8 | #include "include/private/SkSLSampleUsage.h" |
| 9 | |
| 10 | #include "src/sksl/ir/SkSLBinaryExpression.h" |
| 11 | #include "src/sksl/ir/SkSLConstructor.h" |
| 12 | #include "src/sksl/ir/SkSLDoStatement.h" |
| 13 | #include "src/sksl/ir/SkSLExpression.h" |
| 14 | #include "src/sksl/ir/SkSLExpressionStatement.h" |
| 15 | #include "src/sksl/ir/SkSLFieldAccess.h" |
| 16 | #include "src/sksl/ir/SkSLForStatement.h" |
| 17 | #include "src/sksl/ir/SkSLFunctionCall.h" |
| 18 | #include "src/sksl/ir/SkSLIfStatement.h" |
| 19 | #include "src/sksl/ir/SkSLIndexExpression.h" |
| 20 | #include "src/sksl/ir/SkSLPostfixExpression.h" |
| 21 | #include "src/sksl/ir/SkSLPrefixExpression.h" |
| 22 | #include "src/sksl/ir/SkSLProgram.h" |
| 23 | #include "src/sksl/ir/SkSLReturnStatement.h" |
| 24 | #include "src/sksl/ir/SkSLSwitchStatement.h" |
| 25 | #include "src/sksl/ir/SkSLSwizzle.h" |
| 26 | #include "src/sksl/ir/SkSLTernaryExpression.h" |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 27 | #include "src/sksl/ir/SkSLVariable.h" |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 28 | |
| 29 | namespace SkSL { |
| 30 | |
| 31 | SampleUsage SampleUsage::merge(const SampleUsage& other) { |
Brian Osman | 83dae92 | 2021-04-28 10:44:06 -0400 | [diff] [blame^] | 32 | // This function is only used when processing SkSL, to determine the combined SampleUsage for |
| 33 | // a child fp/shader/etc. We should never see matrix sampling here. |
| 34 | SkASSERT(fKind != Kind::kUniformMatrix && other.fKind != Kind::kUniformMatrix); |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 35 | |
Brian Osman | 83dae92 | 2021-04-28 10:44:06 -0400 | [diff] [blame^] | 36 | static_assert(Kind::kExplicit > Kind::kPassThrough); |
| 37 | static_assert(Kind::kPassThrough > Kind::kNone); |
| 38 | fKind = std::max(fKind, other.fKind); |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 39 | |
| 40 | return *this; |
| 41 | } |
| 42 | |
Brian Osman | 83dae92 | 2021-04-28 10:44:06 -0400 | [diff] [blame^] | 43 | std::string SampleUsage::constructor() const { |
| 44 | // This function is only used when processing SkSL. We should never see matrix sampling here. |
| 45 | SkASSERT(fKind != Kind::kUniformMatrix); |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 46 | |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 47 | switch (fKind) { |
Brian Osman | 83dae92 | 2021-04-28 10:44:06 -0400 | [diff] [blame^] | 48 | case Kind::kNone: return "SkSL::SampleUsage()"; |
| 49 | case Kind::kPassThrough: return "SkSL::SampleUsage::PassThrough()"; |
| 50 | case Kind::kExplicit: return "SkSL::SampleUsage::Explicit()"; |
| 51 | default: SkUNREACHABLE; |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 52 | } |
Brian Osman | 1298bc4 | 2020-06-30 13:39:35 -0400 | [diff] [blame] | 53 | } |
| 54 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 55 | } // namespace SkSL |