Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(103)

Side by Side Diff: tests/CanvasTest.cpp

Issue 1986383002: SkCanvas::adjustToTopLayer() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« include/core/SkCanvas.h ('K') | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 AdjustToTopLayerTestStep(SkCanvas* canvas,
503 const TestData& d,
504 skiatest::Reporter* reporter,
505 CanvasTestStep* testStep) {
506 SkMatrix m = SkMatrix::I();
507 SkIRect r = SkIRect::MakeXYWH(0, 0, 10, 10);
508 SkMatrix expectedMatrix = m;
509 SkIRect expectedRect = r;
510 // NOTE: adjustToTopLayer() does *not* reduce the clip size, even if the can vas
511 // is smaller than 10x10!
512
513 canvas->adjustToTopLayer(&m, &r);
514 REPORTER_ASSERT_MESSAGE(reporter, m.isIdentity(), testStep->assertMessage()) ;
515 REPORTER_ASSERT_MESSAGE(reporter, r == expectedRect, testStep->assertMessage ());
516
517 // Putting a full-canvas layer on it should make no change to the results.
518 m = SkMatrix::I();
519 r = SkIRect::MakeXYWH(0, 0, 10, 10);
520 SkRect layerBounds = SkRect::MakeXYWH(0.f, 0.f, 10.f, 10.f);
521 expectedMatrix = m;
522 expectedRect = r;
523
524 canvas->saveLayer(layerBounds, nullptr);
525 canvas->adjustToTopLayer(&m, &r);
526 REPORTER_ASSERT_MESSAGE(reporter, m.isIdentity(), testStep->assertMessage()) ;
527 REPORTER_ASSERT_MESSAGE(reporter, r == expectedRect, testStep->assertMessage ());
528 canvas->restore();
529
530 // Adding a translated layer translates the results.
531 m = SkMatrix::I();
532 r = SkIRect::MakeXYWH(0, 0, 10, 10);
533 layerBounds = SkRect::MakeXYWH(1.f, 1.f, 6.f, 6.f);
534 expectedMatrix = SkMatrix::MakeTrans(-1.f, -1.f);
535 expectedRect = SkIRect::MakeXYWH(-1, -1, 10, 10);
536
537 // Default canvas is only 2x2, so can't offset our layer by very much at all ;
538 // saveLayer() aborts if the bounds don't intersect.
539 canvas->saveLayer(layerBounds, nullptr);
540 canvas->adjustToTopLayer(&m, &r);
541 REPORTER_ASSERT_MESSAGE(reporter, m == expectedMatrix, testStep->assertMessa ge());
542 REPORTER_ASSERT_MESSAGE(reporter, r == expectedRect, testStep->assertMessage ());
543 canvas->restore();
544
545 }
546 TEST_STEP(AdjustToTopLayer, AdjustToTopLayerTestStep);
547
548
501 class CanvasTestingAccess { 549 class CanvasTestingAccess {
502 public: 550 public:
503 static bool SameState(const SkCanvas* canvas1, const SkCanvas* canvas2) { 551 static bool SameState(const SkCanvas* canvas1, const SkCanvas* canvas2) {
504 SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false); 552 SkCanvas::LayerIter layerIter1(const_cast<SkCanvas*>(canvas1), false);
505 SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false); 553 SkCanvas::LayerIter layerIter2(const_cast<SkCanvas*>(canvas2), false);
506 while (!layerIter1.done() && !layerIter2.done()) { 554 while (!layerIter1.done() && !layerIter2.done()) {
507 if (layerIter1.matrix() != layerIter2.matrix()) { 555 if (layerIter1.matrix() != layerIter2.matrix()) {
508 return false; 556 return false;
509 } 557 }
510 if (layerIter1.clip() != layerIter2.clip()) { 558 if (layerIter1.clip() != layerIter2.clip()) {
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa trix()); 814 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa trix());
767 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl ipBounds(&clip2)); 815 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl ipBounds(&clip2));
768 REPORTER_ASSERT(reporter, clip1 == clip2); 816 REPORTER_ASSERT(reporter, clip1 == clip2);
769 817
770 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100)); 818 filterCanvas.clipRect(SkRect::MakeXYWH(30.5f, 30.7f, 100, 100));
771 filterCanvas.scale(0.75f, 0.5f); 819 filterCanvas.scale(0.75f, 0.5f);
772 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa trix()); 820 REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMa trix());
773 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl ipBounds(&clip2)); 821 REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getCl ipBounds(&clip2));
774 REPORTER_ASSERT(reporter, clip1 == clip2); 822 REPORTER_ASSERT(reporter, clip1 == clip2);
775 } 823 }
OLDNEW
« include/core/SkCanvas.h ('K') | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698