summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-setTransform.js
blob: b9ce2179618db4fd9739e94f705c9592120c7f38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
description("Series of tests to ensure correct behaviour of canvas.setTransform()");
var ctx = document.createElement('canvas').getContext('2d');

// Reset the CTM to the initial matrix
ctx.beginPath();
ctx.scale(0.5, 0.5);
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 100, 100);

var imageData = ctx.getImageData(1, 1, 98, 98);
var imgdata = imageData.data;
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "128");
shouldBe("imgdata[6]", "0");

// setTransform should not affect the current path
ctx.beginPath();
ctx.rect(0,0,100,100);
ctx.save();
ctx.setTransform(0.5, 0, 0, 0.5, 10, 10);
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 100, 100);
ctx.restore();
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 100, 100);

imageData = ctx.getImageData(1, 1, 98, 98);
imgdata = imageData.data;
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "128");
shouldBe("imgdata[6]", "0");

// setTransform should not affect the CTM outside of save() and restore()
ctx.beginPath();
ctx.fillStyle = 'green';
ctx.save();
ctx.setTransform(0.5, 0, 0, 0.5, 0, 0);
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 100, 100);
ctx.restore();
ctx.fillRect(0, 0, 100, 100);

imageData = ctx.getImageData(1, 1, 98, 98);
imgdata = imageData.data;
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "128");
shouldBe("imgdata[6]", "0");


// stop drawing on not-invertible CTM
ctx.beginPath();
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 100, 100);
ctx.setTransform(0, 0, 0, 0, 0, 0);
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 100, 100);

imageData = ctx.getImageData(1, 1, 98, 98);
imgdata = imageData.data;
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "128");
shouldBe("imgdata[6]", "0");

// setTransform with a not-invertible matrix should only stop the drawing up to the next restore()
ctx.beginPath();
ctx.save();
ctx.setTransform(0, 0, 0, 0, 0, 0);
ctx.fillStyle = 'red';
ctx.fillRect(0, 0, 100, 100);
ctx.restore();
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 100, 100);

imageData = ctx.getImageData(1, 1, 98, 98);
imgdata = imageData.data;
shouldBe("imgdata[4]", "0");
shouldBe("imgdata[5]", "128");
shouldBe("imgdata[6]", "0");

var successfullyParsed = true;