| 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 29 matching lines...) Expand all Loading... |
| 40 virtual ~GrPipelineBuilder(); | 40 virtual ~GrPipelineBuilder(); |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Initializes the GrPipelineBuilder based on a GrPaint, view matrix and ren
der target. Note | 43 * Initializes the GrPipelineBuilder based on a GrPaint, view matrix and ren
der target. Note |
| 44 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipeli
neBuilder that have | 44 * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipeli
neBuilder that have |
| 45 * no GrPaint equivalents are set to default values with the exception of ve
rtex attribute state | 45 * no GrPaint equivalents are set to default values with the exception of ve
rtex attribute state |
| 46 * which is unmodified by this function and clipping which will be enabled. | 46 * which is unmodified by this function and clipping which will be enabled. |
| 47 */ | 47 */ |
| 48 void setFromPaint(const GrPaint&, GrRenderTarget*, const GrClip&); | 48 void setFromPaint(const GrPaint&, GrRenderTarget*, const GrClip&); |
| 49 | 49 |
| 50 /// @} | |
| 51 | |
| 52 /** | |
| 53 * This function returns true if the render target destination pixel values
will be read for | |
| 54 * blending during draw. | |
| 55 */ | |
| 56 bool willBlendWithDst(const GrPrimitiveProcessor*) const; | |
| 57 | |
| 58 /////////////////////////////////////////////////////////////////////////// | 50 /////////////////////////////////////////////////////////////////////////// |
| 59 /// @name Effect Stages | 51 /// @name Fragment Processors |
| 60 /// Each stage hosts a GrProcessor. The effect produces an output color or c
overage in the | |
| 61 /// fragment shader. Its inputs are the output from the previous stage as we
ll as some variables | |
| 62 /// available to it in the fragment and vertex shader (e.g. the vertex posit
ion, the dst color, | |
| 63 /// the fragment position, local coordinates). | |
| 64 /// | 52 /// |
| 65 /// The stages are divided into two sets, color-computing and coverage-compu
ting. The final | 53 /// GrFragmentProcessors are used to compute per-pixel color and per-pixel f
ractional coverage. |
| 66 /// color stage produces the final pixel color. The coverage-computing stage
s function exactly | 54 /// There are two chains of FPs, one for color and one for coverage. The fir
st FP in each |
| 67 /// as the color-computing but the output of the final coverage stage is tre
ated as a fractional | 55 /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It
computes an output |
| 68 /// pixel coverage rather than as input to the src/dst color blend step. | 56 /// color/coverage which is fed to the next FP in the chain. The last color
and coverage FPs |
| 69 /// | 57 /// feed their output to the GrXferProcessor which controls blending. |
| 70 /// The input color to the first color-stage is either the constant color or
interpolated | |
| 71 /// per-vertex colors. The input to the first coverage stage is either a con
stant coverage | |
| 72 /// (usually full-coverage) or interpolated per-vertex coverage. | |
| 73 /// | |
| 74 /// See the documentation of kCoverageDrawing_StateBit for information about
disabling the | |
| 75 /// the color / coverage distinction. | |
| 76 //// | 58 //// |
| 77 | 59 |
| 78 int numColorStages() const { return fColorStages.count(); } | 60 int numColorFragmentStages() const { return fColorStages.count(); } |
| 79 int numCoverageStages() const { return fCoverageStages.count(); } | 61 int numCoverageFragmentStages() const { return fCoverageStages.count(); } |
| 80 int numFragmentStages() const { return this->numColorStages() + this->numCov
erageStages(); } | 62 int numFragmentStages() const { return this->numColorFragmentStages() + |
| 63 this->numCoverageFragmentStages()
; } |
| 81 | 64 |
| 82 const GrXPFactory* getXPFactory() const { | 65 const GrFragmentStage& getColorFragmentStage(int idx) const { return fColorS
tages[idx]; } |
| 83 if (!fXPFactory) { | 66 const GrFragmentStage& getCoverageFragmentStage(int idx) const { return fCov
erageStages[idx]; } |
| 84 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode
)); | |
| 85 } | |
| 86 return fXPFactory.get(); | |
| 87 } | |
| 88 | |
| 89 const GrFragmentStage& getColorStage(int idx) const { return fColorStages[id
x]; } | |
| 90 const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageSta
ges[idx]; } | |
| 91 | |
| 92 /** | |
| 93 * Checks whether the xp will need a copy of the destination to correctly bl
end. | |
| 94 */ | |
| 95 bool willXPNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& co
lorPOI, | |
| 96 const GrProcOptInfo& coveragePOI) const; | |
| 97 | |
| 98 /** | |
| 99 * The xfer processor factory. | |
| 100 */ | |
| 101 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { | |
| 102 fXPFactory.reset(SkRef(xpFactory)); | |
| 103 return xpFactory; | |
| 104 } | |
| 105 | |
| 106 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage =
false) { | |
| 107 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCovera
ge)); | |
| 108 } | |
| 109 | |
| 110 void setDisableColorXPFactory() { | |
| 111 fXPFactory.reset(GrDisableColorXPFactory::Create()); | |
| 112 } | |
| 113 | 67 |
| 114 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { | 68 const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effe
ct) { |
| 115 SkASSERT(effect); | 69 SkASSERT(effect); |
| 116 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); | 70 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
| 117 fColorProcInfoValid = false; | 71 fColorProcInfoValid = false; |
| 118 return effect; | 72 return effect; |
| 119 } | 73 } |
| 120 | 74 |
| 121 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { | 75 const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* e
ffect) { |
| 122 SkASSERT(effect); | 76 SkASSERT(effect); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 142 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, p
arams))->unref(); | 96 this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, p
arams))->unref(); |
| 143 } | 97 } |
| 144 | 98 |
| 145 void addCoverageTextureProcessor(GrTexture* texture, | 99 void addCoverageTextureProcessor(GrTexture* texture, |
| 146 const SkMatrix& matrix, | 100 const SkMatrix& matrix, |
| 147 const GrTextureParams& params) { | 101 const GrTextureParams& params) { |
| 148 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix
, params))->unref(); | 102 this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix
, params))->unref(); |
| 149 } | 103 } |
| 150 | 104 |
| 151 /** | 105 /** |
| 152 * When this object is destroyed it will remove any color/coverage effects f
rom the pipeline | 106 * When this object is destroyed it will remove any color/coverage FPs from
the pipeline builder |
| 153 * builder that were added after its constructor. | 107 * that were added after its constructor. |
| 154 * | |
| 155 * This class has strange behavior around geometry processor. If there is a
GP on the | |
| 156 * GrPipelineBuilder it will assert that the GP is not modified until after
the destructor of | |
| 157 * the ARE. If the GrPipelineBuilder has a NULL GP when the ARE is construct
ed then it will reset | |
| 158 * it to null in the destructor. | |
| 159 */ | 108 */ |
| 160 class AutoRestoreEffects : public ::SkNoncopyable { | 109 class AutoRestoreFragmentProcessors : public ::SkNoncopyable { |
| 161 public: | 110 public: |
| 162 AutoRestoreEffects() | 111 AutoRestoreFragmentProcessors() |
| 163 : fPipelineBuilder(NULL) | 112 : fPipelineBuilder(NULL) |
| 164 , fColorEffectCnt(0) | 113 , fColorEffectCnt(0) |
| 165 , fCoverageEffectCnt(0) {} | 114 , fCoverageEffectCnt(0) {} |
| 166 | 115 |
| 167 AutoRestoreEffects(GrPipelineBuilder* ds) | 116 AutoRestoreFragmentProcessors(GrPipelineBuilder* ds) |
| 168 : fPipelineBuilder(NULL) | 117 : fPipelineBuilder(NULL) |
| 169 , fColorEffectCnt(0) | 118 , fColorEffectCnt(0) |
| 170 , fCoverageEffectCnt(0) { | 119 , fCoverageEffectCnt(0) { |
| 171 this->set(ds); | 120 this->set(ds); |
| 172 } | 121 } |
| 173 | 122 |
| 174 ~AutoRestoreEffects() { this->set(NULL); } | 123 ~AutoRestoreFragmentProcessors() { this->set(NULL); } |
| 175 | 124 |
| 176 void set(GrPipelineBuilder* ds); | 125 void set(GrPipelineBuilder* ds); |
| 177 | 126 |
| 178 bool isSet() const { return SkToBool(fPipelineBuilder); } | 127 bool isSet() const { return SkToBool(fPipelineBuilder); } |
| 179 | 128 |
| 180 private: | 129 private: |
| 181 GrPipelineBuilder* fPipelineBuilder; | 130 GrPipelineBuilder* fPipelineBuilder; |
| 182 int fColorEffectCnt; | 131 int fColorEffectCnt; |
| 183 int fCoverageEffectCnt; | 132 int fCoverageEffectCnt; |
| 184 }; | 133 }; |
| 185 | 134 |
| 186 /** | |
| 187 * AutoRestoreStencil | |
| 188 * | |
| 189 * This simple struct saves and restores the stencil settings | |
| 190 */ | |
| 191 class AutoRestoreStencil : public ::SkNoncopyable { | |
| 192 public: | |
| 193 AutoRestoreStencil() : fPipelineBuilder(NULL) {} | |
| 194 | |
| 195 AutoRestoreStencil(GrPipelineBuilder* ds) : fPipelineBuilder(NULL) { thi
s->set(ds); } | |
| 196 | |
| 197 ~AutoRestoreStencil() { this->set(NULL); } | |
| 198 | |
| 199 void set(GrPipelineBuilder* ds) { | |
| 200 if (fPipelineBuilder) { | |
| 201 fPipelineBuilder->setStencil(fStencilSettings); | |
| 202 } | |
| 203 fPipelineBuilder = ds; | |
| 204 if (ds) { | |
| 205 fStencilSettings = ds->getStencil(); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 bool isSet() const { return SkToBool(fPipelineBuilder); } | |
| 210 | |
| 211 private: | |
| 212 GrPipelineBuilder* fPipelineBuilder; | |
| 213 GrStencilSettings fStencilSettings; | |
| 214 }; | |
| 215 | |
| 216 /// @} | 135 /// @} |
| 217 | 136 |
| 218 /////////////////////////////////////////////////////////////////////////// | 137 /////////////////////////////////////////////////////////////////////////// |
| 219 /// @name Blending | 138 /// @name Blending |
| 220 //// | 139 //// |
| 221 | 140 |
| 222 /** | 141 /** |
| 223 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional | 142 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional |
| 224 * coverage before the blend will give the correct final destination color.
In general it | 143 * coverage before the blend will give the correct final destination color.
In general it |
| 225 * will not as coverage is applied after blending. | 144 * will not as coverage is applied after blending. |
| 226 */ | 145 */ |
| 227 bool canTweakAlphaForCoverage() const; | 146 bool canTweakAlphaForCoverage() const; |
| 228 | 147 |
| 148 /** |
| 149 * This function returns true if the render target destination pixel values
will be read for |
| 150 * blending during draw. |
| 151 */ |
| 152 bool willBlendWithDst(const GrPrimitiveProcessor*) const; |
| 153 |
| 154 /** |
| 155 * Installs a GrXPFactory. This object controls how src color, fractional pi
xel coverage, |
| 156 * and the dst color are blended. |
| 157 */ |
| 158 const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
| 159 fXPFactory.reset(SkRef(xpFactory)); |
| 160 return xpFactory; |
| 161 } |
| 162 |
| 163 /** |
| 164 * Sets a GrXPFactory that will ignore src color and perform a set operation
between the draws |
| 165 * output coverage and the destination. This is useful to render coverage ma
sks as CSG. |
| 166 */ |
| 167 void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage =
false) { |
| 168 fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCovera
ge)); |
| 169 } |
| 170 |
| 171 /** |
| 172 * Sets a GrXPFactory that disables color writes to the destination. This is
useful when |
| 173 * rendering to the stencil buffer. |
| 174 */ |
| 175 void setDisableColorXPFactory() { |
| 176 fXPFactory.reset(GrDisableColorXPFactory::Create()); |
| 177 } |
| 178 |
| 179 const GrXPFactory* getXPFactory() const { |
| 180 if (!fXPFactory) { |
| 181 fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode
)); |
| 182 } |
| 183 return fXPFactory.get(); |
| 184 } |
| 185 |
| 186 /** |
| 187 * Checks whether the xp will need a copy of the destination to correctly bl
end. |
| 188 */ |
| 189 bool willXPNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& co
lorPOI, |
| 190 const GrProcOptInfo& coveragePOI) const; |
| 191 |
| 229 /// @} | 192 /// @} |
| 230 | 193 |
| 231 | 194 |
| 232 /// @} | |
| 233 | |
| 234 /////////////////////////////////////////////////////////////////////////// | 195 /////////////////////////////////////////////////////////////////////////// |
| 235 /// @name Render Target | 196 /// @name Render Target |
| 236 //// | 197 //// |
| 237 | 198 |
| 238 /** | 199 /** |
| 239 * Retrieves the currently set render-target. | 200 * Retrieves the currently set render-target. |
| 240 * | 201 * |
| 241 * @return The currently set render target. | 202 * @return The currently set render target. |
| 242 */ | 203 */ |
| 243 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } | 204 GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 266 */ | 227 */ |
| 267 void setStencil(const GrStencilSettings& settings) { fStencilSettings = sett
ings; } | 228 void setStencil(const GrStencilSettings& settings) { fStencilSettings = sett
ings; } |
| 268 | 229 |
| 269 /** | 230 /** |
| 270 * Shortcut to disable stencil testing and ops. | 231 * Shortcut to disable stencil testing and ops. |
| 271 */ | 232 */ |
| 272 void disableStencil() { fStencilSettings.setDisabled(); } | 233 void disableStencil() { fStencilSettings.setDisabled(); } |
| 273 | 234 |
| 274 GrStencilSettings* stencil() { return &fStencilSettings; } | 235 GrStencilSettings* stencil() { return &fStencilSettings; } |
| 275 | 236 |
| 237 /** |
| 238 * AutoRestoreStencil |
| 239 * |
| 240 * This simple struct saves and restores the stencil settings |
| 241 */ |
| 242 class AutoRestoreStencil : public ::SkNoncopyable { |
| 243 public: |
| 244 AutoRestoreStencil() : fPipelineBuilder(NULL) {} |
| 245 |
| 246 AutoRestoreStencil(GrPipelineBuilder* ds) : fPipelineBuilder(NULL) { thi
s->set(ds); } |
| 247 |
| 248 ~AutoRestoreStencil() { this->set(NULL); } |
| 249 |
| 250 void set(GrPipelineBuilder* ds) { |
| 251 if (fPipelineBuilder) { |
| 252 fPipelineBuilder->setStencil(fStencilSettings); |
| 253 } |
| 254 fPipelineBuilder = ds; |
| 255 if (ds) { |
| 256 fStencilSettings = ds->getStencil(); |
| 257 } |
| 258 } |
| 259 |
| 260 bool isSet() const { return SkToBool(fPipelineBuilder); } |
| 261 |
| 262 private: |
| 263 GrPipelineBuilder* fPipelineBuilder; |
| 264 GrStencilSettings fStencilSettings; |
| 265 }; |
| 266 |
| 267 |
| 276 /// @} | 268 /// @} |
| 277 | 269 |
| 278 /////////////////////////////////////////////////////////////////////////// | 270 /////////////////////////////////////////////////////////////////////////// |
| 279 /// @name State Flags | 271 /// @name State Flags |
| 280 //// | 272 //// |
| 281 | 273 |
| 282 /** | 274 /** |
| 283 * Flags that affect rendering. Controlled using enable/disableState(). All | 275 * Flags that affect rendering. Controlled using enable/disableState(). All |
| 284 * default to disabled. | 276 * default to disabled. |
| 285 */ | 277 */ |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 */ | 348 */ |
| 357 void setDrawFace(DrawFace face) { | 349 void setDrawFace(DrawFace face) { |
| 358 SkASSERT(kInvalid_DrawFace != face); | 350 SkASSERT(kInvalid_DrawFace != face); |
| 359 fDrawFace = face; | 351 fDrawFace = face; |
| 360 } | 352 } |
| 361 | 353 |
| 362 /// @} | 354 /// @} |
| 363 | 355 |
| 364 /////////////////////////////////////////////////////////////////////////// | 356 /////////////////////////////////////////////////////////////////////////// |
| 365 | 357 |
| 366 GrPipelineBuilder& operator= (const GrPipelineBuilder& that); | 358 GrPipelineBuilder& operator=(const GrPipelineBuilder& that); |
| 367 | 359 |
| 368 // TODO delete when we have Batch | 360 // TODO delete when we have Batch |
| 369 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { | 361 const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { |
| 370 this->calcColorInvariantOutput(pp); | 362 this->calcColorInvariantOutput(pp); |
| 371 return fColorProcInfo; | 363 return fColorProcInfo; |
| 372 } | 364 } |
| 373 | 365 |
| 374 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ | 366 const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const
{ |
| 375 this->calcCoverageInvariantOutput(pp); | 367 this->calcCoverageInvariantOutput(pp); |
| 376 return fCoverageProcInfo; | 368 return fCoverageProcInfo; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 406 void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const; | 398 void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const; |
| 407 | 399 |
| 408 /** | 400 /** |
| 409 * GrBatch provides the initial seed for these loops based off of its initia
l geometry data | 401 * GrBatch provides the initial seed for these loops based off of its initia
l geometry data |
| 410 */ | 402 */ |
| 411 void calcColorInvariantOutput(const GrBatch*) const; | 403 void calcColorInvariantOutput(const GrBatch*) const; |
| 412 void calcCoverageInvariantOutput(const GrBatch*) const; | 404 void calcCoverageInvariantOutput(const GrBatch*) const; |
| 413 | 405 |
| 414 /** | 406 /** |
| 415 * If fColorProcInfoValid is false, function calculates the invariant output
for the color | 407 * If fColorProcInfoValid is false, function calculates the invariant output
for the color |
| 416 * stages and results are stored in fColorProcInfo. | 408 * processors and results are stored in fColorProcInfo. |
| 417 */ | 409 */ |
| 418 void calcColorInvariantOutput(GrColor) const; | 410 void calcColorInvariantOutput(GrColor) const; |
| 419 | 411 |
| 420 /** | 412 /** |
| 421 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage | 413 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage |
| 422 * stages and results are stored in fCoverageProcInfo. | 414 * processors and results are stored in fCoverageProcInfo. |
| 423 */ | 415 */ |
| 424 void calcCoverageInvariantOutput(GrColor) const; | 416 void calcCoverageInvariantOutput(GrColor) const; |
| 425 | 417 |
| 426 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 418 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
| 427 // This is used to assert that this condition holds. | 419 // This is used to assert that this condition holds. |
| 428 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 420 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| 429 | 421 |
| 430 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 422 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
| 431 | 423 |
| 432 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 424 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 433 uint32_t fFlagBits; | 425 uint32_t fFlagBits; |
| 434 GrStencilSettings fStencilSettings; | 426 GrStencilSettings fStencilSettings; |
| 435 DrawFace fDrawFace; | 427 DrawFace fDrawFace; |
| 436 mutable SkAutoTUnref<const GrXPFactory> fXPFactory; | 428 mutable SkAutoTUnref<const GrXPFactory> fXPFactory; |
| 437 FragmentStageArray fColorStages; | 429 FragmentStageArray fColorStages; |
| 438 FragmentStageArray fCoverageStages; | 430 FragmentStageArray fCoverageStages; |
| 439 GrClip fClip; | 431 GrClip fClip; |
| 440 | 432 |
| 441 mutable GrProcOptInfo fColorProcInfo; | 433 mutable GrProcOptInfo fColorProcInfo; |
| 442 mutable GrProcOptInfo fCoverageProcInfo; | 434 mutable GrProcOptInfo fCoverageProcInfo; |
| 443 mutable bool fColorProcInfoValid; | 435 mutable bool fColorProcInfoValid; |
| 444 mutable bool fCoverageProcInfoValid; | 436 mutable bool fCoverageProcInfoValid; |
| 445 mutable GrColor fColorCache; | 437 mutable GrColor fColorCache; |
| 446 mutable GrColor fCoverageCache; | 438 mutable GrColor fCoverageCache; |
| 447 | 439 |
| 448 friend class GrPipeline; | 440 friend class GrPipeline; |
| 449 }; | 441 }; |
| 450 | 442 |
| 451 #endif | 443 #endif |
| OLD | NEW |