Skip to content

Commit

Permalink
Clear webrender image id when resizing a canvas.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Jeffrey committed Jun 13, 2017
1 parent 07f6e11 commit 4e04daa
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 1 deletion.
4 changes: 4 additions & 0 deletions components/canvas/canvas_paint_thread.rs
Expand Up @@ -547,6 +547,10 @@ impl<'a> CanvasPaintThread<'a> {

fn recreate(&mut self, size: Size2D<i32>) {
self.drawtarget = CanvasPaintThread::create(size);
// Webrender doesn't let images change size, so we clear the webrender image key.
if let Some(image_key) = self.image_key.take() {
self.webrender_api.delete_image(image_key);
}
}

fn send_pixels(&mut self, chan: IpcSender<Option<Vec<u8>>>) {
Expand Down
6 changes: 5 additions & 1 deletion components/canvas/webgl_paint_thread.rs
Expand Up @@ -291,14 +291,18 @@ impl WebGLPaintThread {
#[allow(unsafe_code)]
fn recreate(&mut self, size: Size2D<i32>) -> Result<(), &'static str> {
match self.data {
WebGLPaintTaskData::Readback(ref mut context, _, _) => {
WebGLPaintTaskData::Readback(ref mut context, ref webrender_api, ref mut image_key) => {
if size.width > self.size.width ||
size.height > self.size.height {
self.size = try!(context.resize(size));
} else {
self.size = size;
context.gl().scissor(0, 0, size.width, size.height);
}
// Webrender doesn't let images change size, so we clear the webrender image key.
if let Some(image_key) = image_key.take() {
webrender_api.delete_image(image_key);
}
}
WebGLPaintTaskData::WebRender(ref api, id) => {
let device_size = webrender_traits::DeviceIntSize::from_untyped(&size);
Expand Down
25 changes: 25 additions & 0 deletions tests/wpt/mozilla/meta/MANIFEST.json
Expand Up @@ -6449,6 +6449,18 @@
{}
]
],
"mozilla/canvas/set_dimensions.html": [
[
"/_mozilla/mozilla/canvas/set_dimensions.html",
[
[
"/_mozilla/mozilla/canvas/set_dimensions_ref.html",
"=="
]
],
{}
]
],
"mozilla/details_ui_closed.html": [
[
"/_mozilla/mozilla/details_ui_closed.html",
Expand Down Expand Up @@ -9570,6 +9582,11 @@
{}
]
],
"mozilla/canvas/set_dimensions_ref.html": [
[
{}
]
],
"mozilla/click_prevent.html": [
[
{}
Expand Down Expand Up @@ -25493,6 +25510,14 @@
"794dd75566d0e2086deb0dcfc727dfe1834ca17e",
"testharness"
],
"mozilla/canvas/set_dimensions.html": [
"db6e4fa9b3480609a9a3a582430c64fb49b2b047",
"reftest"
],
"mozilla/canvas/set_dimensions_ref.html": [
"dd9ab8e1a360063d40e5155c1228e69154fa0966",
"support"
],
"mozilla/caption.html": [
"51ed2927d2f3910fb9c2dc4bb1ea4d41c261c8c1",
"testharness"
Expand Down
25 changes: 25 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/canvas/set_dimensions.html
@@ -0,0 +1,25 @@
<!doctype html>
<html class="reftest-wait">
<head>
<meta charset=utf-8>
<title>Resizing a canvas</title>
<link rel=match href=/_mozilla/mozilla/canvas/set_dimensions_ref.html>
</head>

<body>
<canvas width="50px" height="50px"></canvas>
<script>
var canvas = document.getElementsByTagName('canvas')[0];
var ctx = canvas.getContext('2d');
ctx.fillStyle = "red";
ctx.fillRect(0, 0, canvas.width, canvas.height);
setTimeout(function() {
canvas.width = 100;
canvas.height = 100;
ctx.fillStyle = "green";
ctx.fillRect(0, 0, canvas.width, canvas.height);
document.documentElement.classList.remove("reftest-wait");
}, 0);
</script>
</body>
</html>
17 changes: 17 additions & 0 deletions tests/wpt/mozilla/tests/mozilla/canvas/set_dimensions_ref.html
@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset=utf-8>
<title>Resizing a canvas reference</title>
</head>

<body>
<canvas width="100px" height="100px"></canvas>
<script>
var canvas = document.getElementsByTagName('canvas')[0];
var ctx = canvas.getContext('2d');
ctx.fillStyle = "green";
ctx.fillRect(0, 0, canvas.width, canvas.height);
</script>
</body>
</html>

0 comments on commit 4e04daa

Please sign in to comment.