Bug 1183363 - Make EnsureWritablePath and EnsureUserSpacePath always imply EnsureTarget. r=Bas, a=ritu
authorLee Salzman <lsalzman@mozilla.com>
Tue, 14 Jul 2015 00:01:29 -0400
changeset 270353 32b78aec27e87406a5a7acf04ca01a120ad0ad42
parent 270352 85cd0bf009c62f0ebbbd559182ecc810c4be079a
child 270354 4938bcc2fb6b019081f2d96e4705cdc825ce39b2
push id8228
push userryanvm@gmail.com
push dateMon, 20 Jul 2015 17:57:15 +0000
treeherdermozilla-aurora@b4a6171753f2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas, ritu
bugs1183363
milestone41.0a2
Bug 1183363 - Make EnsureWritablePath and EnsureUserSpacePath always imply EnsureTarget. r=Bas, a=ritu
dom/canvas/CanvasRenderingContext2D.cpp
--- a/dom/canvas/CanvasRenderingContext2D.cpp
+++ b/dom/canvas/CanvasRenderingContext2D.cpp
@@ -2574,17 +2574,16 @@ CanvasRenderingContext2D::BeginPath()
   mPathBuilder = nullptr;
   mDSPathBuilder = nullptr;
   mPathTransformWillUpdate = false;
 }
 
 void
 CanvasRenderingContext2D::Fill(const CanvasWindingRule& winding)
 {
-  EnsureTarget();
   EnsureUserSpacePath(winding);
 
   if (!mPath) {
     return;
   }
 
   mgfx::Rect bounds;
 
@@ -2620,17 +2619,16 @@ void CanvasRenderingContext2D::Fill(cons
          DrawOptions(CurrentState().globalAlpha, UsedOperation()));
 
   Redraw();
 }
 
 void
 CanvasRenderingContext2D::Stroke()
 {
-  EnsureTarget();
   EnsureUserSpacePath();
 
   if (!mPath) {
     return;
   }
 
   const ContextState &state = CurrentState();
 
@@ -2756,18 +2754,16 @@ bool CanvasRenderingContext2D::DrawCusto
   }
 
   return false;
 }
 
 void
 CanvasRenderingContext2D::Clip(const CanvasWindingRule& winding)
 {
-  EnsureTarget();
-
   EnsureUserSpacePath(winding);
 
   if (!mPath) {
     return;
   }
 
   mTarget->PushClip(mPath);
   CurrentState().clipsPushed.push_back(mPath);
@@ -2899,16 +2895,18 @@ CanvasRenderingContext2D::Rect(double x,
     mDSPathBuilder->LineTo(mTarget->GetTransform() * Point(x, y + h));
     mDSPathBuilder->Close();
   }
 }
 
 void
 CanvasRenderingContext2D::EnsureWritablePath()
 {
+  EnsureTarget();
+
   if (mDSPathBuilder) {
     return;
   }
 
   FillRule fillRule = CurrentState().fillRule;
 
   if (mPathBuilder) {
     if (mPathTransformWillUpdate) {
@@ -2917,17 +2915,16 @@ CanvasRenderingContext2D::EnsureWritable
         mPath->TransformedCopyToBuilder(mPathToDS, fillRule);
       mPath = nullptr;
       mPathBuilder = nullptr;
       mPathTransformWillUpdate = false;
     }
     return;
   }
 
-  EnsureTarget();
   if (!mPath) {
     NS_ASSERTION(!mPathTransformWillUpdate, "mPathTransformWillUpdate should be false, if all paths are null");
     mPathBuilder = mTarget->CreatePathBuilder(fillRule);
   } else if (!mPathTransformWillUpdate) {
     mPathBuilder = mPath->CopyToBuilder(fillRule);
   } else {
     mDSPathBuilder =
       mPath->TransformedCopyToBuilder(mPathToDS, fillRule);
@@ -2938,18 +2935,19 @@ CanvasRenderingContext2D::EnsureWritable
 
 void
 CanvasRenderingContext2D::EnsureUserSpacePath(const CanvasWindingRule& winding)
 {
   FillRule fillRule = CurrentState().fillRule;
   if(winding == CanvasWindingRule::Evenodd)
     fillRule = FillRule::FILL_EVEN_ODD;
 
+  EnsureTarget();
+
   if (!mPath && !mPathBuilder && !mDSPathBuilder) {
-    EnsureTarget();
     mPathBuilder = mTarget->CreatePathBuilder(fillRule);
   }
 
   if (mPathBuilder) {
     mPath = mPathBuilder->Finish();
     mPathBuilder = nullptr;
   }
 
@@ -3206,16 +3204,17 @@ CanvasRenderingContext2D::MeasureText(co
   return new TextMetrics(width);
 }
 
 void
 CanvasRenderingContext2D::AddHitRegion(const HitRegionOptions& options, ErrorResult& error)
 {
   RefPtr<gfx::Path> path;
   if (options.mPath) {
+    EnsureTarget();
     path = options.mPath->GetPath(CanvasWindingRule::Nonzero, mTarget);
   }
 
   if (!path) {
     // check if the path is valid
     EnsureUserSpacePath(CanvasWindingRule::Nonzero);
     path = mPath;
   }