Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(235)

Side by Side Diff: src/gpu/GrDrawState.h

Issue 508663002: Create an optimized draw state but not hooked in yet to gpu pipeline (Closed) Base URL: https://skia.googlesource.com/skia.git@drawBase
Patch Set: Rebased to working ref changes Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrDrawState.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrDrawState_DEFINED 8 #ifndef GrDrawState_DEFINED
9 #define GrDrawState_DEFINED 9 #define GrDrawState_DEFINED
10 10
11 #include "GrBlend.h" 11 #include "GrBlend.h"
12 #include "GrOptDrawState.h"
12 #include "GrProgramResource.h" 13 #include "GrProgramResource.h"
13 #include "GrRODrawState.h" 14 #include "GrRODrawState.h"
14 #include "effects/GrSimpleTextureEffect.h" 15 #include "effects/GrSimpleTextureEffect.h"
15 16
16 /** 17 /**
17 * Modifiable subclass derived from GrRODrawState. The majority of the data that represents a draw 18 * Modifiable subclass derived from GrRODrawState. The majority of the data that represents a draw
18 * state is stored in the parent class. GrDrawState contains methods for setting , adding to, etc. 19 * state is stored in the parent class. GrDrawState contains methods for setting , adding to, etc.
19 * various data members of the draw state. This class is used to configure the s tate used when 20 * various data members of the draw state. This class is used to configure the s tate used when
20 * issuing draws via GrDrawTarget. 21 * issuing draws via GrDrawTarget.
21 */ 22 */
22 class GrDrawState : public GrRODrawState { 23 class GrDrawState : public GrRODrawState {
23 public: 24 public:
24 SK_DECLARE_INST_COUNT(GrDrawState) 25 SK_DECLARE_INST_COUNT(GrDrawState)
25 26
26 GrDrawState() { 27 GrDrawState() : fCachedOptState(NULL) {
27 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 28 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
28 this->reset(); 29 this->reset();
29 } 30 }
30 31
31 GrDrawState(const SkMatrix& initialViewMatrix) { 32 GrDrawState(const SkMatrix& initialViewMatrix) : fCachedOptState(NULL) {
32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 33 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
33 this->reset(initialViewMatrix); 34 this->reset(initialViewMatrix);
34 } 35 }
35 36
36 /** 37 /**
37 * Copies another draw state. 38 * Copies another draw state.
38 **/ 39 **/
39 GrDrawState(const GrDrawState& state) : INHERITED() { 40 GrDrawState(const GrDrawState& state) : INHERITED(), fCachedOptState(NULL) {
40 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 41 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
41 *this = state; 42 *this = state;
42 } 43 }
43 44
44 /** 45 /**
45 * Copies another draw state with a preconcat to the view matrix. 46 * Copies another draw state with a preconcat to the view matrix.
46 **/ 47 **/
47 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); 48 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix);
48 49
49 virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } 50 virtual ~GrDrawState() {
51 SkSafeUnref(fCachedOptState);
52 SkASSERT(0 == fBlockEffectRemovalCnt);
53 }
50 54
51 /** 55 /**
52 * Resets to the default state. GrEffects will be removed from all stages. 56 * Resets to the default state. GrEffects will be removed from all stages.
53 */ 57 */
54 void reset() { this->onReset(NULL); } 58 void reset() { this->onReset(NULL); }
55 59
56 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa trix); } 60 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa trix); }
57 61
58 /** 62 /**
59 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta rget. Note that 63 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta rget. Note that
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 */ 97 */
94 void setDefaultVertexAttribs(); 98 void setDefaultVertexAttribs();
95 99
96 /** 100 /**
97 * Helper to save/restore vertex attribs 101 * Helper to save/restore vertex attribs
98 */ 102 */
99 class AutoVertexAttribRestore { 103 class AutoVertexAttribRestore {
100 public: 104 public:
101 AutoVertexAttribRestore(GrDrawState* drawState); 105 AutoVertexAttribRestore(GrDrawState* drawState);
102 106
103 ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPt r, fVACount, fVAStride); } 107 ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPt r, fVACount,
108 fVASt ride); }
104 109
105 private: 110 private:
106 GrDrawState* fDrawState; 111 GrDrawState* fDrawState;
107 const GrVertexAttrib* fVAPtr; 112 const GrVertexAttrib* fVAPtr;
108 int fVACount; 113 int fVACount;
109 size_t fVAStride; 114 size_t fVAStride;
110 }; 115 };
111 116
112 /// @} 117 /// @}
113 118
(...skipping 14 matching lines...) Expand all
128 /////////////////////////////////////////////////////////////////////////// 133 ///////////////////////////////////////////////////////////////////////////
129 /// @name Color 134 /// @name Color
130 //// 135 ////
131 136
132 /** 137 /**
133 * Sets color for next draw to a premultiplied-alpha color. 138 * Sets color for next draw to a premultiplied-alpha color.
134 * 139 *
135 * @param color the color to set. 140 * @param color the color to set.
136 */ 141 */
137 void setColor(GrColor color) { 142 void setColor(GrColor color) {
138 fColor = color; 143 if (color != fColor) {
139 this->invalidateBlendOptFlags(); 144 fColor = color;
145 this->invalidateOptState();
146 }
140 } 147 }
141 148
142 /** 149 /**
143 * Sets the color to be used for the next draw to be 150 * Sets the color to be used for the next draw to be
144 * (r,g,b,a) = (alpha, alpha, alpha, alpha). 151 * (r,g,b,a) = (alpha, alpha, alpha, alpha).
145 * 152 *
146 * @param alpha The alpha value to set as the color. 153 * @param alpha The alpha value to set as the color.
147 */ 154 */
148 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); } 155 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); }
149 156
150 /// @} 157 /// @}
151 158
152 /////////////////////////////////////////////////////////////////////////// 159 ///////////////////////////////////////////////////////////////////////////
153 /// @name Coverage 160 /// @name Coverage
154 //// 161 ////
155 162
156 /** 163 /**
157 * Sets a constant fractional coverage to be applied to the draw. The 164 * Sets a constant fractional coverage to be applied to the draw. The
158 * initial value (after construction or reset()) is 0xff. The constant 165 * initial value (after construction or reset()) is 0xff. The constant
159 * coverage is ignored when per-vertex coverage is provided. 166 * coverage is ignored when per-vertex coverage is provided.
160 */ 167 */
161 void setCoverage(uint8_t coverage) { 168 void setCoverage(uint8_t coverage) {
162 fCoverage = coverage; 169 if (coverage != fCoverage) {
163 this->invalidateBlendOptFlags(); 170 fCoverage = coverage;
171 this->invalidateOptState();
172 }
164 } 173 }
165 174
166 /// @} 175 /// @}
167 176
168 /** 177 /**
169 * The geometry processor is the sole element of the skia pipeline which can use the vertex, 178 * The geometry processor is the sole element of the skia pipeline which can use the vertex,
170 * geometry, and tesselation shaders. The GP may also compute a coverage in its fragment shader 179 * geometry, and tesselation shaders. The GP may also compute a coverage in its fragment shader
171 * but is never put in the color processing pipeline. 180 * but is never put in the color processing pipeline.
172 */ 181 */
173 182
174 const GrEffect* setGeometryProcessor(const GrEffect* effect, int attr0 = -1, int attr1 = -1) { 183 const GrEffect* setGeometryProcessor(const GrEffect* effect, int attr0 = -1, int attr1 = -1) {
bsalomon 2014/09/08 20:59:03 Don't need to inval here?
egdaniel 2014/09/11 15:35:42 Added inval (missed function from rebase) On 2014/
175 SkASSERT(effect); 184 SkASSERT(effect);
176 SkASSERT(!this->hasGeometryProcessor()); 185 SkASSERT(!this->hasGeometryProcessor());
177 fGeometryProcessor.reset(new GrEffectStage(effect, attr0, attr1)); 186 fGeometryProcessor.reset(new GrEffectStage(effect, attr0, attr1));
178 this->invalidateBlendOptFlags(); 187 this->invalidateBlendOptFlags();
179 return effect; 188 return effect;
180 } 189 }
181 190
182 /////////////////////////////////////////////////////////////////////////// 191 ///////////////////////////////////////////////////////////////////////////
183 /// @name Effect Stages 192 /// @name Effect Stages
184 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment 193 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment
(...skipping 10 matching lines...) Expand all
195 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage 204 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage
196 /// (usually full-coverage) or interpolated per-vertex coverage. 205 /// (usually full-coverage) or interpolated per-vertex coverage.
197 /// 206 ///
198 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the 207 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the
199 /// the color / coverage distinction. 208 /// the color / coverage distinction.
200 //// 209 ////
201 210
202 const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a ttr1 = -1) { 211 const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a ttr1 = -1) {
203 SkASSERT(effect); 212 SkASSERT(effect);
204 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1)); 213 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1));
205 this->invalidateBlendOptFlags(); 214 this->invalidateOptState();
206 return effect; 215 return effect;
207 } 216 }
208 217
209 const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in t attr1 = -1) { 218 const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in t attr1 = -1) {
210 SkASSERT(effect); 219 SkASSERT(effect);
211 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); 220 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1));
212 this->invalidateBlendOptFlags(); 221 this->invalidateOptState();
213 return effect; 222 return effect;
214 } 223 }
215 224
216 /** 225 /**
217 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin ates. 226 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin ates.
218 */ 227 */
219 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { 228 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
220 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un ref(); 229 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un ref();
221 } 230 }
222 231
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 * D' = sat(S*srcCoef + D*dstCoef) 303 * D' = sat(S*srcCoef + D*dstCoef)
295 * 304 *
296 * where D is the existing destination color, S is the incoming source 305 * where D is the existing destination color, S is the incoming source
297 * color, and D' is the new destination color that will be written. sat() 306 * color, and D' is the new destination color that will be written. sat()
298 * is the saturation function. 307 * is the saturation function.
299 * 308 *
300 * @param srcCoef coefficient applied to the src color. 309 * @param srcCoef coefficient applied to the src color.
301 * @param dstCoef coefficient applied to the dst color. 310 * @param dstCoef coefficient applied to the dst color.
302 */ 311 */
303 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { 312 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
304 fSrcBlend = srcCoeff; 313 if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) {
305 fDstBlend = dstCoeff; 314 fSrcBlend = srcCoeff;
306 this->invalidateBlendOptFlags(); 315 fDstBlend = dstCoeff;
316 this->invalidateOptState();
317 }
307 #ifdef SK_DEBUG 318 #ifdef SK_DEBUG
308 if (GrBlendCoeffRefsDst(dstCoeff)) { 319 if (GrBlendCoeffRefsDst(dstCoeff)) {
309 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n"); 320 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n");
310 } 321 }
311 if (GrBlendCoeffRefsSrc(srcCoeff)) { 322 if (GrBlendCoeffRefsSrc(srcCoeff)) {
312 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n"); 323 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n");
313 } 324 }
314 #endif 325 #endif
315 } 326 }
316 327
317 /** 328 /**
318 * Sets the blending function constant referenced by the following blending 329 * Sets the blending function constant referenced by the following blending
319 * coefficients: 330 * coefficients:
320 * kConstC_GrBlendCoeff 331 * kConstC_GrBlendCoeff
321 * kIConstC_GrBlendCoeff 332 * kIConstC_GrBlendCoeff
322 * kConstA_GrBlendCoeff 333 * kConstA_GrBlendCoeff
323 * kIConstA_GrBlendCoeff 334 * kIConstA_GrBlendCoeff
324 * 335 *
325 * @param constant the constant to set 336 * @param constant the constant to set
326 */ 337 */
327 void setBlendConstant(GrColor constant) { 338 void setBlendConstant(GrColor constant) {
328 fBlendConstant = constant; 339 if (constant != fBlendConstant) {
329 this->invalidateBlendOptFlags(); 340 fBlendConstant = constant;
341 // TODO: we should copy new blend
bsalomon 2014/09/08 20:59:03 incomplete comment?
egdaniel 2014/09/11 15:35:42 removed On 2014/09/08 20:59:03, bsalomon wrote:
342 this->invalidateOptState();
343 }
330 } 344 }
331 345
332 /**
333 * Determines what optimizations can be applied based on the blend. The coef ficients may have
334 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional
335 * params that receive the tweaked coefficients. Normally the function looks at the current
336 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively
337 * determine the blend optimizations that would be used if there was partial pixel coverage.
338 *
339 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for
340 * playback) must call this function and respect the flags that replace the output color.
341 *
342 * If the cached BlendOptFlags does not have the invalidate bit set, then ge tBlendOpts will
343 * simply returned the cached flags and coefficients. Otherwise it will calc ulate the values.
344 */
345 BlendOptFlags getBlendOpts(bool forceCoverage = false,
346 GrBlendCoeff* srcCoeff = NULL,
347 GrBlendCoeff* dstCoeff = NULL) const;
348
349 /**
350 * We don't use suplied vertex color attributes if our blend mode is EmitCov erage or
351 * EmitTransBlack
352 */
353 bool canIgnoreColorAttribute() const;
354
355
356 /// @} 346 /// @}
357 347
358 /////////////////////////////////////////////////////////////////////////// 348 ///////////////////////////////////////////////////////////////////////////
359 /// @name View Matrix 349 /// @name View Matrix
360 //// 350 ////
361 351
362 /** 352 /**
363 * Sets the view matrix to identity and updates any installed effects to com pensate for the 353 * Sets the view matrix to identity and updates any installed effects to com pensate for the
364 * coord system change. 354 * coord system change.
365 */ 355 */
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 /// @name Render Target 399 /// @name Render Target
410 //// 400 ////
411 401
412 /** 402 /**
413 * Sets the render-target used at the next drawing call 403 * Sets the render-target used at the next drawing call
414 * 404 *
415 * @param target The render target to set. 405 * @param target The render target to set.
416 */ 406 */
417 void setRenderTarget(GrRenderTarget* target) { 407 void setRenderTarget(GrRenderTarget* target) {
418 fRenderTarget.setResource(SkSafeRef(target), GrProgramResource::kWrite_I OType); 408 fRenderTarget.setResource(SkSafeRef(target), GrProgramResource::kWrite_I OType);
409 this->invalidateOptState();
419 } 410 }
420 411
421 /// @} 412 /// @}
422 413
423 /////////////////////////////////////////////////////////////////////////// 414 ///////////////////////////////////////////////////////////////////////////
424 /// @name Stencil 415 /// @name Stencil
425 //// 416 ////
426 417
427 /** 418 /**
428 * Sets the stencil settings to use for the next draw. 419 * Sets the stencil settings to use for the next draw.
429 * Changing the clip has the side-effect of possibly zeroing 420 * Changing the clip has the side-effect of possibly zeroing
430 * out the client settable stencil bits. So multipass algorithms 421 * out the client settable stencil bits. So multipass algorithms
431 * using stencil should not change the clip between passes. 422 * using stencil should not change the clip between passes.
432 * @param settings the stencil settings to use. 423 * @param settings the stencil settings to use.
433 */ 424 */
434 void setStencil(const GrStencilSettings& settings) { 425 void setStencil(const GrStencilSettings& settings) {
435 fStencilSettings = settings; 426 if (settings != fStencilSettings) {
436 this->invalidateBlendOptFlags(); 427 fStencilSettings = settings;
428 this->invalidateOptState();
429 }
437 } 430 }
438 431
439 /** 432 /**
440 * Shortcut to disable stencil testing and ops. 433 * Shortcut to disable stencil testing and ops.
441 */ 434 */
442 void disableStencil() { 435 void disableStencil() {
443 fStencilSettings.setDisabled(); 436 if (!fStencilSettings.isDisabled()) {
444 this->invalidateBlendOptFlags(); 437 fStencilSettings.setDisabled();
438 this->invalidateOptState();
439 }
445 } 440 }
446 441
447 GrStencilSettings* stencil() { return &fStencilSettings; } 442 GrStencilSettings* stencil() { return &fStencilSettings; }
448 443
449 /// @} 444 /// @}
450 445
451 /////////////////////////////////////////////////////////////////////////// 446 ///////////////////////////////////////////////////////////////////////////
452 /// @name State Flags 447 /// @name State Flags
453 //// 448 ////
454 449
455 void resetStateFlags() { 450 void resetStateFlags() {
456 fFlagBits = 0; 451 if (0 != fFlagBits) {
457 this->invalidateBlendOptFlags(); 452 fFlagBits = 0;
453 this->invalidateOptState();
454 }
458 } 455 }
459 456
460 /** 457 /**
461 * Enable render state settings. 458 * Enable render state settings.
462 * 459 *
463 * @param stateBits bitfield of StateBits specifying the states to enable 460 * @param stateBits bitfield of StateBits specifying the states to enable
464 */ 461 */
465 void enableState(uint32_t stateBits) { 462 void enableState(uint32_t stateBits) {
466 fFlagBits |= stateBits; 463 if (stateBits & ~fFlagBits) {
467 this->invalidateBlendOptFlags(); 464 fFlagBits |= stateBits;
465 this->invalidateOptState();
466 }
468 } 467 }
469 468
470 /** 469 /**
471 * Disable render state settings. 470 * Disable render state settings.
472 * 471 *
473 * @param stateBits bitfield of StateBits specifying the states to disable 472 * @param stateBits bitfield of StateBits specifying the states to disable
474 */ 473 */
475 void disableState(uint32_t stateBits) { 474 void disableState(uint32_t stateBits) {
476 fFlagBits &= ~(stateBits); 475 if (stateBits & fFlagBits) {
477 this->invalidateBlendOptFlags(); 476 fFlagBits &= ~(stateBits);
477 this->invalidateOptState();
478 }
478 } 479 }
479 480
480 /** 481 /**
481 * Enable or disable stateBits based on a boolean. 482 * Enable or disable stateBits based on a boolean.
482 * 483 *
483 * @param stateBits bitfield of StateBits to enable or disable 484 * @param stateBits bitfield of StateBits to enable or disable
484 * @param enable if true enable stateBits, otherwise disable 485 * @param enable if true enable stateBits, otherwise disable
485 */ 486 */
486 void setState(uint32_t stateBits, bool enable) { 487 void setState(uint32_t stateBits, bool enable) {
487 if (enable) { 488 if (enable) {
(...skipping 18 matching lines...) Expand all
506 fDrawFace = face; 507 fDrawFace = face;
507 } 508 }
508 509
509 /// @} 510 /// @}
510 511
511 /////////////////////////////////////////////////////////////////////////// 512 ///////////////////////////////////////////////////////////////////////////
512 /// @name Hints 513 /// @name Hints
513 /// Hints that when provided can enable optimizations. 514 /// Hints that when provided can enable optimizations.
514 //// 515 ////
515 516
516 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, };
517
518 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f Hints & ~hint); } 517 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f Hints & ~hint); }
519 518
520 /// @} 519 /// @}
521 520
522 /////////////////////////////////////////////////////////////////////////// 521 ///////////////////////////////////////////////////////////////////////////
523 522
524 /** Return type for CombineIfPossible. */ 523 /** Return type for CombineIfPossible. */
525 enum CombinedState { 524 enum CombinedState {
526 /** The GrDrawStates cannot be combined. */ 525 /** The GrDrawStates cannot be combined. */
527 kIncompatible_CombinedState, 526 kIncompatible_CombinedState,
528 /** Either draw state can be used in place of the other. */ 527 /** Either draw state can be used in place of the other. */
529 kAOrB_CombinedState, 528 kAOrB_CombinedState,
530 /** Use the first draw state. */ 529 /** Use the first draw state. */
531 kA_CombinedState, 530 kA_CombinedState,
532 /** Use the second draw state. */ 531 /** Use the second draw state. */
533 kB_CombinedState, 532 kB_CombinedState,
534 }; 533 };
535 534
536 /** This function determines whether the GrDrawStates used for two draws can be combined into 535 /** This function determines whether the GrDrawStates used for two draws can be combined into
537 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine 536 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine
538 if draws can be batched. The return value indicates whether combining is possible and, if 537 if draws can be batched. The return value indicates whether combining is possible and, if
539 so, which of the two inputs should be used. */ 538 so, which of the two inputs should be used. */
540 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b, 539 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b,
541 const GrDrawTargetCaps& caps); 540 const GrDrawTargetCaps& caps);
542 541
543 GrDrawState& operator= (const GrDrawState& that); 542 GrDrawState& operator= (const GrDrawState& that);
544 543
544 /**
545 * Returns a snapshot of the current optimized state. If the current drawSta te has a valid
546 * cached optimiezed state it will simply return a pointer to it otherwise i t will create a new
547 * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership i s given to the
548 * caller.
549 */
550 GrOptDrawState* createOptState() const;
551
545 private: 552 private:
553 void invalidateBlendOptFlags() const {
bsalomon 2014/09/08 20:59:03 if invalidateOptState() is the only caller of this
egdaniel 2014/09/11 15:35:42 Merged together On 2014/09/08 20:59:03, bsalomon w
554 fBlendOptFlags = kInvalid_BlendOptFlag;
555 }
556
557 void invalidateOptState() const {
558 SkSafeSetNull(fCachedOptState);
559 this->invalidateBlendOptFlags();
560 }
561
546 void onReset(const SkMatrix* initialViewMatrix); 562 void onReset(const SkMatrix* initialViewMatrix);
547 563
548 /**
549 * Determines whether src alpha is guaranteed to be one for all src pixels
550 */
551 bool srcAlphaWillBeOne() const;
552
553 /**
554 * Helper function for getBlendOpts.
555 */
556 BlendOptFlags calcBlendOpts(bool forceCoverage = false,
557 GrBlendCoeff* srcCoeff = NULL,
558 GrBlendCoeff* dstCoeff = NULL) const;
559
560 void invalidateBlendOptFlags() { 564 void invalidateBlendOptFlags() {
561 fBlendOptFlags = kInvalid_BlendOptFlag; 565 fBlendOptFlags = kInvalid_BlendOptFlag;
562 } 566 }
563 567
564 uint32_t fHints;
565
566 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. 568 // Some of the auto restore objects assume that no effects are removed durin g their lifetime.
567 // This is used to assert that this condition holds. 569 // This is used to assert that this condition holds.
568 SkDEBUGCODE(int fBlockEffectRemovalCnt;) 570 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
569 571
570 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz e_t stride); 572 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz e_t stride);
571 573
574 mutable GrOptDrawState* fCachedOptState;
575
572 typedef GrRODrawState INHERITED; 576 typedef GrRODrawState INHERITED;
573 }; 577 };
574 578
575 #endif 579 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrDrawState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698