| 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 |  | 
| bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 11 | #include "GrBackendEffectFactory.h" | 
| commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 12 | #include "GrBlend.h" | 
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 13 | #include "GrColor.h" | 
| bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 14 | #include "GrEffectStage.h" | 
| bsalomon@google.com | 73818dc | 2013-03-28 13:23:29 +0000 | [diff] [blame] | 15 | #include "GrPaint.h" | 
| commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 16 | #include "GrPoint.h" | 
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 17 | #include "GrRenderTarget.h" | 
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 18 | #include "GrStencil.h" | 
|  | 19 | #include "GrTemplates.h" | 
|  | 20 | #include "GrTexture.h" | 
| bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 21 | #include "GrTypesPriv.h" | 
| bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 22 | #include "effects/GrSimpleTextureEffect.h" | 
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 23 |  | 
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 24 | #include "SkMatrix.h" | 
| commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 25 | #include "SkTypes.h" | 
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 26 | #include "SkXfermode.h" | 
|  | 27 |  | 
| commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 28 | class GrDrawState : public SkRefCnt { | 
| bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 29 | public: | 
| reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 30 | SK_DECLARE_INST_COUNT(GrDrawState) | 
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 31 |  | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 32 | GrDrawState() { | 
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 33 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 34 | this->reset(); | 
|  | 35 | } | 
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 36 |  | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 37 | GrDrawState(const SkMatrix& initialViewMatrix) { | 
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 38 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 39 | this->reset(initialViewMatrix); | 
|  | 40 | } | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 41 |  | 
|  | 42 | /** | 
|  | 43 | * Copies another draw state. | 
|  | 44 | **/ | 
| commit-bot@chromium.org | faa5ae4 | 2013-07-23 11:13:56 +0000 | [diff] [blame] | 45 | GrDrawState(const GrDrawState& state) : INHERITED() { | 
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 46 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 
| bsalomon@google.com | 46f7afb | 2012-01-18 19:51:55 +0000 | [diff] [blame] | 47 | *this = state; | 
|  | 48 | } | 
|  | 49 |  | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 50 | /** | 
|  | 51 | * Copies another draw state with a preconcat to the view matrix. | 
|  | 52 | **/ | 
|  | 53 | GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) { | 
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 54 | SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 55 | *this = state; | 
|  | 56 | if (!preConcatMatrix.isIdentity()) { | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 57 | for (int i = 0; i < fColorStages.count(); ++i) { | 
|  | 58 | fColorStages[i].localCoordChange(preConcatMatrix); | 
|  | 59 | } | 
|  | 60 | for (int i = 0; i < fCoverageStages.count(); ++i) { | 
|  | 61 | fCoverageStages[i].localCoordChange(preConcatMatrix); | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 62 | } | 
|  | 63 | } | 
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 64 | } | 
|  | 65 |  | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 66 | virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 67 |  | 
| bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 68 | /** | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 69 | * 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] | 70 | */ | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 71 | void reset() { this->onReset(NULL); } | 
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 72 |  | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 73 | void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMatrix); } | 
| bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 74 |  | 
|  | 75 | /** | 
| commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 76 | * Initializes the GrDrawState based on a GrPaint, view matrix and render target. Note that | 
|  | 77 | * 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] | 78 | * equivalents are set to default values. Clipping will be enabled. | 
| bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 79 | */ | 
| commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 80 | void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarget*); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 81 |  | 
|  | 82 | /////////////////////////////////////////////////////////////////////////// | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 83 | /// @name Vertex Attributes | 
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 84 | //// | 
|  | 85 |  | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 86 | enum { | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 87 | kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4, | 
| jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 88 | }; | 
|  | 89 |  | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 90 | /** | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 91 | * The format of vertices is represented as an array of GrVertexAttribs, with each representing | 
|  | 92 | * the type of the attribute, its offset, and semantic binding (see GrVertexAttrib in | 
|  | 93 | * GrTypesPriv.h). | 
| jvanverth@google.com | b8b705b | 2013-02-28 16:28:34 +0000 | [diff] [blame] | 94 | * | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 95 | * The mapping of attributes with kEffect bindings to GrEffect inputs is specified when | 
|  | 96 | * setEffect is called. | 
| jvanverth@google.com | b8b705b | 2013-02-28 16:28:34 +0000 | [diff] [blame] | 97 | */ | 
| jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 98 |  | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 99 | /** | 
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 100 | *  Sets vertex attributes for next draw. The object driving the templatization | 
|  | 101 | *  should be a global GrVertexAttrib array that is never changed. | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 102 | */ | 
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 103 | template <const GrVertexAttrib A[]> void setVertexAttribs(int count) { | 
|  | 104 | this->setVertexAttribs(A, count); | 
|  | 105 | } | 
| jvanverth@google.com | b8b705b | 2013-02-28 16:28:34 +0000 | [diff] [blame] | 106 |  | 
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 107 | const GrVertexAttrib* getVertexAttribs() const { return fCommon.fVAPtr; } | 
|  | 108 | int getVertexAttribCount() const { return fCommon.fVACount; } | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 109 |  | 
|  | 110 | size_t getVertexSize() const; | 
|  | 111 |  | 
|  | 112 | /** | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 113 | *  Sets default vertex attributes for next draw. The default is a single attribute: | 
|  | 114 | *  {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 115 | */ | 
|  | 116 | void setDefaultVertexAttribs(); | 
| jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 117 |  | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 118 | /** | 
|  | 119 | * Getters for index into getVertexAttribs() for particular bindings. -1 is returned if the | 
|  | 120 | * binding does not appear in the current attribs. These bindings should appear only once in | 
|  | 121 | * the attrib array. | 
|  | 122 | */ | 
|  | 123 |  | 
|  | 124 | int positionAttributeIndex() const { | 
|  | 125 | return fCommon.fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding]; | 
|  | 126 | } | 
|  | 127 | int localCoordAttributeIndex() const { | 
|  | 128 | return fCommon.fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttribBinding]; | 
|  | 129 | } | 
|  | 130 | int colorVertexAttributeIndex() const { | 
|  | 131 | return fCommon.fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBinding]; | 
|  | 132 | } | 
|  | 133 | int coverageVertexAttributeIndex() const { | 
|  | 134 | return fCommon.fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribBinding]; | 
|  | 135 | } | 
|  | 136 |  | 
|  | 137 | bool hasLocalCoordAttribute() const { | 
|  | 138 | return -1 != fCommon.fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttribBinding]; | 
|  | 139 | } | 
|  | 140 | bool hasColorVertexAttribute() const { | 
|  | 141 | return -1 != fCommon.fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBinding]; | 
|  | 142 | } | 
|  | 143 | bool hasCoverageVertexAttribute() const { | 
|  | 144 | return -1 != fCommon.fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribBinding]; | 
|  | 145 | } | 
|  | 146 |  | 
| commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 147 | bool validateVertexAttribs() const; | 
|  | 148 |  | 
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 149 | /** | 
| bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 150 | * Helper to save/restore vertex attribs | 
|  | 151 | */ | 
|  | 152 | class AutoVertexAttribRestore { | 
|  | 153 | public: | 
|  | 154 | AutoVertexAttribRestore(GrDrawState* drawState) { | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 155 | SkASSERT(NULL != drawState); | 
| bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 156 | fDrawState = drawState; | 
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 157 | fVAPtr = drawState->fCommon.fVAPtr; | 
|  | 158 | fVACount = drawState->fCommon.fVACount; | 
| bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 159 | fDrawState->setDefaultVertexAttribs(); | 
|  | 160 | } | 
|  | 161 |  | 
|  | 162 | ~AutoVertexAttribRestore(){ | 
| commit-bot@chromium.org | fe070ba | 2013-10-16 14:43:12 +0000 | [diff] [blame] | 163 | fDrawState->setVertexAttribs(fVAPtr, fVACount); | 
| bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 164 | } | 
|  | 165 |  | 
|  | 166 | private: | 
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 167 | GrDrawState*          fDrawState; | 
|  | 168 | const GrVertexAttrib* fVAPtr; | 
|  | 169 | int                   fVACount; | 
| bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 170 | }; | 
|  | 171 |  | 
|  | 172 | /** | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 173 | * Accessing positions, local coords, or colors, of a vertex within an array is a hassle | 
|  | 174 | * involving casts and simple math. These helpers exist to keep GrDrawTarget clients' code a bit | 
|  | 175 | * nicer looking. | 
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 176 | */ | 
|  | 177 |  | 
|  | 178 | /** | 
|  | 179 | * Gets a pointer to a GrPoint of a vertex's position or texture | 
|  | 180 | * coordinate. | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 181 | * @param vertices      the vertex array | 
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 182 | * @param vertexIndex   the index of the vertex in the array | 
|  | 183 | * @param vertexSize    the size of each vertex in the array | 
|  | 184 | * @param offset        the offset in bytes of the vertex component. | 
|  | 185 | *                      Defaults to zero (corresponding to vertex position) | 
|  | 186 | * @return pointer to the vertex component as a GrPoint | 
|  | 187 | */ | 
|  | 188 | static GrPoint* GetVertexPoint(void* vertices, | 
|  | 189 | int vertexIndex, | 
|  | 190 | int vertexSize, | 
|  | 191 | int offset = 0) { | 
|  | 192 | intptr_t start = GrTCast<intptr_t>(vertices); | 
|  | 193 | return GrTCast<GrPoint*>(start + offset + | 
|  | 194 | vertexIndex * vertexSize); | 
|  | 195 | } | 
|  | 196 | static const GrPoint* GetVertexPoint(const void* vertices, | 
|  | 197 | int vertexIndex, | 
|  | 198 | int vertexSize, | 
|  | 199 | int offset = 0) { | 
|  | 200 | intptr_t start = GrTCast<intptr_t>(vertices); | 
|  | 201 | return GrTCast<const GrPoint*>(start + offset + | 
|  | 202 | vertexIndex * vertexSize); | 
|  | 203 | } | 
|  | 204 |  | 
|  | 205 | /** | 
|  | 206 | * Gets a pointer to a GrColor inside a vertex within a vertex array. | 
|  | 207 | * @param vertices      the vetex array | 
|  | 208 | * @param vertexIndex   the index of the vertex in the array | 
|  | 209 | * @param vertexSize    the size of each vertex in the array | 
|  | 210 | * @param offset        the offset in bytes of the vertex color | 
|  | 211 | * @return pointer to the vertex component as a GrColor | 
|  | 212 | */ | 
|  | 213 | static GrColor* GetVertexColor(void* vertices, | 
|  | 214 | int vertexIndex, | 
|  | 215 | int vertexSize, | 
|  | 216 | int offset) { | 
|  | 217 | intptr_t start = GrTCast<intptr_t>(vertices); | 
|  | 218 | return GrTCast<GrColor*>(start + offset + | 
|  | 219 | vertexIndex * vertexSize); | 
|  | 220 | } | 
|  | 221 | static const GrColor* GetVertexColor(const void* vertices, | 
|  | 222 | int vertexIndex, | 
|  | 223 | int vertexSize, | 
|  | 224 | int offset) { | 
|  | 225 | const intptr_t start = GrTCast<intptr_t>(vertices); | 
|  | 226 | return GrTCast<const GrColor*>(start + offset + | 
|  | 227 | vertexIndex * vertexSize); | 
|  | 228 | } | 
|  | 229 |  | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 230 | /// @} | 
|  | 231 |  | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 232 | /** | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 233 | * Determines whether src alpha is guaranteed to be one for all src pixels | 
|  | 234 | */ | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 235 | bool srcAlphaWillBeOne() const; | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 236 |  | 
|  | 237 | /** | 
|  | 238 | * Determines whether the output coverage is guaranteed to be one for all pixels hit by a draw. | 
|  | 239 | */ | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 240 | bool hasSolidCoverage() const; | 
| jvanverth@google.com | cc78238 | 2013-01-28 20:39:48 +0000 | [diff] [blame] | 241 |  | 
|  | 242 | /// @} | 
|  | 243 |  | 
|  | 244 | /////////////////////////////////////////////////////////////////////////// | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 245 | /// @name Color | 
|  | 246 | //// | 
|  | 247 |  | 
|  | 248 | /** | 
|  | 249 | *  Sets color for next draw to a premultiplied-alpha color. | 
|  | 250 | * | 
|  | 251 | *  @param color    the color to set. | 
|  | 252 | */ | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 253 | void setColor(GrColor color) { fCommon.fColor = color; } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 254 |  | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 255 | GrColor getColor() const { return fCommon.fColor; } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 256 |  | 
|  | 257 | /** | 
|  | 258 | *  Sets the color to be used for the next draw to be | 
|  | 259 | *  (r,g,b,a) = (alpha, alpha, alpha, alpha). | 
|  | 260 | * | 
|  | 261 | *  @param alpha The alpha value to set as the color. | 
|  | 262 | */ | 
|  | 263 | void setAlpha(uint8_t a) { | 
|  | 264 | this->setColor((a << 24) | (a << 16) | (a << 8) | a); | 
|  | 265 | } | 
|  | 266 |  | 
|  | 267 | /** | 
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 268 | * Constructor sets the color to be 'color' which is undone by the destructor. | 
|  | 269 | */ | 
| commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 270 | class AutoColorRestore : public ::SkNoncopyable { | 
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 271 | public: | 
| sugoi@google.com | 66a58ac | 2013-03-05 20:40:52 +0000 | [diff] [blame] | 272 | AutoColorRestore() : fDrawState(NULL), fOldColor(0) {} | 
| bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 273 |  | 
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 274 | AutoColorRestore(GrDrawState* drawState, GrColor color) { | 
| bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 275 | fDrawState = NULL; | 
|  | 276 | this->set(drawState, color); | 
|  | 277 | } | 
|  | 278 |  | 
|  | 279 | void reset() { | 
|  | 280 | if (NULL != fDrawState) { | 
|  | 281 | fDrawState->setColor(fOldColor); | 
|  | 282 | fDrawState = NULL; | 
|  | 283 | } | 
|  | 284 | } | 
|  | 285 |  | 
|  | 286 | void set(GrDrawState* drawState, GrColor color) { | 
|  | 287 | this->reset(); | 
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 288 | fDrawState = drawState; | 
|  | 289 | fOldColor = fDrawState->getColor(); | 
|  | 290 | fDrawState->setColor(color); | 
|  | 291 | } | 
| bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 292 |  | 
|  | 293 | ~AutoColorRestore() { this->reset(); } | 
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 294 | private: | 
|  | 295 | GrDrawState*    fDrawState; | 
|  | 296 | GrColor         fOldColor; | 
|  | 297 | }; | 
|  | 298 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 299 | /// @} | 
|  | 300 |  | 
|  | 301 | /////////////////////////////////////////////////////////////////////////// | 
| bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 302 | /// @name Coverage | 
|  | 303 | //// | 
|  | 304 |  | 
|  | 305 | /** | 
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 306 | * 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] | 307 | * initial value (after construction or reset()) is 0xff. The constant | 
|  | 308 | * coverage is ignored when per-vertex coverage is provided. | 
|  | 309 | */ | 
|  | 310 | void setCoverage(uint8_t coverage) { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 311 | fCommon.fCoverage = GrColorPackRGBA(coverage, coverage, coverage, coverage); | 
| bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 312 | } | 
|  | 313 |  | 
|  | 314 | /** | 
|  | 315 | * Version of above that specifies 4 channel per-vertex color. The value | 
|  | 316 | * should be premultiplied. | 
|  | 317 | */ | 
|  | 318 | void setCoverage4(GrColor coverage) { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 319 | fCommon.fCoverage = coverage; | 
| bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 320 | } | 
|  | 321 |  | 
|  | 322 | GrColor getCoverage() const { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 323 | return fCommon.fCoverage; | 
| bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 324 | } | 
|  | 325 |  | 
|  | 326 | /// @} | 
|  | 327 |  | 
|  | 328 | /////////////////////////////////////////////////////////////////////////// | 
| bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 329 | /// @name Effect Stages | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 330 | /// Each stage hosts a GrEffect. The effect produces an output color or coverage in the fragment | 
|  | 331 | /// shader. Its inputs are the output from the previous stage as well as some variables | 
|  | 332 | /// available to it in the fragment and vertex shader (e.g. the vertex position, the dst color, | 
|  | 333 | /// the fragment position, local coordinates). | 
|  | 334 | /// | 
|  | 335 | /// The stages are divided into two sets, color-computing and coverage-computing. The final | 
|  | 336 | /// color stage produces the final pixel color. The coverage-computing stages function exactly | 
|  | 337 | /// as the color-computing but the output of the final coverage stage is treated as a fractional | 
|  | 338 | /// pixel coverage rather than as input to the src/dst color blend step. | 
|  | 339 | /// | 
|  | 340 | /// The input color to the first color-stage is either the constant color or interpolated | 
|  | 341 | /// per-vertex colors. The input to the first coverage stage is either a constant coverage | 
|  | 342 | /// (usually full-coverage) or interpolated per-vertex coverage. | 
|  | 343 | /// | 
|  | 344 | /// See the documentation of kCoverageDrawing_StateBit for information about disabling the | 
|  | 345 | /// the color / coverage distinction. | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 346 | //// | 
|  | 347 |  | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 348 | const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) { | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 349 | SkASSERT(NULL != effect); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 350 | SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, attr1)); | 
| jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 351 | return effect; | 
|  | 352 | } | 
| skia.committer@gmail.com | 01c34ee | 2013-03-20 07:01:02 +0000 | [diff] [blame] | 353 |  | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 354 | const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) { | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 355 | SkASSERT(NULL != effect); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 356 | SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); | 
| bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 357 | return effect; | 
|  | 358 | } | 
|  | 359 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 360 | /** | 
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 361 | * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates. | 
| tomhudson@google.com | 1e8f016 | 2012-07-20 16:25:18 +0000 | [diff] [blame] | 362 | */ | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 363 | void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { | 
| bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 364 | GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 365 | this->addColorEffect(effect)->unref(); | 
| bsalomon@google.com | dfdb7e5 | 2012-10-16 15:19:45 +0000 | [diff] [blame] | 366 | } | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 367 |  | 
|  | 368 | void addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix) { | 
|  | 369 | GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix); | 
|  | 370 | this->addCoverageEffect(effect)->unref(); | 
|  | 371 | } | 
|  | 372 |  | 
|  | 373 | void addColorTextureEffect(GrTexture* texture, | 
|  | 374 | const SkMatrix& matrix, | 
|  | 375 | const GrTextureParams& params) { | 
| bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 376 | GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 377 | this->addColorEffect(effect)->unref(); | 
| bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 378 | } | 
|  | 379 |  | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 380 | void addCoverageTextureEffect(GrTexture* texture, | 
|  | 381 | const SkMatrix& matrix, | 
|  | 382 | const GrTextureParams& params) { | 
|  | 383 | GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params); | 
|  | 384 | this->addCoverageEffect(effect)->unref(); | 
| commit-bot@chromium.org | ff6ea26 | 2013-03-12 12:26:08 +0000 | [diff] [blame] | 385 | } | 
| tomhudson@google.com | 676e660 | 2012-07-10 17:21:48 +0000 | [diff] [blame] | 386 |  | 
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 387 | /** | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 388 | * When this object is destroyed it will remove any effects from the draw state that were added | 
|  | 389 | * after its constructor. | 
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 390 | */ | 
| commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 391 | class AutoRestoreEffects : public ::SkNoncopyable { | 
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 392 | public: | 
| bsalomon@google.com | 2fad5a8 | 2013-06-13 19:47:23 +0000 | [diff] [blame] | 393 | AutoRestoreEffects() : fDrawState(NULL), fColorEffectCnt(0), fCoverageEffectCnt(0) {} | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 394 |  | 
| skia.committer@gmail.com | 5c493d5 | 2013-06-14 07:00:49 +0000 | [diff] [blame] | 395 | AutoRestoreEffects(GrDrawState* ds) : fDrawState(NULL), fColorEffectCnt(0), fCoverageEffectCnt(0) { | 
|  | 396 | this->set(ds); | 
| robertphillips@google.com | f09b87d | 2013-06-13 20:06:44 +0000 | [diff] [blame] | 397 | } | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 398 |  | 
|  | 399 | ~AutoRestoreEffects() { this->set(NULL); } | 
|  | 400 |  | 
|  | 401 | void set(GrDrawState* ds) { | 
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 402 | if (NULL != fDrawState) { | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 403 | int n = fDrawState->fColorStages.count() - fColorEffectCnt; | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 404 | SkASSERT(n >= 0); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 405 | fDrawState->fColorStages.pop_back_n(n); | 
|  | 406 | n = fDrawState->fCoverageStages.count() - fCoverageEffectCnt; | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 407 | SkASSERT(n >= 0); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 408 | fDrawState->fCoverageStages.pop_back_n(n); | 
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 409 | SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;) | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 410 | } | 
|  | 411 | fDrawState = ds; | 
|  | 412 | if (NULL != ds) { | 
|  | 413 | fColorEffectCnt = ds->fColorStages.count(); | 
|  | 414 | fCoverageEffectCnt = ds->fCoverageStages.count(); | 
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 415 | SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;) | 
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 416 | } | 
|  | 417 | } | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 418 |  | 
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 419 | private: | 
|  | 420 | GrDrawState* fDrawState; | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 421 | int fColorEffectCnt; | 
|  | 422 | int fCoverageEffectCnt; | 
| robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 423 | }; | 
|  | 424 |  | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 425 | int numColorStages() const { return fColorStages.count(); } | 
|  | 426 | int numCoverageStages() const { return fCoverageStages.count(); } | 
|  | 427 | int numTotalStages() const { return this->numColorStages() + this->numCoverageStages(); } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 428 |  | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 429 | const GrEffectStage& getColorStage(int stageIdx) const { return fColorStages[stageIdx]; } | 
|  | 430 | const GrEffectStage& getCoverageStage(int stageIdx) const { return fCoverageStages[stageIdx]; } | 
| skia.committer@gmail.com | 05a2ee0 | 2013-04-02 07:01:34 +0000 | [diff] [blame] | 431 |  | 
| commit-bot@chromium.org | bb5c465 | 2013-04-01 12:49:31 +0000 | [diff] [blame] | 432 | /** | 
|  | 433 | * Checks whether any of the effects will read the dst pixel color. | 
|  | 434 | */ | 
| bsalomon@google.com | d09ab84 | 2013-05-15 17:30:26 +0000 | [diff] [blame] | 435 | bool willEffectReadDstColor() const; | 
| reed@google.com | 67e7cde | 2013-03-20 17:47:16 +0000 | [diff] [blame] | 436 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 437 | /// @} | 
|  | 438 |  | 
|  | 439 | /////////////////////////////////////////////////////////////////////////// | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 440 | /// @name Blending | 
|  | 441 | //// | 
|  | 442 |  | 
|  | 443 | /** | 
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 444 | * Sets the blending function coefficients. | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 445 | * | 
|  | 446 | * The blend function will be: | 
|  | 447 | *    D' = sat(S*srcCoef + D*dstCoef) | 
|  | 448 | * | 
|  | 449 | *   where D is the existing destination color, S is the incoming source | 
|  | 450 | *   color, and D' is the new destination color that will be written. sat() | 
|  | 451 | *   is the saturation function. | 
|  | 452 | * | 
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 453 | * @param srcCoef coefficient applied to the src color. | 
|  | 454 | * @param dstCoef coefficient applied to the dst color. | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 455 | */ | 
|  | 456 | void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 457 | fCommon.fSrcBlend = srcCoeff; | 
|  | 458 | fCommon.fDstBlend = dstCoeff; | 
| commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 459 | #ifdef SK_DEBUG | 
| commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 460 | if (GrBlendCoeffRefsDst(dstCoeff)) { | 
|  | 461 | 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] | 462 | } | 
| commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 463 | if (GrBlendCoeffRefsSrc(srcCoeff)) { | 
|  | 464 | 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] | 465 | } | 
|  | 466 | #endif | 
|  | 467 | } | 
|  | 468 |  | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 469 | GrBlendCoeff getSrcBlendCoeff() const { return fCommon.fSrcBlend; } | 
|  | 470 | GrBlendCoeff getDstBlendCoeff() const { return fCommon.fDstBlend; } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 471 |  | 
|  | 472 | void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff, | 
|  | 473 | GrBlendCoeff* dstBlendCoeff) const { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 474 | *srcBlendCoeff = fCommon.fSrcBlend; | 
|  | 475 | *dstBlendCoeff = fCommon.fDstBlend; | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 476 | } | 
|  | 477 |  | 
|  | 478 | /** | 
|  | 479 | * Sets the blending function constant referenced by the following blending | 
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 480 | * coefficients: | 
| bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 481 | *      kConstC_GrBlendCoeff | 
|  | 482 | *      kIConstC_GrBlendCoeff | 
|  | 483 | *      kConstA_GrBlendCoeff | 
|  | 484 | *      kIConstA_GrBlendCoeff | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 485 | * | 
|  | 486 | * @param constant the constant to set | 
|  | 487 | */ | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 488 | void setBlendConstant(GrColor constant) { fCommon.fBlendConstant = constant; } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 489 |  | 
|  | 490 | /** | 
|  | 491 | * Retrieves the last value set by setBlendConstant() | 
|  | 492 | * @return the blending constant value | 
|  | 493 | */ | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 494 | GrColor getBlendConstant() const { return fCommon.fBlendConstant; } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 495 |  | 
| bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 496 | /** | 
|  | 497 | * Determines whether multiplying the computed per-pixel color by the pixel's fractional | 
|  | 498 | * coverage before the blend will give the correct final destination color. In general it | 
|  | 499 | * will not as coverage is applied after blending. | 
|  | 500 | */ | 
|  | 501 | bool canTweakAlphaForCoverage() const; | 
|  | 502 |  | 
|  | 503 | /** | 
|  | 504 | * Optimizations for blending / coverage to that can be applied based on the current state. | 
|  | 505 | */ | 
|  | 506 | enum BlendOptFlags { | 
|  | 507 | /** | 
|  | 508 | * No optimization | 
|  | 509 | */ | 
|  | 510 | kNone_BlendOpt                  = 0, | 
|  | 511 | /** | 
|  | 512 | * Don't draw at all | 
|  | 513 | */ | 
|  | 514 | kSkipDraw_BlendOptFlag          = 0x1, | 
|  | 515 | /** | 
|  | 516 | * Emit the src color, disable HW blending (replace dst with src) | 
|  | 517 | */ | 
|  | 518 | kDisableBlend_BlendOptFlag      = 0x2, | 
|  | 519 | /** | 
|  | 520 | * The coverage value does not have to be computed separately from alpha, the the output | 
|  | 521 | * color can be the modulation of the two. | 
|  | 522 | */ | 
|  | 523 | kCoverageAsAlpha_BlendOptFlag   = 0x4, | 
|  | 524 | /** | 
|  | 525 | * Instead of emitting a src color, emit coverage in the alpha channel and r,g,b are | 
|  | 526 | * "don't cares". | 
|  | 527 | */ | 
|  | 528 | kEmitCoverage_BlendOptFlag      = 0x8, | 
|  | 529 | /** | 
|  | 530 | * Emit transparent black instead of the src color, no need to compute coverage. | 
|  | 531 | */ | 
|  | 532 | kEmitTransBlack_BlendOptFlag    = 0x10, | 
|  | 533 | }; | 
|  | 534 | GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags); | 
|  | 535 |  | 
|  | 536 | /** | 
|  | 537 | * Determines what optimizations can be applied based on the blend. The coefficients may have | 
|  | 538 | * to be tweaked in order for the optimization to work. srcCoeff and dstCoeff are optional | 
|  | 539 | * params that receive the tweaked coefficients. Normally the function looks at the current | 
|  | 540 | * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively | 
|  | 541 | * determine the blend optimizations that would be used if there was partial pixel coverage. | 
|  | 542 | * | 
|  | 543 | * Subclasses of GrDrawTarget that actually draw (as opposed to those that just buffer for | 
|  | 544 | * playback) must call this function and respect the flags that replace the output color. | 
|  | 545 | */ | 
|  | 546 | BlendOptFlags getBlendOpts(bool forceCoverage = false, | 
|  | 547 | GrBlendCoeff* srcCoeff = NULL, | 
|  | 548 | GrBlendCoeff* dstCoeff = NULL) const; | 
|  | 549 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 550 | /// @} | 
|  | 551 |  | 
|  | 552 | /////////////////////////////////////////////////////////////////////////// | 
|  | 553 | /// @name View Matrix | 
|  | 554 | //// | 
|  | 555 |  | 
|  | 556 | /** | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 557 | * Sets the view matrix to identity and updates any installed effects to compensate for the | 
|  | 558 | * coord system change. | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 559 | */ | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 560 | bool setIdentityViewMatrix(); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 561 |  | 
|  | 562 | /** | 
|  | 563 | * Retrieves the current view matrix | 
|  | 564 | * @return the current view matrix. | 
|  | 565 | */ | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 566 | const SkMatrix& getViewMatrix() const { return fCommon.fViewMatrix; } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 567 |  | 
|  | 568 | /** | 
|  | 569 | *  Retrieves the inverse of the current view matrix. | 
|  | 570 | * | 
|  | 571 | *  If the current view matrix is invertible, return true, and if matrix | 
|  | 572 | *  is non-null, copy the inverse into it. If the current view matrix is | 
|  | 573 | *  non-invertible, return false and ignore the matrix parameter. | 
|  | 574 | * | 
|  | 575 | * @param matrix if not null, will receive a copy of the current inverse. | 
|  | 576 | */ | 
| bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 577 | bool getViewInverse(SkMatrix* matrix) const { | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 578 | // TODO: determine whether we really need to leave matrix unmodified | 
|  | 579 | // at call sites when inversion fails. | 
| bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 580 | SkMatrix inverse; | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 581 | if (fCommon.fViewMatrix.invert(&inverse)) { | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 582 | if (matrix) { | 
|  | 583 | *matrix = inverse; | 
|  | 584 | } | 
|  | 585 | return true; | 
|  | 586 | } | 
|  | 587 | return false; | 
|  | 588 | } | 
|  | 589 |  | 
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 590 | //////////////////////////////////////////////////////////////////////////// | 
|  | 591 |  | 
|  | 592 | /** | 
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 593 | * 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] | 594 | * 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] | 595 | */ | 
| commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 596 | class AutoViewMatrixRestore : public ::SkNoncopyable { | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 597 | public: | 
|  | 598 | AutoViewMatrixRestore() : fDrawState(NULL) {} | 
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 599 |  | 
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 600 | AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) { | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 601 | fDrawState = NULL; | 
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 602 | this->set(ds, preconcatMatrix); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 603 | } | 
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 604 |  | 
|  | 605 | ~AutoViewMatrixRestore() { this->restore(); } | 
|  | 606 |  | 
| bsalomon@google.com | a834746 | 2012-10-08 18:59:39 +0000 | [diff] [blame] | 607 | /** | 
|  | 608 | * Can be called prior to destructor to restore the original matrix. | 
|  | 609 | */ | 
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 610 | void restore(); | 
| skia.committer@gmail.com | f467ce7 | 2012-10-09 02:01:37 +0000 | [diff] [blame] | 611 |  | 
| bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 612 | void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix); | 
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 613 |  | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 614 | /** Sets the draw state's matrix to identity. This can fail because the current view matrix | 
|  | 615 | is not invertible. */ | 
|  | 616 | bool setIdentity(GrDrawState* drawState); | 
| bsalomon@google.com | 2fdcdeb | 2012-10-08 17:15:55 +0000 | [diff] [blame] | 617 |  | 
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 618 | private: | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 619 | void doEffectCoordChanges(const SkMatrix& coordChangeMatrix); | 
|  | 620 |  | 
|  | 621 | GrDrawState*                                        fDrawState; | 
|  | 622 | SkMatrix                                            fViewMatrix; | 
|  | 623 | int                                                 fNumColorStages; | 
|  | 624 | SkAutoSTArray<8, GrEffectStage::SavedCoordChange>   fSavedCoordChanges; | 
| bsalomon@google.com | 5b3e890 | 2012-10-05 20:13:28 +0000 | [diff] [blame] | 625 | }; | 
|  | 626 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 627 | /// @} | 
|  | 628 |  | 
|  | 629 | /////////////////////////////////////////////////////////////////////////// | 
|  | 630 | /// @name Render Target | 
|  | 631 | //// | 
|  | 632 |  | 
|  | 633 | /** | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 634 | * Sets the render-target used at the next drawing call | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 635 | * | 
|  | 636 | * @param target  The render target to set. | 
|  | 637 | */ | 
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 638 | void setRenderTarget(GrRenderTarget* target) { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 639 | fRenderTarget.reset(SkSafeRef(target)); | 
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 640 | } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 641 |  | 
|  | 642 | /** | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 643 | * Retrieves the currently set render-target. | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 644 | * | 
|  | 645 | * @return    The currently set render target. | 
|  | 646 | */ | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 647 | const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } | 
|  | 648 | GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 649 |  | 
| commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 650 | class AutoRenderTargetRestore : public ::SkNoncopyable { | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 651 | public: | 
| bsalomon@google.com | cadbcb8 | 2012-01-06 19:22:11 +0000 | [diff] [blame] | 652 | AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 653 | AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { | 
|  | 654 | fDrawState = NULL; | 
| robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 655 | fSavedTarget = NULL; | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 656 | this->set(ds, newTarget); | 
|  | 657 | } | 
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 658 | ~AutoRenderTargetRestore() { this->restore(); } | 
|  | 659 |  | 
|  | 660 | void restore() { | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 661 | if (NULL != fDrawState) { | 
|  | 662 | fDrawState->setRenderTarget(fSavedTarget); | 
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 663 | fDrawState = NULL; | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 664 | } | 
| commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 665 | SkSafeSetNull(fSavedTarget); | 
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 666 | } | 
|  | 667 |  | 
|  | 668 | void set(GrDrawState* ds, GrRenderTarget* newTarget) { | 
|  | 669 | this->restore(); | 
|  | 670 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 671 | if (NULL != ds) { | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 672 | SkASSERT(NULL == fSavedTarget); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 673 | fSavedTarget = ds->getRenderTarget(); | 
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 674 | SkSafeRef(fSavedTarget); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 675 | ds->setRenderTarget(newTarget); | 
| robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 676 | fDrawState = ds; | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 677 | } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 678 | } | 
|  | 679 | private: | 
|  | 680 | GrDrawState* fDrawState; | 
|  | 681 | GrRenderTarget* fSavedTarget; | 
|  | 682 | }; | 
|  | 683 |  | 
|  | 684 | /// @} | 
|  | 685 |  | 
|  | 686 | /////////////////////////////////////////////////////////////////////////// | 
|  | 687 | /// @name Stencil | 
|  | 688 | //// | 
|  | 689 |  | 
|  | 690 | /** | 
|  | 691 | * Sets the stencil settings to use for the next draw. | 
|  | 692 | * Changing the clip has the side-effect of possibly zeroing | 
|  | 693 | * out the client settable stencil bits. So multipass algorithms | 
|  | 694 | * using stencil should not change the clip between passes. | 
|  | 695 | * @param settings  the stencil settings to use. | 
|  | 696 | */ | 
|  | 697 | void setStencil(const GrStencilSettings& settings) { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 698 | fCommon.fStencilSettings = settings; | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 699 | } | 
|  | 700 |  | 
|  | 701 | /** | 
|  | 702 | * Shortcut to disable stencil testing and ops. | 
|  | 703 | */ | 
|  | 704 | void disableStencil() { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 705 | fCommon.fStencilSettings.setDisabled(); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 706 | } | 
|  | 707 |  | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 708 | const GrStencilSettings& getStencil() const { return fCommon.fStencilSettings; } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 709 |  | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 710 | GrStencilSettings* stencil() { return &fCommon.fStencilSettings; } | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 711 |  | 
|  | 712 | /// @} | 
|  | 713 |  | 
|  | 714 | /////////////////////////////////////////////////////////////////////////// | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 715 | /// @name State Flags | 
|  | 716 | //// | 
| tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 717 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 718 | /** | 
|  | 719 | *  Flags that affect rendering. Controlled using enable/disableState(). All | 
|  | 720 | *  default to disabled. | 
|  | 721 | */ | 
|  | 722 | enum StateBits { | 
|  | 723 | /** | 
|  | 724 | * Perform dithering. TODO: Re-evaluate whether we need this bit | 
|  | 725 | */ | 
|  | 726 | kDither_StateBit        = 0x01, | 
|  | 727 | /** | 
| bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 728 | * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target, | 
|  | 729 | * or smooth-line rendering if a line primitive is drawn and line smoothing is supported by | 
|  | 730 | * the 3D API. | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 731 | */ | 
|  | 732 | kHWAntialias_StateBit   = 0x02, | 
|  | 733 | /** | 
|  | 734 | * Draws will respect the clip, otherwise the clip is ignored. | 
|  | 735 | */ | 
|  | 736 | kClip_StateBit          = 0x04, | 
|  | 737 | /** | 
|  | 738 | * Disables writing to the color buffer. Useful when performing stencil | 
|  | 739 | * operations. | 
|  | 740 | */ | 
|  | 741 | kNoColorWrites_StateBit = 0x08, | 
| bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 742 |  | 
| bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 743 | /** | 
|  | 744 | * Usually coverage is applied after color blending. The color is blended using the coeffs | 
|  | 745 | * specified by setBlendFunc(). The blended color is then combined with dst using coeffs | 
|  | 746 | * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing a coverage mask. In | 
|  | 747 | * this case there is no distinction between coverage and color and the caller needs direct | 
|  | 748 | * control over the blend coeffs. When set, there will be a single blend step controlled by | 
|  | 749 | * setBlendFunc() which will use coverage*color as the src color. | 
|  | 750 | */ | 
|  | 751 | kCoverageDrawing_StateBit = 0x10, | 
|  | 752 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 753 | // Users of the class may add additional bits to the vector | 
|  | 754 | kDummyStateBit, | 
|  | 755 | kLastPublicStateBit = kDummyStateBit-1, | 
|  | 756 | }; | 
|  | 757 |  | 
|  | 758 | void resetStateFlags() { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 759 | fCommon.fFlagBits = 0; | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 760 | } | 
|  | 761 |  | 
|  | 762 | /** | 
|  | 763 | * Enable render state settings. | 
|  | 764 | * | 
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 765 | * @param stateBits bitfield of StateBits specifying the states to enable | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 766 | */ | 
|  | 767 | void enableState(uint32_t stateBits) { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 768 | fCommon.fFlagBits |= stateBits; | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 769 | } | 
|  | 770 |  | 
|  | 771 | /** | 
|  | 772 | * Disable render state settings. | 
|  | 773 | * | 
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 774 | * @param stateBits bitfield of StateBits specifying the states to disable | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 775 | */ | 
|  | 776 | void disableState(uint32_t stateBits) { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 777 | fCommon.fFlagBits &= ~(stateBits); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 778 | } | 
|  | 779 |  | 
| bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 780 | /** | 
|  | 781 | * Enable or disable stateBits based on a boolean. | 
|  | 782 | * | 
| bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 783 | * @param stateBits bitfield of StateBits to enable or disable | 
| bsalomon@google.com | d5d69ff | 2012-10-04 19:42:00 +0000 | [diff] [blame] | 784 | * @param enable    if true enable stateBits, otherwise disable | 
|  | 785 | */ | 
|  | 786 | void setState(uint32_t stateBits, bool enable) { | 
|  | 787 | if (enable) { | 
|  | 788 | this->enableState(stateBits); | 
|  | 789 | } else { | 
|  | 790 | this->disableState(stateBits); | 
|  | 791 | } | 
|  | 792 | } | 
|  | 793 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 794 | bool isDitherState() const { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 795 | return 0 != (fCommon.fFlagBits & kDither_StateBit); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 796 | } | 
|  | 797 |  | 
|  | 798 | bool isHWAntialiasState() const { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 799 | return 0 != (fCommon.fFlagBits & kHWAntialias_StateBit); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 800 | } | 
|  | 801 |  | 
|  | 802 | bool isClipState() const { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 803 | return 0 != (fCommon.fFlagBits & kClip_StateBit); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 804 | } | 
|  | 805 |  | 
|  | 806 | bool isColorWriteDisabled() const { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 807 | return 0 != (fCommon.fFlagBits & kNoColorWrites_StateBit); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 808 | } | 
|  | 809 |  | 
| bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 810 | bool isCoverageDrawing() const { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 811 | return 0 != (fCommon.fFlagBits & kCoverageDrawing_StateBit); | 
| bsalomon@google.com | cf939ae | 2012-12-13 19:59:23 +0000 | [diff] [blame] | 812 | } | 
|  | 813 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 814 | bool isStateFlagEnabled(uint32_t stateBit) const { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 815 | return 0 != (stateBit & fCommon.fFlagBits); | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 816 | } | 
|  | 817 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 818 | /// @} | 
|  | 819 |  | 
|  | 820 | /////////////////////////////////////////////////////////////////////////// | 
|  | 821 | /// @name Face Culling | 
|  | 822 | //// | 
|  | 823 |  | 
|  | 824 | enum DrawFace { | 
| bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 825 | kInvalid_DrawFace = -1, | 
|  | 826 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 827 | kBoth_DrawFace, | 
|  | 828 | kCCW_DrawFace, | 
|  | 829 | kCW_DrawFace, | 
|  | 830 | }; | 
|  | 831 |  | 
|  | 832 | /** | 
|  | 833 | * Controls whether clockwise, counterclockwise, or both faces are drawn. | 
|  | 834 | * @param face  the face(s) to draw. | 
|  | 835 | */ | 
|  | 836 | void setDrawFace(DrawFace face) { | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 837 | SkASSERT(kInvalid_DrawFace != face); | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 838 | fCommon.fDrawFace = face; | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 839 | } | 
|  | 840 |  | 
|  | 841 | /** | 
|  | 842 | * Gets whether the target is drawing clockwise, counterclockwise, | 
|  | 843 | * or both faces. | 
|  | 844 | * @return the current draw face(s). | 
|  | 845 | */ | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 846 | DrawFace getDrawFace() const { return fCommon.fDrawFace; } | 
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 847 |  | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 848 | /// @} | 
|  | 849 |  | 
|  | 850 | /////////////////////////////////////////////////////////////////////////// | 
| tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 851 |  | 
| bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 852 | bool operator ==(const GrDrawState& s) const { | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 853 | if (fRenderTarget.get() != s.fRenderTarget.get() || | 
|  | 854 | fColorStages.count() != s.fColorStages.count() || | 
|  | 855 | fCoverageStages.count() != s.fCoverageStages.count() || | 
|  | 856 | fCommon != s.fCommon) { | 
| bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 857 | return false; | 
|  | 858 | } | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 859 | for (int i = 0; i < fColorStages.count(); i++) { | 
|  | 860 | if (fColorStages[i] != s.fColorStages[i]) { | 
| bsalomon@google.com | f2f8fc3 | 2012-07-18 18:25:07 +0000 | [diff] [blame] | 861 | return false; | 
|  | 862 | } | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 863 | } | 
|  | 864 | for (int i = 0; i < fCoverageStages.count(); i++) { | 
|  | 865 | if (fCoverageStages[i] != s.fCoverageStages[i]) { | 
| bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 866 | return false; | 
|  | 867 | } | 
|  | 868 | } | 
| bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 869 | return true; | 
|  | 870 | } | 
|  | 871 | bool operator !=(const GrDrawState& s) const { return !(*this == s); } | 
|  | 872 |  | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 873 | GrDrawState& operator= (const GrDrawState& s) { | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 874 | SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 875 | this->setRenderTarget(s.fRenderTarget.get()); | 
|  | 876 | fCommon = s.fCommon; | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 877 | fColorStages = s.fColorStages; | 
|  | 878 | fCoverageStages = s.fCoverageStages; | 
| bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 879 | return *this; | 
|  | 880 | } | 
|  | 881 |  | 
|  | 882 | private: | 
| bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 883 |  | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 884 | void onReset(const SkMatrix* initialViewMatrix) { | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 885 | SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages()); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 886 | fColorStages.reset(); | 
|  | 887 | fCoverageStages.reset(); | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 888 |  | 
|  | 889 | fRenderTarget.reset(NULL); | 
|  | 890 |  | 
|  | 891 | this->setDefaultVertexAttribs(); | 
|  | 892 |  | 
|  | 893 | fCommon.fColor = 0xffffffff; | 
|  | 894 | if (NULL == initialViewMatrix) { | 
|  | 895 | fCommon.fViewMatrix.reset(); | 
|  | 896 | } else { | 
|  | 897 | fCommon.fViewMatrix = *initialViewMatrix; | 
|  | 898 | } | 
|  | 899 | fCommon.fSrcBlend = kOne_GrBlendCoeff; | 
|  | 900 | fCommon.fDstBlend = kZero_GrBlendCoeff; | 
|  | 901 | fCommon.fBlendConstant = 0x0; | 
|  | 902 | fCommon.fFlagBits = 0x0; | 
|  | 903 | fCommon.fStencilSettings.setDisabled(); | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 904 | fCommon.fCoverage = 0xffffffff; | 
| bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 905 | fCommon.fDrawFace = kBoth_DrawFace; | 
|  | 906 | } | 
|  | 907 |  | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 908 | /** Fields that are identical in GrDrawState and GrDrawState::DeferredState. */ | 
|  | 909 | struct CommonState { | 
|  | 910 | // These fields are roughly sorted by decreasing likelihood of being different in op== | 
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 911 | GrColor               fColor; | 
|  | 912 | SkMatrix              fViewMatrix; | 
|  | 913 | GrBlendCoeff          fSrcBlend; | 
|  | 914 | GrBlendCoeff          fDstBlend; | 
|  | 915 | GrColor               fBlendConstant; | 
|  | 916 | uint32_t              fFlagBits; | 
|  | 917 | const GrVertexAttrib* fVAPtr; | 
|  | 918 | int                   fVACount; | 
|  | 919 | GrStencilSettings     fStencilSettings; | 
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 920 | GrColor               fCoverage; | 
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 921 | DrawFace              fDrawFace; | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 922 |  | 
|  | 923 | // This is simply a different representation of info in fVertexAttribs and thus does | 
|  | 924 | // not need to be compared in op==. | 
|  | 925 | int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt]; | 
|  | 926 |  | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 927 | bool operator== (const CommonState& other) const { | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 928 | bool result = fColor == other.fColor && | 
|  | 929 | fViewMatrix.cheapEqualTo(other.fViewMatrix) && | 
|  | 930 | fSrcBlend == other.fSrcBlend && | 
|  | 931 | fDstBlend == other.fDstBlend && | 
|  | 932 | fBlendConstant == other.fBlendConstant && | 
|  | 933 | fFlagBits == other.fFlagBits && | 
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 934 | fVACount == other.fVACount && | 
|  | 935 | !memcmp(fVAPtr, other.fVAPtr, fVACount * sizeof(GrVertexAttrib)) && | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 936 | fStencilSettings == other.fStencilSettings && | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 937 | fCoverage == other.fCoverage && | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 938 | fDrawFace == other.fDrawFace; | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 939 | SkASSERT(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices, | 
| jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 940 | other.fFixedFunctionVertexAttribIndices, | 
|  | 941 | sizeof(fFixedFunctionVertexAttribIndices))); | 
|  | 942 | return result; | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 943 | } | 
|  | 944 | bool operator!= (const CommonState& other) const { return !(*this == other); } | 
|  | 945 | }; | 
| bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 946 |  | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 947 | /** GrDrawState uses GrEffectStages to hold stage state which holds a ref on GrEffectRef. | 
|  | 948 | DeferredState must directly reference GrEffects, however. */ | 
|  | 949 | struct SavedEffectStage { | 
|  | 950 | SavedEffectStage() : fEffect(NULL) {} | 
|  | 951 | const GrEffect*                    fEffect; | 
|  | 952 | GrEffectStage::SavedCoordChange    fCoordChange; | 
|  | 953 | }; | 
|  | 954 |  | 
|  | 955 | public: | 
|  | 956 | /** | 
|  | 957 | * DeferredState contains all of the data of a GrDrawState but does not hold refs on GrResource | 
|  | 958 | * objects. Resources are allowed to hit zero ref count while in DeferredStates. Their internal | 
|  | 959 | * dispose mechanism returns them to the cache. This allows recycling resources through the | 
|  | 960 | * the cache while they are in a deferred draw queue. | 
|  | 961 | */ | 
|  | 962 | class DeferredState { | 
|  | 963 | public: | 
|  | 964 | DeferredState() : fRenderTarget(NULL) { | 
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 965 | SkDEBUGCODE(fInitialized = false;) | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 966 | } | 
|  | 967 | // TODO: Remove this when DeferredState no longer holds a ref to the RT | 
|  | 968 | ~DeferredState() { SkSafeUnref(fRenderTarget); } | 
|  | 969 |  | 
|  | 970 | void saveFrom(const GrDrawState& drawState) { | 
|  | 971 | fCommon = drawState.fCommon; | 
|  | 972 | // TODO: Here we will copy the GrRenderTarget pointer without taking a ref. | 
|  | 973 | fRenderTarget = drawState.fRenderTarget.get(); | 
|  | 974 | SkSafeRef(fRenderTarget); | 
|  | 975 | // Here we ref the effects directly rather than the effect-refs. TODO: When the effect- | 
|  | 976 | // ref gets fully unref'ed it will cause the underlying effect to unref its resources | 
|  | 977 | // and recycle them to the cache (if no one else is holding a ref to the resources). | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 978 | fStages.reset(drawState.fColorStages.count() + drawState.fCoverageStages.count()); | 
|  | 979 | fColorStageCnt = drawState.fColorStages.count(); | 
|  | 980 | for (int i = 0; i < fColorStageCnt; ++i) { | 
|  | 981 | fStages[i].saveFrom(drawState.fColorStages[i]); | 
|  | 982 | } | 
|  | 983 | for (int i = 0; i < drawState.fCoverageStages.count(); ++i) { | 
|  | 984 | fStages[i + fColorStageCnt].saveFrom(drawState.fCoverageStages[i]); | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 985 | } | 
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 986 | SkDEBUGCODE(fInitialized = true;) | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 987 | } | 
|  | 988 |  | 
|  | 989 | void restoreTo(GrDrawState* drawState) { | 
| tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 990 | SkASSERT(fInitialized); | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 991 | drawState->fCommon = fCommon; | 
|  | 992 | drawState->setRenderTarget(fRenderTarget); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 993 | // reinflate color/cov stage arrays. | 
| commit-bot@chromium.org | 2d3b492 | 2013-07-15 13:54:06 +0000 | [diff] [blame] | 994 | drawState->fColorStages.reset(); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 995 | for (int i = 0; i < fColorStageCnt; ++i) { | 
| commit-bot@chromium.org | 2d3b492 | 2013-07-15 13:54:06 +0000 | [diff] [blame] | 996 | SkNEW_APPEND_TO_TARRAY(&drawState->fColorStages, GrEffectStage, (fStages[i])); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 997 | } | 
|  | 998 | int coverageStageCnt = fStages.count() - fColorStageCnt; | 
| commit-bot@chromium.org | 2d3b492 | 2013-07-15 13:54:06 +0000 | [diff] [blame] | 999 | drawState->fCoverageStages.reset(); | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1000 | for (int i = 0; i < coverageStageCnt; ++i) { | 
| commit-bot@chromium.org | 2d3b492 | 2013-07-15 13:54:06 +0000 | [diff] [blame] | 1001 | SkNEW_APPEND_TO_TARRAY(&drawState->fCoverageStages, | 
|  | 1002 | GrEffectStage, (fStages[i + fColorStageCnt])); | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 1003 | } | 
|  | 1004 | } | 
|  | 1005 |  | 
|  | 1006 | bool isEqual(const GrDrawState& state) const { | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1007 | int numCoverageStages = fStages.count() - fColorStageCnt; | 
|  | 1008 | if (fRenderTarget != state.fRenderTarget.get() || | 
|  | 1009 | fColorStageCnt != state.fColorStages.count() || | 
|  | 1010 | numCoverageStages != state.fCoverageStages.count() || | 
|  | 1011 | fCommon != state.fCommon) { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 1012 | return false; | 
|  | 1013 | } | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1014 | bool explicitLocalCoords = state.hasLocalCoordAttribute(); | 
|  | 1015 | for (int i = 0; i < fColorStageCnt; ++i) { | 
|  | 1016 | if (!fStages[i].isEqual(state.fColorStages[i], explicitLocalCoords)) { | 
|  | 1017 | return false; | 
|  | 1018 | } | 
|  | 1019 | } | 
|  | 1020 | for (int i = 0; i < numCoverageStages; ++i) { | 
|  | 1021 | int s = fColorStageCnt + i; | 
|  | 1022 | if (!fStages[s].isEqual(state.fCoverageStages[i], explicitLocalCoords)) { | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 1023 | return false; | 
|  | 1024 | } | 
|  | 1025 | } | 
|  | 1026 | return true; | 
|  | 1027 | } | 
|  | 1028 |  | 
|  | 1029 | private: | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1030 | typedef SkAutoSTArray<8, GrEffectStage::DeferredStage> DeferredStageArray; | 
|  | 1031 |  | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 1032 | GrRenderTarget*                       fRenderTarget; | 
|  | 1033 | CommonState                           fCommon; | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1034 | int                                   fColorStageCnt; | 
|  | 1035 | DeferredStageArray                    fStages; | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 1036 |  | 
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 1037 | SkDEBUGCODE(bool fInitialized;) | 
| bsalomon@google.com | ca43208 | 2013-01-23 19:53:46 +0000 | [diff] [blame] | 1038 | }; | 
|  | 1039 |  | 
|  | 1040 | private: | 
| jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 1041 |  | 
| bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1042 | SkAutoTUnref<GrRenderTarget>        fRenderTarget; | 
|  | 1043 | CommonState                         fCommon; | 
|  | 1044 |  | 
|  | 1045 | typedef SkSTArray<4, GrEffectStage> EffectStageArray; | 
|  | 1046 | EffectStageArray                    fColorStages; | 
|  | 1047 | EffectStageArray                    fCoverageStages; | 
|  | 1048 |  | 
|  | 1049 | // Some of the auto restore objects assume that no effects are removed during their lifetime. | 
|  | 1050 | // This is used to assert that this condition holds. | 
| commit-bot@chromium.org | 1acc3d7 | 2013-09-06 23:13:05 +0000 | [diff] [blame] | 1051 | SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 
| bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 1052 |  | 
| robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 1053 | /** | 
|  | 1054 | *  Sets vertex attributes for next draw. | 
|  | 1055 | * | 
|  | 1056 | *  @param attribs    the array of vertex attributes to set. | 
|  | 1057 | *  @param count      the number of attributes being set, limited to kMaxVertexAttribCnt. | 
|  | 1058 | */ | 
|  | 1059 | void setVertexAttribs(const GrVertexAttrib attribs[], int count); | 
|  | 1060 |  | 
| commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 1061 | typedef SkRefCnt INHERITED; | 
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1062 | }; | 
|  | 1063 |  | 
| bsalomon@google.com | 2b44673 | 2013-02-12 16:47:41 +0000 | [diff] [blame] | 1064 | GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags); | 
|  | 1065 |  | 
| tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 1066 | #endif |