| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2011 Google Inc. | 2  * Copyright 2011 Google Inc. | 
| 3  * | 3  * | 
| 4  * Use of this source code is governed by a BSD-style license that can be | 4  * Use of this source code is governed by a BSD-style license that can be | 
| 5  * found in the LICENSE file. | 5  * found in the LICENSE file. | 
| 6  */ | 6  */ | 
| 7 | 7 | 
| 8 #ifndef GrDrawState_DEFINED | 8 #ifndef GrDrawState_DEFINED | 
| 9 #define GrDrawState_DEFINED | 9 #define GrDrawState_DEFINED | 
| 10 | 10 | 
| 11 #include "GrBlend.h" | 11 #include "GrBlend.h" | 
|  | 12 #include "GrOptDrawState.h" | 
| 12 #include "GrProgramResource.h" | 13 #include "GrProgramResource.h" | 
| 13 #include "GrRODrawState.h" | 14 #include "GrRODrawState.h" | 
| 14 #include "effects/GrSimpleTextureEffect.h" | 15 #include "effects/GrSimpleTextureEffect.h" | 
| 15 | 16 | 
| 16 /** | 17 /** | 
| 17  * Modifiable subclass derived from GrRODrawState. The majority of the data that
      represents a draw | 18  * Modifiable subclass derived from GrRODrawState. The majority of the data that
      represents a draw | 
| 18  * state is stored in the parent class. GrDrawState contains methods for setting
     , adding to, etc. | 19  * state is stored in the parent class. GrDrawState contains methods for setting
     , adding to, etc. | 
| 19  * various data members of the draw state. This class is used to configure the s
     tate used when | 20  * various data members of the draw state. This class is used to configure the s
     tate used when | 
| 20  * issuing draws via GrDrawTarget. | 21  * issuing draws via GrDrawTarget. | 
| 21  */ | 22  */ | 
| 22 class GrDrawState : public GrRODrawState { | 23 class GrDrawState : public GrRODrawState { | 
| 23 public: | 24 public: | 
| 24     SK_DECLARE_INST_COUNT(GrDrawState) | 25     SK_DECLARE_INST_COUNT(GrDrawState) | 
| 25 | 26 | 
| 26     GrDrawState() { | 27     GrDrawState() : fCachedOptState(NULL) { | 
| 27         SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 28         SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 
| 28         this->reset(); | 29         this->reset(); | 
| 29     } | 30     } | 
| 30 | 31 | 
| 31     GrDrawState(const SkMatrix& initialViewMatrix) { | 32     GrDrawState(const SkMatrix& initialViewMatrix) : fCachedOptState(NULL) { | 
| 32         SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 33         SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 
| 33         this->reset(initialViewMatrix); | 34         this->reset(initialViewMatrix); | 
| 34     } | 35     } | 
| 35 | 36 | 
| 36     /** | 37     /** | 
| 37      * Copies another draw state. | 38      * Copies another draw state. | 
| 38      **/ | 39      **/ | 
| 39     GrDrawState(const GrDrawState& state) : INHERITED() { | 40     GrDrawState(const GrDrawState& state) : INHERITED(), fCachedOptState(NULL) { | 
| 40         SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 41         SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 
| 41         *this = state; | 42         *this = state; | 
| 42     } | 43     } | 
| 43 | 44 | 
| 44     /** | 45     /** | 
| 45      * Copies another draw state with a preconcat to the view matrix. | 46      * Copies another draw state with a preconcat to the view matrix. | 
| 46      **/ | 47      **/ | 
| 47     GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); | 48     GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); | 
| 48 | 49 | 
| 49     virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } | 50     virtual ~GrDrawState() { | 
|  | 51         SkSafeUnref(fCachedOptState); | 
|  | 52         SkASSERT(0 == fBlockEffectRemovalCnt); | 
|  | 53     } | 
| 50 | 54 | 
| 51     /** | 55     /** | 
| 52      * Resets to the default state. GrEffects will be removed from all stages. | 56      * Resets to the default state. GrEffects will be removed from all stages. | 
| 53      */ | 57      */ | 
| 54     void reset() { this->onReset(NULL); } | 58     void reset() { this->onReset(NULL); } | 
| 55 | 59 | 
| 56     void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa
     trix); } | 60     void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa
     trix); } | 
