gfx/skia/trunk/include/effects/SkGradientShader.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/effects/SkGradientShader.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,147 @@
     1.4 +/*
     1.5 + * Copyright 2006 The Android Open Source Project
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkGradientShader_DEFINED
    1.12 +#define SkGradientShader_DEFINED
    1.13 +
    1.14 +#include "SkShader.h"
    1.15 +
    1.16 +class SkUnitMapper;
    1.17 +
    1.18 +/** \class SkGradientShader
    1.19 +
    1.20 +    SkGradientShader hosts factories for creating subclasses of SkShader that
    1.21 +    render linear and radial gradients.
    1.22 +*/
    1.23 +class SK_API SkGradientShader {
    1.24 +public:
    1.25 +    enum Flags {
    1.26 +        /** By default gradients will interpolate their colors in unpremul space
    1.27 +         *  and then premultiply each of the results. By setting this flag, the
    1.28 +         *  gradients will premultiply their colors first, and then interpolate
    1.29 +         *  between them.
    1.30 +         */
    1.31 +        kInterpolateColorsInPremul_Flag = 1 << 0,
    1.32 +    };
    1.33 +
    1.34 +    /** Returns a shader that generates a linear gradient between the two
    1.35 +        specified points.
    1.36 +        <p />
    1.37 +        CreateLinear returns a shader with a reference count of 1.
    1.38 +        The caller should decrement the shader's reference count when done with the shader.
    1.39 +        It is an error for count to be < 2.
    1.40 +        @param  pts The start and end points for the gradient.
    1.41 +        @param  colors  The array[count] of colors, to be distributed between the two points
    1.42 +        @param  pos     May be NULL. array[count] of SkScalars, or NULL, of the relative position of
    1.43 +                        each corresponding color in the colors array. If this is NULL,
    1.44 +                        the the colors are distributed evenly between the start and end point.
    1.45 +                        If this is not null, the values must begin with 0, end with 1.0, and
    1.46 +                        intermediate values must be strictly increasing.
    1.47 +        @param  count   Must be >=2. The number of colors (and pos if not NULL) entries.
    1.48 +        @param  mode    The tiling mode
    1.49 +        @param  mapper  May be NULL. Callback to modify the spread of the colors.
    1.50 +    */
    1.51 +    static SkShader* CreateLinear(const SkPoint pts[2],
    1.52 +                                  const SkColor colors[], const SkScalar pos[], int count,
    1.53 +                                  SkShader::TileMode mode,
    1.54 +                                  SkUnitMapper* mapper = NULL,
    1.55 +                                  uint32_t flags = 0);
    1.56 +
    1.57 +    /** Returns a shader that generates a radial gradient given the center and radius.
    1.58 +        <p />
    1.59 +        CreateRadial returns a shader with a reference count of 1.
    1.60 +        The caller should decrement the shader's reference count when done with the shader.
    1.61 +        It is an error for colorCount to be < 2, or for radius to be <= 0.
    1.62 +        @param  center  The center of the circle for this gradient
    1.63 +        @param  radius  Must be positive. The radius of the circle for this gradient
    1.64 +        @param  colors  The array[count] of colors, to be distributed between the center and edge of the circle
    1.65 +        @param  pos     May be NULL. The array[count] of SkScalars, or NULL, of the relative position of
    1.66 +                        each corresponding color in the colors array. If this is NULL,
    1.67 +                        the the colors are distributed evenly between the center and edge of the circle.
    1.68 +                        If this is not null, the values must begin with 0, end with 1.0, and
    1.69 +                        intermediate values must be strictly increasing.
    1.70 +        @param  count   Must be >= 2. The number of colors (and pos if not NULL) entries
    1.71 +        @param  mode    The tiling mode
    1.72 +        @param  mapper  May be NULL. Callback to modify the spread of the colors.
    1.73 +    */
    1.74 +    static SkShader* CreateRadial(const SkPoint& center, SkScalar radius,
    1.75 +                                  const SkColor colors[], const SkScalar pos[], int count,
    1.76 +                                  SkShader::TileMode mode,
    1.77 +                                  SkUnitMapper* mapper = NULL,
    1.78 +                                  uint32_t flags = 0);
    1.79 +
    1.80 +    /** Returns a shader that generates a radial gradient given the start position, start radius, end position and end radius.
    1.81 +        <p />
    1.82 +        CreateTwoPointRadial returns a shader with a reference count of 1.
    1.83 +        The caller should decrement the shader's reference count when done with the shader.
    1.84 +        It is an error for colorCount to be < 2, for startRadius or endRadius to be < 0, or for
    1.85 +        startRadius to be equal to endRadius.
    1.86 +        @param  start   The center of the start circle for this gradient
    1.87 +        @param  startRadius  Must be positive.  The radius of the start circle for this gradient.
    1.88 +        @param  end     The center of the end circle for this gradient
    1.89 +        @param  endRadius  Must be positive. The radius of the end circle for this gradient.
    1.90 +        @param  colors  The array[count] of colors, to be distributed between the center and edge of the circle
    1.91 +        @param  pos     May be NULL. The array[count] of SkScalars, or NULL, of the relative position of
    1.92 +                        each corresponding color in the colors array. If this is NULL,
    1.93 +                        the the colors are distributed evenly between the center and edge of the circle.
    1.94 +                        If this is not null, the values must begin with 0, end with 1.0, and
    1.95 +                        intermediate values must be strictly increasing.
    1.96 +        @param  count   Must be >= 2. The number of colors (and pos if not NULL) entries
    1.97 +        @param  mode    The tiling mode
    1.98 +        @param  mapper  May be NULL. Callback to modify the spread of the colors.
    1.99 +    */
   1.100 +    static SkShader* CreateTwoPointRadial(const SkPoint& start,
   1.101 +                                          SkScalar startRadius,
   1.102 +                                          const SkPoint& end,
   1.103 +                                          SkScalar endRadius,
   1.104 +                                          const SkColor colors[],
   1.105 +                                          const SkScalar pos[], int count,
   1.106 +                                          SkShader::TileMode mode,
   1.107 +                                          SkUnitMapper* mapper = NULL,
   1.108 +                                          uint32_t flags = 0);
   1.109 +
   1.110 +    /**
   1.111 +     *  Returns a shader that generates a conical gradient given two circles, or
   1.112 +     *  returns NULL if the inputs are invalid. The gradient interprets the
   1.113 +     *  two circles according to the following HTML spec.
   1.114 +     *  http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient
   1.115 +     */
   1.116 +    static SkShader* CreateTwoPointConical(const SkPoint& start,
   1.117 +                                           SkScalar startRadius,
   1.118 +                                           const SkPoint& end,
   1.119 +                                           SkScalar endRadius,
   1.120 +                                           const SkColor colors[],
   1.121 +                                           const SkScalar pos[], int count,
   1.122 +                                           SkShader::TileMode mode,
   1.123 +                                           SkUnitMapper* mapper = NULL,
   1.124 +                                           uint32_t flags = 0);
   1.125 +
   1.126 +    /** Returns a shader that generates a sweep gradient given a center.
   1.127 +        <p />
   1.128 +        CreateSweep returns a shader with a reference count of 1.
   1.129 +        The caller should decrement the shader's reference count when done with the shader.
   1.130 +        It is an error for colorCount to be < 2.
   1.131 +        @param  cx      The X coordinate of the center of the sweep
   1.132 +        @param  cx      The Y coordinate of the center of the sweep
   1.133 +        @param  colors  The array[count] of colors, to be distributed around the center.
   1.134 +        @param  pos     May be NULL. The array[count] of SkScalars, or NULL, of the relative position of
   1.135 +                        each corresponding color in the colors array. If this is NULL,
   1.136 +                        the the colors are distributed evenly between the center and edge of the circle.
   1.137 +                        If this is not null, the values must begin with 0, end with 1.0, and
   1.138 +                        intermediate values must be strictly increasing.
   1.139 +        @param  count   Must be >= 2. The number of colors (and pos if not NULL) entries
   1.140 +        @param  mapper  May be NULL. Callback to modify the spread of the colors.
   1.141 +    */
   1.142 +    static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
   1.143 +                                 const SkColor colors[], const SkScalar pos[],
   1.144 +                                 int count, SkUnitMapper* mapper = NULL,
   1.145 +                                 uint32_t flags = 0);
   1.146 +
   1.147 +    SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
   1.148 +};
   1.149 +
   1.150 +#endif

mercurial