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 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 11 | #include "GrBlend.h" |
bsalomon | f96ba02 | 2014-09-17 08:05:40 -0700 | [diff] [blame] | 12 | #include "GrGpuResourceRef.h" |
bsalomon | 2a9ca78 | 2014-09-05 14:27:43 -0700 | [diff] [blame] | 13 | #include "GrRODrawState.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 14 | #include "effects/GrSimpleTextureEffect.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 15 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 16 | class GrOptDrawState; |
| 17 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 18 | /** |
| 19 | * Modifiable subclass derived from GrRODrawState. The majority of the data that represents a draw |
| 20 | * state is stored in the parent class. GrDrawState contains methods for setting, adding to, etc. |
| 21 | * various data members of the draw state. This class is used to configure the state used when |
| 22 | * issuing draws via GrDrawTarget. |
| 23 | */ |
| 24 | class GrDrawState : public GrRODrawState { |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 25 | public: |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 26 | SK_DECLARE_INST_COUNT(GrDrawState) |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 27 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 28 | GrDrawState() : fCachedOptState(NULL) { |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 29 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 30 | this->reset(); |
| 31 | } |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 32 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 33 | GrDrawState(const SkMatrix& initialViewMatrix) : fCachedOptState(NULL) { |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 34 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 35 | this->reset(initialViewMatrix); |
| 36 | } |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Copies another draw state. |
| 40 | **/ |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 41 | GrDrawState(const GrDrawState& state) : INHERITED(), fCachedOptState(NULL) { |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 42 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
bsalomon@google.com | 46f7afb | 2012-01-18 19:51:55 +0000 | [diff] [blame] | 43 | *this = state; |
| 44 | } |
| 45 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 46 | /** |
| 47 | * Copies another draw state with a preconcat to the view matrix. |
| 48 | **/ |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 49 | GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 50 | |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 51 | virtual ~GrDrawState(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 52 | |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 53 | /** |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 54 | * Resets to the default state. GrEffects will be removed from all stages. |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 55 | */ |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 56 | void reset() { this->onReset(NULL); } |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 57 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 58 | void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMatrix); } |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 59 | |
| 60 | /** |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 61 | * Initializes the GrDrawState based on a GrPaint, view matrix and render target. Note that |
| 62 | * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that have no GrPaint |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 63 | * equivalents are set to default values with the exception of vertex attribute state which |
| 64 | * is unmodified by this function and clipping which will be enabled. |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 65 | */ |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 66 | void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarget*); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 67 | |
| 68 | /////////////////////////////////////////////////////////////////////////// |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 69 | /// @name Vertex Attributes |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 70 | //// |
| 71 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 72 | /** |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 73 | * The format of vertices is represented as an array of GrVertexAttribs, with each representing |
| 74 | * the type of the attribute, its offset, and semantic binding (see GrVertexAttrib in |
| 75 | * GrTypesPriv.h). |
jvanverth@google.com | b8b705b | 2013-02-28 16:28:34 +0000 | [diff] [blame] | 76 | * |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 77 | * The mapping of attributes with kEffect bindings to GrEffect inputs is specified when |
| 78 | * setEffect is called. |
jvanverth@google.com | b8b705b | 2013-02-28 16:28:34 +0000 | [diff] [blame] | 79 | */ |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 80 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 81 | /** |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 82 | * Sets vertex attributes for next draw. The object driving the templatization |
| 83 | * should be a global GrVertexAttrib array that is never changed. |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 84 | * |
| 85 | * @param count the number of attributes being set, limited to kMaxVertexAttribCnt. |
| 86 | * @param stride the number of bytes between successive vertex data. |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 87 | */ |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 88 | template <const GrVertexAttrib A[]> void setVertexAttribs(int count, size_t stride) { |
| 89 | this->internalSetVertexAttribs(A, count, stride); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 90 | } |
jvanverth@google.com | b8b705b | 2013-02-28 16:28:34 +0000 | [diff] [blame] | 91 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 92 | /** |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 93 | * Sets default vertex attributes for next draw. The default is a single attribute: |
| 94 | * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 95 | */ |
| 96 | void setDefaultVertexAttribs(); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 97 | |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 98 | /** |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 99 | * Helper to save/restore vertex attribs |
| 100 | */ |
| 101 | class AutoVertexAttribRestore { |
| 102 | public: |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 103 | AutoVertexAttribRestore(GrDrawState* drawState); |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 104 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 105 | ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPtr, fVACount, |
| 106 | fVAStride); } |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 107 | |
| 108 | private: |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 109 | GrDrawState* fDrawState; |
| 110 | const GrVertexAttrib* fVAPtr; |
| 111 | int fVACount; |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 112 | size_t fVAStride; |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 115 | /// @} |
| 116 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 117 | /** |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 118 | * Depending on features available in the underlying 3D API and the color blend mode requested |
| 119 | * it may or may not be possible to correctly blend with fractional pixel coverage generated by |
| 120 | * the fragment shader. |
| 121 | * |
| 122 | * This function considers the current draw state and the draw target's capabilities to |
| 123 | * determine whether coverage can be handled correctly. This function assumes that the caller |
| 124 | * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex |
| 125 | * attribute, or a coverage effect) but may not have specified it yet. |
| 126 | */ |
| 127 | bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; |
| 128 | |
jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 129 | /// @} |
| 130 | |
| 131 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 132 | /// @name Color |
| 133 | //// |
| 134 | |
| 135 | /** |
| 136 | * Sets color for next draw to a premultiplied-alpha color. |
| 137 | * |
| 138 | * @param color the color to set. |
| 139 | */ |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 140 | void setColor(GrColor color) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 141 | if (color != fColor) { |
| 142 | fColor = color; |
| 143 | this->invalidateOptState(); |
| 144 | } |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 145 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 146 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 147 | /** |
| 148 | * Sets the color to be used for the next draw to be |
| 149 | * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
| 150 | * |
| 151 | * @param alpha The alpha value to set as the color. |
| 152 | */ |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 153 | 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] | 154 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 155 | /// @} |
| 156 | |
| 157 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 158 | /// @name Coverage |
| 159 | //// |
| 160 | |
| 161 | /** |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 162 | * 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] | 163 | * initial value (after construction or reset()) is 0xff. The constant |
| 164 | * coverage is ignored when per-vertex coverage is provided. |
| 165 | */ |
| 166 | void setCoverage(uint8_t coverage) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 167 | if (coverage != fCoverage) { |
| 168 | fCoverage = coverage; |
| 169 | this->invalidateOptState(); |
| 170 | } |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 171 | } |
| 172 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 173 | /// @} |
| 174 | |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 175 | /** |
| 176 | * The geometry processor is the sole element of the skia pipeline which can use the vertex, |
| 177 | * geometry, and tesselation shaders. The GP may also compute a coverage in its fragment shader |
| 178 | * but is never put in the color processing pipeline. |
| 179 | */ |
| 180 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 181 | const GrEffect* setGeometryProcessor(const GrEffect* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 182 | SkASSERT(effect); |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 183 | SkASSERT(effect->requiresVertexShader()); |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 184 | SkASSERT(!this->hasGeometryProcessor()); |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 185 | fGeometryProcessor.reset(new GrEffectStage(effect)); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 186 | this->invalidateOptState(); |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 187 | return effect; |
| 188 | } |
| 189 | |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 190 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 191 | /// @name Effect Stages |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 192 | /// Each stage hosts a GrEffect. The effect produces an output color or coverage in the fragment |
| 193 | /// shader. Its inputs are the output from the previous stage as well as some variables |
| 194 | /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color, |
| 195 | /// the fragment position, local coordinates). |
| 196 | /// |
| 197 | /// The stages are divided into two sets, color-computing and coverage-computing. The final |
| 198 | /// color stage produces the final pixel color. The coverage-computing stages function exactly |
| 199 | /// as the color-computing but the output of the final coverage stage is treated as a fractional |
| 200 | /// pixel coverage rather than as input to the src/dst color blend step. |
| 201 | /// |
| 202 | /// The input color to the first color-stage is either the constant color or interpolated |
| 203 | /// per-vertex colors. The input to the first coverage stage is either a constant coverage |
| 204 | /// (usually full-coverage) or interpolated per-vertex coverage. |
| 205 | /// |
| 206 | /// See the documentation of kCoverageDrawing_StateBit for information about disabling the |
| 207 | /// the color / coverage distinction. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 208 | //// |
| 209 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 210 | const GrEffect* addColorEffect(const GrEffect* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 211 | SkASSERT(effect); |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 212 | SkASSERT(!effect->requiresVertexShader()); |
| 213 | SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect)); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 214 | this->invalidateOptState(); |
jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 215 | return effect; |
| 216 | } |
skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 217 | |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 218 | const GrEffect* addCoverageEffect(const GrEffect* effect) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 219 | SkASSERT(effect); |
joshualitt | 249af15 | 2014-09-15 11:41:13 -0700 | [diff] [blame] | 220 | SkASSERT(!effect->requiresVertexShader()); |
| 221 | SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect)); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 222 | this->invalidateOptState(); |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 223 | return effect; |
| 224 | } |
| 225 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 226 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 227 | * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates. |
tomhudson@google.com | 1e8f016 | 2012-07-20 16:25:18 +0000 | [diff] [blame] | 228 | */ |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 229 | void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { |
bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 230 | this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 231 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 232 | |
| 233 | void addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix) { |
bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 234 | this->addCoverageEffect(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void addColorTextureEffect(GrTexture* texture, |
| 238 | const SkMatrix& matrix, |
| 239 | const GrTextureParams& params) { |
bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 240 | this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 241 | } |
| 242 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 243 | void addCoverageTextureEffect(GrTexture* texture, |
| 244 | const SkMatrix& matrix, |
| 245 | const GrTextureParams& params) { |
bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 246 | this->addCoverageEffect(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 247 | } |
tomhudson@google.com | 676e660 | 2012-07-10 17:21:48 +0000 | [diff] [blame] | 248 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 249 | /** |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 250 | * When this object is destroyed it will remove any color/coverage effects from the draw state |
| 251 | * that were added after its constructor. |
| 252 | * |
| 253 | * This class has strange behavior around geometry processor. If there is a GP on the draw state |
| 254 | * it will assert that the GP is not modified until after the destructor of the ARE. If the |
| 255 | * draw state has a NULL GP when the ARE is constructed then it will reset it to null in the |
| 256 | * destructor. |
| 257 | * |
| 258 | * TODO: We'd prefer for the ARE to just save and restore the GP. However, this would add |
| 259 | * significant complexity to the multi-ref architecture for deferred drawing. Once GrDrawState |
| 260 | * and GrOptDrawState are fully separated then GrDrawState will never be in the deferred |
| 261 | * execution state and GrOptDrawState always will be (and will be immutable and therefore |
| 262 | * unable to have an ARE). At this point we can restore sanity and have the ARE save and restore |
| 263 | * the GP. |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 264 | */ |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 265 | class AutoRestoreEffects : public ::SkNoncopyable { |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 266 | public: |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 267 | AutoRestoreEffects() |
| 268 | : fDrawState(NULL) |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 269 | , fOriginalGPID(SK_InvalidUniqueID) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 270 | , fColorEffectCnt(0) |
| 271 | , fCoverageEffectCnt(0) {} |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 272 | |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 273 | AutoRestoreEffects(GrDrawState* ds) |
| 274 | : fDrawState(NULL) |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 275 | , fOriginalGPID(SK_InvalidUniqueID) |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 276 | , fColorEffectCnt(0) |
| 277 | , fCoverageEffectCnt(0) { |
skia.committer@gmail.com | 5c493d5 | 2013-06-14 07:00:49 +0000 | [diff] [blame] | 278 | this->set(ds); |
robertphillips@google.com | f09b87d | 2013-06-13 20:06:44 +0000 | [diff] [blame] | 279 | } |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 280 | |
| 281 | ~AutoRestoreEffects() { this->set(NULL); } |
| 282 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 283 | void set(GrDrawState* ds); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 284 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 285 | bool isSet() const { return SkToBool(fDrawState); } |
bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 286 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 287 | private: |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 288 | GrDrawState* fDrawState; |
bsalomon | 52e9d63 | 2014-09-05 12:23:12 -0700 | [diff] [blame] | 289 | uint32_t fOriginalGPID; |
bsalomon | 9b53652 | 2014-09-05 09:18:51 -0700 | [diff] [blame] | 290 | int fColorEffectCnt; |
| 291 | int fCoverageEffectCnt; |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 292 | }; |
| 293 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 294 | /// @} |
| 295 | |
| 296 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 297 | /// @name Blending |
| 298 | //// |
| 299 | |
| 300 | /** |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 301 | * Sets the blending function coefficients. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 302 | * |
| 303 | * The blend function will be: |
| 304 | * D' = sat(S*srcCoef + D*dstCoef) |
| 305 | * |
| 306 | * where D is the existing destination color, S is the incoming source |
| 307 | * color, and D' is the new destination color that will be written. sat() |
| 308 | * is the saturation function. |
| 309 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 310 | * @param srcCoef coefficient applied to the src color. |
| 311 | * @param dstCoef coefficient applied to the dst color. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 312 | */ |
| 313 | void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 314 | if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) { |
| 315 | fSrcBlend = srcCoeff; |
| 316 | fDstBlend = dstCoeff; |
| 317 | this->invalidateOptState(); |
| 318 | } |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 319 | #ifdef SK_DEBUG |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 320 | if (GrBlendCoeffRefsDst(dstCoeff)) { |
| 321 | GrPrintf("Unexpected dst blend coeff. Won't work correctly with coverage stages.\n"); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 322 | } |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 323 | if (GrBlendCoeffRefsSrc(srcCoeff)) { |
| 324 | GrPrintf("Unexpected src blend coeff. Won't work correctly with coverage stages.\n"); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 325 | } |
| 326 | #endif |
| 327 | } |
| 328 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 329 | /** |
| 330 | * Sets the blending function constant referenced by the following blending |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 331 | * coefficients: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 332 | * kConstC_GrBlendCoeff |
| 333 | * kIConstC_GrBlendCoeff |
| 334 | * kConstA_GrBlendCoeff |
| 335 | * kIConstA_GrBlendCoeff |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 336 | * |
| 337 | * @param constant the constant to set |
| 338 | */ |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 339 | void setBlendConstant(GrColor constant) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 340 | if (constant != fBlendConstant) { |
| 341 | fBlendConstant = constant; |
| 342 | this->invalidateOptState(); |
| 343 | } |
egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 344 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 345 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 346 | /// @} |
| 347 | |
| 348 | /////////////////////////////////////////////////////////////////////////// |
| 349 | /// @name View Matrix |
| 350 | //// |
| 351 | |
| 352 | /** |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 353 | * Sets the view matrix to identity and updates any installed effects to compensate for the |
| 354 | * coord system change. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 355 | */ |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 356 | bool setIdentityViewMatrix(); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 357 | |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 358 | //////////////////////////////////////////////////////////////////////////// |
| 359 | |
| 360 | /** |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 361 | * 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] | 362 | * 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] | 363 | */ |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 364 | class AutoViewMatrixRestore : public ::SkNoncopyable { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 365 | public: |
| 366 | AutoViewMatrixRestore() : fDrawState(NULL) {} |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 367 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 368 | AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 369 | fDrawState = NULL; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 370 | this->set(ds, preconcatMatrix); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 371 | } |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 372 | |
| 373 | ~AutoViewMatrixRestore() { this->restore(); } |
| 374 | |
bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 375 | /** |
| 376 | * Can be called prior to destructor to restore the original matrix. |
| 377 | */ |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 378 | void restore(); |
skia.committer@gmail.com | f467ce7 | 2012-10-09 02:01:37 +0000 | [diff] [blame] | 379 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 380 | void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix); |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 381 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 382 | /** Sets the draw state's matrix to identity. This can fail because the current view matrix |
| 383 | is not invertible. */ |
| 384 | bool setIdentity(GrDrawState* drawState); |
bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 385 | |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 386 | private: |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 387 | void doEffectCoordChanges(const SkMatrix& coordChangeMatrix); |
| 388 | |
| 389 | GrDrawState* fDrawState; |
| 390 | SkMatrix fViewMatrix; |
| 391 | int fNumColorStages; |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 392 | bool fHasGeometryProcessor; |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 393 | SkAutoSTArray<8, GrEffectStage::SavedCoordChange> fSavedCoordChanges; |
bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 394 | }; |
| 395 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 396 | /// @} |
| 397 | |
| 398 | /////////////////////////////////////////////////////////////////////////// |
| 399 | /// @name Render Target |
| 400 | //// |
| 401 | |
| 402 | /** |
bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 403 | * Sets the render-target used at the next drawing call |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 404 | * |
| 405 | * @param target The render target to set. |
| 406 | */ |
bsalomon | 2a9ca78 | 2014-09-05 14:27:43 -0700 | [diff] [blame] | 407 | void setRenderTarget(GrRenderTarget* target) { |
bsalomon | 45725db | 2014-09-19 11:48:02 -0700 | [diff] [blame^] | 408 | fRenderTarget.set(SkSafeRef(target), GrIORef::kWrite_IOType); |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 409 | this->invalidateOptState(); |
bsalomon | 2a9ca78 | 2014-09-05 14:27:43 -0700 | [diff] [blame] | 410 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 411 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 412 | /// @} |
| 413 | |
| 414 | /////////////////////////////////////////////////////////////////////////// |
| 415 | /// @name Stencil |
| 416 | //// |
| 417 | |
| 418 | /** |
| 419 | * Sets the stencil settings to use for the next draw. |
| 420 | * Changing the clip has the side-effect of possibly zeroing |
| 421 | * out the client settable stencil bits. So multipass algorithms |
| 422 | * using stencil should not change the clip between passes. |
| 423 | * @param settings the stencil settings to use. |
| 424 | */ |
| 425 | void setStencil(const GrStencilSettings& settings) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 426 | if (settings != fStencilSettings) { |
| 427 | fStencilSettings = settings; |
| 428 | this->invalidateOptState(); |
| 429 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Shortcut to disable stencil testing and ops. |
| 434 | */ |
| 435 | void disableStencil() { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 436 | if (!fStencilSettings.isDisabled()) { |
| 437 | fStencilSettings.setDisabled(); |
| 438 | this->invalidateOptState(); |
| 439 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 440 | } |
| 441 | |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 442 | GrStencilSettings* stencil() { return &fStencilSettings; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 443 | |
| 444 | /// @} |
| 445 | |
| 446 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 447 | /// @name State Flags |
| 448 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 449 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 450 | void resetStateFlags() { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 451 | if (0 != fFlagBits) { |
| 452 | fFlagBits = 0; |
| 453 | this->invalidateOptState(); |
| 454 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | /** |
| 458 | * Enable render state settings. |
| 459 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 460 | * @param stateBits bitfield of StateBits specifying the states to enable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 461 | */ |
| 462 | void enableState(uint32_t stateBits) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 463 | if (stateBits & ~fFlagBits) { |
| 464 | fFlagBits |= stateBits; |
| 465 | this->invalidateOptState(); |
| 466 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Disable render state settings. |
| 471 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 472 | * @param stateBits bitfield of StateBits specifying the states to disable |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 473 | */ |
| 474 | void disableState(uint32_t stateBits) { |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 475 | if (stateBits & fFlagBits) { |
| 476 | fFlagBits &= ~(stateBits); |
| 477 | this->invalidateOptState(); |
| 478 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 479 | } |
| 480 | |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 481 | /** |
| 482 | * Enable or disable stateBits based on a boolean. |
| 483 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 484 | * @param stateBits bitfield of StateBits to enable or disable |
bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 485 | * @param enable if true enable stateBits, otherwise disable |
| 486 | */ |
| 487 | void setState(uint32_t stateBits, bool enable) { |
| 488 | if (enable) { |
| 489 | this->enableState(stateBits); |
| 490 | } else { |
| 491 | this->disableState(stateBits); |
| 492 | } |
| 493 | } |
| 494 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 495 | /// @} |
| 496 | |
| 497 | /////////////////////////////////////////////////////////////////////////// |
| 498 | /// @name Face Culling |
| 499 | //// |
| 500 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 501 | /** |
| 502 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 503 | * @param face the face(s) to draw. |
| 504 | */ |
| 505 | void setDrawFace(DrawFace face) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 506 | SkASSERT(kInvalid_DrawFace != face); |
bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 507 | fDrawFace = face; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 508 | } |
| 509 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 510 | /// @} |
| 511 | |
| 512 | /////////////////////////////////////////////////////////////////////////// |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 513 | /// @name Hints |
| 514 | /// Hints that when provided can enable optimizations. |
| 515 | //// |
| 516 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 517 | void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (fHints & ~hint); } |
| 518 | |
| 519 | /// @} |
| 520 | |
| 521 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 522 | |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 523 | /** Return type for CombineIfPossible. */ |
| 524 | enum CombinedState { |
| 525 | /** The GrDrawStates cannot be combined. */ |
| 526 | kIncompatible_CombinedState, |
| 527 | /** Either draw state can be used in place of the other. */ |
| 528 | kAOrB_CombinedState, |
| 529 | /** Use the first draw state. */ |
| 530 | kA_CombinedState, |
| 531 | /** Use the second draw state. */ |
| 532 | kB_CombinedState, |
| 533 | }; |
| 534 | |
| 535 | /** This function determines whether the GrDrawStates used for two draws can be combined into |
| 536 | a single GrDrawState. This is used to avoid storing redundant GrDrawStates and to determine |
| 537 | if draws can be batched. The return value indicates whether combining is possible and, if |
| 538 | so, which of the two inputs should be used. */ |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 539 | static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawState& b, |
| 540 | const GrDrawTargetCaps& caps); |
bsalomon | 72336ed | 2014-08-05 07:35:56 -0700 | [diff] [blame] | 541 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 542 | GrDrawState& operator= (const GrDrawState& that); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 543 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 544 | /** |
| 545 | * Returns a snapshot of the current optimized state. If the current drawState has a valid |
| 546 | * cached optimiezed state it will simply return a pointer to it otherwise it will create a new |
| 547 | * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership is given to the |
| 548 | * caller. |
| 549 | */ |
| 550 | GrOptDrawState* createOptState() const; |
| 551 | |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 552 | private: |
egdaniel | 170f90b | 2014-09-16 12:54:40 -0700 | [diff] [blame] | 553 | void invalidateOptState() const; |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 554 | |
bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 555 | void onReset(const SkMatrix* initialViewMatrix); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 556 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 557 | // Some of the auto restore objects assume that no effects are removed during their lifetime. |
| 558 | // This is used to assert that this condition holds. |
commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 559 | SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 560 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 561 | void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, size_t stride); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 562 | |
egdaniel | 3658f38 | 2014-09-15 07:01:59 -0700 | [diff] [blame] | 563 | mutable GrOptDrawState* fCachedOptState; |
| 564 | |
egdaniel | 21aed57 | 2014-08-26 12:24:06 -0700 | [diff] [blame] | 565 | typedef GrRODrawState INHERITED; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 566 | }; |
| 567 | |
| 568 | #endif |