Bug 924573 - Deal with canvas 0 width and height more consistently. r=bas
authorMilan Sreckovic <milan@mozilla.com>
Wed, 09 Oct 2013 17:22:11 -0400
changeset 164883 877210776b71a3cd9c2eb1726fc12f8ce9f8f533
parent 164882 bdcfcd904df05594733829643b9acd4d6040346d
child 164884 05153aa834272ed9ebfef0f2ffbe5aeb9bf2f0b7
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs924573
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 924573 - Deal with canvas 0 width and height more consistently. r=bas
content/canvas/src/CanvasRenderingContext2D.cpp
content/canvas/src/WebGLContext.cpp
content/html/content/src/HTMLCanvasElement.cpp
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -923,26 +923,28 @@ CanvasRenderingContext2D::GetHeight() co
 }
 #endif
 
 NS_IMETHODIMP
 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;
 }
 
 void
 CanvasRenderingContext2D::ClearTarget()
 {
   Reset();
--- a/content/canvas/src/WebGLContext.cpp
+++ b/content/canvas/src/WebGLContext.cpp
@@ -376,18 +376,20 @@ WebGLContext::SetDimensions(int32_t widt
     // Early success return cases
 
     GetCanvas()->InvalidateCanvas();
 
     if (gl && mWidth == width && mHeight == 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;
     }
 
     // If we already have a gl context, then we just need to resize it
     if (gl) {
         MakeContextCurrent();
 
         gl->ResizeOffscreen(gfxIntSize(width, height)); // Doesn't matter if it succeeds (soft-fail)
--- a/content/html/content/src/HTMLCanvasElement.cpp
+++ b/content/html/content/src/HTMLCanvasElement.cpp
@@ -592,19 +592,24 @@ HTMLCanvasElement::ToBlob(JSContext* aCx
   bool usingCustomParseOptions;
   aRv = ParseParams(aCx, type, encoderOptions, params, &usingCustomParseOptions);
   if (aRv.Failed()) {
     return;
   }
 
 #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
 
   bool fallbackToPNG = false;
 
   nsCOMPtr<nsIInputStream> stream;
   aRv = ExtractData(type, params, getter_AddRefs(stream), fallbackToPNG);
   // If there are unrecognized custom parse options, we should fall back to