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 = half(length(sk_TransformedCoords2D[0])); 16 sk_OutColor = half4(t, 1, 0, 0); // y = 1 for always valid 17} 18 19////////////////////////////////////////////////////////////////////////////// 20 21@header { 22 #include "SkRadialGradient.h" 23 #include "GrGradientShader.h" 24} 25 26// The radial 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 SkRadialGradient& gradient, 33 const GrFPArgs& args); 34} 35 36@cppEnd { 37 std::unique_ptr<GrFragmentProcessor> GrRadialGradientLayout::Make( 38 const SkRadialGradient& 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 GrRadialGradientLayout(matrix)); 45 } 46} 47 48////////////////////////////////////////////////////////////////////////////// 49 50@test(d) { 51 SkScalar scale = GrGradientShader::RandomParams::kGradientScale; 52 sk_sp<SkShader> shader; 53 do { 54 GrGradientShader::RandomParams params(d->fRandom); 55 SkPoint center = {d->fRandom->nextRangeScalar(0.0f, scale), 56 d->fRandom->nextRangeScalar(0.0f, scale)}; 57 SkScalar radius = d->fRandom->nextRangeScalar(0.0f, scale); 58 shader = params.fUseColors4f 59 ? SkGradientShader::MakeRadial(center, radius, params.fColors4f, 60 params.fColorSpace, params.fStops, 61 params.fColorCount, params.fTileMode) 62 : SkGradientShader::MakeRadial(center, radius, params.fColors, 63 params.fStops, params.fColorCount, 64 params.fTileMode); 65 } while (!shader); 66 GrTest::TestAsFPArgs asFPArgs(d); 67 std::unique_ptr<GrFragmentProcessor> fp = as_SB(shader)->asFragmentProcessor(asFPArgs.args()); 68 GrAlwaysAssert(fp); 69 return fp; 70} 71