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 half4x4 gradientMatrix; 9 10@coordTransform { 11 gradientMatrix 12} 13 14void main() { 15 half t = sk_TransformedCoords2D[0].x; 16 sk_OutColor = half4(t, 1, 0, 0); // y = 1 for always valid 17} 18 19////////////////////////////////////////////////////////////////////////////// 20 21@header { 22 #include "SkLinearGradient.h" 23 #include "GrGradientShader.h" 24} 25 26// The linear gradient never rejects a pixel so it doesn't change opacity 27@optimizationFlags { 28 kPreservesOpaqueInput_OptimizationFlag 29} 30 31@make { 32 static std::unique_ptr<GrFragmentProcessor> Make(const SkLinearGradient& gradient, 33 const GrFPArgs& args); 34} 35 36@cppEnd { 37 std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::Make( 38 const SkLinearGradient& grad, const GrFPArgs& args) { 39 SkMatrix matrix; 40 if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) { 41 return nullptr; 42 } 43 matrix.postConcat(grad.getGradientMatrix()); 44 return std::unique_ptr<GrFragmentProcessor>(new GrLinearGradientLayout(matrix)); 45 } 46} 47 48////////////////////////////////////////////////////////////////////////////// 49 50@test(d) { 51 SkScalar scale = GrGradientShader::RandomParams::kGradientScale; 52 SkPoint points[] = {{d->fRandom->nextRangeScalar(0.0f, scale), 53 d->fRandom->nextRangeScalar(0.0f, scale)}, 54 {d->fRandom->nextRangeScalar(0.0f, scale), 55 d->fRandom->nextRangeScalar(0.0f, scale)}}; 56 57 GrGradientShader::RandomParams params(d->fRandom); 58 auto shader = params.fUseColors4f ? 59 SkGradientShader::MakeLinear(points, params.fColors4f, params.fColorSpace, params.fStops, 60 params.fColorCount, params.fTileMode) : 61 SkGradientShader::MakeLinear(points, params.fColors, params.fStops, 62 params.fColorCount, params.fTileMode); 63 GrTest::TestAsFPArgs asFPArgs(d); 64 std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args()); 65 GrAlwaysAssert(fp); 66 return fp; 67} 68