| ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
| 8 | #ifndef SKSL_ASTLAYOUT |
| 9 | #define SKSL_ASTLAYOUT |
| 10 | |
| 11 | #include "SkSLASTNode.h" |
| 12 | #include "SkSLUtil.h" |
| 13 | |
| 14 | namespace SkSL { |
| 15 | |
| 16 | /** |
| 17 | * Represents a layout block appearing before a variable declaration, as in: |
| 18 | * |
| 19 | * layout (location = 0) int x; |
| 20 | */ |
| 21 | struct ASTLayout : public ASTNode { |
| 22 | // For all parameters, a -1 means no value |
| ethannicholas | dcfe6db | 2016-10-10 10:09:00 -0700 | [diff] [blame^] | 23 | ASTLayout(int location, int binding, int index, int set, int builtin, bool originUpperLeft, |
| 24 | bool overrideCoverage, bool blendSupportAllEquations) |
| ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 25 | : fLocation(location) |
| 26 | , fBinding(binding) |
| 27 | , fIndex(index) |
| 28 | , fSet(set) |
| ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 29 | , fBuiltin(builtin) |
| ethannicholas | dcfe6db | 2016-10-10 10:09:00 -0700 | [diff] [blame^] | 30 | , fOriginUpperLeft(originUpperLeft) |
| 31 | , fOverrideCoverage(overrideCoverage) |
| 32 | , fBlendSupportAllEquations(blendSupportAllEquations) {} |
| ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 33 | |
| 34 | std::string description() const { |
| 35 | std::string result; |
| 36 | std::string separator; |
| 37 | if (fLocation >= 0) { |
| 38 | result += separator + "location = " + to_string(fLocation); |
| 39 | separator = ", "; |
| 40 | } |
| 41 | if (fBinding >= 0) { |
| 42 | result += separator + "binding = " + to_string(fBinding); |
| 43 | separator = ", "; |
| 44 | } |
| 45 | if (fIndex >= 0) { |
| 46 | result += separator + "index = " + to_string(fIndex); |
| 47 | separator = ", "; |
| 48 | } |
| 49 | if (fSet >= 0) { |
| 50 | result += separator + "set = " + to_string(fSet); |
| 51 | separator = ", "; |
| 52 | } |
| 53 | if (fBuiltin >= 0) { |
| 54 | result += separator + "builtin = " + to_string(fBuiltin); |
| 55 | separator = ", "; |
| 56 | } |
| ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 57 | if (fOriginUpperLeft) { |
| 58 | result += separator + "origin_upper_left"; |
| 59 | separator = ", "; |
| 60 | } |
| ethannicholas | dcfe6db | 2016-10-10 10:09:00 -0700 | [diff] [blame^] | 61 | if (fOverrideCoverage) { |
| 62 | result += separator + "override_coverage"; |
| 63 | separator = ", "; |
| 64 | } |
| 65 | if (fBlendSupportAllEquations) { |
| 66 | result += separator + "blend_support_all_equations"; |
| 67 | separator = ", "; |
| 68 | } |
| ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 69 | if (result.length() > 0) { |
| 70 | result = "layout (" + result + ")"; |
| 71 | } |
| 72 | return result; |
| 73 | } |
| 74 | |
| 75 | const int fLocation; |
| 76 | const int fBinding; |
| 77 | const int fIndex; |
| 78 | const int fSet; |
| 79 | const int fBuiltin; |
| ethannicholas | f789b38 | 2016-08-03 12:43:36 -0700 | [diff] [blame] | 80 | const bool fOriginUpperLeft; |
| ethannicholas | dcfe6db | 2016-10-10 10:09:00 -0700 | [diff] [blame^] | 81 | const bool fOverrideCoverage; |
| 82 | const bool fBlendSupportAllEquations; |
| ethannicholas | b3058bd | 2016-07-01 08:22:01 -0700 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | } // namespace |
| 86 | |
| 87 | #endif |