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) { |
| 153 | fXPFactory.reset(SkRef(xpFactory)); |
| 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 { |
| 174 | if (!fXPFactory) { |
| 175 | fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
| 176 | } |
| 177 | return fXPFactory.get(); |
| 178 | } |
| 179 | |
| 180 | /** |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 181 | * Checks whether the xp will need destination in a texture to correctly blend. |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 182 | */ |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 183 | bool willXPNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI, |
| 184 | const GrProcOptInfo& coveragePOI) const; |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 185 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 186 | /// @} |
| 187 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 188 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 189 | /////////////////////////////////////////////////////////////////////////// |
| 190 | /// @name Render Target |
| 191 | //// |
| 192 | |
| 193 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 194 | * Retrieves the currently set render-target. |
| 195 | * |
| 196 | * @return The currently set render target. |
| 197 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 198 | GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 199 | |
| 200 | /** |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 201 | * Sets the render-target used at the next drawing call |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 202 | * |
| 203 | * @param target The render target to set. |
| 204 | */ |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 205 | void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 206 | |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 207 | /** |
| 208 | * Returns whether the rasterizer and stencil test (if any) will run at a higher sample rate |
| 209 | * than the color buffer. In is scenario, the higher sample rate is resolved during blending. |
| 210 | */ |
| 211 | bool hasMixedSamples() const { |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 212 | return this->isHWAntialias() && !fRenderTarget->isUnifiedMultisampled(); |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 213 | } |
| 214 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 215 | /// @} |
| 216 | |
| 217 | /////////////////////////////////////////////////////////////////////////// |
| 218 | /// @name Stencil |
| 219 | //// |
| 220 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 221 | const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 222 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 223 | /** |
| 224 | * Sets the stencil settings to use for the next draw. |
| 225 | * Changing the clip has the side-effect of possibly zeroing |
| 226 | * out the client settable stencil bits. So multipass algorithms |
| 227 | * using stencil should not change the clip between passes. |
| 228 | * @param settings the stencil settings to use. |
| 229 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 230 | void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 231 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 232 | GrStencilSettings* stencil() { return &fStencilSettings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 233 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 234 | /** |
| 235 | * AutoRestoreStencil |
| 236 | * |
| 237 | * This simple struct saves and restores the stencil settings |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 238 | * This class can transiently modify its "const" GrPipelineBuilder object but will restore it |
| 239 | * when done - so it is notionally "const" correct. |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 240 | */ |
| 241 | class AutoRestoreStencil : public ::SkNoncopyable { |
| 242 | public: |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 243 | AutoRestoreStencil() : fPipelineBuilder(nullptr) {} |
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(const GrPipelineBuilder& ds) : fPipelineBuilder(nullptr) { this->set(&ds); } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 246 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 247 | ~AutoRestoreStencil() { this->set(nullptr); } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 248 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 249 | void set(const GrPipelineBuilder* ds) { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 250 | if (fPipelineBuilder) { |
| 251 | fPipelineBuilder->setStencil(fStencilSettings); |
| 252 | } |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 253 | fPipelineBuilder = const_cast<GrPipelineBuilder*>(ds); |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 254 | if (ds) { |
| 255 | fStencilSettings = ds->getStencil(); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | bool isSet() const { return SkToBool(fPipelineBuilder); } |
| 260 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 261 | void setStencil(const GrStencilSettings& settings) { |
| 262 | SkASSERT(this->isSet()); |
| 263 | fPipelineBuilder->setStencil(settings); |
| 264 | } |
| 265 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 266 | private: |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 267 | // notionally const (as marginalia) |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 268 | GrPipelineBuilder* fPipelineBuilder; |
| 269 | GrStencilSettings fStencilSettings; |
| 270 | }; |
| 271 | |
| 272 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 273 | /// @} |
| 274 | |
| 275 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 276 | /// @name State Flags |
| 277 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 278 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 279 | /** |
| 280 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 281 | * default to disabled. |
| 282 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 283 | enum Flags { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 284 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 285 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 286 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 287 | * the 3D API. |
| 288 | */ |
bsalomon | aca31fe | 2015-09-22 11:38:46 -0700 | [diff] [blame] | 289 | kHWAntialias_Flag = 0x01, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 290 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 291 | /** |
| 292 | * Modifies the vertex shader so that vertices will be positioned at pixel centers. |
| 293 | */ |
bsalomon | aca31fe | 2015-09-22 11:38:46 -0700 | [diff] [blame] | 294 | kSnapVerticesToPixelCenters_Flag = 0x02, |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 295 | |
| 296 | kLast_Flag = kSnapVerticesToPixelCenters_Flag, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 297 | }; |
| 298 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 299 | bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); } |
| 300 | bool snapVerticesToPixelCenters() const { |
| 301 | return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 302 | |
| 303 | /** |
| 304 | * Enable render state settings. |
| 305 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 306 | * @param flags bitfield of Flags specifying the states to enable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 307 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 308 | void enableState(uint32_t flags) { fFlags |= flags; } |
| 309 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 310 | /** |
| 311 | * Disable render state settings. |
| 312 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 313 | * @param flags bitfield of Flags specifying the states to disable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 314 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 315 | void disableState(uint32_t flags) { fFlags &= ~(flags); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 316 | |
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 | * Enable or disable flags based on a boolean. |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 319 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 320 | * @param flags bitfield of Flags to enable or disable |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 321 | * @param enable if true enable stateBits, otherwise disable |
| 322 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 323 | void setState(uint32_t flags, bool enable) { |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 324 | if (enable) { |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 325 | this->enableState(flags); |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 326 | } else { |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 327 | this->disableState(flags); |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 331 | /// @} |
| 332 | |
| 333 | /////////////////////////////////////////////////////////////////////////// |
| 334 | /// @name Face Culling |
| 335 | //// |
| 336 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 337 | enum DrawFace { |
| 338 | kInvalid_DrawFace = -1, |
| 339 | |
| 340 | kBoth_DrawFace, |
| 341 | kCCW_DrawFace, |
| 342 | kCW_DrawFace, |
| 343 | }; |
| 344 | |
| 345 | /** |
| 346 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 347 | * or both faces. |
| 348 | * @return the current draw face(s). |
| 349 | */ |
| 350 | DrawFace getDrawFace() const { return fDrawFace; } |
| 351 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 352 | /** |
| 353 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 354 | * @param face the face(s) to draw. |
| 355 | */ |
| 356 | void setDrawFace(DrawFace face) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 357 | SkASSERT(kInvalid_DrawFace != face); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 358 | fDrawFace = face; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 359 | } |
| 360 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 361 | /// @} |
| 362 | |
| 363 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 364 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 365 | const GrProcOptInfo& colorProcInfo(const GrDrawBatch* batch) const { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 366 | this->calcColorInvariantOutput(batch); |
| 367 | return fColorProcInfo; |
| 368 | } |
| 369 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 370 | const GrProcOptInfo& coverageProcInfo(const GrDrawBatch* batch) const { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 371 | this->calcCoverageInvariantOutput(batch); |
| 372 | return fCoverageProcInfo; |
| 373 | } |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 374 | |
| 375 | void setClip(const GrClip& clip) { fClip = clip; } |
| 376 | const GrClip& clip() const { return fClip; } |
| 377 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 378 | private: |
| 379 | // Calculating invariant color / coverage information is expensive, so we partially cache the |
| 380 | // results. |
| 381 | // |
| 382 | // canUseFracCoveragePrimProc() - Called in regular skia draw, caches results but only for a |
| 383 | // specific color and coverage. May be called multiple times |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 384 | // GrOptDrawState constructor - never caches results |
joshualitt | d15e4e4 | 2015-01-26 13:30:10 -0800 | [diff] [blame] | 385 | |
| 386 | /** |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 387 | * GrBatch provides the initial seed for these loops based off of its initial geometry data |
| 388 | */ |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 389 | void calcColorInvariantOutput(const GrDrawBatch*) const; |
| 390 | void calcCoverageInvariantOutput(const GrDrawBatch*) const; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 391 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 392 | // Some of the auto restore objects assume that no effects are removed during their lifetime. |
| 393 | // This is used to assert that this condition holds. |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 394 | SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;) |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 395 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 396 | typedef SkSTArray<4, const GrFragmentProcessor*, true> FragmentProcessorArray; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 397 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 398 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 399 | uint32_t fFlags; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 400 | GrStencilSettings fStencilSettings; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 401 | DrawFace fDrawFace; |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 402 | mutable SkAutoTUnref<const GrXPFactory> fXPFactory; |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 403 | FragmentProcessorArray fColorFragmentProcessors; |
| 404 | FragmentProcessorArray fCoverageFragmentProcessors; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 405 | GrClip fClip; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 406 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 407 | mutable GrProcOptInfo fColorProcInfo; |
| 408 | mutable GrProcOptInfo fCoverageProcInfo; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 409 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 410 | friend class GrPipeline; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 411 | }; |
| 412 | |
| 413 | #endif |