| 57 | 61 | 
| 58     /** | 62     /** | 
| 59      * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
     rget. Note that | 63      * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
     rget. Note that | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 93      */ | 97      */ | 
| 94     void setDefaultVertexAttribs(); | 98     void setDefaultVertexAttribs(); | 
| 95 | 99 | 
| 96     /** | 100     /** | 
| 97      * Helper to save/restore vertex attribs | 101      * Helper to save/restore vertex attribs | 
| 98      */ | 102      */ | 
| 99      class AutoVertexAttribRestore { | 103      class AutoVertexAttribRestore { | 
| 100      public: | 104      public: | 
| 101          AutoVertexAttribRestore(GrDrawState* drawState); | 105          AutoVertexAttribRestore(GrDrawState* drawState); | 
| 102 | 106 | 
| 103          ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPt
     r, fVACount, fVAStride); } | 107          ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPt
     r, fVACount, | 
|  | 108                                                                            fVASt
     ride); } | 
| 104 | 109 | 
| 105      private: | 110      private: | 
| 106          GrDrawState*          fDrawState; | 111          GrDrawState*          fDrawState; | 
| 107          const GrVertexAttrib* fVAPtr; | 112          const GrVertexAttrib* fVAPtr; | 
| 108          int                   fVACount; | 113          int                   fVACount; | 
| 109          size_t                fVAStride; | 114          size_t                fVAStride; | 
| 110      }; | 115      }; | 
| 111 | 116 | 
| 112     /// @} | 117     /// @} | 
| 113 | 118 | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 128     /////////////////////////////////////////////////////////////////////////// | 133     /////////////////////////////////////////////////////////////////////////// | 
| 129     /// @name Color | 134     /// @name Color | 
| 130     //// | 135     //// | 
| 131 | 136 | 
| 132     /** | 137     /** | 
| 133      *  Sets color for next draw to a premultiplied-alpha color. | 138      *  Sets color for next draw to a premultiplied-alpha color. | 
| 134      * | 139      * | 
| 135      *  @param color    the color to set. | 140      *  @param color    the color to set. | 
| 136      */ | 141      */ | 
| 137     void setColor(GrColor color) { | 142     void setColor(GrColor color) { | 
| 138         fColor = color; | 143         if (color != fColor) { | 
| 139         this->invalidateBlendOptFlags(); | 144             fColor = color; | 
|  | 145             this->invalidateOptState(); | 
|  | 146         } | 
| 140     } | 147     } | 
| 141 | 148 | 
| 142     /** | 149     /** | 
| 143      *  Sets the color to be used for the next draw to be | 150      *  Sets the color to be used for the next draw to be | 
| 144      *  (r,g,b,a) = (alpha, alpha, alpha, alpha). | 151      *  (r,g,b,a) = (alpha, alpha, alpha, alpha). | 
| 145      * | 152      * | 
| 146      *  @param alpha The alpha value to set as the color. | 153      *  @param alpha The alpha value to set as the color. | 
| 147      */ | 154      */ | 
| 148     void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) |
      a); } | 155     void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) |
      a); } | 
