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