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_MODIFIERS 9 #define SKSL_MODIFIERS 10 11 #include "SkSLLayout.h" 12 13 namespace SkSL { 14 15 /** 16 * A set of modifier keywords (in, out, uniform, etc.) appearing before a declaration. 17 */ 18 struct Modifiers { 19 enum Flag { 20 kNo_Flag = 0, 21 kConst_Flag = 1 << 0, 22 kIn_Flag = 1 << 1, 23 kOut_Flag = 1 << 2, 24 kLowp_Flag = 1 << 3, 25 kMediump_Flag = 1 << 4, 26 kHighp_Flag = 1 << 5, 27 kUniform_Flag = 1 << 6, 28 kFlat_Flag = 1 << 7, 29 kNoPerspective_Flag = 1 << 8, 30 kReadOnly_Flag = 1 << 9, 31 kWriteOnly_Flag = 1 << 10, 32 kCoherent_Flag = 1 << 11, 33 kVolatile_Flag = 1 << 12, 34 kRestrict_Flag = 1 << 13, 35 kBuffer_Flag = 1 << 14, 36 kHasSideEffects_Flag = 1 << 15 37 }; 38 ModifiersModifiers39 Modifiers() 40 : fLayout(Layout()) 41 , fFlags(0) {} 42 ModifiersModifiers43 Modifiers(Layout& layout, int flags) 44 : fLayout(layout) 45 , fFlags(flags) {} 46 descriptionModifiers47 String description() const { 48 String result = fLayout.description(); 49 if (fFlags & kUniform_Flag) { 50 result += "uniform "; 51 } 52 if (fFlags & kConst_Flag) { 53 result += "const "; 54 } 55 if (fFlags & kLowp_Flag) { 56 result += "lowp "; 57 } 58 if (fFlags & kMediump_Flag) { 59 result += "mediump "; 60 } 61 if (fFlags & kHighp_Flag) { 62 result += "highp "; 63 } 64 if (fFlags & kFlat_Flag) { 65 result += "flat "; 66 } 67 if (fFlags & kNoPerspective_Flag) { 68 result += "noperspective "; 69 } 70 if (fFlags & kReadOnly_Flag) { 71 result += "readonly "; 72 } 73 if (fFlags & kWriteOnly_Flag) { 74 result += "writeonly "; 75 } 76 if (fFlags & kCoherent_Flag) { 77 result += "coherent "; 78 } 79 if (fFlags & kVolatile_Flag) { 80 result += "volatile "; 81 } 82 if (fFlags & kRestrict_Flag) { 83 result += "restrict "; 84 } 85 if (fFlags & kBuffer_Flag) { 86 result += "buffer "; 87 } 88 if (fFlags & kHasSideEffects_Flag) { 89 result += "sk_has_side_effects "; 90 } 91 92 if ((fFlags & kIn_Flag) && (fFlags & kOut_Flag)) { 93 result += "inout "; 94 } else if (fFlags & kIn_Flag) { 95 result += "in "; 96 } else if (fFlags & kOut_Flag) { 97 result += "out "; 98 } 99 100 return result; 101 } 102 103 bool operator==(const Modifiers& other) const { 104 return fLayout == other.fLayout && fFlags == other.fFlags; 105 } 106 107 bool operator!=(const Modifiers& other) const { 108 return !(*this == other); 109 } 110 111 Layout fLayout; 112 int fFlags; 113 }; 114 115 } // namespace 116 117 #endif 118