blob: dbeb2fb069818b4e9dab862bd66cb2aecb3a6f51 [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.
rmistry@google.comfbfcd562012-08-23 18:09:54 +000037 @param count Must be >=2. The number of colors (and pos if not NULL) entries.
reed@android.com8a1c16f2008-12-17 15:59:43 +000038 @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@google.comcb7be692012-06-06 20:31:56 +000096
97 /**
98 * Returns a shader that generates a conical gradient given two circles, or
99 * returns NULL if the inputs are invalid. The gradient interprets the
100 * two circles according to the following HTML spec.
101 * http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient
102 */
103 static SkShader* CreateTwoPointConical(const SkPoint& start,
104 SkScalar startRadius,
105 const SkPoint& end,
106 SkScalar endRadius,
107 const SkColor colors[],
108 const SkScalar pos[], int count,
109 SkShader::TileMode mode,
110 SkUnitMapper* mapper = NULL);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000111
reed@android.com8a1c16f2008-12-17 15:59:43 +0000112 /** Returns a shader that generates a sweep gradient given a center.
113 <p />
senorblanco@chromium.org7ef071f2009-09-22 17:25:29 +0000114 CreateSweep returns a shader with a reference count of 1.
reed@android.com8a1c16f2008-12-17 15:59:43 +0000115 The caller should decrement the shader's reference count when done with the shader.
116 It is an error for colorCount to be < 2.
117 @param cx The X coordinate of the center of the sweep
118 @param cx The Y coordinate of the center of the sweep
119 @param colors The array[count] of colors, to be distributed around the center.
120 @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of
121 each corresponding color in the colors array. If this is NULL,
122 the the colors are distributed evenly between the center and edge of the circle.
123 If this is not null, the values must begin with 0, end with 1.0, and
124 intermediate values must be strictly increasing.
125 @param count Must be >= 2. The number of colors (and pos if not NULL) entries
126 @param mapper May be NULL. Callback to modify the spread of the colors.
127 */
128 static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
129 const SkColor colors[], const SkScalar pos[],
130 int count, SkUnitMapper* mapper = NULL);
caryclark@google.comd26147a2011-12-15 14:16:43 +0000131
djsollen@google.coma2ca41e2012-03-23 19:00:34 +0000132 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
reed@android.com8a1c16f2008-12-17 15:59:43 +0000133};
134
135#endif