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