| 149 | 156 | 
| 150     /// @} | 157     /// @} | 
| 151 | 158 | 
| 152     /////////////////////////////////////////////////////////////////////////// | 159     /////////////////////////////////////////////////////////////////////////// | 
| 153     /// @name Coverage | 160     /// @name Coverage | 
| 154     //// | 161     //// | 
| 155 | 162 | 
| 156     /** | 163     /** | 
| 157      * Sets a constant fractional coverage to be applied to the draw. The | 164      * Sets a constant fractional coverage to be applied to the draw. The | 
| 158      * initial value (after construction or reset()) is 0xff. The constant | 165      * initial value (after construction or reset()) is 0xff. The constant | 
| 159      * coverage is ignored when per-vertex coverage is provided. | 166      * coverage is ignored when per-vertex coverage is provided. | 
| 160      */ | 167      */ | 
| 161     void setCoverage(uint8_t coverage) { | 168     void setCoverage(uint8_t coverage) { | 
| 162         fCoverage = coverage; | 169         if (coverage != fCoverage) { | 
| 163         this->invalidateBlendOptFlags(); | 170             fCoverage = coverage; | 
|  | 171             this->invalidateOptState(); | 
|  | 172         } | 
| 164     } | 173     } | 
| 165 | 174 | 
| 166     /// @} | 175     /// @} | 
| 167 | 176 | 
| 168     /** | 177     /** | 
| 169      * The geometry processor is the sole element of the skia pipeline which can
      use the vertex, | 178      * The geometry processor is the sole element of the skia pipeline which can
      use the vertex, | 
| 170      * geometry, and tesselation shaders.  The GP may also compute a coverage in
      its fragment shader | 179      * geometry, and tesselation shaders.  The GP may also compute a coverage in
      its fragment shader | 
| 171      * but is never put in the color processing pipeline. | 180      * but is never put in the color processing pipeline. | 
| 172      */ | 181      */ | 
| 173 | 182 | 
| 174     const GrEffect* setGeometryProcessor(const GrEffect* effect, int attr0 = -1,
      int attr1 = -1) { | 183     const GrEffect* setGeometryProcessor(const GrEffect* effect, int attr0 = -1,
      int attr1 = -1) { | 
| 175         SkASSERT(effect); | 184         SkASSERT(effect); | 
| 176         SkASSERT(!this->hasGeometryProcessor()); | 185         SkASSERT(!this->hasGeometryProcessor()); | 
| 177         fGeometryProcessor.reset(new GrEffectStage(effect, attr0, attr1)); | 186         fGeometryProcessor.reset(new GrEffectStage(effect, attr0, attr1)); | 
| 178         this->invalidateBlendOptFlags(); | 187         this->invalidateOptState(); | 
| 179         return effect; | 188         return effect; | 
| 180     } | 189     } | 
| 181 | 190 | 
| 182     /////////////////////////////////////////////////////////////////////////// | 191     /////////////////////////////////////////////////////////////////////////// | 
| 183     /// @name Effect Stages | 192     /// @name Effect Stages | 
| 184     /// Each stage hosts a GrEffect. The effect produces an output color or cove
     rage in the fragment | 193     /// Each stage hosts a GrEffect. The effect produces an output color or cove
     rage in the fragment | 
| 185     /// shader. Its inputs are the output from the previous stage as well as som
     e variables | 194     /// shader. Its inputs are the output from the previous stage as well as som
     e variables | 
| 186     /// available to it in the fragment and vertex shader (e.g. the vertex posit
     ion, the dst color, | 195     /// available to it in the fragment and vertex shader (e.g. the vertex posit
     ion, the dst color, | 
| 187     /// the fragment position, local coordinates). | 196     /// the fragment position, local coordinates). | 
| 188     /// | 197     /// | 
| 189     /// The stages are divided into two sets, color-computing and coverage-compu
     ting. The final | 198     /// The stages are divided into two sets, color-computing and coverage-compu
     ting. The final | 
| 190     /// color stage produces the final pixel color. The coverage-computing stage
     s function exactly | 199     /// color stage produces the final pixel color. The coverage-computing stage
     s function exactly | 
| 191     /// as the color-computing but the output of the final coverage stage is tre
     ated as a fractional | 200     /// as the color-computing but the output of the final coverage stage is tre
     ated as a fractional | 
