| 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" |
| 49 #include "SkDocument.h" | 50 #include "SkDocument.h" |
| 50 #include "SkMatrix.h" | 51 #include "SkMatrix.h" |
| 51 #include "SkNWayCanvas.h" | 52 #include "SkNWayCanvas.h" |
| 52 #include "SkPaint.h" | 53 #include "SkPaint.h" |
| 53 #include "SkPaintFilterCanvas.h" | 54 #include "SkPaintFilterCanvas.h" |
| 54 #include "SkPath.h" | 55 #include "SkPath.h" |
| 55 #include "SkPicture.h" | 56 #include "SkPicture.h" |
| 56 #include "SkPictureRecord.h" | 57 #include "SkPictureRecord.h" |
| 57 #include "SkPictureRecorder.h" | 58 #include "SkPictureRecorder.h" |
| 58 #include "SkRect.h" | 59 #include "SkRect.h" |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); | 491 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
| 491 canvas->save(); | 492 canvas->save(); |
| 492 canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); | 493 canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); |
| 493 canvas->drawRect(d.fRect,d.fPaint); | 494 canvas->drawRect(d.fRect,d.fPaint); |
| 494 canvas->flush(); | 495 canvas->flush(); |
| 495 canvas->restore(); | 496 canvas->restore(); |
| 496 canvas->restore(); | 497 canvas->restore(); |
| 497 } | 498 } |
| 498 TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); | 499 TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); |
| 499 | 500 |
| 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 | |
| 534 static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData
& d, | 501 static void AssertCanvasStatesEqual(skiatest::Reporter* reporter, const TestData
& d, |
| 535 const SkCanvas* canvas1, const SkCanvas* can
vas2, | 502 const SkCanvas* canvas1, const SkCanvas* can
vas2, |
| 536 CanvasTestStep* testStep) { | 503 CanvasTestStep* testStep) { |
| 537 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == | 504 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getDeviceSize() == |
| 538 canvas2->getDeviceSize(), testStep->assertMessage()); | 505 canvas2->getDeviceSize(), testStep->assertMessage()); |
| 539 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() == | 506 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getSaveCount() == |
| 540 canvas2->getSaveCount(), testStep->assertMessage()); | 507 canvas2->getSaveCount(), testStep->assertMessage()); |
| 541 | 508 |
| 542 SkRect bounds1, bounds2; | 509 SkRect bounds1, bounds2; |
| 543 REPORTER_ASSERT_MESSAGE(reporter, | 510 REPORTER_ASSERT_MESSAGE(reporter, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 554 SkIRect deviceBounds1, deviceBounds2; | 521 SkIRect deviceBounds1, deviceBounds2; |
| 555 REPORTER_ASSERT_MESSAGE(reporter, | 522 REPORTER_ASSERT_MESSAGE(reporter, |
| 556 canvas1->getClipDeviceBounds(&deviceBounds1) == | 523 canvas1->getClipDeviceBounds(&deviceBounds1) == |
| 557 canvas2->getClipDeviceBounds(&deviceBounds2), | 524 canvas2->getClipDeviceBounds(&deviceBounds2), |
| 558 testStep->assertMessage()); | 525 testStep->assertMessage()); |
| 559 REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2, testStep->
assertMessage()); | 526 REPORTER_ASSERT_MESSAGE(reporter, deviceBounds1 == deviceBounds2, testStep->
assertMessage()); |
| 560 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() == | 527 REPORTER_ASSERT_MESSAGE(reporter, canvas1->getTotalMatrix() == |
| 561 canvas2->getTotalMatrix(), testStep->assertMessage()); | 528 canvas2->getTotalMatrix(), testStep->assertMessage()); |
| 562 REPORTER_ASSERT_MESSAGE(reporter, equal_clips(*canvas1, *canvas2), testStep-
>assertMessage()); | 529 REPORTER_ASSERT_MESSAGE(reporter, equal_clips(*canvas1, *canvas2), testStep-
>assertMessage()); |
| 563 | 530 |
| 564 REPORTER_ASSERT_MESSAGE(reporter, | 531 SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false); |
| 565 CanvasTestingAccess::SameState(canvas1, canvas2), | 532 SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false); |
| 566 testStep->assertMessage()); | 533 while (!layerIter1.done() && !layerIter2.done()) { |
| 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 |
| 567 } | 552 } |
| 568 | 553 |
| 569 static void TestPdfDevice(skiatest::Reporter* reporter, | 554 static void TestPdfDevice(skiatest::Reporter* reporter, |
| 570 const TestData& d, | 555 const TestData& d, |
| 571 CanvasTestStep* testStep) { | 556 CanvasTestStep* testStep) { |
| 572 SkDynamicMemoryWStream outStream; | 557 SkDynamicMemoryWStream outStream; |
| 573 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); | 558 SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(&outStream)); |
| 574 #if SK_SUPPORT_PDF | 559 #if SK_SUPPORT_PDF |
| 575 REPORTER_ASSERT(reporter, doc); | 560 REPORTER_ASSERT(reporter, doc); |
| 576 #else | 561 #else |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 750 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
| 766 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 751 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
| 767 REPORTER_ASSERT(reporter, clip1 == clip2); | 752 REPORTER_ASSERT(reporter, clip1 == clip2); |
| 768 | 753 |
| 769 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); | 754 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); |
| 770 filterCanvas.scale(0.75f, 0.5f); | 755 filterCanvas.scale(0.75f, 0.5f); |
| 771 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 756 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
| 772 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 757 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
| 773 REPORTER_ASSERT(reporter, clip1 == clip2); | 758 REPORTER_ASSERT(reporter, clip1 == clip2); |
| 774 } | 759 } |
| OLD | NEW |