| 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 "src/gpu/GrFPArgs.h" | 
|---|
| 12 | #include "src/gpu/GrFragmentProcessor.h" | 
|---|
| 13 | #include "src/shaders/gradients/SkGradientShaderPriv.h" | 
|---|
| 14 | #include "src/shaders/gradients/SkLinearGradient.h" | 
|---|
| 15 | #include "src/shaders/gradients/SkRadialGradient.h" | 
|---|
| 16 | #include "src/shaders/gradients/SkSweepGradient.h" | 
|---|
| 17 | #include "src/shaders/gradients/SkTwoPointConicalGradient.h" | 
|---|
| 18 |  | 
|---|
| 19 | #if GR_TEST_UTILS | 
|---|
| 20 | #include "include/utils/SkRandom.h" | 
|---|
| 21 | #endif | 
|---|
| 22 |  | 
|---|
| 23 | namespace GrGradientShader { | 
|---|
| 24 | std::unique_ptr<GrFragmentProcessor> MakeLinear(const SkLinearGradient& shader, | 
|---|
| 25 | const GrFPArgs& args); | 
|---|
| 26 |  | 
|---|
| 27 | std::unique_ptr<GrFragmentProcessor> MakeRadial(const SkRadialGradient& shader, | 
|---|
| 28 | const GrFPArgs& args); | 
|---|
| 29 |  | 
|---|
| 30 | std::unique_ptr<GrFragmentProcessor> MakeSweep(const SkSweepGradient& shader, | 
|---|
| 31 | const GrFPArgs& args); | 
|---|
| 32 |  | 
|---|
| 33 | std::unique_ptr<GrFragmentProcessor> MakeConical(const SkTwoPointConicalGradient& shader, | 
|---|
| 34 | const GrFPArgs& args); | 
|---|
| 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 |  | 
|---|
| 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 |  | 
|---|
| 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 | SkTileMode fTileMode; | 
|---|
| 58 | int fColorCount; | 
|---|
| 59 | SkScalar* fStops; | 
|---|
| 60 | }; | 
|---|
| 61 | #endif | 
|---|
| 62 |  | 
|---|
| 63 | }  // namespace GrGradientShader | 
|---|
| 64 |  | 
|---|
| 65 | #endif // GrGradientShader_DEFINE | 
|---|
| 66 |  | 
|---|