| 192     /// pixel coverage rather than as input to the src/dst color blend step. | 201     /// pixel coverage rather than as input to the src/dst color blend step. | 
| 193     /// | 202     /// | 
| 194     /// The input color to the first color-stage is either the constant color or
      interpolated | 203     /// The input color to the first color-stage is either the constant color or
      interpolated | 
| 195     /// per-vertex colors. The input to the first coverage stage is either a con
     stant coverage | 204     /// per-vertex colors. The input to the first coverage stage is either a con
     stant coverage | 
| 196     /// (usually full-coverage) or interpolated per-vertex coverage. | 205     /// (usually full-coverage) or interpolated per-vertex coverage. | 
| 197     /// | 206     /// | 
| 198     /// See the documentation of kCoverageDrawing_StateBit for information about
      disabling the | 207     /// See the documentation of kCoverageDrawing_StateBit for information about
      disabling the | 
| 199     /// the color / coverage distinction. | 208     /// the color / coverage distinction. | 
| 200     //// | 209     //// | 
| 201 | 210 | 
| 202     const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a
     ttr1 = -1) { | 211     const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a
     ttr1 = -1) { | 
| 203         SkASSERT(effect); | 212         SkASSERT(effect); | 
| 204         SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att
     r1)); | 213         SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att
     r1)); | 
| 205         this->invalidateBlendOptFlags(); | 214         this->invalidateOptState(); | 
| 206         return effect; | 215         return effect; | 
| 207     } | 216     } | 
| 208 | 217 | 
| 209     const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in
     t attr1 = -1) { | 218     const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in
     t attr1 = -1) { | 
| 210         SkASSERT(effect); | 219         SkASSERT(effect); | 
| 211         SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, 
     attr1)); | 220         SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, 
     attr1)); | 
