blob: 871b34a41f9069747dc4dc7951806d00b23cd490 [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
8#ifndef SkGradientShader_DEFINED
9#define SkGradientShader_DEFINED
10
11#include "SkShader.h"
12
13class SkUnitMapper;
14
15/** \class SkGradientShader
16
17 SkGradientShader hosts factories for creating subclasses of SkShader that
18 render linear and radial gradients.
19*/
ctguil@chromium.org7ffb1b22011-03-15 21:27:08 +000020class SK_API SkGradientShader {
reed@android.com8a1c16f2008-12-17 15:59:43 +000021public:
reed@google.com3d3a8602013-05-24 14:58:44 +000022 enum Flags {
23 /** By default gradients will interpolate their colors in unpremul space
24 * and then premultiply each of the results. By setting this flag, the
25 * gradients will premultiply their colors first, and then interpolate
26 * between them.
27 */
28 kInterpolateColorsInPremul_Flag = 1 << 0,
29 };
30
reed@android.com8a1c16f2008-12-17 15:59:43 +000031 /** Returns a shader that generates a linear gradient between the two
32 specified points.
33 <p />
34 CreateLinear returns a shader with a reference count of 1.
35 The caller should decrement the shader's reference count when done with the shader.
36 It is an error for count to be < 2.
37 @param pts The start and end points for the gradient.
38 @param colors The array[count] of colors, to be distributed between the two points
39 @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of
40 each corresponding color in the colors array. If this is NULL,
41 the the colors are distributed evenly between the start and end point.
42 If this is not null, the values must begin with 0, end with 1.0, and
43 intermediate values must be strictly increasing.
rmistry@google.comfbfcd562012-08-23 18:09:54 +000044 @param count Must be >=2. The number of colors (and pos if not NULL) entries.
reed@android.com8a1c16f2008-12-17 15:59:43 +000045 @param mode The tiling mode
46 @param mapper May be NULL. Callback to modify the spread of the colors.
47 */
reed@google.com3d3a8602013-05-24 14:58:44 +000048 static SkShader* CreateLinear(const SkPoint pts[2],
49 const SkColor colors[], const SkScalar pos[], int count,
50 SkShader::TileMode mode,
51 SkUnitMapper* mapper = NULL,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000052 uint32_t flags = 0,
53 const SkMatrix* localMatrix = NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000054
55 /** Returns a shader that generates a radial gradient given the center and radius.
56 <p />
57 CreateRadial returns a shader with a reference count of 1.
58 The caller should decrement the shader's reference count when done with the shader.
59 It is an error for colorCount to be < 2, or for radius to be <= 0.
60 @param center The center of the circle for this gradient
61 @param radius Must be positive. The radius of the circle for this gradient
62 @param colors The array[count] of colors, to be distributed between the center and edge of the circle
63 @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of
64 each corresponding color in the colors array. If this is NULL,
65 the the colors are distributed evenly between the center and edge of the circle.
66 If this is not null, the values must begin with 0, end with 1.0, and
67 intermediate values must be strictly increasing.
68 @param count Must be >= 2. The number of colors (and pos if not NULL) entries
69 @param mode The tiling mode
70 @param mapper May be NULL. Callback to modify the spread of the colors.
71 */
reed@google.com3d3a8602013-05-24 14:58:44 +000072 static SkShader* CreateRadial(const SkPoint& center, SkScalar radius,
73 const SkColor colors[], const SkScalar pos[], int count,
74 SkShader::TileMode mode,
75 SkUnitMapper* mapper = NULL,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +000076 uint32_t flags = 0,
77 const SkMatrix* localMatrix = NULL);
reed@android.com8a1c16f2008-12-17 15:59:43 +000078
senorblanco@chromium.org7ef071f2009-09-22 17:25:29 +000079 /** Returns a shader that generates a radial gradient given the start position, start radius, end position and end radius.
80 <p />
81 CreateTwoPointRadial returns a shader with a reference count of 1.
82 The caller should decrement the shader's reference count when done with the shader.
83 It is an error for colorCount to be < 2, for startRadius or endRadius to be < 0, or for
84 startRadius to be equal to endRadius.
85 @param start The center of the start circle for this gradient
86 @param startRadius Must be positive. The radius of the start circle for this gradient.
87 @param end The center of the end circle for this gradient
88 @param endRadius Must be positive. The radius of the end circle for this gradient.
89 @param colors The array[count] of colors, to be distributed between the center and edge of the circle
90 @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of
91 each corresponding color in the colors array. If this is NULL,
92 the the colors are distributed evenly between the center and edge of the circle.
93 If this is not null, the values must begin with 0, end with 1.0, and
94 intermediate values must be strictly increasing.
95 @param count Must be >= 2. The number of colors (and pos if not NULL) entries
96 @param mode The tiling mode
97 @param mapper May be NULL. Callback to modify the spread of the colors.
98 */
99 static SkShader* CreateTwoPointRadial(const SkPoint& start,
100 SkScalar startRadius,
101 const SkPoint& end,
102 SkScalar endRadius,
103 const SkColor colors[],
104 const SkScalar pos[], int count,
105 SkShader::TileMode mode,
reed@google.com3d3a8602013-05-24 14:58:44 +0000106 SkUnitMapper* mapper = NULL,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000107 uint32_t flags = 0,
108 const SkMatrix* localMatrix = NULL);
reed@google.comcb7be692012-06-06 20:31:56 +0000109
110 /**
111 * Returns a shader that generates a conical gradient given two circles, or
112 * returns NULL if the inputs are invalid. The gradient interprets the
113 * two circles according to the following HTML spec.
114 * http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient
115 */
116 static SkShader* CreateTwoPointConical(const SkPoint& start,
reed@google.com3d3a8602013-05-24 14:58:44 +0000117 SkScalar startRadius,
118 const SkPoint& end,
119 SkScalar endRadius,
120 const SkColor colors[],
121 const SkScalar pos[], int count,
122 SkShader::TileMode mode,
123 SkUnitMapper* mapper = NULL,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000124 uint32_t flags = 0,
125 const SkMatrix* localMatrix = NULL);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000126
reed@android.com8a1c16f2008-12-17 15:59:43 +0000127 /** Returns a shader that generates a sweep gradient given a center.
128 <p />
senorblanco@chromium.org7ef071f2009-09-22 17:25:29 +0000129 CreateSweep returns a shader with a reference count of 1.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000130 The caller should decrement the shader's reference count when done with the shader.
131 It is an error for colorCount to be < 2.
132 @param cx The X coordinate of the center of the sweep
133 @param cx The Y coordinate of the center of the sweep
134 @param colors The array[count] of colors, to be distributed around the center.
135 @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of
136 each corresponding color in the colors array. If this is NULL,
137 the the colors are distributed evenly between the center and edge of the circle.
138 If this is not null, the values must begin with 0, end with 1.0, and
139 intermediate values must be strictly increasing.
140 @param count Must be >= 2. The number of colors (and pos if not NULL) entries
141 @param mapper May be NULL. Callback to modify the spread of the colors.
142 */
143 static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
144 const SkColor colors[], const SkScalar pos[],
reed@google.com3d3a8602013-05-24 14:58:44 +0000145 int count, SkUnitMapper* mapper = NULL,
commit-bot@chromium.org9c9005a2014-04-28 14:55:39 +0000146 uint32_t flags = 0,
147 const SkMatrix* localMatrix = NULL);
caryclark@google.comd26147a2011-12-15 14:16:43 +0000148
djsollen@google.coma2ca41e2012-03-23 19:00:34 +0000149 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
reed@android.com8a1c16f2008-12-17 15:59:43 +0000150};
151
152#endif