Bug 1355168 - Ensure mTarget in CanvasRendering2D::DrawWindow; r?mats draft
authorKevin Chen <kechen@mozilla.com>
Mon, 17 Apr 2017 10:40:53 +0800
changeset 563924 f167d51ea4af4907f028fc821306498deb751d68
parent 563410 c697e756f738ce37abc56f31bfbc48f55625d617
child 624625 bda7107a1e0d0b8f309140f5325890afaa0323df
push id54472
push userbmo:kechen@mozilla.com
push dateTue, 18 Apr 2017 04:01:35 +0000
reviewersmats
bugs1355168
milestone55.0a1
Bug 1355168 - Ensure mTarget in CanvasRendering2D::DrawWindow; r?mats MozReview-Commit-ID: 3xmzJc5Mq7J
dom/canvas/CanvasRenderingContext2D.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -5575,25 +5575,28 @@ CanvasRenderingContext2D::DrawWindow(nsG
 
   // protect against too-large surfaces that will cause allocation
   // or overflow issues
   if (!Factory::CheckSurfaceSize(IntSize(int32_t(aW), int32_t(aH)), 0xffff)) {
     aError.Throw(NS_ERROR_FAILURE);
     return;
   }
 
+  // Flush layout updates
+  if (!(aFlags & nsIDOMCanvasRenderingContext2D::DRAWWINDOW_DO_NOT_FLUSH)) {
+    nsContentUtils::FlushLayoutForTree(aWindow.AsInner()->GetOuterWindow());
+  }
+
   CompositionOp op = UsedOperation();
   bool discardContent = GlobalAlpha() == 1.0f
     && (op == CompositionOp::OP_OVER || op == CompositionOp::OP_SOURCE);
   const gfx::Rect drawRect(aX, aY, aW, aH);
   EnsureTarget(discardContent ? &drawRect : nullptr);
-
-  // Flush layout updates
-  if (!(aFlags & nsIDOMCanvasRenderingContext2D::DRAWWINDOW_DO_NOT_FLUSH)) {
-    nsContentUtils::FlushLayoutForTree(aWindow.AsInner()->GetOuterWindow());
+  if (!IsTargetValid()) {
+    return;
   }
 
   RefPtr<nsPresContext> presContext;
   nsIDocShell* docshell = aWindow.GetDocShell();
   if (docshell) {
     docshell->GetPresContext(getter_AddRefs(presContext));
   }
   if (!presContext) {