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

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: Updates 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
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"
12 #include "GrOptDrawState.h"
11 #include "GrRODrawState.h" 13 #include "GrRODrawState.h"
12
13 #include "GrBlend.h"
14 #include "effects/GrSimpleTextureEffect.h" 14 #include "effects/GrSimpleTextureEffect.h"
15 15
16 /** 16 /**
17 * Modifiable subclass derived from GrRODrawState. The majority of the data that represents a draw 17 * 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. 18 * 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 19 * various data members of the draw state. This class is used to configure the s tate used when
20 * issuing draws via GrDrawTarget. 20 * issuing draws via GrDrawTarget.
21 */ 21 */
22 class GrDrawState : public GrRODrawState { 22 class GrDrawState : public GrRODrawState {
23 public: 23 public:
24 SK_DECLARE_INST_COUNT(GrDrawState) 24 SK_DECLARE_INST_COUNT(GrDrawState)
25 25
26 GrDrawState() { 26 GrDrawState() : fCachedOptState(NULL) {
27 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 27 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
28 this->reset(); 28 this->reset();
29 } 29 }
30 30
31 GrDrawState(const SkMatrix& initialViewMatrix) { 31 GrDrawState(const SkMatrix& initialViewMatrix) : fCachedOptState(NULL) {
32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
33 this->reset(initialViewMatrix); 33 this->reset(initialViewMatrix);
34 } 34 }
35 35
36 /** 36 /**
37 * Copies another draw state. 37 * Copies another draw state.
38 **/ 38 **/
39 GrDrawState(const GrDrawState& state) : INHERITED() { 39 GrDrawState(const GrDrawState& state) : INHERITED(), fCachedOptState(NULL) {
40 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 40 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
41 *this = state; 41 *this = state;
42 } 42 }
43 43
44 /** 44 /**
45 * Copies another draw state with a preconcat to the view matrix. 45 * Copies another draw state with a preconcat to the view matrix.
46 **/ 46 **/
47 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix); 47 GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix);
48 48
49 virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); } 49 virtual ~GrDrawState() {
50 SkSafeUnref(fCachedOptState);
51 SkASSERT(0 == fBlockEffectRemovalCnt);
52 }
50 53
51 /** 54 /**
52 * Resets to the default state. GrEffects will be removed from all stages. 55 * Resets to the default state. GrEffects will be removed from all stages.
53 */ 56 */
54 void reset() { this->onReset(NULL); } 57 void reset() { this->onReset(NULL); }
55 58
56 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa trix); } 59 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa trix); }
57 60
58 /** 61 /**
59 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta rget. Note that 62 * 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 */ 96 */
94 void setDefaultVertexAttribs(); 97 void setDefaultVertexAttribs();
95 98
96 /** 99 /**
97 * Helper to save/restore vertex attribs 100 * Helper to save/restore vertex attribs
98 */ 101 */
99 class AutoVertexAttribRestore { 102 class AutoVertexAttribRestore {
100 public: 103 public:
101 AutoVertexAttribRestore(GrDrawState* drawState); 104 AutoVertexAttribRestore(GrDrawState* drawState);
102 105
103 ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPt r, fVACount, fVAStride); } 106 ~AutoVertexAttribRestore() { fDrawState->internalSetVertexAttribs(fVAPt r, fVACount, fVAStride); }
bsalomon 2014/08/28 15:05:02 This guy no longer fits on one line.
104 107
105 private: 108 private:
106 GrDrawState* fDrawState; 109 GrDrawState* fDrawState;
107 const GrVertexAttrib* fVAPtr; 110 const GrVertexAttrib* fVAPtr;
108 int fVACount; 111 int fVACount;
109 size_t fVAStride; 112 size_t fVAStride;
110 }; 113 };
111 114
112 /// @} 115 /// @}
113 116
(...skipping 14 matching lines...) Expand all
128 /////////////////////////////////////////////////////////////////////////// 131 ///////////////////////////////////////////////////////////////////////////
129 /// @name Color 132 /// @name Color
130 //// 133 ////
131 134
132 /** 135 /**
133 * Sets color for next draw to a premultiplied-alpha color. 136 * Sets color for next draw to a premultiplied-alpha color.
134 * 137 *
135 * @param color the color to set. 138 * @param color the color to set.
136 */ 139 */
137 void setColor(GrColor color) { 140 void setColor(GrColor color) {
138 fColor = color; 141 if (color != fColor) {
139 this->invalidateBlendOptFlags(); 142 fColor = color;
143 this->invalidateOptState();
144 }
140 } 145 }
141 146
142 /** 147 /**
143 * Sets the color to be used for the next draw to be 148 * Sets the color to be used for the next draw to be
144 * (r,g,b,a) = (alpha, alpha, alpha, alpha). 149 * (r,g,b,a) = (alpha, alpha, alpha, alpha).
145 * 150 *
146 * @param alpha The alpha value to set as the color. 151 * @param alpha The alpha value to set as the color.
147 */ 152 */
148 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); } 153 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); }
149 154
150 /// @} 155 /// @}
151 156
152 /////////////////////////////////////////////////////////////////////////// 157 ///////////////////////////////////////////////////////////////////////////
153 /// @name Coverage 158 /// @name Coverage
154 //// 159 ////
155 160
156 /** 161 /**
157 * Sets a constant fractional coverage to be applied to the draw. The 162 * Sets a constant fractional coverage to be applied to the draw. The
158 * initial value (after construction or reset()) is 0xff. The constant 163 * initial value (after construction or reset()) is 0xff. The constant
159 * coverage is ignored when per-vertex coverage is provided. 164 * coverage is ignored when per-vertex coverage is provided.
160 */ 165 */
161 void setCoverage(uint8_t coverage) { 166 void setCoverage(uint8_t coverage) {
162 fCoverage = coverage; 167 if (coverage != fCoverage) {
163 this->invalidateBlendOptFlags(); 168 fCoverage = coverage;
169 this->invalidateOptState();
170 }
164 } 171 }
165 172
166 /// @} 173 /// @}
167 174
168 /////////////////////////////////////////////////////////////////////////// 175 ///////////////////////////////////////////////////////////////////////////
169 /// @name Effect Stages 176 /// @name Effect Stages
170 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment 177 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment
171 /// shader. Its inputs are the output from the previous stage as well as som e variables 178 /// shader. Its inputs are the output from the previous stage as well as som e variables
172 /// available to it in the fragment and vertex shader (e.g. the vertex posit ion, the dst color, 179 /// available to it in the fragment and vertex shader (e.g. the vertex posit ion, the dst color,
173 /// the fragment position, local coordinates). 180 /// the fragment position, local coordinates).
174 /// 181 ///
175 /// The stages are divided into two sets, color-computing and coverage-compu ting. The final 182 /// The stages are divided into two sets, color-computing and coverage-compu ting. The final
176 /// color stage produces the final pixel color. The coverage-computing stage s function exactly 183 /// color stage produces the final pixel color. The coverage-computing stage s function exactly
177 /// as the color-computing but the output of the final coverage stage is tre ated as a fractional 184 /// as the color-computing but the output of the final coverage stage is tre ated as a fractional
178 /// pixel coverage rather than as input to the src/dst color blend step. 185 /// pixel coverage rather than as input to the src/dst color blend step.
179 /// 186 ///
180 /// The input color to the first color-stage is either the constant color or interpolated 187 /// The input color to the first color-stage is either the constant color or interpolated
181 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage 188 /// per-vertex colors. The input to the first coverage stage is either a con stant coverage
182 /// (usually full-coverage) or interpolated per-vertex coverage. 189 /// (usually full-coverage) or interpolated per-vertex coverage.
183 /// 190 ///
184 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the 191 /// See the documentation of kCoverageDrawing_StateBit for information about disabling the
185 /// the color / coverage distinction. 192 /// the color / coverage distinction.
186 //// 193 ////
187 194
188 const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a ttr1 = -1) { 195 const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int a ttr1 = -1) {
189 SkASSERT(NULL != effect); 196 SkASSERT(NULL != effect);
190 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1)); 197 SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, att r1));
191 this->invalidateBlendOptFlags(); 198 this->invalidateOptState();
192 return effect; 199 return effect;
193 } 200 }
194 201
195 const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in t attr1 = -1) { 202 const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, in t attr1 = -1) {
196 SkASSERT(NULL != effect); 203 SkASSERT(NULL != effect);
197 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1)); 204 SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1));
198 this->invalidateBlendOptFlags(); 205 this->invalidateOptState();
199 return effect; 206 return effect;
200 } 207 }
201 208
202 /** 209 /**
203 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin ates. 210 * Creates a GrSimpleTextureEffect that uses local coords as texture coordin ates.
204 */ 211 */
205 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) { 212 void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
206 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un ref(); 213 this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->un ref();
207 } 214 }
208 215
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 * D' = sat(S*srcCoef + D*dstCoef) 266 * D' = sat(S*srcCoef + D*dstCoef)
260 * 267 *
261 * where D is the existing destination color, S is the incoming source 268 * where D is the existing destination color, S is the incoming source
262 * color, and D' is the new destination color that will be written. sat() 269 * color, and D' is the new destination color that will be written. sat()
263 * is the saturation function. 270 * is the saturation function.
264 * 271 *
265 * @param srcCoef coefficient applied to the src color. 272 * @param srcCoef coefficient applied to the src color.
266 * @param dstCoef coefficient applied to the dst color. 273 * @param dstCoef coefficient applied to the dst color.
267 */ 274 */
268 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) { 275 void setBlendFunc(GrBlendCoeff srcCoeff, GrBlendCoeff dstCoeff) {
269 fSrcBlend = srcCoeff; 276 if (srcCoeff != fSrcBlend || dstCoeff != fDstBlend) {
270 fDstBlend = dstCoeff; 277 fSrcBlend = srcCoeff;
271 this->invalidateBlendOptFlags(); 278 fDstBlend = dstCoeff;
279 this->invalidateOptState();
280 }
272 #ifdef SK_DEBUG 281 #ifdef SK_DEBUG
273 if (GrBlendCoeffRefsDst(dstCoeff)) { 282 if (GrBlendCoeffRefsDst(dstCoeff)) {
274 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n"); 283 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n");
275 } 284 }
276 if (GrBlendCoeffRefsSrc(srcCoeff)) { 285 if (GrBlendCoeffRefsSrc(srcCoeff)) {
277 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n"); 286 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n");
278 } 287 }
279 #endif 288 #endif
280 } 289 }
281 290
282 /** 291 /**
283 * Sets the blending function constant referenced by the following blending 292 * Sets the blending function constant referenced by the following blending
284 * coefficients: 293 * coefficients:
285 * kConstC_GrBlendCoeff 294 * kConstC_GrBlendCoeff
286 * kIConstC_GrBlendCoeff 295 * kIConstC_GrBlendCoeff
287 * kConstA_GrBlendCoeff 296 * kConstA_GrBlendCoeff
288 * kIConstA_GrBlendCoeff 297 * kIConstA_GrBlendCoeff
289 * 298 *
290 * @param constant the constant to set 299 * @param constant the constant to set
291 */ 300 */
292 void setBlendConstant(GrColor constant) { 301 void setBlendConstant(GrColor constant) {
293 fBlendConstant = constant; 302 if (constant != fBlendConstant) {
294 this->invalidateBlendOptFlags(); 303 fBlendConstant = constant;
304 this->invalidateOptState();
305 }
295 } 306 }
296 307
297 /**
298 * Determines what optimizations can be applied based on the blend. The coef ficients may have
299 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional
300 * params that receive the tweaked coefficients. Normally the function looks at the current
301 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively
302 * determine the blend optimizations that would be used if there was partial pixel coverage.
303 *
304 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for
305 * playback) must call this function and respect the flags that replace the output color.
306 *
307 * If the cached BlendOptFlags does not have the invalidate bit set, then ge tBlendOpts will
308 * simply returned the cached flags and coefficients. Otherwise it will calc ulate the values.
309 */
310 BlendOptFlags getBlendOpts(bool forceCoverage = false,
311 GrBlendCoeff* srcCoeff = NULL,
312 GrBlendCoeff* dstCoeff = NULL) const;
313
314 /**
315 * We don't use suplied vertex color attributes if our blend mode is EmitCov erage or
316 * EmitTransBlack
317 */
318 bool canIgnoreColorAttribute() const;
319
320
321 /// @} 308 /// @}
322 309
323 /////////////////////////////////////////////////////////////////////////// 310 ///////////////////////////////////////////////////////////////////////////
324 /// @name View Matrix 311 /// @name View Matrix
325 //// 312 ////
326 313
327 /** 314 /**
328 * Sets the view matrix to identity and updates any installed effects to com pensate for the 315 * Sets the view matrix to identity and updates any installed effects to com pensate for the
329 * coord system change. 316 * coord system change.
330 */ 317 */
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 358
372 /////////////////////////////////////////////////////////////////////////// 359 ///////////////////////////////////////////////////////////////////////////
373 /// @name Render Target 360 /// @name Render Target
374 //// 361 ////
375 362
376 /** 363 /**
377 * Sets the render-target used at the next drawing call 364 * Sets the render-target used at the next drawing call
378 * 365 *
379 * @param target The render target to set. 366 * @param target The render target to set.
380 */ 367 */
381 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef (target)); } 368 void setRenderTarget(GrRenderTarget* target) {
369 fRenderTarget.reset(SkSafeRef(target));
370 this->invalidateOptState();
371 }
382 372
383 class AutoRenderTargetRestore : public ::SkNoncopyable { 373 class AutoRenderTargetRestore : public ::SkNoncopyable {
384 public: 374 public:
385 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} 375 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {}
386 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { 376 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) {
387 fDrawState = NULL; 377 fDrawState = NULL;
388 fSavedTarget = NULL; 378 fSavedTarget = NULL;
389 this->set(ds, newTarget); 379 this->set(ds, newTarget);
390 } 380 }
391 ~AutoRenderTargetRestore() { this->restore(); } 381 ~AutoRenderTargetRestore() { this->restore(); }
(...skipping 29 matching lines...) Expand all
421 //// 411 ////
422 412
423 /** 413 /**
424 * Sets the stencil settings to use for the next draw. 414 * Sets the stencil settings to use for the next draw.
425 * Changing the clip has the side-effect of possibly zeroing 415 * Changing the clip has the side-effect of possibly zeroing
426 * out the client settable stencil bits. So multipass algorithms 416 * out the client settable stencil bits. So multipass algorithms
427 * using stencil should not change the clip between passes. 417 * using stencil should not change the clip between passes.
428 * @param settings the stencil settings to use. 418 * @param settings the stencil settings to use.
429 */ 419 */
430 void setStencil(const GrStencilSettings& settings) { 420 void setStencil(const GrStencilSettings& settings) {
431 fStencilSettings = settings; 421 if (settings != fStencilSettings) {
432 this->invalidateBlendOptFlags(); 422 fStencilSettings = settings;
423 this->invalidateOptState();
424 }
433 } 425 }
434 426
435 /** 427 /**
436 * Shortcut to disable stencil testing and ops. 428 * Shortcut to disable stencil testing and ops.
437 */ 429 */
438 void disableStencil() { 430 void disableStencil() {
439 fStencilSettings.setDisabled(); 431 if (!fStencilSettings.isDisabled()) {
440 this->invalidateBlendOptFlags(); 432 fStencilSettings.setDisabled();
433 this->invalidateOptState();
434 }
441 } 435 }
442 436
443 GrStencilSettings* stencil() { return &fStencilSettings; } 437 GrStencilSettings* stencil() { return &fStencilSettings; }
444 438
445 /// @} 439 /// @}
446 440
447 /////////////////////////////////////////////////////////////////////////// 441 ///////////////////////////////////////////////////////////////////////////
448 /// @name State Flags 442 /// @name State Flags
449 //// 443 ////
450 444
451 void resetStateFlags() { 445 void resetStateFlags() {
452 fFlagBits = 0; 446 if (0 != fFlagBits) {
453 this->invalidateBlendOptFlags(); 447 fFlagBits = 0;
448 this->invalidateOptState();
449 }
454 } 450 }
455 451
456 /** 452 /**
457 * Enable render state settings. 453 * Enable render state settings.
458 * 454 *
459 * @param stateBits bitfield of StateBits specifying the states to enable 455 * @param stateBits bitfield of StateBits specifying the states to enable
460 */ 456 */
461 void enableState(uint32_t stateBits) { 457 void enableState(uint32_t stateBits) {
462 fFlagBits |= stateBits; 458 if (stateBits & ~fFlagBits) {
463 this->invalidateBlendOptFlags(); 459 fFlagBits |= stateBits;
460 this->invalidateOptState();
461 }
464 } 462 }
465 463
466 /** 464 /**
467 * Disable render state settings. 465 * Disable render state settings.
468 * 466 *
469 * @param stateBits bitfield of StateBits specifying the states to disable 467 * @param stateBits bitfield of StateBits specifying the states to disable
470 */ 468 */
471 void disableState(uint32_t stateBits) { 469 void disableState(uint32_t stateBits) {
472 fFlagBits &= ~(stateBits); 470 if (stateBits & fFlagBits) {
473 this->invalidateBlendOptFlags(); 471 fFlagBits &= ~(stateBits);
472 this->invalidateOptState();
473 }
474 } 474 }
475 475
476 /** 476 /**
477 * Enable or disable stateBits based on a boolean. 477 * Enable or disable stateBits based on a boolean.
478 * 478 *
479 * @param stateBits bitfield of StateBits to enable or disable 479 * @param stateBits bitfield of StateBits to enable or disable
480 * @param enable if true enable stateBits, otherwise disable 480 * @param enable if true enable stateBits, otherwise disable
481 */ 481 */
482 void setState(uint32_t stateBits, bool enable) { 482 void setState(uint32_t stateBits, bool enable) {
483 if (enable) { 483 if (enable) {
(...skipping 18 matching lines...) Expand all
502 fDrawFace = face; 502 fDrawFace = face;
503 } 503 }
504 504
505 /// @} 505 /// @}
506 506
507 /////////////////////////////////////////////////////////////////////////// 507 ///////////////////////////////////////////////////////////////////////////
508 /// @name Hints 508 /// @name Hints
509 /// Hints that when provided can enable optimizations. 509 /// Hints that when provided can enable optimizations.
510 //// 510 ////
511 511
512 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, };
513
514 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f Hints & ~hint); } 512 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f Hints & ~hint); }
515 513
516 /// @} 514 /// @}
517 515
518 /////////////////////////////////////////////////////////////////////////// 516 ///////////////////////////////////////////////////////////////////////////
519 517
520 /** Return type for CombineIfPossible. */ 518 /** Return type for CombineIfPossible. */
521 enum CombinedState { 519 enum CombinedState {
522 /** The GrDrawStates cannot be combined. */ 520 /** The GrDrawStates cannot be combined. */
523 kIncompatible_CombinedState, 521 kIncompatible_CombinedState,
524 /** Either draw state can be used in place of the other. */ 522 /** Either draw state can be used in place of the other. */
525 kAOrB_CombinedState, 523 kAOrB_CombinedState,
526 /** Use the first draw state. */ 524 /** Use the first draw state. */
527 kA_CombinedState, 525 kA_CombinedState,
528 /** Use the second draw state. */ 526 /** Use the second draw state. */
529 kB_CombinedState, 527 kB_CombinedState,
530 }; 528 };
531 529
532 /** This function determines whether the GrDrawStates used for two draws can be combined into 530 /** This function determines whether the GrDrawStates used for two draws can be combined into
533 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine 531 a single GrDrawState. This is used to avoid storing redundant GrDrawStat es and to determine
534 if draws can be batched. The return value indicates whether combining is possible and, if 532 if draws can be batched. The return value indicates whether combining is possible and, if
535 so, which of the two inputs should be used. */ 533 so, which of the two inputs should be used. */
536 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b, 534 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b,
537 const GrDrawTargetCaps& caps); 535 const GrDrawTargetCaps& caps);
538 536
539 GrDrawState& operator= (const GrDrawState& that); 537 GrDrawState& operator= (const GrDrawState& that);
540 538
539 /**
540 * Returns a snapshot of the current optimized state. If the current drawSta te has a valid
541 * cached optimiezed state it will simply return a pointer to it otherwise i t will create a new
542 * GrOptDrawState. In all cases the GrOptDrawState is reffed and ownership i s given to the
543 * caller.
544 */
545 GrOptDrawState* createOptState() const;
546
541 private: 547 private:
548 void invalidateBlendOptFlags() const {
549 fBlendOptFlags = kInvalid_BlendOptFlag;
550 }
551
552 void invalidateOptState() const {
553 SkSafeSetNull(fCachedOptState);
554 this->invalidateBlendOptFlags();
555 }
556
542 void onReset(const SkMatrix* initialViewMatrix); 557 void onReset(const SkMatrix* initialViewMatrix);
543 558
544 /**
545 * Determines whether src alpha is guaranteed to be one for all src pixels
546 */
547 bool srcAlphaWillBeOne() const;
548
549 /**
550 * Helper function for getBlendOpts.
551 */
552 BlendOptFlags calcBlendOpts(bool forceCoverage = false,
553 GrBlendCoeff* srcCoeff = NULL,
554 GrBlendCoeff* dstCoeff = NULL) const;
555
556 void invalidateBlendOptFlags() { 559 void invalidateBlendOptFlags() {
557 fBlendOptFlags = kInvalid_BlendOptFlag; 560 fBlendOptFlags = kInvalid_BlendOptFlag;
558 } 561 }
559 562
560 uint32_t fHints;
561
562 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. 563 // Some of the auto restore objects assume that no effects are removed durin g their lifetime.
563 // This is used to assert that this condition holds. 564 // This is used to assert that this condition holds.
564 SkDEBUGCODE(int fBlockEffectRemovalCnt;) 565 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
565 566
566 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz e_t stride); 567 void internalSetVertexAttribs(const GrVertexAttrib attribs[], int count, siz e_t stride);
567 568
569 mutable GrOptDrawState* fCachedOptState;
570
568 typedef GrRODrawState INHERITED; 571 typedef GrRODrawState INHERITED;
569 }; 572 };
570 573
571 #endif 574 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrDrawState.cpp » ('j') | src/gpu/GrRODrawState.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698