Add a basic caching mechanism for ImageKeys. (#37369)

This creates a new method in shared/compositing/lib to generate image
keys that are send over the webview. This does not immediately return
the keys but goes over the constellation to receive the keys from the
IOCompositor. To make this more efficient, we now cache the keys in
image_cache in a simple FIFO order. The old blocking method stays intact
for now but got renamed to make the blocking clear.
The blocking calls that are left are in:
- `components/canvas/canvas_data.rs`
- `components/script/dom/htmlmediaelement.rs`

Testing: WPT tests should cover this as this doesn't change any
functionality.
Fixes: Was mentioned in
https://github.com/servo/servo/issues/37161#issuecomment-2915750051 and
part of https://github.com/servo/servo/issues/37086

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
Co-authored-by: gterzian <2792687+gterzian@users.noreply.github.com>
This commit is contained in:
Narfinger 2025-07-03 22:16:43 +09:00 committed by GitHub
parent 89bfa26f00
commit ca47cc2fa3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 392 additions and 70 deletions

View file

@ -10756,6 +10756,50 @@
"9235007d960cc6c804a93c89f24881bedc3613c3",
[]
],
"test1.jpg": [
"124d70729ea649ee253254ec0f1e2ea0f926ed31",
[]
],
"test10.jpg": [
"1ff396cd08dbf8a6039f39e79af860c44859da48",
[]
],
"test11.jpg": [
"8074fffaa33a371825c7a54c9536fc22f4d8bca4",
[]
],
"test2.jpg": [
"e35589b82207d655379acbcac3932ccbef846dee",
[]
],
"test3.jpg": [
"1f135409c45ea58b4cb7b89bdf4f71b8b43d0b88",
[]
],
"test4.jpg": [
"793ded09d3e65db01ea2c55c6f9f2bbe10366b94",
[]
],
"test5.jpg": [
"3df583072e57fd6195104e8fb16be7a91b751a70",
[]
],
"test6.jpg": [
"81c68f412a27fcdcb1d961db568168b0e9ea2caf",
[]
],
"test7.jpg": [
"b6169d4a7b804b184e4677eb9eda54c67f0d2e75",
[]
],
"test8.jpg": [
"295e9c523527c584eac494298060d2631d69603d",
[]
],
"test9.jpg": [
"c82f94f0134105792bb45a3a827c2a51cc92e674",
[]
],
"text-overflow-ellipsis-stacking-context-ref.html": [
"14215e780ab4a0cf00ef23b8472636a393aeacf1",
[]
@ -13525,6 +13569,13 @@
{}
]
],
"img_load_more_than_cache.html": [
"41f1212f8df42c9082d462d861a1ae5545ea5523",
[
null,
{}
]
],
"img_multiple_request.html": [
"df625a2bc338c0220808cf7a153128fe9b9d48a8",
[

View file

@ -0,0 +1,48 @@
<!doctype html>
<meta charset="utf-8">
<title>Test Loading more images than keys obtained in a batch by the image cache</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<img src="test1.jpg" id="img1">
<img src="test2.jpg" id="img2">
<img src="test3.jpg" id="img3">
<img src="test4.jpg" id="img4">
<img src="test5.jpg" id="img5">
<img src="test6.jpg" id="img6">
<img src="test7.jpg" id="img7">
<img src="test8.jpg" id="img8">
<img src="test9.jpg" id="img9">
<img src="test10.jpg" id="img10">
<img src="test11.jpg" id="img11">
<script>
promise_test(function() {
let image_tags = [];
image_tags.push(document.getElementById('img1'));
image_tags.push(document.getElementById('img2'));
image_tags.push(document.getElementById('img3'));
image_tags.push(document.getElementById('img4'));
image_tags.push(document.getElementById('img5'));
image_tags.push(document.getElementById('img6'));
image_tags.push(document.getElementById('img7'));
image_tags.push(document.getElementById('img8'));
image_tags.push(document.getElementById('img9'));
image_tags.push(document.getElementById('img10'));
image_tags.push(document.getElementById('img11'));
return Promise.all(image_tags.map((elem) => {
if (elem.complete === true) {
return Promise.resolve(true)
} else {
return new Promise(resolve => {
elem.onload = () => resolve(true);
elem.onerror = () => resolve(false);
})
}
})).then(function(values) {
assert_equals(values.every((elem, index, array) => elem), true)
});
})
</script>
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB