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 |
11 * used in several test cases that verify that different types of SkCanvas | 11 * used in several test cases that verify that different types of SkCanvas |
12 * flavors and derivatives pass it and yield consistent behavior. The | 12 * flavors and derivatives pass it and yield consistent behavior. The |
13 * test cases analyse results that are queryable through the API. They do | 13 * test cases analyse results that are queryable through the API. They do |
14 * not look at rendering results. | 14 * not look at rendering results. |
15 * | 15 * |
16 * Adding test stepss: | 16 * Adding test stepss: |
17 * The general pattern for creating a new test step is to write a test | 17 * The general pattern for creating a new test step is to write a test |
18 * function of the form: | 18 * function of the form: |
19 * | 19 * |
20 * static void MyTestStepFunction(SkCanvas* canvas, | 20 * static void MyTestStepFunction(SkCanvas* canvas, |
| 21 * const TestData& d, |
21 * skiatest::Reporter* reporter, | 22 * skiatest::Reporter* reporter, |
22 * CanvasTestStep* testStep) | 23 * CanvasTestStep* testStep) |
23 * { | 24 * { |
24 * canvas->someCanvasAPImethod(); | 25 * canvas->someCanvasAPImethod(); |
25 * (...) | 26 * (...) |
26 * REPORTER_ASSERT_MESSAGE(reporter, (...), \ | 27 * REPORTER_ASSERT_MESSAGE(reporter, (...), \ |
27 * testStep->assertMessage()); | 28 * testStep->assertMessage()); |
28 * } | 29 * } |
29 * | 30 * |
30 * The definition of the test step function should be followed by an | 31 * The definition of the test step function should be followed by an |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); | 492 canvas->translate(SkIntToScalar(2), SkIntToScalar(1)); |
492 canvas->save(); | 493 canvas->save(); |
493 canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); | 494 canvas->scale(SkIntToScalar(3), SkIntToScalar(3)); |
494 canvas->drawRect(d.fRect,d.fPaint); | 495 canvas->drawRect(d.fRect,d.fPaint); |
495 canvas->flush(); | 496 canvas->flush(); |
496 canvas->restore(); | 497 canvas->restore(); |
497 canvas->restore(); | 498 canvas->restore(); |
498 } | 499 } |
499 TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); | 500 TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep); |
500 | 501 |
| 502 static void DescribeTopLayerTestStep(SkCanvas* canvas, |
| 503 const TestData& d, |
| 504 skiatest::Reporter* reporter, |
| 505 CanvasTestStep* testStep) { |
| 506 SkMatrix m; |
| 507 SkIRect r; |
| 508 // NOTE: adjustToTopLayer() does *not* reduce the clip size, even if the can
vas |
| 509 // is smaller than 10x10! |
| 510 |
| 511 canvas->temporary_internal_describeTopLayer(&m, &r); |
| 512 REPORTER_ASSERT_MESSAGE(reporter, m.isIdentity(), testStep->assertMessage())
; |
| 513 REPORTER_ASSERT_MESSAGE(reporter, r == SkIRect::MakeXYWH(0, 0, 2, 2), |
| 514 testStep->assertMessage()); |
| 515 |
| 516 // Putting a full-canvas layer on it should make no change to the results. |
| 517 SkRect layerBounds = SkRect::MakeXYWH(0.f, 0.f, 10.f, 10.f); |
| 518 canvas->saveLayer(layerBounds, nullptr); |
| 519 canvas->temporary_internal_describeTopLayer(&m, &r); |
| 520 REPORTER_ASSERT_MESSAGE(reporter, m.isIdentity(), testStep->assertMessage())
; |
| 521 REPORTER_ASSERT_MESSAGE(reporter, r == SkIRect::MakeXYWH(0, 0, 2, 2), |
| 522 testStep->assertMessage()); |
| 523 canvas->restore(); |
| 524 |
| 525 // Adding a translated layer translates the results. |
| 526 // Default canvas is only 2x2, so can't offset our layer by very much at all
; |
| 527 // saveLayer() aborts if the bounds don't intersect. |
| 528 layerBounds = SkRect::MakeXYWH(1.f, 1.f, 6.f, 6.f); |
| 529 canvas->saveLayer(layerBounds, nullptr); |
| 530 canvas->temporary_internal_describeTopLayer(&m, &r); |
| 531 REPORTER_ASSERT_MESSAGE(reporter, m == SkMatrix::MakeTrans(-1.f, -1.f), |
| 532 testStep->assertMessage()); |
| 533 REPORTER_ASSERT_MESSAGE(reporter, r == SkIRect::MakeXYWH(0, 0, 1, 1), |
| 534 testStep->assertMessage()); |
| 535 canvas->restore(); |
| 536 |
| 537 } |
| 538 TEST_STEP(DescribeTopLayer, DescribeTopLayerTestStep); |
| 539 |
| 540 |
501 class CanvasTestingAccess { | 541 class CanvasTestingAccess { |
502 public: | 542 public: |
503 static bool SameState(const SkCanvas* canvas1, const SkCanvas* canvas2) { | 543 static bool SameState(const SkCanvas* canvas1, const SkCanvas* canvas2) { |
504 SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false); | 544 SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false); |
505 SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false); | 545 SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false); |
506 while (!layerIter1.done() && !layerIter2.done()) { | 546 while (!layerIter1.done() && !layerIter2.done()) { |
507 if (layerIter1.matrix() != layerIter2.matrix()) { | 547 if (layerIter1.matrix() != layerIter2.matrix()) { |
508 return false; | 548 return false; |
509 } | 549 } |
510 if (layerIter1.clip() != layerIter2.clip()) { | 550 if (layerIter1.clip() != layerIter2.clip()) { |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 806 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
767 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 807 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
768 REPORTER_ASSERT(reporter, clip1 == clip2); | 808 REPORTER_ASSERT(reporter, clip1 == clip2); |
769 | 809 |
770 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); | 810 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); |
771 filterCanvas.scale(0.75f, 0.5f); | 811 filterCanvas.scale(0.75f, 0.5f); |
772 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); | 812 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa
trix()); |
773 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); | 813 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl
ipBounds(&clip2)); |
774 REPORTER_ASSERT(reporter, clip1 == clip2); | 814 REPORTER_ASSERT(reporter, clip1 == clip2); |
775 } | 815 } |
OLD | NEW |