Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 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 | |
| 8 | in half4x4 gradientMatrix; |
| 9 | |
| 10 | @coordTransform { |
| 11 | gradientMatrix |
| 12 | } |
| 13 | |
| 14 | void main() { |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 15 | half t = sk_TransformedCoords2D[0].x; |
| 16 | sk_OutColor = half4(t, 1, 0, 0); // y = 1 for always valid |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | ////////////////////////////////////////////////////////////////////////////// |
| 20 | |
| 21 | @header { |
| 22 | #include "SkLinearGradient.h" |
| 23 | } |
| 24 | |
Michael Ludwig | b96cba3 | 2018-09-14 13:59:24 -0400 | [diff] [blame^] | 25 | // The linear gradient never rejects a pixel so it doesn't change opacity |
| 26 | @optimizationFlags { |
| 27 | kPreservesOpaqueInput_OptimizationFlag |
| 28 | } |
| 29 | |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 30 | @make { |
| 31 | static std::unique_ptr<GrFragmentProcessor> Make(const SkLinearGradient& gradient, |
| 32 | const GrFPArgs& args); |
| 33 | } |
| 34 | |
| 35 | @cppEnd { |
| 36 | std::unique_ptr<GrFragmentProcessor> GrLinearGradientLayout::Make( |
| 37 | const SkLinearGradient& grad, const GrFPArgs& args) { |
| 38 | SkMatrix matrix; |
| 39 | if (!grad.totalLocalMatrix(args.fPreLocalMatrix, args.fPostLocalMatrix)->invert(&matrix)) { |
| 40 | return nullptr; |
| 41 | } |
| 42 | matrix.postConcat(grad.getGradientMatrix()); |
| 43 | return std::unique_ptr<GrFragmentProcessor>(new GrLinearGradientLayout(matrix)); |
| 44 | } |
| 45 | } |