| OLD | NEW |
| 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 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 class GrPaint; | 28 class GrPaint; |
| 29 class GrTexture; | 29 class GrTexture; |
| 30 | 30 |
| 31 class GrDrawState { | 31 class GrDrawState { |
| 32 public: | 32 public: |
| 33 GrDrawState() { | 33 GrDrawState() { |
| 34 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 34 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
| 35 this->reset(); | 35 this->reset(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 GrDrawState(const SkMatrix& initialViewMatrix) { | |
| 39 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | |
| 40 this->reset(initialViewMatrix); | |
| 41 } | |
| 42 | |
| 43 /** | 38 /** |
| 44 * Copies another draw state. | 39 * Copies another draw state. |
| 45 **/ | 40 **/ |
| 46 GrDrawState(const GrDrawState& state) { | 41 GrDrawState(const GrDrawState& state) { |
| 47 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) | 42 SkDEBUGCODE(fBlockEffectRemovalCnt = 0;) |
| 48 *this = state; | 43 *this = state; |
| 49 } | 44 } |
| 50 | 45 |
| 51 virtual ~GrDrawState(); | 46 virtual ~GrDrawState(); |
| 52 | 47 |
| 53 /** | 48 /** |
| 54 * Resets to the default state. GrProcessors will be removed from all stages
. | 49 * Resets to the default state. GrProcessors will be removed from all stages
. |
| 55 */ | 50 */ |
| 56 void reset() { this->onReset(NULL); } | 51 void reset() { this->onReset(); } |
| 57 | |
| 58 void reset(const SkMatrix& initialViewMatrix) { this->onReset(&initialViewMa
trix); } | |
| 59 | 52 |
| 60 /** | 53 /** |
| 61 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that | 54 * Initializes the GrDrawState based on a GrPaint, view matrix and render ta
rget. Note that |
| 62 * GrDrawState encompasses more than GrPaint. Aspects of GrDrawState that ha
ve no GrPaint | 55 * 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 | 56 * 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. | 57 * is unmodified by this function and clipping which will be enabled. |
| 65 */ | 58 */ |
| 66 void setFromPaint(const GrPaint& , const SkMatrix& viewMatrix, GrRenderTarge
t*); | 59 void setFromPaint(const GrPaint&, GrRenderTarget*); |
| 67 | 60 |
| 68 /// @} | 61 /// @} |
| 69 | 62 |
| 70 /** | 63 /** |
| 71 * Depending on features available in the underlying 3D API and the color bl
end mode requested | 64 * Depending on features available in the underlying 3D API and the color bl
end mode requested |
| 72 * it may or may not be possible to correctly blend with fractional pixel co
verage generated by | 65 * it may or may not be possible to correctly blend with fractional pixel co
verage generated by |
| 73 * the fragment shader. | 66 * the fragment shader. |
| 74 * | 67 * |
| 75 * This function considers the current draw state and the draw target's capa
bilities to | 68 * This function considers the current draw state and the draw target's capa
bilities to |
| 76 * determine whether coverage can be handled correctly. This function assume
s that the caller | 69 * determine whether coverage can be handled correctly. This function assume
s that the caller |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 254 |
| 262 /** | 255 /** |
| 263 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional | 256 * Determines whether multiplying the computed per-pixel color by the pixel'
s fractional |
| 264 * coverage before the blend will give the correct final destination color.
In general it | 257 * coverage before the blend will give the correct final destination color.
In general it |
| 265 * will not as coverage is applied after blending. | 258 * will not as coverage is applied after blending. |
| 266 */ | 259 */ |
| 267 bool canTweakAlphaForCoverage() const; | 260 bool canTweakAlphaForCoverage() const; |
| 268 | 261 |
| 269 /// @} | 262 /// @} |
| 270 | 263 |
| 271 /////////////////////////////////////////////////////////////////////////// | |
| 272 /// @name View Matrix | |
| 273 //// | |
| 274 | |
| 275 /** | |
| 276 * Retrieves the current view matrix | |
| 277 * @return the current view matrix. | |
| 278 */ | |
| 279 const SkMatrix& getViewMatrix() const { return fViewMatrix; } | |
| 280 | |
| 281 /** | |
| 282 * Retrieves the inverse of the current view matrix. | |
| 283 * | |
| 284 * If the current view matrix is invertible, return true, and if matrix | |
| 285 * is non-null, copy the inverse into it. If the current view matrix is | |
| 286 * non-invertible, return false and ignore the matrix parameter. | |
| 287 * | |
| 288 * @param matrix if not null, will receive a copy of the current inverse. | |
| 289 */ | |
| 290 bool getViewInverse(SkMatrix* matrix) const { | |
| 291 SkMatrix inverse; | |
| 292 if (fViewMatrix.invert(&inverse)) { | |
| 293 if (matrix) { | |
| 294 *matrix = inverse; | |
| 295 } | |
| 296 return true; | |
| 297 } | |
| 298 return false; | |
| 299 } | |
| 300 | |
| 301 //////////////////////////////////////////////////////////////////////////// | |
| 302 | |
| 303 /** | |
| 304 * Sets the viewmatrix to identity and restores it in the destructor. | |
| 305 * TODO remove vm off of drawstate | |
| 306 */ | |
| 307 class AutoViewMatrixRestore : public ::SkNoncopyable { | |
| 308 public: | |
| 309 AutoViewMatrixRestore() { | |
| 310 fDrawState = NULL; | |
| 311 } | |
| 312 | |
| 313 AutoViewMatrixRestore(GrDrawState* ds) { | |
| 314 SkASSERT(ds); | |
| 315 fDrawState = ds; | |
| 316 fViewMatrix = fDrawState->fViewMatrix; | |
| 317 fDrawState->fViewMatrix = SkMatrix::I(); | |
| 318 } | |
| 319 | |
| 320 void setIdentity(GrDrawState* ds) { | |
| 321 SkASSERT(ds); | |
| 322 fDrawState = ds; | |
| 323 fViewMatrix = fDrawState->fViewMatrix; | |
| 324 fDrawState->fViewMatrix = SkMatrix::I(); | |
| 325 } | |
| 326 | |
| 327 ~AutoViewMatrixRestore() { | |
| 328 if (fDrawState) { | |
| 329 fDrawState->fViewMatrix = fViewMatrix; | |
| 330 } | |
| 331 } | |
| 332 | |
| 333 private: | |
| 334 GrDrawState* fDrawState; | |
| 335 SkMatrix fViewMatrix; | |
| 336 }; | |
| 337 | |
| 338 | 264 |
| 339 /// @} | 265 /// @} |
| 340 | 266 |
| 341 /////////////////////////////////////////////////////////////////////////// | 267 /////////////////////////////////////////////////////////////////////////// |
| 342 /// @name Render Target | 268 /// @name Render Target |
| 343 //// | 269 //// |
| 344 | 270 |
| 345 /** | 271 /** |
| 346 * Retrieves the currently set render-target. | 272 * Retrieves the currently set render-target. |
| 347 * | 273 * |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 * stages and results are stored in fColorProcInfo. | 433 * stages and results are stored in fColorProcInfo. |
| 508 */ | 434 */ |
| 509 void calcColorInvariantOutput(GrColor) const; | 435 void calcColorInvariantOutput(GrColor) const; |
| 510 | 436 |
| 511 /** | 437 /** |
| 512 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage | 438 * If fCoverageProcInfoValid is false, function calculates the invariant out
put for the coverage |
| 513 * stages and results are stored in fCoverageProcInfo. | 439 * stages and results are stored in fCoverageProcInfo. |
| 514 */ | 440 */ |
| 515 void calcCoverageInvariantOutput(GrColor) const; | 441 void calcCoverageInvariantOutput(GrColor) const; |
| 516 | 442 |
| 517 void onReset(const SkMatrix* initialViewMatrix); | 443 void onReset(); |
| 518 | 444 |
| 519 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. | 445 // Some of the auto restore objects assume that no effects are removed durin
g their lifetime. |
| 520 // This is used to assert that this condition holds. | 446 // This is used to assert that this condition holds. |
| 521 SkDEBUGCODE(int fBlockEffectRemovalCnt;) | 447 SkDEBUGCODE(int fBlockEffectRemovalCnt;) |
| 522 | 448 |
| 523 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; | 449 typedef SkSTArray<4, GrFragmentStage> FragmentStageArray; |
| 524 | 450 |
| 525 SkAutoTUnref<GrRenderTarget> fRenderTarget; | 451 SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 526 SkMatrix fViewMatrix; | |
| 527 uint32_t fFlagBits; | 452 uint32_t fFlagBits; |
| 528 GrStencilSettings fStencilSettings; | 453 GrStencilSettings fStencilSettings; |
| 529 DrawFace fDrawFace; | 454 DrawFace fDrawFace; |
| 530 SkAutoTUnref<const GrXPFactory> fXPFactory; | 455 SkAutoTUnref<const GrXPFactory> fXPFactory; |
| 531 FragmentStageArray fColorStages; | 456 FragmentStageArray fColorStages; |
| 532 FragmentStageArray fCoverageStages; | 457 FragmentStageArray fCoverageStages; |
| 533 | 458 |
| 534 mutable GrProcOptInfo fColorProcInfo; | 459 mutable GrProcOptInfo fColorProcInfo; |
| 535 mutable GrProcOptInfo fCoverageProcInfo; | 460 mutable GrProcOptInfo fCoverageProcInfo; |
| 536 mutable bool fColorProcInfoValid; | 461 mutable bool fColorProcInfoValid; |
| 537 mutable bool fCoverageProcInfoValid; | 462 mutable bool fCoverageProcInfoValid; |
| 538 mutable GrColor fColorCache; | 463 mutable GrColor fColorCache; |
| 539 mutable GrColor fCoverageCache; | 464 mutable GrColor fCoverageCache; |
| 540 mutable const GrPrimitiveProcessor* fColorPrimProc; | 465 mutable const GrPrimitiveProcessor* fColorPrimProc; |
| 541 mutable const GrPrimitiveProcessor* fCoveragePrimProc; | 466 mutable const GrPrimitiveProcessor* fCoveragePrimProc; |
| 542 | 467 |
| 543 friend class GrOptDrawState; | 468 friend class GrOptDrawState; |
| 544 }; | 469 }; |
| 545 | 470 |
| 546 #endif | 471 #endif |
| OLD | NEW |