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" |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 12 | #include "GrClip.h" |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 13 | #include "GrDrawTargetCaps.h" |
bsalomon | f96ba02 | 2014-09-17 08:05:40 -0700 | [diff] [blame] | 14 | #include "GrGpuResourceRef.h" |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 15 | #include "GrFragmentStage.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 16 | #include "GrProcOptInfo.h" |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 17 | #include "GrRenderTarget.h" |
| 18 | #include "GrStencil.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 19 | #include "GrXferProcessor.h" |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 20 | #include "SkMatrix.h" |
egdaniel | 8750924 | 2014-12-17 13:37:13 -0800 | [diff] [blame] | 21 | #include "effects/GrCoverageSetOpXP.h" |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 22 | #include "effects/GrDisableColorXP.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 23 | #include "effects/GrPorterDuffXferProcessor.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 24 | #include "effects/GrSimpleTextureEffect.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 25 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame^] | 26 | class GrBatch; |
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 | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 48 | void setFromPaint(const GrPaint&, GrRenderTarget*, const GrClip&); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 49 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 50 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 51 | /// @name Fragment Processors |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 52 | /// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 53 | /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage. |
| 54 | /// There are two chains of FPs, one for color and one for coverage. The first FP in each |
| 55 | /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output |
| 56 | /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs |
| 57 | /// feed their output to the GrXferProcessor which controls blending. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 58 | //// |
| 59 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 60 | int numColorFragmentStages() const { return fColorStages.count(); } |
| 61 | int numCoverageFragmentStages() const { return fCoverageStages.count(); } |
| 62 | int numFragmentStages() const { return this->numColorFragmentStages() + |
| 63 | this->numCoverageFragmentStages(); } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 64 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 65 | const GrFragmentStage& getColorFragmentStage(int idx) const { return fColorStages[idx]; } |
| 66 | const GrFragmentStage& getCoverageFragmentStage(int idx) const { return fCoverageStages[idx]; } |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 67 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 68 | const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 69 | SkASSERT(effect); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 70 | SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 71 | fColorProcInfoValid = false; |
jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 72 | return effect; |
| 73 | } |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 74 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 75 | const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 76 | SkASSERT(effect); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 77 | SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 78 | fCoverageProcInfoValid = false; |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 79 | return effect; |
| 80 | } |
| 81 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 82 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 83 | * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates. |
tomhudson@google.com | 1e8f016 | 2012-07-20 16:25:18 +0000 | [diff] [blame] | 84 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 85 | void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 86 | this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 87 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 88 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 89 | void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 90 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 91 | } |
| 92 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 93 | void addColorTextureProcessor(GrTexture* texture, |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 94 | const SkMatrix& matrix, |
| 95 | const GrTextureParams& params) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 96 | this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
| 97 | } |
| 98 | |
| 99 | void addCoverageTextureProcessor(GrTexture* texture, |
| 100 | const SkMatrix& matrix, |
| 101 | const GrTextureParams& params) { |
| 102 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 103 | } |
tomhudson@google.com | 676e660 | 2012-07-10 17:21:48 +0000 | [diff] [blame] | 104 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 105 | /** |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 106 | * When this object is destroyed it will remove any color/coverage FPs from the pipeline builder |
| 107 | * that were added after its constructor. |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 108 | */ |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 109 | class AutoRestoreFragmentProcessors : public ::SkNoncopyable { |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 110 | public: |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 111 | AutoRestoreFragmentProcessors() |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 112 | : fPipelineBuilder(NULL) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 113 | , fColorEffectCnt(0) |
| 114 | , fCoverageEffectCnt(0) {} |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 115 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 116 | AutoRestoreFragmentProcessors(GrPipelineBuilder* ds) |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 117 | : fPipelineBuilder(NULL) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 118 | , fColorEffectCnt(0) |
| 119 | , fCoverageEffectCnt(0) { |
skia.committer@gmail.com | 5c493d5 | 2013-06-14 07:00:49 +0000 | [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 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 123 | ~AutoRestoreFragmentProcessors() { this->set(NULL); } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 124 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 125 | void set(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 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 129 | private: |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 130 | GrPipelineBuilder* fPipelineBuilder; |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 131 | int fColorEffectCnt; |
| 132 | int fCoverageEffectCnt; |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 135 | /// @} |
| 136 | |
| 137 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 138 | /// @name Blending |
| 139 | //// |
| 140 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 141 | /** |
| 142 | * Determines whether multiplying the computed per-pixel color by the pixel's fractional |
| 143 | * coverage before the blend will give the correct final destination color. In general it |
| 144 | * will not as coverage is applied after blending. |
| 145 | */ |
| 146 | bool canTweakAlphaForCoverage() const; |
| 147 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 148 | /** |
| 149 | * This function returns true if the render target destination pixel values will be read for |
| 150 | * blending during draw. |
| 151 | */ |
| 152 | bool willBlendWithDst(const GrPrimitiveProcessor*) const; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 153 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 154 | /** |
| 155 | * Installs a GrXPFactory. This object controls how src color, fractional pixel coverage, |
| 156 | * and the dst color are blended. |
| 157 | */ |
| 158 | const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
| 159 | fXPFactory.reset(SkRef(xpFactory)); |
| 160 | return xpFactory; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Sets a GrXPFactory that will ignore src color and perform a set operation between the draws |
| 165 | * output coverage and the destination. This is useful to render coverage masks as CSG. |
| 166 | */ |
| 167 | void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) { |
| 168 | fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage)); |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Sets a GrXPFactory that disables color writes to the destination. This is useful when |
| 173 | * rendering to the stencil buffer. |
| 174 | */ |
| 175 | void setDisableColorXPFactory() { |
| 176 | fXPFactory.reset(GrDisableColorXPFactory::Create()); |
| 177 | } |
| 178 | |
| 179 | const GrXPFactory* getXPFactory() const { |
| 180 | if (!fXPFactory) { |
| 181 | fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
| 182 | } |
| 183 | return fXPFactory.get(); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Checks whether the xp will need a copy of the destination to correctly blend. |
| 188 | */ |
| 189 | bool willXPNeedDstCopy(const GrDrawTargetCaps& caps, const GrProcOptInfo& colorPOI, |
| 190 | const GrProcOptInfo& coveragePOI) const; |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 191 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 192 | /// @} |
| 193 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 194 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 195 | /////////////////////////////////////////////////////////////////////////// |
| 196 | /// @name Render Target |
| 197 | //// |
| 198 | |
| 199 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 200 | * Retrieves the currently set render-target. |
| 201 | * |
| 202 | * @return The currently set render target. |
| 203 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 204 | GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 205 | |
| 206 | /** |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 207 | * Sets the render-target used at the next drawing call |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 208 | * |
| 209 | * @param target The render target to set. |
| 210 | */ |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 211 | void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 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 | |
| 230 | /** |
| 231 | * Shortcut to disable stencil testing and ops. |
| 232 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 233 | void disableStencil() { fStencilSettings.setDisabled(); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 234 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 235 | GrStencilSettings* stencil() { return &fStencilSettings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 236 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 237 | /** |
| 238 | * AutoRestoreStencil |
| 239 | * |
| 240 | * This simple struct saves and restores the stencil settings |
| 241 | */ |
| 242 | class AutoRestoreStencil : public ::SkNoncopyable { |
| 243 | public: |
| 244 | AutoRestoreStencil() : fPipelineBuilder(NULL) {} |
| 245 | |
| 246 | AutoRestoreStencil(GrPipelineBuilder* ds) : fPipelineBuilder(NULL) { this->set(ds); } |
| 247 | |
| 248 | ~AutoRestoreStencil() { this->set(NULL); } |
| 249 | |
| 250 | void set(GrPipelineBuilder* ds) { |
| 251 | if (fPipelineBuilder) { |
| 252 | fPipelineBuilder->setStencil(fStencilSettings); |
| 253 | } |
| 254 | fPipelineBuilder = ds; |
| 255 | if (ds) { |
| 256 | fStencilSettings = ds->getStencil(); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | bool isSet() const { return SkToBool(fPipelineBuilder); } |
| 261 | |
| 262 | private: |
| 263 | GrPipelineBuilder* fPipelineBuilder; |
| 264 | GrStencilSettings fStencilSettings; |
| 265 | }; |
| 266 | |
| 267 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 268 | /// @} |
| 269 | |
| 270 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 271 | /// @name State Flags |
| 272 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 273 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 274 | /** |
| 275 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 276 | * default to disabled. |
| 277 | */ |
| 278 | enum StateBits { |
| 279 | /** |
| 280 | * Perform dithering. TODO: Re-evaluate whether we need this bit |
| 281 | */ |
| 282 | kDither_StateBit = 0x01, |
| 283 | /** |
| 284 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 285 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 286 | * the 3D API. |
| 287 | */ |
| 288 | kHWAntialias_StateBit = 0x02, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 289 | |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 290 | kLast_StateBit = kHWAntialias_StateBit, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 291 | }; |
| 292 | |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 293 | bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); } |
| 294 | bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 295 | |
| 296 | /** |
| 297 | * Enable render state settings. |
| 298 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 299 | * @param stateBits bitfield of StateBits specifying the states to enable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 300 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 301 | void enableState(uint32_t stateBits) { fFlagBits |= stateBits; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 302 | |
| 303 | /** |
| 304 | * Disable render state settings. |
| 305 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 306 | * @param stateBits bitfield of StateBits specifying the states to disable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 307 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 308 | void disableState(uint32_t stateBits) { fFlagBits &= ~(stateBits); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 309 | |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 310 | /** |
| 311 | * Enable or disable stateBits based on a boolean. |
| 312 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 313 | * @param stateBits bitfield of StateBits to enable or disable |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 314 | * @param enable if true enable stateBits, otherwise disable |
| 315 | */ |
| 316 | void setState(uint32_t stateBits, bool enable) { |
| 317 | if (enable) { |
| 318 | this->enableState(stateBits); |
| 319 | } else { |
| 320 | this->disableState(stateBits); |
| 321 | } |
| 322 | } |
| 323 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 324 | /// @} |
| 325 | |
| 326 | /////////////////////////////////////////////////////////////////////////// |
| 327 | /// @name Face Culling |
| 328 | //// |
| 329 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 330 | enum DrawFace { |
| 331 | kInvalid_DrawFace = -1, |
| 332 | |
| 333 | kBoth_DrawFace, |
| 334 | kCCW_DrawFace, |
| 335 | kCW_DrawFace, |
| 336 | }; |
| 337 | |
| 338 | /** |
| 339 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 340 | * or both faces. |
| 341 | * @return the current draw face(s). |
| 342 | */ |
| 343 | DrawFace getDrawFace() const { return fDrawFace; } |
| 344 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 345 | /** |
| 346 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 347 | * @param face the face(s) to draw. |
| 348 | */ |
| 349 | void setDrawFace(DrawFace face) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 350 | SkASSERT(kInvalid_DrawFace != face); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 351 | fDrawFace = face; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 352 | } |
| 353 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 354 | /// @} |
| 355 | |
| 356 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 357 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 358 | GrPipelineBuilder& operator=(const GrPipelineBuilder& that); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 359 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 360 | // TODO delete when we have Batch |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 361 | const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { |
| 362 | this->calcColorInvariantOutput(pp); |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 363 | return fColorProcInfo; |
| 364 | } |
| 365 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 366 | const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const { |
| 367 | this->calcCoverageInvariantOutput(pp); |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 368 | return fCoverageProcInfo; |
| 369 | } |
| 370 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 371 | const GrProcOptInfo& colorProcInfo(const GrBatch* batch) const { |
| 372 | this->calcColorInvariantOutput(batch); |
| 373 | return fColorProcInfo; |
| 374 | } |
| 375 | |
| 376 | const GrProcOptInfo& coverageProcInfo(const GrBatch* batch) const { |
| 377 | this->calcCoverageInvariantOutput(batch); |
| 378 | return fCoverageProcInfo; |
| 379 | } |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 380 | |
| 381 | void setClip(const GrClip& clip) { fClip = clip; } |
| 382 | const GrClip& clip() const { return fClip; } |
| 383 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 384 | private: |
| 385 | // Calculating invariant color / coverage information is expensive, so we partially cache the |
| 386 | // results. |
| 387 | // |
| 388 | // canUseFracCoveragePrimProc() - Called in regular skia draw, caches results but only for a |
| 389 | // specific color and coverage. May be called multiple times |
| 390 | // willBlendWithDst() - only called by Nvpr, does not cache results |
| 391 | // GrOptDrawState constructor - never caches results |
joshualitt | d15e4e4 | 2015-01-26 13:30:10 -0800 | [diff] [blame] | 392 | |
| 393 | /** |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 394 | * Primproc variants of the calc functions |
| 395 | * TODO remove these when batch is everywhere |
joshualitt | d5a7db4 | 2015-01-27 15:39:06 -0800 | [diff] [blame] | 396 | */ |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 397 | void calcColorInvariantOutput(const GrPrimitiveProcessor*) const; |
joshualitt | c2893c5 | 2015-01-28 06:54:30 -0800 | [diff] [blame] | 398 | void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const; |
joshualitt | d5a7db4 | 2015-01-27 15:39:06 -0800 | [diff] [blame] | 399 | |
| 400 | /** |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 401 | * GrBatch provides the initial seed for these loops based off of its initial geometry data |
| 402 | */ |
| 403 | void calcColorInvariantOutput(const GrBatch*) const; |
| 404 | void calcCoverageInvariantOutput(const GrBatch*) const; |
| 405 | |
| 406 | /** |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 407 | * If fColorProcInfoValid is false, function calculates the invariant output for the color |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 408 | * processors and results are stored in fColorProcInfo. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 409 | */ |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 410 | void calcColorInvariantOutput(GrColor) const; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 411 | |
| 412 | /** |
| 413 | * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 414 | * processors and results are stored in fCoverageProcInfo. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 415 | */ |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 416 | void calcCoverageInvariantOutput(GrColor) const; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 417 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 418 | // Some of the auto restore objects assume that no effects are removed during their lifetime. |
| 419 | // This is used to assert that this condition holds. |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 420 | SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 421 | |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 422 | typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 423 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 424 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 425 | uint32_t fFlagBits; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 426 | GrStencilSettings fStencilSettings; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 427 | DrawFace fDrawFace; |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 428 | mutable SkAutoTUnref<const GrXPFactory> fXPFactory; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 429 | FragmentStageArray fColorStages; |
| 430 | FragmentStageArray fCoverageStages; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 431 | GrClip fClip; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 432 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 433 | mutable GrProcOptInfo fColorProcInfo; |
| 434 | mutable GrProcOptInfo fCoverageProcInfo; |
| 435 | mutable bool fColorProcInfoValid; |
| 436 | mutable bool fCoverageProcInfoValid; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 437 | mutable GrColor fColorCache; |
| 438 | mutable GrColor fCoverageCache; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 439 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 440 | friend class GrPipeline; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 441 | }; |
| 442 | |
| 443 | #endif |