Bug 927413 - Gracefully handle 0 sized DrawWindow rects. r=roc, a=bajaj
authorMatt Woodrow <mwoodrow@mozilla.com>
Mon, 04 Nov 2013 14:47:17 +1300
changeset 166439 b93ea15eb3565e846ef34c99ebfc3d164c789809
parent 166438 571b5e7bf31ff16b41be84ce5116c99a249ca32d
child 166440 eef59d3645d39e1b53cfafb5fb09024aaed36458
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)
reviewersroc, bajaj
bugs927413
milestone27.0a2
Bug 927413 - Gracefully handle 0 sized DrawWindow rects. r=roc, a=bajaj
content/canvas/src/CanvasRenderingContext2D.cpp
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -3296,16 +3296,19 @@ CanvasRenderingContext2D::DrawWindow(nsG
     renderDocFlags |= nsIPresShell::RENDER_DRAWWINDOW_NOT_FLUSHING;
   }
 
   // gfxContext-over-Azure may modify the DrawTarget's transform, so
   // save and restore it
   Matrix matrix = mTarget->GetTransform();
   double sw = matrix._11 * w;
   double sh = matrix._22 * h;
+  if (!sw || !sh) {
+    return;
+  }
   nsRefPtr<gfxContext> thebes;
   nsRefPtr<gfxASurface> drawSurf;
   RefPtr<DrawTarget> drawDT;
   if (gfxPlatform::GetPlatform()->SupportsAzureContentForDrawTarget(mTarget)) {
     thebes = new gfxContext(mTarget);
     thebes->SetMatrix(gfxMatrix(matrix._11, matrix._12, matrix._21,
                                 matrix._22, matrix._31, matrix._32));
   } else if (gfxPlatform::GetPlatform()->SupportsAzureContent()) {
@@ -3358,16 +3361,21 @@ CanvasRenderingContext2D::DrawWindow(nsG
 
       source =
         mTarget->CreateSourceSurfaceFromData(data->GetData(),
                                              data->GetSize(),
                                              data->Stride(),
                                              data->GetFormat());
     }
 
+    if (!source) {
+      error.Throw(NS_ERROR_FAILURE);
+      return;
+    }
+
     mgfx::Rect destRect(0, 0, w, h);
     mgfx::Rect sourceRect(0, 0, sw, sh);
     mTarget->DrawSurface(source, destRect, sourceRect,
                          DrawSurfaceOptions(mgfx::FILTER_POINT),
                          DrawOptions(1.0f, OP_SOURCE, AA_NONE));
     mTarget->Flush();
   } else {
     mTarget->SetTransform(matrix);