| 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 28 matching lines...) Expand all Loading... |
| 39 * | 39 * |
| 40 * SIMPLE_TEST_STEP(MytestStep, someCanvasAPIMethod()); | 40 * SIMPLE_TEST_STEP(MytestStep, someCanvasAPIMethod()); |
| 41 * | 41 * |
| 42 * There is another macro called SIMPLE_TEST_STEP_WITH_ASSERT that | 42 * There is another macro called SIMPLE_TEST_STEP_WITH_ASSERT that |
| 43 * works the same way as SIMPLE_TEST_STEP, and additionally verifies | 43 * works the same way as SIMPLE_TEST_STEP, and additionally verifies |
| 44 * that the invoked method returns a non-zero value. | 44 * that the invoked method returns a non-zero value. |
| 45 */ | 45 */ |
| 46 #include "SkBitmap.h" | 46 #include "SkBitmap.h" |
| 47 #include "SkCanvas.h" | 47 #include "SkCanvas.h" |
| 48 #include "SkClipStack.h" | 48 #include "SkClipStack.h" |
| 49 #include "SkDevice.h" | |
| 50 #include "SkDocument.h" | 49 #include "SkDocument.h" |
| 51 #include "SkMatrix.h" | 50 #include "SkMatrix.h" |
| 52 #include "SkNWayCanvas.h" | 51 #include "SkNWayCanvas.h" |
| 53 #include "SkPaint.h" | 52 #include "SkPaint.h" |
| 54 #include "SkPaintFilterCanvas.h" | 53 #include "SkPaintFilterCanvas.h" |
| 55 #include "SkPath.h" | 54 #include "SkPath.h" |
| 56 #include "SkPicture.h" | 55 #include "SkPicture.h" |
| 57 #include "SkPictureRecord.h" | 56 #include "SkPictureRecord.h" |
| 58 #include "SkPictureRecorder.h" | 57 #include "SkPictureRecorder.h" |
| 59 #include "SkRect.h" | 58 #include "SkRect.h" |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); | 490 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
| 492 canvas->save(); | 491 canvas->save(); |
| 493 canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); | 492 canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); |
| 494 canvas->drawRect(d.fRect,d.fPaint); | 493 canvas->drawRect(d.fRect,d.fPaint); |
| 495 canvas->flush(); | 494 canvas->flush(); |
| 496 canvas->restore(); | 495 canvas->restore(); |
| 497 canvas->restore(); | 496 canvas->restore(); |
| 498 } | 497 } |
| 499 TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); | 498 TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); |
| 500 | 499 |
| 500 class CanvasTestingAccess { |
| 501 public: |
| 502 static bool SameState(const SkCanvas* canvas1, const SkCanvas* canvas2) { |
| 503 SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false); |
| 504 SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false); |
| 505 while (!layerIter1.done() && !layerIter2.done()) { |
| 506 if (layerIter1.matrix() != layerIter2.matrix()) { |
| 507 return false; |
| 508 } |
| 509 if (layerIter1.clip() != layerIter2.clip()) { |
| 510 return false; |
| 511 } |
| 512 if (layerIter1.paint() != layerIter2.paint()) { |
| 513 return false; |
| 514 } |
| 515 if (layerIter1.x() != layerIter2.x()) { |
| 516 return false; |
| 517 } |
| 518 if (layerIter1.y() != layerIter2.y()) { |
| 519 return false; |
| 520 } |
| 521 layerIter1.next(); |
| 522 layerIter2.next(); |
| 523 } |
| 524 if (!layerIter1.done()) { |
| 525 return false; |
| 526 } |
| 527 if (!layerIter2.done()) { |
| 528 return false; |
| 529 } |
| 530 return true; |
| 531 } |
| 532 }; |
| 533 |
| 501 static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData
& d, | 534 static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData
& d, |
| 502 const SkCanvas* canvas1, const SkCanvas* can
vas2, | 535 const SkCanvas* canvas1, const SkCanvas* can
vas2, |
| 503 CanvasTestStep* testStep) { | 536 CanvasTestStep* testStep) { |
| 504 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == | 537 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == |
| 505 canvas2->getDeviceSize(), testStep->assertMessage()); | 538 canvas2->getDeviceSize(), testStep->assertMessage()); |
| 506 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() == | 539 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() == |
| 507 canvas2->getSaveCount(), testStep->assertMessage()); | 540 canvas2->getSaveCount(), testStep->assertMessage()); |
| 508 | 541 |
| 509 SkRect bounds1, bounds2; | 542 SkRect bounds1, bounds2; |
| 510 REPORTER_ASSERT_MESSAGE(reporter, | 543 REPORTER_ASSERT_MESSAGE(reporter, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 521 SkIRect deviceBounds1, deviceBounds2; | 554 SkIRect deviceBounds1, deviceBounds2; |
| 522 REPORTER_ASSERT_MESSAGE(reporter, | 555 REPORTER_ASSERT_MESSAGE(reporter, |
| 523 canvas1->getClipDeviceBounds(&deviceBounds1) == | 556 canvas1->getClipDeviceBounds(&deviceBounds1) == |
| 524 canvas2->getClipDeviceBounds(&deviceBounds2), | 557 canvas2->getClipDeviceBounds(&deviceBounds2), |
| 525 testStep->assertMessage()); | 558 testStep->assertMessage()); |
| 526 REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2, testStep->
assertMessage()); | 559 REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2, testStep->
assertMessage()); |
| 527 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() == | 560 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() == |
| 528 canvas2->getTotalMatrix(), testStep->assertMessage()); | 561 canvas2->getTotalMatrix(), testStep->assertMessage()); |
| 529 REPORTER_ASSERT_MESSAGE(reporter, equal_clips(*canvas1, *canvas2), testStep-
>assertMessage()); | 562 REPORTER_ASSERT_MESSAGE(reporter, equal_clips(*canvas1, *canvas2), testStep-
>assertMessage()); |
| 530 | 563 |
| 531 SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false); | 564 REPORTER_ASSERT_MESSAGE(reporter, |
| 532 SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false); | 565 CanvasTestingAccess::SameState(canvas1, canvas2), |
| 533 while (!layerIter1.done() && !layerIter2.done()) { | 566 testStep->assertMessage()); |
| 534 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.matrix() == | |
| 535 layerIter2.matrix(), testStep->assertMessage()); | |
| 536 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.clip() == | |
| 537 layerIter2.clip(), testStep->assertMessage()); | |
| 538 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.paint() == | |
| 539 layerIter2.paint(), testStep->assertMessage()); | |
| 540 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.x() == | |
| 541 layerIter2.x(), testStep->assertMessage()); | |
| 542 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.y() == | |
| 543 layerIter2.y(), testStep->assertMessage()); | |
| 544 layerIter1.next(); | |
| 545 layerIter2.next(); | |
| 546 } | |
| 547 REPORTER_ASSERT_MESSAGE(reporter, layerIter1.done(), | |
| 548 testStep->assertMessage()); | |
| 549 REPORTER_ASSERT_MESSAGE(reporter, layerIter2.done(), | |
| 550 testStep->assertMessage()); | |
| 551 | |
| 552 } | 567 } |
| 553 | 568 |
| 554 static void TestPdfDevice(skiatest::Reporter* reporter, | 569 static void TestPdfDevice(skiatest::Reporter* reporter, |
| 555 const TestData& d, | 570 const TestData& d, |
| 556 CanvasTestStep* testStep) { | 571 CanvasTestStep* testStep) { |
| 557 SkDynamicMemoryWStream outStream; | 572 SkDynamicMemoryWStream outStream; |
| 558 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); | 573 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); |
| 559 #if SK_SUPPORT_PDF | 574 #if SK_SUPPORT_PDF |
| 560 REPORTER_ASSERT(reporter, doc); | 575 REPORTER_ASSERT(reporter, doc); |
| 561 #else | 576 #else |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 765 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
| 751 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 766 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
| 752 REPORTER_ASSERT(reporter, clip1 == clip2); | 767 REPORTER_ASSERT(reporter, clip1 == clip2); |
| 753 | 768 |
| 754 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); | 769 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); |
| 755 filterCanvas.scale(0.75f, 0.5f); | 770 filterCanvas.scale(0.75f, 0.5f); |
| 756 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 771 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
| 757 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 772 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
| 758 REPORTER_ASSERT(reporter, clip1 == clip2); | 773 REPORTER_ASSERT(reporter, clip1 == clip2); |
| 759 } | 774 } |
| OLD | NEW |