skia2/resources/sksl/shared/Enum.sksl
Brian Osman 3e4ef49890 Remove SkBlendMode from SkSL
We've lived without this for a long time. It bloats sksl_gpu (inhibits
some inlining!), and if things go according to plan, we'll be removing
enum support from SkSL entirely soon.

Change-Id: If844bbe5fdae41df7930d5c8ea9b832f9dd1b922
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/419099
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
2021-06-16 21:01:30 +00:00

48 lines
1.6 KiB
Plaintext

// Declare a user enum.
enum class E {
kZero = 0,
kOne = 1,
kTwo = 2,
kThree = 3
};
void main() {
// Test that the user enum is subject to the same optimizations as a plain int.
const E e = E::kZero;
if (e == E::kZero) { sk_FragColor = half4(1); }
@if (e == E::kZero) { sk_FragColor = half4(2); }
@if (e != E::kZero) { sk_FragColor = half4(3); }
if (e == E::kOne) { sk_FragColor = half4(4); }
@if (e == E::kOne) { sk_FragColor = half4(5); }
@if (e != E::kOne) { sk_FragColor = half4(6); }
sk_FragColor = (e == E::kZero) ? half4(7) : half4(-7);
sk_FragColor = (e != E::kZero) ? half4(8) : half4(-8);
sk_FragColor = (e == E::kOne) ? half4(9) : half4(-9);
sk_FragColor = (e != E::kOne) ? half4(10) : half4(-10);
switch (e) {
case E::kZero: sk_FragColor = half4(11); break;
case E::kOne: sk_FragColor = half4(12); break;
}
@switch (E::kZero) {
case E::kZero: sk_FragColor = half4(13); break;
case E::kOne: sk_FragColor = half4(14); break;
}
// Test with a non-const enum.
E f = E::kOne;
if (f == E::kOne) { sk_FragColor = half4(1); }
if (f != E::kOne) { sk_FragColor = half4(4); }
sk_FragColor = (f == E::kZero) ? half4(7) : half4(-7);
sk_FragColor = (f != E::kZero) ? half4(8) : half4(-8);
sk_FragColor = (f == E::kOne) ? half4(9) : half4(-9);
sk_FragColor = (f != E::kOne) ? half4(10) : half4(-10);
switch (f) {
case E::kZero: sk_FragColor = half4(11); break;
case E::kOne: sk_FragColor = half4(12); break;
}
}