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" |
bsalomon | f96ba02 | 2014-09-17 08:05:40 -0700 | [diff] [blame] | 13 | #include "GrGpuResourceRef.h" |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 14 | #include "GrProcOptInfo.h" |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 15 | #include "GrRenderTarget.h" |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 16 | #include "GrUserStencilSettings.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 17 | #include "GrXferProcessor.h" |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 18 | #include "SkMatrix.h" |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 19 | #include "SkRefCnt.h" |
egdaniel | 8750924 | 2014-12-17 13:37:13 -0800 | [diff] [blame] | 20 | #include "effects/GrCoverageSetOpXP.h" |
egdaniel | 080e673 | 2014-12-22 07:35:52 -0800 | [diff] [blame] | 21 | #include "effects/GrDisableColorXP.h" |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 22 | #include "effects/GrPorterDuffXferProcessor.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 23 | #include "effects/GrSimpleTextureEffect.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 24 | |
bsalomon | abd30f5 | 2015-08-13 13:34:48 -0700 | [diff] [blame] | 25 | class GrDrawBatch; |
bsalomon | 4b91f76 | 2015-05-19 09:29:46 -0700 | [diff] [blame] | 26 | class GrCaps; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 27 | class GrPaint; |
| 28 | class GrTexture; |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 29 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 30 | class GrPipelineBuilder : public SkNoncopyable { |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 31 | public: |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 32 | GrPipelineBuilder(); |
| 33 | |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 34 | /** |
robertphillips | 55fdccc | 2016-06-06 06:16:20 -0700 | [diff] [blame] | 35 | * Initializes the GrPipelineBuilder based on a GrPaint and MSAA availability. Note |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 36 | * that GrPipelineBuilder encompasses more than GrPaint. Aspects of GrPipelineBuilder that have |
| 37 | * no GrPaint equivalents are set to default values with the exception of vertex attribute state |
| 38 | * which is unmodified by this function and clipping which will be enabled. |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 39 | */ |
csmartdalton | ecbc12b | 2016-06-08 10:08:43 -0700 | [diff] [blame] | 40 | GrPipelineBuilder(const GrPaint&, bool useHWAA = false); |
joshualitt | 7b670db | 2015-07-09 13:25:02 -0700 | [diff] [blame] | 41 | |
| 42 | virtual ~GrPipelineBuilder(); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 43 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 44 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 45 | /// @name Fragment Processors |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 46 | /// |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 47 | /// GrFragmentProcessors are used to compute per-pixel color and per-pixel fractional coverage. |
| 48 | /// There are two chains of FPs, one for color and one for coverage. The first FP in each |
| 49 | /// chain gets the initial color/coverage from the GrPrimitiveProcessor. It computes an output |
| 50 | /// color/coverage which is fed to the next FP in the chain. The last color and coverage FPs |
| 51 | /// feed their output to the GrXferProcessor which controls blending. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 52 | //// |
| 53 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 54 | int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); } |
| 55 | int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); } |
| 56 | int numFragmentProcessors() const { return this->numColorFragmentProcessors() + |
| 57 | this->numCoverageFragmentProcessors(); } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 58 | |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 59 | const GrFragmentProcessor* getColorFragmentProcessor(int idx) const { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 60 | return fColorFragmentProcessors[idx].get(); |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 61 | } |
| 62 | const GrFragmentProcessor* getCoverageFragmentProcessor(int idx) const { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 63 | return fCoverageFragmentProcessors[idx].get(); |
jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 64 | } |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 65 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 66 | void addColorFragmentProcessor(sk_sp<GrFragmentProcessor> processor) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 67 | SkASSERT(processor); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 68 | fColorFragmentProcessors.push_back(std::move(processor)); |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 69 | } |
| 70 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 71 | void addCoverageFragmentProcessor(sk_sp<GrFragmentProcessor> processor) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 72 | SkASSERT(processor); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 73 | fCoverageFragmentProcessors.push_back(std::move(processor)); |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 74 | } |
| 75 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 76 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 77 | * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates. |
tomhudson@google.com | 1e8f016 | 2012-07-20 16:25:18 +0000 | [diff] [blame] | 78 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 79 | void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 80 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix)); |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 81 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 82 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 83 | void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 84 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix)); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 85 | } |
| 86 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 87 | void addColorTextureProcessor(GrTexture* texture, |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 88 | const SkMatrix& matrix, |
| 89 | const GrTextureParams& params) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 90 | this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix, |
| 91 | params)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | void addCoverageTextureProcessor(GrTexture* texture, |
| 95 | const SkMatrix& matrix, |
| 96 | const GrTextureParams& params) { |
brianosman | 54f30c1 | 2016-07-18 10:53:52 -0700 | [diff] [blame] | 97 | this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix, |
| 98 | params)); |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 99 | } |
tomhudson@google.com | 676e660 | 2012-07-10 17:21:48 +0000 | [diff] [blame] | 100 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 101 | /** |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 102 | * When this object is destroyed it will remove any color/coverage FPs from the pipeline builder |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 103 | * that were added after its constructor. |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 104 | * This class can transiently modify its "const" GrPipelineBuilder object but will restore it |
| 105 | * when done - so it is notionally "const" correct. |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 106 | */ |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 107 | class AutoRestoreFragmentProcessorState : public ::SkNoncopyable { |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 108 | public: |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 109 | AutoRestoreFragmentProcessorState() |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 110 | : fPipelineBuilder(nullptr) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 111 | , fColorEffectCnt(0) |
joshualitt | af2533a | 2015-09-09 10:00:12 -0700 | [diff] [blame] | 112 | , fCoverageEffectCnt(0) {} |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 113 | |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 114 | AutoRestoreFragmentProcessorState(const GrPipelineBuilder& ds) |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 115 | : fPipelineBuilder(nullptr) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 116 | , fColorEffectCnt(0) |
joshualitt | af2533a | 2015-09-09 10:00:12 -0700 | [diff] [blame] | 117 | , fCoverageEffectCnt(0) { |
joshualitt | 4421a4c | 2015-07-13 09:36:41 -0700 | [diff] [blame] | 118 | this->set(&ds); |
robertphillips@google.com | f09b87d | 2013-06-13 20:06:44 +0000 | [diff] [blame] | 119 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 120 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 121 | ~AutoRestoreFragmentProcessorState() { this->set(nullptr); } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 122 | |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 123 | void set(const GrPipelineBuilder* ds); |
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 | bool isSet() const { return SkToBool(fPipelineBuilder); } |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 126 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 127 | void addCoverageFragmentProcessor(sk_sp<GrFragmentProcessor> processor) { |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 128 | SkASSERT(this->isSet()); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 129 | return fPipelineBuilder->addCoverageFragmentProcessor(std::move(processor)); |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 130 | } |
| 131 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 132 | private: |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 133 | // notionally const (as marginalia) |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 134 | GrPipelineBuilder* fPipelineBuilder; |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 135 | int fColorEffectCnt; |
| 136 | int fCoverageEffectCnt; |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 139 | /// @} |
| 140 | |
| 141 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 142 | /// @name Blending |
| 143 | //// |
| 144 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 145 | /** |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 146 | * Installs a GrXPFactory. This object controls how src color, fractional pixel coverage, |
| 147 | * and the dst color are blended. |
| 148 | */ |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 149 | void setXPFactory(sk_sp<GrXPFactory> xpFactory) { |
| 150 | fXPFactory = std::move(xpFactory); |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /** |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 154 | * Sets a GrXPFactory that disables color writes to the destination. This is useful when |
| 155 | * rendering to the stencil buffer. |
| 156 | */ |
| 157 | void setDisableColorXPFactory() { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 158 | fXPFactory = GrDisableColorXPFactory::Make(); |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | const GrXPFactory* getXPFactory() const { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 162 | return fXPFactory.get(); |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /** |
bsalomon | 6a44c6a | 2015-05-26 09:49:05 -0700 | [diff] [blame] | 166 | * Checks whether the xp will need destination in a texture to correctly blend. |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 167 | */ |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 168 | bool willXPNeedDstTexture(const GrCaps& caps, |
ethannicholas | de4166a | 2015-11-30 08:57:38 -0800 | [diff] [blame] | 169 | const GrPipelineOptimizations& optimizations) const; |
joshualitt | d27f73e | 2014-12-29 07:43:36 -0800 | [diff] [blame] | 170 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 171 | /// @} |
| 172 | |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 173 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 174 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 175 | /// @name Stencil |
| 176 | //// |
| 177 | |
robertphillips | 976f5f0 | 2016-06-03 10:59:20 -0700 | [diff] [blame] | 178 | bool hasUserStencilSettings() const { return !fUserStencilSettings->isUnused(); } |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 179 | const GrUserStencilSettings* getUserStencil() const { return fUserStencilSettings; } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 180 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 181 | /** |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 182 | * Sets the user stencil settings for the next draw. |
| 183 | * This class only stores pointers to stencil settings objects. |
| 184 | * The caller guarantees the pointer will remain valid until it |
| 185 | * changes or goes out of scope. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 186 | * @param settings the stencil settings to use. |
| 187 | */ |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 188 | void setUserStencil(const GrUserStencilSettings* settings) { fUserStencilSettings = settings; } |
| 189 | void disableUserStencil() { fUserStencilSettings = &GrUserStencilSettings::kUnused; } |
bsalomon | 6be6f7c | 2015-02-26 13:05:21 -0800 | [diff] [blame] | 190 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 191 | /// @} |
| 192 | |
| 193 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 194 | /// @name State Flags |
| 195 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 196 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 197 | /** |
| 198 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 199 | * default to disabled. |
| 200 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 201 | enum Flags { |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 202 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 203 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 204 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 205 | * the 3D API. |
| 206 | */ |
bsalomon | aca31fe | 2015-09-22 11:38:46 -0700 | [diff] [blame] | 207 | kHWAntialias_Flag = 0x01, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 208 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 209 | /** |
| 210 | * Modifies the vertex shader so that vertices will be positioned at pixel centers. |
| 211 | */ |
bsalomon | aca31fe | 2015-09-22 11:38:46 -0700 | [diff] [blame] | 212 | kSnapVerticesToPixelCenters_Flag = 0x02, |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 213 | |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 214 | /** |
| 215 | * Suppress linear -> sRGB conversion when rendering to sRGB render targets. |
| 216 | */ |
| 217 | kDisableOutputConversionToSRGB_Flag = 0x04, |
| 218 | |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 219 | /** |
| 220 | * Allow sRGB -> linear conversion when reading from sRGB inputs. |
| 221 | */ |
| 222 | kAllowSRGBInputs_Flag = 0x08, |
| 223 | |
dvonbeck | 9b03e7b | 2016-08-01 11:01:56 -0700 | [diff] [blame] | 224 | /** |
| 225 | * Signals that one or more FPs need access to the distance vector field to the nearest |
| 226 | * edge |
| 227 | */ |
| 228 | kUsesDistanceVectorField_Flag = 0x10, |
| 229 | |
| 230 | kLast_Flag = kUsesDistanceVectorField_Flag, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 233 | bool isHWAntialias() const { return SkToBool(fFlags & kHWAntialias_Flag); } |
| 234 | bool snapVerticesToPixelCenters() const { |
| 235 | return SkToBool(fFlags & kSnapVerticesToPixelCenters_Flag); } |
brianosman | 64d094d | 2016-03-25 06:01:59 -0700 | [diff] [blame] | 236 | bool getDisableOutputConversionToSRGB() const { |
| 237 | return SkToBool(fFlags & kDisableOutputConversionToSRGB_Flag); } |
brianosman | 898235c | 2016-04-06 07:38:23 -0700 | [diff] [blame] | 238 | bool getAllowSRGBInputs() const { |
| 239 | return SkToBool(fFlags & kAllowSRGBInputs_Flag); } |
dvonbeck | 9b03e7b | 2016-08-01 11:01:56 -0700 | [diff] [blame] | 240 | bool getUsesDistanceVectorField() const { |
| 241 | return SkToBool(fFlags & kUsesDistanceVectorField_Flag); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * Enable render state settings. |
| 245 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 246 | * @param flags bitfield of Flags specifying the states to enable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 247 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 248 | void enableState(uint32_t flags) { fFlags |= flags; } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 249 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 250 | /** |
| 251 | * Disable render state settings. |
| 252 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 253 | * @param flags bitfield of Flags specifying the states to disable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 254 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 255 | void disableState(uint32_t flags) { fFlags &= ~(flags); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 256 | |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 257 | /** |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 258 | * Enable or disable flags based on a boolean. |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 259 | * |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 260 | * @param flags bitfield of Flags to enable or disable |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 261 | * @param enable if true enable stateBits, otherwise disable |
| 262 | */ |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 263 | void setState(uint32_t flags, bool enable) { |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 264 | if (enable) { |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 265 | this->enableState(flags); |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 266 | } else { |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 267 | this->disableState(flags); |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 271 | /// @} |
| 272 | |
| 273 | /////////////////////////////////////////////////////////////////////////// |
| 274 | /// @name Face Culling |
| 275 | //// |
| 276 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 277 | /** |
| 278 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 279 | * or both faces. |
| 280 | * @return the current draw face(s). |
| 281 | */ |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 282 | GrDrawFace getDrawFace() const { return fDrawFace; } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 283 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 284 | /** |
| 285 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 286 | * @param face the face(s) to draw. |
| 287 | */ |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 288 | void setDrawFace(GrDrawFace face) { |
| 289 | SkASSERT(GrDrawFace::kInvalid != face); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 290 | fDrawFace = face; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 291 | } |
| 292 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 293 | /// @} |
| 294 | |
| 295 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 296 | |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 297 | bool usePLSDstRead(const GrDrawBatch* batch) const; |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 298 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 299 | private: |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 300 | // Some of the auto restore objects assume that no effects are removed during their lifetime. |
| 301 | // This is used to assert that this condition holds. |
joshualitt | 5e6ba21 | 2015-07-13 07:35:05 -0700 | [diff] [blame] | 302 | SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;) |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 303 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 304 | typedef SkSTArray<4, sk_sp<GrFragmentProcessor>> FragmentProcessorArray; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 305 | |
bsalomon | d79c549 | 2015-04-27 10:07:04 -0700 | [diff] [blame] | 306 | uint32_t fFlags; |
cdalton | 93a379b | 2016-05-11 13:58:08 -0700 | [diff] [blame] | 307 | const GrUserStencilSettings* fUserStencilSettings; |
robertphillips | 5fa7f30 | 2016-07-21 09:21:04 -0700 | [diff] [blame] | 308 | GrDrawFace fDrawFace; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 309 | mutable sk_sp<GrXPFactory> fXPFactory; |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 310 | FragmentProcessorArray fColorFragmentProcessors; |
| 311 | FragmentProcessorArray fCoverageFragmentProcessors; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 312 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 313 | friend class GrPipeline; |
ethannicholas | ff21032 | 2015-11-24 12:10:10 -0800 | [diff] [blame] | 314 | friend class GrDrawTarget; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 315 | }; |
| 316 | |
| 317 | #endif |