| 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 /* Description: | 8 /* Description: |
| 9 * This test defines a series of elementatry test steps that perform | 9 * This test defines a series of elementatry test steps that perform |
| 10 * a single or a small group of canvas API calls. Each test step is | 10 * a single or a small group of canvas API calls. Each test step is |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount(
), | 464 REPORTER_ASSERT_MESSAGE(reporter, baseSaveCount + 1 == canvas->getSaveCount(
), |
| 465 testStep->assertMessage()); | 465 testStep->assertMessage()); |
| 466 | 466 |
| 467 // should this pin to 1, or be a no-op, or crash? | 467 // should this pin to 1, or be a no-op, or crash? |
| 468 canvas->restoreToCount(0); | 468 canvas->restoreToCount(0); |
| 469 REPORTER_ASSERT_MESSAGE(reporter, 1 == canvas->getSaveCount(), | 469 REPORTER_ASSERT_MESSAGE(reporter, 1 == canvas->getSaveCount(), |
| 470 testStep->assertMessage()); | 470 testStep->assertMessage()); |
| 471 } | 471 } |
| 472 TEST_STEP(SaveRestore, SaveRestoreTestStep); | 472 TEST_STEP(SaveRestore, SaveRestoreTestStep); |
| 473 | 473 |
| 474 static void DrawLayerTestStep(SkCanvas* canvas, const TestData& d, | |
| 475 skiatest::Reporter* reporter, CanvasTestStep* test
Step) { | |
| 476 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), | |
| 477 testStep->assertMessage()); | |
| 478 canvas->save(); | |
| 479 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), | |
| 480 testStep->assertMessage()); | |
| 481 canvas->restore(); | |
| 482 | |
| 483 const SkRect* bounds = NULL; // null means include entire bounds | |
| 484 const SkPaint* paint = NULL; | |
| 485 | |
| 486 canvas->saveLayer(bounds, paint); | |
| 487 REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(), | |
| 488 testStep->assertMessage()); | |
| 489 canvas->restore(); | |
| 490 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), | |
| 491 testStep->assertMessage()); | |
| 492 | |
| 493 canvas->saveLayer(bounds, paint); | |
| 494 canvas->saveLayer(bounds, paint); | |
| 495 REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(), | |
| 496 testStep->assertMessage()); | |
| 497 canvas->restore(); | |
| 498 REPORTER_ASSERT_MESSAGE(reporter, canvas->isDrawingToLayer(), | |
| 499 testStep->assertMessage()); | |
| 500 canvas->restore(); | |
| 501 // now layer count should be 0 | |
| 502 REPORTER_ASSERT_MESSAGE(reporter, !canvas->isDrawingToLayer(), | |
| 503 testStep->assertMessage()); | |
| 504 } | |
| 505 TEST_STEP(DrawLayer, DrawLayerTestStep); | |
| 506 | |
| 507 static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, const Test
Data& d, | 474 static void NestedSaveRestoreWithSolidPaintTestStep(SkCanvas* canvas, const Test
Data& d, |
| 508 skiatest::Reporter*, CanvasT
estStep*) { | 475 skiatest::Reporter*, CanvasT
estStep*) { |
| 509 // This test step challenges the TestDeferredCanvasStateConsistency | 476 // This test step challenges the TestDeferredCanvasStateConsistency |
| 510 // test cases because the opaque paint can trigger an optimization | 477 // test cases because the opaque paint can trigger an optimization |
| 511 // that discards previously recorded commands. The challenge is to maintain | 478 // that discards previously recorded commands. The challenge is to maintain |
| 512 // correct clip and matrix stack state. | 479 // correct clip and matrix stack state. |
| 513 canvas->resetMatrix(); | 480 canvas->resetMatrix(); |
| 514 canvas->rotate(SkIntToScalar(30)); | 481 canvas->rotate(SkIntToScalar(30)); |
| 515 canvas->save(); | 482 canvas->save(); |
| 516 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); | 483 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 544 } | 511 } |
| 545 TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); | 512 TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); |
| 546 | 513 |
| 547 static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData
& d, | 514 static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData
& d, |
| 548 const SkCanvas* canvas1, const SkCanvas* can
vas2, | 515 const SkCanvas* canvas1, const SkCanvas* can
vas2, |
| 549 CanvasTestStep* testStep) { | 516 CanvasTestStep* testStep) { |
| 550 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == | 517 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == |
| 551 canvas2->getDeviceSize(), testStep->assertMessage()); | 518 canvas2->getDeviceSize(), testStep->assertMessage()); |
| 552 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() == | 519 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() == |
| 553 canvas2->getSaveCount(), testStep->assertMessage()); | 520 canvas2->getSaveCount(), testStep->assertMessage()); |
| 554 REPORTER_ASSERT_MESSAGE(reporter, canvas1->isDrawingToLayer() == | |
| 555 canvas2->isDrawingToLayer(), testStep->assertMessage()); | |
| 556 | 521 |
| 557 SkRect bounds1, bounds2; | 522 SkRect bounds1, bounds2; |
| 558 REPORTER_ASSERT_MESSAGE(reporter, | 523 REPORTER_ASSERT_MESSAGE(reporter, |
| 559 canvas1->getClipBounds(&bounds1) == canvas2->getClipBounds(&bounds2), | 524 canvas1->getClipBounds(&bounds1) == canvas2->getClipBounds(&bounds2), |
| 560 testStep->assertMessage()); | 525 testStep->assertMessage()); |
| 561 REPORTER_ASSERT_MESSAGE(reporter, bounds1 == bounds2, | 526 REPORTER_ASSERT_MESSAGE(reporter, bounds1 == bounds2, |
| 562 testStep->assertMessage()); | 527 testStep->assertMessage()); |
| 563 | 528 |
| 564 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDrawFilter() == | 529 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDrawFilter() == |
| 565 canvas2->getDrawFilter(), testStep->assertMessage()); | 530 canvas2->getDrawFilter(), testStep->assertMessage()); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 | 778 |
| 814 n = canvas.saveLayer(NULL, NULL); | 779 n = canvas.saveLayer(NULL, NULL); |
| 815 REPORTER_ASSERT(reporter, 2 == n); | 780 REPORTER_ASSERT(reporter, 2 == n); |
| 816 REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount()); | 781 REPORTER_ASSERT(reporter, 3 == canvas.getSaveCount()); |
| 817 | 782 |
| 818 canvas.restore(); | 783 canvas.restore(); |
| 819 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); | 784 REPORTER_ASSERT(reporter, 2 == canvas.getSaveCount()); |
| 820 canvas.restore(); | 785 canvas.restore(); |
| 821 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); | 786 REPORTER_ASSERT(reporter, 1 == canvas.getSaveCount()); |
| 822 } | 787 } |
| OLD | NEW |