blob: 427b3da35cbab8364de7d88dd27e64d0d1dd829c [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@android.com8a1c16f2008-12-17 15:59:43 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00004 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00005 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00007 */
8
epoger@google.comec3ed6a2011-07-28 14:26:00 +00009
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#ifndef SkGradientShader_DEFINED
11#define SkGradientShader_DEFINED
12
13#include "SkShader.h"
14
15class SkUnitMapper;
16
17/** \class SkGradientShader
18
19 SkGradientShader hosts factories for creating subclasses of SkShader that
20 render linear and radial gradients.
21*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000022class SK_API SkGradientShader {
reed@android.com8a1c16f2008-12-17 15:59:43 +000023public:
24 /** Returns a shader that generates a linear gradient between the two
25 specified points.
26 <p />
27 CreateLinear returns a shader with a reference count of 1.
28 The caller should decrement the shader's reference count when done with the shader.
29 It is an error for count to be < 2.
30 @param pts The start and end points for the gradient.
31 @param colors The array[count] of colors, to be distributed between the two points
32 @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of
33 each corresponding color in the colors array. If this is NULL,
34 the the colors are distributed evenly between the start and end point.
35 If this is not null, the values must begin with 0, end with 1.0, and
36 intermediate values must be strictly increasing.
37 @param count Must be >=2. The number of colors (and pos if not NULL) entries.
38 @param mode The tiling mode
39 @param mapper May be NULL. Callback to modify the spread of the colors.
40 */
41 static SkShader* CreateLinear( const SkPoint pts[2],
42 const SkColor colors[], const SkScalar pos[], int count,
43 SkShader::TileMode mode,
44 SkUnitMapper* mapper = NULL);
45
46 /** Returns a shader that generates a radial gradient given the center and radius.
47 <p />
48 CreateRadial returns a shader with a reference count of 1.
49 The caller should decrement the shader's reference count when done with the shader.
50 It is an error for colorCount to be < 2, or for radius to be <= 0.
51 @param center The center of the circle for this gradient
52 @param radius Must be positive. The radius of the circle for this gradient
53 @param colors The array[count] of colors, to be distributed between the center and edge of the circle
54 @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of
55 each corresponding color in the colors array. If this is NULL,
56 the the colors are distributed evenly between the center and edge of the circle.
57 If this is not null, the values must begin with 0, end with 1.0, and
58 intermediate values must be strictly increasing.
59 @param count Must be >= 2. The number of colors (and pos if not NULL) entries
60 @param mode The tiling mode
61 @param mapper May be NULL. Callback to modify the spread of the colors.
62 */
63 static SkShader* CreateRadial( const SkPoint& center, SkScalar radius,
64 const SkColor colors[], const SkScalar pos[], int count,
65 SkShader::TileMode mode,
66 SkUnitMapper* mapper = NULL);
67
senorblanco@chromium.org7ef071f2009-09-22 17:25:29 +000068 /** Returns a shader that generates a radial gradient given the start position, start radius, end position and end radius.
69 <p />
70 CreateTwoPointRadial returns a shader with a reference count of 1.
71 The caller should decrement the shader's reference count when done with the shader.
72 It is an error for colorCount to be < 2, for startRadius or endRadius to be < 0, or for
73 startRadius to be equal to endRadius.
74 @param start The center of the start circle for this gradient
75 @param startRadius Must be positive. The radius of the start circle for this gradient.
76 @param end The center of the end circle for this gradient
77 @param endRadius Must be positive. The radius of the end circle for this gradient.
78 @param colors The array[count] of colors, to be distributed between the center and edge of the circle
79 @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of
80 each corresponding color in the colors array. If this is NULL,
81 the the colors are distributed evenly between the center and edge of the circle.
82 If this is not null, the values must begin with 0, end with 1.0, and
83 intermediate values must be strictly increasing.
84 @param count Must be >= 2. The number of colors (and pos if not NULL) entries
85 @param mode The tiling mode
86 @param mapper May be NULL. Callback to modify the spread of the colors.
87 */
88 static SkShader* CreateTwoPointRadial(const SkPoint& start,
89 SkScalar startRadius,
90 const SkPoint& end,
91 SkScalar endRadius,
92 const SkColor colors[],
93 const SkScalar pos[], int count,
94 SkShader::TileMode mode,
95 SkUnitMapper* mapper = NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000096 /** Returns a shader that generates a sweep gradient given a center.
97 <p />
senorblanco@chromium.org7ef071f2009-09-22 17:25:29 +000098 CreateSweep returns a shader with a reference count of 1.
reed@android.com8a1c16f2008-12-17 15:59:43 +000099 The caller should decrement the shader's reference count when done with the shader.
100 It is an error for colorCount to be < 2.
101 @param cx The X coordinate of the center of the sweep
102 @param cx The Y coordinate of the center of the sweep
103 @param colors The array[count] of colors, to be distributed around the center.
104 @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of
105 each corresponding color in the colors array. If this is NULL,
106 the the colors are distributed evenly between the center and edge of the circle.
107 If this is not null, the values must begin with 0, end with 1.0, and
108 intermediate values must be strictly increasing.
109 @param count Must be >= 2. The number of colors (and pos if not NULL) entries
110 @param mapper May be NULL. Callback to modify the spread of the colors.
111 */
112 static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
113 const SkColor colors[], const SkScalar pos[],
114 int count, SkUnitMapper* mapper = NULL);
caryclark@google.comd26147a2011-12-15 14:16:43 +0000115
djsollen@google.coma2ca41e2012-03-23 19:00:34 +0000116 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
reed@android.com8a1c16f2008-12-17 15:59:43 +0000117};
118
119#endif
120