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 | #ifndef GrGradientShader_DEFINE |
| 9 | #define GrGradientShader_DEFINE |
| 10 | |
| 11 | #include "GrFPArgs.h" |
Michael Ludwig | afebe16 | 2018-09-12 15:24:34 -0400 | [diff] [blame] | 12 | #include "GrFragmentProcessor.h" |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 13 | #include "SkGradientShaderPriv.h" |
| 14 | #include "SkLinearGradient.h" |
Michael Ludwig | 4089df8 | 2018-09-12 15:22:37 -0400 | [diff] [blame] | 15 | #include "SkRadialGradient.h" |
Michael Ludwig | 24d438b | 2018-09-12 15:22:50 -0400 | [diff] [blame] | 16 | #include "SkSweepGradient.h" |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 17 | #include "SkTwoPointConicalGradient.h" |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 18 | |
Michael Ludwig | afebe16 | 2018-09-12 15:24:34 -0400 | [diff] [blame] | 19 | #if GR_TEST_UTILS |
| 20 | #include "SkRandom.h" |
| 21 | #endif |
| 22 | |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 23 | namespace GrGradientShader { |
| 24 | std::unique_ptr<GrFragmentProcessor> MakeLinear(const SkLinearGradient& shader, |
| 25 | const GrFPArgs& args); |
Michael Ludwig | 4089df8 | 2018-09-12 15:22:37 -0400 | [diff] [blame] | 26 | |
| 27 | std::unique_ptr<GrFragmentProcessor> MakeRadial(const SkRadialGradient& shader, |
| 28 | const GrFPArgs& args); |
Michael Ludwig | 24d438b | 2018-09-12 15:22:50 -0400 | [diff] [blame] | 29 | |
| 30 | std::unique_ptr<GrFragmentProcessor> MakeSweep(const SkSweepGradient& shader, |
| 31 | const GrFPArgs& args); |
Michael Ludwig | 8f68508 | 2018-09-12 15:23:01 -0400 | [diff] [blame] | 32 | |
| 33 | std::unique_ptr<GrFragmentProcessor> MakeConical(const SkTwoPointConicalGradient& shader, |
| 34 | const GrFPArgs& args); |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 35 | |
| 36 | #if GR_TEST_UTILS |
| 37 | /** Helper struct that stores (and populates) parameters to construct a random gradient. |
| 38 | If fUseColors4f is true, then the SkColor4f factory should be called, with fColors4f and |
| 39 | fColorSpace. Otherwise, the SkColor factory should be called, with fColors. fColorCount |
| 40 | will be the number of color stops in either case, and fColors and fStops can be passed to |
| 41 | the gradient factory. (The constructor may decide not to use stops, in which case fStops |
| 42 | will be nullptr). */ |
| 43 | struct RandomParams { |
| 44 | static constexpr int kMaxRandomGradientColors = 5; |
| 45 | |
Michael Ludwig | 083bc15 | 2018-10-01 17:15:15 -0400 | [diff] [blame] | 46 | // Should be of similar magnitude to the draw area of the tests so that the gradient |
| 47 | // sampling is done at an appropriate scale. |
| 48 | static constexpr SkScalar kGradientScale = 256.0f; |
| 49 | |
Michael Ludwig | 7f8c524 | 2018-09-14 15:07:55 -0400 | [diff] [blame] | 50 | RandomParams(SkRandom* r); |
| 51 | |
| 52 | bool fUseColors4f; |
| 53 | SkColor fColors[kMaxRandomGradientColors]; |
| 54 | SkColor4f fColors4f[kMaxRandomGradientColors]; |
| 55 | sk_sp<SkColorSpace> fColorSpace; |
| 56 | SkScalar fStopStorage[kMaxRandomGradientColors]; |
| 57 | SkShader::TileMode fTileMode; |
| 58 | int fColorCount; |
| 59 | SkScalar* fStops; |
| 60 | }; |
| 61 | #endif |
| 62 | |
Michael Ludwig | 4f94ef6 | 2018-09-12 15:22:16 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | #endif // GrGradientShader_DEFINE |