| 212         this->invalidateBlendOptFlags(); | 221         this->invalidateOptState(); | 
| 213         return effect; | 222         return effect; | 
| 214     } | 223     } | 
| 215 | 224 | 
| 216     /** | 225     /** | 
| 217      * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
     ates. | 226      * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
     ates. | 
| 218      */ | 227      */ | 
| 219     void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { | 228     void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { | 
| 220         this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un
     ref(); | 229         this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un
     ref(); | 
| 221     } | 230     } | 
| 222 | 231 | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 294      *    D' = sat(S*srcCoef + D*dstCoef) | 303      *    D' = sat(S*srcCoef + D*dstCoef) | 
| 295      * | 304      * | 
| 296      *   where D is the existing destination color, S is the incoming source | 305      *   where D is the existing destination color, S is the incoming source | 
| 297      *   color, and D' is the new destination color that will be written. sat() | 306      *   color, and D' is the new destination color that will be written. sat() | 
| 298      *   is the saturation function. | 307      *   is the saturation function. | 
| 299      * | 308      * | 
| 300      * @param srcCoef coefficient applied to the src color. | 309      * @param srcCoef coefficient applied to the src color. | 
| 301      * @param dstCoef coefficient applied to the dst color. | 310      * @param dstCoef coefficient applied to the dst color. | 
| 302      */ | 311      */ | 
| 303     void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { | 312     void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { | 
| 304         fSrcBlend = srcCoeff; | 313         if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) { | 
| 305         fDstBlend = dstCoeff; | 314             fSrcBlend = srcCoeff; | 
| 306         this->invalidateBlendOptFlags(); | 315             fDstBlend = dstCoeff; | 
|  | 316             this->invalidateOptState(); | 
|  | 317         } | 
| 307     #ifdef SK_DEBUG | 318     #ifdef SK_DEBUG | 
| 308         if (GrBlendCoeffRefsDst(dstCoeff)) { | 319         if (GrBlendCoeffRefsDst(dstCoeff)) { | 
| 309             GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove
     rage stages.\n"); | 320             GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove
     rage stages.\n"); | 
| 310         } | 321         } | 
| 311         if (GrBlendCoeffRefsSrc(srcCoeff)) { | 322         if (GrBlendCoeffRefsSrc(srcCoeff)) { | 
| 312             GrPrintf("Unexpected src blend coeff. Won't work correctly with cove
     rage stages.\n"); | 323             GrPrintf("Unexpected src blend coeff. Won't work correctly with cove
     rage stages.\n"); | 
| 313         } | 324         } | 
| 314     #endif | 325     #endif | 
| 315     } | 326     } | 
| 316 | 327 | 
| 317     /** | 328     /** | 
| 318      * Sets the blending function constant referenced by the following blending | 329      * Sets the blending function constant referenced by the following blending | 
| 319      * coefficients: | 330      * coefficients: | 
| 320      *      kConstC_GrBlendCoeff | 331      *      kConstC_GrBlendCoeff | 
| 321      *      kIConstC_GrBlendCoeff | 332      *      kIConstC_GrBlendCoeff | 
| 322      *      kConstA_GrBlendCoeff | 333      *      kConstA_GrBlendCoeff | 
| 323      *      kIConstA_GrBlendCoeff | 334      *      kIConstA_GrBlendCoeff | 
| 324      * | 335      * | 
| 325      * @param constant the constant to set | 336      * @param constant the constant to set | 
| 326      */ | 337      */ | 
| 327     void setBlendConstant(GrColor constant) { | 338     void setBlendConstant(GrColor constant) { | 
| 328         fBlendConstant = constant; | 339         if (constant != fBlendConstant) { | 
| 329         this->invalidateBlendOptFlags(); | 340             fBlendConstant = constant; | 
|  | 341             this->invalidateOptState(); | 
|  | 342         } | 
| 330     } | 343     } | 
| 331 | 344 | 
| 332     /** |  | 
| 333      * Determines what optimizations can be applied based on the blend. The coef
     ficients may have |  | 
| 334      * to be tweaked in order for the optimization to work. srcCoeff and dstCoef
     f are optional |  | 
| 335      * params that receive the tweaked coefficients. Normally the function looks
      at the current |  | 
| 336      * state to see if coverage is enabled. By setting forceCoverage the caller 
     can speculatively |  | 
| 337      * determine the blend optimizations that would be used if there was partial
      pixel coverage. |  | 
| 338      * |  | 
| 339      * Subclasses of GrDrawTarget that actually draw (as opposed to those that j
     ust buffer for |  | 
| 340      * playback) must call this function and respect the flags that replace the 
     output color. |  | 
| 341      * |  | 
| 342      * If the cached BlendOptFlags does not have the invalidate bit set, then ge
     tBlendOpts will |  | 
| 343      * simply returned the cached flags and coefficients. Otherwise it will calc
     ulate the values. |  | 
| 344      */ |  | 
| 345     BlendOptFlags getBlendOpts(bool forceCoverage = false, |  | 
| 346                                GrBlendCoeff* srcCoeff = NULL, |  | 
| 347                                GrBlendCoeff* dstCoeff = NULL) const; |  | 
| 348 |  | 
| 349     /** |  | 
| 350      * We don't use suplied vertex color attributes if our blend mode is EmitCov
     erage or |  | 
| 351      * EmitTransBlack |  | 
| 352      */ |  | 
| 353     bool canIgnoreColorAttribute() const; |  | 
| 354 |  | 
| 355 |  | 
| 356     /// @} | 345     /// @} | 
| 357 | 346 | 
| 358     /////////////////////////////////////////////////////////////////////////// | 347     /////////////////////////////////////////////////////////////////////////// | 
| 359     /// @name View Matrix | 348     /// @name View Matrix | 
| 360     //// | 349     //// | 
| 361 | 350 | 
| 362     /** | 351     /** | 
| 363      * Sets the view matrix to identity and updates any installed effects to com
     pensate for the | 352      * Sets the view matrix to identity and updates any installed effects to com
     pensate for the | 
| 364      * coord system change. | 353      * coord system change. | 
| 365      */ | 354      */ | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 409     /// @name Render Target | 398     /// @name Render Target | 
| 410     //// | 399     //// | 
| 411 | 400 | 
| 412     /** | 401     /** | 
| 413      * Sets the render-target used at the next drawing call | 402      * Sets the render-target used at the next drawing call | 
| 414      * | 403      * | 
| 415      * @param target  The render target to set. | 404      * @param target  The render target to set. | 
| 416      */ | 405      */ | 
| 417     void setRenderTarget(GrRenderTarget* target) { | 406     void setRenderTarget(GrRenderTarget* target) { | 
| 418         fRenderTarget.setResource(SkSafeRef(target), GrProgramResource::kWrite_I
     OType); | 407         fRenderTarget.setResource(SkSafeRef(target), GrProgramResource::kWrite_I
     OType); | 
|  | 408         this->invalidateOptState(); | 
| 419     } | 409     } | 
| 420 | 410 | 
| 421     /// @} | 411     /// @} | 
| 422 | 412 | 
| 423     /////////////////////////////////////////////////////////////////////////// | 413     /////////////////////////////////////////////////////////////////////////// | 
| 424     /// @name Stencil | 414     /// @name Stencil | 
| 425     //// | 415     //// | 
| 426 | 416 | 
| 427     /** | 417     /** | 
| 428      * Sets the stencil settings to use for the next draw. | 418      * Sets the stencil settings to use for the next draw. | 
| 429      * Changing the clip has the side-effect of possibly zeroing | 419      * Changing the clip has the side-effect of possibly zeroing | 
| 430      * out the client settable stencil bits. So multipass algorithms | 420      * out the client settable stencil bits. So multipass algorithms | 
| 431      * using stencil should not change the clip between passes. | 421      * using stencil should not change the clip between passes. | 
| 432      * @param settings  the stencil settings to use. | 422      * @param settings  the stencil settings to use. | 
| 433      */ | 423      */ | 
| 434     void setStencil(const GrStencilSettings& settings) { | 424     void setStencil(const GrStencilSettings& settings) { | 
| 435         fStencilSettings = settings; | 425         if (settings != fStencilSettings) { | 
| 436         this->invalidateBlendOptFlags(); | 426             fStencilSettings = settings; | 
|  | 427             this->invalidateOptState(); | 
|  | 428         } | 
| 437     } | 429     } | 
| 438 | 430 | 
| 439     /** | 431     /** | 
| 440      * Shortcut to disable stencil testing and ops. | 432      * Shortcut to disable stencil testing and ops. | 
| 441      */ | 433      */ | 
| 442     void disableStencil() { | 434     void disableStencil() { | 
| 443         fStencilSettings.setDisabled(); | 435         if (!fStencilSettings.isDisabled()) { | 
| 444         this->invalidateBlendOptFlags(); | 436             fStencilSettings.setDisabled(); | 
|  | 437             this->invalidateOptState(); | 
|  | 438         } | 
| 445     } | 439     } | 
| 446 | 440 | 
| 447     GrStencilSettings* stencil() { return &fStencilSettings; } | 441     GrStencilSettings* stencil() { return &fStencilSettings; } | 
| 448 | 442 | 
| 449     /// @} | 443     /// @} | 
| 450 | 444 | 
| 451     /////////////////////////////////////////////////////////////////////////// | 445     /////////////////////////////////////////////////////////////////////////// | 
| 452     /// @name State Flags | 446     /// @name State Flags | 
| 453     //// | 447     //// | 
| 454 | 448 | 
| 455     void resetStateFlags() { | 449     void resetStateFlags() { | 
| 456         fFlagBits = 0; | 450         if (0 != fFlagBits) { | 
| 457         this->invalidateBlendOptFlags(); | 451             fFlagBits = 0; | 
|  | 452             this->invalidateOptState(); | 
|  | 453         } | 
| 458     } | 454     } | 
| 459 | 455 | 
| 460     /** | 456     /** | 
| 461      * Enable render state settings. | 457      * Enable render state settings. | 
| 462      * | 458      * | 
| 463      * @param stateBits bitfield of StateBits specifying the states to enable | 459      * @param stateBits bitfield of StateBits specifying the states to enable | 
| 464      */ | 460      */ | 
| 465     void enableState(uint32_t stateBits) { | 461     void enableState(uint32_t stateBits) { | 
| 466         fFlagBits |= stateBits; | 462         if (stateBits & ~fFlagBits) { | 
| 467         this->invalidateBlendOptFlags(); | 463             fFlagBits |= stateBits; | 
|  | 464             this->invalidateOptState(); | 
|  | 465         } | 
| 468     } | 466     } | 
| 469 | 467 | 
| 470     /** | 468     /** | 
| 471      * Disable render state settings. | 469      * Disable render state settings. | 
| 472      * | 470      * | 
| 473      * @param stateBits bitfield of StateBits specifying the states to disable | 471      * @param stateBits bitfield of StateBits specifying the states to disable | 
| 474      */ | 472      */ | 
| 475     void disableState(uint32_t stateBits) { | 473     void disableState(uint32_t stateBits) { | 
| 476         fFlagBits &= ~(stateBits); | 474         if (stateBits & fFlagBits) { | 
| 477         this->invalidateBlendOptFlags(); | 475             fFlagBits &= ~(stateBits); | 
|  | 476             this->invalidateOptState(); | 
|  | 477         } | 
| 478     } | 478     } | 
| 479 | 479 | 
| 480     /** | 480     /** | 
| 481      * Enable or disable stateBits based on a boolean. | 481      * Enable or disable stateBits based on a boolean. | 
| 482      * | 482      * | 
| 483      * @param stateBits bitfield of StateBits to enable or disable | 483      * @param stateBits bitfield of StateBits to enable or disable | 
| 484      * @param enable    if true enable stateBits, otherwise disable | 484      * @param enable    if true enable stateBits, otherwise disable | 
| 485      */ | 485      */ | 
| 486     void setState(uint32_t stateBits, bool enable) { | 486     void setState(uint32_t stateBits, bool enable) { | 
| 487         if (enable) { | 487         if (enable) { | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 506         fDrawFace = face; | 506         fDrawFace = face; | 
| 507     } | 507     } | 
| 508 | 508 | 
| 509     /// @} | 509     /// @} | 
| 510 | 510 | 
| 511     /////////////////////////////////////////////////////////////////////////// | 511     /////////////////////////////////////////////////////////////////////////// | 
| 512     /// @name Hints | 512     /// @name Hints | 
| 513     /// Hints that when provided can enable optimizations. | 513     /// Hints that when provided can enable optimizations. | 
| 514     //// | 514     //// | 
| 515 | 515 | 
| 516     enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; |  | 
| 517 |  | 
| 518     void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f
     Hints & ~hint); } | 516     void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f
     Hints & ~hint); } | 
