• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/ganesh/GrFPArgs.h"
12 #include "src/gpu/ganesh/GrFragmentProcessor.h"
13 #include "src/shaders/gradients/SkGradientShaderBase.h"
14 #include "src/shaders/gradients/SkLinearGradient.h"
15 
16 #if GR_TEST_UTILS
17 #include "src/base/SkRandom.h"
18 #endif
19 
20 namespace GrGradientShader {
21     std::unique_ptr<GrFragmentProcessor> MakeGradientFP(const SkGradientShaderBase& shader,
22                                                         const GrFPArgs& args,
23                                                         const SkShaderBase::MatrixRec&,
24                                                         std::unique_ptr<GrFragmentProcessor> layout,
25                                                         const SkMatrix* overrideMatrix = nullptr);
26 
27     std::unique_ptr<GrFragmentProcessor> MakeLinear(const SkLinearGradient& shader,
28                                                     const GrFPArgs& args,
29                                                     const SkShaderBase::MatrixRec&);
30 
31 #if GR_TEST_UTILS
32     /** Helper struct that stores (and populates) parameters to construct a random gradient.
33         If fUseColors4f is true, then the SkColor4f factory should be called, with fColors4f and
34         fColorSpace. Otherwise, the SkColor factory should be called, with fColors. fColorCount
35         will be the number of color stops in either case, and fColors and fStops can be passed to
36         the gradient factory. (The constructor may decide not to use stops, in which case fStops
37         will be nullptr). */
38     struct RandomParams {
39         inline static constexpr int kMaxRandomGradientColors = 5;
40 
41         // Should be of similar magnitude to the draw area of the tests so that the gradient
42         // sampling is done at an appropriate scale.
43         inline static constexpr SkScalar kGradientScale = 256.0f;
44 
45         RandomParams(SkRandom* r);
46 
47         bool fUseColors4f;
48         SkColor fColors[kMaxRandomGradientColors];
49         SkColor4f fColors4f[kMaxRandomGradientColors];
50         sk_sp<SkColorSpace> fColorSpace;
51         SkScalar fStopStorage[kMaxRandomGradientColors];
52         SkTileMode fTileMode;
53         int fColorCount;
54         SkScalar* fStops;
55     };
56 #endif
57 
58 }  // namespace GrGradientShader
59 
60 #endif // GrGradientShader_DEFINE
61