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, |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 52 | uint32_t flags = 0, |
| 53 | const SkMatrix* localMatrix = NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 54 | |
| 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.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 72 | 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.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 76 | uint32_t flags = 0, |
| 77 | const SkMatrix* localMatrix = NULL); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 78 | |
senorblanco@chromium.org | 7ef071f | 2009-09-22 17:25:29 +0000 | [diff] [blame] | 79 | /** 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.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 106 | SkUnitMapper* mapper = NULL, |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 107 | uint32_t flags = 0, |
| 108 | const SkMatrix* localMatrix = NULL); |
reed@google.com | cb7be69 | 2012-06-06 20:31:56 +0000 | [diff] [blame] | 109 | |
| 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.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 117 | 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.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 124 | uint32_t flags = 0, |
| 125 | const SkMatrix* localMatrix = NULL); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 126 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 127 | /** Returns a shader that generates a sweep gradient given a center. |
| 128 | <p /> |
senorblanco@chromium.org | 7ef071f | 2009-09-22 17:25:29 +0000 | [diff] [blame] | 129 | CreateSweep returns a shader with a reference count of 1. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 130 | 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.com | 3d3a860 | 2013-05-24 14:58:44 +0000 | [diff] [blame] | 145 | int count, SkUnitMapper* mapper = NULL, |
commit-bot@chromium.org | 9c9005a | 2014-04-28 14:55:39 +0000 | [diff] [blame] | 146 | uint32_t flags = 0, |
| 147 | const SkMatrix* localMatrix = NULL); |
caryclark@google.com | d26147a | 2011-12-15 14:16:43 +0000 | [diff] [blame] | 148 | |
djsollen@google.com | a2ca41e | 2012-03-23 19:00:34 +0000 | [diff] [blame] | 149 | SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | #endif |