forked from WebKit/WebKit-http
-
Notifications
You must be signed in to change notification settings - Fork 158
Expand file tree
/
Copy pathasync-image-multiple-clients-repaint.html
More file actions
94 lines (88 loc) · 3.38 KB
/
async-image-multiple-clients-repaint.html
File metadata and controls
94 lines (88 loc) · 3.38 KB
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
<!DOCTYPE html>
<html>
<head>
<style>
.box {
image-rendering: crisp-edges;
}
.small-box {
height: 50px;
width: 100px;
background-position: -50px -16500px;
background-size: 200px 33100px;
}
.large-box {
height: 100px;
width: 200px;
background-position: -100px -33000px;
background-size: 400px 66200px;
}
.vertical-space {
height: 250px;
width: 250px;
}
.image-background {
}
</style>
</head>
<body>
<div class="box small-box image-background"></div>
<br>
<div class="vertical-space"></div>
<br>
<div class="box large-box image-background"></div>
<script>
function setElementImageBackground(element, image) {
return new Promise((resolve) => {
element.style.backgroundImage = 'url(' + image.src + ')';
// Force layout and display so the image frame starts decoding
document.body.offsetHeight;
testRunner.display();
element.addEventListener("webkitImageFrameReady", function() {
resolve();
}, false);
});
}
function recordAndStopTrackingRepaints() {
var repaintRects = window.internals.repaintRectsAsText();
internals.stopTrackingRepaints()
var pre = document.createElement('pre');
document.body.appendChild(pre);
pre.innerHTML = repaintRects;
}
(function() {
if (window.internals && window.testRunner) {
internals.clearMemoryCache();
internals.settings.setWebkitImageReadyEventEnabled(true);
internals.settings.setLargeImageAsyncDecodingEnabled(true);
testRunner.dumpAsText(true);
testRunner.waitUntilDone();
}
var image = new Image();
image.onload = function() {
// Force async image decoding for this image.
if (window.internals)
internals.setAsyncDecodingEnabledForTesting(image, true);
if (window.internals && window.testRunner) {
setElementImageBackground(document.querySelector(".small-box"), image).then(() => {
// Call the next setElementImageBackground() asynchronously, using setTimeout(, 0),
// to avoid calling testRunner.display() while the webkitImageFrameReady callback of
// the previous setElementImageBackground() still in the call stack.
setTimeout(function() {
internals.startTrackingRepaints();
setElementImageBackground(document.querySelector(".large-box"), image).then(() => {
recordAndStopTrackingRepaints();
testRunner.notifyDone();
});
}, 0);
});
} else {
document.querySelector(".small-box").style.backgroundImage = 'url(' + image.src + ')';
document.querySelector(".large-box").style.backgroundImage = 'url(' + image.src + ')';
}
}
image.src = "resources/sprite-sheet-red-green-blue.png";
})();
</script>
</body>
</html>