| OLD | NEW | 
|    1  |    1  | 
|    2 /* |    2 /* | 
|    3  * Copyright 2011 Google Inc. |    3  * Copyright 2011 Google Inc. | 
|    4  * |    4  * | 
|    5  * Use of this source code is governed by a BSD-style license that can be |    5  * Use of this source code is governed by a BSD-style license that can be | 
|    6  * found in the LICENSE file. |    6  * found in the LICENSE file. | 
|    7  */ |    7  */ | 
|    8  |    8  | 
|    9  |    9  | 
|   10 #ifndef GrPaint_DEFINED |   10 #ifndef GrPaint_DEFINED | 
|   11 #define GrPaint_DEFINED |   11 #define GrPaint_DEFINED | 
|   12  |   12  | 
|   13 #include "GrColor.h" |   13 #include "GrColor.h" | 
|   14 #include "GrXferProcessor.h" |   14 #include "GrXferProcessor.h" | 
|   15 #include "effects/GrPorterDuffXferProcessor.h" |   15 #include "effects/GrPorterDuffXferProcessor.h" | 
|   16 #include "GrFragmentProcessor.h" |   16 #include "GrFragmentProcessor.h" | 
|   17  |   17  | 
 |   18 #include "SkRefCnt.h" | 
|   18 #include "SkRegion.h" |   19 #include "SkRegion.h" | 
|   19 #include "SkXfermode.h" |   20 #include "SkXfermode.h" | 
|   20  |   21  | 
|   21 /** |   22 /** | 
|   22  * The paint describes how color and coverage are computed at each pixel by GrCo
     ntext draw |   23  * The paint describes how color and coverage are computed at each pixel by GrCo
     ntext draw | 
|   23  * functions and the how color is blended with the destination pixel. |   24  * functions and the how color is blended with the destination pixel. | 
|   24  * |   25  * | 
|   25  * The paint allows installation of custom color and coverage stages. New types 
     of stages are |   26  * The paint allows installation of custom color and coverage stages. New types 
     of stages are | 
|   26  * created by subclassing GrProcessor. |   27  * created by subclassing GrProcessor. | 
|   27  * |   28  * | 
|   28  * The primitive color computation starts with the color specified by setColor()
     . This color is the |   29  * The primitive color computation starts with the color specified by setColor()
     . This color is the | 
|   29  * input to the first color stage. Each color stage feeds its output to the next
      color stage. |   30  * input to the first color stage. Each color stage feeds its output to the next
      color stage. | 
|   30  * |   31  * | 
|   31  * Fractional pixel coverage follows a similar flow. The coverage is initially t
     he value specified |   32  * Fractional pixel coverage follows a similar flow. The coverage is initially t
     he value specified | 
|   32  * by setCoverage(). This is input to the first coverage stage. Coverage stages 
     are chained |   33  * by setCoverage(). This is input to the first coverage stage. Coverage stages 
     are chained | 
|   33  * together in the same manner as color stages. The output of the last stage is 
     modulated by any |   34  * together in the same manner as color stages. The output of the last stage is 
     modulated by any | 
|   34  * fractional coverage produced by anti-aliasing. This last step produces the fi
     nal coverage, C. |   35  * fractional coverage produced by anti-aliasing. This last step produces the fi
     nal coverage, C. | 
|   35  * |   36  * | 
|   36  * setXPFactory is used to control blending between the output color and dest. I
     t also implements |   37  * setXPFactory is used to control blending between the output color and dest. I
     t also implements | 
|   37  * the application of fractional coverage from the coverage pipeline. |   38  * the application of fractional coverage from the coverage pipeline. | 
|   38  */ |   39  */ | 
|   39 class GrPaint { |   40 class GrPaint { | 
|   40 public: |   41 public: | 
|   41     GrPaint(); |   42     GrPaint(); | 
|   42  |   43  | 
|   43     GrPaint(const GrPaint& paint) { *this = paint; } |   44     GrPaint(const GrPaint& paint) { *this = paint; } | 
|   44  |   45  | 
|   45     ~GrPaint() { this->resetFragmentProcessors();  } |   46     ~GrPaint() { } | 
|   46  |   47  | 
|   47     /** |   48     /** | 
|   48      * The initial color of the drawn primitive. Defaults to solid white. |   49      * The initial color of the drawn primitive. Defaults to solid white. | 
|   49      */ |   50      */ | 
|   50     void setColor(GrColor color) { fColor = color; } |   51     void setColor(GrColor color) { fColor = color; } | 
|   51     GrColor getColor() const { return fColor; } |   52     GrColor getColor() const { return fColor; } | 
|   52  |   53  | 
|   53     /** |   54     /** | 
|   54      * Should primitives be anti-aliased or not. Defaults to false. |   55      * Should primitives be anti-aliased or not. Defaults to false. | 
|   55      */ |   56      */ | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
|   72  |   73  | 
|   73     /** |   74     /** | 
|   74      * Should rendering be gamma-correct, end-to-end. Causes sRGB render targets
      to behave |   75      * Should rendering be gamma-correct, end-to-end. Causes sRGB render targets
      to behave | 
|   75      * as such (with linear blending), and sRGB inputs to be filtered and decode
     d correctly. |   76      * as such (with linear blending), and sRGB inputs to be filtered and decode
     d correctly. | 
|   76      */ |   77      */ | 
|   77     void setGammaCorrect(bool gammaCorrect) { |   78     void setGammaCorrect(bool gammaCorrect) { | 
|   78         setDisableOutputConversionToSRGB(!gammaCorrect); |   79         setDisableOutputConversionToSRGB(!gammaCorrect); | 
|   79         setAllowSRGBInputs(gammaCorrect); |   80         setAllowSRGBInputs(gammaCorrect); | 
|   80     } |   81     } | 
|   81  |   82  | 
|   82     const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |   83     void setXPFactory(sk_sp<GrXPFactory> xpFactory) { | 
|   83         fXPFactory.reset(SkSafeRef(xpFactory)); |   84         fXPFactory = std::move(xpFactory); | 
|   84         return xpFactory; |  | 
|   85     } |   85     } | 
|   86  |   86  | 
|   87     void setPorterDuffXPFactory(SkXfermode::Mode mode) { |   87     void setPorterDuffXPFactory(SkXfermode::Mode mode) { | 
|   88         fXPFactory.reset(GrPorterDuffXPFactory::Create(mode)); |   88         fXPFactory = GrPorterDuffXPFactory::Make(mode); | 
|   89     } |   89     } | 
|   90  |   90  | 
|   91     void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = 
     false);  |   91     void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = 
     false);  | 
