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

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

Issue 506803003: Create Read-only Base class for GrDrawState that holds data members and getters (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Nits 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 "GrRODrawState.h"
12
11 #include "GrBlend.h" 13 #include "GrBlend.h"
12 #include "GrColor.h"
13 #include "GrEffectStage.h"
14 #include "GrStencil.h"
15 #include "effects/GrSimpleTextureEffect.h" 14 #include "effects/GrSimpleTextureEffect.h"
16 15
17 #include "SkMatrix.h" 16 /**
18 17 * Modifiable subclass derived from GrRODrawState. The majority of the data that represents a draw
19 class GrDrawTargetCaps; 18 * state is stored in the parent class. GrDrawState contains methods for setting , adding to, etc.
20 class GrPaint; 19 * various data members of the draw state. This class is used to configure the s tate used when
21 class GrRenderTarget; 20 * issuing draws via GrDrawTarget.
22 class GrTexture; 21 */
23 22 class GrDrawState : public GrRODrawState {
24 class GrDrawState : public SkRefCnt {
25 public: 23 public:
26 SK_DECLARE_INST_COUNT(GrDrawState) 24 SK_DECLARE_INST_COUNT(GrDrawState)
27 25
28 GrDrawState() { 26 GrDrawState() {
29 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 27 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
30 this->reset(); 28 this->reset();
31 } 29 }
32 30
33 GrDrawState(const SkMatrix& initialViewMatrix) { 31 GrDrawState(const SkMatrix& initialViewMatrix) {
34 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) 32 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
(...skipping 27 matching lines...) Expand all
62 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha ve no GrPaint 60 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha ve no GrPaint
63 * equivalents are set to default values with the exception of vertex attrib ute state which 61 * equivalents are set to default values with the exception of vertex attrib ute state which
64 * is unmodified by this function and clipping which will be enabled. 62 * is unmodified by this function and clipping which will be enabled.
65 */ 63 */
66 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge t*); 64 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge t*);
67 65
68 /////////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////////
69 /// @name Vertex Attributes 67 /// @name Vertex Attributes
70 //// 68 ////
71 69
72 enum {
73 kMaxVertexAttribCnt = kLast_GrVertexAttribBinding + 4,
74 };
75
76 /** 70 /**
77 * The format of vertices is represented as an array of GrVertexAttribs, wit h each representing 71 * The format of vertices is represented as an array of GrVertexAttribs, wit h each representing
78 * the type of the attribute, its offset, and semantic binding (see GrVertex Attrib in 72 * the type of the attribute, its offset, and semantic binding (see GrVertex Attrib in
79 * GrTypesPriv.h). 73 * GrTypesPriv.h).
80 * 74 *
81 * The mapping of attributes with kEffect bindings to GrEffect inputs is spe cified when 75 * The mapping of attributes with kEffect bindings to GrEffect inputs is spe cified when
82 * setEffect is called. 76 * setEffect is called.
83 */ 77 */
84 78
85 /** 79 /**
86 * Sets vertex attributes for next draw. The object driving the templatizat ion 80 * Sets vertex attributes for next draw. The object driving the templatizat ion
87 * should be a global GrVertexAttrib array that is never changed. 81 * should be a global GrVertexAttrib array that is never changed.
88 */ 82 */
89 template <const GrVertexAttrib A[]> void setVertexAttribs(int count) { 83 template <const GrVertexAttrib A[]> void setVertexAttribs(int count) {
90 this->setVertexAttribs(A, count); 84 this->setVertexAttribs(A, count);
91 } 85 }
92 86
93 const GrVertexAttrib* getVertexAttribs() const { return fVAPtr; }
94 int getVertexAttribCount() const { return fVACount; }
95
96 size_t getVertexSize() const;
97
98 /** 87 /**
99 * Sets default vertex attributes for next draw. The default is a single at tribute: 88 * Sets default vertex attributes for next draw. The default is a single at tribute:
100 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType} 89 * {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribType}
101 */ 90 */
102 void setDefaultVertexAttribs(); 91 void setDefaultVertexAttribs();
103 92
104 /** 93 /**
105 * Getters for index into getVertexAttribs() for particular bindings. -1 is returned if the
106 * binding does not appear in the current attribs. These bindings should app ear only once in
107 * the attrib array.
108 */
109
110 int positionAttributeIndex() const {
111 return fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding ];
112 }
113 int localCoordAttributeIndex() const {
114 return fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttribBindi ng];
115 }
116 int colorVertexAttributeIndex() const {
117 return fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBinding];
118 }
119 int coverageVertexAttributeIndex() const {
120 return fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribBinding ];
121 }
122
123 bool hasLocalCoordAttribute() const {
124 return -1 != fFixedFunctionVertexAttribIndices[kLocalCoord_GrVertexAttri bBinding];
125 }
126 bool hasColorVertexAttribute() const {
127 return -1 != fFixedFunctionVertexAttribIndices[kColor_GrVertexAttribBind ing];
128 }
129 bool hasCoverageVertexAttribute() const {
130 return -1 != fFixedFunctionVertexAttribIndices[kCoverage_GrVertexAttribB inding];
131 }
132
133 bool validateVertexAttribs() const;
134
135 /**
136 * Helper to save/restore vertex attribs 94 * Helper to save/restore vertex attribs
137 */ 95 */
138 class AutoVertexAttribRestore { 96 class AutoVertexAttribRestore {
139 public: 97 public:
140 AutoVertexAttribRestore(GrDrawState* drawState); 98 AutoVertexAttribRestore(GrDrawState* drawState);
141 99
142 ~AutoVertexAttribRestore() { fDrawState->setVertexAttribs(fVAPtr, fVACo unt); } 100 ~AutoVertexAttribRestore() { fDrawState->setVertexAttribs(fVAPtr, fVACo unt); }
143 101
144 private: 102 private:
145 GrDrawState* fDrawState; 103 GrDrawState* fDrawState;
146 const GrVertexAttrib* fVAPtr; 104 const GrVertexAttrib* fVAPtr;
147 int fVACount; 105 int fVACount;
148 }; 106 };
149 107
150 /// @} 108 /// @}
151 109
152 /** 110 /**
153 * Determines whether src alpha is guaranteed to be one for all src pixels
154 */
155 bool srcAlphaWillBeOne() const;
156
157 /**
158 * Determines whether the output coverage is guaranteed to be one for all pi xels hit by a draw.
159 */
160 bool hasSolidCoverage() const;
161
162 /**
163 * Depending on features available in the underlying 3D API and the color bl end mode requested 111 * Depending on features available in the underlying 3D API and the color bl end mode requested
164 * it may or may not be possible to correctly blend with fractional pixel co verage generated by 112 * it may or may not be possible to correctly blend with fractional pixel co verage generated by
165 * the fragment shader. 113 * the fragment shader.
166 * 114 *
167 * This function considers the current draw state and the draw target's capa bilities to 115 * This function considers the current draw state and the draw target's capa bilities to
168 * determine whether coverage can be handled correctly. This function assume s that the caller 116 * determine whether coverage can be handled correctly. This function assume s that the caller
169 * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex 117 * intends to specify fractional pixel coverage (via setCoverage(), through a coverage vertex
170 * attribute, or a coverage effect) but may not have specified it yet. 118 * attribute, or a coverage effect) but may not have specified it yet.
171 */ 119 */
172 bool couldApplyCoverage(const GrDrawTargetCaps& caps) const; 120 bool couldApplyCoverage(const GrDrawTargetCaps& caps) const;
173 121
174 /// @} 122 /// @}
175 123
176 /////////////////////////////////////////////////////////////////////////// 124 ///////////////////////////////////////////////////////////////////////////
177 /// @name Color 125 /// @name Color
178 //// 126 ////
179 127
180 /** 128 /**
181 * Sets color for next draw to a premultiplied-alpha color. 129 * Sets color for next draw to a premultiplied-alpha color.
182 * 130 *
183 * @param color the color to set. 131 * @param color the color to set.
184 */ 132 */
185 void setColor(GrColor color) { 133 void setColor(GrColor color) {
186 fColor = color; 134 fColor = color;
187 this->invalidateBlendOptFlags(); 135 this->invalidateBlendOptFlags();
188 } 136 }
189 137
190 GrColor getColor() const { return fColor; }
191
192 /** 138 /**
193 * Sets the color to be used for the next draw to be 139 * Sets the color to be used for the next draw to be
194 * (r,g,b,a) = (alpha, alpha, alpha, alpha). 140 * (r,g,b,a) = (alpha, alpha, alpha, alpha).
195 * 141 *
196 * @param alpha The alpha value to set as the color. 142 * @param alpha The alpha value to set as the color.
197 */ 143 */
198 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); } 144 void setAlpha(uint8_t a) { this->setColor((a << 24) | (a << 16) | (a << 8) | a); }
199 145
200 /// @} 146 /// @}
201 147
202 /////////////////////////////////////////////////////////////////////////// 148 ///////////////////////////////////////////////////////////////////////////
203 /// @name Coverage 149 /// @name Coverage
204 //// 150 ////
205 151
206 /** 152 /**
207 * Sets a constant fractional coverage to be applied to the draw. The 153 * Sets a constant fractional coverage to be applied to the draw. The
208 * initial value (after construction or reset()) is 0xff. The constant 154 * initial value (after construction or reset()) is 0xff. The constant
209 * coverage is ignored when per-vertex coverage is provided. 155 * coverage is ignored when per-vertex coverage is provided.
210 */ 156 */
211 void setCoverage(uint8_t coverage) { 157 void setCoverage(uint8_t coverage) {
212 fCoverage = coverage; 158 fCoverage = coverage;
213 this->invalidateBlendOptFlags(); 159 this->invalidateBlendOptFlags();
214 } 160 }
215 161
216 uint8_t getCoverage() const { return fCoverage; }
217
218 GrColor getCoverageColor() const {
219 return GrColorPackRGBA(fCoverage, fCoverage, fCoverage, fCoverage);
220 }
221
222 /// @} 162 /// @}
223 163
224 /////////////////////////////////////////////////////////////////////////// 164 ///////////////////////////////////////////////////////////////////////////
225 /// @name Effect Stages 165 /// @name Effect Stages
226 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment 166 /// Each stage hosts a GrEffect. The effect produces an output color or cove rage in the fragment
227 /// shader. Its inputs are the output from the previous stage as well as som e variables 167 /// shader. Its inputs are the output from the previous stage as well as som e variables
228 /// available to it in the fragment and vertex shader (e.g. the vertex posit ion, the dst color, 168 /// available to it in the fragment and vertex shader (e.g. the vertex posit ion, the dst color,
229 /// the fragment position, local coordinates). 169 /// the fragment position, local coordinates).
230 /// 170 ///
231 /// The stages are divided into two sets, color-computing and coverage-compu ting. The final 171 /// The stages are divided into two sets, color-computing and coverage-compu ting. The final
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 void set(GrDrawState* ds); 235 void set(GrDrawState* ds);
296 236
297 bool isSet() const { return NULL != fDrawState; } 237 bool isSet() const { return NULL != fDrawState; }
298 238
299 private: 239 private:
300 GrDrawState* fDrawState; 240 GrDrawState* fDrawState;
301 int fColorEffectCnt; 241 int fColorEffectCnt;
302 int fCoverageEffectCnt; 242 int fCoverageEffectCnt;
303 }; 243 };
304 244
305 int numColorStages() const { return fColorStages.count(); }
306 int numCoverageStages() const { return fCoverageStages.count(); }
307 int numTotalStages() const { return this->numColorStages() + this->numCovera geStages(); }
308
309 const GrEffectStage& getColorStage(int stageIdx) const { return fColorStages [stageIdx]; }
310 const GrEffectStage& getCoverageStage(int stageIdx) const { return fCoverage Stages[stageIdx]; }
311
312 /**
313 * Checks whether any of the effects will read the dst pixel color.
314 */
315 bool willEffectReadDstColor() const;
316
317 /// @} 245 /// @}
318 246
319 /////////////////////////////////////////////////////////////////////////// 247 ///////////////////////////////////////////////////////////////////////////
320 /// @name Blending 248 /// @name Blending
321 //// 249 ////
322 250
323 /** 251 /**
324 * Sets the blending function coefficients. 252 * Sets the blending function coefficients.
325 * 253 *
326 * The blend function will be: 254 * The blend function will be:
(...skipping 13 matching lines...) Expand all
340 #ifdef SK_DEBUG 268 #ifdef SK_DEBUG
341 if (GrBlendCoeffRefsDst(dstCoeff)) { 269 if (GrBlendCoeffRefsDst(dstCoeff)) {
342 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n"); 270 GrPrintf("Unexpected dst blend coeff. Won't work correctly with cove rage stages.\n");
343 } 271 }
344 if (GrBlendCoeffRefsSrc(srcCoeff)) { 272 if (GrBlendCoeffRefsSrc(srcCoeff)) {
345 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n"); 273 GrPrintf("Unexpected src blend coeff. Won't work correctly with cove rage stages.\n");
346 } 274 }
347 #endif 275 #endif
348 } 276 }
349 277
350 GrBlendCoeff getSrcBlendCoeff() const { return fSrcBlend; }
351 GrBlendCoeff getDstBlendCoeff() const { return fDstBlend; }
352
353 void getDstBlendCoeff(GrBlendCoeff* srcBlendCoeff,
354 GrBlendCoeff* dstBlendCoeff) const {
355 *srcBlendCoeff = fSrcBlend;
356 *dstBlendCoeff = fDstBlend;
357 }
358
359 /** 278 /**
360 * Sets the blending function constant referenced by the following blending 279 * Sets the blending function constant referenced by the following blending
361 * coefficients: 280 * coefficients:
362 * kConstC_GrBlendCoeff 281 * kConstC_GrBlendCoeff
363 * kIConstC_GrBlendCoeff 282 * kIConstC_GrBlendCoeff
364 * kConstA_GrBlendCoeff 283 * kConstA_GrBlendCoeff
365 * kIConstA_GrBlendCoeff 284 * kIConstA_GrBlendCoeff
366 * 285 *
367 * @param constant the constant to set 286 * @param constant the constant to set
368 */ 287 */
369 void setBlendConstant(GrColor constant) { 288 void setBlendConstant(GrColor constant) {
370 fBlendConstant = constant; 289 fBlendConstant = constant;
371 this->invalidateBlendOptFlags(); 290 this->invalidateBlendOptFlags();
372 } 291 }
373 292
374 /** 293 /**
375 * Retrieves the last value set by setBlendConstant()
376 * @return the blending constant value
377 */
378 GrColor getBlendConstant() const { return fBlendConstant; }
379
380 /**
381 * Determines whether multiplying the computed per-pixel color by the pixel' s fractional
382 * coverage before the blend will give the correct final destination color. In general it
383 * will not as coverage is applied after blending.
384 */
385 bool canTweakAlphaForCoverage() const;
386
387 /**
388 * Optimizations for blending / coverage to that can be applied based on the current state.
389 */
390 enum BlendOptFlags {
391 /**
392 * No optimization
393 */
394 kNone_BlendOpt = 0,
395 /**
396 * Don't draw at all
397 */
398 kSkipDraw_BlendOptFlag = 0x1,
399 /**
400 * The coverage value does not have to be computed separately from alpha , the the output
401 * color can be the modulation of the two.
402 */
403 kCoverageAsAlpha_BlendOptFlag = 0x2,
404 /**
405 * Instead of emitting a src color, emit coverage in the alpha channel a nd r,g,b are
406 * "don't cares".
407 */
408 kEmitCoverage_BlendOptFlag = 0x4,
409 /**
410 * Emit transparent black instead of the src color, no need to compute c overage.
411 */
412 kEmitTransBlack_BlendOptFlag = 0x8,
413 /**
414 * Flag used to invalidate the cached BlendOptFlags, OptSrcCoeff, and Op tDstCoeff cached by
415 * the get BlendOpts function.
416 */
417 kInvalid_BlendOptFlag = 1 << 31,
418 };
419 GR_DECL_BITFIELD_OPS_FRIENDS(BlendOptFlags);
420
421 void invalidateBlendOptFlags() {
422 fBlendOptFlags = kInvalid_BlendOptFlag;
423 }
424
425 /**
426 * We don't use suplied vertex color attributes if our blend mode is EmitCov erage or
427 * EmitTransBlack
428 */
429 bool canIgnoreColorAttribute() const;
430
431 /**
432 * Determines what optimizations can be applied based on the blend. The coef ficients may have 294 * Determines what optimizations can be applied based on the blend. The coef ficients may have
433 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional 295 * to be tweaked in order for the optimization to work. srcCoeff and dstCoef f are optional
434 * params that receive the tweaked coefficients. Normally the function looks at the current 296 * params that receive the tweaked coefficients. Normally the function looks at the current
435 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively 297 * state to see if coverage is enabled. By setting forceCoverage the caller can speculatively
436 * determine the blend optimizations that would be used if there was partial pixel coverage. 298 * determine the blend optimizations that would be used if there was partial pixel coverage.
437 * 299 *
438 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for 300 * Subclasses of GrDrawTarget that actually draw (as opposed to those that j ust buffer for
439 * playback) must call this function and respect the flags that replace the output color. 301 * playback) must call this function and respect the flags that replace the output color.
440 * 302 *
441 * If the cached BlendOptFlags does not have the invalidate bit set, then ge tBlendOpts will 303 * If the cached BlendOptFlags does not have the invalidate bit set, then ge tBlendOpts will
442 * simply returned the cached flags and coefficients. Otherwise it will calc ulate the values. 304 * simply returned the cached flags and coefficients. Otherwise it will calc ulate the values.
443 */ 305 */
444 BlendOptFlags getBlendOpts(bool forceCoverage = false, 306 BlendOptFlags getBlendOpts(bool forceCoverage = false,
445 GrBlendCoeff* srcCoeff = NULL, 307 GrBlendCoeff* srcCoeff = NULL,
446 GrBlendCoeff* dstCoeff = NULL) const; 308 GrBlendCoeff* dstCoeff = NULL) const;
447 309
310 /**
311 * We don't use suplied vertex color attributes if our blend mode is EmitCov erage or
312 * EmitTransBlack
313 */
314 bool canIgnoreColorAttribute() const;
315
316
448 /// @} 317 /// @}
449 318
450 /////////////////////////////////////////////////////////////////////////// 319 ///////////////////////////////////////////////////////////////////////////
451 /// @name View Matrix 320 /// @name View Matrix
452 //// 321 ////
453 322
454 /** 323 /**
455 * Sets the view matrix to identity and updates any installed effects to com pensate for the 324 * Sets the view matrix to identity and updates any installed effects to com pensate for the
456 * coord system change. 325 * coord system change.
457 */ 326 */
458 bool setIdentityViewMatrix(); 327 bool setIdentityViewMatrix();
459 328
460 /**
461 * Retrieves the current view matrix
462 * @return the current view matrix.
463 */
464 const SkMatrix& getViewMatrix() const { return fViewMatrix; }
465
466 /**
467 * Retrieves the inverse of the current view matrix.
468 *
469 * If the current view matrix is invertible, return true, and if matrix
470 * is non-null, copy the inverse into it. If the current view matrix is
471 * non-invertible, return false and ignore the matrix parameter.
472 *
473 * @param matrix if not null, will receive a copy of the current inverse.
474 */
475 bool getViewInverse(SkMatrix* matrix) const {
476 // TODO: determine whether we really need to leave matrix unmodified
477 // at call sites when inversion fails.
478 SkMatrix inverse;
479 if (fViewMatrix.invert(&inverse)) {
480 if (matrix) {
481 *matrix = inverse;
482 }
483 return true;
484 }
485 return false;
486 }
487
488 //////////////////////////////////////////////////////////////////////////// 329 ////////////////////////////////////////////////////////////////////////////
489 330
490 /** 331 /**
491 * Preconcats the current view matrix and restores the previous view matrix in the destructor. 332 * Preconcats the current view matrix and restores the previous view matrix in the destructor.
492 * Effect matrices are automatically adjusted to compensate and adjusted bac k in the destructor. 333 * Effect matrices are automatically adjusted to compensate and adjusted bac k in the destructor.
493 */ 334 */
494 class AutoViewMatrixRestore : public ::SkNoncopyable { 335 class AutoViewMatrixRestore : public ::SkNoncopyable {
495 public: 336 public:
496 AutoViewMatrixRestore() : fDrawState(NULL) {} 337 AutoViewMatrixRestore() : fDrawState(NULL) {}
497 338
(...skipping 30 matching lines...) Expand all
528 /// @name Render Target 369 /// @name Render Target
529 //// 370 ////
530 371
531 /** 372 /**
532 * Sets the render-target used at the next drawing call 373 * Sets the render-target used at the next drawing call
533 * 374 *
534 * @param target The render target to set. 375 * @param target The render target to set.
535 */ 376 */
536 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef (target)); } 377 void setRenderTarget(GrRenderTarget* target) { fRenderTarget.reset(SkSafeRef (target)); }
537 378
538 /**
539 * Retrieves the currently set render-target.
540 *
541 * @return The currently set render target.
542 */
543 const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); }
544 GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); }
545
546 class AutoRenderTargetRestore : public ::SkNoncopyable { 379 class AutoRenderTargetRestore : public ::SkNoncopyable {
547 public: 380 public:
548 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {} 381 AutoRenderTargetRestore() : fDrawState(NULL), fSavedTarget(NULL) {}
549 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) { 382 AutoRenderTargetRestore(GrDrawState* ds, GrRenderTarget* newTarget) {
550 fDrawState = NULL; 383 fDrawState = NULL;
551 fSavedTarget = NULL; 384 fSavedTarget = NULL;
552 this->set(ds, newTarget); 385 this->set(ds, newTarget);
553 } 386 }
554 ~AutoRenderTargetRestore() { this->restore(); } 387 ~AutoRenderTargetRestore() { this->restore(); }
555 388
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 429 }
597 430
598 /** 431 /**
599 * Shortcut to disable stencil testing and ops. 432 * Shortcut to disable stencil testing and ops.
600 */ 433 */
601 void disableStencil() { 434 void disableStencil() {
602 fStencilSettings.setDisabled(); 435 fStencilSettings.setDisabled();
603 this->invalidateBlendOptFlags(); 436 this->invalidateBlendOptFlags();
604 } 437 }
605 438
606 const GrStencilSettings& getStencil() const { return fStencilSettings; }
607
608 GrStencilSettings* stencil() { return &fStencilSettings; } 439 GrStencilSettings* stencil() { return &fStencilSettings; }
609 440
610 /// @} 441 /// @}
611 442
612 /////////////////////////////////////////////////////////////////////////// 443 ///////////////////////////////////////////////////////////////////////////
613 /// @name State Flags 444 /// @name State Flags
614 //// 445 ////
615 446
616 /**
617 * Flags that affect rendering. Controlled using enable/disableState(). All
618 * default to disabled.
619 */
620 enum StateBits {
621 /**
622 * Perform dithering. TODO: Re-evaluate whether we need this bit
623 */
624 kDither_StateBit = 0x01,
625 /**
626 * Perform HW anti-aliasing. This means either HW FSAA, if supported by the render target,
627 * or smooth-line rendering if a line primitive is drawn and line smooth ing is supported by
628 * the 3D API.
629 */
630 kHWAntialias_StateBit = 0x02,
631 /**
632 * Draws will respect the clip, otherwise the clip is ignored.
633 */
634 kClip_StateBit = 0x04,
635 /**
636 * Disables writing to the color buffer. Useful when performing stencil
637 * operations.
638 */
639 kNoColorWrites_StateBit = 0x08,
640
641 /**
642 * Usually coverage is applied after color blending. The color is blende d using the coeffs
643 * specified by setBlendFunc(). The blended color is then combined with dst using coeffs
644 * of src_coverage, 1-src_coverage. Sometimes we are explicitly drawing a coverage mask. In
645 * this case there is no distinction between coverage and color and the caller needs direct
646 * control over the blend coeffs. When set, there will be a single blend step controlled by
647 * setBlendFunc() which will use coverage*color as the src color.
648 */
649 kCoverageDrawing_StateBit = 0x10,
650
651 // Users of the class may add additional bits to the vector
652 kDummyStateBit,
653 kLastPublicStateBit = kDummyStateBit-1,
654 };
655
656 void resetStateFlags() { 447 void resetStateFlags() {
657 fFlagBits = 0; 448 fFlagBits = 0;
658 this->invalidateBlendOptFlags(); 449 this->invalidateBlendOptFlags();
659 } 450 }
660 451
661 /** 452 /**
662 * Enable render state settings. 453 * Enable render state settings.
663 * 454 *
664 * @param stateBits bitfield of StateBits specifying the states to enable 455 * @param stateBits bitfield of StateBits specifying the states to enable
665 */ 456 */
(...skipping 19 matching lines...) Expand all
685 * @param enable if true enable stateBits, otherwise disable 476 * @param enable if true enable stateBits, otherwise disable
686 */ 477 */
687 void setState(uint32_t stateBits, bool enable) { 478 void setState(uint32_t stateBits, bool enable) {
688 if (enable) { 479 if (enable) {
689 this->enableState(stateBits); 480 this->enableState(stateBits);
690 } else { 481 } else {
691 this->disableState(stateBits); 482 this->disableState(stateBits);
692 } 483 }
693 } 484 }
694 485
695 bool isStateFlagEnabled(uint32_t stateBit) const { return 0 != (stateBit & f FlagBits); }
696
697 bool isDitherState() const { return 0 != (fFlagBits & kDither_StateBit); }
698 bool isHWAntialiasState() const { return 0 != (fFlagBits & kHWAntialias_Stat eBit); }
699 bool isClipState() const { return 0 != (fFlagBits & kClip_StateBit); }
700 bool isColorWriteDisabled() const { return 0 != (fFlagBits & kNoColorWrites_ StateBit); }
701 bool isCoverageDrawing() const { return 0 != (fFlagBits & kCoverageDrawing_S tateBit); }
702
703 /// @} 486 /// @}
704 487
705 /////////////////////////////////////////////////////////////////////////// 488 ///////////////////////////////////////////////////////////////////////////
706 /// @name Face Culling 489 /// @name Face Culling
707 //// 490 ////
708 491
709 enum DrawFace {
710 kInvalid_DrawFace = -1,
711
712 kBoth_DrawFace,
713 kCCW_DrawFace,
714 kCW_DrawFace,
715 };
716
717 /** 492 /**
718 * Controls whether clockwise, counterclockwise, or both faces are drawn. 493 * Controls whether clockwise, counterclockwise, or both faces are drawn.
719 * @param face the face(s) to draw. 494 * @param face the face(s) to draw.
720 */ 495 */
721 void setDrawFace(DrawFace face) { 496 void setDrawFace(DrawFace face) {
722 SkASSERT(kInvalid_DrawFace != face); 497 SkASSERT(kInvalid_DrawFace != face);
723 fDrawFace = face; 498 fDrawFace = face;
724 } 499 }
725 500
726 /**
727 * Gets whether the target is drawing clockwise, counterclockwise,
728 * or both faces.
729 * @return the current draw face(s).
730 */
731 DrawFace getDrawFace() const { return fDrawFace; }
732
733 /// @} 501 /// @}
734 502
735 /////////////////////////////////////////////////////////////////////////// 503 ///////////////////////////////////////////////////////////////////////////
736 /// @name Hints 504 /// @name Hints
737 /// Hints that when provided can enable optimizations. 505 /// Hints that when provided can enable optimizations.
738 //// 506 ////
739 507
740 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, }; 508 enum Hints { kVertexColorsAreOpaque_Hint = 0x1, };
741 509
742 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f Hints & ~hint); } 510 void setHint(Hints hint, bool value) { fHints = value ? (fHints | hint) : (f Hints & ~hint); }
(...skipping 19 matching lines...) Expand all
762 if draws can be batched. The return value indicates whether combining is possible and, if 530 if draws can be batched. The return value indicates whether combining is possible and, if
763 so, which of the two inputs should be used. */ 531 so, which of the two inputs should be used. */
764 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b, 532 static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawSta te& b,
765 const GrDrawTargetCaps& caps); 533 const GrDrawTargetCaps& caps);
766 534
767 GrDrawState& operator= (const GrDrawState& that); 535 GrDrawState& operator= (const GrDrawState& that);
768 536
769 private: 537 private:
770 void onReset(const SkMatrix* initialViewMatrix); 538 void onReset(const SkMatrix* initialViewMatrix);
771 539
540 /**
541 * Determines whether src alpha is guaranteed to be one for all src pixels
542 */
543 bool srcAlphaWillBeOne() const;
544
545 /**
546 * Helper function for getBlendOpts.
547 */
772 BlendOptFlags calcBlendOpts(bool forceCoverage = false, 548 BlendOptFlags calcBlendOpts(bool forceCoverage = false,
773 GrBlendCoeff* srcCoeff = NULL, 549 GrBlendCoeff* srcCoeff = NULL,
774 GrBlendCoeff* dstCoeff = NULL) const; 550 GrBlendCoeff* dstCoeff = NULL) const;
775 551
776 // These fields are roughly sorted by decreasing likelihood of being differe nt in op== 552 void invalidateBlendOptFlags() {
777 SkAutoTUnref<GrRenderTarget> fRenderTarget; 553 fBlendOptFlags = kInvalid_BlendOptFlag;
778 GrColor fColor; 554 }
779 SkMatrix fViewMatrix;
780 GrBlendCoeff fSrcBlend;
781 GrBlendCoeff fDstBlend;
782 GrColor fBlendConstant;
783 uint32_t fFlagBits;
784 const GrVertexAttrib* fVAPtr;
785 int fVACount;
786 size_t fVertexSize;
787 GrStencilSettings fStencilSettings;
788 uint8_t fCoverage;
789 DrawFace fDrawFace;
790
791 typedef SkSTArray<4, GrEffectStage> EffectStageArray;
792 EffectStageArray fColorStages;
793 EffectStageArray fCoverageStages;
794 555
795 uint32_t fHints; 556 uint32_t fHints;
796
797 mutable GrBlendCoeff fOptSrcBlend;
798 mutable GrBlendCoeff fOptDstBlend;
799 mutable BlendOptFlags fBlendOptFlags;
800
801 // This is simply a different representation of info in fVertexAttribs and t hus does
802 // not need to be compared in op==.
803 int fFixedFunctionVertexAttribIndices[kGrFixedFunctionVertexAttribBindingCnt ];
804 557
805 // Some of the auto restore objects assume that no effects are removed durin g their lifetime. 558 // Some of the auto restore objects assume that no effects are removed durin g their lifetime.
806 // This is used to assert that this condition holds. 559 // This is used to assert that this condition holds.
807 SkDEBUGCODE(int fBlockEffectRemovalCnt;) 560 SkDEBUGCODE(int fBlockEffectRemovalCnt;)
808 561
809 /** 562 /**
810 * Sets vertex attributes for next draw. 563 * Sets vertex attributes for next draw.
811 * 564 *
812 * @param attribs the array of vertex attributes to set. 565 * @param attribs the array of vertex attributes to set.
813 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt. 566 * @param count the number of attributes being set, limited to kMaxVer texAttribCnt.
814 */ 567 */
815 void setVertexAttribs(const GrVertexAttrib attribs[], int count); 568 void setVertexAttribs(const GrVertexAttrib attribs[], int count);
816 569
817 typedef SkRefCnt INHERITED; 570 typedef GrRODrawState INHERITED;
818 }; 571 };
819 572
820 GR_MAKE_BITFIELD_OPS(GrDrawState::BlendOptFlags);
821
822 #endif 573 #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