tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1 | /* |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 2 | * Copyright 2015 Google Inc. |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 8 | #ifndef GrPipelineBuilder_DEFINED |
| 9 | #define GrPipelineBuilder_DEFINED |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 10 | |
joshualitt | d5a7db4 | 2015-01-27 15:39:06 -0800 | [diff] [blame^] | 11 | #include "GrBatch.h" |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 12 | #include "GrBlend.h" |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 13 | #include "GrDrawTargetCaps.h" |
bsalomon | 6251d17 | 2014-10-15 10:50:36 -0700 | [diff] [blame] | 14 | #include "GrGeometryProcessor.h" |
bsalomon | f96ba02 | 2014-09-17 08:05:40 -0700 | [diff] [blame] | 15 | #include "GrGpuResourceRef.h" |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 16 | #include "GrFragmentStage.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 17 | #include "GrProcOptInfo.h" |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 18 | #include "GrRenderTarget.h" |
| 19 | #include "GrStencil.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 20 | #include "GrXferProcessor.h" |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 21 | #include "SkMatrix.h" |
egdaniel | 8750924 | 2014-12-17 13:37:13 -0800 | [diff] [blame] | 22 | #include "effects/GrCoverageSetOpXP.h" |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 23 | #include "effects/GrDisableColorXP.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 24 | #include "effects/GrPorterDuffXferProcessor.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 25 | #include "effects/GrSimpleTextureEffect.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 26 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 27 | class GrDrawTargetCaps; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 28 | class GrPaint; |
| 29 | class GrTexture; |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 30 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 31 | class GrPipelineBuilder { |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 32 | public: |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 33 | GrPipelineBuilder(); |
| 34 | |
| 35 | GrPipelineBuilder(const GrPipelineBuilder& pipelineBuilder) { |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 36 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 37 | *this = pipelineBuilder; |
bsalomon@google.com | 46f7afb | 2012-01-18 19:51:55 +0000 | [diff] [blame] | 38 | } |
| 39 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 40 | virtual ~GrPipelineBuilder(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 41 | |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 42 | /** |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 43 | * Initializes the GrPipelineBuilder based on a GrPaint, view matrix and render target. Note |
| 44 | * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have |
| 45 | * no GrPaint equivalents are set to default values with the exception of vertex attribute state |
| 46 | * which is unmodified by this function and clipping which will be enabled. |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 47 | */ |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 48 | void setFromPaint(const GrPaint&, GrRenderTarget*); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 49 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 50 | /// @} |
| 51 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 52 | /** |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 53 | * Depending on features available in the underlying 3D API and the color blend mode requested |
| 54 | * it may or may not be possible to correctly blend with fractional pixel coverage generated by |
| 55 | * the fragment shader. |
| 56 | * |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 57 | * This function considers the current GrPipelineBuilder and the draw target's capabilities to |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 58 | * determine whether coverage can be handled correctly. This function assumes that the caller |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 59 | * intends to specify fractional pixel coverage via a primitive processor but may not have |
| 60 | * specified it yet. |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 61 | */ |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 62 | bool canUseFracCoveragePrimProc(GrColor color, const GrDrawTargetCaps& caps) const; |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 63 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 64 | /** |
egdaniel | cd8b630 | 2014-11-11 14:46:05 -0800 | [diff] [blame] | 65 | * This function returns true if the render target destination pixel values will be read for |
| 66 | * blending during draw. |
| 67 | */ |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 68 | bool willBlendWithDst(const GrPrimitiveProcessor*) const; |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 69 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 70 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 71 | /// @name Effect Stages |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 72 | /// Each stage hosts a GrProcessor. The effect produces an output color or coverage in the |
| 73 | /// fragment shader. Its inputs are the output from the previous stage as well as some variables |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 74 | /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color, |
| 75 | /// the fragment position, local coordinates). |
| 76 | /// |
| 77 | /// The stages are divided into two sets, color-computing and coverage-computing. The final |
| 78 | /// color stage produces the final pixel color. The coverage-computing stages function exactly |
| 79 | /// as the color-computing but the output of the final coverage stage is treated as a fractional |
| 80 | /// pixel coverage rather than as input to the src/dst color blend step. |
| 81 | /// |
| 82 | /// The input color to the first color-stage is either the constant color or interpolated |
| 83 | /// per-vertex colors. The input to the first coverage stage is either a constant coverage |
| 84 | /// (usually full-coverage) or interpolated per-vertex coverage. |
| 85 | /// |
| 86 | /// See the documentation of kCoverageDrawing_StateBit for information about disabling the |
| 87 | /// the color / coverage distinction. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 88 | //// |
| 89 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 90 | int numColorStages() const { return fColorStages.count(); } |
| 91 | int numCoverageStages() const { return fCoverageStages.count(); } |
joshualitt | 4dd9988 | 2014-11-11 08:51:30 -0800 | [diff] [blame] | 92 | int numFragmentStages() const { return this->numColorStages() + this->numCoverageStages(); } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 93 | |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 94 | const GrXPFactory* getXPFactory() const { |
| 95 | if (!fXPFactory) { |
| 96 | fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
| 97 | } |
| 98 | return fXPFactory.get(); |
| 99 | } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 100 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 101 | const GrFragmentStage& getColorStage(int idx) const { return fColorStages[idx]; } |
| 102 | const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; } |
| 103 | |
| 104 | /** |
egdaniel | 71e236c | 2015-01-20 06:34:51 -0800 | [diff] [blame] | 105 | * Checks whether the xp will read the dst pixel color. |
| 106 | * TODO: remove when we have dstCpy contained inside of GrXP |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 107 | */ |
egdaniel | 71e236c | 2015-01-20 06:34:51 -0800 | [diff] [blame] | 108 | bool willEffectReadDstColor() const; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 109 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 110 | /** |
| 111 | * The xfer processor factory. |
| 112 | */ |
| 113 | const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
| 114 | fXPFactory.reset(SkRef(xpFactory)); |
| 115 | return xpFactory; |
| 116 | } |
| 117 | |
| 118 | void setPorterDuffXPFactory(SkXfermode::Mode mode) { |
| 119 | fXPFactory.reset(GrPorterDuffXPFactory::Create(mode)); |
| 120 | } |
| 121 | |
| 122 | void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) { |
| 123 | fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst)); |
| 124 | } |
| 125 | |
egdaniel | 8750924 | 2014-12-17 13:37:13 -0800 | [diff] [blame] | 126 | void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) { |
| 127 | fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage)); |
| 128 | } |
| 129 | |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 130 | void setDisableColorXPFactory() { |
| 131 | fXPFactory.reset(GrDisableColorXPFactory::Create()); |
| 132 | } |
| 133 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 134 | const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 135 | SkASSERT(effect); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 136 | SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 137 | fColorProcInfoValid = false; |
jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 138 | return effect; |
| 139 | } |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 140 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 141 | const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 142 | SkASSERT(effect); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 143 | SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 144 | fCoverageProcInfoValid = false; |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 145 | return effect; |
| 146 | } |
| 147 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 148 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 149 | * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates. |
tomhudson@google.com | 1e8f016 | 2012-07-20 16:25:18 +0000 | [diff] [blame] | 150 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 151 | void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 152 | this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 153 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 154 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 155 | void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 156 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 157 | } |
| 158 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 159 | void addColorTextureProcessor(GrTexture* texture, |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 160 | const SkMatrix& matrix, |
| 161 | const GrTextureParams& params) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 162 | this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
| 163 | } |
| 164 | |
| 165 | void addCoverageTextureProcessor(GrTexture* texture, |
| 166 | const SkMatrix& matrix, |
| 167 | const GrTextureParams& params) { |
| 168 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 169 | } |
tomhudson@google.com | 676e660 | 2012-07-10 17:21:48 +0000 | [diff] [blame] | 170 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 171 | /** |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 172 | * When this object is destroyed it will remove any color/coverage effects from the pipeline |
| 173 | * builder that were added after its constructor. |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 174 | * |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 175 | * This class has strange behavior around geometry processor. If there is a GP on the |
| 176 | * GrPipelineBuilder it will assert that the GP is not modified until after the destructor of |
| 177 | * the ARE. If the GrPipelineBuilder has a NULL GP when the ARE is constructed then it will reset |
| 178 | * it to null in the destructor. |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 179 | */ |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 180 | class AutoRestoreEffects : public ::SkNoncopyable { |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 181 | public: |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 182 | AutoRestoreEffects() |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 183 | : fPipelineBuilder(NULL) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 184 | , fColorEffectCnt(0) |
| 185 | , fCoverageEffectCnt(0) {} |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 186 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 187 | AutoRestoreEffects(GrPipelineBuilder* ds) |
| 188 | : fPipelineBuilder(NULL) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 189 | , fColorEffectCnt(0) |
| 190 | , fCoverageEffectCnt(0) { |
skia.committer@gmail.com | 5c493d5 | 2013-06-14 07:00:49 +0000 | [diff] [blame] | 191 | this->set(ds); |
robertphillips@google.com | f09b87d | 2013-06-13 20:06:44 +0000 | [diff] [blame] | 192 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 193 | |
| 194 | ~AutoRestoreEffects() { this->set(NULL); } |
| 195 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 196 | void set(GrPipelineBuilder* ds); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 197 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 198 | bool isSet() const { return SkToBool(fPipelineBuilder); } |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 199 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 200 | private: |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 201 | GrPipelineBuilder* fPipelineBuilder; |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 202 | int fColorEffectCnt; |
| 203 | int fCoverageEffectCnt; |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 204 | }; |
| 205 | |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 206 | /** |
| 207 | * AutoRestoreStencil |
| 208 | * |
| 209 | * This simple struct saves and restores the stencil settings |
| 210 | */ |
| 211 | class AutoRestoreStencil : public ::SkNoncopyable { |
| 212 | public: |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 213 | AutoRestoreStencil() : fPipelineBuilder(NULL) {} |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 214 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 215 | AutoRestoreStencil(GrPipelineBuilder* ds) : fPipelineBuilder(NULL) { this->set(ds); } |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 216 | |
| 217 | ~AutoRestoreStencil() { this->set(NULL); } |
| 218 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 219 | void set(GrPipelineBuilder* ds) { |
| 220 | if (fPipelineBuilder) { |
| 221 | fPipelineBuilder->setStencil(fStencilSettings); |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 222 | } |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 223 | fPipelineBuilder = ds; |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 224 | if (ds) { |
| 225 | fStencilSettings = ds->getStencil(); |
| 226 | } |
| 227 | } |
| 228 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 229 | bool isSet() const { return SkToBool(fPipelineBuilder); } |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 230 | |
| 231 | private: |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 232 | GrPipelineBuilder* fPipelineBuilder; |
| 233 | GrStencilSettings fStencilSettings; |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 234 | }; |
| 235 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 236 | /// @} |
| 237 | |
| 238 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 239 | /// @name Blending |
| 240 | //// |
| 241 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 242 | /** |
| 243 | * Determines whether multiplying the computed per-pixel color by the pixel's fractional |
| 244 | * coverage before the blend will give the correct final destination color. In general it |
| 245 | * will not as coverage is applied after blending. |
| 246 | */ |
| 247 | bool canTweakAlphaForCoverage() const; |
| 248 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 249 | /// @} |
| 250 | |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 251 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 252 | /// @} |
| 253 | |
| 254 | /////////////////////////////////////////////////////////////////////////// |
| 255 | /// @name Render Target |
| 256 | //// |
| 257 | |
| 258 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 259 | * Retrieves the currently set render-target. |
| 260 | * |
| 261 | * @return The currently set render target. |
| 262 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 263 | GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 264 | |
| 265 | /** |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 266 | * Sets the render-target used at the next drawing call |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 267 | * |
| 268 | * @param target The render target to set. |
| 269 | */ |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 270 | void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 271 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 272 | /// @} |
| 273 | |
| 274 | /////////////////////////////////////////////////////////////////////////// |
| 275 | /// @name Stencil |
| 276 | //// |
| 277 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 278 | const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 279 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 280 | /** |
| 281 | * Sets the stencil settings to use for the next draw. |
| 282 | * Changing the clip has the side-effect of possibly zeroing |
| 283 | * out the client settable stencil bits. So multipass algorithms |
| 284 | * using stencil should not change the clip between passes. |
| 285 | * @param settings the stencil settings to use. |
| 286 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 287 | void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 288 | |
| 289 | /** |
| 290 | * Shortcut to disable stencil testing and ops. |
| 291 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 292 | void disableStencil() { fStencilSettings.setDisabled(); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 293 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 294 | GrStencilSettings* stencil() { return &fStencilSettings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 295 | |
| 296 | /// @} |
| 297 | |
| 298 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 299 | /// @name State Flags |
| 300 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 301 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 302 | /** |
| 303 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 304 | * default to disabled. |
| 305 | */ |
| 306 | enum StateBits { |
| 307 | /** |
| 308 | * Perform dithering. TODO: Re-evaluate whether we need this bit |
| 309 | */ |
| 310 | kDither_StateBit = 0x01, |
| 311 | /** |
| 312 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 313 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 314 | * the 3D API. |
| 315 | */ |
| 316 | kHWAntialias_StateBit = 0x02, |
| 317 | /** |
| 318 | * Draws will respect the clip, otherwise the clip is ignored. |
| 319 | */ |
| 320 | kClip_StateBit = 0x04, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 321 | |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 322 | kLast_StateBit = kClip_StateBit, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 323 | }; |
| 324 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 325 | bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 326 | bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); } |
| 327 | bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 328 | |
| 329 | /** |
| 330 | * Enable render state settings. |
| 331 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 332 | * @param stateBits bitfield of StateBits specifying the states to enable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 333 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 334 | void enableState(uint32_t stateBits) { fFlagBits |= stateBits; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 335 | |
| 336 | /** |
| 337 | * Disable render state settings. |
| 338 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 339 | * @param stateBits bitfield of StateBits specifying the states to disable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 340 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 341 | void disableState(uint32_t stateBits) { fFlagBits &= ~(stateBits); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 342 | |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 343 | /** |
| 344 | * Enable or disable stateBits based on a boolean. |
| 345 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 346 | * @param stateBits bitfield of StateBits to enable or disable |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 347 | * @param enable if true enable stateBits, otherwise disable |
| 348 | */ |
| 349 | void setState(uint32_t stateBits, bool enable) { |
| 350 | if (enable) { |
| 351 | this->enableState(stateBits); |
| 352 | } else { |
| 353 | this->disableState(stateBits); |
| 354 | } |
| 355 | } |
| 356 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 357 | /// @} |
| 358 | |
| 359 | /////////////////////////////////////////////////////////////////////////// |
| 360 | /// @name Face Culling |
| 361 | //// |
| 362 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 363 | enum DrawFace { |
| 364 | kInvalid_DrawFace = -1, |
| 365 | |
| 366 | kBoth_DrawFace, |
| 367 | kCCW_DrawFace, |
| 368 | kCW_DrawFace, |
| 369 | }; |
| 370 | |
| 371 | /** |
| 372 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 373 | * or both faces. |
| 374 | * @return the current draw face(s). |
| 375 | */ |
| 376 | DrawFace getDrawFace() const { return fDrawFace; } |
| 377 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 378 | /** |
| 379 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 380 | * @param face the face(s) to draw. |
| 381 | */ |
| 382 | void setDrawFace(DrawFace face) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 383 | SkASSERT(kInvalid_DrawFace != face); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 384 | fDrawFace = face; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 385 | } |
| 386 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 387 | /// @} |
| 388 | |
| 389 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 390 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 391 | GrPipelineBuilder& operator= (const GrPipelineBuilder& that); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 392 | |
| 393 | private: |
joshualitt | d5a7db4 | 2015-01-27 15:39:06 -0800 | [diff] [blame^] | 394 | // Calculating invariant color / coverage information is expensive, so we partially cache the |
| 395 | // results. |
| 396 | // |
| 397 | // canUseFracCoveragePrimProc() - Called in regular skia draw, caches results but only for a |
| 398 | // specific color and coverage. May be called multiple times |
| 399 | // willBlendWithDst() - only called by Nvpr, does not cache results |
| 400 | // GrOptDrawState constructor - never caches results |
| 401 | |
| 402 | // TODO delete when we have Batch |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 403 | const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { |
| 404 | this->calcColorInvariantOutput(pp); |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 405 | return fColorProcInfo; |
| 406 | } |
| 407 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 408 | const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const { |
| 409 | this->calcCoverageInvariantOutput(pp); |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 410 | return fCoverageProcInfo; |
| 411 | } |
| 412 | |
joshualitt | d5a7db4 | 2015-01-27 15:39:06 -0800 | [diff] [blame^] | 413 | const GrProcOptInfo& colorProcInfo(const GrBatch* batch) const { |
| 414 | this->calcColorInvariantOutput(batch); |
| 415 | return fColorProcInfo; |
| 416 | } |
| 417 | |
| 418 | const GrProcOptInfo& coverageProcInfo(const GrBatch* batch) const { |
| 419 | this->calcCoverageInvariantOutput(batch); |
| 420 | return fCoverageProcInfo; |
| 421 | } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 422 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 423 | /** |
joshualitt | d5a7db4 | 2015-01-27 15:39:06 -0800 | [diff] [blame^] | 424 | * Primproc variants of the calc functions |
| 425 | * TODO remove these when batch is everywhere |
joshualitt | d15e4e4 | 2015-01-26 13:30:10 -0800 | [diff] [blame] | 426 | */ |
joshualitt | d5a7db4 | 2015-01-27 15:39:06 -0800 | [diff] [blame^] | 427 | void calcColorInvariantOutput(const GrPrimitiveProcessor*) const; |
joshualitt | ca0a179 | 2015-01-27 06:41:33 -0800 | [diff] [blame] | 428 | void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const; |
joshualitt | d15e4e4 | 2015-01-26 13:30:10 -0800 | [diff] [blame] | 429 | |
| 430 | /** |
joshualitt | d5a7db4 | 2015-01-27 15:39:06 -0800 | [diff] [blame^] | 431 | * GrBatch provides the initial seed for these loops based off of its initial geometry data |
| 432 | */ |
| 433 | void calcColorInvariantOutput(const GrBatch*) const; |
| 434 | void calcCoverageInvariantOutput(const GrBatch*) const; |
| 435 | |
| 436 | /** |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 437 | * If fColorProcInfoValid is false, function calculates the invariant output for the color |
| 438 | * stages and results are stored in fColorProcInfo. |
| 439 | */ |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 440 | void calcColorInvariantOutput(GrColor) const; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 441 | |
| 442 | /** |
| 443 | * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage |
| 444 | * stages and results are stored in fCoverageProcInfo. |
| 445 | */ |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 446 | void calcCoverageInvariantOutput(GrColor) const; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 447 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 448 | // Some of the auto restore objects assume that no effects are removed during their lifetime. |
| 449 | // This is used to assert that this condition holds. |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 450 | SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 451 | |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 452 | typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 453 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 454 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 455 | uint32_t fFlagBits; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 456 | GrStencilSettings fStencilSettings; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 457 | DrawFace fDrawFace; |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 458 | mutable SkAutoTUnref<const GrXPFactory> fXPFactory; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 459 | FragmentStageArray fColorStages; |
| 460 | FragmentStageArray fCoverageStages; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 461 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 462 | mutable GrProcOptInfo fColorProcInfo; |
| 463 | mutable GrProcOptInfo fCoverageProcInfo; |
| 464 | mutable bool fColorProcInfoValid; |
| 465 | mutable bool fCoverageProcInfoValid; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 466 | mutable GrColor fColorCache; |
| 467 | mutable GrColor fCoverageCache; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 468 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 469 | friend class GrPipeline; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 470 | }; |
| 471 | |
| 472 | #endif |