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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 class GrDrawTargetCaps; | 22 class GrDrawTargetCaps; |
23 class GrOptDrawState; | 23 class GrOptDrawState; |
24 class GrPaint; | 24 class GrPaint; |
25 class GrTexture; | 25 class GrTexture; |
26 | 26 |
27 class GrDrawState : public SkRefCnt { | 27 class GrDrawState : public SkRefCnt { |
28 public: | 28 public: |
29 SK_DECLARE_INST_COUNT(GrDrawState) | 29 SK_DECLARE_INST_COUNT(GrDrawState) |
30 | 30 |
31 GrDrawState() : fCachedOptState(NULL) { | 31 GrDrawState() { |
32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
33 this->reset(); | 33 this->reset(); |
34 } | 34 } |
35 | 35 |
36 GrDrawState(const SkMatrix& initialViewMatrix) : fCachedOptState(NULL) { | 36 GrDrawState(const SkMatrix& initialViewMatrix) { |
37 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 37 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
38 this->reset(initialViewMatrix); | 38 this->reset(initialViewMatrix); |
39 } | 39 } |
40 | 40 |
41 /** | 41 /** |
42 * Copies another draw state. | 42 * Copies another draw state. |
43 **/ | 43 **/ |
44 GrDrawState(const GrDrawState& state) : INHERITED(), fCachedOptState(NULL) { | 44 GrDrawState(const GrDrawState& state) : INHERITED() { |
45 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 45 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
46 *this = state; | 46 *this = state; |
47 } | 47 } |
48 | 48 |
49 /** | 49 /** |
50 * Copies another draw state with a preconcat to the view matrix. | 50 * Copies another draw state with a preconcat to the view matrix. |
51 **/ | 51 **/ |
52 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); | 52 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); |
53 | 53 |
54 virtual ~GrDrawState(); | 54 virtual ~GrDrawState(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 GrColor getColor() const { return fColor; } | 168 GrColor getColor() const { return fColor; } |
169 | 169 |
170 /** | 170 /** |
171 * Sets color for next draw to a premultiplied-alpha color. | 171 * Sets color for next draw to a premultiplied-alpha color. |
172 * | 172 * |
173 * @param color the color to set. | 173 * @param color the color to set. |
174 */ | 174 */ |
175 void setColor(GrColor color) { | 175 void setColor(GrColor color) { |
176 if (color != fColor) { | 176 if (color != fColor) { |
177 fColor = color; | 177 fColor = color; |
178 this->invalidateOptState(); | |
179 } | 178 } |
180 } | 179 } |
181 | 180 |
182 /** | 181 /** |
183 * Sets the color to be used for the next draw to be | 182 * Sets the color to be used for the next draw to be |
184 * (r,g,b,a) = (alpha, alpha, alpha, alpha). | 183 * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
185 * | 184 * |
186 * @param alpha The alpha value to set as the color. | 185 * @param alpha The alpha value to set as the color. |
187 */ | 186 */ |
188 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) |
a); } | 187 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) |
a); } |
(...skipping 11 matching lines...) Expand all Loading... |
200 } | 199 } |
201 | 200 |
202 /** | 201 /** |
203 * Sets a constant fractional coverage to be applied to the draw. The | 202 * Sets a constant fractional coverage to be applied to the draw. The |
204 * initial value (after construction or reset()) is 0xff. The constant | 203 * initial value (after construction or reset()) is 0xff. The constant |
205 * coverage is ignored when per-vertex coverage is provided. | 204 * coverage is ignored when per-vertex coverage is provided. |
206 */ | 205 */ |
207 void setCoverage(uint8_t coverage) { | 206 void setCoverage(uint8_t coverage) { |
208 if (coverage != fCoverage) { | 207 if (coverage != fCoverage) { |
209 fCoverage = coverage; | 208 fCoverage = coverage; |
210 this->invalidateOptState(); | |
211 } | 209 } |
212 } | 210 } |
213 | 211 |
214 /// @} | 212 /// @} |
215 | 213 |
216 /** | 214 /** |
217 * The geometry processor is the sole element of the skia pipeline which can
use the vertex, | 215 * The geometry processor is the sole element of the skia pipeline which can
use the vertex, |
218 * geometry, and tesselation shaders. The GP may also compute a coverage in
its fragment shader | 216 * geometry, and tesselation shaders. The GP may also compute a coverage in
its fragment shader |
219 * but is never put in the color processing pipeline. | 217 * but is never put in the color processing pipeline. |
220 */ | 218 */ |
221 | 219 |
222 const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* g
eometryProcessor) { | 220 const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* g
eometryProcessor) { |
223 SkASSERT(geometryProcessor); | 221 SkASSERT(geometryProcessor); |
224 SkASSERT(!this->hasGeometryProcessor()); | 222 SkASSERT(!this->hasGeometryProcessor()); |
225 fGeometryProcessor.reset(SkRef(geometryProcessor)); | 223 fGeometryProcessor.reset(SkRef(geometryProcessor)); |
226 this->invalidateOptState(); | |
227 return geometryProcessor; | 224 return geometryProcessor; |
228 } | 225 } |
229 | 226 |
230 /////////////////////////////////////////////////////////////////////////// | 227 /////////////////////////////////////////////////////////////////////////// |
231 /// @name Effect Stages | 228 /// @name Effect Stages |
232 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the | 229 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the |
233 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables | 230 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables |
234 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, | 231 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, |
235 /// the fragment position, local coordinates). | 232 /// the fragment position, local coordinates). |
236 /// | 233 /// |
(...skipping 23 matching lines...) Expand all Loading... |
260 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } | 257 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } |
261 | 258 |
262 /** | 259 /** |
263 * Checks whether any of the effects will read the dst pixel color. | 260 * Checks whether any of the effects will read the dst pixel color. |
264 */ | 261 */ |
265 bool willEffectReadDstColor() const; | 262 bool willEffectReadDstColor() const; |
266 | 263 |
267 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { | 264 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { |
268 SkASSERT(effect); | 265 SkASSERT(effect); |
269 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); | 266 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
270 this->invalidateOptState(); | |
271 return effect; | 267 return effect; |
272 } | 268 } |
273 | 269 |
274 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { | 270 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { |
275 SkASSERT(effect); | 271 SkASSERT(effect); |
276 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); | 272 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
277 this->invalidateOptState(); | |
278 return effect; | 273 return effect; |
279 } | 274 } |
280 | 275 |
281 /** | 276 /** |
282 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
ates. | 277 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
ates. |
283 */ | 278 */ |
284 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { | 279 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
285 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))-
>unref(); | 280 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))-
>unref(); |
286 } | 281 } |
287 | 282 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 * color, and D' is the new destination color that will be written. sat() | 403 * color, and D' is the new destination color that will be written. sat() |
409 * is the saturation function. | 404 * is the saturation function. |
410 * | 405 * |
411 * @param srcCoef coefficient applied to the src color. | 406 * @param srcCoef coefficient applied to the src color. |
412 * @param dstCoef coefficient applied to the dst color. | 407 * @param dstCoef coefficient applied to the dst color. |
413 */ | 408 */ |
414 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { | 409 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { |
415 if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) { | 410 if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) { |
416 fSrcBlend = srcCoeff; | 411 fSrcBlend = srcCoeff; |
417 fDstBlend = dstCoeff; | 412 fDstBlend = dstCoeff; |
418 this->invalidateOptState(); | |
419 } | 413 } |
420 #ifdef SK_DEBUG | 414 #ifdef SK_DEBUG |
421 if (GrBlendCoeffRefsDst(dstCoeff)) { | 415 if (GrBlendCoeffRefsDst(dstCoeff)) { |
422 SkDebugf("Unexpected dst blend coeff. Won't work correctly with cove
rage stages.\n"); | 416 SkDebugf("Unexpected dst blend coeff. Won't work correctly with cove
rage stages.\n"); |
423 } | 417 } |
424 if (GrBlendCoeffRefsSrc(srcCoeff)) { | 418 if (GrBlendCoeffRefsSrc(srcCoeff)) { |
425 SkDebugf("Unexpected src blend coeff. Won't work correctly with cove
rage stages.\n"); | 419 SkDebugf("Unexpected src blend coeff. Won't work correctly with cove
rage stages.\n"); |
426 } | 420 } |
427 #endif | 421 #endif |
428 } | 422 } |
429 | 423 |
430 /** | 424 /** |
431 * Sets the blending function constant referenced by the following blending | 425 * Sets the blending function constant referenced by the following blending |
432 * coefficients: | 426 * coefficients: |
433 * kConstC_GrBlendCoeff | 427 * kConstC_GrBlendCoeff |
434 * kIConstC_GrBlendCoeff | 428 * kIConstC_GrBlendCoeff |
435 * kConstA_GrBlendCoeff | 429 * kConstA_GrBlendCoeff |
436 * kIConstA_GrBlendCoeff | 430 * kIConstA_GrBlendCoeff |
437 * | 431 * |
438 * @param constant the constant to set | 432 * @param constant the constant to set |
439 */ | 433 */ |
440 void setBlendConstant(GrColor constant) { | 434 void setBlendConstant(GrColor constant) { |
441 if (constant != fBlendConstant) { | 435 if (constant != fBlendConstant) { |
442 fBlendConstant = constant; | 436 fBlendConstant = constant; |
443 this->invalidateOptState(); | |
444 } | 437 } |
445 } | 438 } |
446 | 439 |
447 /// @} | 440 /// @} |
448 | 441 |
449 /////////////////////////////////////////////////////////////////////////// | 442 /////////////////////////////////////////////////////////////////////////// |
450 /// @name View Matrix | 443 /// @name View Matrix |
451 //// | 444 //// |
452 | 445 |
453 /** | 446 /** |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 */ | 525 */ |
533 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } | 526 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
534 | 527 |
535 /** | 528 /** |
536 * Sets the render-target used at the next drawing call | 529 * Sets the render-target used at the next drawing call |
537 * | 530 * |
538 * @param target The render target to set. | 531 * @param target The render target to set. |
539 */ | 532 */ |
540 void setRenderTarget(GrRenderTarget* target) { | 533 void setRenderTarget(GrRenderTarget* target) { |
541 fRenderTarget.set(SkSafeRef(target), kWrite_GrIOType); | 534 fRenderTarget.set(SkSafeRef(target), kWrite_GrIOType); |
542 this->invalidateOptState(); | |
543 } | 535 } |
544 | 536 |
545 /// @} | 537 /// @} |
546 | 538 |
547 /////////////////////////////////////////////////////////////////////////// | 539 /////////////////////////////////////////////////////////////////////////// |
548 /// @name Stencil | 540 /// @name Stencil |
549 //// | 541 //// |
550 | 542 |
551 const GrStencilSettings& getStencil() const { return fStencilSettings; } | 543 const GrStencilSettings& getStencil() const { return fStencilSettings; } |
552 | 544 |
553 /** | 545 /** |
554 * Sets the stencil settings to use for the next draw. | 546 * Sets the stencil settings to use for the next draw. |
555 * Changing the clip has the side-effect of possibly zeroing | 547 * Changing the clip has the side-effect of possibly zeroing |
556 * out the client settable stencil bits. So multipass algorithms | 548 * out the client settable stencil bits. So multipass algorithms |
557 * using stencil should not change the clip between passes. | 549 * using stencil should not change the clip between passes. |
558 * @param settings the stencil settings to use. | 550 * @param settings the stencil settings to use. |
559 */ | 551 */ |
560 void setStencil(const GrStencilSettings& settings) { | 552 void setStencil(const GrStencilSettings& settings) { |
561 if (settings != fStencilSettings) { | 553 if (settings != fStencilSettings) { |
562 fStencilSettings = settings; | 554 fStencilSettings = settings; |
563 this->invalidateOptState(); | |
564 } | 555 } |
565 } | 556 } |
566 | 557 |
567 /** | 558 /** |
568 * Shortcut to disable stencil testing and ops. | 559 * Shortcut to disable stencil testing and ops. |
569 */ | 560 */ |
570 void disableStencil() { | 561 void disableStencil() { |
571 if (!fStencilSettings.isDisabled()) { | 562 if (!fStencilSettings.isDisabled()) { |
572 fStencilSettings.setDisabled(); | 563 fStencilSettings.setDisabled(); |
573 this->invalidateOptState(); | |
574 } | 564 } |
575 } | 565 } |
576 | 566 |
577 GrStencilSettings* stencil() { return &fStencilSettings; } | 567 GrStencilSettings* stencil() { return &fStencilSettings; } |
578 | 568 |
579 /// @} | 569 /// @} |
580 | 570 |
581 /////////////////////////////////////////////////////////////////////////// | 571 /////////////////////////////////////////////////////////////////////////// |
582 /// @name State Flags | 572 /// @name State Flags |
583 //// | 573 //// |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 | 613 |
624 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f
FlagBits); } | 614 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f
FlagBits); } |
625 | 615 |
626 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } | 616 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } |
627 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_
StateBit); } | 617 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_
StateBit); } |
628 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S
tateBit); } | 618 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S
tateBit); } |
629 | 619 |
630 void resetStateFlags() { | 620 void resetStateFlags() { |
631 if (0 != fFlagBits) { | 621 if (0 != fFlagBits) { |
632 fFlagBits = 0; | 622 fFlagBits = 0; |
633 this->invalidateOptState(); | |
634 } | 623 } |
635 } | 624 } |
636 | 625 |
637 /** | 626 /** |
638 * Enable render state settings. | 627 * Enable render state settings. |
639 * | 628 * |
640 * @param stateBits bitfield of StateBits specifying the states to enable | 629 * @param stateBits bitfield of StateBits specifying the states to enable |
641 */ | 630 */ |
642 void enableState(uint32_t stateBits) { | 631 void enableState(uint32_t stateBits) { |
643 if (stateBits & ~fFlagBits) { | 632 if (stateBits & ~fFlagBits) { |
644 fFlagBits |= stateBits; | 633 fFlagBits |= stateBits; |
645 this->invalidateOptState(); | |
646 } | 634 } |
647 } | 635 } |
648 | 636 |
649 /** | 637 /** |
650 * Disable render state settings. | 638 * Disable render state settings. |
651 * | 639 * |
652 * @param stateBits bitfield of StateBits specifying the states to disable | 640 * @param stateBits bitfield of StateBits specifying the states to disable |
653 */ | 641 */ |
654 void disableState(uint32_t stateBits) { | 642 void disableState(uint32_t stateBits) { |
655 if (stateBits & fFlagBits) { | 643 if (stateBits & fFlagBits) { |
656 fFlagBits &= ~(stateBits); | 644 fFlagBits &= ~(stateBits); |
657 this->invalidateOptState(); | |
658 } | 645 } |
659 } | 646 } |
660 | 647 |
661 /** | 648 /** |
662 * Enable or disable stateBits based on a boolean. | 649 * Enable or disable stateBits based on a boolean. |
663 * | 650 * |
664 * @param stateBits bitfield of StateBits to enable or disable | 651 * @param stateBits bitfield of StateBits to enable or disable |
665 * @param enable if true enable stateBits, otherwise disable | 652 * @param enable if true enable stateBits, otherwise disable |
666 */ | 653 */ |
667 void setState(uint32_t stateBits, bool enable) { | 654 void setState(uint32_t stateBits, bool enable) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 */ | 789 */ |
803 BlendOptFlags getBlendOpts(bool forceCoverage = false, | 790 BlendOptFlags getBlendOpts(bool forceCoverage = false, |
804 GrBlendCoeff* srcCoeff = NULL, | 791 GrBlendCoeff* srcCoeff = NULL, |
805 GrBlendCoeff* dstCoeff = NULL) const; | 792 GrBlendCoeff* dstCoeff = NULL) const; |
806 | 793 |
807 /** | 794 /** |
808 * Determines whether src alpha is guaranteed to be one for all src pixels | 795 * Determines whether src alpha is guaranteed to be one for all src pixels |
809 */ | 796 */ |
810 bool srcAlphaWillBeOne() const; | 797 bool srcAlphaWillBeOne() const; |
811 | 798 |
812 void invalidateOptState() const; | |
813 | |
814 void onReset(const SkMatrix* initialViewMatrix); | 799 void onReset(const SkMatrix* initialViewMatrix); |
815 | 800 |
816 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 801 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
817 // This is used to assert that this condition holds. | 802 // This is used to assert that this condition holds. |
818 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 803 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
819 | 804 |
820 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz
e_t stride); | 805 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz
e_t stride); |
821 | 806 |
822 typedef GrTGpuResourceRef<GrRenderTarget> ProgramRenderTarget; | 807 typedef GrTGpuResourceRef<GrRenderTarget> ProgramRenderTarget; |
823 // These fields are roughly sorted by decreasing likelihood of being differe
nt in op== | 808 // These fields are roughly sorted by decreasing likelihood of being differe
nt in op== |
(...skipping 16 matching lines...) Expand all Loading... |
840 ProgramGeometryProcessor fGeometryProcessor; | 825 ProgramGeometryProcessor fGeometryProcessor; |
841 FragmentStageArray fColorStages; | 826 FragmentStageArray fColorStages; |
842 FragmentStageArray fCoverageStages; | 827 FragmentStageArray fCoverageStages; |
843 | 828 |
844 uint32_t fHints; | 829 uint32_t fHints; |
845 | 830 |
846 // This is simply a different representation of info in fVertexAttribs and t
hus does | 831 // This is simply a different representation of info in fVertexAttribs and t
hus does |
847 // not need to be compared in op==. | 832 // not need to be compared in op==. |
848 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; | 833 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt
]; |
849 | 834 |
850 mutable GrOptDrawState* fCachedOptState; | |
851 mutable uint32_t fCachedCapsID; | |
852 | |
853 friend class GrOptDrawState; | 835 friend class GrOptDrawState; |
854 | 836 |
855 typedef SkRefCnt INHERITED; | 837 typedef SkRefCnt INHERITED; |
856 }; | 838 }; |
857 | 839 |
858 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 840 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
859 | 841 |
860 #endif | 842 #endif |
OLD | NEW |