Don't send empty canvases to WebRender

If any dimension of a canvas is 0, don't try to render it as it causes
problems inside webrender.
This commit is contained in:
Daniel Alley 2020-03-29 17:19:39 -04:00
parent e66ab111a6
commit 61fb84d6a0
5 changed files with 34 additions and 0 deletions

View file

@ -1875,6 +1875,12 @@ impl Fragment {
}
},
SpecificFragmentInfo::Canvas(ref canvas_fragment_info) => {
if canvas_fragment_info.dom_width == Au(0) ||
canvas_fragment_info.dom_height == Au(0)
{
return;
}
let image_key = match canvas_fragment_info.source {
CanvasFragmentSource::WebGL(image_key) => image_key,
CanvasFragmentSource::Image(ref ipc_renderer) => match *ipc_renderer {

View file

@ -87,6 +87,7 @@ impl Fragment {
.rect
.to_physical(i.style.writing_mode, containing_block)
.translate(containing_block.origin.to_vector());
let common = builder.common_properties(rect.clone().to_webrender());
builder.wr.push_image(
&common,

View file

@ -102,6 +102,7 @@ impl ReplacedContent {
let width = (intrinsic_size_in_dots.width as CSSFloat) / dppx;
let height = (intrinsic_size_in_dots.height as CSSFloat) / dppx;
return Some(Self {
kind,
intrinsic: IntrinsicSizes {
@ -201,6 +202,12 @@ impl ReplacedContent {
.into_iter()
.collect(),
ReplacedContentKind::Canvas(canvas_info) => {
if self.intrinsic.width == Some(Length::zero()) ||
self.intrinsic.height == Some(Length::zero())
{
return vec![];
}
let image_key = match canvas_info.source {
CanvasSource::WebGL(image_key) => image_key,
CanvasSource::Image(ref ipc_renderer) => match *ipc_renderer {

View file

@ -14591,6 +14591,13 @@
null,
{}
]
],
"zero_size_canvas_crash.html": [
"45eb9b559e8d6105baca5ab4d336de520d33b36b",
[
null,
{}
]
]
},
"webxr": {

View file

@ -0,0 +1,13 @@
<!doctype html>
<meta charset="utf-8">
<title>Test for #21411: Panic when putting a zero-sized canvas on the display list.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<canvas id="myCanvas" width="0" height="0" style="width:10px; height:10px;"></canvas>
<script>
test(function () {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
}, "Doesn't crash when the page has a canvas with a zero-dimension");
</script>