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 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 11 | #include "GrBlend.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 12 | #include "GrCaps.h" |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 13 | #include "GrClip.h" |
bsalomon | f96ba02 | 2014-09-17 08:05:40 -0700 | [diff] [blame] | 14 | #include "GrGpuResourceRef.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 15 | #include "GrProcOptInfo.h" |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 16 | #include "GrRenderTarget.h" |
| 17 | #include "GrStencil.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 18 | #include "GrXferProcessor.h" |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 19 | #include "SkMatrix.h" |
egdaniel | 8750924 | 2014-12-17 13:37:13 -0800 | [diff] [blame] | 20 | #include "effects/GrCoverageSetOpXP.h" |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 21 | #include "effects/GrDisableColorXP.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 22 | #include "effects/GrPorterDuffXferProcessor.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 23 | #include "effects/GrSimpleTextureEffect.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 24 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 25 | class GrDrawBatch; |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 26 | class GrCaps; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 27 | class GrPaint; |
| 28 | class GrTexture; |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 29 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 30 | class GrPipelineBuilder : public SkNoncopyable { |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 31 | public: |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 32 | GrPipelineBuilder(); |
| 33 | |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 34 | /** |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 35 | * Initializes the GrPipelineBuilder based on a GrPaint, render target, and clip. Note |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 36 | * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have |
| 37 | * no GrPaint equivalents are set to default values with the exception of vertex attribute state |
| 38 | * 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] | 39 | */ |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 40 | GrPipelineBuilder(const GrPaint&, GrRenderTarget*, const GrClip&); |
| 41 | |
| 42 | virtual ~GrPipelineBuilder(); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 43 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 44 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 45 | /// @name Fragment Processors |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 46 | /// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 47 | /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage. |
| 48 | /// There are two chains of FPs, one for color and one for coverage. The first FP in each |
| 49 | /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output |
| 50 | /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs |
| 51 | /// feed their output to the GrXferProcessor which controls blending. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 52 | //// |
| 53 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 54 | int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); } |
| 55 | int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); } |
| 56 | int numFragmentProcessors() const { return this->numColorFragmentProcessors() + |
| 57 | this->numCoverageFragmentProcessors(); } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 58 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 59 | const GrFragmentProcessor* getColorFragmentProcessor(int idx) const { |
| 60 | return fColorFragmentProcessors[idx]; |
| 61 | } |
| 62 | const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const { |
| 63 | return fCoverageFragmentProcessors[idx]; |
jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 64 | } |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 65 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 66 | const GrFragmentProcessor* addColorFragmentProcessor(const GrFragmentProcessor* processor) { |
| 67 | SkASSERT(processor); |
| 68 | fColorFragmentProcessors.push_back(SkRef(processor)); |
| 69 | return processor; |
| 70 | } |
| 71 | |
| 72 | const GrFragmentProcessor* addCoverageFragmentProcessor(const GrFragmentProcessor* processor) { |
| 73 | SkASSERT(processor); |
| 74 | fCoverageFragmentProcessors.push_back(SkRef(processor)); |
| 75 | return processor; |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 76 | } |
| 77 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 78 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 79 | * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates. |
tomhudson@google.com | 1e8f016 | 2012-07-20 16:25:18 +0000 | [diff] [blame] | 80 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 81 | void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 82 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 83 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 84 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 85 | void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 86 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 87 | } |
| 88 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 89 | void addColorTextureProcessor(GrTexture* texture, |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 90 | const SkMatrix& matrix, |
| 91 | const GrTextureParams& params) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 92 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix, |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 93 | params))->unref(); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void addCoverageTextureProcessor(GrTexture* texture, |
| 97 | const SkMatrix& matrix, |
| 98 | const GrTextureParams& params) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 99 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Create(texture, matrix, |
| 100 | params))->unref(); |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 101 | } |
tomhudson@google.com | 676e660 | 2012-07-10 17:21:48 +0000 | [diff] [blame] | 102 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 103 | /** |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 104 | * When this object is destroyed it will remove any color/coverage FPs from the pipeline builder |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 105 | * that were added after its constructor. |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 106 | * This class can transiently modify its "const" GrPipelineBuilder object but will restore it |
| 107 | * when done - so it is notionally "const" correct. |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 108 | */ |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 109 | class AutoRestoreFragmentProcessorState : public ::SkNoncopyable { |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 110 | public: |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 111 | AutoRestoreFragmentProcessorState() |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 112 | : fPipelineBuilder(nullptr) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 113 | , fColorEffectCnt(0) |
joshualitt | af2533a | 2015-09-09 10:00:12 -0700 | [diff] [blame] | 114 | , fCoverageEffectCnt(0) {} |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 115 | |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 116 | AutoRestoreFragmentProcessorState(const GrPipelineBuilder& ds) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 117 | : fPipelineBuilder(nullptr) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 118 | , fColorEffectCnt(0) |
joshualitt | af2533a | 2015-09-09 10:00:12 -0700 | [diff] [blame] | 119 | , fCoverageEffectCnt(0) { |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 120 | this->set(&ds); |
robertphillips@google.com | f09b87d | 2013-06-13 20:06:44 +0000 | [diff] [blame] | 121 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 122 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 123 | ~AutoRestoreFragmentProcessorState() { this->set(nullptr); } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 124 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 125 | void set(const GrPipelineBuilder* ds); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 126 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 127 | bool isSet() const { return SkToBool(fPipelineBuilder); } |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 128 | |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 129 | const GrFragmentProcessor* addCoverageFragmentProcessor( |
| 130 | const GrFragmentProcessor* processor) { |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 131 | SkASSERT(this->isSet()); |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 132 | return fPipelineBuilder->addCoverageFragmentProcessor(processor); |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 133 | } |
| 134 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 135 | private: |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 136 | // notionally const (as marginalia) |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 137 | GrPipelineBuilder* fPipelineBuilder; |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 138 | int fColorEffectCnt; |
| 139 | int fCoverageEffectCnt; |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 140 | }; |
| 141 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 142 | /// @} |
| 143 | |
| 144 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 145 | /// @name Blending |
| 146 | //// |
| 147 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 148 | /** |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 149 | * Installs a GrXPFactory. This object controls how src color, fractional pixel coverage, |
| 150 | * and the dst color are blended. |
| 151 | */ |
| 152 | const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 153 | fXPFactory.reset(SkSafeRef(xpFactory)); |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 154 | return xpFactory; |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Sets a GrXPFactory that will ignore src color and perform a set operation between the draws |
| 159 | * output coverage and the destination. This is useful to render coverage masks as CSG. |
| 160 | */ |
| 161 | void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) { |
| 162 | fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage)); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Sets a GrXPFactory that disables color writes to the destination. This is useful when |
| 167 | * rendering to the stencil buffer. |
| 168 | */ |
| 169 | void setDisableColorXPFactory() { |
| 170 | fXPFactory.reset(GrDisableColorXPFactory::Create()); |
| 171 | } |
| 172 | |
| 173 | const GrXPFactory* getXPFactory() const { |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 174 | return fXPFactory; |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | /** |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 178 | * Checks whether the xp will need destination in a texture to correctly blend. |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 179 | */ |
ethannicholas | de4166a | 2015-11-30 08:57:38 -0800 | [diff] [blame^] | 180 | bool willXPNeedDstTexture(const GrCaps& caps, |
| 181 | const GrPipelineOptimizations& optimizations) const; |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 182 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 183 | /// @} |
| 184 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 185 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 186 | /////////////////////////////////////////////////////////////////////////// |
| 187 | /// @name Render Target |
| 188 | //// |
| 189 | |
| 190 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 191 | * Retrieves the currently set render-target. |
| 192 | * |
| 193 | * @return The currently set render target. |
| 194 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 195 | GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 196 | |
| 197 | /** |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 198 | * Sets the render-target used at the next drawing call |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 199 | * |
| 200 | * @param target The render target to set. |
| 201 | */ |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 202 | void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 203 | |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 204 | /** |
| 205 | * Returns whether the rasterizer and stencil test (if any) will run at a higher sample rate |
| 206 | * than the color buffer. In is scenario, the higher sample rate is resolved during blending. |
| 207 | */ |
| 208 | bool hasMixedSamples() const { |
cdalton | ede7574 | 2015-11-11 15:27:57 -0800 | [diff] [blame] | 209 | return fRenderTarget->hasMixedSamples() && |
| 210 | (this->isHWAntialias() || !fStencilSettings.isDisabled()); |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 211 | } |
| 212 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 213 | /// @} |
| 214 | |
| 215 | /////////////////////////////////////////////////////////////////////////// |
| 216 | /// @name Stencil |
| 217 | //// |
| 218 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 219 | const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 220 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 221 | /** |
| 222 | * Sets the stencil settings to use for the next draw. |
| 223 | * Changing the clip has the side-effect of possibly zeroing |
| 224 | * out the client settable stencil bits. So multipass algorithms |
| 225 | * using stencil should not change the clip between passes. |
| 226 | * @param settings the stencil settings to use. |
| 227 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 228 | void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 229 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 230 | GrStencilSettings* stencil() { return &fStencilSettings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 231 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 232 | /** |
| 233 | * AutoRestoreStencil |
| 234 | * |
| 235 | * This simple struct saves and restores the stencil settings |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 236 | * This class can transiently modify its "const" GrPipelineBuilder object but will restore it |
| 237 | * when done - so it is notionally "const" correct. |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 238 | */ |
| 239 | class AutoRestoreStencil : public ::SkNoncopyable { |
| 240 | public: |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 241 | AutoRestoreStencil() : fPipelineBuilder(nullptr) {} |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 242 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 243 | AutoRestoreStencil(const GrPipelineBuilder& ds) : fPipelineBuilder(nullptr) { this->set(&ds); } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 244 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 245 | ~AutoRestoreStencil() { this->set(nullptr); } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 246 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 247 | void set(const GrPipelineBuilder* ds) { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 248 | if (fPipelineBuilder) { |
| 249 | fPipelineBuilder->setStencil(fStencilSettings); |
| 250 | } |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 251 | fPipelineBuilder = const_cast<GrPipelineBuilder*>(ds); |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 252 | if (ds) { |
| 253 | fStencilSettings = ds->getStencil(); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | bool isSet() const { return SkToBool(fPipelineBuilder); } |
| 258 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 259 | void setStencil(const GrStencilSettings& settings) { |
| 260 | SkASSERT(this->isSet()); |
| 261 | fPipelineBuilder->setStencil(settings); |
| 262 | } |
| 263 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 264 | private: |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 265 | // notionally const (as marginalia) |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 266 | GrPipelineBuilder* fPipelineBuilder; |
| 267 | GrStencilSettings fStencilSettings; |
| 268 | }; |
| 269 | |
| 270 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 271 | /// @} |
| 272 | |
| 273 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 274 | /// @name State Flags |
| 275 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 276 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 279 | * default to disabled. |
| 280 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 281 | enum Flags { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 282 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 283 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 284 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 285 | * the 3D API. |
| 286 | */ |
bsalomon | aca31fe | 2015-09-22 11:38:46 -0700 | [diff] [blame] | 287 | kHWAntialias_Flag = 0x01, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 288 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 289 | /** |
| 290 | * Modifies the vertex shader so that vertices will be positioned at pixel centers. |
| 291 | */ |
bsalomon | aca31fe | 2015-09-22 11:38:46 -0700 | [diff] [blame] | 292 | kSnapVerticesToPixelCenters_Flag = 0x02, |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 293 | |
| 294 | kLast_Flag = kSnapVerticesToPixelCenters_Flag, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 295 | }; |
| 296 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 297 | bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); } |
| 298 | bool snapVerticesToPixelCenters() const { |
| 299 | return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 300 | |
| 301 | /** |
| 302 | * Enable render state settings. |
| 303 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 304 | * @param flags bitfield of Flags specifying the states to enable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 305 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 306 | void enableState(uint32_t flags) { fFlags |= flags; } |
| 307 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 308 | /** |
| 309 | * Disable render state settings. |
| 310 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 311 | * @param flags bitfield of Flags specifying the states to disable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 312 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 313 | void disableState(uint32_t flags) { fFlags &= ~(flags); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 314 | |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 315 | /** |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 316 | * Enable or disable flags based on a boolean. |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 317 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 318 | * @param flags bitfield of Flags to enable or disable |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 319 | * @param enable if true enable stateBits, otherwise disable |
| 320 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 321 | void setState(uint32_t flags, bool enable) { |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 322 | if (enable) { |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 323 | this->enableState(flags); |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 324 | } else { |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 325 | this->disableState(flags); |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 329 | /// @} |
| 330 | |
| 331 | /////////////////////////////////////////////////////////////////////////// |
| 332 | /// @name Face Culling |
| 333 | //// |
| 334 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 335 | enum DrawFace { |
| 336 | kInvalid_DrawFace = -1, |
| 337 | |
| 338 | kBoth_DrawFace, |
| 339 | kCCW_DrawFace, |
| 340 | kCW_DrawFace, |
| 341 | }; |
| 342 | |
| 343 | /** |
| 344 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 345 | * or both faces. |
| 346 | * @return the current draw face(s). |
| 347 | */ |
| 348 | DrawFace getDrawFace() const { return fDrawFace; } |
| 349 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 350 | /** |
| 351 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 352 | * @param face the face(s) to draw. |
| 353 | */ |
| 354 | void setDrawFace(DrawFace face) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 355 | SkASSERT(kInvalid_DrawFace != face); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 356 | fDrawFace = face; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 357 | } |
| 358 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 359 | /// @} |
| 360 | |
| 361 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 362 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 363 | bool usePLSDstRead(const GrDrawBatch* batch) const; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 364 | |
| 365 | void setClip(const GrClip& clip) { fClip = clip; } |
| 366 | const GrClip& clip() const { return fClip; } |
| 367 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 368 | private: |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 369 | // Some of the auto restore objects assume that no effects are removed during their lifetime. |
| 370 | // This is used to assert that this condition holds. |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 371 | SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;) |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 372 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 373 | typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArray; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 374 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 375 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 376 | uint32_t fFlags; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 377 | GrStencilSettings fStencilSettings; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 378 | DrawFace fDrawFace; |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 379 | mutable SkAutoTUnref<const GrXPFactory> fXPFactory; |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 380 | FragmentProcessorArray fColorFragmentProcessors; |
| 381 | FragmentProcessorArray fCoverageFragmentProcessors; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 382 | GrClip fClip; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 383 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 384 | friend class GrPipeline; |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 385 | friend class GrDrawTarget; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 386 | }; |
| 387 | |
| 388 | #endif |