blob: e74f562f7decb5ee8a6f47222b923b55544c9418 [file] [log] [blame]
Michael Ludwig4f94ef62018-09-12 15:22:16 -04001/*
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 Ludwigafebe162018-09-12 15:24:34 -040012#include "GrFragmentProcessor.h"
Michael Ludwig4f94ef62018-09-12 15:22:16 -040013#include "SkGradientShaderPriv.h"
14#include "SkLinearGradient.h"
Michael Ludwig4089df82018-09-12 15:22:37 -040015#include "SkRadialGradient.h"
Michael Ludwig24d438b2018-09-12 15:22:50 -040016#include "SkSweepGradient.h"
Michael Ludwig8f685082018-09-12 15:23:01 -040017#include "SkTwoPointConicalGradient.h"
Michael Ludwig4f94ef62018-09-12 15:22:16 -040018
Michael Ludwigafebe162018-09-12 15:24:34 -040019#if GR_TEST_UTILS
20#include "SkRandom.h"
21#endif
22
Michael Ludwig4f94ef62018-09-12 15:22:16 -040023namespace GrGradientShader {
24 std::unique_ptr<GrFragmentProcessor> MakeLinear(const SkLinearGradient& shader,
25 const GrFPArgs& args);
Michael Ludwig4089df82018-09-12 15:22:37 -040026
27 std::unique_ptr<GrFragmentProcessor> MakeRadial(const SkRadialGradient& shader,
28 const GrFPArgs& args);
Michael Ludwig24d438b2018-09-12 15:22:50 -040029
30 std::unique_ptr<GrFragmentProcessor> MakeSweep(const SkSweepGradient& shader,
31 const GrFPArgs& args);
Michael Ludwig8f685082018-09-12 15:23:01 -040032
33 std::unique_ptr<GrFragmentProcessor> MakeConical(const SkTwoPointConicalGradient& shader,
34 const GrFPArgs& args);
Michael Ludwig7f8c5242018-09-14 15:07:55 -040035
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 Ludwig083bc152018-10-01 17:15:15 -040046 // 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 Ludwig7f8c5242018-09-14 15:07:55 -040050 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 Ludwig4f94ef62018-09-12 15:22:16 -040063}
64
65#endif // GrGradientShader_DEFINE