| 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" |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 12 | #include "GrColor.h" |
| bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 13 | #include "GrEffectStage.h" |
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 14 | #include "GrStencil.h" |
| bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 15 | #include "effects/GrSimpleTextureEffect.h" |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 16 | |
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 17 | #include "SkMatrix.h" |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 18 | |
| 19 | class GrDrawTargetCaps; |
| 20 | class GrPaint; |
| 21 | class GrRenderTarget; |
| 22 | class GrTexture; |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 23 | |
| commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 24 | class GrDrawState : public SkRefCnt { |
| 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 | |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 28 | GrDrawState() { |
| 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 | |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 33 | GrDrawState(const SkMatrix& initialViewMatrix) { |
| 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 | **/ |
| commit-bot@chromium.org | faa5ae4 | 2013-07-23 11:13:56 +0000 | [diff] [blame] | 41 | GrDrawState(const GrDrawState& state) : INHERITED() { |
| 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 | |
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 51 | virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } |
| 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@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 63 | * equivalents are set to default values. Clipping will be enabled. |
| bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 64 | */ |
| commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 65 | void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarget*); |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 66 | |
| 67 | /////////////////////////////////////////////////////////////////////////// |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 68 | /// @name Vertex Attributes |
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 69 | //// |
| 70 | |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 71 | enum { |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 72 | kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, |
| jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 75 | /** |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 76 | * The format of vertices is represented as an array of GrVertexAttribs, with each representing |
| 77 | * the type of the attribute, its offset, and semantic binding (see GrVertexAttrib in |
| 78 | * GrTypesPriv.h). |
| jvanverth@google.com | b8b705b | 2013-02-28 16:28:34 +0000 | [diff] [blame] | 79 | * |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 80 | * The mapping of attributes with kEffect bindings to GrEffect inputs is specified when |
| 81 | * setEffect is called. |
| jvanverth@google.com | b8b705b | 2013-02-28 16:28:34 +0000 | [diff] [blame] | 82 | */ |
| jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 83 | |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 84 | /** |
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 85 | * Sets vertex attributes for next draw. The object driving the templatization |
| 86 | * should be a global GrVertexAttrib array that is never changed. |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 87 | */ |
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 88 | template <const GrVertexAttrib A[]> void setVertexAttribs(int count) { |
| 89 | this->setVertexAttribs(A, count); |
| 90 | } |
| jvanverth@google.com | b8b705b | 2013-02-28 16:28:34 +0000 | [diff] [blame] | 91 | |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 92 | const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; } |
| 93 | int getVertexAttribCount() const { return fVACount; } |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 94 | |
| 95 | size_t getVertexSize() const; |
| 96 | |
| 97 | /** |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 98 | * Sets default vertex attributes for next draw. The default is a single attribute: |
| 99 | * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 100 | */ |
| 101 | void setDefaultVertexAttribs(); |
| jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 102 | |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 103 | /** |
| 104 | * Getters for index into getVertexAttribs() for particular bindings. -1 is returned if the |
| 105 | * binding does not appear in the current attribs. These bindings should appear only once in |
| 106 | * the attrib array. |
| 107 | */ |
| 108 | |
| 109 | int positionAttributeIndex() const { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 110 | return fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding]; |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 111 | } |
| 112 | int localCoordAttributeIndex() const { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 113 | return fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttribBinding]; |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 114 | } |
| 115 | int colorVertexAttributeIndex() const { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 116 | return fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBinding]; |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 117 | } |
| 118 | int coverageVertexAttributeIndex() const { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 119 | return fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribBinding]; |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | bool hasLocalCoordAttribute() const { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 123 | return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttribBinding]; |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 124 | } |
| 125 | bool hasColorVertexAttribute() const { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 126 | return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBinding]; |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 127 | } |
| 128 | bool hasCoverageVertexAttribute() const { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 129 | return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribBinding]; |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 132 | bool validateVertexAttribs() const; |
| 133 | |
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 134 | /** |
| bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 135 | * Helper to save/restore vertex attribs |
| 136 | */ |
| 137 | class AutoVertexAttribRestore { |
| 138 | public: |
| bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 139 | AutoVertexAttribRestore(GrDrawState* drawState); |
| bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 140 | |
| bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 141 | ~AutoVertexAttribRestore() { fDrawState->setVertexAttribs(fVAPtr, fVACount); } |
| bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 142 | |
| 143 | private: |
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 144 | GrDrawState* fDrawState; |
| 145 | const GrVertexAttrib* fVAPtr; |
| 146 | int fVACount; |
| bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 149 | /// @} |
| 150 | |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 151 | /** |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 152 | * Determines whether src alpha is guaranteed to be one for all src pixels |
| 153 | */ |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 154 | bool srcAlphaWillBeOne() const; |
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 155 | |
| 156 | /** |
| 157 | * Determines whether the output coverage is guaranteed to be one for all pixels hit by a draw. |
| 158 | */ |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 159 | bool hasSolidCoverage() const; |
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 160 | |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 161 | /** |
| 162 | * Depending on features available in the underlying 3D API and the color blend mode requested |
| 163 | * it may or may not be possible to correctly blend with fractional pixel coverage generated by |
| 164 | * the fragment shader. |
| 165 | * |
| 166 | * This function considers the current draw state and the draw target's capabilities to |
| 167 | * determine whether coverage can be handled correctly. This function assumes that the caller |
| 168 | * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex |
| 169 | * attribute, or a coverage effect) but may not have specified it yet. |
| 170 | */ |
| 171 | bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; |
| 172 | |
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 173 | /// @} |
| 174 | |
| 175 | /////////////////////////////////////////////////////////////////////////// |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 176 | /// @name Color |
| 177 | //// |
| 178 | |
| 179 | /** |
| 180 | * Sets color for next draw to a premultiplied-alpha color. |
| 181 | * |
| 182 | * @param color the color to set. |
| 183 | */ |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 184 | void setColor(GrColor color) { |
| 185 | fColor = color; |
| 186 | this->invalidateBlendOptFlags(); |
| 187 | } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 188 | |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 189 | GrColor getColor() const { return fColor; } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * Sets the color to be used for the next draw to be |
| 193 | * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
| 194 | * |
| 195 | * @param alpha The alpha value to set as the color. |
| 196 | */ |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 197 | 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] | 198 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 199 | /// @} |
| 200 | |
| 201 | /////////////////////////////////////////////////////////////////////////// |
| bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 202 | /// @name Coverage |
| 203 | //// |
| 204 | |
| 205 | /** |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 206 | * 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] | 207 | * initial value (after construction or reset()) is 0xff. The constant |
| 208 | * coverage is ignored when per-vertex coverage is provided. |
| 209 | */ |
| 210 | void setCoverage(uint8_t coverage) { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 211 | fCoverage = GrColorPackRGBA(coverage, coverage, coverage, coverage); |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 212 | this->invalidateBlendOptFlags(); |
| bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 215 | uint8_t getCoverage() const { return GrColorUnpackR(fCoverage); } |
| bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 216 | |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 217 | GrColor getCoverageColor() const { return fCoverage; } |
| bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 218 | |
| 219 | /// @} |
| 220 | |
| egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 221 | /** |
| 222 | * This struct is here so that the GrDrawState can have multiple instances of state information. |
| 223 | * The use of this will come in a future revision when we want to keep track of the original |
| 224 | * draw state as well as an optimized version of it. |
| 225 | */ |
| 226 | struct State { |
| 227 | State() { |
| 228 | this->reset(); |
| 229 | } |
| 230 | |
| 231 | State(const GrEffectStage* colorArray, int colorCount, |
| 232 | const GrEffectStage* coverageArray, int coverageCount) |
| 233 | : fColorStages(colorArray, colorCount), fCoverageStages(coverageArray, coverageCount) { |
| 234 | fSrcBlend = kOne_GrBlendCoeff; |
| 235 | fDstBlend = kZero_GrBlendCoeff; |
| 236 | } |
| 237 | |
| 238 | static bool HaveCompatibleState(const State& a, const State& b, bool explicitLocalCoords); |
| 239 | |
| 240 | void reset() { |
| 241 | fSrcBlend = kOne_GrBlendCoeff; |
| 242 | fDstBlend = kZero_GrBlendCoeff; |
| 243 | fColorStages.reset(); |
| 244 | fCoverageStages.reset(); |
| 245 | } |
| 246 | |
| 247 | GrBlendCoeff fSrcBlend; |
| 248 | GrBlendCoeff fDstBlend; |
| 249 | |
| 250 | typedef SkSTArray<4, GrEffectStage> EffectStageArray; |
| 251 | EffectStageArray fColorStages; |
| 252 | EffectStageArray fCoverageStages; |
| 253 | }; |
| 254 | |
| bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 255 | /////////////////////////////////////////////////////////////////////////// |
| bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 256 | /// @name Effect Stages |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 257 | /// Each stage hosts a GrEffect. The effect produces an output color or coverage in the fragment |
| 258 | /// shader. Its inputs are the output from the previous stage as well as some variables |
| 259 | /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color, |
| 260 | /// the fragment position, local coordinates). |
| 261 | /// |
| 262 | /// The stages are divided into two sets, color-computing and coverage-computing. The final |
| 263 | /// color stage produces the final pixel color. The coverage-computing stages function exactly |
| 264 | /// as the color-computing but the output of the final coverage stage is treated as a fractional |
| 265 | /// pixel coverage rather than as input to the src/dst color blend step. |
| 266 | /// |
| 267 | /// The input color to the first color-stage is either the constant color or interpolated |
| 268 | /// per-vertex colors. The input to the first coverage stage is either a constant coverage |
| 269 | /// (usually full-coverage) or interpolated per-vertex coverage. |
| 270 | /// |
| 271 | /// See the documentation of kCoverageDrawing_StateBit for information about disabling the |
| 272 | /// the color / coverage distinction. |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 273 | //// |
| 274 | |
| bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 275 | 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] | 276 | SkASSERT(NULL != effect); |
| egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 277 | SkNEW_APPEND_TO_TARRAY(&fState.fColorStages, GrEffectStage, (effect, attr0, attr1)); |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 278 | this->invalidateBlendOptFlags(); |
| jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 279 | return effect; |
| 280 | } |
| skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 281 | |
| bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 282 | 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] | 283 | SkASSERT(NULL != effect); |
| egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 284 | SkNEW_APPEND_TO_TARRAY(&fState.fCoverageStages, GrEffectStage, (effect, attr0, attr1)); |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 285 | this->invalidateBlendOptFlags(); |
| bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 286 | return effect; |
| 287 | } |
| 288 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 289 | /** |
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 290 | * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates. |
| tomhudson@google.com | 1e8f016 | 2012-07-20 16:25:18 +0000 | [diff] [blame] | 291 | */ |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 292 | void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { |
| bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 293 | this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
| bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 294 | } |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 295 | |
| 296 | void addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix) { |
| bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 297 | this->addCoverageEffect(GrSimpleTextureEffect::Create(texture, matrix))->unref(); |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | void addColorTextureEffect(GrTexture* texture, |
| 301 | const SkMatrix& matrix, |
| 302 | const GrTextureParams& params) { |
| bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 303 | this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
| bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 304 | } |
| 305 | |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 306 | void addCoverageTextureEffect(GrTexture* texture, |
| 307 | const SkMatrix& matrix, |
| 308 | const GrTextureParams& params) { |
| bsalomon | 97b9ab7 | 2014-07-08 06:52:35 -0700 | [diff] [blame] | 309 | this->addCoverageEffect(GrSimpleTextureEffect::Create(texture, matrix, params))->unref(); |
| commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 310 | } |
| tomhudson@google.com | 676e660 | 2012-07-10 17:21:48 +0000 | [diff] [blame] | 311 | |
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 312 | /** |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 313 | * When this object is destroyed it will remove any effects from the draw state that were added |
| 314 | * after its constructor. |
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 315 | */ |
| commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 316 | class AutoRestoreEffects : public ::SkNoncopyable { |
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 317 | public: |
| bsalomon@google.com | 2fad5a8 | 2013-06-13 19:47:23 +0000 | [diff] [blame] | 318 | AutoRestoreEffects() : fDrawState(NULL), fColorEffectCnt(0), fCoverageEffectCnt(0) {} |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 319 | |
| skia.committer@gmail.com | 5c493d5 | 2013-06-14 07:00:49 +0000 | [diff] [blame] | 320 | AutoRestoreEffects(GrDrawState* ds) : fDrawState(NULL), fColorEffectCnt(0), fCoverageEffectCnt(0) { |
| 321 | this->set(ds); |
| robertphillips@google.com | f09b87d | 2013-06-13 20:06:44 +0000 | [diff] [blame] | 322 | } |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 323 | |
| 324 | ~AutoRestoreEffects() { this->set(NULL); } |
| 325 | |
| bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 326 | void set(GrDrawState* ds); |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 327 | |
| bsalomon | 8af0523 | 2014-06-03 06:34:58 -0700 | [diff] [blame] | 328 | bool isSet() const { return NULL != fDrawState; } |
| 329 | |
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 330 | private: |
| 331 | GrDrawState* fDrawState; |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 332 | int fColorEffectCnt; |
| 333 | int fCoverageEffectCnt; |
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 334 | }; |
| 335 | |
| egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 336 | int numColorStages() const { return fState.fColorStages.count(); } |
| 337 | int numCoverageStages() const { return fState.fCoverageStages.count(); } |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 338 | int numTotalStages() const { return this->numColorStages() + this->numCoverageStages(); } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 339 | |
| egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 340 | const GrEffectStage& getColorStage(int stageIdx) const { return fState.fColorStages[stageIdx]; } |
| 341 | const GrEffectStage& getCoverageStage(int stageIdx) const { return fState.fCoverageStages[stageIdx]; } |
| skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 342 | |
| commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 343 | /** |
| 344 | * Checks whether any of the effects will read the dst pixel color. |
| 345 | */ |
| bsalomon@google.com | d09ab84 | 2013-05-15 17:30:26 +0000 | [diff] [blame] | 346 | bool willEffectReadDstColor() const; |
| reed@google.com | 67e7cde | 2013-03-20 17:47:16 +0000 | [diff] [blame] | 347 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 348 | /// @} |
| 349 | |
| 350 | /////////////////////////////////////////////////////////////////////////// |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 351 | /// @name Blending |
| 352 | //// |
| 353 | |
| 354 | /** |
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 355 | * Sets the blending function coefficients. |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 356 | * |
| 357 | * The blend function will be: |
| 358 | * D' = sat(S*srcCoef + D*dstCoef) |
| 359 | * |
| 360 | * where D is the existing destination color, S is the incoming source |
| 361 | * color, and D' is the new destination color that will be written. sat() |
| 362 | * is the saturation function. |
| 363 | * |
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 364 | * @param srcCoef coefficient applied to the src color. |
| 365 | * @param dstCoef coefficient applied to the dst color. |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 366 | */ |
| 367 | void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { |
| egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 368 | fState.fSrcBlend = srcCoeff; |
| 369 | fState.fDstBlend = dstCoeff; |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 370 | this->invalidateBlendOptFlags(); |
| commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 371 | #ifdef SK_DEBUG |
| commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 372 | if (GrBlendCoeffRefsDst(dstCoeff)) { |
| 373 | 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] | 374 | } |
| commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 375 | if (GrBlendCoeffRefsSrc(srcCoeff)) { |
| 376 | 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] | 377 | } |
| 378 | #endif |
| 379 | } |
| 380 | |
| egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 381 | GrBlendCoeff getSrcBlendCoeff() const { return fState.fSrcBlend; } |
| 382 | GrBlendCoeff getDstBlendCoeff() const { return fState.fDstBlend; } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 383 | |
| 384 | void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff, |
| 385 | GrBlendCoeff* dstBlendCoeff) const { |
| egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 386 | *srcBlendCoeff = fState.fSrcBlend; |
| 387 | *dstBlendCoeff = fState.fDstBlend; |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /** |
| 391 | * Sets the blending function constant referenced by the following blending |
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 392 | * coefficients: |
| bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 393 | * kConstC_GrBlendCoeff |
| 394 | * kIConstC_GrBlendCoeff |
| 395 | * kConstA_GrBlendCoeff |
| 396 | * kIConstA_GrBlendCoeff |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 397 | * |
| 398 | * @param constant the constant to set |
| 399 | */ |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 400 | void setBlendConstant(GrColor constant) { |
| 401 | fBlendConstant = constant; |
| 402 | this->invalidateBlendOptFlags(); |
| 403 | } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 404 | |
| 405 | /** |
| 406 | * Retrieves the last value set by setBlendConstant() |
| 407 | * @return the blending constant value |
| 408 | */ |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 409 | GrColor getBlendConstant() const { return fBlendConstant; } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 410 | |
| bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 411 | /** |
| 412 | * Determines whether multiplying the computed per-pixel color by the pixel's fractional |
| 413 | * coverage before the blend will give the correct final destination color. In general it |
| 414 | * will not as coverage is applied after blending. |
| 415 | */ |
| 416 | bool canTweakAlphaForCoverage() const; |
| 417 | |
| 418 | /** |
| 419 | * Optimizations for blending / coverage to that can be applied based on the current state. |
| 420 | */ |
| 421 | enum BlendOptFlags { |
| 422 | /** |
| 423 | * No optimization |
| 424 | */ |
| 425 | kNone_BlendOpt = 0, |
| 426 | /** |
| 427 | * Don't draw at all |
| 428 | */ |
| 429 | kSkipDraw_BlendOptFlag = 0x1, |
| 430 | /** |
| bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 431 | * The coverage value does not have to be computed separately from alpha, the the output |
| 432 | * color can be the modulation of the two. |
| 433 | */ |
| egdaniel | 0f1a7c4 | 2014-07-30 13:18:32 -0700 | [diff] [blame] | 434 | kCoverageAsAlpha_BlendOptFlag = 0x2, |
| bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 435 | /** |
| 436 | * Instead of emitting a src color, emit coverage in the alpha channel and r,g,b are |
| 437 | * "don't cares". |
| 438 | */ |
| egdaniel | 0f1a7c4 | 2014-07-30 13:18:32 -0700 | [diff] [blame] | 439 | kEmitCoverage_BlendOptFlag = 0x4, |
| bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 440 | /** |
| 441 | * Emit transparent black instead of the src color, no need to compute coverage. |
| 442 | */ |
| egdaniel | 0f1a7c4 | 2014-07-30 13:18:32 -0700 | [diff] [blame] | 443 | kEmitTransBlack_BlendOptFlag = 0x8, |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 444 | /** |
| 445 | * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and OptDstCoeff cached by |
| 446 | * the get BlendOpts function. |
| 447 | */ |
| egdaniel | 0f1a7c4 | 2014-07-30 13:18:32 -0700 | [diff] [blame] | 448 | kInvalid_BlendOptFlag = 1 << 31, |
| bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 449 | }; |
| 450 | GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); |
| 451 | |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 452 | void invalidateBlendOptFlags() { |
| 453 | fBlendOptFlags = kInvalid_BlendOptFlag; |
| 454 | } |
| 455 | |
| bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 456 | /** |
| egdaniel | 02cafcc | 2014-07-21 11:37:28 -0700 | [diff] [blame] | 457 | * We don't use suplied vertex color attributes if our blend mode is EmitCoverage or |
| 458 | * EmitTransBlack |
| 459 | */ |
| 460 | bool canIgnoreColorAttribute() const; |
| 461 | |
| 462 | /** |
| bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 463 | * Determines what optimizations can be applied based on the blend. The coefficients may have |
| 464 | * to be tweaked in order for the optimization to work. srcCoeff and dstCoeff are optional |
| 465 | * params that receive the tweaked coefficients. Normally the function looks at the current |
| 466 | * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively |
| 467 | * determine the blend optimizations that would be used if there was partial pixel coverage. |
| 468 | * |
| 469 | * Subclasses of GrDrawTarget that actually draw (as opposed to those that just buffer for |
| 470 | * 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] | 471 | * |
| 472 | * If the cached BlendOptFlags does not have the invalidate bit set, then getBlendOpts will |
| 473 | * 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] | 474 | */ |
| 475 | BlendOptFlags getBlendOpts(bool forceCoverage = false, |
| 476 | GrBlendCoeff* srcCoeff = NULL, |
| 477 | GrBlendCoeff* dstCoeff = NULL) const; |
| 478 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 479 | /// @} |
| 480 | |
| 481 | /////////////////////////////////////////////////////////////////////////// |
| 482 | /// @name View Matrix |
| 483 | //// |
| 484 | |
| 485 | /** |
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 486 | * Sets the view matrix to identity and updates any installed effects to compensate for the |
| 487 | * coord system change. |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 488 | */ |
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 489 | bool setIdentityViewMatrix(); |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 490 | |
| 491 | /** |
| 492 | * Retrieves the current view matrix |
| 493 | * @return the current view matrix. |
| 494 | */ |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 495 | const SkMatrix& getViewMatrix() const { return fViewMatrix; } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 496 | |
| 497 | /** |
| 498 | * Retrieves the inverse of the current view matrix. |
| 499 | * |
| 500 | * If the current view matrix is invertible, return true, and if matrix |
| 501 | * is non-null, copy the inverse into it. If the current view matrix is |
| 502 | * non-invertible, return false and ignore the matrix parameter. |
| 503 | * |
| 504 | * @param matrix if not null, will receive a copy of the current inverse. |
| 505 | */ |
| bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 506 | bool getViewInverse(SkMatrix* matrix) const { |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 507 | // TODO: determine whether we really need to leave matrix unmodified |
| 508 | // at call sites when inversion fails. |
| bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 509 | SkMatrix inverse; |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 510 | if (fViewMatrix.invert(&inverse)) { |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 511 | if (matrix) { |
| 512 | *matrix = inverse; |
| 513 | } |
| 514 | return true; |
| 515 | } |
| 516 | return false; |
| 517 | } |
| 518 | |
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 519 | //////////////////////////////////////////////////////////////////////////// |
| 520 | |
| 521 | /** |
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 522 | * 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] | 523 | * 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] | 524 | */ |
| commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 525 | class AutoViewMatrixRestore : public ::SkNoncopyable { |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 526 | public: |
| 527 | AutoViewMatrixRestore() : fDrawState(NULL) {} |
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 528 | |
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 529 | AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) { |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 530 | fDrawState = NULL; |
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 531 | this->set(ds, preconcatMatrix); |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 532 | } |
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 533 | |
| 534 | ~AutoViewMatrixRestore() { this->restore(); } |
| 535 | |
| bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 536 | /** |
| 537 | * Can be called prior to destructor to restore the original matrix. |
| 538 | */ |
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 539 | void restore(); |
| skia.committer@gmail.com | f467ce7 | 2012-10-09 02:01:37 +0000 | [diff] [blame] | 540 | |
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 541 | void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix); |
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 542 | |
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 543 | /** Sets the draw state's matrix to identity. This can fail because the current view matrix |
| 544 | is not invertible. */ |
| 545 | bool setIdentity(GrDrawState* drawState); |
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 546 | |
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 547 | private: |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 548 | void doEffectCoordChanges(const SkMatrix& coordChangeMatrix); |
| 549 | |
| 550 | GrDrawState* fDrawState; |
| 551 | SkMatrix fViewMatrix; |
| 552 | int fNumColorStages; |
| 553 | SkAutoSTArray<8, GrEffectStage::SavedCoordChange> fSavedCoordChanges; |
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 554 | }; |
| 555 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 556 | /// @} |
| 557 | |
| 558 | /////////////////////////////////////////////////////////////////////////// |
| 559 | /// @name Render Target |
| 560 | //// |
| 561 | |
| 562 | /** |
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 563 | * Sets the render-target used at the next drawing call |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 564 | * |
| 565 | * @param target The render target to set. |
| 566 | */ |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 567 | void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef(target)); } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 568 | |
| 569 | /** |
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 570 | * Retrieves the currently set render-target. |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 571 | * |
| 572 | * @return The currently set render target. |
| 573 | */ |
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 574 | const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
| 575 | GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 576 | |
| commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 577 | class AutoRenderTargetRestore : public ::SkNoncopyable { |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 578 | public: |
| bsalomon@google.com | cadbcb8 | 2012-01-06 19:22:11 +0000 | [diff] [blame] | 579 | AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 580 | AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { |
| 581 | fDrawState = NULL; |
| robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 582 | fSavedTarget = NULL; |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 583 | this->set(ds, newTarget); |
| 584 | } |
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 585 | ~AutoRenderTargetRestore() { this->restore(); } |
| 586 | |
| 587 | void restore() { |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 588 | if (NULL != fDrawState) { |
| 589 | fDrawState->setRenderTarget(fSavedTarget); |
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 590 | fDrawState = NULL; |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 591 | } |
| commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 592 | SkSafeSetNull(fSavedTarget); |
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | void set(GrDrawState* ds, GrRenderTarget* newTarget) { |
| 596 | this->restore(); |
| 597 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 598 | if (NULL != ds) { |
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 599 | SkASSERT(NULL == fSavedTarget); |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 600 | fSavedTarget = ds->getRenderTarget(); |
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 601 | SkSafeRef(fSavedTarget); |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 602 | ds->setRenderTarget(newTarget); |
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 603 | fDrawState = ds; |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 604 | } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 605 | } |
| 606 | private: |
| 607 | GrDrawState* fDrawState; |
| 608 | GrRenderTarget* fSavedTarget; |
| 609 | }; |
| 610 | |
| 611 | /// @} |
| 612 | |
| 613 | /////////////////////////////////////////////////////////////////////////// |
| 614 | /// @name Stencil |
| 615 | //// |
| 616 | |
| 617 | /** |
| 618 | * Sets the stencil settings to use for the next draw. |
| 619 | * Changing the clip has the side-effect of possibly zeroing |
| 620 | * out the client settable stencil bits. So multipass algorithms |
| 621 | * using stencil should not change the clip between passes. |
| 622 | * @param settings the stencil settings to use. |
| 623 | */ |
| 624 | void setStencil(const GrStencilSettings& settings) { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 625 | fStencilSettings = settings; |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 626 | this->invalidateBlendOptFlags(); |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | /** |
| 630 | * Shortcut to disable stencil testing and ops. |
| 631 | */ |
| 632 | void disableStencil() { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 633 | fStencilSettings.setDisabled(); |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 634 | this->invalidateBlendOptFlags(); |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 637 | const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 638 | |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 639 | GrStencilSettings* stencil() { return &fStencilSettings; } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 640 | |
| 641 | /// @} |
| 642 | |
| 643 | /////////////////////////////////////////////////////////////////////////// |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 644 | /// @name State Flags |
| 645 | //// |
| tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 646 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 647 | /** |
| 648 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 649 | * default to disabled. |
| 650 | */ |
| 651 | enum StateBits { |
| 652 | /** |
| 653 | * Perform dithering. TODO: Re-evaluate whether we need this bit |
| 654 | */ |
| 655 | kDither_StateBit = 0x01, |
| 656 | /** |
| bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 657 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, |
| 658 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by |
| 659 | * the 3D API. |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 660 | */ |
| 661 | kHWAntialias_StateBit = 0x02, |
| 662 | /** |
| 663 | * Draws will respect the clip, otherwise the clip is ignored. |
| 664 | */ |
| 665 | kClip_StateBit = 0x04, |
| 666 | /** |
| 667 | * Disables writing to the color buffer. Useful when performing stencil |
| 668 | * operations. |
| 669 | */ |
| 670 | kNoColorWrites_StateBit = 0x08, |
| bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 671 | |
| bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 672 | /** |
| 673 | * Usually coverage is applied after color blending. The color is blended using the coeffs |
| 674 | * specified by setBlendFunc(). The blended color is then combined with dst using coeffs |
| 675 | * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing a coverage mask. In |
| 676 | * this case there is no distinction between coverage and color and the caller needs direct |
| 677 | * control over the blend coeffs. When set, there will be a single blend step controlled by |
| 678 | * setBlendFunc() which will use coverage*color as the src color. |
| 679 | */ |
| 680 | kCoverageDrawing_StateBit = 0x10, |
| 681 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 682 | // Users of the class may add additional bits to the vector |
| 683 | kDummyStateBit, |
| 684 | kLastPublicStateBit = kDummyStateBit-1, |
| 685 | }; |
| 686 | |
| 687 | void resetStateFlags() { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 688 | fFlagBits = 0; |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 689 | this->invalidateBlendOptFlags(); |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /** |
| 693 | * Enable render state settings. |
| 694 | * |
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 695 | * @param stateBits bitfield of StateBits specifying the states to enable |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 696 | */ |
| 697 | void enableState(uint32_t stateBits) { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 698 | fFlagBits |= stateBits; |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 699 | this->invalidateBlendOptFlags(); |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | /** |
| 703 | * Disable render state settings. |
| 704 | * |
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 705 | * @param stateBits bitfield of StateBits specifying the states to disable |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 706 | */ |
| 707 | void disableState(uint32_t stateBits) { |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 708 | fFlagBits &= ~(stateBits); |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 709 | this->invalidateBlendOptFlags(); |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 710 | } |
| 711 | |
| bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 712 | /** |
| 713 | * Enable or disable stateBits based on a boolean. |
| 714 | * |
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 715 | * @param stateBits bitfield of StateBits to enable or disable |
| bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 716 | * @param enable if true enable stateBits, otherwise disable |
| 717 | */ |
| 718 | void setState(uint32_t stateBits, bool enable) { |
| 719 | if (enable) { |
| 720 | this->enableState(stateBits); |
| 721 | } else { |
| 722 | this->disableState(stateBits); |
| 723 | } |
| 724 | } |
| 725 | |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 726 | bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & fFlagBits); } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 727 | |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 728 | bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); } |
| 729 | bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_StateBit); } |
| 730 | bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); } |
| 731 | bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_StateBit); } |
| 732 | bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_StateBit); } |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 733 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 734 | /// @} |
| 735 | |
| 736 | /////////////////////////////////////////////////////////////////////////// |
| 737 | /// @name Face Culling |
| 738 | //// |
| 739 | |
| 740 | enum DrawFace { |
| bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 741 | kInvalid_DrawFace = -1, |
| 742 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 743 | kBoth_DrawFace, |
| 744 | kCCW_DrawFace, |
| 745 | kCW_DrawFace, |
| 746 | }; |
| 747 | |
| 748 | /** |
| 749 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 750 | * @param face the face(s) to draw. |
| 751 | */ |
| 752 | void setDrawFace(DrawFace face) { |
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 753 | SkASSERT(kInvalid_DrawFace != face); |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 754 | fDrawFace = face; |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | /** |
| 758 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 759 | * or both faces. |
| 760 | * @return the current draw face(s). |
| 761 | */ |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 762 | DrawFace getDrawFace() const { return fDrawFace; } |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 763 | |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 764 | /// @} |
| 765 | |
| 766 | /////////////////////////////////////////////////////////////////////////// |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 767 | /// @name Hints |
| 768 | /// Hints that when provided can enable optimizations. |
| 769 | //// |
| 770 | |
| 771 | enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; |
| 772 | |
| 773 | void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (fHints & ~hint); } |
| 774 | |
| 775 | /// @} |
| 776 | |
| 777 | /////////////////////////////////////////////////////////////////////////// |
| tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 778 | |
| bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 779 | /** Return type for CombineIfPossible. */ |
| 780 | enum CombinedState { |
| 781 | /** The GrDrawStates cannot be combined. */ |
| 782 | kIncompatible_CombinedState, |
| 783 | /** Either draw state can be used in place of the other. */ |
| 784 | kAOrB_CombinedState, |
| 785 | /** Use the first draw state. */ |
| 786 | kA_CombinedState, |
| 787 | /** Use the second draw state. */ |
| 788 | kB_CombinedState, |
| 789 | }; |
| 790 | |
| 791 | /** This function determines whether the GrDrawStates used for two draws can be combined into |
| 792 | a single GrDrawState. This is used to avoid storing redundant GrDrawStates and to determine |
| 793 | if draws can be batched. The return value indicates whether combining is possible and, if |
| 794 | so, which of the two inputs should be used. */ |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 795 | static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawState& b, |
| 796 | const GrDrawTargetCaps& caps); |
| bsalomon | 72336ed | 2014-08-05 07:35:56 -0700 | [diff] [blame] | 797 | |
| bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 798 | GrDrawState& operator= (const GrDrawState& that); |
| bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 799 | |
| 800 | private: |
| bsalomon | 8f72733 | 2014-08-05 07:50:06 -0700 | [diff] [blame] | 801 | void onReset(const SkMatrix* initialViewMatrix); |
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 802 | |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 803 | BlendOptFlags calcBlendOpts(bool forceCoverage = false, |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 804 | GrBlendCoeff* srcCoeff = NULL, |
| 805 | GrBlendCoeff* dstCoeff = NULL) const; |
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 806 | |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 807 | // These fields are roughly sorted by decreasing likelihood of being different in op== |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 808 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 809 | GrColor fColor; |
| 810 | SkMatrix fViewMatrix; |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 811 | GrColor fBlendConstant; |
| 812 | uint32_t fFlagBits; |
| 813 | const GrVertexAttrib* fVAPtr; |
| 814 | int fVACount; |
| 815 | GrStencilSettings fStencilSettings; |
| 816 | GrColor fCoverage; |
| 817 | DrawFace fDrawFace; |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 818 | |
| egdaniel | 776bdbd | 2014-08-06 11:07:02 -0700 | [diff] [blame] | 819 | State fState; |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 820 | |
| 821 | uint32_t fHints; |
| egdaniel | 9514d24 | 2014-07-18 06:15:43 -0700 | [diff] [blame] | 822 | |
| bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame^] | 823 | mutable GrBlendCoeff fOptSrcBlend; |
| 824 | mutable GrBlendCoeff fOptDstBlend; |
| 825 | mutable BlendOptFlags fBlendOptFlags; |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 826 | |
| bsalomon | 2ed5ef8 | 2014-07-07 08:44:05 -0700 | [diff] [blame] | 827 | // This is simply a different representation of info in fVertexAttribs and thus does |
| 828 | // not need to be compared in op==. |
| 829 | int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt]; |
| 830 | |
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 831 | // Some of the auto restore objects assume that no effects are removed during their lifetime. |
| 832 | // This is used to assert that this condition holds. |
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 833 | SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 834 | |
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 835 | /** |
| 836 | * Sets vertex attributes for next draw. |
| 837 | * |
| 838 | * @param attribs the array of vertex attributes to set. |
| 839 | * @param count the number of attributes being set, limited to kMaxVertexAttribCnt. |
| 840 | */ |
| 841 | void setVertexAttribs(const GrVertexAttrib attribs[], int count); |
| 842 | |
| commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 843 | typedef SkRefCnt INHERITED; |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 844 | }; |
| 845 | |
| bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 846 | GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); |
| 847 | |
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 848 | #endif |