OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 GrPipelineBuilder_DEFINED | 8 #ifndef GrPipelineBuilder_DEFINED |
9 #define GrPipelineBuilder_DEFINED | 9 #define GrPipelineBuilder_DEFINED |
10 | 10 |
11 #include "GrBlend.h" | 11 #include "GrBlend.h" |
12 #include "GrCaps.h" | 12 #include "GrCaps.h" |
13 #include "GrClip.h" | 13 #include "GrClip.h" |
14 #include "GrGpuResourceRef.h" | 14 #include "GrGpuResourceRef.h" |
| 15 #include "GrStagedProcessor.h" |
15 #include "GrProcOptInfo.h" | 16 #include "GrProcOptInfo.h" |
16 #include "GrProcessorDataManager.h" | 17 #include "GrProcessorDataManager.h" |
17 #include "GrRenderTarget.h" | 18 #include "GrRenderTarget.h" |
18 #include "GrStencil.h" | 19 #include "GrStencil.h" |
19 #include "GrXferProcessor.h" | 20 #include "GrXferProcessor.h" |
20 #include "SkMatrix.h" | 21 #include "SkMatrix.h" |
21 #include "effects/GrCoverageSetOpXP.h" | 22 #include "effects/GrCoverageSetOpXP.h" |
22 #include "effects/GrDisableColorXP.h" | 23 #include "effects/GrDisableColorXP.h" |
23 #include "effects/GrPorterDuffXferProcessor.h" | 24 #include "effects/GrPorterDuffXferProcessor.h" |
24 #include "effects/GrSimpleTextureEffect.h" | 25 #include "effects/GrSimpleTextureEffect.h" |
25 | 26 |
26 class GrDrawBatch; | 27 class GrDrawBatch; |
27 class GrCaps; | 28 class GrCaps; |
28 class GrPaint; | 29 class GrPaint; |
29 class GrTexture; | 30 class GrTexture; |
30 | 31 |
31 class GrPipelineBuilder : public SkNoncopyable { | 32 class GrPipelineBuilder { |
32 public: | 33 public: |
33 GrPipelineBuilder(); | 34 GrPipelineBuilder(); |
34 | 35 |
| 36 GrPipelineBuilder(const GrPipelineBuilder& pipelineBuilder) { |
| 37 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
| 38 *this = pipelineBuilder; |
| 39 } |
| 40 |
35 /** | 41 /** |
36 * Initializes the GrPipelineBuilder based on a GrPaint, render target, and
clip. Note | 42 * Initializes the GrPipelineBuilder based on a GrPaint, render target, and
clip. Note |
37 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipeli
neBuilder that have | 43 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipeli
neBuilder that have |
38 * no GrPaint equivalents are set to default values with the exception of ve
rtex attribute state | 44 * no GrPaint equivalents are set to default values with the exception of ve
rtex attribute state |
39 * which is unmodified by this function and clipping which will be enabled. | 45 * which is unmodified by this function and clipping which will be enabled. |
40 */ | 46 */ |
41 GrPipelineBuilder(const GrPaint&, GrRenderTarget*, const GrClip&); | 47 GrPipelineBuilder(const GrPaint&, GrRenderTarget*, const GrClip&); |
42 | 48 |
43 virtual ~GrPipelineBuilder(); | 49 virtual ~GrPipelineBuilder(); |
44 | 50 |
45 /////////////////////////////////////////////////////////////////////////// | 51 /////////////////////////////////////////////////////////////////////////// |
46 /// @name Fragment Processors | 52 /// @name Fragment Processors |
47 /// | 53 /// |
48 /// GrFragmentProcessors are used to compute per-pixel color and per-pixel f
ractional coverage. | 54 /// GrFragmentProcessors are used to compute per-pixel color and per-pixel f
ractional coverage. |
49 /// There are two chains of FPs, one for color and one for coverage. The fir
st FP in each | 55 /// There are two chains of FPs, one for color and one for coverage. The fir
st FP in each |
50 /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It
computes an output | 56 /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It
computes an output |
51 /// color/coverage which is fed to the next FP in the chain. The last color
and coverage FPs | 57 /// color/coverage which is fed to the next FP in the chain. The last color
and coverage FPs |
52 /// feed their output to the GrXferProcessor which controls blending. | 58 /// feed their output to the GrXferProcessor which controls blending. |
53 //// | 59 //// |
54 | 60 |
55 int numColorFragmentProcessors() const { return fColorFragmentProcessors.cou
nt(); } | 61 int numColorFragmentStages() const { return fColorStages.count(); } |
56 int numCoverageFragmentProcessors() const { return fCoverageFragmentProcesso
rs.count(); } | 62 int numCoverageFragmentStages() const { return fCoverageStages.count(); } |
57 int numFragmentProcessors() const { return this->numColorFragmentProcessors(
) + | 63 int numFragmentStages() const { return this->numColorFragmentStages() + |
58 this->numCoverageFragmentProcesso
rs(); } | 64 this->numCoverageFragmentStages()
; } |
59 | 65 |
60 const GrFragmentProcessor* getColorFragmentProcessor(int idx) const { | 66 const GrFragmentStage& getColorFragmentStage(int idx) const { return fColorS
tages[idx]; } |
61 return fColorFragmentProcessors[idx]; | 67 const GrFragmentStage& getCoverageFragmentStage(int idx) const { return fCov
erageStages[idx]; } |
62 } | 68 |
63 const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const { | 69 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { |
64 return fCoverageFragmentProcessors[idx]; | 70 SkASSERT(effect); |
| 71 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
| 72 return effect; |
65 } | 73 } |
66 | 74 |
67 const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcess
or* processor) { | 75 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { |
68 SkASSERT(processor); | 76 SkASSERT(effect); |
69 fColorFragmentProcessors.push_back(SkRef(processor)); | 77 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
70 return processor; | 78 return effect; |
71 } | |
72 | |
73 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProc
essor* processor) { | |
74 SkASSERT(processor); | |
75 fCoverageFragmentProcessors.push_back(SkRef(processor)); | |
76 return processor; | |
77 } | 79 } |
78 | 80 |
79 /** | 81 /** |
80 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
ates. | 82 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
ates. |
81 */ | 83 */ |
82 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { | 84 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
83 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataM
anager, texture, | 85 this->addColorProcessor(GrSimpleTextureEffect::Create(fProcDataManager,
texture, |
84 matrix))->
unref(); | 86 matrix))->unref(); |
85 } | 87 } |
86 | 88 |
87 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix)
{ | 89 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix)
{ |
88 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDa
taManager, texture, | 90 this->addCoverageProcessor(GrSimpleTextureEffect::Create(fProcDataManage
r, texture, |
89 matrix)
)->unref(); | 91 matrix))->unref
(); |
90 } | 92 } |
91 | 93 |
92 void addColorTextureProcessor(GrTexture* texture, | 94 void addColorTextureProcessor(GrTexture* texture, |
93 const SkMatrix& matrix, | 95 const SkMatrix& matrix, |
94 const GrTextureParams& params) { | 96 const GrTextureParams& params) { |
95 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(fProcDataM
anager, texture, | 97 this->addColorProcessor(GrSimpleTextureEffect::Create(fProcDataManager,
texture, matrix, |
96 matrix, | 98 params))->unref(); |
97 params))->
unref(); | |
98 } | 99 } |
99 | 100 |
100 void addCoverageTextureProcessor(GrTexture* texture, | 101 void addCoverageTextureProcessor(GrTexture* texture, |
101 const SkMatrix& matrix, | 102 const SkMatrix& matrix, |
102 const GrTextureParams& params) { | 103 const GrTextureParams& params) { |
103 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(fProcDa
taManager, texture, | 104 this->addCoverageProcessor(GrSimpleTextureEffect::Create(fProcDataManage
r, texture, matrix, |
104 matrix,
params))->unref(); | 105 params))->unref
(); |
105 } | 106 } |
106 | 107 |
107 /** | 108 /** |
108 * When this object is destroyed it will remove any color/coverage FPs from
the pipeline builder | 109 * When this object is destroyed it will remove any color/coverage FPs from
the pipeline builder |
109 * and also remove any additions to the GrProcessorDataManager that were add
ed after its | 110 * and also remove any additions to the GrProcessorDataManager that were add
ed after its |
110 * constructor. | 111 * constructor. |
111 * This class can transiently modify its "const" GrPipelineBuilder object bu
t will restore it | 112 * This class can transiently modify its "const" GrPipelineBuilder object bu
t will restore it |
112 * when done - so it is notionally "const" correct. | 113 * when done - so it is notionally "const" correct. |
113 */ | 114 */ |
114 class AutoRestoreFragmentProcessorState : public ::SkNoncopyable { | 115 class AutoRestoreFragmentProcessorState : public ::SkNoncopyable { |
(...skipping 16 matching lines...) Expand all Loading... |
131 | 132 |
132 void set(const GrPipelineBuilder* ds); | 133 void set(const GrPipelineBuilder* ds); |
133 | 134 |
134 bool isSet() const { return SkToBool(fPipelineBuilder); } | 135 bool isSet() const { return SkToBool(fPipelineBuilder); } |
135 | 136 |
136 GrProcessorDataManager* getProcessorDataManager() { | 137 GrProcessorDataManager* getProcessorDataManager() { |
137 SkASSERT(this->isSet()); | 138 SkASSERT(this->isSet()); |
138 return fPipelineBuilder->getProcessorDataManager(); | 139 return fPipelineBuilder->getProcessorDataManager(); |
139 } | 140 } |
140 | 141 |
141 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragment
Processor* processor) { | 142 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcesso
r* processor) { |
142 SkASSERT(this->isSet()); | 143 SkASSERT(this->isSet()); |
143 return fPipelineBuilder->addCoverageFragmentProcessor(processor); | 144 return fPipelineBuilder->addCoverageProcessor(processor); |
144 } | 145 } |
145 | 146 |
146 private: | 147 private: |
147 // notionally const (as marginalia) | 148 // notionally const (as marginalia) |
148 GrPipelineBuilder* fPipelineBuilder; | 149 GrPipelineBuilder* fPipelineBuilder; |
149 int fColorEffectCnt; | 150 int fColorEffectCnt; |
150 int fCoverageEffectCnt; | 151 int fCoverageEffectCnt; |
151 uint32_t fSaveMarker; | 152 uint32_t fSaveMarker; |
152 }; | 153 }; |
153 | 154 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 */ | 378 */ |
378 void setDrawFace(DrawFace face) { | 379 void setDrawFace(DrawFace face) { |
379 SkASSERT(kInvalid_DrawFace != face); | 380 SkASSERT(kInvalid_DrawFace != face); |
380 fDrawFace = face; | 381 fDrawFace = face; |
381 } | 382 } |
382 | 383 |
383 /// @} | 384 /// @} |
384 | 385 |
385 /////////////////////////////////////////////////////////////////////////// | 386 /////////////////////////////////////////////////////////////////////////// |
386 | 387 |
| 388 GrPipelineBuilder& operator=(const GrPipelineBuilder& that); |
| 389 |
387 // TODO delete when we have Batch | 390 // TODO delete when we have Batch |
388 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { | 391 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { |
389 this->calcColorInvariantOutput(pp); | 392 this->calcColorInvariantOutput(pp); |
390 return fColorProcInfo; | 393 return fColorProcInfo; |
391 } | 394 } |
392 | 395 |
393 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ | 396 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ |
394 this->calcCoverageInvariantOutput(pp); | 397 this->calcCoverageInvariantOutput(pp); |
395 return fCoverageProcInfo; | 398 return fCoverageProcInfo; |
396 } | 399 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 /** | 432 /** |
430 * GrBatch provides the initial seed for these loops based off of its initia
l geometry data | 433 * GrBatch provides the initial seed for these loops based off of its initia
l geometry data |
431 */ | 434 */ |
432 void calcColorInvariantOutput(const GrDrawBatch*) const; | 435 void calcColorInvariantOutput(const GrDrawBatch*) const; |
433 void calcCoverageInvariantOutput(const GrDrawBatch*) const; | 436 void calcCoverageInvariantOutput(const GrDrawBatch*) const; |
434 | 437 |
435 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 438 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
436 // This is used to assert that this condition holds. | 439 // This is used to assert that this condition holds. |
437 SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;) | 440 SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;) |
438 | 441 |
439 typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArra
y; | 442 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
440 | 443 |
441 SkAutoTUnref<GrProcessorDataManager> fProcDataManager; | 444 SkAutoTUnref<GrProcessorDataManager> fProcDataManager; |
442 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 445 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
443 uint32_t fFlags; | 446 uint32_t fFlags; |
444 GrStencilSettings fStencilSettings; | 447 GrStencilSettings fStencilSettings; |
445 DrawFace fDrawFace; | 448 DrawFace fDrawFace; |
446 mutable SkAutoTUnref<const GrXPFactory> fXPFactory; | 449 mutable SkAutoTUnref<const GrXPFactory> fXPFactory; |
447 FragmentProcessorArray fColorFragmentProcessors; | 450 FragmentStageArray fColorStages; |
448 FragmentProcessorArray fCoverageFragmentProcessors; | 451 FragmentStageArray fCoverageStages; |
449 GrClip fClip; | 452 GrClip fClip; |
450 | 453 |
451 mutable GrProcOptInfo fColorProcInfo; | 454 mutable GrProcOptInfo fColorProcInfo; |
452 mutable GrProcOptInfo fCoverageProcInfo; | 455 mutable GrProcOptInfo fCoverageProcInfo; |
453 | 456 |
454 friend class GrPipeline; | 457 friend class GrPipeline; |
455 }; | 458 }; |
456 | 459 |
457 #endif | 460 #endif |
OLD | NEW |