| Index: tests/CanvasTest.cpp
|
| diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
|
| index 1f217e21ca076dd76ee0e82fef74efa29a33b0a5..f5befc1613d2d02537759580c1bb264b99193674 100644
|
| --- a/tests/CanvasTest.cpp
|
| +++ b/tests/CanvasTest.cpp
|
| @@ -18,6 +18,7 @@
|
| * function of the form:
|
| *
|
| * static void MyTestStepFunction(SkCanvas* canvas,
|
| + * const TestData& d,
|
| * skiatest::Reporter* reporter,
|
| * CanvasTestStep* testStep)
|
| * {
|
| @@ -498,6 +499,53 @@ static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, const TestData&
|
| }
|
| TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep);
|
|
|
| +static void AdjustToTopLayerTestStep(SkCanvas* canvas,
|
| + const TestData& d,
|
| + skiatest::Reporter* reporter,
|
| + CanvasTestStep* testStep) {
|
| + SkMatrix m = SkMatrix::I();
|
| + SkIRect r = SkIRect::MakeXYWH(0, 0, 10, 10);
|
| + SkMatrix expectedMatrix = m;
|
| + SkIRect expectedRect = r;
|
| + // NOTE: adjustToTopLayer() does *not* reduce the clip size, even if the canvas
|
| + // is smaller than 10x10!
|
| +
|
| + canvas->adjustToTopLayer(&m, &r);
|
| + REPORTER_ASSERT_MESSAGE(reporter, m.isIdentity(), testStep->assertMessage());
|
| + REPORTER_ASSERT_MESSAGE(reporter, r == expectedRect, testStep->assertMessage());
|
| +
|
| + // Putting a full-canvas layer on it should make no change to the results.
|
| + m = SkMatrix::I();
|
| + r = SkIRect::MakeXYWH(0, 0, 10, 10);
|
| + SkRect layerBounds = SkRect::MakeXYWH(0.f, 0.f, 10.f, 10.f);
|
| + expectedMatrix = m;
|
| + expectedRect = r;
|
| +
|
| + canvas->saveLayer(layerBounds, nullptr);
|
| + canvas->adjustToTopLayer(&m, &r);
|
| + REPORTER_ASSERT_MESSAGE(reporter, m.isIdentity(), testStep->assertMessage());
|
| + REPORTER_ASSERT_MESSAGE(reporter, r == expectedRect, testStep->assertMessage());
|
| + canvas->restore();
|
| +
|
| + // Adding a translated layer translates the results.
|
| + m = SkMatrix::I();
|
| + r = SkIRect::MakeXYWH(0, 0, 10, 10);
|
| + layerBounds = SkRect::MakeXYWH(1.f, 1.f, 6.f, 6.f);
|
| + expectedMatrix = SkMatrix::MakeTrans(-1.f, -1.f);
|
| + expectedRect = SkIRect::MakeXYWH(-1, -1, 10, 10);
|
| +
|
| + // Default canvas is only 2x2, so can't offset our layer by very much at all;
|
| + // saveLayer() aborts if the bounds don't intersect.
|
| + canvas->saveLayer(layerBounds, nullptr);
|
| + canvas->adjustToTopLayer(&m, &r);
|
| + REPORTER_ASSERT_MESSAGE(reporter, m == expectedMatrix, testStep->assertMessage());
|
| + REPORTER_ASSERT_MESSAGE(reporter, r == expectedRect, testStep->assertMessage());
|
| + canvas->restore();
|
| +
|
| +}
|
| +TEST_STEP(AdjustToTopLayer, AdjustToTopLayerTestStep);
|
| +
|
| +
|
| class CanvasTestingAccess {
|
| public:
|
| static bool SameState(const SkCanvas* canvas1, const SkCanvas* canvas2) {
|
|
|