skia2/resources/sksl/shared/Enum.sksl
John Stiles bfc9be0f77 Migrate SkSL test inputs to the resources/ directory.
This will allow us to load these inputs for unit testing in `dm`.

Change-Id: Id256ba7c30d3ec94b98048e47af44cf9efe580d5
Bug: skia:11009
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/357282
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2021-01-22 18:57:29 +00:00

49 lines
1.8 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.
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) {
case E::kZero: sk_FragColor = half4(13); break;
case E::kOne: sk_FragColor = half4(14); break;
}
// Test that built-in enums work equally well.
SkBlendMode m = SkBlendMode::kClear;
if (m == SkBlendMode::kClear) { sk_FragColor = half4(15); }
@if (m == SkBlendMode::kClear) { sk_FragColor = half4(16); }
if (m == SkBlendMode::kSrc) { sk_FragColor = half4(17); }
@if (m != SkBlendMode::kDst) { sk_FragColor = half4(18); }
sk_FragColor = (m == SkBlendMode::kClear) ? half4(19) : half4(-19);
sk_FragColor = (m != SkBlendMode::kSrc) ? half4(20) : half4(-20);
@switch (m) {
case SkBlendMode::kClear: sk_FragColor = half4(21); break;
case SkBlendMode::kSrc: sk_FragColor = half4(22); break;
case SkBlendMode::kDst: sk_FragColor = half4(23); break;
}
}