xref: /aosp_15_r20/external/skia/resources/sksl/shared/SwitchWithLoops.sksl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1/*#pragma settings RewriteSwitchStatements*/
2
3uniform half4 colorGreen, colorRed;
4
5bool switch_with_break_in_loop(int x) {
6    int val = 0;
7    switch (x) {
8        case 1:  for (int i=0; i<10; ++i) { ++val; break; ++val; }
9        default: ++val;
10    }
11    return val == 2;
12}
13
14bool switch_with_continue_in_loop(int x) {
15    int val = 0;
16    switch (x) {
17        case 1:  for (int i=0; i<10; ++i) { ++val; continue; ++val; }
18        default: ++val;
19    }
20    return val == 11;
21}
22
23bool loop_with_break_in_switch(int x) {
24    int val = 0;
25    for (int i=0; i<10; ++i) {
26        switch (x) {
27            case 1:  ++val; break;
28            default: return false;
29        }
30        ++val;
31    }
32    return val == 20;
33}
34
35half4 main(float2 coords) {
36    int x = int(colorGreen.g);
37    return (switch_with_break_in_loop(x) &&
38            switch_with_continue_in_loop(x) &&
39            loop_with_break_in_switch(x)) ? colorGreen : colorRed;
40}
41