reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkGradientShader_DEFINED |
| 9 | #define SkGradientShader_DEFINED |
| 10 | |
| 11 | #include "SkShader.h" |
| 12 | |
| 13 | class 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.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 20 | class SK_API SkGradientShader { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | public: |
reed@google.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 22 | 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.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | /** 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.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 44 | @param count Must be >=2. The number of colors (and pos if not NULL) entries. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 45 | @param mode The tiling mode |
| 46 | @param mapper May be NULL. Callback to modify the spread of the colors. |
| 47 | */ |
reed@google.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 48 | static SkShader* CreateLinear(const SkPoint pts[2], |
| 49 | const SkColor colors[], const SkScalar pos[], int count, |
| 50 | SkShader::TileMode mode, |
| 51 | SkUnitMapper* mapper = NULL, |
| 52 | uint32_t flags = 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 53 | |
| 54 | /** Returns a shader that generates a radial gradient given the center and radius. |
| 55 | <p /> |
| 56 | CreateRadial returns a shader with a reference count of 1. |
| 57 | The caller should decrement the shader's reference count when done with the shader. |
| 58 | It is an error for colorCount to be < 2, or for radius to be <= 0. |
| 59 | @param center The center of the circle for this gradient |
| 60 | @param radius Must be positive. The radius of the circle for this gradient |
| 61 | @param colors The array[count] of colors, to be distributed between the center and edge of the circle |
| 62 | @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of |
| 63 | each corresponding color in the colors array. If this is NULL, |
| 64 | the the colors are distributed evenly between the center and edge of the circle. |
| 65 | If this is not null, the values must begin with 0, end with 1.0, and |
| 66 | intermediate values must be strictly increasing. |
| 67 | @param count Must be >= 2. The number of colors (and pos if not NULL) entries |
| 68 | @param mode The tiling mode |
| 69 | @param mapper May be NULL. Callback to modify the spread of the colors. |
| 70 | */ |
reed@google.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 71 | static SkShader* CreateRadial(const SkPoint& center, SkScalar radius, |
| 72 | const SkColor colors[], const SkScalar pos[], int count, |
| 73 | SkShader::TileMode mode, |
| 74 | SkUnitMapper* mapper = NULL, |
| 75 | uint32_t flags = 0); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 76 | |
senorblanco@chromium.org | 7ef071f | 2009-09-22 17:25:29 +0000 | [diff] [blame] | 77 | /** Returns a shader that generates a radial gradient given the start position, start radius, end position and end radius. |
| 78 | <p /> |
| 79 | CreateTwoPointRadial returns a shader with a reference count of 1. |
| 80 | The caller should decrement the shader's reference count when done with the shader. |
| 81 | It is an error for colorCount to be < 2, for startRadius or endRadius to be < 0, or for |
| 82 | startRadius to be equal to endRadius. |
| 83 | @param start The center of the start circle for this gradient |
| 84 | @param startRadius Must be positive. The radius of the start circle for this gradient. |
| 85 | @param end The center of the end circle for this gradient |
| 86 | @param endRadius Must be positive. The radius of the end circle for this gradient. |
| 87 | @param colors The array[count] of colors, to be distributed between the center and edge of the circle |
| 88 | @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of |
| 89 | each corresponding color in the colors array. If this is NULL, |
| 90 | the the colors are distributed evenly between the center and edge of the circle. |
| 91 | If this is not null, the values must begin with 0, end with 1.0, and |
| 92 | intermediate values must be strictly increasing. |
| 93 | @param count Must be >= 2. The number of colors (and pos if not NULL) entries |
| 94 | @param mode The tiling mode |
| 95 | @param mapper May be NULL. Callback to modify the spread of the colors. |
| 96 | */ |
| 97 | static SkShader* CreateTwoPointRadial(const SkPoint& start, |
| 98 | SkScalar startRadius, |
| 99 | const SkPoint& end, |
| 100 | SkScalar endRadius, |
| 101 | const SkColor colors[], |
| 102 | const SkScalar pos[], int count, |
| 103 | SkShader::TileMode mode, |
reed@google.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 104 | SkUnitMapper* mapper = NULL, |
| 105 | uint32_t flags = 0); |
reed@google.com | cb7be69 | 2012-06-06 20:31:56 +0000 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * Returns a shader that generates a conical gradient given two circles, or |
| 109 | * returns NULL if the inputs are invalid. The gradient interprets the |
| 110 | * two circles according to the following HTML spec. |
| 111 | * http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient |
| 112 | */ |
| 113 | static SkShader* CreateTwoPointConical(const SkPoint& start, |
reed@google.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 114 | SkScalar startRadius, |
| 115 | const SkPoint& end, |
| 116 | SkScalar endRadius, |
| 117 | const SkColor colors[], |
| 118 | const SkScalar pos[], int count, |
| 119 | SkShader::TileMode mode, |
| 120 | SkUnitMapper* mapper = NULL, |
| 121 | uint32_t flags = 0); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 122 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 123 | /** Returns a shader that generates a sweep gradient given a center. |
| 124 | <p /> |
senorblanco@chromium.org | 7ef071f | 2009-09-22 17:25:29 +0000 | [diff] [blame] | 125 | CreateSweep returns a shader with a reference count of 1. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 126 | The caller should decrement the shader's reference count when done with the shader. |
| 127 | It is an error for colorCount to be < 2. |
| 128 | @param cx The X coordinate of the center of the sweep |
| 129 | @param cx The Y coordinate of the center of the sweep |
| 130 | @param colors The array[count] of colors, to be distributed around the center. |
| 131 | @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of |
| 132 | each corresponding color in the colors array. If this is NULL, |
| 133 | the the colors are distributed evenly between the center and edge of the circle. |
| 134 | If this is not null, the values must begin with 0, end with 1.0, and |
| 135 | intermediate values must be strictly increasing. |
| 136 | @param count Must be >= 2. The number of colors (and pos if not NULL) entries |
| 137 | @param mapper May be NULL. Callback to modify the spread of the colors. |
| 138 | */ |
| 139 | static SkShader* CreateSweep(SkScalar cx, SkScalar cy, |
| 140 | const SkColor colors[], const SkScalar pos[], |
reed@google.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 141 | int count, SkUnitMapper* mapper = NULL, |
| 142 | uint32_t flags = 0); |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 143 | |
djsollen@google.com | a2ca41e | 2012-03-23 19:00:34 +0000 | [diff] [blame] | 144 | SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | #endif |