1/* 2 * Copyright 2018 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8in fragmentProcessor inputFP; 9in fragmentProcessor maskFP; 10in uniform half innerThreshold; 11in uniform half outerThreshold; 12 13@optimizationFlags { 14 ProcessorOptimizationFlags(inputFP.get()) & 15 ((outerThreshold >= 1.0) ? kPreservesOpaqueInput_OptimizationFlag : kNone_OptimizationFlags) 16} 17 18half4 main() { 19 half4 color = sample(inputFP); 20 half4 mask_color = sample(maskFP); 21 if (mask_color.a < 0.5) { 22 if (color.a > outerThreshold) { 23 half scale = outerThreshold / color.a; 24 color.rgb *= scale; 25 color.a = outerThreshold; 26 } 27 } else if (color.a < innerThreshold) { 28 half scale = innerThreshold / max(0.001, color.a); 29 color.rgb *= scale; 30 color.a = innerThreshold; 31 } 32 return color; 33} 34 35@test(testData) { 36 // Make the inner and outer thresholds be in [0, 1]. 37 float outerThresh = testData->fRandom->nextUScalar1(); 38 float innerThresh = testData->fRandom->nextUScalar1(); 39 std::unique_ptr<GrFragmentProcessor> inputChild, maskChild; 40 if (testData->fRandom->nextBool()) { 41 inputChild = GrProcessorUnitTest::MakeChildFP(testData); 42 } 43 maskChild = GrProcessorUnitTest::MakeChildFP(testData); 44 45 return GrAlphaThresholdFragmentProcessor::Make(std::move(inputChild), std::move(maskChild), 46 innerThresh, outerThresh); 47} 48