gfx/skia/trunk/src/gpu/GrDrawState.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial