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 12 matching lines...) Expand all Loading... |
23 #include "effects/GrDisableColorXP.h" | 23 #include "effects/GrDisableColorXP.h" |
24 #include "effects/GrPorterDuffXferProcessor.h" | 24 #include "effects/GrPorterDuffXferProcessor.h" |
25 #include "effects/GrSimpleTextureEffect.h" | 25 #include "effects/GrSimpleTextureEffect.h" |
26 | 26 |
27 class GrDrawTargetCaps; | 27 class GrDrawTargetCaps; |
28 class GrPaint; | 28 class GrPaint; |
29 class GrTexture; | 29 class GrTexture; |
30 | 30 |
31 class GrDrawState { | 31 class GrDrawState { |
32 public: | 32 public: |
33 GrDrawState() { | 33 GrDrawState(); |
34 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | |
35 this->reset(); | |
36 } | |
37 | |
38 /** | 34 /** |
39 * Copies another draw state. | 35 * Copies another draw state. |
40 **/ | 36 **/ |
41 GrDrawState(const GrDrawState& state) { | 37 GrDrawState(const GrDrawState& state) { |
42 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 38 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
43 *this = state; | 39 *this = state; |
44 } | 40 } |
45 | 41 |
46 virtual ~GrDrawState(); | 42 virtual ~GrDrawState(); |
47 | 43 |
48 /** | 44 /** |
49 * Resets to the default state. GrProcessors will be removed from all stages
. | |
50 */ | |
51 void reset() { this->onReset(); } | |
52 | |
53 /** | |
54 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that | 45 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that |
55 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint | 46 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint |
56 * equivalents are set to default values with the exception of vertex attrib
ute state which | 47 * equivalents are set to default values with the exception of vertex attrib
ute state which |
57 * is unmodified by this function and clipping which will be enabled. | 48 * is unmodified by this function and clipping which will be enabled. |
58 */ | 49 */ |
59 void setFromPaint(const GrPaint&, GrRenderTarget*); | 50 void setFromPaint(const GrPaint&, GrRenderTarget*); |
60 | 51 |
61 /// @} | 52 /// @} |
62 | 53 |
63 /** | 54 /** |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 /// (usually full-coverage) or interpolated per-vertex coverage. | 86 /// (usually full-coverage) or interpolated per-vertex coverage. |
96 /// | 87 /// |
97 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the | 88 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the |
98 /// the color / coverage distinction. | 89 /// the color / coverage distinction. |
99 //// | 90 //// |
100 | 91 |
101 int numColorStages() const { return fColorStages.count(); } | 92 int numColorStages() const { return fColorStages.count(); } |
102 int numCoverageStages() const { return fCoverageStages.count(); } | 93 int numCoverageStages() const { return fCoverageStages.count(); } |
103 int numFragmentStages() const { return this->numColorStages() + this->numCov
erageStages(); } | 94 int numFragmentStages() const { return this->numColorStages() + this->numCov
erageStages(); } |
104 | 95 |
105 const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } | 96 const GrXPFactory* getXPFactory() const { |
| 97 if (!fXPFactory) { |
| 98 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode
)); |
| 99 } |
| 100 return fXPFactory.get(); |
| 101 } |
106 | 102 |
107 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } | 103 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } |
108 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } | 104 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } |
109 | 105 |
110 /** | 106 /** |
111 * Checks whether the xp will read the dst pixel color. | 107 * Checks whether the xp will read the dst pixel color. |
112 * TODO: remove when we have dstCpy contained inside of GrXP | 108 * TODO: remove when we have dstCpy contained inside of GrXP |
113 */ | 109 */ |
114 bool willEffectReadDstColor() const; | 110 bool willEffectReadDstColor() const; |
115 | 111 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 fDrawFace = face; | 393 fDrawFace = face; |
398 } | 394 } |
399 | 395 |
400 /// @} | 396 /// @} |
401 | 397 |
402 /////////////////////////////////////////////////////////////////////////// | 398 /////////////////////////////////////////////////////////////////////////// |
403 | 399 |
404 GrDrawState& operator= (const GrDrawState& that); | 400 GrDrawState& operator= (const GrDrawState& that); |
405 | 401 |
406 private: | 402 private: |
407 bool isEqual(const GrDrawState& that, bool explicitLocalCoords) const; | |
408 | |
409 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { | 403 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { |
410 this->calcColorInvariantOutput(pp); | 404 this->calcColorInvariantOutput(pp); |
411 return fColorProcInfo; | 405 return fColorProcInfo; |
412 } | 406 } |
413 | 407 |
414 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ | 408 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ |
415 this->calcCoverageInvariantOutput(pp); | 409 this->calcCoverageInvariantOutput(pp); |
416 return fCoverageProcInfo; | 410 return fCoverageProcInfo; |
417 } | 411 } |
418 | 412 |
(...skipping 14 matching lines...) Expand all Loading... |
433 * stages and results are stored in fColorProcInfo. | 427 * stages and results are stored in fColorProcInfo. |
434 */ | 428 */ |
435 void calcColorInvariantOutput(GrColor) const; | 429 void calcColorInvariantOutput(GrColor) const; |
436 | 430 |
437 /** | 431 /** |
438 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage | 432 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage |
439 * stages and results are stored in fCoverageProcInfo. | 433 * stages and results are stored in fCoverageProcInfo. |
440 */ | 434 */ |
441 void calcCoverageInvariantOutput(GrColor) const; | 435 void calcCoverageInvariantOutput(GrColor) const; |
442 | 436 |
443 void onReset(); | |
444 | |
445 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 437 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
446 // This is used to assert that this condition holds. | 438 // This is used to assert that this condition holds. |
447 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 439 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
448 | 440 |
449 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 441 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
450 | 442 |
451 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 443 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
452 uint32_t fFlagBits; | 444 uint32_t fFlagBits; |
453 GrStencilSettings fStencilSettings; | 445 GrStencilSettings fStencilSettings; |
454 DrawFace fDrawFace; | 446 DrawFace fDrawFace; |
455 SkAutoTUnref<const GrXPFactory> fXPFactory; | 447 mutable SkAutoTUnref<const GrXPFactory> fXPFactory; |
456 FragmentStageArray fColorStages; | 448 FragmentStageArray fColorStages; |
457 FragmentStageArray fCoverageStages; | 449 FragmentStageArray fCoverageStages; |
458 | 450 |
459 mutable GrProcOptInfo fColorProcInfo; | 451 mutable GrProcOptInfo fColorProcInfo; |
460 mutable GrProcOptInfo fCoverageProcInfo; | 452 mutable GrProcOptInfo fCoverageProcInfo; |
461 mutable bool fColorProcInfoValid; | 453 mutable bool fColorProcInfoValid; |
462 mutable bool fCoverageProcInfoValid; | 454 mutable bool fCoverageProcInfoValid; |
463 mutable GrColor fColorCache; | 455 mutable GrColor fColorCache; |
464 mutable GrColor fCoverageCache; | 456 mutable GrColor fCoverageCache; |
465 mutable const GrPrimitiveProcessor* fColorPrimProc; | 457 mutable const GrPrimitiveProcessor* fColorPrimProc; |
466 mutable const GrPrimitiveProcessor* fCoveragePrimProc; | 458 mutable const GrPrimitiveProcessor* fCoveragePrimProc; |
467 | 459 |
468 friend class GrOptDrawState; | 460 friend class GrOptDrawState; |
469 }; | 461 }; |
470 | 462 |
471 #endif | 463 #endif |
OLD | NEW |