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

Unified Diff: tests/CanvasTest.cpp

Issue 1986383002: SkCanvas::adjustToTopLayer() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Mike's comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/CanvasTest.cpp
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index 1f217e21ca076dd76ee0e82fef74efa29a33b0a5..70c2c04ffabf511239239fe8fe3cf91ab78582af 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,45 @@ static void NestedSaveRestoreWithFlushTestStep(SkCanvas* canvas, const TestData&
}
TEST_STEP(NestedSaveRestoreWithFlush, NestedSaveRestoreWithFlushTestStep);
+static void DescribeTopLayerTestStep(SkCanvas* canvas,
+ const TestData& d,
+ skiatest::Reporter* reporter,
+ CanvasTestStep* testStep) {
+ SkMatrix m;
+ SkIRect r;
+ // NOTE: adjustToTopLayer() does *not* reduce the clip size, even if the canvas
+ // is smaller than 10x10!
+
+ canvas->temporary_internal_describeTopLayer(&m, &r);
+ REPORTER_ASSERT_MESSAGE(reporter, m.isIdentity(), testStep->assertMessage());
+ REPORTER_ASSERT_MESSAGE(reporter, r == SkIRect::MakeXYWH(0, 0, 2, 2),
+ testStep->assertMessage());
+
+ // Putting a full-canvas layer on it should make no change to the results.
+ SkRect layerBounds = SkRect::MakeXYWH(0.f, 0.f, 10.f, 10.f);
+ canvas->saveLayer(layerBounds, nullptr);
+ canvas->temporary_internal_describeTopLayer(&m, &r);
+ REPORTER_ASSERT_MESSAGE(reporter, m.isIdentity(), testStep->assertMessage());
+ REPORTER_ASSERT_MESSAGE(reporter, r == SkIRect::MakeXYWH(0, 0, 2, 2),
+ testStep->assertMessage());
+ canvas->restore();
+
+ // Adding a translated layer translates the results.
+ // Default canvas is only 2x2, so can't offset our layer by very much at all;
+ // saveLayer() aborts if the bounds don't intersect.
+ layerBounds = SkRect::MakeXYWH(1.f, 1.f, 6.f, 6.f);
+ canvas->saveLayer(layerBounds, nullptr);
+ canvas->temporary_internal_describeTopLayer(&m, &r);
+ REPORTER_ASSERT_MESSAGE(reporter, m == SkMatrix::MakeTrans(-1.f, -1.f),
+ testStep->assertMessage());
+ REPORTER_ASSERT_MESSAGE(reporter, r == SkIRect::MakeXYWH(0, 0, 1, 1),
+ testStep->assertMessage());
+ canvas->restore();
+
+}
+TEST_STEP(DescribeTopLayer, DescribeTopLayerTestStep);
+
+
class CanvasTestingAccess {
public:
static bool SameState(const SkCanvas* canvas1, const SkCanvas* canvas2) {
« no previous file with comments | « src/core/SkCanvas.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698