1// Declare a user enum. 2enum class E { 3 kZero = 0, 4 kOne = 1, 5 kTwo = 2, 6 kThree = 3 7}; 8 9void main() { 10 // Test that the user enum is subject to the same optimizations as a plain int. 11 const E e = E::kZero; 12 if (e == E::kZero) { sk_FragColor = half4(1); } 13 @if (e == E::kZero) { sk_FragColor = half4(2); } 14 @if (e != E::kZero) { sk_FragColor = half4(3); } 15 if (e == E::kOne) { sk_FragColor = half4(4); } 16 @if (e == E::kOne) { sk_FragColor = half4(5); } 17 @if (e != E::kOne) { sk_FragColor = half4(6); } 18 19 sk_FragColor = (e == E::kZero) ? half4(7) : half4(-7); 20 sk_FragColor = (e != E::kZero) ? half4(8) : half4(-8); 21 sk_FragColor = (e == E::kOne) ? half4(9) : half4(-9); 22 sk_FragColor = (e != E::kOne) ? half4(10) : half4(-10); 23 24 switch (e) { 25 case E::kZero: sk_FragColor = half4(11); break; 26 case E::kOne: sk_FragColor = half4(12); break; 27 } 28 @switch (E::kZero) { 29 case E::kZero: sk_FragColor = half4(13); break; 30 case E::kOne: sk_FragColor = half4(14); break; 31 } 32 33 // Test that built-in enums work equally well. 34 const SkBlendMode m = SkBlendMode::kClear; 35 if (m == SkBlendMode::kClear) { sk_FragColor = half4(15); } 36 @if (m == SkBlendMode::kClear) { sk_FragColor = half4(16); } 37 if (m == SkBlendMode::kSrc) { sk_FragColor = half4(17); } 38 @if (m != SkBlendMode::kDst) { sk_FragColor = half4(18); } 39 40 sk_FragColor = (m == SkBlendMode::kClear) ? half4(19) : half4(-19); 41 sk_FragColor = (m != SkBlendMode::kSrc) ? half4(20) : half4(-20); 42 43 @switch (SkBlendMode::kClear) { 44 case SkBlendMode::kClear: sk_FragColor = half4(21); break; 45 case SkBlendMode::kSrc: sk_FragColor = half4(22); break; 46 case SkBlendMode::kDst: sk_FragColor = half4(23); break; 47 } 48 49 // Test with a non-const enum. 50 E f = E::kOne; 51 if (f == E::kOne) { sk_FragColor = half4(1); } 52 if (f != E::kOne) { sk_FragColor = half4(4); } 53 54 sk_FragColor = (f == E::kZero) ? half4(7) : half4(-7); 55 sk_FragColor = (f != E::kZero) ? half4(8) : half4(-8); 56 sk_FragColor = (f == E::kOne) ? half4(9) : half4(-9); 57 sk_FragColor = (f != E::kOne) ? half4(10) : half4(-10); 58 59 switch (f) { 60 case E::kZero: sk_FragColor = half4(11); break; 61 case E::kOne: sk_FragColor = half4(12); break; 62 } 63} 64