Bug 1285207 - Don't let canvas have a DrawTarget without a BufferProvider and keep them in sync. r=lsalzman
authorNicolas Silva <nsilva@mozilla.com>
Fri, 08 Jul 2016 19:26:44 +0200
changeset 304291 b7f2d54f39046516662b17faa0c8605d98eb3385
parent 304290 fceb3f145f918129ee966a0013960437acf48dde
child 304292 75f6c7e15d7641a294a00ec454e34866807a0f83
push id19932
push userphilringnalda@gmail.com
push dateSat, 09 Jul 2016 16:00:45 +0000
treeherderfx-team@679118259e91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslsalzman
bugs1285207
milestone50.0a1
Bug 1285207 - Don't let canvas have a DrawTarget without a BufferProvider and keep them in sync. r=lsalzman
dom/canvas/CanvasRenderingContext2D.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -1616,16 +1616,17 @@ CanvasRenderingContext2D::EnsureTarget(c
             gfxCriticalNote << "Failed to create a SkiaGL DrawTarget, falling back to software\n";
             mode = RenderingMode::SoftwareBackendMode;
           }
         }
 #endif
       }
 
       if (!mBufferProvider) {
+        mTarget = nullptr;
         mBufferProvider = layerManager->CreatePersistentBufferProvider(size, format);
       }
     }
 
     if (mBufferProvider) {
       mTarget = mBufferProvider->BorrowDrawTarget(IntRect(IntPoint(), IntSize(mWidth, mHeight)));
     } else if (!mTarget) {
       mTarget = gfxPlatform::GetPlatform()->CreateOffscreenCanvasDrawTarget(size, format);
@@ -1662,16 +1663,17 @@ CanvasRenderingContext2D::EnsureTarget(c
       mCanvasElement->InvalidateCanvas();
     }
     // Calling Redraw() tells our invalidation machinery that the entire
     // canvas is already invalid, which can speed up future drawing.
     Redraw();
   } else {
     EnsureErrorTarget();
     mTarget = sErrorTarget;
+    mBufferProvider = nullptr;
   }
 
   // Drop a note in the debug builds if we ever use accelerated Skia canvas.
   if (mIsSkiaGL && mTarget && mTarget->GetType() == DrawTargetType::HARDWARE_RASTER) {
     gfxWarningOnce() << "Using SkiaGL canvas.";
   }
   return mode;
 }
@@ -1768,19 +1770,21 @@ CanvasRenderingContext2D::InitializeWith
                                                    gfx::DrawTarget* aTarget)
 {
   RemovePostRefreshObserver();
   mDocShell = aShell;
   AddPostRefreshObserverIfNecessary();
 
   IntSize size = aTarget->GetSize();
   SetDimensions(size.width, size.height);
-  mTarget = aTarget;
-
-  if (!mTarget) {
+
+  if (aTarget) {
+    mTarget = aTarget;
+    mBufferProvider = new PersistentBufferProviderBasic(aTarget);
+  } else {
     EnsureErrorTarget();
     mTarget = sErrorTarget;
   }
 
   if (mTarget->GetBackendType() == gfx::BackendType::CAIRO) {
     // Cf comment in EnsureTarget
     mTarget->PushClipRect(gfx::Rect(Point(0, 0), Size(mWidth, mHeight)));
   }
@@ -5787,29 +5791,26 @@ CanvasRenderingContext2D::GetBufferProvi
   if (AlreadyShutDown()) {
     return nullptr;
   }
 
   if (mBufferProvider) {
     return mBufferProvider;
   }
 
-  if (!mTarget) {
-    return nullptr;
+  if (mTarget) {
+    mBufferProvider = new PersistentBufferProviderBasic(mTarget);
+    return mBufferProvider;
   }
 
   if (aManager) {
     mBufferProvider = aManager->CreatePersistentBufferProvider(gfx::IntSize(mWidth, mHeight),
                                                                GetSurfaceFormat());
   }
 
-  if (!mBufferProvider) {
-    mBufferProvider = new PersistentBufferProviderBasic(mTarget);
-  }
-
   return mBufferProvider;
 }
 
 already_AddRefed<Layer>
 CanvasRenderingContext2D::GetCanvasLayer(nsDisplayListBuilder* aBuilder,
                                          Layer *aOldLayer,
                                          LayerManager *aManager,
                                          bool aMirror /* = false */)