xref: /aosp_15_r20/external/skia/resources/sksl/intrinsics/ClampInt.sksl (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1*c8dee2aaSAndroid Build Coastguard Workeruniform half4 testInputs;
2*c8dee2aaSAndroid Build Coastguard Workeruniform half4 colorGreen, colorRed;
3*c8dee2aaSAndroid Build Coastguard Worker
4*c8dee2aaSAndroid Build Coastguard Workerhalf4 main(float2 coords) {
5*c8dee2aaSAndroid Build Coastguard Worker    int4 intValues       = int4(testInputs * 100);
6*c8dee2aaSAndroid Build Coastguard Worker
7*c8dee2aaSAndroid Build Coastguard Worker    int4 expectedA       = int4(-100,     0,  75, 100);
8*c8dee2aaSAndroid Build Coastguard Worker
9*c8dee2aaSAndroid Build Coastguard Worker    const int4 clampLow  = int4(-100, -200, -200, 100);
10*c8dee2aaSAndroid Build Coastguard Worker    const int4 constVal  = int4(-125,    0,   75, 225);
11*c8dee2aaSAndroid Build Coastguard Worker    int4 expectedB       = int4(-100,    0,   50, 225);
12*c8dee2aaSAndroid Build Coastguard Worker    const int4 clampHigh = int4( 100,  200,   50, 300);
13*c8dee2aaSAndroid Build Coastguard Worker
14*c8dee2aaSAndroid Build Coastguard Worker    return (clamp(intValues.x,    -100, 100)                      == expectedA.x     &&
15*c8dee2aaSAndroid Build Coastguard Worker            clamp(intValues.xy,   -100, 100)                      == expectedA.xy    &&
16*c8dee2aaSAndroid Build Coastguard Worker            clamp(intValues.xyz,  -100, 100)                      == expectedA.xyz   &&
17*c8dee2aaSAndroid Build Coastguard Worker            clamp(intValues.xyzw, -100, 100)                      == expectedA.xyzw  &&
18*c8dee2aaSAndroid Build Coastguard Worker            clamp(constVal.x,     -100, 100)                      == expectedA.x     &&
19*c8dee2aaSAndroid Build Coastguard Worker            clamp(constVal.xy,    -100, 100)                      == expectedA.xy    &&
20*c8dee2aaSAndroid Build Coastguard Worker            clamp(constVal.xyz,   -100, 100)                      == expectedA.xyz   &&
21*c8dee2aaSAndroid Build Coastguard Worker            clamp(constVal.xyzw,  -100, 100)                      == expectedA.xyzw  &&
22*c8dee2aaSAndroid Build Coastguard Worker            clamp(intValues.x,     clampLow.x,    clampHigh.x   ) == expectedB.x     &&
23*c8dee2aaSAndroid Build Coastguard Worker            clamp(intValues.xy,    clampLow.xy,   clampHigh.xy  ) == expectedB.xy    &&
24*c8dee2aaSAndroid Build Coastguard Worker            clamp(intValues.xyz,   clampLow.xyz,  clampHigh.xyz ) == expectedB.xyz   &&
25*c8dee2aaSAndroid Build Coastguard Worker            clamp(intValues.xyzw,  clampLow.xyzw, clampHigh.xyzw) == expectedB.xyzw  &&
26*c8dee2aaSAndroid Build Coastguard Worker            clamp(constVal.x,      clampLow.x,    clampHigh.x   ) == expectedB.x     &&
27*c8dee2aaSAndroid Build Coastguard Worker            clamp(constVal.xy,     clampLow.xy,   clampHigh.xy  ) == expectedB.xy    &&
28*c8dee2aaSAndroid Build Coastguard Worker            clamp(constVal.xyz,    clampLow.xyz,  clampHigh.xyz ) == expectedB.xyz   &&
29*c8dee2aaSAndroid Build Coastguard Worker            clamp(constVal.xyzw,   clampLow.xyzw, clampHigh.xyzw) == expectedB.xyzw) ? colorGreen
30*c8dee2aaSAndroid Build Coastguard Worker                                                                                     : colorRed;
31*c8dee2aaSAndroid Build Coastguard Worker}
32