| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2012 Google Inc. | 2  * Copyright 2012 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 #include "GrDrawState.h" | 8 #include "GrDrawState.h" | 
| 9 #include "GrPaint.h" | 9 #include "GrPaint.h" | 
| 10 | 10 | 
|  | 11 bool GrDrawState::setIdentityViewMatrix()  { | 
|  | 12     SkMatrix invVM; | 
|  | 13     bool inverted = false; | 
|  | 14     for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 
|  | 15         if (this->isStageEnabled(s)) { | 
|  | 16             if (!inverted) { | 
|  | 17                 if (!fCommon.fViewMatrix.invert(&invVM)) { | 
|  | 18                     // sad trombone sound | 
|  | 19                     return false; | 
|  | 20                 } | 
|  | 21                 inverted = true; | 
|  | 22             } | 
|  | 23             fStages[s].localCoordChange(invVM); | 
|  | 24         } | 
|  | 25     } | 
|  | 26     fCommon.fViewMatrix.reset(); | 
|  | 27     return true; | 
|  | 28 } | 
|  | 29 | 
| 11 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
     rTarget* rt) { | 30 void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
     rTarget* rt) { | 
| 12     for (int i = 0; i < GrPaint::kMaxColorStages; ++i) { | 31     for (int i = 0; i < GrPaint::kMaxColorStages; ++i) { | 
| 13         int s = i + GrPaint::kFirstColorStage; | 32         int s = i + GrPaint::kFirstColorStage; | 
| 14         if (paint.isColorStageEnabled(i)) { | 33         if (paint.isColorStageEnabled(i)) { | 
| 15             fStages[s] = paint.getColorStage(i); | 34             fStages[s] = paint.getColorStage(i); | 
| 16         } else { | 35         } else { | 
| 17             fStages[s].setEffect(NULL); | 36             fStages[s].setEffect(NULL); | 
| 18         } | 37         } | 
| 19     } | 38     } | 
| 20 | 39 | 
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 388         // need blending. | 407         // need blending. | 
| 389         return kDisableBlend_BlendOptFlag; | 408         return kDisableBlend_BlendOptFlag; | 
| 390     } | 409     } | 
| 391     return kNone_BlendOpt; | 410     return kNone_BlendOpt; | 
| 392 } | 411 } | 
| 393 | 412 | 
| 394 //////////////////////////////////////////////////////////////////////////////// | 413 //////////////////////////////////////////////////////////////////////////////// | 
| 395 | 414 | 
| 396 void GrDrawState::AutoViewMatrixRestore::restore() { | 415 void GrDrawState::AutoViewMatrixRestore::restore() { | 
| 397     if (NULL != fDrawState) { | 416     if (NULL != fDrawState) { | 
| 398         fDrawState->setViewMatrix(fViewMatrix); | 417         fDrawState->fCommon.fViewMatrix = fViewMatrix; | 
| 399         for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 418         for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 
| 400             if (fRestoreMask & (1 << s)) { | 419             if (fRestoreMask & (1 << s)) { | 
| 401                 fDrawState->fStages[s].restoreCoordChange(fSavedCoordChanges[s])
     ; | 420                 fDrawState->fStages[s].restoreCoordChange(fSavedCoordChanges[s])
     ; | 
| 402             } | 421             } | 
| 403         } | 422         } | 
|  | 423         fDrawState = NULL; | 
| 404     } | 424     } | 
| 405     fDrawState = NULL; |  | 
| 406 } | 425 } | 
| 407 | 426 | 
| 408 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, | 427 void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState, | 
| 409                                              const SkMatrix& preconcatMatrix) { | 428                                              const SkMatrix& preconcatMatrix) { | 
| 410     this->restore(); | 429     this->restore(); | 
| 411 | 430 | 
| 412     fDrawState = drawState; | 431     if (NULL == drawState || preconcatMatrix.isIdentity()) { | 
| 413     if (NULL == drawState) { |  | 
| 414         return; | 432         return; | 
| 415     } | 433     } | 
|  | 434     fDrawState = drawState; | 
| 416 | 435 | 
| 417     fRestoreMask = 0; | 436     fRestoreMask = 0; | 
| 418     fViewMatrix = drawState->getViewMatrix(); | 437     fViewMatrix = drawState->getViewMatrix(); | 
| 419     drawState->preConcatViewMatrix(preconcatMatrix); | 438     drawState->fCommon.fViewMatrix.preConcat(preconcatMatrix); | 
| 420     for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 439     for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 
| 421         if (drawState->isStageEnabled(s)) { | 440         if (drawState->isStageEnabled(s)) { | 
| 422             fRestoreMask |= (1 << s); | 441             fRestoreMask |= (1 << s); | 
| 423             fDrawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]); | 442             drawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]); | 
| 424             drawState->fStages[s].localCoordChange(preconcatMatrix); | 443             drawState->fStages[s].localCoordChange(preconcatMatrix); | 
| 425         } | 444         } | 
| 426     } | 445     } | 
| 427 } | 446 } | 
| 428 | 447 | 
| 429 //////////////////////////////////////////////////////////////////////////////// | 448 bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) { | 
| 430 |  | 
| 431 void GrDrawState::AutoDeviceCoordDraw::restore() { |  | 
| 432     if (NULL != fDrawState) { |  | 
| 433         fDrawState->setViewMatrix(fViewMatrix); |  | 
| 434         for (int s = 0; s < GrDrawState::kNumStages; ++s) { |  | 
| 435             if (fRestoreMask & (1 << s)) { |  | 
| 436                 fDrawState->fStages[s].restoreCoordChange(fSavedCoordChanges[s])
     ; |  | 
| 437             } |  | 
| 438         } |  | 
| 439     } |  | 
| 440     fDrawState = NULL; |  | 
| 441 } |  | 
| 442 |  | 
| 443 bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState) { |  | 
| 444     GrAssert(NULL != drawState); |  | 
| 445 |  | 
| 446     this->restore(); | 449     this->restore(); | 
| 447 | 450 | 
| 448     fDrawState = drawState; | 451     if (NULL == drawState) { | 
| 449     if (NULL == fDrawState) { |  | 
| 450         return false; | 452         return false; | 
| 451     } | 453     } | 
| 452 | 454 | 
|  | 455     if (drawState->getViewMatrix().isIdentity()) { | 
|  | 456         return true; | 
|  | 457     } | 
|  | 458 | 
| 453     fViewMatrix = drawState->getViewMatrix(); | 459     fViewMatrix = drawState->getViewMatrix(); | 
| 454     fRestoreMask = 0; | 460     fRestoreMask = 0; | 
| 455     SkMatrix invVM; |  | 
| 456     bool inverted = false; |  | 
| 457 |  | 
| 458     for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 461     for (int s = 0; s < GrDrawState::kNumStages; ++s) { | 
| 459         if (drawState->isStageEnabled(s)) { | 462         if (drawState->isStageEnabled(s)) { | 
| 460             if (!inverted && !fViewMatrix.invert(&invVM)) { |  | 
| 461                 // sad trombone sound |  | 
| 462                 fDrawState = NULL; |  | 
| 463                 return false; |  | 
| 464             } else { |  | 
| 465                 inverted = true; |  | 
| 466             } |  | 
| 467             fRestoreMask |= (1 << s); | 463             fRestoreMask |= (1 << s); | 
| 468             GrEffectStage* stage = drawState->fStages + s; | 464             drawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]); | 
| 469             stage->saveCoordChange(&fSavedCoordChanges[s]); |  | 
| 470             stage->localCoordChange(invVM); |  | 
| 471         } | 465         } | 
| 472     } | 466     } | 
| 473     drawState->viewMatrix()->reset(); | 467     if (!drawState->setIdentityViewMatrix()) { | 
|  | 468         return false; | 
|  | 469     } | 
|  | 470     fDrawState = drawState; | 
| 474     return true; | 471     return true; | 
| 475 } | 472 } | 
| OLD | NEW | 
|---|