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 | |
| 11 | #include "GrColor.h" |
| 12 | #include "GrMatrix.h" |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 13 | #include "GrNoncopyable.h" |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 14 | #include "GrRefCnt.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 15 | #include "GrSamplerState.h" |
| 16 | #include "GrStencil.h" |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 17 | #include "GrTexture.h" |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 18 | #include "GrRenderTarget.h" |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 19 | |
| 20 | #include "SkXfermode.h" |
| 21 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 22 | |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 23 | class GrDrawState : public GrRefCnt { |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 24 | |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 25 | public: |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 26 | /** |
| 27 | * Number of texture stages. Each stage takes as input a color and |
| 28 | * 2D texture coordinates. The color input to the first enabled stage is the |
| 29 | * per-vertex color or the constant color (setColor/setAlpha) if there are |
| 30 | * no per-vertex colors. For subsequent stages the input color is the output |
| 31 | * color from the previous enabled stage. The output color of each stage is |
| 32 | * the input color modulated with the result of a texture lookup. Texture |
| 33 | * lookups are specified by a texture a sampler (setSamplerState). Texture |
| 34 | * coordinates for each stage come from the vertices based on a |
| 35 | * GrVertexLayout bitfield. The output fragment color is the output color of |
| 36 | * the last enabled stage. The presence or absence of texture coordinates |
| 37 | * for each stage in the vertex layout indicates whether a stage is enabled |
| 38 | * or not. |
robertphillips@google.com | bf5cad4 | 2012-05-10 12:40:40 +0000 | [diff] [blame] | 39 | * |
| 40 | * Stages 0 through GrPaint::kTotalStages-1 are reserved for setting up |
| 41 | * the draw (i.e., textures and filter masks). Stages GrPaint::kTotalStages |
| 42 | * through kNumStages-1 are earmarked for use by GrTextContext and |
| 43 | * GrPathRenderer-derived classes. |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 44 | */ |
| 45 | enum { |
robertphillips@google.com | ec05eaa | 2012-04-27 18:59:52 +0000 | [diff] [blame] | 46 | kNumStages = 4, |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 47 | kMaxTexCoords = kNumStages |
| 48 | }; |
| 49 | |
bsalomon@google.com | 39ee0ff | 2011-12-06 15:32:52 +0000 | [diff] [blame] | 50 | /** |
| 51 | * Bitfield used to indicate a set of stages. |
| 52 | */ |
| 53 | typedef uint32_t StageMask; |
| 54 | GR_STATIC_ASSERT(sizeof(StageMask)*8 >= GrDrawState::kNumStages); |
| 55 | |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 56 | GrDrawState() |
| 57 | : fRenderTarget(NULL) { |
| 58 | |
| 59 | for (int i = 0; i < kNumStages; ++i) { |
| 60 | fTextures[i] = NULL; |
| 61 | } |
| 62 | |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 63 | this->reset(); |
| 64 | } |
bsalomon@google.com | 46f7afb | 2012-01-18 19:51:55 +0000 | [diff] [blame] | 65 | |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 66 | GrDrawState(const GrDrawState& state) |
| 67 | : fRenderTarget(NULL) { |
| 68 | |
| 69 | for (int i = 0; i < kNumStages; ++i) { |
| 70 | fTextures[i] = NULL; |
| 71 | } |
| 72 | |
bsalomon@google.com | 46f7afb | 2012-01-18 19:51:55 +0000 | [diff] [blame] | 73 | *this = state; |
| 74 | } |
| 75 | |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 76 | virtual ~GrDrawState() { |
| 77 | this->releaseTextures(); |
| 78 | GrSafeSetNull(fRenderTarget); |
| 79 | } |
| 80 | |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 81 | /** |
| 82 | * Resets to the default state. Sampler states will not be modified. |
| 83 | */ |
| 84 | void reset() { |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 85 | |
| 86 | this->releaseTextures(); |
| 87 | GrSafeSetNull(fRenderTarget); |
| 88 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 89 | // make sure any pad is zero for memcmp |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 90 | // all GrDrawState members should default to something valid by the |
| 91 | // the memset except those initialized individually below. There should |
| 92 | // be no padding between the individually initialized members. |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 93 | memset(this->podStart(), 0, this->memsetSize()); |
| 94 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 95 | // pedantic assertion that our ptrs will |
| 96 | // be NULL (0 ptr is mem addr 0) |
| 97 | GrAssert((intptr_t)(void*)NULL == 0LL); |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 98 | GR_STATIC_ASSERT(0 == kBoth_DrawFace); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 99 | GrAssert(fStencilSettings.isDisabled()); |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 100 | |
| 101 | // memset exceptions |
| 102 | fColor = 0xffffffff; |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 103 | fCoverage = 0xffffffff; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 104 | fFirstCoverageStage = kNumStages; |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 105 | fColorFilterMode = SkXfermode::kDst_Mode; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 106 | fSrcBlend = kOne_GrBlendCoeff; |
| 107 | fDstBlend = kZero_GrBlendCoeff; |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 108 | fViewMatrix.reset(); |
| 109 | |
| 110 | // ensure values that will be memcmp'ed in == but not memset in reset() |
| 111 | // are tightly packed |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 112 | GrAssert(this->memsetSize() + sizeof(fColor) + sizeof(fCoverage) + |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 113 | sizeof(fFirstCoverageStage) + sizeof(fColorFilterMode) + |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 114 | sizeof(fSrcBlend) + sizeof(fDstBlend) + sizeof(fTextures) + |
| 115 | sizeof(fRenderTarget) == this->podSize()); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /////////////////////////////////////////////////////////////////////////// |
| 119 | /// @name Color |
| 120 | //// |
| 121 | |
| 122 | /** |
| 123 | * Sets color for next draw to a premultiplied-alpha color. |
| 124 | * |
| 125 | * @param color the color to set. |
| 126 | */ |
| 127 | void setColor(GrColor color) { fColor = color; } |
| 128 | |
| 129 | GrColor getColor() const { return fColor; } |
| 130 | |
| 131 | /** |
| 132 | * Sets the color to be used for the next draw to be |
| 133 | * (r,g,b,a) = (alpha, alpha, alpha, alpha). |
| 134 | * |
| 135 | * @param alpha The alpha value to set as the color. |
| 136 | */ |
| 137 | void setAlpha(uint8_t a) { |
| 138 | this->setColor((a << 24) | (a << 16) | (a << 8) | a); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Add a color filter that can be represented by a color and a mode. Applied |
| 143 | * after color-computing texture stages. |
| 144 | */ |
| 145 | void setColorFilter(GrColor c, SkXfermode::Mode mode) { |
| 146 | fColorFilterColor = c; |
| 147 | fColorFilterMode = mode; |
| 148 | } |
| 149 | |
| 150 | GrColor getColorFilterColor() const { return fColorFilterColor; } |
| 151 | SkXfermode::Mode getColorFilterMode() const { return fColorFilterMode; } |
| 152 | |
| 153 | /// @} |
| 154 | |
| 155 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 156 | /// @name Coverage |
| 157 | //// |
| 158 | |
| 159 | /** |
| 160 | * Sets a constant fractional coverage to be applied to the draw. The |
| 161 | * initial value (after construction or reset()) is 0xff. The constant |
| 162 | * coverage is ignored when per-vertex coverage is provided. |
| 163 | */ |
| 164 | void setCoverage(uint8_t coverage) { |
| 165 | fCoverage = GrColorPackRGBA(coverage, coverage, coverage, coverage); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Version of above that specifies 4 channel per-vertex color. The value |
| 170 | * should be premultiplied. |
| 171 | */ |
| 172 | void setCoverage4(GrColor coverage) { |
| 173 | fCoverage = coverage; |
| 174 | } |
| 175 | |
| 176 | GrColor getCoverage() const { |
| 177 | return fCoverage; |
| 178 | } |
| 179 | |
| 180 | /// @} |
| 181 | |
| 182 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 183 | /// @name Textures |
| 184 | //// |
| 185 | |
| 186 | /** |
| 187 | * Sets the texture used at the next drawing call |
| 188 | * |
| 189 | * @param stage The texture stage for which the texture will be set |
| 190 | * |
| 191 | * @param texture The texture to set. Can be NULL though there is no |
| 192 | * advantage to settings a NULL texture if doing non-textured drawing |
| 193 | */ |
| 194 | void setTexture(int stage, GrTexture* texture) { |
| 195 | GrAssert((unsigned)stage < kNumStages); |
robertphillips@google.com | 1942c05 | 2012-05-03 17:58:27 +0000 | [diff] [blame] | 196 | |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 197 | GrSafeAssign(fTextures[stage], texture); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Retrieves the currently set texture. |
| 202 | * |
| 203 | * @return The currently set texture. The return value will be NULL if no |
| 204 | * texture has been set, NULL was most recently passed to |
| 205 | * setTexture, or the last setTexture was destroyed. |
| 206 | */ |
| 207 | const GrTexture* getTexture(int stage) const { |
| 208 | GrAssert((unsigned)stage < kNumStages); |
| 209 | return fTextures[stage]; |
| 210 | } |
| 211 | GrTexture* getTexture(int stage) { |
| 212 | GrAssert((unsigned)stage < kNumStages); |
| 213 | return fTextures[stage]; |
| 214 | } |
| 215 | |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 216 | /** |
| 217 | * Release all the textures referred to by this draw state |
| 218 | */ |
| 219 | void releaseTextures() { |
| 220 | for (int i = 0; i < kNumStages; ++i) { |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 221 | GrSafeSetNull(fTextures[i]); |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | class AutoTextureRelease : public ::GrNoncopyable { |
| 226 | public: |
| 227 | AutoTextureRelease(GrDrawState* ds) : fDrawState(ds) {} |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 228 | ~AutoTextureRelease() { |
robertphillips@google.com | 972265d | 2012-06-13 18:49:30 +0000 | [diff] [blame] | 229 | if (NULL != fDrawState) { |
| 230 | fDrawState->releaseTextures(); |
| 231 | } |
| 232 | } |
| 233 | private: |
| 234 | GrDrawState* fDrawState; |
| 235 | }; |
| 236 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 237 | /// @} |
| 238 | |
| 239 | /////////////////////////////////////////////////////////////////////////// |
| 240 | /// @name Samplers |
| 241 | //// |
| 242 | |
| 243 | /** |
| 244 | * Returns the current sampler for a stage. |
| 245 | */ |
| 246 | const GrSamplerState& getSampler(int stage) const { |
| 247 | GrAssert((unsigned)stage < kNumStages); |
| 248 | return fSamplerStates[stage]; |
| 249 | } |
| 250 | |
| 251 | /** |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 252 | * Writable pointer to a stage's sampler. |
| 253 | */ |
| 254 | GrSamplerState* sampler(int stage) { |
| 255 | GrAssert((unsigned)stage < kNumStages); |
| 256 | return fSamplerStates + stage; |
| 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Preconcats the matrix of all samplers in the mask with the same matrix. |
| 261 | */ |
| 262 | void preConcatSamplerMatrices(StageMask stageMask, const GrMatrix& matrix) { |
| 263 | GrAssert(!(stageMask & kIllegalStageMaskBits)); |
| 264 | for (int i = 0; i < kNumStages; ++i) { |
| 265 | if ((1 << i) & stageMask) { |
| 266 | fSamplerStates[i].preConcatMatrix(matrix); |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /// @} |
| 272 | |
| 273 | /////////////////////////////////////////////////////////////////////////// |
| 274 | /// @name Coverage / Color Stages |
| 275 | //// |
| 276 | |
| 277 | /** |
| 278 | * A common pattern is to compute a color with the initial stages and then |
| 279 | * modulate that color by a coverage value in later stage(s) (AA, mask- |
| 280 | * filters, glyph mask, etc). Color-filters, xfermodes, etc should be |
| 281 | * computed based on the pre-coverage-modulated color. The division of |
| 282 | * stages between color-computing and coverage-computing is specified by |
| 283 | * this method. Initially this is kNumStages (all stages |
| 284 | * are color-computing). |
| 285 | */ |
| 286 | void setFirstCoverageStage(int firstCoverageStage) { |
| 287 | GrAssert((unsigned)firstCoverageStage <= kNumStages); |
| 288 | fFirstCoverageStage = firstCoverageStage; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Gets the index of the first coverage-computing stage. |
| 293 | */ |
| 294 | int getFirstCoverageStage() const { |
| 295 | return fFirstCoverageStage; |
| 296 | } |
| 297 | |
| 298 | ///@} |
| 299 | |
| 300 | /////////////////////////////////////////////////////////////////////////// |
| 301 | /// @name Blending |
| 302 | //// |
| 303 | |
| 304 | /** |
| 305 | * Sets the blending function coeffecients. |
| 306 | * |
| 307 | * The blend function will be: |
| 308 | * D' = sat(S*srcCoef + D*dstCoef) |
| 309 | * |
| 310 | * where D is the existing destination color, S is the incoming source |
| 311 | * color, and D' is the new destination color that will be written. sat() |
| 312 | * is the saturation function. |
| 313 | * |
| 314 | * @param srcCoef coeffecient applied to the src color. |
| 315 | * @param dstCoef coeffecient applied to the dst color. |
| 316 | */ |
| 317 | void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { |
| 318 | fSrcBlend = srcCoeff; |
| 319 | fDstBlend = dstCoeff; |
| 320 | #if GR_DEBUG |
| 321 | switch (dstCoeff) { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 322 | case kDC_GrBlendCoeff: |
| 323 | case kIDC_GrBlendCoeff: |
| 324 | case kDA_GrBlendCoeff: |
| 325 | case kIDA_GrBlendCoeff: |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 326 | GrPrintf("Unexpected dst blend coeff. Won't work correctly with" |
| 327 | "coverage stages.\n"); |
| 328 | break; |
| 329 | default: |
| 330 | break; |
| 331 | } |
| 332 | switch (srcCoeff) { |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 333 | case kSC_GrBlendCoeff: |
| 334 | case kISC_GrBlendCoeff: |
| 335 | case kSA_GrBlendCoeff: |
| 336 | case kISA_GrBlendCoeff: |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 337 | GrPrintf("Unexpected src blend coeff. Won't work correctly with" |
| 338 | "coverage stages.\n"); |
| 339 | break; |
| 340 | default: |
| 341 | break; |
| 342 | } |
| 343 | #endif |
| 344 | } |
| 345 | |
| 346 | GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; } |
| 347 | GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; } |
| 348 | |
| 349 | void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff, |
| 350 | GrBlendCoeff* dstBlendCoeff) const { |
| 351 | *srcBlendCoeff = fSrcBlend; |
| 352 | *dstBlendCoeff = fDstBlend; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * Sets the blending function constant referenced by the following blending |
| 357 | * coeffecients: |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 358 | * kConstC_GrBlendCoeff |
| 359 | * kIConstC_GrBlendCoeff |
| 360 | * kConstA_GrBlendCoeff |
| 361 | * kIConstA_GrBlendCoeff |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 362 | * |
| 363 | * @param constant the constant to set |
| 364 | */ |
| 365 | void setBlendConstant(GrColor constant) { fBlendConstant = constant; } |
| 366 | |
| 367 | /** |
| 368 | * Retrieves the last value set by setBlendConstant() |
| 369 | * @return the blending constant value |
| 370 | */ |
| 371 | GrColor getBlendConstant() const { return fBlendConstant; } |
| 372 | |
| 373 | /// @} |
| 374 | |
| 375 | /////////////////////////////////////////////////////////////////////////// |
| 376 | /// @name View Matrix |
| 377 | //// |
| 378 | |
| 379 | /** |
robertphillips@google.com | a72eef3 | 2012-05-01 17:22:59 +0000 | [diff] [blame] | 380 | * Sets the matrix applied to vertex positions. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 381 | * |
| 382 | * In the post-view-matrix space the rectangle [0,w]x[0,h] |
| 383 | * fully covers the render target. (w and h are the width and height of the |
| 384 | * the rendertarget.) |
| 385 | */ |
| 386 | void setViewMatrix(const GrMatrix& m) { fViewMatrix = m; } |
| 387 | |
| 388 | /** |
| 389 | * Gets a writable pointer to the view matrix. |
| 390 | */ |
| 391 | GrMatrix* viewMatrix() { return &fViewMatrix; } |
| 392 | |
| 393 | /** |
| 394 | * Multiplies the current view matrix by a matrix |
| 395 | * |
| 396 | * After this call V' = V*m where V is the old view matrix, |
| 397 | * m is the parameter to this function, and V' is the new view matrix. |
| 398 | * (We consider positions to be column vectors so position vector p is |
| 399 | * transformed by matrix X as p' = X*p.) |
| 400 | * |
| 401 | * @param m the matrix used to modify the view matrix. |
| 402 | */ |
| 403 | void preConcatViewMatrix(const GrMatrix& m) { fViewMatrix.preConcat(m); } |
| 404 | |
| 405 | /** |
| 406 | * Multiplies the current view matrix by a matrix |
| 407 | * |
| 408 | * After this call V' = m*V where V is the old view matrix, |
| 409 | * m is the parameter to this function, and V' is the new view matrix. |
| 410 | * (We consider positions to be column vectors so position vector p is |
| 411 | * transformed by matrix X as p' = X*p.) |
| 412 | * |
| 413 | * @param m the matrix used to modify the view matrix. |
| 414 | */ |
| 415 | void postConcatViewMatrix(const GrMatrix& m) { fViewMatrix.postConcat(m); } |
| 416 | |
| 417 | /** |
| 418 | * Retrieves the current view matrix |
| 419 | * @return the current view matrix. |
| 420 | */ |
| 421 | const GrMatrix& getViewMatrix() const { return fViewMatrix; } |
| 422 | |
| 423 | /** |
| 424 | * Retrieves the inverse of the current view matrix. |
| 425 | * |
| 426 | * If the current view matrix is invertible, return true, and if matrix |
| 427 | * is non-null, copy the inverse into it. If the current view matrix is |
| 428 | * non-invertible, return false and ignore the matrix parameter. |
| 429 | * |
| 430 | * @param matrix if not null, will receive a copy of the current inverse. |
| 431 | */ |
| 432 | bool getViewInverse(GrMatrix* matrix) const { |
| 433 | // TODO: determine whether we really need to leave matrix unmodified |
| 434 | // at call sites when inversion fails. |
| 435 | GrMatrix inverse; |
| 436 | if (fViewMatrix.invert(&inverse)) { |
| 437 | if (matrix) { |
| 438 | *matrix = inverse; |
| 439 | } |
| 440 | return true; |
| 441 | } |
| 442 | return false; |
| 443 | } |
| 444 | |
| 445 | class AutoViewMatrixRestore : public ::GrNoncopyable { |
| 446 | public: |
| 447 | AutoViewMatrixRestore() : fDrawState(NULL) {} |
| 448 | AutoViewMatrixRestore(GrDrawState* ds, const GrMatrix& newMatrix) { |
| 449 | fDrawState = NULL; |
| 450 | this->set(ds, newMatrix); |
| 451 | } |
| 452 | AutoViewMatrixRestore(GrDrawState* ds) { |
| 453 | fDrawState = NULL; |
| 454 | this->set(ds); |
| 455 | } |
| 456 | ~AutoViewMatrixRestore() { |
| 457 | this->set(NULL, GrMatrix::I()); |
| 458 | } |
| 459 | void set(GrDrawState* ds, const GrMatrix& newMatrix) { |
| 460 | if (NULL != fDrawState) { |
| 461 | fDrawState->setViewMatrix(fSavedMatrix); |
| 462 | } |
| 463 | if (NULL != ds) { |
| 464 | fSavedMatrix = ds->getViewMatrix(); |
| 465 | ds->setViewMatrix(newMatrix); |
| 466 | } |
| 467 | fDrawState = ds; |
| 468 | } |
| 469 | void set(GrDrawState* ds) { |
| 470 | if (NULL != fDrawState) { |
| 471 | fDrawState->setViewMatrix(fSavedMatrix); |
| 472 | } |
| 473 | if (NULL != ds) { |
| 474 | fSavedMatrix = ds->getViewMatrix(); |
| 475 | } |
| 476 | fDrawState = ds; |
| 477 | } |
| 478 | private: |
| 479 | GrDrawState* fDrawState; |
| 480 | GrMatrix fSavedMatrix; |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 481 | }; |
| 482 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 483 | /// @} |
| 484 | |
| 485 | /////////////////////////////////////////////////////////////////////////// |
| 486 | /// @name Render Target |
| 487 | //// |
| 488 | |
| 489 | /** |
| 490 | * Sets the rendertarget used at the next drawing call |
| 491 | * |
| 492 | * @param target The render target to set. |
| 493 | */ |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 494 | void setRenderTarget(GrRenderTarget* target) { |
| 495 | GrSafeAssign(fRenderTarget, target); |
| 496 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 497 | |
| 498 | /** |
| 499 | * Retrieves the currently set rendertarget. |
| 500 | * |
| 501 | * @return The currently set render target. |
| 502 | */ |
| 503 | const GrRenderTarget* getRenderTarget() const { return fRenderTarget; } |
| 504 | GrRenderTarget* getRenderTarget() { return fRenderTarget; } |
| 505 | |
| 506 | class AutoRenderTargetRestore : public ::GrNoncopyable { |
| 507 | public: |
bsalomon@google.com | cadbcb8 | 2012-01-06 19:22:11 +0000 | [diff] [blame] | 508 | AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 509 | AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { |
| 510 | fDrawState = NULL; |
robertphillips@google.com | 7460b37 | 2012-04-25 16:54:51 +0000 | [diff] [blame] | 511 | fSavedTarget = NULL; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 512 | this->set(ds, newTarget); |
| 513 | } |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 514 | ~AutoRenderTargetRestore() { this->restore(); } |
| 515 | |
| 516 | void restore() { |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 517 | if (NULL != fDrawState) { |
| 518 | fDrawState->setRenderTarget(fSavedTarget); |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 519 | fDrawState = NULL; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 520 | } |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 521 | GrSafeSetNull(fSavedTarget); |
| 522 | } |
| 523 | |
| 524 | void set(GrDrawState* ds, GrRenderTarget* newTarget) { |
| 525 | this->restore(); |
| 526 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 527 | if (NULL != ds) { |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 528 | GrAssert(NULL == fSavedTarget); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 529 | fSavedTarget = ds->getRenderTarget(); |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 530 | SkSafeRef(fSavedTarget); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 531 | ds->setRenderTarget(newTarget); |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 532 | fDrawState = ds; |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 533 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 534 | } |
| 535 | private: |
| 536 | GrDrawState* fDrawState; |
| 537 | GrRenderTarget* fSavedTarget; |
| 538 | }; |
| 539 | |
| 540 | /// @} |
| 541 | |
| 542 | /////////////////////////////////////////////////////////////////////////// |
| 543 | /// @name Stencil |
| 544 | //// |
| 545 | |
| 546 | /** |
| 547 | * Sets the stencil settings to use for the next draw. |
| 548 | * Changing the clip has the side-effect of possibly zeroing |
| 549 | * out the client settable stencil bits. So multipass algorithms |
| 550 | * using stencil should not change the clip between passes. |
| 551 | * @param settings the stencil settings to use. |
| 552 | */ |
| 553 | void setStencil(const GrStencilSettings& settings) { |
| 554 | fStencilSettings = settings; |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Shortcut to disable stencil testing and ops. |
| 559 | */ |
| 560 | void disableStencil() { |
| 561 | fStencilSettings.setDisabled(); |
| 562 | } |
| 563 | |
| 564 | const GrStencilSettings& getStencil() const { return fStencilSettings; } |
| 565 | |
| 566 | GrStencilSettings* stencil() { return &fStencilSettings; } |
| 567 | |
| 568 | /// @} |
| 569 | |
| 570 | /////////////////////////////////////////////////////////////////////////// |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 571 | /// @name Color Matrix |
| 572 | //// |
| 573 | |
| 574 | /** |
| 575 | * Sets the color matrix to use for the next draw. |
| 576 | * @param matrix the 5x4 matrix to apply to the incoming color |
| 577 | */ |
| 578 | void setColorMatrix(const float matrix[20]) { |
| 579 | memcpy(fColorMatrix, matrix, sizeof(fColorMatrix)); |
| 580 | } |
| 581 | |
| 582 | const float* getColorMatrix() const { return fColorMatrix; } |
| 583 | |
| 584 | /// @} |
| 585 | |
| 586 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 587 | // @name Edge AA |
bsalomon@google.com | 7ffe681 | 2012-05-11 17:32:43 +0000 | [diff] [blame] | 588 | // Edge equations can be specified to perform antialiasing. Because the |
| 589 | // edges are specified as per-vertex data, vertices that are shared by |
| 590 | // multiple edges must be split. |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 591 | // |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 592 | //// |
| 593 | |
| 594 | /** |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 595 | * When specifying edges as vertex data this enum specifies what type of |
| 596 | * edges are in use. The edges are always 4 GrScalars in memory, even when |
| 597 | * the edge type requires fewer than 4. |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 598 | * |
| 599 | * TODO: Fix the fact that HairLine and Circle edge types use y-down coords. |
| 600 | * (either adjust in VS or use origin_upper_left in GLSL) |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 601 | */ |
| 602 | enum VertexEdgeType { |
| 603 | /* 1-pixel wide line |
| 604 | 2D implicit line eq (a*x + b*y +c = 0). 4th component unused */ |
| 605 | kHairLine_EdgeType, |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 606 | /* Quadratic specified by u^2-v canonical coords (only 2 |
| 607 | components used). Coverage based on signed distance with negative |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 608 | being inside, positive outside. Edge specified in window space |
| 609 | (y-down) */ |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 610 | kQuad_EdgeType, |
| 611 | /* Same as above but for hairline quadratics. Uses unsigned distance. |
| 612 | Coverage is min(0, 1-distance). */ |
| 613 | kHairQuad_EdgeType, |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 614 | /* Circle specified as center_x, center_y, outer_radius, inner_radius |
| 615 | all in window space (y-down). */ |
| 616 | kCircle_EdgeType, |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 617 | |
| 618 | kVertexEdgeTypeCnt |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 619 | }; |
| 620 | |
| 621 | /** |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 622 | * Determines the interpretation per-vertex edge data when the |
| 623 | * kEdge_VertexLayoutBit is set (see GrDrawTarget). When per-vertex edges |
| 624 | * are not specified the value of this setting has no effect. |
| 625 | */ |
| 626 | void setVertexEdgeType(VertexEdgeType type) { |
bsalomon@google.com | 69cc6ad | 2012-01-17 14:25:10 +0000 | [diff] [blame] | 627 | GrAssert(type >=0 && type < kVertexEdgeTypeCnt); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 628 | fVertexEdgeType = type; |
| 629 | } |
| 630 | |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 631 | VertexEdgeType getVertexEdgeType() const { return fVertexEdgeType; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 632 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 633 | /// @} |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 634 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 635 | /////////////////////////////////////////////////////////////////////////// |
| 636 | /// @name State Flags |
| 637 | //// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 638 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 639 | /** |
| 640 | * Flags that affect rendering. Controlled using enable/disableState(). All |
| 641 | * default to disabled. |
| 642 | */ |
| 643 | enum StateBits { |
| 644 | /** |
| 645 | * Perform dithering. TODO: Re-evaluate whether we need this bit |
| 646 | */ |
| 647 | kDither_StateBit = 0x01, |
| 648 | /** |
| 649 | * Perform HW anti-aliasing. This means either HW FSAA, if supported |
| 650 | * by the render target, or smooth-line rendering if a line primitive |
| 651 | * is drawn and line smoothing is supported by the 3D API. |
| 652 | */ |
| 653 | kHWAntialias_StateBit = 0x02, |
| 654 | /** |
| 655 | * Draws will respect the clip, otherwise the clip is ignored. |
| 656 | */ |
| 657 | kClip_StateBit = 0x04, |
| 658 | /** |
| 659 | * Disables writing to the color buffer. Useful when performing stencil |
| 660 | * operations. |
| 661 | */ |
| 662 | kNoColorWrites_StateBit = 0x08, |
| 663 | /** |
senorblanco@chromium.org | 50bdad8 | 2012-01-03 20:51:57 +0000 | [diff] [blame] | 664 | * Draws will apply the color matrix, otherwise the color matrix is |
| 665 | * ignored. |
| 666 | */ |
| 667 | kColorMatrix_StateBit = 0x20, |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 668 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 669 | // Users of the class may add additional bits to the vector |
| 670 | kDummyStateBit, |
| 671 | kLastPublicStateBit = kDummyStateBit-1, |
| 672 | }; |
| 673 | |
| 674 | void resetStateFlags() { |
| 675 | fFlagBits = 0; |
| 676 | } |
| 677 | |
| 678 | /** |
| 679 | * Enable render state settings. |
| 680 | * |
| 681 | * @param flags bitfield of StateBits specifing the states to enable |
| 682 | */ |
| 683 | void enableState(uint32_t stateBits) { |
| 684 | fFlagBits |= stateBits; |
| 685 | } |
| 686 | |
| 687 | /** |
| 688 | * Disable render state settings. |
| 689 | * |
| 690 | * @param flags bitfield of StateBits specifing the states to disable |
| 691 | */ |
| 692 | void disableState(uint32_t stateBits) { |
| 693 | fFlagBits &= ~(stateBits); |
| 694 | } |
| 695 | |
| 696 | bool isDitherState() const { |
| 697 | return 0 != (fFlagBits & kDither_StateBit); |
| 698 | } |
| 699 | |
| 700 | bool isHWAntialiasState() const { |
| 701 | return 0 != (fFlagBits & kHWAntialias_StateBit); |
| 702 | } |
| 703 | |
| 704 | bool isClipState() const { |
| 705 | return 0 != (fFlagBits & kClip_StateBit); |
| 706 | } |
| 707 | |
| 708 | bool isColorWriteDisabled() const { |
| 709 | return 0 != (fFlagBits & kNoColorWrites_StateBit); |
| 710 | } |
| 711 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 712 | bool isStateFlagEnabled(uint32_t stateBit) const { |
| 713 | return 0 != (stateBit & fFlagBits); |
| 714 | } |
| 715 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 716 | /// @} |
| 717 | |
| 718 | /////////////////////////////////////////////////////////////////////////// |
| 719 | /// @name Face Culling |
| 720 | //// |
| 721 | |
| 722 | enum DrawFace { |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 723 | kInvalid_DrawFace = -1, |
| 724 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 725 | kBoth_DrawFace, |
| 726 | kCCW_DrawFace, |
| 727 | kCW_DrawFace, |
| 728 | }; |
| 729 | |
| 730 | /** |
| 731 | * Controls whether clockwise, counterclockwise, or both faces are drawn. |
| 732 | * @param face the face(s) to draw. |
| 733 | */ |
| 734 | void setDrawFace(DrawFace face) { |
bsalomon@google.com | 978c8c6 | 2012-05-21 14:45:49 +0000 | [diff] [blame] | 735 | GrAssert(kInvalid_DrawFace != face); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 736 | fDrawFace = face; |
| 737 | } |
| 738 | |
| 739 | /** |
| 740 | * Gets whether the target is drawing clockwise, counterclockwise, |
| 741 | * or both faces. |
| 742 | * @return the current draw face(s). |
| 743 | */ |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 744 | DrawFace getDrawFace() const { return fDrawFace; } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 745 | |
| 746 | /// @} |
| 747 | |
| 748 | /////////////////////////////////////////////////////////////////////////// |
tomhudson@google.com | 62b0968 | 2011-11-09 16:39:17 +0000 | [diff] [blame] | 749 | |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 750 | // Most stages are usually not used, so conditionals here |
| 751 | // reduce the expected number of bytes touched by 50%. |
| 752 | bool operator ==(const GrDrawState& s) const { |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 753 | if (memcmp(this->podStart(), s.podStart(), this->podSize())) { |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 754 | return false; |
| 755 | } |
| 756 | |
| 757 | if (!s.fViewMatrix.cheapEqualTo(fViewMatrix)) { |
| 758 | return false; |
| 759 | } |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 760 | |
| 761 | for (int i = 0; i < kNumStages; i++) { |
| 762 | if (fTextures[i] && |
tomhudson@google.com | 02b1ea2 | 2012-04-30 20:19:07 +0000 | [diff] [blame] | 763 | this->fSamplerStates[i] != s.fSamplerStates[i]) { |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 764 | return false; |
| 765 | } |
| 766 | } |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 767 | if (kColorMatrix_StateBit & s.fFlagBits) { |
| 768 | if (memcmp(fColorMatrix, |
| 769 | s.fColorMatrix, |
| 770 | sizeof(fColorMatrix))) { |
| 771 | return false; |
| 772 | } |
| 773 | } |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 774 | |
| 775 | return true; |
| 776 | } |
| 777 | bool operator !=(const GrDrawState& s) const { return !(*this == s); } |
| 778 | |
| 779 | // Most stages are usually not used, so conditionals here |
| 780 | // reduce the expected number of bytes touched by 50%. |
| 781 | GrDrawState& operator =(const GrDrawState& s) { |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 782 | memcpy(this->podStart(), s.podStart(), this->podSize()); |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 783 | |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 784 | fViewMatrix = s.fViewMatrix; |
| 785 | |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 786 | for (int i = 0; i < kNumStages; i++) { |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 787 | SkSafeRef(fTextures[i]); // already copied by memcpy |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 788 | if (s.fTextures[i]) { |
tomhudson@google.com | 02b1ea2 | 2012-04-30 20:19:07 +0000 | [diff] [blame] | 789 | this->fSamplerStates[i] = s.fSamplerStates[i]; |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 790 | } |
| 791 | } |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 792 | |
| 793 | SkSafeRef(fRenderTarget); // already copied by memcpy |
| 794 | |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 795 | if (kColorMatrix_StateBit & s.fFlagBits) { |
| 796 | memcpy(this->fColorMatrix, s.fColorMatrix, sizeof(fColorMatrix)); |
| 797 | } |
bsalomon@google.com | 3d0835b | 2011-12-08 16:12:03 +0000 | [diff] [blame] | 798 | |
| 799 | return *this; |
| 800 | } |
| 801 | |
| 802 | private: |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 803 | |
| 804 | const void* podStart() const { |
| 805 | return reinterpret_cast<const void*>(&fPodStartMarker); |
| 806 | } |
| 807 | void* podStart() { |
| 808 | return reinterpret_cast<void*>(&fPodStartMarker); |
| 809 | } |
| 810 | size_t memsetSize() const { |
| 811 | return reinterpret_cast<size_t>(&fMemsetEndMarker) - |
| 812 | reinterpret_cast<size_t>(&fPodStartMarker) + |
| 813 | sizeof(fMemsetEndMarker); |
| 814 | } |
| 815 | size_t podSize() const { |
| 816 | // Can't use offsetof() with non-POD types, so stuck with pointer math. |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 817 | return reinterpret_cast<size_t>(&fPodEndMarker) - |
| 818 | reinterpret_cast<size_t>(&fPodStartMarker) + |
| 819 | sizeof(fPodEndMarker); |
| 820 | } |
| 821 | |
caryclark@google.com | cf6285b | 2012-06-06 12:09:01 +0000 | [diff] [blame] | 822 | static const StageMask kIllegalStageMaskBits = ~((1U << kNumStages)-1); |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 823 | // @{ these fields can be initialized with memset to 0 |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 824 | union { |
| 825 | GrColor fBlendConstant; |
| 826 | GrColor fPodStartMarker; |
| 827 | }; |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 828 | GrColor fColorFilterColor; |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 829 | DrawFace fDrawFace; |
robertphillips@google.com | c077d1e | 2012-05-28 14:10:15 +0000 | [diff] [blame] | 830 | VertexEdgeType fVertexEdgeType; |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 831 | GrStencilSettings fStencilSettings; |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 832 | union { |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 833 | uint32_t fFlagBits; |
| 834 | uint32_t fMemsetEndMarker; |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 835 | }; |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 836 | // @} |
| 837 | |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 838 | int fFirstCoverageStage; |
| 839 | |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 840 | // @{ Initialized to values other than zero, but memcmp'ed in operator== |
| 841 | // and memcpy'ed in operator=. |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame^] | 842 | GrTexture* fTextures[kNumStages]; |
| 843 | GrRenderTarget* fRenderTarget; |
| 844 | |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 845 | GrColor fColor; |
bsalomon@google.com | 2401ae8 | 2012-01-17 21:03:05 +0000 | [diff] [blame] | 846 | GrColor fCoverage; |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 847 | SkXfermode::Mode fColorFilterMode; |
| 848 | GrBlendCoeff fSrcBlend; |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 849 | union { |
robertphillips@google.com | c077d1e | 2012-05-28 14:10:15 +0000 | [diff] [blame] | 850 | GrBlendCoeff fDstBlend; |
| 851 | GrBlendCoeff fPodEndMarker; |
bsalomon@google.com | 2e3d144 | 2012-03-26 20:33:54 +0000 | [diff] [blame] | 852 | }; |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 853 | // @} |
| 854 | |
bsalomon@google.com | 8fe84b5 | 2012-03-26 15:24:27 +0000 | [diff] [blame] | 855 | GrMatrix fViewMatrix; |
| 856 | |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 857 | // This field must be last; it will not be copied or compared |
| 858 | // if the corresponding fTexture[] is NULL. |
bsalomon@google.com | 52a5dcb | 2012-01-17 16:01:37 +0000 | [diff] [blame] | 859 | GrSamplerState fSamplerStates[kNumStages]; |
bsalomon@google.com | 9b1517e | 2012-03-05 17:58:34 +0000 | [diff] [blame] | 860 | // only compared if the color matrix enable flag is set |
| 861 | float fColorMatrix[20]; // 5 x 4 matrix |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 862 | |
tomhudson@google.com | 9381363 | 2011-10-27 20:21:16 +0000 | [diff] [blame] | 863 | }; |
| 864 | |
| 865 | #endif |