aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/CanvasTest.cpp
diff options
context:
space:
mode:
authorGravatar vjiaoblack <vjiaoblack@google.com>2016-07-13 14:05:28 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-13 14:05:28 -0700
commite5de130788c8637d2f7df9ddb0241b78e04d5882 (patch)
treee837af1f0ce2a87a9b4be70172f74d9a5dea57a4 /tests/CanvasTest.cpp
parentf382b48687176f15091c2defc0002f0a189f4167 (diff)
Added the framework for having canvas/recorder/picture record depth_set's.
Diffstat (limited to 'tests/CanvasTest.cpp')
-rw-r--r--tests/CanvasTest.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/CanvasTest.cpp b/tests/CanvasTest.cpp
index 82e065f5ac..1e5f9e18bc 100644
--- a/tests/CanvasTest.cpp
+++ b/tests/CanvasTest.cpp
@@ -779,6 +779,45 @@ DEF_TEST(Canvas_ClipEmptyPath, reporter) {
canvas.restore();
}
+#define SHADOW_TEST_CANVAS_CONST 10
+
+class SkShadowTestCanvas : public SkPaintFilterCanvas {
+public:
+
+ SkShadowTestCanvas(int x, int y, skiatest::Reporter* reporter)
+ : INHERITED(x,y)
+ , fReporter(reporter) {}
+
+ bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type type) const {
+ REPORTER_ASSERT(this->fReporter, this->getZ() == SHADOW_TEST_CANVAS_CONST);
+
+ return true;
+ }
+
+ void testUpdateDepth(skiatest::Reporter *reporter) {
+ // set some depths (with picture enabled), then check them as they get set
+
+ REPORTER_ASSERT(reporter, this->getZ() == 0);
+ this->translateZ(-10);
+ REPORTER_ASSERT(reporter, this->getZ() == -10);
+
+ this->save();
+ this->translateZ(20);
+ REPORTER_ASSERT(reporter, this->getZ() == 10);
+
+ this->restore();
+ REPORTER_ASSERT(reporter, this->getZ() == -10);
+
+ this->translateZ(13.14f);
+ REPORTER_ASSERT(reporter, SkScalarNearlyEqual(this->getZ(), 3.14f));
+ }
+
+private:
+ skiatest::Reporter* fReporter;
+
+ typedef SkPaintFilterCanvas INHERITED;
+};
+
namespace {
class MockFilterCanvas : public SkPaintFilterCanvas {
@@ -812,6 +851,20 @@ DEF_TEST(PaintFilterCanvas_ConsistentState, reporter) {
REPORTER_ASSERT(reporter, canvas.getTotalMatrix() == filterCanvas.getTotalMatrix());
REPORTER_ASSERT(reporter, canvas.getClipBounds(&clip1) == filterCanvas.getClipBounds(&clip2));
REPORTER_ASSERT(reporter, clip1 == clip2);
+
+ SkShadowTestCanvas* tCanvas = new SkShadowTestCanvas(100,100, reporter);
+ tCanvas->testUpdateDepth(reporter);
+ delete(tCanvas);
+
+ SkPictureRecorder recorder;
+ SkShadowTestCanvas *tSCanvas = new SkShadowTestCanvas(100, 100, reporter);
+ SkCanvas *tPCanvas = recorder.beginRecording(SkRect::MakeIWH(100, 100));
+
+ tPCanvas->translateZ(SHADOW_TEST_CANVAS_CONST);
+ sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture();
+ tSCanvas->drawPicture(pic);
+
+ delete(tSCanvas);
}
///////////////////////////////////////////////////////////////////////////////////////////////////