blob: a1191152f58444296cc6424df4808b6be8a08084 [file] [log] [blame]
tomhudson@google.com93813632011-10-27 20:21:16 +00001/*
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.com8f9cbd62011-12-09 15:55:34 +000013#include "GrNoncopyable.h"
tomhudson@google.com93813632011-10-27 20:21:16 +000014#include "GrSamplerState.h"
15#include "GrStencil.h"
16
17#include "SkXfermode.h"
18
19class GrRenderTarget;
20class GrTexture;
21
22struct GrDrawState {
23
24 /**
25 * Number of texture stages. Each stage takes as input a color and
26 * 2D texture coordinates. The color input to the first enabled stage is the
27 * per-vertex color or the constant color (setColor/setAlpha) if there are
28 * no per-vertex colors. For subsequent stages the input color is the output
29 * color from the previous enabled stage. The output color of each stage is
30 * the input color modulated with the result of a texture lookup. Texture
31 * lookups are specified by a texture a sampler (setSamplerState). Texture
32 * coordinates for each stage come from the vertices based on a
33 * GrVertexLayout bitfield. The output fragment color is the output color of
34 * the last enabled stage. The presence or absence of texture coordinates
35 * for each stage in the vertex layout indicates whether a stage is enabled
36 * or not.
37 */
38 enum {
39 kNumStages = 3,
40 kMaxTexCoords = kNumStages
41 };
42
bsalomon@google.com39ee0ff2011-12-06 15:32:52 +000043 /**
44 * Bitfield used to indicate a set of stages.
45 */
46 typedef uint32_t StageMask;
47 GR_STATIC_ASSERT(sizeof(StageMask)*8 >= GrDrawState::kNumStages);
48
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +000049 GrDrawState() {
50 // make sure any pad is zero for memcmp
51 // all GrDrawState members should default to something
52 // valid by the memset
53 memset(this, 0, sizeof(GrDrawState));
54
55 // memset exceptions
56 fColorFilterMode = SkXfermode::kDstIn_Mode;
57 fFirstCoverageStage = kNumStages;
58
59 // pedantic assertion that our ptrs will
60 // be NULL (0 ptr is mem addr 0)
61 GrAssert((intptr_t)(void*)NULL == 0LL);
62
63 GrAssert(fStencilSettings.isDisabled());
64 fFirstCoverageStage = kNumStages;
65 }
66
67 ///////////////////////////////////////////////////////////////////////////
68 /// @name Color
69 ////
70
71 /**
72 * Sets color for next draw to a premultiplied-alpha color.
73 *
74 * @param color the color to set.
75 */
76 void setColor(GrColor color) { fColor = color; }
77
78 GrColor getColor() const { return fColor; }
79
80 /**
81 * Sets the color to be used for the next draw to be
82 * (r,g,b,a) = (alpha, alpha, alpha, alpha).
83 *
84 * @param alpha The alpha value to set as the color.
85 */
86 void setAlpha(uint8_t a) {
87 this->setColor((a << 24) | (a << 16) | (a << 8) | a);
88 }
89
90 /**
91 * Add a color filter that can be represented by a color and a mode. Applied
92 * after color-computing texture stages.
93 */
94 void setColorFilter(GrColor c, SkXfermode::Mode mode) {
95 fColorFilterColor = c;
96 fColorFilterMode = mode;
97 }
98
99 GrColor getColorFilterColor() const { return fColorFilterColor; }
100 SkXfermode::Mode getColorFilterMode() const { return fColorFilterMode; }
101
102 /// @}
103
104 ///////////////////////////////////////////////////////////////////////////
105 /// @name Textures
106 ////
107
108 /**
109 * Sets the texture used at the next drawing call
110 *
111 * @param stage The texture stage for which the texture will be set
112 *
113 * @param texture The texture to set. Can be NULL though there is no
114 * advantage to settings a NULL texture if doing non-textured drawing
115 */
116 void setTexture(int stage, GrTexture* texture) {
117 GrAssert((unsigned)stage < kNumStages);
118 fTextures[stage] = texture;
119 }
120
121 /**
122 * Retrieves the currently set texture.
123 *
124 * @return The currently set texture. The return value will be NULL if no
125 * texture has been set, NULL was most recently passed to
126 * setTexture, or the last setTexture was destroyed.
127 */
128 const GrTexture* getTexture(int stage) const {
129 GrAssert((unsigned)stage < kNumStages);
130 return fTextures[stage];
131 }
132 GrTexture* getTexture(int stage) {
133 GrAssert((unsigned)stage < kNumStages);
134 return fTextures[stage];
135 }
136
137 /// @}
138
139 ///////////////////////////////////////////////////////////////////////////
140 /// @name Samplers
141 ////
142
143 /**
144 * Returns the current sampler for a stage.
145 */
146 const GrSamplerState& getSampler(int stage) const {
147 GrAssert((unsigned)stage < kNumStages);
148 return fSamplerStates[stage];
149 }
150
151 /**
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000152 * Writable pointer to a stage's sampler.
153 */
154 GrSamplerState* sampler(int stage) {
155 GrAssert((unsigned)stage < kNumStages);
156 return fSamplerStates + stage;
157 }
158
159 /**
160 * Preconcats the matrix of all samplers in the mask with the same matrix.
161 */
162 void preConcatSamplerMatrices(StageMask stageMask, const GrMatrix& matrix) {
163 GrAssert(!(stageMask & kIllegalStageMaskBits));
164 for (int i = 0; i < kNumStages; ++i) {
165 if ((1 << i) & stageMask) {
166 fSamplerStates[i].preConcatMatrix(matrix);
167 }
168 }
169 }
170
171 /// @}
172
173 ///////////////////////////////////////////////////////////////////////////
174 /// @name Coverage / Color Stages
175 ////
176
177 /**
178 * A common pattern is to compute a color with the initial stages and then
179 * modulate that color by a coverage value in later stage(s) (AA, mask-
180 * filters, glyph mask, etc). Color-filters, xfermodes, etc should be
181 * computed based on the pre-coverage-modulated color. The division of
182 * stages between color-computing and coverage-computing is specified by
183 * this method. Initially this is kNumStages (all stages
184 * are color-computing).
185 */
186 void setFirstCoverageStage(int firstCoverageStage) {
187 GrAssert((unsigned)firstCoverageStage <= kNumStages);
188 fFirstCoverageStage = firstCoverageStage;
189 }
190
191 /**
192 * Gets the index of the first coverage-computing stage.
193 */
194 int getFirstCoverageStage() const {
195 return fFirstCoverageStage;
196 }
197
198 ///@}
199
200 ///////////////////////////////////////////////////////////////////////////
201 /// @name Blending
202 ////
203
204 /**
205 * Sets the blending function coeffecients.
206 *
207 * The blend function will be:
208 * D' = sat(S*srcCoef + D*dstCoef)
209 *
210 * where D is the existing destination color, S is the incoming source
211 * color, and D' is the new destination color that will be written. sat()
212 * is the saturation function.
213 *
214 * @param srcCoef coeffecient applied to the src color.
215 * @param dstCoef coeffecient applied to the dst color.
216 */
217 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
218 fSrcBlend = srcCoeff;
219 fDstBlend = dstCoeff;
220 #if GR_DEBUG
221 switch (dstCoeff) {
222 case kDC_BlendCoeff:
223 case kIDC_BlendCoeff:
224 case kDA_BlendCoeff:
225 case kIDA_BlendCoeff:
226 GrPrintf("Unexpected dst blend coeff. Won't work correctly with"
227 "coverage stages.\n");
228 break;
229 default:
230 break;
231 }
232 switch (srcCoeff) {
233 case kSC_BlendCoeff:
234 case kISC_BlendCoeff:
235 case kSA_BlendCoeff:
236 case kISA_BlendCoeff:
237 GrPrintf("Unexpected src blend coeff. Won't work correctly with"
238 "coverage stages.\n");
239 break;
240 default:
241 break;
242 }
243 #endif
244 }
245
246 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; }
247 GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; }
248
249 void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff,
250 GrBlendCoeff* dstBlendCoeff) const {
251 *srcBlendCoeff = fSrcBlend;
252 *dstBlendCoeff = fDstBlend;
253 }
254
255 /**
256 * Sets the blending function constant referenced by the following blending
257 * coeffecients:
258 * kConstC_BlendCoeff
259 * kIConstC_BlendCoeff
260 * kConstA_BlendCoeff
261 * kIConstA_BlendCoeff
262 *
263 * @param constant the constant to set
264 */
265 void setBlendConstant(GrColor constant) { fBlendConstant = constant; }
266
267 /**
268 * Retrieves the last value set by setBlendConstant()
269 * @return the blending constant value
270 */
271 GrColor getBlendConstant() const { return fBlendConstant; }
272
273 /// @}
274
275 ///////////////////////////////////////////////////////////////////////////
276 /// @name View Matrix
277 ////
278
279 /**
280 * Sets the matrix applied to veretx positions.
281 *
282 * In the post-view-matrix space the rectangle [0,w]x[0,h]
283 * fully covers the render target. (w and h are the width and height of the
284 * the rendertarget.)
285 */
286 void setViewMatrix(const GrMatrix& m) { fViewMatrix = m; }
287
288 /**
289 * Gets a writable pointer to the view matrix.
290 */
291 GrMatrix* viewMatrix() { return &fViewMatrix; }
292
293 /**
294 * Multiplies the current view matrix by a matrix
295 *
296 * After this call V' = V*m where V is the old view matrix,
297 * m is the parameter to this function, and V' is the new view matrix.
298 * (We consider positions to be column vectors so position vector p is
299 * transformed by matrix X as p' = X*p.)
300 *
301 * @param m the matrix used to modify the view matrix.
302 */
303 void preConcatViewMatrix(const GrMatrix& m) { fViewMatrix.preConcat(m); }
304
305 /**
306 * Multiplies the current view matrix by a matrix
307 *
308 * After this call V' = m*V where V is the old view matrix,
309 * m is the parameter to this function, and V' is the new view matrix.
310 * (We consider positions to be column vectors so position vector p is
311 * transformed by matrix X as p' = X*p.)
312 *
313 * @param m the matrix used to modify the view matrix.
314 */
315 void postConcatViewMatrix(const GrMatrix& m) { fViewMatrix.postConcat(m); }
316
317 /**
318 * Retrieves the current view matrix
319 * @return the current view matrix.
320 */
321 const GrMatrix& getViewMatrix() const { return fViewMatrix; }
322
323 /**
324 * Retrieves the inverse of the current view matrix.
325 *
326 * If the current view matrix is invertible, return true, and if matrix
327 * is non-null, copy the inverse into it. If the current view matrix is
328 * non-invertible, return false and ignore the matrix parameter.
329 *
330 * @param matrix if not null, will receive a copy of the current inverse.
331 */
332 bool getViewInverse(GrMatrix* matrix) const {
333 // TODO: determine whether we really need to leave matrix unmodified
334 // at call sites when inversion fails.
335 GrMatrix inverse;
336 if (fViewMatrix.invert(&inverse)) {
337 if (matrix) {
338 *matrix = inverse;
339 }
340 return true;
341 }
342 return false;
343 }
344
345 class AutoViewMatrixRestore : public ::GrNoncopyable {
346 public:
347 AutoViewMatrixRestore() : fDrawState(NULL) {}
348 AutoViewMatrixRestore(GrDrawState* ds, const GrMatrix& newMatrix) {
349 fDrawState = NULL;
350 this->set(ds, newMatrix);
351 }
352 AutoViewMatrixRestore(GrDrawState* ds) {
353 fDrawState = NULL;
354 this->set(ds);
355 }
356 ~AutoViewMatrixRestore() {
357 this->set(NULL, GrMatrix::I());
358 }
359 void set(GrDrawState* ds, const GrMatrix& newMatrix) {
360 if (NULL != fDrawState) {
361 fDrawState->setViewMatrix(fSavedMatrix);
362 }
363 if (NULL != ds) {
364 fSavedMatrix = ds->getViewMatrix();
365 ds->setViewMatrix(newMatrix);
366 }
367 fDrawState = ds;
368 }
369 void set(GrDrawState* ds) {
370 if (NULL != fDrawState) {
371 fDrawState->setViewMatrix(fSavedMatrix);
372 }
373 if (NULL != ds) {
374 fSavedMatrix = ds->getViewMatrix();
375 }
376 fDrawState = ds;
377 }
378 private:
379 GrDrawState* fDrawState;
380 GrMatrix fSavedMatrix;
tomhudson@google.com93813632011-10-27 20:21:16 +0000381 };
382
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000383 /// @}
384
385 ///////////////////////////////////////////////////////////////////////////
386 /// @name Render Target
387 ////
388
389 /**
390 * Sets the rendertarget used at the next drawing call
391 *
392 * @param target The render target to set.
393 */
394 void setRenderTarget(GrRenderTarget* target) { fRenderTarget = target; }
395
396 /**
397 * Retrieves the currently set rendertarget.
398 *
399 * @return The currently set render target.
400 */
401 const GrRenderTarget* getRenderTarget() const { return fRenderTarget; }
402 GrRenderTarget* getRenderTarget() { return fRenderTarget; }
403
404 class AutoRenderTargetRestore : public ::GrNoncopyable {
405 public:
406 AutoRenderTargetRestore() : fDrawState(NULL) {}
407 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) {
408 fDrawState = NULL;
409 this->set(ds, newTarget);
410 }
411 ~AutoRenderTargetRestore() { this->set(NULL, NULL); }
412 void set(GrDrawState* ds, GrRenderTarget* newTarget) {
413 if (NULL != fDrawState) {
414 fDrawState->setRenderTarget(fSavedTarget);
415 }
416 if (NULL != ds) {
417 fSavedTarget = ds->getRenderTarget();
418 ds->setRenderTarget(newTarget);
419 }
420 fDrawState = ds;
421 }
422 private:
423 GrDrawState* fDrawState;
424 GrRenderTarget* fSavedTarget;
425 };
426
427 /// @}
428
429 ///////////////////////////////////////////////////////////////////////////
430 /// @name Stencil
431 ////
432
433 /**
434 * Sets the stencil settings to use for the next draw.
435 * Changing the clip has the side-effect of possibly zeroing
436 * out the client settable stencil bits. So multipass algorithms
437 * using stencil should not change the clip between passes.
438 * @param settings the stencil settings to use.
439 */
440 void setStencil(const GrStencilSettings& settings) {
441 fStencilSettings = settings;
442 }
443
444 /**
445 * Shortcut to disable stencil testing and ops.
446 */
447 void disableStencil() {
448 fStencilSettings.setDisabled();
449 }
450
451 const GrStencilSettings& getStencil() const { return fStencilSettings; }
452
453 GrStencilSettings* stencil() { return &fStencilSettings; }
454
455 /// @}
456
457 ///////////////////////////////////////////////////////////////////////////
458 // @name Edge AA
459 // There are two ways to perform antialiasing using edge equations. One
460 // is to specify an (linear or quadratic) edge eq per-vertex. This requires
461 // splitting vertices shared by primitives.
462 //
463 // The other is via setEdgeAAData which sets a set of edges and each
464 // is tested against all the edges.
465 ////
466
467 /**
tomhudson@google.com93813632011-10-27 20:21:16 +0000468 * When specifying edges as vertex data this enum specifies what type of
469 * edges are in use. The edges are always 4 GrScalars in memory, even when
470 * the edge type requires fewer than 4.
471 */
472 enum VertexEdgeType {
473 /* 1-pixel wide line
474 2D implicit line eq (a*x + b*y +c = 0). 4th component unused */
475 kHairLine_EdgeType,
476 /* 1-pixel wide quadratic
477 u^2-v canonical coords (only 2 components used) */
478 kHairQuad_EdgeType
479 };
480
481 /**
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000482 * Determines the interpretation per-vertex edge data when the
483 * kEdge_VertexLayoutBit is set (see GrDrawTarget). When per-vertex edges
484 * are not specified the value of this setting has no effect.
485 */
486 void setVertexEdgeType(VertexEdgeType type) {
487 fVertexEdgeType = type;
488 }
489
490 VertexEdgeType getVertexEdgeType() const {
491 return fVertexEdgeType;
492 }
493
494 /**
tomhudson@google.com93813632011-10-27 20:21:16 +0000495 * The absolute maximum number of edges that may be specified for
496 * a single draw call when performing edge antialiasing. This is used for
497 * the size of several static buffers, so implementations of getMaxEdges()
498 * (below) should clamp to this value.
499 */
500 enum {
tomhudson@google.com62b09682011-11-09 16:39:17 +0000501 // TODO: this should be 32 when GrTesselatedPathRenderer is used
502 // Visual Studio 2010 does not permit a member array of size 0.
503 kMaxEdges = 1
tomhudson@google.com93813632011-10-27 20:21:16 +0000504 };
505
506 class Edge {
507 public:
508 Edge() {}
509 Edge(float x, float y, float z) : fX(x), fY(y), fZ(z) {}
510 GrPoint intersect(const Edge& other) {
511 return GrPoint::Make(
bsalomon@google.com72e49b82011-10-27 21:47:03 +0000512 SkFloatToScalar((fY * other.fZ - other.fY * fZ) /
513 (fX * other.fY - other.fX * fY)),
514 SkFloatToScalar((fX * other.fZ - other.fX * fZ) /
515 (other.fX * fY - fX * other.fY)));
tomhudson@google.com93813632011-10-27 20:21:16 +0000516 }
517 float fX, fY, fZ;
518 };
519
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000520 /**
521 * Sets the edge data required for edge antialiasing.
522 *
523 * @param edges 3 * numEdges float values, representing the edge
524 * equations in Ax + By + C form
525 */
526 void setEdgeAAData(const Edge* edges, int numEdges) {
527 GrAssert(numEdges <= GrDrawState::kMaxEdges);
528 memcpy(fEdgeAAEdges, edges, numEdges * sizeof(GrDrawState::Edge));
529 fEdgeAANumEdges = numEdges;
tomhudson@google.com93813632011-10-27 20:21:16 +0000530 }
531
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000532 int getNumAAEdges() const { return fEdgeAANumEdges; }
tomhudson@google.com93813632011-10-27 20:21:16 +0000533
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000534 const Edge* getAAEdges() const { return fEdgeAAEdges; }
tomhudson@google.com62b09682011-11-09 16:39:17 +0000535
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000536 /// @}
tomhudson@google.com62b09682011-11-09 16:39:17 +0000537
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000538 ///////////////////////////////////////////////////////////////////////////
539 /// @name State Flags
540 ////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000541
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000542 /**
543 * Flags that affect rendering. Controlled using enable/disableState(). All
544 * default to disabled.
545 */
546 enum StateBits {
547 /**
548 * Perform dithering. TODO: Re-evaluate whether we need this bit
549 */
550 kDither_StateBit = 0x01,
551 /**
552 * Perform HW anti-aliasing. This means either HW FSAA, if supported
553 * by the render target, or smooth-line rendering if a line primitive
554 * is drawn and line smoothing is supported by the 3D API.
555 */
556 kHWAntialias_StateBit = 0x02,
557 /**
558 * Draws will respect the clip, otherwise the clip is ignored.
559 */
560 kClip_StateBit = 0x04,
561 /**
562 * Disables writing to the color buffer. Useful when performing stencil
563 * operations.
564 */
565 kNoColorWrites_StateBit = 0x08,
566 /**
567 * Modifies the behavior of edge AA specified by setEdgeAA. If set,
568 * will test edge pairs for convexity when rasterizing. Set this if the
569 * source polygon is non-convex.
570 */
571 kEdgeAAConcave_StateBit = 0x10,
tomhudson@google.com62b09682011-11-09 16:39:17 +0000572
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000573 // Users of the class may add additional bits to the vector
574 kDummyStateBit,
575 kLastPublicStateBit = kDummyStateBit-1,
576 };
577
578 void resetStateFlags() {
579 fFlagBits = 0;
580 }
581
582 /**
583 * Enable render state settings.
584 *
585 * @param flags bitfield of StateBits specifing the states to enable
586 */
587 void enableState(uint32_t stateBits) {
588 fFlagBits |= stateBits;
589 }
590
591 /**
592 * Disable render state settings.
593 *
594 * @param flags bitfield of StateBits specifing the states to disable
595 */
596 void disableState(uint32_t stateBits) {
597 fFlagBits &= ~(stateBits);
598 }
599
600 bool isDitherState() const {
601 return 0 != (fFlagBits & kDither_StateBit);
602 }
603
604 bool isHWAntialiasState() const {
605 return 0 != (fFlagBits & kHWAntialias_StateBit);
606 }
607
608 bool isClipState() const {
609 return 0 != (fFlagBits & kClip_StateBit);
610 }
611
612 bool isColorWriteDisabled() const {
613 return 0 != (fFlagBits & kNoColorWrites_StateBit);
614 }
615
616 bool isConcaveEdgeAAState() const {
617 return 0 != (fFlagBits & kEdgeAAConcave_StateBit);
618 }
619
620 bool isStateFlagEnabled(uint32_t stateBit) const {
621 return 0 != (stateBit & fFlagBits);
622 }
623
624 void copyStateFlags(const GrDrawState& ds) {
625 fFlagBits = ds.fFlagBits;
626 }
627
628 /// @}
629
630 ///////////////////////////////////////////////////////////////////////////
631 /// @name Face Culling
632 ////
633
634 enum DrawFace {
635 kBoth_DrawFace,
636 kCCW_DrawFace,
637 kCW_DrawFace,
638 };
639
640 /**
641 * Controls whether clockwise, counterclockwise, or both faces are drawn.
642 * @param face the face(s) to draw.
643 */
644 void setDrawFace(DrawFace face) {
645 fDrawFace = face;
646 }
647
648 /**
649 * Gets whether the target is drawing clockwise, counterclockwise,
650 * or both faces.
651 * @return the current draw face(s).
652 */
653 DrawFace getDrawFace() const {
654 return fDrawFace;
655 }
656
657 /// @}
658
659 ///////////////////////////////////////////////////////////////////////////
tomhudson@google.com62b09682011-11-09 16:39:17 +0000660
bsalomon@google.com3d0835b2011-12-08 16:12:03 +0000661 // Most stages are usually not used, so conditionals here
662 // reduce the expected number of bytes touched by 50%.
663 bool operator ==(const GrDrawState& s) const {
664 if (memcmp(this, &s, this->leadingBytes())) return false;
665
666 for (int i = 0; i < kNumStages; i++) {
667 if (fTextures[i] &&
668 memcmp(&this->fSamplerStates[i], &s.fSamplerStates[i],
669 sizeof(GrSamplerState))) {
670 return false;
671 }
672 }
673
674 return true;
675 }
676 bool operator !=(const GrDrawState& s) const { return !(*this == s); }
677
678 // Most stages are usually not used, so conditionals here
679 // reduce the expected number of bytes touched by 50%.
680 GrDrawState& operator =(const GrDrawState& s) {
681 memcpy(this, &s, this->leadingBytes());
682
683 for (int i = 0; i < kNumStages; i++) {
684 if (s.fTextures[i]) {
685 memcpy(&this->fSamplerStates[i], &s.fSamplerStates[i],
686 sizeof(GrSamplerState));
687 }
688 }
689
690 return *this;
691 }
692
693private:
bsalomon@google.com8f9cbd62011-12-09 15:55:34 +0000694 static const StageMask kIllegalStageMaskBits = ~((1 << kNumStages)-1);
695 uint8_t fFlagBits;
696 GrBlendCoeff fSrcBlend : 8;
697 GrBlendCoeff fDstBlend : 8;
698 DrawFace fDrawFace : 8;
699 uint8_t fFirstCoverageStage;
700 SkXfermode::Mode fColorFilterMode : 8;
701 GrColor fBlendConstant;
702 GrTexture* fTextures[kNumStages];
703 GrRenderTarget* fRenderTarget;
704 GrColor fColor;
705 GrColor fColorFilterColor;
706 GrStencilSettings fStencilSettings;
707 GrMatrix fViewMatrix;
708 // @{ Data for GrTesselatedPathRenderer
709 // TODO: currently ignored in copying & comparison for performance.
710 // Must be considered if GrTesselatedPathRenderer is being used.
711
712 VertexEdgeType fVertexEdgeType;
713 int fEdgeAANumEdges;
714 Edge fEdgeAAEdges[kMaxEdges];
715
716 // @}
717 // This field must be last; it will not be copied or compared
718 // if the corresponding fTexture[] is NULL.
719 GrSamplerState fSamplerStates[kNumStages];
720
tomhudson@google.com62b09682011-11-09 16:39:17 +0000721 size_t leadingBytes() const {
722 // Can't use offsetof() with non-POD types, so stuck with pointer math.
723 // TODO: ignores GrTesselatedPathRenderer data structures. We don't
724 // have a compile-time flag that lets us know if it's being used, and
725 // checking at runtime seems to cost 5% performance.
726 return (size_t) ((unsigned char*)&fEdgeAANumEdges -
727 (unsigned char*)&fFlagBits);
728 }
729
tomhudson@google.com93813632011-10-27 20:21:16 +0000730};
731
732#endif