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 kPLS_Flag = 1 << 16, 38 kPLSIn_Flag = 1 << 17, 39 kPLSOut_Flag = 1 << 18, 40 }; 41 ModifiersModifiers42 Modifiers() 43 : fLayout(Layout()) 44 , fFlags(0) {} 45 ModifiersModifiers46 Modifiers(const Layout& layout, int flags) 47 : fLayout(layout) 48 , fFlags(flags) {} 49 descriptionModifiers50 String description() const { 51 String result = fLayout.description(); 52 if (fFlags & kUniform_Flag) { 53 result += "uniform "; 54 } 55 if (fFlags & kConst_Flag) { 56 result += "const "; 57 } 58 if (fFlags & kLowp_Flag) { 59 result += "lowp "; 60 } 61 if (fFlags & kMediump_Flag) { 62 result += "mediump "; 63 } 64 if (fFlags & kHighp_Flag) { 65 result += "highp "; 66 } 67 if (fFlags & kFlat_Flag) { 68 result += "flat "; 69 } 70 if (fFlags & kNoPerspective_Flag) { 71 result += "noperspective "; 72 } 73 if (fFlags & kReadOnly_Flag) { 74 result += "readonly "; 75 } 76 if (fFlags & kWriteOnly_Flag) { 77 result += "writeonly "; 78 } 79 if (fFlags & kCoherent_Flag) { 80 result += "coherent "; 81 } 82 if (fFlags & kVolatile_Flag) { 83 result += "volatile "; 84 } 85 if (fFlags & kRestrict_Flag) { 86 result += "restrict "; 87 } 88 if (fFlags & kBuffer_Flag) { 89 result += "buffer "; 90 } 91 if (fFlags & kHasSideEffects_Flag) { 92 result += "sk_has_side_effects "; 93 } 94 if (fFlags & kPLS_Flag) { 95 result += "__pixel_localEXT "; 96 } 97 if (fFlags & kPLSIn_Flag) { 98 result += "__pixel_local_inEXT "; 99 } 100 if (fFlags & kPLSOut_Flag) { 101 result += "__pixel_local_outEXT "; 102 } 103 if ((fFlags & kIn_Flag) && (fFlags & kOut_Flag)) { 104 result += "inout "; 105 } else if (fFlags & kIn_Flag) { 106 result += "in "; 107 } else if (fFlags & kOut_Flag) { 108 result += "out "; 109 } 110 111 return result; 112 } 113 114 bool operator==(const Modifiers& other) const { 115 return fLayout == other.fLayout && fFlags == other.fFlags; 116 } 117 118 bool operator!=(const Modifiers& other) const { 119 return !(*this == other); 120 } 121 122 Layout fLayout; 123 int fFlags; 124 }; 125 126 } // namespace 127 128 #endif 129