180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/*
380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Copyright 2011 Google Inc.
480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Use of this source code is governed by a BSD-style license that can be
680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * found in the LICENSE file.
780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#ifndef GrPaint_DEFINED
1180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#define GrPaint_DEFINED
1280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "GrColor.h"
14363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger#include "GrEffectStage.h"
1580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#include "SkXfermode.h"
1780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
1880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru/**
1980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * The paint describes how color and coverage are computed at each pixel by GrContext draw
2080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * functions and the how color is blended with the destination pixel.
2180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
2280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * The paint allows installation of custom color and coverage stages. New types of stages are
23363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger * created by subclassing GrEffect.
2480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
2580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * The primitive color computation starts with the color specified by setColor(). This color is the
2680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * input to the first color stage. Each color stage feeds its output to the next color stage. The
2780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * final color stage's output color is input to the color filter specified by
28363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger * setXfermodeColorFilter which produces the final source color, S.
2980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
3080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Fractional pixel coverage follows a similar flow. The coverage is initially the value specified
3180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * by setCoverage(). This is input to the first coverage stage. Coverage stages are chained
3280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * together in the same manner as color stages. The output of the last stage is modulated by any
3380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * fractional coverage produced by anti-aliasing. This last step produces the final coverage, C.
3480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
3580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * setBlendFunc() specifies blending coefficients for S (described above) and D, the initial value
3680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * of the destination pixel, labeled Bs and Bd respectively. The final value of the destination
3780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * pixel is then D' = (1-C)*D + C*(Bd*D + Bs*S).
3880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
3980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * Note that the coverage is applied after the blend. This is why they are computed as distinct
4080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru * values.
4180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru *
42363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger * TODO: Encapsulate setXfermodeColorFilter in a GrEffect and remove from GrPaint.
4380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru */
4480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruclass GrPaint {
4580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Querupublic:
4680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    enum {
4780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kMaxColorStages     = 2,
4880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kMaxCoverageStages  = 1,
4980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
5080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrPaint() { this->reset(); }
5280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrPaint(const GrPaint& paint) { *this = paint; }
5480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    ~GrPaint() {}
5680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
5780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
5880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * Sets the blending coefficients to use to blend the final primitive color with the
5980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * destination color. Defaults to kOne for src and kZero for dst (i.e. src mode).
6080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
6180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
6280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fSrcBlendCoeff = srcCoeff;
6380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fDstBlendCoeff = dstCoeff;
6480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
6580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlendCoeff; }
6680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrBlendCoeff getDstBlendCoeff() const { return fDstBlendCoeff; }
6780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
6880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
6980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * The initial color of the drawn primitive. Defaults to solid white.
7080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
7180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setColor(GrColor color) { fColor = color; }
7280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrColor getColor() const { return fColor; }
7380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
7480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
7580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * Applies fractional coverage to the entire drawn primitive. Defaults to 0xff.
7680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
7780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setCoverage(uint8_t coverage) { fCoverage = coverage; }
7880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint8_t getCoverage() const { return fCoverage; }
7980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
8180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * Should primitives be anti-aliased or not. Defaults to false.
8280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
8380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setAntiAlias(bool aa) { fAntiAlias = aa; }
8480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool isAntiAlias() const { return fAntiAlias; }
8580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
8680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
8780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * Should dithering be applied. Defaults to false.
8880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
8980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setDither(bool dither) { fDither = dither; }
9080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool isDither() const { return fDither; }
9180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
9280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
9380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * Enables a SkXfermode::Mode-based color filter applied to the primitive color. The constant
9480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * color passed to this function is considered the "src" color and the primitive's color is
9580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * considered the "dst" color. Defaults to kDst_Mode which equates to simply passing through
9680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * the primitive color unmodified.
9780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
9880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void setXfermodeColorFilter(SkXfermode::Mode mode, GrColor color) {
9980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fColorFilterColor = color;
10080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fColorFilterXfermode = mode;
10180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
10280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkXfermode::Mode getColorFilterMode() const { return fColorFilterXfermode; }
10380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrColor getColorFilterColor() const { return fColorFilterColor; }
10480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
10580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
106363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger     * Disables the SkXfermode::Mode color filter.
10780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
10880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void resetColorFilter() {
10980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fColorFilterXfermode = SkXfermode::kDst_Mode;
11080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fColorFilterColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
11180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
11280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
11380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
11480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * Specifies a stage of the color pipeline. Usually the texture matrices of color stages apply
11580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * to the primitive's positions. Some GrContext calls take explicit coords as an array or a
116363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger     * rect. In this case these are the pre-matrix coords to colorStage(0).
11780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
118363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    GrEffectStage* colorStage(int i) {
11980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert((unsigned)i < kMaxColorStages);
120363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger        return fColorStages + i;
12180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
12280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
123363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    const GrEffectStage& getColorStage(int i) const {
12480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert((unsigned)i < kMaxColorStages);
125363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger        return fColorStages[i];
12680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
12780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
12880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool isColorStageEnabled(int i) const {
12980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert((unsigned)i < kMaxColorStages);
130363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger        return (NULL != fColorStages[i].getEffect());
13180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
13280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
13380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
13480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * Specifies a stage of the coverage pipeline. Coverage stages' texture matrices are always
13580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * applied to the primitive's position, never to explicit texture coords.
13680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
137363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    GrEffectStage* coverageStage(int i) {
13880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert((unsigned)i < kMaxCoverageStages);
139363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger        return fCoverageStages + i;
14080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
14180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
142363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    const GrEffectStage& getCoverageStage(int i) const {
14380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert((unsigned)i < kMaxCoverageStages);
144363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger        return fCoverageStages[i];
14580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
14680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
14780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool isCoverageStageEnabled(int i) const {
14880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        GrAssert((unsigned)i < kMaxCoverageStages);
149363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger        return (NULL != fCoverageStages[i].getEffect());
15080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
15180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
15280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool hasCoverageStage() const {
15380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        for (int i = 0; i < kMaxCoverageStages; ++i) {
15480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (this->isCoverageStageEnabled(i)) {
15580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                return true;
15680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
15780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
15880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return false;
15980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
16080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
16180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool hasColorStage() const {
16280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        for (int i = 0; i < kMaxColorStages; ++i) {
16380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (this->isColorStageEnabled(i)) {
16480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                return true;
16580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
16680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
16780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return false;
16880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
16980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool hasStage() const { return this->hasColorStage() || this->hasCoverageStage(); }
17180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
17280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
173363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger     * Called when the source coord system is changing. preConcatInverse is the inverse of the
174363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger     * transformation from the old coord system to the new coord system. Returns false if the matrix
175363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger     * cannot be inverted.
17680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
177363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    bool sourceCoordChangeByInverse(const SkMatrix& preConcatInverse) {
178363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger        SkMatrix inv;
17980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        bool computed = false;
18080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        for (int i = 0; i < kMaxColorStages; ++i) {
18180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (this->isColorStageEnabled(i)) {
182363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger                if (!computed && !preConcatInverse.invert(&inv)) {
18380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    return false;
18480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                } else {
18580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    computed = true;
18680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                }
187363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger                fColorStages[i].preConcatCoordChange(inv);
18880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
18980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
19080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        for (int i = 0; i < kMaxCoverageStages; ++i) {
19180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (this->isCoverageStageEnabled(i)) {
192363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger                if (!computed && !preConcatInverse.invert(&inv)) {
19380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    return false;
19480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                } else {
19580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                    computed = true;
19680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru                }
197363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger                fCoverageStages[i].preConcatCoordChange(inv);
19880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
19980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
20080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return true;
20180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
20280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
20380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
204363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger     * Called when the source coord system is changing. preConcat gives the transformation from the
205363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger     * old coord system to the new coord system.
20680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
207363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    void sourceCoordChange(const SkMatrix& preConcat) {
20880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        for (int i = 0; i < kMaxColorStages; ++i) {
20980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (this->isColorStageEnabled(i)) {
210363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger                fColorStages[i].preConcatCoordChange(preConcat);
21180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
21280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
21380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        for (int i = 0; i < kMaxCoverageStages; ++i) {
21480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (this->isCoverageStageEnabled(i)) {
215363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger                fCoverageStages[i].preConcatCoordChange(preConcat);
21680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
21780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
21880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
21980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrPaint& operator=(const GrPaint& paint) {
22180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fSrcBlendCoeff = paint.fSrcBlendCoeff;
22280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fDstBlendCoeff = paint.fDstBlendCoeff;
22380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fAntiAlias = paint.fAntiAlias;
22480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fDither = paint.fDither;
22580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fColor = paint.fColor;
22780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fCoverage = paint.fCoverage;
22880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
22980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fColorFilterColor = paint.fColorFilterColor;
23080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fColorFilterXfermode = paint.fColorFilterXfermode;
23180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
23280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        for (int i = 0; i < kMaxColorStages; ++i) {
23380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (paint.isColorStageEnabled(i)) {
234363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger                fColorStages[i] = paint.fColorStages[i];
23580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
23680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
23780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        for (int i = 0; i < kMaxCoverageStages; ++i) {
23880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            if (paint.isCoverageStageEnabled(i)) {
239363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger                fCoverageStages[i] = paint.fCoverageStages[i];
24080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru            }
24180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
24280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        return *this;
24380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
24480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
24580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    /**
24680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     * Resets the paint to the defaults.
24780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru     */
24880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void reset() {
24980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        this->resetBlend();
25080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        this->resetOptions();
25180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        this->resetColor();
25280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        this->resetCoverage();
253363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger        this->resetStages();
25480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        this->resetColorFilter();
25580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
25680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
25780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // internal use
25880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // GrPaint's textures and masks map to the first N stages
25980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    // of GrDrawTarget in that order (textures followed by masks)
26080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    enum {
26180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kFirstColorStage = 0,
26280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kFirstCoverageStage = kMaxColorStages,
26380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        kTotalStages = kFirstColorStage + kMaxColorStages + kMaxCoverageStages,
26480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    };
26580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
26680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queruprivate:
26780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
268363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    GrEffectStage               fColorStages[kMaxColorStages];
269363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    GrEffectStage               fCoverageStages[kMaxCoverageStages];
27080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
27180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrBlendCoeff                fSrcBlendCoeff;
27280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrBlendCoeff                fDstBlendCoeff;
27380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool                        fAntiAlias;
27480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    bool                        fDither;
27580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
27680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrColor                     fColor;
27780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    uint8_t                     fCoverage;
27880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
27980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    GrColor                     fColorFilterColor;
28080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    SkXfermode::Mode            fColorFilterXfermode;
28180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
28280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void resetBlend() {
28380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fSrcBlendCoeff = kOne_GrBlendCoeff;
28480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fDstBlendCoeff = kZero_GrBlendCoeff;
28580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
28680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
28780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void resetOptions() {
28880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fAntiAlias = false;
28980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fDither = false;
29080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
29180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
29280bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void resetColor() {
29380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
29480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
29580bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
29680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    void resetCoverage() {
29780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        fCoverage = 0xff;
29880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
29980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
300363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger    void resetStages() {
30180bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        for (int i = 0; i < kMaxColorStages; ++i) {
302363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger            fColorStages[i].reset();
30380bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
30480bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        for (int i = 0; i < kMaxCoverageStages; ++i) {
305363e546ed626b6dbbc42f5db87b3594bc0b5944bDerek Sollenberger            fCoverageStages[i].reset();
30680bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru        }
30780bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru    }
30880bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru};
30980bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru
31080bacfeb4bda06541e8695bd502229727bccfeaJean-Baptiste Queru#endif
311