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