Home | History | Annotate | Download | only in effects
      1 
      2 /*
      3  * Copyright 2006 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef SkGradientShader_DEFINED
     11 #define SkGradientShader_DEFINED
     12 
     13 #include "SkShader.h"
     14 
     15 class SkUnitMapper;
     16 
     17 /** \class SkGradientShader
     18 
     19     SkGradientShader hosts factories for creating subclasses of SkShader that
     20     render linear and radial gradients.
     21 */
     22 class SK_API SkGradientShader {
     23 public:
     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 
     68     /** 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);
     96     /** Returns a shader that generates a sweep gradient given a center.
     97         <p />
     98         CreateSweep returns a shader with a reference count of 1.
     99         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);
    115 
    116     SK_DECLARE_FLATTENABLE_REGISTRAR()
    117 };
    118 
    119 #endif
    120 
    121