Bug 1524554 - Part 2: Ensure DrawTarget validity for DTs created inside Canvas. r=rhunt a=lizzard
authorBas Schouten <bschouten@mozilla.com>
Mon, 04 Mar 2019 10:49:46 +0100
changeset 516305 cc6fc6015015707bdacbeaf206679df6ff78b6d2
parent 516304 5892e926a68ca496e7b2539b2f0795239ca6d962
child 516306 067b9599e2aa2f1ec5fdfb76b14753435fd65f93
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrhunt, lizzard
bugs1524554
milestone66.0
Bug 1524554 - Part 2: Ensure DrawTarget validity for DTs created inside Canvas. r=rhunt a=lizzard Differential Revision: https://phabricator.services.mozilla.com/D21901
dom/canvas/CanvasRenderingContext2D.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -366,17 +366,22 @@ class AdjustedTargetForFilter {
       // create a DrawTarget that we can return from DT() anyway, so we'll
       // just use a 1x1-sized one.
       mSourceGraphicRect.SizeTo(1, 1);
     }
 
     mTarget = mFinalTarget->CreateSimilarDrawTarget(mSourceGraphicRect.Size(),
                                                     SurfaceFormat::B8G8R8A8);
 
-    if (!mTarget) {
+    if (mTarget) {
+      // See bug 1524554.
+      mTarget->ClearRect(gfx::Rect());
+    }
+
+    if (!mTarget || !mTarget->IsValid()) {
       // XXX - Deal with the situation where our temp size is too big to
       // fit in a texture (bug 1066622).
       mTarget = mFinalTarget;
       mCtx = nullptr;
       mFinalTarget = nullptr;
       return;
     }
 
@@ -388,17 +393,23 @@ class AdjustedTargetForFilter {
   already_AddRefed<SourceSurface> DoSourcePaint(
       gfx::IntRect& aRect, CanvasRenderingContext2D::Style aStyle) {
     if (aRect.IsEmpty()) {
       return nullptr;
     }
 
     RefPtr<DrawTarget> dt = mFinalTarget->CreateSimilarDrawTarget(
         aRect.Size(), SurfaceFormat::B8G8R8A8);
-    if (!dt) {
+
+    if (dt) {
+      // See bug 1524554.
+      dt->ClearRect(gfx::Rect());
+    }
+
+    if (!dt || !dt->IsValid()) {
       aRect.SetEmpty();
       return nullptr;
     }
 
     Matrix transform =
         mFinalTarget->GetTransform().PostTranslate(-aRect.TopLeft() + mOffset);
 
     dt->SetTransform(transform);
@@ -477,17 +488,22 @@ class AdjustedTargetForShadow {
     int32_t blurRadius = state.ShadowBlurRadius();
     bounds.Inflate(blurRadius);
     bounds.RoundOut();
     bounds.ToIntRect(&mTempRect);
 
     mTarget = mFinalTarget->CreateShadowDrawTarget(
         mTempRect.Size(), SurfaceFormat::B8G8R8A8, mSigma);
 
-    if (!mTarget) {
+    if (mTarget) {
+      // See bug 1524554.
+      mTarget->ClearRect(gfx::Rect());
+    }
+
+    if (!mTarget || !mTarget->IsValid()) {
       // XXX - Deal with the situation where our temp size is too big to
       // fit in a texture (bug 1066622).
       mTarget = mFinalTarget;
       mCtx = nullptr;
       mFinalTarget = nullptr;
     } else {
       mTarget->SetTransform(
           mFinalTarget->GetTransform().PostTranslate(-mTempRect.TopLeft()));
@@ -4468,17 +4484,22 @@ static already_AddRefed<SourceSurface> E
   if (!roundedOutSourceRect.ToIntRect(&roundedOutSourceRectInt)) {
     RefPtr<SourceSurface> surface(aSurface);
     return surface.forget();
   }
 
   RefPtr<DrawTarget> subrectDT = aTargetDT->CreateSimilarDrawTarget(
       roundedOutSourceRectInt.Size(), SurfaceFormat::B8G8R8A8);
 
-  if (!subrectDT) {
+  if (subrectDT) {
+    // See bug 1524554.
+    subrectDT->ClearRect(gfx::Rect());
+  }
+
+  if (!subrectDT || !subrectDT->IsValid()) {
     RefPtr<SourceSurface> surface(aSurface);
     return surface.forget();
   }
 
   *aSourceRect -= roundedOutSourceRect.TopLeft();
 
   subrectDT->CopySurface(aSurface, roundedOutSourceRectInt, IntPoint());
   return subrectDT->Snapshot();