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 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 void addCoverageTextureProcessor(GrTexture* texture, | 103 void addCoverageTextureProcessor(GrTexture* texture, |
104 const SkMatrix& matrix, | 104 const SkMatrix& matrix, |
105 const GrTextureParams& params) { | 105 const GrTextureParams& params) { |
106 this->addCoverageProcessor(GrSimpleTextureEffect::Create(fProcDataManage
r, texture, matrix, | 106 this->addCoverageProcessor(GrSimpleTextureEffect::Create(fProcDataManage
r, texture, matrix, |
107 params))->unref
(); | 107 params))->unref
(); |
108 } | 108 } |
109 | 109 |
110 /** | 110 /** |
111 * When this object is destroyed it will remove any color/coverage FPs from
the pipeline builder | 111 * When this object is destroyed it will remove any color/coverage FPs from
the pipeline builder |
112 * that were added after its constructor. | 112 * that were added after its constructor. |
| 113 * This class can transiently modify its "const" GrPipelineBuilder object bu
t will restore it |
| 114 * when done - so it is notionally "const" correct. |
113 */ | 115 */ |
114 class AutoRestoreFragmentProcessors : public ::SkNoncopyable { | 116 class AutoRestoreFragmentProcessors : public ::SkNoncopyable { |
115 public: | 117 public: |
116 AutoRestoreFragmentProcessors() | 118 AutoRestoreFragmentProcessors() |
117 : fPipelineBuilder(NULL) | 119 : fPipelineBuilder(NULL) |
118 , fColorEffectCnt(0) | 120 , fColorEffectCnt(0) |
119 , fCoverageEffectCnt(0) {} | 121 , fCoverageEffectCnt(0) {} |
120 | 122 |
121 AutoRestoreFragmentProcessors(GrPipelineBuilder* ds) | 123 AutoRestoreFragmentProcessors(GrPipelineBuilder* ds) |
122 : fPipelineBuilder(NULL) | 124 : fPipelineBuilder(NULL) |
123 , fColorEffectCnt(0) | 125 , fColorEffectCnt(0) |
124 , fCoverageEffectCnt(0) { | 126 , fCoverageEffectCnt(0) { |
125 this->set(ds); | 127 this->set(ds); |
126 } | 128 } |
127 | 129 |
128 ~AutoRestoreFragmentProcessors() { this->set(NULL); } | 130 ~AutoRestoreFragmentProcessors() { this->set(NULL); } |
129 | 131 |
130 void set(GrPipelineBuilder* ds); | 132 void set(const GrPipelineBuilder* ds); |
131 | 133 |
132 bool isSet() const { return SkToBool(fPipelineBuilder); } | 134 bool isSet() const { return SkToBool(fPipelineBuilder); } |
133 | 135 |
| 136 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcesso
r* processor) { |
| 137 SkASSERT(this->isSet()); |
| 138 return fPipelineBuilder->addCoverageProcessor(processor); |
| 139 } |
| 140 |
134 private: | 141 private: |
| 142 // notionally const (as marginalia) |
135 GrPipelineBuilder* fPipelineBuilder; | 143 GrPipelineBuilder* fPipelineBuilder; |
136 int fColorEffectCnt; | 144 int fColorEffectCnt; |
137 int fCoverageEffectCnt; | 145 int fCoverageEffectCnt; |
138 }; | 146 }; |
139 | 147 |
140 /// @} | 148 /// @} |
141 | 149 |
142 /////////////////////////////////////////////////////////////////////////// | 150 /////////////////////////////////////////////////////////////////////////// |
143 /// @name Blending | 151 /// @name Blending |
144 //// | 152 //// |
145 | 153 |
146 /** | 154 /** |
147 * Returns true if this pipeline's color output will be affected by the exis
ting render target | 155 * Returns true if this pipeline's color output will be affected by the exis
ting render target |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 * Shortcut to disable stencil testing and ops. | 247 * Shortcut to disable stencil testing and ops. |
240 */ | 248 */ |
241 void disableStencil() { fStencilSettings.setDisabled(); } | 249 void disableStencil() { fStencilSettings.setDisabled(); } |
242 | 250 |
243 GrStencilSettings* stencil() { return &fStencilSettings; } | 251 GrStencilSettings* stencil() { return &fStencilSettings; } |
244 | 252 |
245 /** | 253 /** |
246 * AutoRestoreStencil | 254 * AutoRestoreStencil |
247 * | 255 * |
248 * This simple struct saves and restores the stencil settings | 256 * This simple struct saves and restores the stencil settings |
| 257 * This class can transiently modify its "const" GrPipelineBuilder object bu
t will restore it |
| 258 * when done - so it is notionally "const" correct. |
249 */ | 259 */ |
250 class AutoRestoreStencil : public ::SkNoncopyable { | 260 class AutoRestoreStencil : public ::SkNoncopyable { |
251 public: | 261 public: |
252 AutoRestoreStencil() : fPipelineBuilder(NULL) {} | 262 AutoRestoreStencil() : fPipelineBuilder(NULL) {} |
253 | 263 |
254 AutoRestoreStencil(GrPipelineBuilder* ds) : fPipelineBuilder(NULL) { thi
s->set(ds); } | 264 AutoRestoreStencil(const GrPipelineBuilder* ds) : fPipelineBuilder(NULL)
{ this->set(ds); } |
255 | 265 |
256 ~AutoRestoreStencil() { this->set(NULL); } | 266 ~AutoRestoreStencil() { this->set(NULL); } |
257 | 267 |
258 void set(GrPipelineBuilder* ds) { | 268 void set(const GrPipelineBuilder* ds) { |
259 if (fPipelineBuilder) { | 269 if (fPipelineBuilder) { |
260 fPipelineBuilder->setStencil(fStencilSettings); | 270 fPipelineBuilder->setStencil(fStencilSettings); |
261 } | 271 } |
262 fPipelineBuilder = ds; | 272 fPipelineBuilder = const_cast<GrPipelineBuilder*>(ds); |
263 if (ds) { | 273 if (ds) { |
264 fStencilSettings = ds->getStencil(); | 274 fStencilSettings = ds->getStencil(); |
265 } | 275 } |
266 } | 276 } |
267 | 277 |
268 bool isSet() const { return SkToBool(fPipelineBuilder); } | 278 bool isSet() const { return SkToBool(fPipelineBuilder); } |
269 | 279 |
| 280 void setStencil(const GrStencilSettings& settings) { |
| 281 SkASSERT(this->isSet()); |
| 282 fPipelineBuilder->setStencil(settings); |
| 283 } |
| 284 |
270 private: | 285 private: |
| 286 // notionally const (as marginalia) |
271 GrPipelineBuilder* fPipelineBuilder; | 287 GrPipelineBuilder* fPipelineBuilder; |
272 GrStencilSettings fStencilSettings; | 288 GrStencilSettings fStencilSettings; |
273 }; | 289 }; |
274 | 290 |
275 | 291 |
276 /// @} | 292 /// @} |
277 | 293 |
278 /////////////////////////////////////////////////////////////////////////// | 294 /////////////////////////////////////////////////////////////////////////// |
279 /// @name State Flags | 295 /// @name State Flags |
280 //// | 296 //// |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 this->calcCoverageInvariantOutput(batch); | 408 this->calcCoverageInvariantOutput(batch); |
393 return fCoverageProcInfo; | 409 return fCoverageProcInfo; |
394 } | 410 } |
395 | 411 |
396 void setClip(const GrClip& clip) { fClip = clip; } | 412 void setClip(const GrClip& clip) { fClip = clip; } |
397 const GrClip& clip() const { return fClip; } | 413 const GrClip& clip() const { return fClip; } |
398 | 414 |
399 GrProcessorDataManager* getProcessorDataManager() { return fProcDataManager.
get(); } | 415 GrProcessorDataManager* getProcessorDataManager() { return fProcDataManager.
get(); } |
400 const GrProcessorDataManager* processorDataManager() const { return fProcDat
aManager.get(); } | 416 const GrProcessorDataManager* processorDataManager() const { return fProcDat
aManager.get(); } |
401 | 417 |
| 418 /** |
| 419 * When this object is destroyed it will remove any additions to the GrProce
ssorDataManager |
| 420 * owned by the GrPipelineBuilder |
| 421 * This class can transiently modify its "const" GrPipelineBuilder object bu
t will restore it |
| 422 * when done - so it is notionally "const" correct. |
| 423 */ |
| 424 class AutoRestoreProcessorDataManager : public ::SkNoncopyable { |
| 425 public: |
| 426 AutoRestoreProcessorDataManager() : fPipelineBuilder(NULL), fSaveMarker(
0) {} |
| 427 |
| 428 AutoRestoreProcessorDataManager(GrPipelineBuilder* ds) |
| 429 : fPipelineBuilder(NULL) |
| 430 , fSaveMarker(0) { |
| 431 this->set(ds); |
| 432 } |
| 433 |
| 434 ~AutoRestoreProcessorDataManager() { this->set(NULL); } |
| 435 |
| 436 void set(const GrPipelineBuilder* ds) { |
| 437 if (fPipelineBuilder) { |
| 438 fPipelineBuilder->getProcessorDataManager()->restoreToSaveMarker
(/*fSaveMarker*/); |
| 439 } |
| 440 fPipelineBuilder = const_cast<GrPipelineBuilder*>(ds); |
| 441 if (ds) { |
| 442 fSaveMarker = ds->processorDataManager()->currentSaveMarker(); |
| 443 } |
| 444 } |
| 445 |
| 446 bool isSet() const { return SkToBool(fPipelineBuilder); } |
| 447 |
| 448 GrProcessorDataManager* getProcessorDataManager() { |
| 449 SkASSERT(this->isSet()); |
| 450 return fPipelineBuilder->getProcessorDataManager(); |
| 451 } |
| 452 |
| 453 private: |
| 454 // notionally const (as marginalia) |
| 455 GrPipelineBuilder* fPipelineBuilder; |
| 456 uint32_t fSaveMarker; |
| 457 }; |
| 458 |
| 459 |
402 private: | 460 private: |
403 // Calculating invariant color / coverage information is expensive, so we pa
rtially cache the | 461 // Calculating invariant color / coverage information is expensive, so we pa
rtially cache the |
404 // results. | 462 // results. |
405 // | 463 // |
406 // canUseFracCoveragePrimProc() - Called in regular skia draw, caches result
s but only for a | 464 // canUseFracCoveragePrimProc() - Called in regular skia draw, caches result
s but only for a |
407 // specific color and coverage. May be calle
d multiple times | 465 // specific color and coverage. May be calle
d multiple times |
408 // willColorBlendWithDst() - only called by Nvpr, does not cache results | 466 // willColorBlendWithDst() - only called by Nvpr, does not cache results |
409 // GrOptDrawState constructor - never caches results | 467 // GrOptDrawState constructor - never caches results |
410 | 468 |
411 /** | 469 /** |
(...skipping 16 matching lines...) Expand all Loading... |
428 void calcColorInvariantOutput(GrColor) const; | 486 void calcColorInvariantOutput(GrColor) const; |
429 | 487 |
430 /** | 488 /** |
431 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage | 489 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage |
432 * processors and results are stored in fCoverageProcInfo. | 490 * processors and results are stored in fCoverageProcInfo. |
433 */ | 491 */ |
434 void calcCoverageInvariantOutput(GrColor) const; | 492 void calcCoverageInvariantOutput(GrColor) const; |
435 | 493 |
436 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 494 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
437 // This is used to assert that this condition holds. | 495 // This is used to assert that this condition holds. |
438 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 496 SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;) |
439 | 497 |
440 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 498 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
441 | 499 |
442 SkAutoTUnref<GrProcessorDataManager> fProcDataManager; | 500 SkAutoTUnref<GrProcessorDataManager> fProcDataManager; |
443 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 501 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
444 uint32_t fFlags; | 502 uint32_t fFlags; |
445 GrStencilSettings fStencilSettings; | 503 GrStencilSettings fStencilSettings; |
446 DrawFace fDrawFace; | 504 DrawFace fDrawFace; |
447 mutable SkAutoTUnref<const GrXPFactory> fXPFactory; | 505 mutable SkAutoTUnref<const GrXPFactory> fXPFactory; |
448 FragmentStageArray fColorStages; | 506 FragmentStageArray fColorStages; |
449 FragmentStageArray fCoverageStages; | 507 FragmentStageArray fCoverageStages; |
450 GrClip fClip; | 508 GrClip fClip; |
451 | 509 |
452 mutable GrProcOptInfo fColorProcInfo; | 510 mutable GrProcOptInfo fColorProcInfo; |
453 mutable GrProcOptInfo fCoverageProcInfo; | 511 mutable GrProcOptInfo fCoverageProcInfo; |
454 mutable bool fColorProcInfoValid; | 512 mutable bool fColorProcInfoValid; |
455 mutable bool fCoverageProcInfoValid; | 513 mutable bool fCoverageProcInfoValid; |
456 mutable GrColor fColorCache; | 514 mutable GrColor fColorCache; |
457 mutable GrColor fCoverageCache; | 515 mutable GrColor fCoverageCache; |
458 | 516 |
459 friend class GrPipeline; | 517 friend class GrPipeline; |
460 }; | 518 }; |
461 | 519 |
462 #endif | 520 #endif |
OLD | NEW |