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