-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdl-test.html
190 lines (161 loc) · 3.74 KB
/
dl-test.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<html>
<head>
<style>
div {
display: inline-block;
}
.square {
width:10px;
height:10px;
background-color:green;
}
.wrapper {
display: inline;
position: relative;
z-index: 0;
}
body {
overflow: hidden;
}
.active {
transform: translate3d(1px, 1px, 1px);
}
.inactive {
transform: translate(1px);
}
.flattened {
opacity: 0.95;
}
</style>
</head>
<body id="body">
displaylist_mutate
</body>
<script>
function parseArgs() {
var query = window.location.search.substring(1);
var split = query.split("&");
var args = {}
for (var i = 0; i < split.length; i++) {
var pair = split[i].split("=");
var key = pair[0];
var value = true;
if (pair.length >= 2) {
value = pair[1];
}
args[key] = value;
}
return args;
}
var gArgs = null;
function arg(key, defaultVal) {
if (gArgs === null) {
gArgs = parseArgs();
}
if (!(key in gArgs))
return defaultVal;
return gArgs[key];
}
/**
* count=<number>
*
* Specify the number of rects to create, defaults
* to 1000.
*/
var divCount = arg("count", 10000);
/**
* layer=active|inactive|flattened|none
*
* Specifies what type of Layer to create around each rects.
* active and inactive create a transform, with active using 3d
* to force an active layer.
* flattened creates an opacity, which gecko will flatten away.
* Default is none, which creates no layers.
*/
var layerType = arg("layer", "none");
/**
* modify=all|one|iterate|offscreen
*
* Specifies which rect to modify each frame.
* all modifies all rectangles, one modifies only the first.
* iterate (the default) modifies a successive rect each frame.
*/
var modify = arg("modify", "iterate");
/**
* rebuild
*
* Forces a full display item rebuild each frame (disables
* retained-dl) by triggering a no-op style change on the
* body element.
*/
var rebuild = arg("rebuild", false);
/**
* siblings
*
* Max number of siblings for each group of rectangles
* before we wrap them in a container element.
*/
var siblings = arg("siblings", 0);
var depth = (siblings == 0) ? 1 : Math.pow(divCount, 1/siblings);
var created = 0;
function createNodes(depth) {
var elem = document.createElement("div");
if (depth == 0) {
elem.id = created++;
elem.className = "square " + layerType;
return elem;
} else {
elem.className = "wrapper";
}
for (var i = 0; i < ((siblings == 0) ? divCount : siblings); i++) {
if (created == divCount) {
return elem;
}
elem.appendChild(createNodes(depth - 1));
}
return elem;
}
document.getElementById("body").appendChild(createNodes(Math.floor(depth)));
if (modify == "offscreen") {
var div = document.createElement("div");
div.id = "offscreen";
div.className = layerType;
div.style.display = "block";
div.style.position = "absolute";
div.style.top = "2000px";
document.getElementById("body").appendChild(div);
}
function toggleSquare(index) {
if (document.getElementById(index).style.backgroundColor == "red") {
document.getElementById(index).style.backgroundColor = "green";
} else {
document.getElementById(index).style.backgroundColor = "red";
}
}
var iteration = 0;
function runFrame() {
if (modify == "all") {
for (var i = 0; i < divCount; i++) {
toggleSquare(i);
}
} else if (modify == "offscreen") {
toggleSquare("offscreen");
} else {
toggleSquare(iteration);
if (modify == "iterate") {
iteration++;
iteration = iteration % divCount;
}
}
if (rebuild) {
if (document.body.style.left == "1px") {
document.body.style.left = "2px";
} else {
document.body.style.left = "1px";
}
}
window.requestAnimationFrame(runFrame);
}
window.requestAnimationFrame(runFrame);
</script>
</html>