Skip to content

Commit

Permalink
Ensure that removed contexts are made active before removal.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed Mar 8, 2019
1 parent 0e30666 commit 056edbb
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components/canvas/webgl_thread.rs
Expand Up @@ -382,6 +382,10 @@ impl<VR: WebVRRenderHandler + 'static> WebGLThread<VR> {
self.webrender_api.update_resources(txn.resource_updates)
}

// We need to make the context current so its resources can be disposed of.
let _ =
Self::make_current_if_needed(context_id, &self.contexts, &mut self.bound_context_id);

// Release GL context.
self.contexts.remove(&context_id);

Expand Down
22 changes: 22 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -10604,6 +10604,16 @@
{}
]
],
"mozilla/webgl/clearcolor_blue.html": [
[
{}
]
],
"mozilla/webgl/clearcolor_green.html": [
[
{}
]
],
"mozilla/webgl/clearcolor_ref.html": [
[
{}
Expand Down Expand Up @@ -20092,6 +20102,14 @@
"4760f382f0374985a334a5f6d0e0fe055670c61d",
"reftest"
],
"mozilla/webgl/clearcolor_blue.html": [
"d534babb2a664b7cb861f1cc253020e319f281e9",
"support"
],
"mozilla/webgl/clearcolor_green.html": [
"db11b31ab9839777d9d74cf7f2c46de00349c76e",
"support"
],
"mozilla/webgl/clearcolor_ref.html": [
"49cce2cc9009057742cb17e3fd452a986bd6c177",
"support"
Expand All @@ -20116,6 +20134,10 @@
"691535db4766536d66769408212cb13f3f64bef6",
"testharness"
],
"mozilla/webgl/history.html": [
"d470c229fbcca5a47d3370e8e58bae34882be491",
"testharness"
],
"mozilla/webgl/img/rust-logo-256x256.png": [
"63506dd85efce44f8433942a6f4e54d718a97046",
"support"
Expand Down
33 changes: 33 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/webgl/clearcolor_blue.html
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>WebGL ClearColor Test</title>
</head>
<style>

html, body {
margin: 0;
}

</style>
<body>
<canvas id="canvas" width="640" height="480"></canvas>
<!-- Dummy canvas that is only used to create a GL context that will be garbage collected -->
<canvas id="canvas2" width="640" height="480"></canvas>
<script type="text/javascript">

var gl = document.getElementById("canvas").getContext("webgl");
var gl2 = document.getElementById("canvas2").getContext("webgl");
gl2 = null;
document.getElementById('canvas2').remove();

function draw() {
gl.clearColor(0.0, 0.0, 1.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
}

draw();
</script>
</body>
</html>
33 changes: 33 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/webgl/clearcolor_green.html
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>WebGL ClearColor Test</title>
</head>
<style>

html, body {
margin: 0;
}

</style>
<body>
<canvas id="canvas" width="640" height="480"></canvas>
<!-- Dummy canvas that is only used to create a GL context that will be garbage collected -->
<canvas id="canvas2" width="640" height="480"></canvas>
<script type="text/javascript">

var gl = document.getElementById("canvas").getContext("webgl");
var gl2 = document.getElementById("canvas2").getContext("webgl");
gl2 = null;
document.getElementById('canvas2').remove();

function draw() {
gl.clearColor(0.0, 1.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
}

draw();
</script>
</body>
</html>
42 changes: 42 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/webgl/history.html
@@ -0,0 +1,42 @@
<!doctype html>
<meta charset="utf-8">
<title>Traversing history with webgl content does not panic</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<iframe></iframe>
<script>
/*
Load two pages that each create two GL contexts and draw in one of them.
Traverse history and attempt to draw again; this has historically caused crashes.
*/
var first = "clearcolor_green.html";
var second = "clearcolor_blue.html";

var iframe = document.querySelector('iframe');
iframe.src = first;

var t = async_test();
onload = t.step_func(function() {
iframe.src = second;

iframe.onload = t.step_func(function() {
assert_true(iframe.contentWindow.location.href.endsWith(second));
iframe.contentWindow.history.back();

t.step_timeout(function() {
assert_true(iframe.contentWindow.location.href.endsWith(first));
// Try to use the previously-used GL context.
iframe.contentWindow.draw();
iframe.contentWindow.history.forward();

t.step_timeout(function() {
assert_true(iframe.contentWindow.location.href.endsWith(second));
// Try to use the previously-used GL context.
iframe.contentWindow.draw();
t.done();
}, 1000);

}, 1000);
});
});
</script>

0 comments on commit 056edbb

Please sign in to comment.