| 519 | 517 | 
| 520     /// @} | 518     /// @} | 
| 521 | 519 | 
| 522     /////////////////////////////////////////////////////////////////////////// | 520     /////////////////////////////////////////////////////////////////////////// | 
| 523 | 521 | 
| 524     /** Return type for CombineIfPossible. */ | 522     /** Return type for CombineIfPossible. */ | 
| 525     enum CombinedState { | 523     enum CombinedState { | 
| 526         /** The GrDrawStates cannot be combined. */ | 524         /** The GrDrawStates cannot be combined. */ | 
| 527         kIncompatible_CombinedState, | 525         kIncompatible_CombinedState, | 
| 528         /** Either draw state can be used in place of the other. */ | 526         /** Either draw state can be used in place of the other. */ | 
| 529         kAOrB_CombinedState, | 527         kAOrB_CombinedState, | 
| 530         /** Use the first draw state. */ | 528         /** Use the first draw state. */ | 
| 531         kA_CombinedState, | 529         kA_CombinedState, | 
| 532         /** Use the second draw state. */ | 530         /** Use the second draw state. */ | 
| 533         kB_CombinedState, | 531         kB_CombinedState, | 
| 534     }; | 532     }; | 
| 535 | 533 | 
| 536     /** This function determines whether the GrDrawStates used for two draws can
      be combined into | 534     /** This function determines whether the GrDrawStates used for two draws can
      be combined into | 
| 537         a single GrDrawState. This is used to avoid storing redundant GrDrawStat
     es and to determine | 535         a single GrDrawState. This is used to avoid storing redundant GrDrawStat
     es and to determine | 
| 538         if draws can be batched. The return value indicates whether combining is
      possible and, if | 536         if draws can be batched. The return value indicates whether combining is
      possible and, if | 
| 539         so, which of the two inputs should be used. */ | 537         so, which of the two inputs should be used. */ | 
| 540     static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta
     te& b, | 538     static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta
     te& b, | 
