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