michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkGradientShader_DEFINED michael@0: #define SkGradientShader_DEFINED michael@0: michael@0: #include "SkShader.h" michael@0: michael@0: class SkUnitMapper; michael@0: michael@0: /** \class SkGradientShader michael@0: michael@0: SkGradientShader hosts factories for creating subclasses of SkShader that michael@0: render linear and radial gradients. michael@0: */ michael@0: class SK_API SkGradientShader { michael@0: public: michael@0: enum Flags { michael@0: /** By default gradients will interpolate their colors in unpremul space michael@0: * and then premultiply each of the results. By setting this flag, the michael@0: * gradients will premultiply their colors first, and then interpolate michael@0: * between them. michael@0: */ michael@0: kInterpolateColorsInPremul_Flag = 1 << 0, michael@0: }; michael@0: michael@0: /** Returns a shader that generates a linear gradient between the two michael@0: specified points. michael@0:

michael@0: CreateLinear returns a shader with a reference count of 1. michael@0: The caller should decrement the shader's reference count when done with the shader. michael@0: It is an error for count to be < 2. michael@0: @param pts The start and end points for the gradient. michael@0: @param colors The array[count] of colors, to be distributed between the two points michael@0: @param pos May be NULL. array[count] of SkScalars, or NULL, of the relative position of michael@0: each corresponding color in the colors array. If this is NULL, michael@0: the the colors are distributed evenly between the start and end point. michael@0: If this is not null, the values must begin with 0, end with 1.0, and michael@0: intermediate values must be strictly increasing. michael@0: @param count Must be >=2. The number of colors (and pos if not NULL) entries. michael@0: @param mode The tiling mode michael@0: @param mapper May be NULL. Callback to modify the spread of the colors. michael@0: */ michael@0: static SkShader* CreateLinear(const SkPoint pts[2], michael@0: const SkColor colors[], const SkScalar pos[], int count, michael@0: SkShader::TileMode mode, michael@0: SkUnitMapper* mapper = NULL, michael@0: uint32_t flags = 0); michael@0: michael@0: /** Returns a shader that generates a radial gradient given the center and radius. michael@0:

michael@0: CreateRadial returns a shader with a reference count of 1. michael@0: The caller should decrement the shader's reference count when done with the shader. michael@0: It is an error for colorCount to be < 2, or for radius to be <= 0. michael@0: @param center The center of the circle for this gradient michael@0: @param radius Must be positive. The radius of the circle for this gradient michael@0: @param colors The array[count] of colors, to be distributed between the center and edge of the circle michael@0: @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of michael@0: each corresponding color in the colors array. If this is NULL, michael@0: the the colors are distributed evenly between the center and edge of the circle. michael@0: If this is not null, the values must begin with 0, end with 1.0, and michael@0: intermediate values must be strictly increasing. michael@0: @param count Must be >= 2. The number of colors (and pos if not NULL) entries michael@0: @param mode The tiling mode michael@0: @param mapper May be NULL. Callback to modify the spread of the colors. michael@0: */ michael@0: static SkShader* CreateRadial(const SkPoint& center, SkScalar radius, michael@0: const SkColor colors[], const SkScalar pos[], int count, michael@0: SkShader::TileMode mode, michael@0: SkUnitMapper* mapper = NULL, michael@0: uint32_t flags = 0); michael@0: michael@0: /** Returns a shader that generates a radial gradient given the start position, start radius, end position and end radius. michael@0:

michael@0: CreateTwoPointRadial returns a shader with a reference count of 1. michael@0: The caller should decrement the shader's reference count when done with the shader. michael@0: It is an error for colorCount to be < 2, for startRadius or endRadius to be < 0, or for michael@0: startRadius to be equal to endRadius. michael@0: @param start The center of the start circle for this gradient michael@0: @param startRadius Must be positive. The radius of the start circle for this gradient. michael@0: @param end The center of the end circle for this gradient michael@0: @param endRadius Must be positive. The radius of the end circle for this gradient. michael@0: @param colors The array[count] of colors, to be distributed between the center and edge of the circle michael@0: @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of michael@0: each corresponding color in the colors array. If this is NULL, michael@0: the the colors are distributed evenly between the center and edge of the circle. michael@0: If this is not null, the values must begin with 0, end with 1.0, and michael@0: intermediate values must be strictly increasing. michael@0: @param count Must be >= 2. The number of colors (and pos if not NULL) entries michael@0: @param mode The tiling mode michael@0: @param mapper May be NULL. Callback to modify the spread of the colors. michael@0: */ michael@0: static SkShader* CreateTwoPointRadial(const SkPoint& start, michael@0: SkScalar startRadius, michael@0: const SkPoint& end, michael@0: SkScalar endRadius, michael@0: const SkColor colors[], michael@0: const SkScalar pos[], int count, michael@0: SkShader::TileMode mode, michael@0: SkUnitMapper* mapper = NULL, michael@0: uint32_t flags = 0); michael@0: michael@0: /** michael@0: * Returns a shader that generates a conical gradient given two circles, or michael@0: * returns NULL if the inputs are invalid. The gradient interprets the michael@0: * two circles according to the following HTML spec. michael@0: * http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient michael@0: */ michael@0: static SkShader* CreateTwoPointConical(const SkPoint& start, michael@0: SkScalar startRadius, michael@0: const SkPoint& end, michael@0: SkScalar endRadius, michael@0: const SkColor colors[], michael@0: const SkScalar pos[], int count, michael@0: SkShader::TileMode mode, michael@0: SkUnitMapper* mapper = NULL, michael@0: uint32_t flags = 0); michael@0: michael@0: /** Returns a shader that generates a sweep gradient given a center. michael@0:

michael@0: CreateSweep returns a shader with a reference count of 1. michael@0: The caller should decrement the shader's reference count when done with the shader. michael@0: It is an error for colorCount to be < 2. michael@0: @param cx The X coordinate of the center of the sweep michael@0: @param cx The Y coordinate of the center of the sweep michael@0: @param colors The array[count] of colors, to be distributed around the center. michael@0: @param pos May be NULL. The array[count] of SkScalars, or NULL, of the relative position of michael@0: each corresponding color in the colors array. If this is NULL, michael@0: the the colors are distributed evenly between the center and edge of the circle. michael@0: If this is not null, the values must begin with 0, end with 1.0, and michael@0: intermediate values must be strictly increasing. michael@0: @param count Must be >= 2. The number of colors (and pos if not NULL) entries michael@0: @param mapper May be NULL. Callback to modify the spread of the colors. michael@0: */ michael@0: static SkShader* CreateSweep(SkScalar cx, SkScalar cy, michael@0: const SkColor colors[], const SkScalar pos[], michael@0: int count, SkUnitMapper* mapper = NULL, michael@0: uint32_t flags = 0); michael@0: michael@0: SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() michael@0: }; michael@0: michael@0: #endif