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