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" |
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" |
joshualitt | 2cdec31 | 2015-07-09 07:31:31 -0700 | [diff] [blame] | 17 | #include "GrProcessorDataManager.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 | |
joshualitt | 5bf99f1 | 2015-03-13 11:47:42 -0700 | [diff] [blame] | 27 | class GrBatch; |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 28 | class GrCaps; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 29 | class GrPaint; |
| 30 | class GrTexture; |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 31 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 32 | class GrPipelineBuilder { |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 33 | public: |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 34 | GrPipelineBuilder(); |
| 35 | |
| 36 | GrPipelineBuilder(const GrPipelineBuilder& pipelineBuilder) { |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 37 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 38 | *this = pipelineBuilder; |
bsalomon@google.com | 46f7afb | 2012-01-18 19:51:55 +0000 | [diff] [blame] | 39 | } |
| 40 | |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 41 | /** |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 42 | * Initializes the GrPipelineBuilder based on a GrPaint, render target, and clip. Note |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 43 | * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have |
| 44 | * no GrPaint equivalents are set to default values with the exception of vertex attribute state |
| 45 | * 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] | 46 | */ |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 47 | GrPipelineBuilder(const GrPaint&, GrRenderTarget*, const GrClip&); |
| 48 | |
| 49 | virtual ~GrPipelineBuilder(); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 50 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 51 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 52 | /// @name Fragment Processors |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 53 | /// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 54 | /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage. |
| 55 | /// There are two chains of FPs, one for color and one for coverage. The first FP in each |
| 56 | /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output |
| 57 | /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs |
| 58 | /// feed their output to the GrXferProcessor which controls blending. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 59 | //// |
| 60 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 61 | int numColorFragmentStages() const { return fColorStages.count(); } |
| 62 | int numCoverageFragmentStages() const { return fCoverageStages.count(); } |
| 63 | int numFragmentStages() const { return this->numColorFragmentStages() + |
| 64 | this->numCoverageFragmentStages(); } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 65 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 66 | const GrFragmentStage& getColorFragmentStage(int idx) const { return fColorStages[idx]; } |
| 67 | const GrFragmentStage& getCoverageFragmentStage(int idx) const { return fCoverageStages[idx]; } |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 68 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 69 | const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 70 | SkASSERT(effect); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 71 | SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 72 | fColorProcInfoValid = false; |
jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 73 | return effect; |
| 74 | } |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 75 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 76 | const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 77 | SkASSERT(effect); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 78 | SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 79 | fCoverageProcInfoValid = false; |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 80 | return effect; |
| 81 | } |
| 82 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 83 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 84 | * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates. |
tomhudson@google.com | 1e8f016 | 2012-07-20 16:25:18 +0000 | [diff] [blame] | 85 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 86 | void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
joshualitt | 5b4f05f | 2015-07-10 07:26:21 -0700 | [diff] [blame] | 87 | this->addColorProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 88 | matrix))->unref(); |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 89 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 90 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 91 | void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
joshualitt | 5b4f05f | 2015-07-10 07:26:21 -0700 | [diff] [blame] | 92 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 93 | matrix))->unref(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 94 | } |
| 95 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 96 | void addColorTextureProcessor(GrTexture* texture, |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 97 | const SkMatrix& matrix, |
| 98 | const GrTextureParams& params) { |
joshualitt | 5b4f05f | 2015-07-10 07:26:21 -0700 | [diff] [blame] | 99 | this->addColorProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 100 | params))->unref(); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void addCoverageTextureProcessor(GrTexture* texture, |
| 104 | const SkMatrix& matrix, |
| 105 | const GrTextureParams& params) { |
joshualitt | 5b4f05f | 2015-07-10 07:26:21 -0700 | [diff] [blame] | 106 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(fProcDataManager, texture, matrix, |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 107 | params))->unref(); |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 108 | } |
tomhudson@google.com | 676e660 | 2012-07-10 17:21:48 +0000 | [diff] [blame] | 109 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 110 | /** |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 111 | * When this object is destroyed it will remove any color/coverage FPs from the pipeline builder |
| 112 | * that were added after its constructor. |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 113 | * This class can transiently modify its "const" GrPipelineBuilder object but will restore it |
| 114 | * when done - so it is notionally "const" correct. |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 115 | */ |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 116 | class AutoRestoreFragmentProcessors : public ::SkNoncopyable { |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 117 | public: |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 118 | AutoRestoreFragmentProcessors() |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 119 | : fPipelineBuilder(NULL) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 120 | , fColorEffectCnt(0) |
| 121 | , fCoverageEffectCnt(0) {} |
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(GrPipelineBuilder* ds) |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 124 | : fPipelineBuilder(NULL) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 125 | , fColorEffectCnt(0) |
| 126 | , fCoverageEffectCnt(0) { |
skia.committer@gmail.com | 5c493d5 | 2013-06-14 07:00:49 +0000 | [diff] [blame] | 127 | this->set(ds); |
robertphillips@google.com | f09b87d | 2013-06-13 20:06:44 +0000 | [diff] [blame] | 128 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 129 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 130 | ~AutoRestoreFragmentProcessors() { this->set(NULL); } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 131 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 132 | void set(const GrPipelineBuilder* ds); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 133 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 134 | bool isSet() const { return SkToBool(fPipelineBuilder); } |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 135 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 136 | const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* processor) { |
| 137 | SkASSERT(this->isSet()); |
| 138 | return fPipelineBuilder->addCoverageProcessor(processor); |
| 139 | } |
| 140 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 141 | private: |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 142 | // notionally const (as marginalia) |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 143 | GrPipelineBuilder* fPipelineBuilder; |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 144 | int fColorEffectCnt; |
| 145 | int fCoverageEffectCnt; |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 146 | }; |
| 147 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 148 | /// @} |
| 149 | |
| 150 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 151 | /// @name Blending |
| 152 | //// |
| 153 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 154 | /** |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 155 | * Returns true if this pipeline's color output will be affected by the existing render target |
| 156 | * destination pixel values (meaning we need to be careful with overlapping draws). Note that we |
| 157 | * can conflate coverage and color, so the destination color may still bleed into pixels that |
| 158 | * have partial coverage, even if this function returns false. |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 159 | */ |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 160 | bool willColorBlendWithDst(const GrPrimitiveProcessor*) const; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 161 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 162 | /** |
| 163 | * Installs a GrXPFactory. This object controls how src color, fractional pixel coverage, |
| 164 | * and the dst color are blended. |
| 165 | */ |
| 166 | const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
| 167 | fXPFactory.reset(SkRef(xpFactory)); |
| 168 | return xpFactory; |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Sets a GrXPFactory that will ignore src color and perform a set operation between the draws |
| 173 | * output coverage and the destination. This is useful to render coverage masks as CSG. |
| 174 | */ |
| 175 | void setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCoverage = false) { |
| 176 | fXPFactory.reset(GrCoverageSetOpXPFactory::Create(regionOp, invertCoverage)); |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Sets a GrXPFactory that disables color writes to the destination. This is useful when |
| 181 | * rendering to the stencil buffer. |
| 182 | */ |
| 183 | void setDisableColorXPFactory() { |
| 184 | fXPFactory.reset(GrDisableColorXPFactory::Create()); |
| 185 | } |
| 186 | |
| 187 | const GrXPFactory* getXPFactory() const { |
| 188 | if (!fXPFactory) { |
| 189 | fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode)); |
| 190 | } |
| 191 | return fXPFactory.get(); |
| 192 | } |
| 193 | |
| 194 | /** |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 195 | * Checks whether the xp will need destination in a texture to correctly blend. |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 196 | */ |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 197 | bool willXPNeedDstTexture(const GrCaps& caps, const GrProcOptInfo& colorPOI, |
| 198 | const GrProcOptInfo& coveragePOI) const; |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 199 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 200 | /// @} |
| 201 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 202 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 203 | /////////////////////////////////////////////////////////////////////////// |
| 204 | /// @name Render Target |
| 205 | //// |
| 206 | |
| 207 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 208 | * Retrieves the currently set render-target. |
| 209 | * |
| 210 | * @return The currently set render target. |
| 211 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 212 | GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 213 | |
| 214 | /** |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 215 | * Sets the render-target used at the next drawing call |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 216 | * |
| 217 | * @param target The render target to set. |
| 218 | */ |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 219 | void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 220 | |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 221 | /** |
| 222 | * Returns whether the rasterizer and stencil test (if any) will run at a higher sample rate |
| 223 | * than the color buffer. In is scenario, the higher sample rate is resolved during blending. |
| 224 | */ |
| 225 | bool hasMixedSamples() const { |
vbuzinov | dded696 | 2015-06-12 08:59:45 -0700 | [diff] [blame] | 226 | return this->isHWAntialias() && !fRenderTarget->isUnifiedMultisampled(); |
cdalton | 86ae0a9 | 2015-06-08 15:11:04 -0700 | [diff] [blame] | 227 | } |
| 228 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 229 | /// @} |
| 230 | |
| 231 | /////////////////////////////////////////////////////////////////////////// |
| 232 | /// @name Stencil |
| 233 | //// |
| 234 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 235 | const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 236 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 237 | /** |
| 238 | * Sets the stencil settings to use for the next draw. |
| 239 | * Changing the clip has the side-effect of possibly zeroing |
| 240 | * out the client settable stencil bits. So multipass algorithms |
| 241 | * using stencil should not change the clip between passes. |
| 242 | * @param settings the stencil settings to use. |
| 243 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 244 | void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 245 | |
| 246 | /** |
| 247 | * Shortcut to disable stencil testing and ops. |
| 248 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 249 | void disableStencil() { fStencilSettings.setDisabled(); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 250 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 251 | GrStencilSettings* stencil() { return &fStencilSettings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 252 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 253 | /** |
| 254 | * AutoRestoreStencil |
| 255 | * |
| 256 | * This simple struct saves and restores the stencil settings |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 257 | * This class can transiently modify its "const" GrPipelineBuilder object but will restore it |
| 258 | * when done - so it is notionally "const" correct. |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 259 | */ |
| 260 | class AutoRestoreStencil : public ::SkNoncopyable { |
| 261 | public: |
| 262 | AutoRestoreStencil() : fPipelineBuilder(NULL) {} |
| 263 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 264 | AutoRestoreStencil(const GrPipelineBuilder* ds) : fPipelineBuilder(NULL) { this->set(ds); } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 265 | |
| 266 | ~AutoRestoreStencil() { this->set(NULL); } |
| 267 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 268 | void set(const GrPipelineBuilder* ds) { |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 269 | if (fPipelineBuilder) { |
| 270 | fPipelineBuilder->setStencil(fStencilSettings); |
| 271 | } |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 272 | fPipelineBuilder = const_cast<GrPipelineBuilder*>(ds); |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 273 | if (ds) { |
| 274 | fStencilSettings = ds->getStencil(); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | bool isSet() const { return SkToBool(fPipelineBuilder); } |
| 279 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 280 | void setStencil(const GrStencilSettings& settings) { |
| 281 | SkASSERT(this->isSet()); |
| 282 | fPipelineBuilder->setStencil(settings); |
| 283 | } |
| 284 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 285 | private: |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 286 | // notionally const (as marginalia) |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 287 | GrPipelineBuilder* fPipelineBuilder; |
| 288 | GrStencilSettings fStencilSettings; |
| 289 | }; |
| 290 | |
| 291 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 292 | /// @} |
| 293 | |
| 294 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 295 | /// @name State Flags |
| 296 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 297 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 298 | /** |
| 299 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 300 | * default to disabled. |
| 301 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 302 | enum Flags { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 303 | /** |
| 304 | * Perform dithering. TODO: Re-evaluate whether we need this bit |
| 305 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 306 | kDither_Flag = 0x01, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 307 | /** |
| 308 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 309 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 310 | * the 3D API. |
| 311 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 312 | kHWAntialias_Flag = 0x02, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 313 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 314 | /** |
| 315 | * Modifies the vertex shader so that vertices will be positioned at pixel centers. |
| 316 | */ |
| 317 | kSnapVerticesToPixelCenters_Flag = 0x04, |
| 318 | |
| 319 | kLast_Flag = kSnapVerticesToPixelCenters_Flag, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 320 | }; |
| 321 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 322 | bool isDither() const { return SkToBool(fFlags & kDither_Flag); } |
| 323 | bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); } |
| 324 | bool snapVerticesToPixelCenters() const { |
| 325 | return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 326 | |
| 327 | /** |
| 328 | * Enable render state settings. |
| 329 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 330 | * @param flags bitfield of Flags specifying the states to enable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 331 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 332 | void enableState(uint32_t flags) { fFlags |= flags; } |
| 333 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 334 | /** |
| 335 | * Disable render state settings. |
| 336 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 337 | * @param flags bitfield of Flags specifying the states to disable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 338 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 339 | void disableState(uint32_t flags) { fFlags &= ~(flags); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 340 | |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 341 | /** |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 342 | * Enable or disable flags based on a boolean. |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 343 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 344 | * @param flags bitfield of Flags to enable or disable |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 345 | * @param enable if true enable stateBits, otherwise disable |
| 346 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 347 | void setState(uint32_t flags, bool enable) { |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 348 | if (enable) { |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 349 | this->enableState(flags); |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 350 | } else { |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 351 | this->disableState(flags); |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 355 | /// @} |
| 356 | |
| 357 | /////////////////////////////////////////////////////////////////////////// |
| 358 | /// @name Face Culling |
| 359 | //// |
| 360 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 361 | enum DrawFace { |
| 362 | kInvalid_DrawFace = -1, |
| 363 | |
| 364 | kBoth_DrawFace, |
| 365 | kCCW_DrawFace, |
| 366 | kCW_DrawFace, |
| 367 | }; |
| 368 | |
| 369 | /** |
| 370 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 371 | * or both faces. |
| 372 | * @return the current draw face(s). |
| 373 | */ |
| 374 | DrawFace getDrawFace() const { return fDrawFace; } |
| 375 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 376 | /** |
| 377 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 378 | * @param face the face(s) to draw. |
| 379 | */ |
| 380 | void setDrawFace(DrawFace face) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 381 | SkASSERT(kInvalid_DrawFace != face); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 382 | fDrawFace = face; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 383 | } |
| 384 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 385 | /// @} |
| 386 | |
| 387 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 388 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 389 | GrPipelineBuilder& operator=(const GrPipelineBuilder& that); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 390 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 391 | // TODO delete when we have Batch |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 392 | const GrProcOptInfo& colorProcInfo(const GrPrimitiveProcessor* pp) const { |
| 393 | this->calcColorInvariantOutput(pp); |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 394 | return fColorProcInfo; |
| 395 | } |
| 396 | |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 397 | const GrProcOptInfo& coverageProcInfo(const GrPrimitiveProcessor* pp) const { |
| 398 | this->calcCoverageInvariantOutput(pp); |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 399 | return fCoverageProcInfo; |
| 400 | } |
| 401 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 402 | const GrProcOptInfo& colorProcInfo(const GrBatch* batch) const { |
| 403 | this->calcColorInvariantOutput(batch); |
| 404 | return fColorProcInfo; |
| 405 | } |
| 406 | |
| 407 | const GrProcOptInfo& coverageProcInfo(const GrBatch* batch) const { |
| 408 | this->calcCoverageInvariantOutput(batch); |
| 409 | return fCoverageProcInfo; |
| 410 | } |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 411 | |
| 412 | void setClip(const GrClip& clip) { fClip = clip; } |
| 413 | const GrClip& clip() const { return fClip; } |
| 414 | |
joshualitt | 5b4f05f | 2015-07-10 07:26:21 -0700 | [diff] [blame] | 415 | GrProcessorDataManager* getProcessorDataManager() { return fProcDataManager.get(); } |
| 416 | const GrProcessorDataManager* processorDataManager() const { return fProcDataManager.get(); } |
joshualitt | 2cdec31 | 2015-07-09 07:31:31 -0700 | [diff] [blame] | 417 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 418 | /** |
| 419 | * When this object is destroyed it will remove any additions to the GrProcessorDataManager |
| 420 | * owned by the GrPipelineBuilder |
| 421 | * This class can transiently modify its "const" GrPipelineBuilder object but will restore it |
| 422 | * when done - so it is notionally "const" correct. |
| 423 | */ |
| 424 | class AutoRestoreProcessorDataManager : public ::SkNoncopyable { |
| 425 | public: |
| 426 | AutoRestoreProcessorDataManager() : fPipelineBuilder(NULL), fSaveMarker(0) {} |
| 427 | |
| 428 | AutoRestoreProcessorDataManager(GrPipelineBuilder* ds) |
| 429 | : fPipelineBuilder(NULL) |
| 430 | , fSaveMarker(0) { |
| 431 | this->set(ds); |
| 432 | } |
| 433 | |
| 434 | ~AutoRestoreProcessorDataManager() { this->set(NULL); } |
| 435 | |
| 436 | void set(const GrPipelineBuilder* ds) { |
| 437 | if (fPipelineBuilder) { |
| 438 | fPipelineBuilder->getProcessorDataManager()->restoreToSaveMarker(/*fSaveMarker*/); |
| 439 | } |
| 440 | fPipelineBuilder = const_cast<GrPipelineBuilder*>(ds); |
| 441 | if (ds) { |
| 442 | fSaveMarker = ds->processorDataManager()->currentSaveMarker(); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | bool isSet() const { return SkToBool(fPipelineBuilder); } |
| 447 | |
| 448 | GrProcessorDataManager* getProcessorDataManager() { |
| 449 | SkASSERT(this->isSet()); |
| 450 | return fPipelineBuilder->getProcessorDataManager(); |
| 451 | } |
| 452 | |
| 453 | private: |
| 454 | // notionally const (as marginalia) |
| 455 | GrPipelineBuilder* fPipelineBuilder; |
| 456 | uint32_t fSaveMarker; |
| 457 | }; |
| 458 | |
| 459 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 460 | private: |
| 461 | // Calculating invariant color / coverage information is expensive, so we partially cache the |
| 462 | // results. |
| 463 | // |
| 464 | // canUseFracCoveragePrimProc() - Called in regular skia draw, caches results but only for a |
| 465 | // specific color and coverage. May be called multiple times |
cdalton | 1fa4572 | 2015-06-02 10:43:39 -0700 | [diff] [blame] | 466 | // willColorBlendWithDst() - only called by Nvpr, does not cache results |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 467 | // GrOptDrawState constructor - never caches results |
joshualitt | d15e4e4 | 2015-01-26 13:30:10 -0800 | [diff] [blame] | 468 | |
| 469 | /** |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 470 | * Primproc variants of the calc functions |
| 471 | * TODO remove these when batch is everywhere |
joshualitt | d5a7db4 | 2015-01-27 15:39:06 -0800 | [diff] [blame] | 472 | */ |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 473 | void calcColorInvariantOutput(const GrPrimitiveProcessor*) const; |
joshualitt | c2893c5 | 2015-01-28 06:54:30 -0800 | [diff] [blame] | 474 | void calcCoverageInvariantOutput(const GrPrimitiveProcessor*) const; |
joshualitt | d5a7db4 | 2015-01-27 15:39:06 -0800 | [diff] [blame] | 475 | |
| 476 | /** |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 477 | * GrBatch provides the initial seed for these loops based off of its initial geometry data |
| 478 | */ |
| 479 | void calcColorInvariantOutput(const GrBatch*) const; |
| 480 | void calcCoverageInvariantOutput(const GrBatch*) const; |
| 481 | |
| 482 | /** |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 483 | * If fColorProcInfoValid is false, function calculates the invariant output for the color |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 484 | * processors and results are stored in fColorProcInfo. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 485 | */ |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 486 | void calcColorInvariantOutput(GrColor) const; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 487 | |
| 488 | /** |
| 489 | * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 490 | * processors and results are stored in fCoverageProcInfo. |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 491 | */ |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 492 | void calcCoverageInvariantOutput(GrColor) const; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 493 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 494 | // Some of the auto restore objects assume that no effects are removed during their lifetime. |
| 495 | // This is used to assert that this condition holds. |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame^] | 496 | SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;) |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 497 | |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 498 | typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 499 | |
joshualitt | 5b4f05f | 2015-07-10 07:26:21 -0700 | [diff] [blame] | 500 | SkAutoTUnref<GrProcessorDataManager> fProcDataManager; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 501 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 502 | uint32_t fFlags; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 503 | GrStencilSettings fStencilSettings; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 504 | DrawFace fDrawFace; |
joshualitt | 2fdeda0 | 2015-01-22 07:11:44 -0800 | [diff] [blame] | 505 | mutable SkAutoTUnref<const GrXPFactory> fXPFactory; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 506 | FragmentStageArray fColorStages; |
| 507 | FragmentStageArray fCoverageStages; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 508 | GrClip fClip; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 509 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 510 | mutable GrProcOptInfo fColorProcInfo; |
| 511 | mutable GrProcOptInfo fCoverageProcInfo; |
| 512 | mutable bool fColorProcInfoValid; |
| 513 | mutable bool fCoverageProcInfoValid; |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 514 | mutable GrColor fColorCache; |
| 515 | mutable GrColor fCoverageCache; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 516 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 517 | friend class GrPipeline; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | #endif |