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 "src/sksl/ir/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 kUniform_Flag = 1 << 3, 25 kFlat_Flag = 1 << 4, 26 kNoPerspective_Flag = 1 << 5, 27 kReadOnly_Flag = 1 << 6, 28 kWriteOnly_Flag = 1 << 7, 29 kCoherent_Flag = 1 << 8, 30 kVolatile_Flag = 1 << 9, 31 kRestrict_Flag = 1 << 10, 32 kBuffer_Flag = 1 << 11, 33 kHasSideEffects_Flag = 1 << 12, 34 kPLS_Flag = 1 << 13, 35 kPLSIn_Flag = 1 << 14, 36 kPLSOut_Flag = 1 << 15, 37 }; 38 ModifiersModifiers39 Modifiers() 40 : fLayout(Layout()) 41 , fFlags(0) {} 42 ModifiersModifiers43 Modifiers(const 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 & kFlat_Flag) { 56 result += "flat "; 57 } 58 if (fFlags & kNoPerspective_Flag) { 59 result += "noperspective "; 60 } 61 if (fFlags & kReadOnly_Flag) { 62 result += "readonly "; 63 } 64 if (fFlags & kWriteOnly_Flag) { 65 result += "writeonly "; 66 } 67 if (fFlags & kCoherent_Flag) { 68 result += "coherent "; 69 } 70 if (fFlags & kVolatile_Flag) { 71 result += "volatile "; 72 } 73 if (fFlags & kRestrict_Flag) { 74 result += "restrict "; 75 } 76 if (fFlags & kBuffer_Flag) { 77 result += "buffer "; 78 } 79 if (fFlags & kHasSideEffects_Flag) { 80 result += "sk_has_side_effects "; 81 } 82 if (fFlags & kPLS_Flag) { 83 result += "__pixel_localEXT "; 84 } 85 if (fFlags & kPLSIn_Flag) { 86 result += "__pixel_local_inEXT "; 87 } 88 if (fFlags & kPLSOut_Flag) { 89 result += "__pixel_local_outEXT "; 90 } 91 if ((fFlags & kIn_Flag) && (fFlags & kOut_Flag)) { 92 result += "inout "; 93 } else if (fFlags & kIn_Flag) { 94 result += "in "; 95 } else if (fFlags & kOut_Flag) { 96 result += "out "; 97 } 98 99 return result; 100 } 101 102 bool operator==(const Modifiers& other) const { 103 return fLayout == other.fLayout && fFlags == other.fFlags; 104 } 105 106 bool operator!=(const Modifiers& other) const { 107 return !(*this == other); 108 } 109 110 Layout fLayout; 111 int fFlags; 112 }; 113 114 } // namespace 115 116 #endif 117