| 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 "GrProcOptInfo.h" | 15 #include "GrProcOptInfo.h" |
| 16 #include "GrProcessorDataManager.h" | |
| 17 #include "GrRenderTarget.h" | 16 #include "GrRenderTarget.h" |
| 18 #include "GrStencil.h" | 17 #include "GrStencil.h" |
| 19 #include "GrXferProcessor.h" | 18 #include "GrXferProcessor.h" |
| 20 #include "SkMatrix.h" | 19 #include "SkMatrix.h" |
| 21 #include "effects/GrCoverageSetOpXP.h" | 20 #include "effects/GrCoverageSetOpXP.h" |
| 22 #include "effects/GrDisableColorXP.h" | 21 #include "effects/GrDisableColorXP.h" |
| 23 #include "effects/GrPorterDuffXferProcessor.h" | 22 #include "effects/GrPorterDuffXferProcessor.h" |
| 24 #include "effects/GrSimpleTextureEffect.h" | 23 #include "effects/GrSimpleTextureEffect.h" |
| 25 | 24 |
| 26 class GrDrawBatch; | 25 class GrDrawBatch; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProc
essor* processor) { | 72 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProc
essor* processor) { |
| 74 SkASSERT(processor); | 73 SkASSERT(processor); |
| 75 fCoverageFragmentProcessors.push_back(SkRef(processor)); | 74 fCoverageFragmentProcessors.push_back(SkRef(processor)); |
| 76 return processor; | 75 return processor; |
| 77 } | 76 } |
| 78 | 77 |
| 79 /** | 78 /** |
| 80 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
ates. | 79 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin
ates. |
| 81 */ | 80 */ |
| 82 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { | 81 void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 83 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(&fProcData
Manager, texture, | 82 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, m
atrix))->unref(); |
| 84 matrix))->
unref(); | |
| 85 } | 83 } |
| 86 | 84 |
| 87 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix)
{ | 85 void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix)
{ |
| 88 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(&fProcD
ataManager, texture, | 86 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture
, matrix))->unref(); |
| 89 matrix)
)->unref(); | |
| 90 } | 87 } |
| 91 | 88 |
| 92 void addColorTextureProcessor(GrTexture* texture, | 89 void addColorTextureProcessor(GrTexture* texture, |
| 93 const SkMatrix& matrix, | 90 const SkMatrix& matrix, |
| 94 const GrTextureParams& params) { | 91 const GrTextureParams& params) { |
| 95 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(&fProcData
Manager, texture, | 92 this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, m
atrix, |
| 96 matrix, | |
| 97 params))->
unref(); | 93 params))->
unref(); |
| 98 } | 94 } |
| 99 | 95 |
| 100 void addCoverageTextureProcessor(GrTexture* texture, | 96 void addCoverageTextureProcessor(GrTexture* texture, |
| 101 const SkMatrix& matrix, | 97 const SkMatrix& matrix, |
| 102 const GrTextureParams& params) { | 98 const GrTextureParams& params) { |
| 103 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(&fProcD
ataManager, texture, | 99 this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture
, matrix, |
| 104 matrix,
params))->unref(); | 100 params)
)->unref(); |
| 105 } | 101 } |
| 106 | 102 |
| 107 /** | 103 /** |
| 108 * When this object is destroyed it will remove any color/coverage FPs from
the pipeline builder | 104 * 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 | 105 * that were added after its constructor. |
| 110 * constructor. | |
| 111 * This class can transiently modify its "const" GrPipelineBuilder object bu
t will restore it | 106 * This class can transiently modify its "const" GrPipelineBuilder object bu
t will restore it |
| 112 * when done - so it is notionally "const" correct. | 107 * when done - so it is notionally "const" correct. |
| 113 */ | 108 */ |
| 114 class AutoRestoreFragmentProcessorState : public ::SkNoncopyable { | 109 class AutoRestoreFragmentProcessorState : public ::SkNoncopyable { |
| 115 public: | 110 public: |
| 116 AutoRestoreFragmentProcessorState() | 111 AutoRestoreFragmentProcessorState() |
| 117 : fPipelineBuilder(nullptr) | 112 : fPipelineBuilder(nullptr) |
| 118 , fColorEffectCnt(0) | 113 , fColorEffectCnt(0) |
| 119 , fCoverageEffectCnt(0) {} | 114 , fCoverageEffectCnt(0) {} |
| 120 | 115 |
| 121 AutoRestoreFragmentProcessorState(const GrPipelineBuilder& ds) | 116 AutoRestoreFragmentProcessorState(const GrPipelineBuilder& ds) |
| 122 : fPipelineBuilder(nullptr) | 117 : fPipelineBuilder(nullptr) |
| 123 , fColorEffectCnt(0) | 118 , fColorEffectCnt(0) |
| 124 , fCoverageEffectCnt(0) { | 119 , fCoverageEffectCnt(0) { |
| 125 this->set(&ds); | 120 this->set(&ds); |
| 126 } | 121 } |
| 127 | 122 |
| 128 ~AutoRestoreFragmentProcessorState() { this->set(nullptr); } | 123 ~AutoRestoreFragmentProcessorState() { this->set(nullptr); } |
| 129 | 124 |
| 130 void set(const GrPipelineBuilder* ds); | 125 void set(const GrPipelineBuilder* ds); |
| 131 | 126 |
| 132 bool isSet() const { return SkToBool(fPipelineBuilder); } | 127 bool isSet() const { return SkToBool(fPipelineBuilder); } |
| 133 | 128 |
| 134 GrProcessorDataManager* getProcessorDataManager() { | 129 const GrFragmentProcessor* addCoverageFragmentProcessor( |
| 135 SkASSERT(this->isSet()); | 130 const GrFragmentProcessor* processor) { |
| 136 return fPipelineBuilder->getProcessorDataManager(); | |
| 137 } | |
| 138 | |
| 139 const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragment
Processor* processor) { | |
| 140 SkASSERT(this->isSet()); | 131 SkASSERT(this->isSet()); |
| 141 return fPipelineBuilder->addCoverageFragmentProcessor(processor); | 132 return fPipelineBuilder->addCoverageFragmentProcessor(processor); |
| 142 } | 133 } |
| 143 | 134 |
| 144 private: | 135 private: |
| 145 // notionally const (as marginalia) | 136 // notionally const (as marginalia) |
| 146 GrPipelineBuilder* fPipelineBuilder; | 137 GrPipelineBuilder* fPipelineBuilder; |
| 147 int fColorEffectCnt; | 138 int fColorEffectCnt; |
| 148 int fCoverageEffectCnt; | 139 int fCoverageEffectCnt; |
| 149 }; | 140 }; |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 } | 373 } |
| 383 | 374 |
| 384 const GrProcOptInfo& coverageProcInfo(const GrDrawBatch* batch) const { | 375 const GrProcOptInfo& coverageProcInfo(const GrDrawBatch* batch) const { |
| 385 this->calcCoverageInvariantOutput(batch); | 376 this->calcCoverageInvariantOutput(batch); |
| 386 return fCoverageProcInfo; | 377 return fCoverageProcInfo; |
| 387 } | 378 } |
| 388 | 379 |
| 389 void setClip(const GrClip& clip) { fClip = clip; } | 380 void setClip(const GrClip& clip) { fClip = clip; } |
| 390 const GrClip& clip() const { return fClip; } | 381 const GrClip& clip() const { return fClip; } |
| 391 | 382 |
| 392 GrProcessorDataManager* getProcessorDataManager() { return &fProcDataManager
; } | |
| 393 const GrProcessorDataManager* processorDataManager() const { return &fProcDa
taManager; } | |
| 394 | |
| 395 private: | 383 private: |
| 396 // Calculating invariant color / coverage information is expensive, so we pa
rtially cache the | 384 // Calculating invariant color / coverage information is expensive, so we pa
rtially cache the |
| 397 // results. | 385 // results. |
| 398 // | 386 // |
| 399 // canUseFracCoveragePrimProc() - Called in regular skia draw, caches result
s but only for a | 387 // canUseFracCoveragePrimProc() - Called in regular skia draw, caches result
s but only for a |
| 400 // specific color and coverage. May be calle
d multiple times | 388 // specific color and coverage. May be calle
d multiple times |
| 401 // GrOptDrawState constructor - never caches results | 389 // GrOptDrawState constructor - never caches results |
| 402 | 390 |
| 403 /** | 391 /** |
| 404 * GrBatch provides the initial seed for these loops based off of its initia
l geometry data | 392 * GrBatch provides the initial seed for these loops based off of its initia
l geometry data |
| 405 */ | 393 */ |
| 406 void calcColorInvariantOutput(const GrDrawBatch*) const; | 394 void calcColorInvariantOutput(const GrDrawBatch*) const; |
| 407 void calcCoverageInvariantOutput(const GrDrawBatch*) const; | 395 void calcCoverageInvariantOutput(const GrDrawBatch*) const; |
| 408 | 396 |
| 409 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 397 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
| 410 // This is used to assert that this condition holds. | 398 // This is used to assert that this condition holds. |
| 411 SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;) | 399 SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;) |
| 412 | 400 |
| 413 typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArra
y; | 401 typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArra
y; |
| 414 | 402 |
| 415 GrProcessorDataManager fProcDataManager; | |
| 416 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 403 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 417 uint32_t fFlags; | 404 uint32_t fFlags; |
| 418 GrStencilSettings fStencilSettings; | 405 GrStencilSettings fStencilSettings; |
| 419 DrawFace fDrawFace; | 406 DrawFace fDrawFace; |
| 420 mutable SkAutoTUnref<const GrXPFactory> fXPFactory; | 407 mutable SkAutoTUnref<const GrXPFactory> fXPFactory; |
| 421 FragmentProcessorArray fColorFragmentProcessors; | 408 FragmentProcessorArray fColorFragmentProcessors; |
| 422 FragmentProcessorArray fCoverageFragmentProcessors; | 409 FragmentProcessorArray fCoverageFragmentProcessors; |
| 423 GrClip fClip; | 410 GrClip fClip; |
| 424 | 411 |
| 425 mutable GrProcOptInfo fColorProcInfo; | 412 mutable GrProcOptInfo fColorProcInfo; |
| 426 mutable GrProcOptInfo fCoverageProcInfo; | 413 mutable GrProcOptInfo fCoverageProcInfo; |
| 427 | 414 |
| 428 friend class GrPipeline; | 415 friend class GrPipeline; |
| 429 }; | 416 }; |
| 430 | 417 |
| 431 #endif | 418 #endif |
| OLD | NEW |