|   92  |   92  | 
|   93     /** |   93     /** | 
|   94      * Appends an additional color processor to the color computation. |   94      * Appends an additional color processor to the color computation. | 
|   95      */ |   95      */ | 
|   96     const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcess
     or* fp) { |   96     void addColorFragmentProcessor(sk_sp<GrFragmentProcessor> fp) { | 
|   97         SkASSERT(fp); |   97         SkASSERT(fp); | 
|   98         fColorFragmentProcessors.push_back(SkRef(fp)); |   98         fColorFragmentProcessors.push_back(std::move(fp)); | 
|   99         return fp; |  | 
|  100     } |   99     } | 
|  101  |  100  | 
|  102     /** |  101     /** | 
|  103      * Appends an additional coverage processor to the coverage computation. |  102      * Appends an additional coverage processor to the coverage computation. | 
|  104      */ |  103      */ | 
|  105     const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProc
     essor* fp) { |  104     void addCoverageFragmentProcessor(sk_sp<GrFragmentProcessor> fp) { | 
|  106         SkASSERT(fp); |  105         SkASSERT(fp); | 
|  107         fCoverageFragmentProcessors.push_back(SkRef(fp)); |  106         fCoverageFragmentProcessors.push_back(std::move(fp)); | 
|  108         return fp; |  | 
|  109     } |  107     } | 
|  110  |  108  | 
|  111     /** |  109     /** | 
|  112      * Helpers for adding color or coverage effects that sample a texture. The m
     atrix is applied |  110      * Helpers for adding color or coverage effects that sample a texture. The m
     atrix is applied | 
|  113      * to the src space position to compute texture coordinates. |  111      * to the src space position to compute texture coordinates. | 
|  114      */ |  112      */ | 
|  115     void addColorTextureProcessor(GrTexture*, const SkMatrix&); |  113     void addColorTextureProcessor(GrTexture*, const SkMatrix&); | 
|  116     void addCoverageTextureProcessor(GrTexture*, const SkMatrix&); |  114     void addCoverageTextureProcessor(GrTexture*, const SkMatrix&); | 
|  117     void addColorTextureProcessor(GrTexture*, const SkMatrix&, const GrTexturePa
     rams&); |  115     void addColorTextureProcessor(GrTexture*, const SkMatrix&, const GrTexturePa
     rams&); | 
|  118     void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrTextur
     eParams&); |  116     void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrTextur
     eParams&); | 
|  119  |  117  | 
|  120     int numColorFragmentProcessors() const { return fColorFragmentProcessors.cou
     nt(); } |  118     int numColorFragmentProcessors() const { return fColorFragmentProcessors.cou
     nt(); } | 
|  121     int numCoverageFragmentProcessors() const { return fCoverageFragmentProcesso
     rs.count(); } |  119     int numCoverageFragmentProcessors() const { return fCoverageFragmentProcesso
     rs.count(); } | 
|  122     int numTotalFragmentProcessors() const { return this->numColorFragmentProces
     sors() + |  120     int numTotalFragmentProcessors() const { return this->numColorFragmentProces
     sors() + | 
|  123                                               this->numCoverageFragmentProcessor
     s(); } |  121                                               this->numCoverageFragmentProcessor
     s(); } | 
