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