| 541                                            const GrDrawTargetCaps& caps); | 539                                            const GrDrawTargetCaps& caps); | 
| 542 | 540 | 
| 543     GrDrawState& operator= (const GrDrawState& that); | 541     GrDrawState& operator= (const GrDrawState& that); | 
| 544 | 542 | 
|  | 543     /** | 
|  | 544      * Returns a snapshot of the current optimized state. If the current drawSta
     te has a valid | 
|  | 545      * cached optimiezed state it will simply return a pointer to it otherwise i
     t will create a new | 
|  | 546      * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership i
     s given to the | 
|  | 547      * caller. | 
|  | 548      */ | 
|  | 549     GrOptDrawState* createOptState() const; | 
|  | 550 | 
| 545 private: | 551 private: | 
|  | 552     void invalidateOptState() const { | 
|  | 553         SkSafeSetNull(fCachedOptState); | 
|  | 554         fBlendOptFlags = kInvalid_BlendOptFlag; | 
|  | 555     } | 
|  | 556 | 
| 546     void onReset(const SkMatrix* initialViewMatrix); | 557     void onReset(const SkMatrix* initialViewMatrix); | 
| 547 | 558 | 
| 548     /** |  | 
| 549      * Determines whether src alpha is guaranteed to be one for all src pixels |  | 
| 550      */ |  | 
| 551     bool srcAlphaWillBeOne() const; |  | 
| 552 |  | 
| 553     /** |  | 
| 554      * Helper function for getBlendOpts. |  | 
| 555      */ |  | 
| 556     BlendOptFlags calcBlendOpts(bool forceCoverage = false, |  | 
| 557                                 GrBlendCoeff* srcCoeff = NULL, |  | 
| 558                                 GrBlendCoeff* dstCoeff = NULL) const; |  | 
| 559 |  | 
| 560     void invalidateBlendOptFlags() { | 559     void invalidateBlendOptFlags() { | 
| 561         fBlendOptFlags = kInvalid_BlendOptFlag; | 560         fBlendOptFlags = kInvalid_BlendOptFlag; | 
| 562     } | 561     } | 
| 563 | 562 | 
| 564     uint32_t                            fHints; |  | 
| 565 |  | 
| 566     // Some of the auto restore objects assume that no effects are removed durin
     g their lifetime. | 563     // Some of the auto restore objects assume that no effects are removed durin
     g their lifetime. | 
| 567     // This is used to assert that this condition holds. | 564     // This is used to assert that this condition holds. | 
| 568     SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 565     SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 
| 569 | 566 | 
| 570     void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz
     e_t stride); | 567     void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz
     e_t stride); | 
| 571 | 568 | 
|  | 569     mutable GrOptDrawState* fCachedOptState; | 
|  | 570 | 
| 572     typedef GrRODrawState INHERITED; | 571     typedef GrRODrawState INHERITED; | 
| 573 }; | 572 }; | 
| 574 | 573 | 
| 575 #endif | 574 #endif | 
| OLD | NEW | 
|---|