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, 22 kIn_Flag = 2, 23 kOut_Flag = 4, 24 kLowp_Flag = 8, 25 kMediump_Flag = 16, 26 kHighp_Flag = 32, 27 kUniform_Flag = 64, 28 kFlat_Flag = 128, 29 kNoPerspective_Flag = 256, 30 kReadOnly_Flag = 512, 31 kWriteOnly_Flag = 1024, 32 kCoherent_Flag = 2048, 33 kVolatile_Flag = 4096, 34 kRestrict_Flag = 8192 35 }; 36 ModifiersModifiers37 Modifiers() 38 : fLayout(Layout()) 39 , fFlags(0) {} 40 ModifiersModifiers41 Modifiers(Layout& layout, int flags) 42 : fLayout(layout) 43 , fFlags(flags) {} 44 descriptionModifiers45 SkString description() const { 46 SkString result = fLayout.description(); 47 if (fFlags & kUniform_Flag) { 48 result += "uniform "; 49 } 50 if (fFlags & kConst_Flag) { 51 result += "const "; 52 } 53 if (fFlags & kLowp_Flag) { 54 result += "lowp "; 55 } 56 if (fFlags & kMediump_Flag) { 57 result += "mediump "; 58 } 59 if (fFlags & kHighp_Flag) { 60 result += "highp "; 61 } 62 if (fFlags & kFlat_Flag) { 63 result += "flat "; 64 } 65 if (fFlags & kNoPerspective_Flag) { 66 result += "noperspective "; 67 } 68 if (fFlags & kReadOnly_Flag) { 69 result += "readonly "; 70 } 71 if (fFlags & kWriteOnly_Flag) { 72 result += "writeonly "; 73 } 74 if (fFlags & kCoherent_Flag) { 75 result += "coherent "; 76 } 77 if (fFlags & kVolatile_Flag) { 78 result += "volatile "; 79 } 80 if (fFlags & kRestrict_Flag) { 81 result += "restrict "; 82 } 83 84 if ((fFlags & kIn_Flag) && (fFlags & kOut_Flag)) { 85 result += "inout "; 86 } else if (fFlags & kIn_Flag) { 87 result += "in "; 88 } else if (fFlags & kOut_Flag) { 89 result += "out "; 90 } 91 92 return result; 93 } 94 95 bool operator==(const Modifiers& other) const { 96 return fLayout == other.fLayout && fFlags == other.fFlags; 97 } 98 99 bool operator!=(const Modifiers& other) const { 100 return !(*this == other); 101 } 102 103 Layout fLayout; 104 int fFlags; 105 }; 106 107 } // namespace 108 109 #endif 110