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