|  124  |  122  | 
|  125     const GrXPFactory* getXPFactory() const { |  123     GrXPFactory* getXPFactory() const { | 
|  126         return fXPFactory; |  124         return fXPFactory.get(); | 
|  127     } |  125     } | 
|  128  |  126  | 
|  129     const GrFragmentProcessor* getColorFragmentProcessor(int i) const { |  127     GrFragmentProcessor* getColorFragmentProcessor(int i) const { | 
|  130         return fColorFragmentProcessors[i]; |  128         return fColorFragmentProcessors[i].get(); | 
|  131     } |  129     } | 
|  132     const GrFragmentProcessor* getCoverageFragmentProcessor(int i) const { |  130     GrFragmentProcessor* getCoverageFragmentProcessor(int i) const { | 
|  133         return fCoverageFragmentProcessors[i]; |  131         return fCoverageFragmentProcessors[i].get(); | 
|  134     } |  132     } | 
|  135  |  133  | 
|  136     GrPaint& operator=(const GrPaint& paint) { |  134     GrPaint& operator=(const GrPaint& paint) { | 
|  137         fAntiAlias = paint.fAntiAlias; |  135         fAntiAlias = paint.fAntiAlias; | 
|  138         fDisableOutputConversionToSRGB = paint.fDisableOutputConversionToSRGB; |  136         fDisableOutputConversionToSRGB = paint.fDisableOutputConversionToSRGB; | 
|  139         fAllowSRGBInputs = paint.fAllowSRGBInputs; |  137         fAllowSRGBInputs = paint.fAllowSRGBInputs; | 
|  140  |  138  | 
|  141         fColor = paint.fColor; |  139         fColor = paint.fColor; | 
|  142         this->resetFragmentProcessors(); |  | 
|  143         fColorFragmentProcessors = paint.fColorFragmentProcessors; |  140         fColorFragmentProcessors = paint.fColorFragmentProcessors; | 
|  144         fCoverageFragmentProcessors = paint.fCoverageFragmentProcessors; |  141         fCoverageFragmentProcessors = paint.fCoverageFragmentProcessors; | 
|  145         for (int i = 0; i < fColorFragmentProcessors.count(); ++i) { |  | 
|  146             fColorFragmentProcessors[i]->ref(); |  | 
|  147         } |  | 
|  148         for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) { |  | 
|  149             fCoverageFragmentProcessors[i]->ref(); |  | 
|  150         } |  | 
|  151  |  142  | 
|  152         fXPFactory.reset(SkSafeRef(paint.getXPFactory())); |  143         fXPFactory = paint.fXPFactory; | 
|  153  |  144  | 
|  154         return *this; |  145         return *this; | 
|  155     } |  146     } | 
|  156  |  147  | 
|  157     /** |  148     /** | 
|  158      * Returns true if the paint's output color will be constant after blending.
      If the result is |  149      * Returns true if the paint's output color will be constant after blending.
      If the result is | 
|  159      * true, constantColor will be updated to contain the constant color. Note t
     hat we can conflate |  150      * true, constantColor will be updated to contain the constant color. Note t
     hat we can conflate | 
|  160      * coverage and color, so the actual values written to pixels with partial c
     overage may still |  151      * coverage and color, so the actual values written to pixels with partial c
     overage may still | 
|  161      * not seem constant, even if this function returns true. |  152      * not seem constant, even if this function returns true. | 
|  162      */ |  153      */ | 
|  163     bool isConstantBlendedColor(GrColor* constantColor) const; |  154     bool isConstantBlendedColor(GrColor* constantColor) const; | 
|  164  |  155  | 
|  165 private: |  156 private: | 
|  166     void resetFragmentProcessors() { |  157     mutable sk_sp<GrXPFactory>                fXPFactory; | 
|  167         for (int i = 0; i < fColorFragmentProcessors.count(); ++i) { |  158     SkSTArray<4, sk_sp<GrFragmentProcessor>>  fColorFragmentProcessors; | 
|  168             fColorFragmentProcessors[i]->unref(); |  159     SkSTArray<2, sk_sp<GrFragmentProcessor>>  fCoverageFragmentProcessors; | 
|  169         } |  | 
|  170         for (int i = 0; i < fCoverageFragmentProcessors.count(); ++i) { |  | 
|  171             fCoverageFragmentProcessors[i]->unref(); |  | 
|  172         } |  | 
|  173         fColorFragmentProcessors.reset(); |  | 
|  174         fCoverageFragmentProcessors.reset(); |  | 
|  175     } |  | 
|  176  |  160  | 
|  177     mutable SkAutoTUnref<const GrXPFactory>         fXPFactory; |  161     bool                                      fAntiAlias; | 
|  178     SkSTArray<4, const GrFragmentProcessor*, true>  fColorFragmentProcessors; |  162     bool                                      fDisableOutputConversionToSRGB; | 
|  179     SkSTArray<2, const GrFragmentProcessor*, true>  fCoverageFragmentProcessors; |  163     bool                                      fAllowSRGBInputs; | 
|  180  |  164  | 
|  181     bool                                            fAntiAlias; |  165     GrColor                                   fColor; | 
|  182     bool                                            fDisableOutputConversionToSR
     GB; |  | 
|  183     bool                                            fAllowSRGBInputs; |  | 
|  184  |  | 
|  185     GrColor                                         fColor; |  | 
|  186 }; |  166 }; | 
|  187  |  167  | 
|  188 #endif |  168 #endif | 
| OLD | NEW |