Bug 715401. Instead of trying to create a fallback surface, just leave mTarget alone. r=bas,a=akeybl
authorRobert O'Callahan <robert@ocallahan.org>
Tue, 21 Feb 2012 12:55:41 +1300
changeset 87217 1daa4441b7aaa8234e4b574141e13b95e4867208
parent 87216 77b10632390c2be7a75c6da29fe99c3f9b42dc06
child 87218 c98c403449370a31b17e179a9f3fe3d5ce0f7393
push id877
push userrocallahan@mozilla.com
push dateMon, 20 Feb 2012 23:57:28 +0000
treeherdermozilla-aurora@1daa4441b7aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas, akeybl
bugs715401
milestone12.0a2
Bug 715401. Instead of trying to create a fallback surface, just leave mTarget alone. r=bas,a=akeybl
content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
--- a/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
+++ b/content/canvas/src/nsCanvasRenderingContext2DAzure.cpp
@@ -1286,54 +1286,53 @@ nsCanvasRenderingContext2DAzure::Initial
   Reset();
 
   NS_ASSERTION(mCanvasElement, "Must have a canvas element!");
   mDocShell = nsnull;
 
   mWidth = width;
   mHeight = height;
 
-  mTarget = target;
+  // This first time this is called on this object is via
+  // nsHTMLCanvasElement::GetContext. If target was non-null then mTarget is
+  // non-null, otherwise we'll return an error here and GetContext won't
+  // return this context object and we'll never enter this code again.
+  // All other times this method is called, if target is null then
+  // mTarget won't be changed, i.e. it will remain non-null, or else it
+  // will be set to non-null.
+  // In all cases, any usable canvas context will have non-null mTarget.
+
+  if (target) {
+    mValid = true;
+    mTarget = target;
+  } else {
+    mValid = false;
+  }
 
   mResetLayer = true;
 
-  /* Create dummy surfaces here - target can be null when a canvas was created
-   * that is too large to support.
-   */
-  if (!target)
-  {
-    mTarget = gfxPlatform::GetPlatform()->CreateOffscreenDrawTarget(IntSize(1, 1), FORMAT_B8G8R8A8);
-    if (!mTarget) {
-      // SupportsAzure() is controlled by the "gfx.canvas.azure.prefer-skia"
-      // pref so that may be the reason rather than an OOM.
-      mValid = false;
-      return NS_ERROR_OUT_OF_MEMORY;
-    }
-  } else {
-    mValid = true;
-  }
-
   // set up the initial canvas defaults
   mStyleStack.Clear();
   mPathBuilder = nsnull;
   mPath = nsnull;
   mDSPathBuilder = nsnull;
 
   ContextState *state = mStyleStack.AppendElement();
   state->globalAlpha = 1.0;
 
   state->colorStyles[STYLE_FILL] = NS_RGB(0,0,0);
   state->colorStyles[STYLE_STROKE] = NS_RGB(0,0,0);
   state->shadowColor = NS_RGBA(0,0,0,0);
 
-  mTarget->ClearRect(mgfx::Rect(Point(0, 0), Size(mWidth, mHeight)));
-    
-  // always force a redraw, because if the surface dimensions were reset
-  // then the surface became cleared, and we need to redraw everything.
-  Redraw();
+  if (mTarget) {
+    mTarget->ClearRect(mgfx::Rect(Point(0, 0), Size(mWidth, mHeight)));
+    // always force a redraw, because if the surface dimensions were reset
+    // then the surface became cleared, and we need to redraw everything.
+    Redraw();
+  }
 
   return mValid ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
 NS_IMETHODIMP
 nsCanvasRenderingContext2DAzure::SetIsOpaque(bool isOpaque)
 {
   if (isOpaque == mOpaque)