tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 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 | |
| 8 | #ifndef GrDrawState_DEFINED |
| 9 | #define GrDrawState_DEFINED |
| 10 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 11 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 12 | #include "GrBlend.h" |
egdaniel | c064824 | 2014-09-22 13:17:02 -0700 | [diff] [blame] | 13 | #include "GrDrawTargetCaps.h" |
bsalomon | 6251d17 | 2014-10-15 10:50:36 -0700 | [diff] [blame] | 14 | #include "GrGeometryProcessor.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 | 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 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 25 | class GrDrawTargetCaps; |
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 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 29 | class GrDrawState { |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 30 | public: |
egdaniel | 69bb90c | 2014-11-11 07:32:45 -0800 | [diff] [blame] | 31 | GrDrawState() { |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 32 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 33 | this->reset(); |
| 34 | } |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 35 | |
egdaniel | 69bb90c | 2014-11-11 07:32:45 -0800 | [diff] [blame] | 36 | GrDrawState(const SkMatrix& initialViewMatrix) { |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 37 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 38 | this->reset(initialViewMatrix); |
| 39 | } |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Copies another draw state. |
| 43 | **/ |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 44 | GrDrawState(const GrDrawState& state) { |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 45 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
bsalomon@google.com | 46f7afb | 2012-01-18 19:51:55 +0000 | [diff] [blame] | 46 | *this = state; |
| 47 | } |
| 48 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 49 | /** |
| 50 | * Copies another draw state with a preconcat to the view matrix. |
| 51 | **/ |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 52 | GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 53 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 54 | virtual ~GrDrawState(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 55 | |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 56 | /** |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 57 | * Resets to the default state. GrProcessors will be removed from all stages. |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 58 | */ |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 59 | void reset() { this->onReset(NULL); } |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 60 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 61 | void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMatrix); } |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 62 | |
| 63 | /** |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 64 | * Initializes the GrDrawState based on a GrPaint, view matrix and render target. Note that |
| 65 | * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that have no GrPaint |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 66 | * equivalents are set to default values with the exception of vertex attribute state which |
| 67 | * is unmodified by this function and clipping which will be enabled. |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 68 | */ |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 69 | void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarget*); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 70 | |
| 71 | /////////////////////////////////////////////////////////////////////////// |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 72 | /// @name Vertex Attributes |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 73 | //// |
| 74 | |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 75 | // TODO when we move this info off of GrGeometryProcessor, delete these |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 76 | bool hasLocalCoordAttribute() const { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 77 | return this->hasGeometryProcessor() && this->getGeometryProcessor()->hasLocalCoords(); |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 78 | } |
| 79 | bool hasColorVertexAttribute() const { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 80 | return this->hasGeometryProcessor() && this->getGeometryProcessor()->hasVertexColor(); |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 81 | } |
| 82 | bool hasCoverageVertexAttribute() const { |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 83 | return this->hasGeometryProcessor() && this->getGeometryProcessor()->hasVertexCoverage(); |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 84 | } |
| 85 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 86 | /// @} |
| 87 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 88 | /** |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 89 | * Depending on features available in the underlying 3D API and the color blend mode requested |
| 90 | * it may or may not be possible to correctly blend with fractional pixel coverage generated by |
| 91 | * the fragment shader. |
| 92 | * |
| 93 | * This function considers the current draw state and the draw target's capabilities to |
| 94 | * determine whether coverage can be handled correctly. This function assumes that the caller |
| 95 | * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex |
| 96 | * attribute, or a coverage effect) but may not have specified it yet. |
| 97 | */ |
| 98 | bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; |
| 99 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 100 | /** |
| 101 | * Determines whether the output coverage is guaranteed to be one for all pixels hit by a draw. |
| 102 | */ |
| 103 | bool hasSolidCoverage() const; |
| 104 | |
egdaniel | cd8b630 | 2014-11-11 14:46:05 -0800 | [diff] [blame] | 105 | /** |
| 106 | * This function returns true if the render target destination pixel values will be read for |
| 107 | * blending during draw. |
| 108 | */ |
| 109 | bool willBlendWithDst() const; |
| 110 | |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 111 | /// @} |
| 112 | |
| 113 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 114 | /// @name Color |
| 115 | //// |
| 116 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 117 | GrColor getColor() const { return fColor; } |
| 118 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 119 | /** |
| 120 | * Sets color for next draw to a premultiplied-alpha color. |
| 121 | * |
| 122 | * @param color the color to set. |
| 123 | */ |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 124 | void setColor(GrColor color) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 125 | if (color != fColor) { |
| 126 | fColor = color; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 127 | fColorProcInfoValid = false; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 128 | } |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 129 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 130 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 131 | /** |
| 132 | * Sets the color to be used for the next draw to be |
| 133 | * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
| 134 | * |
| 135 | * @param alpha The alpha value to set as the color. |
| 136 | */ |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 137 | void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 138 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 139 | /// @} |
| 140 | |
| 141 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 142 | /// @name Coverage |
| 143 | //// |
| 144 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 145 | uint8_t getCoverage() const { return fCoverage; } |
| 146 | |
| 147 | GrColor getCoverageColor() const { |
| 148 | return GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage); |
| 149 | } |
| 150 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 151 | /** |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 152 | * Sets a constant fractional coverage to be applied to the draw. The |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 153 | * initial value (after construction or reset()) is 0xff. The constant |
| 154 | * coverage is ignored when per-vertex coverage is provided. |
| 155 | */ |
| 156 | void setCoverage(uint8_t coverage) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 157 | if (coverage != fCoverage) { |
| 158 | fCoverage = coverage; |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 159 | fCoverageProcInfoValid = false; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 160 | } |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 161 | } |
| 162 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 163 | /// @} |
| 164 | |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 165 | /** |
| 166 | * The geometry processor is the sole element of the skia pipeline which can use the vertex, |
| 167 | * geometry, and tesselation shaders. The GP may also compute a coverage in its fragment shader |
| 168 | * but is never put in the color processing pipeline. |
| 169 | */ |
| 170 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 171 | const GrGeometryProcessor* setGeometryProcessor(const GrGeometryProcessor* geometryProcessor) { |
| 172 | SkASSERT(geometryProcessor); |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 173 | SkASSERT(!this->hasGeometryProcessor()); |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 174 | fGeometryProcessor.reset(SkRef(geometryProcessor)); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 175 | fCoverageProcInfoValid = false; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 176 | return geometryProcessor; |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 177 | } |
| 178 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 179 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 180 | /// @name Effect Stages |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 181 | /// Each stage hosts a GrProcessor. The effect produces an output color or coverage in the |
| 182 | /// 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] | 183 | /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color, |
| 184 | /// the fragment position, local coordinates). |
| 185 | /// |
| 186 | /// The stages are divided into two sets, color-computing and coverage-computing. The final |
| 187 | /// color stage produces the final pixel color. The coverage-computing stages function exactly |
| 188 | /// as the color-computing but the output of the final coverage stage is treated as a fractional |
| 189 | /// pixel coverage rather than as input to the src/dst color blend step. |
| 190 | /// |
| 191 | /// The input color to the first color-stage is either the constant color or interpolated |
| 192 | /// per-vertex colors. The input to the first coverage stage is either a constant coverage |
| 193 | /// (usually full-coverage) or interpolated per-vertex coverage. |
| 194 | /// |
| 195 | /// See the documentation of kCoverageDrawing_StateBit for information about disabling the |
| 196 | /// the color / coverage distinction. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 197 | //// |
| 198 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 199 | int numColorStages() const { return fColorStages.count(); } |
| 200 | int numCoverageStages() const { return fCoverageStages.count(); } |
joshualitt | 4dd9988 | 2014-11-11 08:51:30 -0800 | [diff] [blame] | 201 | int numFragmentStages() const { return this->numColorStages() + this->numCoverageStages(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 202 | int numTotalStages() const { |
joshualitt | 4dd9988 | 2014-11-11 08:51:30 -0800 | [diff] [blame] | 203 | return this->numFragmentStages() + (this->hasGeometryProcessor() ? 1 : 0); |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | bool hasGeometryProcessor() const { return SkToBool(fGeometryProcessor.get()); } |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 207 | const GrGeometryProcessor* getGeometryProcessor() const { return fGeometryProcessor.get(); } |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 208 | |
| 209 | const GrXPFactory* getXPFactory() const { return fXPFactory.get(); } |
| 210 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 211 | const GrFragmentStage& getColorStage(int idx) const { return fColorStages[idx]; } |
| 212 | const GrFragmentStage& getCoverageStage(int idx) const { return fCoverageStages[idx]; } |
| 213 | |
| 214 | /** |
| 215 | * Checks whether any of the effects will read the dst pixel color. |
| 216 | */ |
| 217 | bool willEffectReadDstColor() const; |
| 218 | |
egdaniel | 9513143 | 2014-12-09 11:15:43 -0800 | [diff] [blame] | 219 | /** |
| 220 | * The xfer processor factory. |
| 221 | */ |
| 222 | const GrXPFactory* setXPFactory(const GrXPFactory* xpFactory) { |
| 223 | fXPFactory.reset(SkRef(xpFactory)); |
| 224 | return xpFactory; |
| 225 | } |
| 226 | |
| 227 | void setPorterDuffXPFactory(SkXfermode::Mode mode) { |
| 228 | fXPFactory.reset(GrPorterDuffXPFactory::Create(mode)); |
| 229 | } |
| 230 | |
| 231 | void setPorterDuffXPFactory(GrBlendCoeff src, GrBlendCoeff dst) { |
| 232 | fXPFactory.reset(GrPorterDuffXPFactory::Create(src, dst)); |
| 233 | } |
| 234 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 235 | const GrFragmentProcessor* addColorProcessor(const GrFragmentProcessor* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 236 | SkASSERT(effect); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 237 | SkNEW_APPEND_TO_TARRAY(&fColorStages, GrFragmentStage, (effect)); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 238 | fColorProcInfoValid = false; |
jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 239 | return effect; |
| 240 | } |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 241 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 242 | const GrFragmentProcessor* addCoverageProcessor(const GrFragmentProcessor* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 243 | SkASSERT(effect); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 244 | SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrFragmentStage, (effect)); |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 245 | fCoverageProcInfoValid = false; |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 246 | return effect; |
| 247 | } |
| 248 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 249 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 250 | * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates. |
tomhudson@google.com | 1e8f016 | 2012-07-20 16:25:18 +0000 | [diff] [blame] | 251 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 252 | void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 253 | this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 254 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 255 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 256 | void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) { |
| 257 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 258 | } |
| 259 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 260 | void addColorTextureProcessor(GrTexture* texture, |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 261 | const SkMatrix& matrix, |
| 262 | const GrTextureParams& params) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 263 | this->addColorProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
| 264 | } |
| 265 | |
| 266 | void addCoverageTextureProcessor(GrTexture* texture, |
| 267 | const SkMatrix& matrix, |
| 268 | const GrTextureParams& params) { |
| 269 | this->addCoverageProcessor(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 270 | } |
tomhudson@google.com | 676e660 | 2012-07-10 17:21:48 +0000 | [diff] [blame] | 271 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 272 | /** |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 273 | * When this object is destroyed it will remove any color/coverage effects from the draw state |
| 274 | * that were added after its constructor. |
| 275 | * |
| 276 | * This class has strange behavior around geometry processor. If there is a GP on the draw state |
| 277 | * it will assert that the GP is not modified until after the destructor of the ARE. If the |
| 278 | * draw state has a NULL GP when the ARE is constructed then it will reset it to null in the |
| 279 | * destructor. |
| 280 | * |
| 281 | * TODO: We'd prefer for the ARE to just save and restore the GP. However, this would add |
| 282 | * significant complexity to the multi-ref architecture for deferred drawing. Once GrDrawState |
| 283 | * and GrOptDrawState are fully separated then GrDrawState will never be in the deferred |
| 284 | * execution state and GrOptDrawState always will be (and will be immutable and therefore |
| 285 | * unable to have an ARE). At this point we can restore sanity and have the ARE save and restore |
| 286 | * the GP. |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 287 | */ |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 288 | class AutoRestoreEffects : public ::SkNoncopyable { |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 289 | public: |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 290 | AutoRestoreEffects() |
| 291 | : fDrawState(NULL) |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 292 | , fOriginalGPID(SK_InvalidUniqueID) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 293 | , fColorEffectCnt(0) |
| 294 | , fCoverageEffectCnt(0) {} |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 295 | |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 296 | AutoRestoreEffects(GrDrawState* ds) |
| 297 | : fDrawState(NULL) |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 298 | , fOriginalGPID(SK_InvalidUniqueID) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 299 | , fColorEffectCnt(0) |
| 300 | , fCoverageEffectCnt(0) { |
skia.committer@gmail.com | 5c493d5 | 2013-06-14 07:00:49 +0000 | [diff] [blame] | 301 | this->set(ds); |
robertphillips@google.com | f09b87d | 2013-06-13 20:06:44 +0000 | [diff] [blame] | 302 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 303 | |
| 304 | ~AutoRestoreEffects() { this->set(NULL); } |
| 305 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 306 | void set(GrDrawState* ds); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 307 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 308 | bool isSet() const { return SkToBool(fDrawState); } |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 309 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 310 | private: |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 311 | GrDrawState* fDrawState; |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 312 | uint32_t fOriginalGPID; |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 313 | int fColorEffectCnt; |
| 314 | int fCoverageEffectCnt; |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 315 | }; |
| 316 | |
joshualitt | a58fe35 | 2014-10-27 08:39:00 -0700 | [diff] [blame] | 317 | /** |
| 318 | * AutoRestoreStencil |
| 319 | * |
| 320 | * This simple struct saves and restores the stencil settings |
| 321 | */ |
| 322 | class AutoRestoreStencil : public ::SkNoncopyable { |
| 323 | public: |
| 324 | AutoRestoreStencil() : fDrawState(NULL) {} |
| 325 | |
| 326 | AutoRestoreStencil(GrDrawState* ds) : fDrawState(NULL) { this->set(ds); } |
| 327 | |
| 328 | ~AutoRestoreStencil() { this->set(NULL); } |
| 329 | |
| 330 | void set(GrDrawState* ds) { |
| 331 | if (fDrawState) { |
| 332 | fDrawState->setStencil(fStencilSettings); |
| 333 | } |
| 334 | fDrawState = ds; |
| 335 | if (ds) { |
| 336 | fStencilSettings = ds->getStencil(); |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | bool isSet() const { return SkToBool(fDrawState); } |
| 341 | |
| 342 | private: |
| 343 | GrDrawState* fDrawState; |
| 344 | GrStencilSettings fStencilSettings; |
| 345 | }; |
| 346 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 347 | /// @} |
| 348 | |
| 349 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 350 | /// @name Blending |
| 351 | //// |
| 352 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 353 | /** |
| 354 | * Determines whether multiplying the computed per-pixel color by the pixel's fractional |
| 355 | * coverage before the blend will give the correct final destination color. In general it |
| 356 | * will not as coverage is applied after blending. |
| 357 | */ |
| 358 | bool canTweakAlphaForCoverage() const; |
| 359 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 360 | /// @} |
| 361 | |
| 362 | /////////////////////////////////////////////////////////////////////////// |
| 363 | /// @name View Matrix |
| 364 | //// |
| 365 | |
| 366 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 367 | * Retrieves the current view matrix |
| 368 | * @return the current view matrix. |
| 369 | */ |
| 370 | const SkMatrix& getViewMatrix() const { return fViewMatrix; } |
| 371 | |
| 372 | /** |
| 373 | * Retrieves the inverse of the current view matrix. |
| 374 | * |
| 375 | * If the current view matrix is invertible, return true, and if matrix |
| 376 | * is non-null, copy the inverse into it. If the current view matrix is |
| 377 | * non-invertible, return false and ignore the matrix parameter. |
| 378 | * |
| 379 | * @param matrix if not null, will receive a copy of the current inverse. |
| 380 | */ |
| 381 | bool getViewInverse(SkMatrix* matrix) const { |
| 382 | SkMatrix inverse; |
| 383 | if (fViewMatrix.invert(&inverse)) { |
| 384 | if (matrix) { |
| 385 | *matrix = inverse; |
| 386 | } |
| 387 | return true; |
| 388 | } |
| 389 | return false; |
| 390 | } |
| 391 | |
| 392 | /** |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 393 | * Sets the view matrix to identity and updates any installed effects to compensate for the |
| 394 | * coord system change. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 395 | */ |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 396 | bool setIdentityViewMatrix(); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 397 | |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 398 | //////////////////////////////////////////////////////////////////////////// |
| 399 | |
| 400 | /** |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 401 | * Preconcats the current view matrix and restores the previous view matrix in the destructor. |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 402 | * Effect matrices are automatically adjusted to compensate and adjusted back in the destructor. |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 403 | */ |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 404 | class AutoViewMatrixRestore : public ::SkNoncopyable { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 405 | public: |
| 406 | AutoViewMatrixRestore() : fDrawState(NULL) {} |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 407 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 408 | AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 409 | fDrawState = NULL; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 410 | this->set(ds, preconcatMatrix); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 411 | } |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 412 | |
| 413 | ~AutoViewMatrixRestore() { this->restore(); } |
| 414 | |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 415 | /** |
| 416 | * Can be called prior to destructor to restore the original matrix. |
| 417 | */ |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 418 | void restore(); |
skia.committer@gmail.com | f467ce7 | 2012-10-09 02:01:37 +0000 | [diff] [blame] | 419 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 420 | void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix); |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 421 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 422 | /** Sets the draw state's matrix to identity. This can fail because the current view matrix |
| 423 | is not invertible. */ |
| 424 | bool setIdentity(GrDrawState* drawState); |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 425 | |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 426 | private: |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 427 | void doEffectCoordChanges(const SkMatrix& coordChangeMatrix); |
| 428 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 429 | GrDrawState* fDrawState; |
| 430 | SkMatrix fViewMatrix; |
| 431 | int fNumColorStages; |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 432 | SkAutoSTArray<8, GrFragmentStage::SavedCoordChange> fSavedCoordChanges; |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 433 | }; |
| 434 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 435 | /// @} |
| 436 | |
| 437 | /////////////////////////////////////////////////////////////////////////// |
| 438 | /// @name Render Target |
| 439 | //// |
| 440 | |
| 441 | /** |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 442 | * Retrieves the currently set render-target. |
| 443 | * |
| 444 | * @return The currently set render target. |
| 445 | */ |
bsalomon | 37dd331 | 2014-11-03 08:47:23 -0800 | [diff] [blame] | 446 | GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 447 | |
| 448 | /** |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 449 | * Sets the render-target used at the next drawing call |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 450 | * |
| 451 | * @param target The render target to set. |
| 452 | */ |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 453 | void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 454 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 455 | /// @} |
| 456 | |
| 457 | /////////////////////////////////////////////////////////////////////////// |
| 458 | /// @name Stencil |
| 459 | //// |
| 460 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 461 | const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 462 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 463 | /** |
| 464 | * Sets the stencil settings to use for the next draw. |
| 465 | * Changing the clip has the side-effect of possibly zeroing |
| 466 | * out the client settable stencil bits. So multipass algorithms |
| 467 | * using stencil should not change the clip between passes. |
| 468 | * @param settings the stencil settings to use. |
| 469 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 470 | void setStencil(const GrStencilSettings& settings) { fStencilSettings = settings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 471 | |
| 472 | /** |
| 473 | * Shortcut to disable stencil testing and ops. |
| 474 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 475 | void disableStencil() { fStencilSettings.setDisabled(); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 476 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 477 | GrStencilSettings* stencil() { return &fStencilSettings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 478 | |
| 479 | /// @} |
| 480 | |
| 481 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 482 | /// @name State Flags |
| 483 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 484 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 485 | /** |
| 486 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 487 | * default to disabled. |
| 488 | */ |
| 489 | enum StateBits { |
| 490 | /** |
| 491 | * Perform dithering. TODO: Re-evaluate whether we need this bit |
| 492 | */ |
| 493 | kDither_StateBit = 0x01, |
| 494 | /** |
| 495 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 496 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 497 | * the 3D API. |
| 498 | */ |
| 499 | kHWAntialias_StateBit = 0x02, |
| 500 | /** |
| 501 | * Draws will respect the clip, otherwise the clip is ignored. |
| 502 | */ |
| 503 | kClip_StateBit = 0x04, |
| 504 | /** |
| 505 | * Disables writing to the color buffer. Useful when performing stencil |
| 506 | * operations. |
| 507 | */ |
| 508 | kNoColorWrites_StateBit = 0x08, |
| 509 | |
| 510 | /** |
| 511 | * Usually coverage is applied after color blending. The color is blended using the coeffs |
| 512 | * specified by setBlendFunc(). The blended color is then combined with dst using coeffs |
| 513 | * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing a coverage mask. In |
| 514 | * this case there is no distinction between coverage and color and the caller needs direct |
| 515 | * control over the blend coeffs. When set, there will be a single blend step controlled by |
| 516 | * setBlendFunc() which will use coverage*color as the src color. |
| 517 | */ |
| 518 | kCoverageDrawing_StateBit = 0x10, |
joshualitt | 7a6184f | 2014-10-29 18:29:27 -0700 | [diff] [blame] | 519 | kLast_StateBit = kCoverageDrawing_StateBit, |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 520 | }; |
| 521 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 522 | bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } |
| 523 | bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_StateBit); } |
| 524 | bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_StateBit); } |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 525 | bool isDither() const { return 0 != (fFlagBits & kDither_StateBit); } |
| 526 | bool isHWAntialias() const { return 0 != (fFlagBits & kHWAntialias_StateBit); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 527 | |
| 528 | /** |
| 529 | * Enable render state settings. |
| 530 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 531 | * @param stateBits bitfield of StateBits specifying the states to enable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 532 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 533 | void enableState(uint32_t stateBits) { fFlagBits |= stateBits; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 534 | |
| 535 | /** |
| 536 | * Disable render state settings. |
| 537 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 538 | * @param stateBits bitfield of StateBits specifying the states to disable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 539 | */ |
bsalomon | 04ddf89 | 2014-11-19 12:36:22 -0800 | [diff] [blame] | 540 | void disableState(uint32_t stateBits) { fFlagBits &= ~(stateBits); } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 541 | |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 542 | /** |
| 543 | * Enable or disable stateBits based on a boolean. |
| 544 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 545 | * @param stateBits bitfield of StateBits to enable or disable |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 546 | * @param enable if true enable stateBits, otherwise disable |
| 547 | */ |
| 548 | void setState(uint32_t stateBits, bool enable) { |
| 549 | if (enable) { |
| 550 | this->enableState(stateBits); |
| 551 | } else { |
| 552 | this->disableState(stateBits); |
| 553 | } |
| 554 | } |
| 555 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 556 | /// @} |
| 557 | |
| 558 | /////////////////////////////////////////////////////////////////////////// |
| 559 | /// @name Face Culling |
| 560 | //// |
| 561 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 562 | enum DrawFace { |
| 563 | kInvalid_DrawFace = -1, |
| 564 | |
| 565 | kBoth_DrawFace, |
| 566 | kCCW_DrawFace, |
| 567 | kCW_DrawFace, |
| 568 | }; |
| 569 | |
| 570 | /** |
| 571 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 572 | * or both faces. |
| 573 | * @return the current draw face(s). |
| 574 | */ |
| 575 | DrawFace getDrawFace() const { return fDrawFace; } |
| 576 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 577 | /** |
| 578 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 579 | * @param face the face(s) to draw. |
| 580 | */ |
| 581 | void setDrawFace(DrawFace face) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 582 | SkASSERT(kInvalid_DrawFace != face); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 583 | fDrawFace = face; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 584 | } |
| 585 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 586 | /// @} |
| 587 | |
| 588 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 589 | /// @name Hints |
| 590 | /// Hints that when provided can enable optimizations. |
| 591 | //// |
| 592 | |
joshualitt | 6517134 | 2014-10-09 07:25:36 -0700 | [diff] [blame] | 593 | enum Hints { |
| 594 | kVertexColorsAreOpaque_Hint = 0x1, |
| 595 | kLast_Hint = kVertexColorsAreOpaque_Hint |
| 596 | }; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 597 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 598 | void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (fHints & ~hint); } |
| 599 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 600 | bool vertexColorsAreOpaque() const { return kVertexColorsAreOpaque_Hint & fHints; } |
| 601 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 602 | /// @} |
| 603 | |
| 604 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 605 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 606 | GrDrawState& operator= (const GrDrawState& that); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 607 | |
| 608 | private: |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 609 | bool isEqual(const GrDrawState& that) const; |
| 610 | |
egdaniel | 912b3d2 | 2014-11-17 07:45:53 -0800 | [diff] [blame] | 611 | const GrProcOptInfo& colorProcInfo() const { |
| 612 | this->calcColorInvariantOutput(); |
| 613 | return fColorProcInfo; |
| 614 | } |
| 615 | |
| 616 | const GrProcOptInfo& coverageProcInfo() const { |
| 617 | this->calcCoverageInvariantOutput(); |
| 618 | return fCoverageProcInfo; |
| 619 | } |
| 620 | |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 621 | /** |
| 622 | * Determines whether src alpha is guaranteed to be one for all src pixels |
| 623 | */ |
| 624 | bool srcAlphaWillBeOne() const; |
| 625 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 626 | /** |
| 627 | * If fColorProcInfoValid is false, function calculates the invariant output for the color |
| 628 | * stages and results are stored in fColorProcInfo. |
| 629 | */ |
| 630 | void calcColorInvariantOutput() const; |
| 631 | |
| 632 | /** |
| 633 | * If fCoverageProcInfoValid is false, function calculates the invariant output for the coverage |
| 634 | * stages and results are stored in fCoverageProcInfo. |
| 635 | */ |
| 636 | void calcCoverageInvariantOutput() const; |
| 637 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 638 | void onReset(const SkMatrix* initialViewMatrix); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 639 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 640 | // Some of the auto restore objects assume that no effects are removed during their lifetime. |
| 641 | // This is used to assert that this condition holds. |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 642 | SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 643 | |
joshualitt | a5305a1 | 2014-10-10 17:47:00 -0700 | [diff] [blame] | 644 | typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 645 | |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 646 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 647 | GrColor fColor; |
| 648 | SkMatrix fViewMatrix; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 649 | uint32_t fFlagBits; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 650 | GrStencilSettings fStencilSettings; |
| 651 | uint8_t fCoverage; |
| 652 | DrawFace fDrawFace; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 653 | SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor; |
egdaniel | 378092f | 2014-12-03 10:40:13 -0800 | [diff] [blame] | 654 | SkAutoTUnref<const GrXPFactory> fXPFactory; |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 655 | FragmentStageArray fColorStages; |
| 656 | FragmentStageArray fCoverageStages; |
| 657 | uint32_t fHints; |
egdaniel | 89af44a | 2014-09-26 06:15:04 -0700 | [diff] [blame] | 658 | |
egdaniel | b6cbc38 | 2014-11-13 11:00:34 -0800 | [diff] [blame] | 659 | mutable GrProcOptInfo fColorProcInfo; |
| 660 | mutable GrProcOptInfo fCoverageProcInfo; |
| 661 | mutable bool fColorProcInfoValid; |
| 662 | mutable bool fCoverageProcInfoValid; |
| 663 | |
egdaniel | b109ac2 | 2014-10-07 06:45:44 -0700 | [diff] [blame] | 664 | friend class GrOptDrawState; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | #endif |