Bug 924573 - Deal with canvas 0 width and height more consistently. r=bas

This commit is contained in:
Milan Sreckovic 2013-10-09 17:22:11 -04:00
parent 84e762a2dc
commit 9635910d8f
3 changed files with 20 additions and 11 deletions

View File

@ -928,16 +928,18 @@ CanvasRenderingContext2D::SetDimensions(int32_t width, int32_t height)
{
ClearTarget();
// Zero sized surfaces cause issues, so just go with 1x1.
if (height == 0 || width == 0) {
// Zero sized surfaces can cause problems.
mZero = false;
if (height == 0) {
height = 1;
mZero = true;
mWidth = 1;
mHeight = 1;
} else {
mZero = false;
mWidth = width;
mHeight = height;
}
if (width == 0) {
width = 1;
mZero = true;
}
mWidth = width;
mHeight = height;
return NS_OK;
}

View File

@ -381,8 +381,10 @@ WebGLContext::SetDimensions(int32_t width, int32_t height)
return NS_OK;
// Zero-sized surfaces can cause problems.
if (width == 0 || height == 0) {
if (width == 0) {
width = 1;
}
if (height == 0) {
height = 1;
}

View File

@ -597,9 +597,14 @@ HTMLCanvasElement::ToBlob(JSContext* aCx,
#ifdef DEBUG
if (mCurrentContext) {
// We disallow canvases of width or height zero, and set them to 1, so
// we will have a discrepancy with the sizes of the canvas and the context.
// That discrepancy is OK, the rest are not.
nsIntSize elementSize = GetWidthHeight();
MOZ_ASSERT(elementSize.width == mCurrentContext->GetWidth());
MOZ_ASSERT(elementSize.height == mCurrentContext->GetHeight());
MOZ_ASSERT(elementSize.width == mCurrentContext->GetWidth() ||
(elementSize.width == 0 && mCurrentContext->GetWidth() == 1));
MOZ_ASSERT(elementSize.height == mCurrentContext->GetHeight() ||
(elementSize.height == 0 && mCurrentContext->GetHeight() == 1));
}
#endif