xref: /aosp_15_r20/external/skia/resources/sksl/shared/PostfixExpressions.sksl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1uniform half4 colorGreen, colorRed;
2
3half4 main(float2 c) {
4    bool ok = true;
5
6    // Postfix ++ and -- (scalar int).
7    int i = 5;
8    i++;
9    ok = ok && (i++ == 6);
10    ok = ok && (i == 7);
11    ok = ok && (i-- == 7);
12    ok = ok && (i == 6);
13    i--;
14    ok = ok && (i == 5);
15
16    // Postfix ++ and -- (scalar float).
17    float f = 0.5;
18    f++;
19    ok = ok && (f++ == 1.5);
20    ok = ok && (f == 2.5);
21    ok = ok && (f-- == 2.5);
22    ok = ok && (f == 1.5);
23    f--;
24    ok = ok && (f == 0.5);
25
26    // Postfix ++ and -- (vector-component float).
27    float2 f2 = float2(0.5);
28    f2.x++;
29    ok = ok && (f2.x++ == 1.5);
30    ok = ok && (f2.x == 2.5);
31    ok = ok && (f2.x-- == 2.5);
32    ok = ok && (f2.x == 1.5);
33    f2.x--;
34    ok = ok && (f2.x == 0.5);
35
36    // Postfix ++ and -- (vector float).
37    f2++;
38    ok = ok && (f2++ == float2(1.5));
39    ok = ok && (f2 == float2(2.5));
40    ok = ok && (f2-- == float2(2.5));
41    ok = ok && (f2 == float2(1.5));
42    f2--;
43    ok = ok && (f2 == float2(0.5));
44
45    // Postfix ++ and -- (vector int).
46    int4 i4 = int4(7, 8, 9, 10);
47    i4++;
48    ok = ok && (i4++ == int4(8, 9, 10, 11));
49    ok = ok && (i4 == int4(9, 10, 11, 12));
50    ok = ok && (i4-- == int4(9, 10, 11, 12));
51    ok = ok && (i4 == int4(8, 9, 10, 11));
52    i4--;
53    ok = ok && (i4 == int4(7, 8, 9, 10));
54
55    // Postfix ++ and -- (matrix).
56    float3x3 m3x3 = float3x3(1, 2, 3, 4, 5, 6, 7, 8, 9);
57    m3x3++;
58    ok = ok && (m3x3++ == float3x3(2, 3, 4, 5, 6, 7, 8, 9, 10));
59    ok = ok && (m3x3 == float3x3(3, 4, 5, 6, 7, 8, 9, 10, 11));
60    ok = ok && (m3x3-- == float3x3(3, 4, 5, 6, 7, 8, 9, 10, 11));
61    ok = ok && (m3x3 == float3x3(2, 3, 4, 5, 6, 7, 8, 9, 10));
62    m3x3--;
63    ok = ok && (m3x3 == float3x3(1, 2, 3, 4, 5, 6, 7, 8, 9));
64
65    return ok ? colorGreen : colorRed;
66}
67