Bug 767933 part 5. Remove no longer needed FloatValidate calls from canvas code. r=bas
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 27 Nov 2012 15:32:05 -0500
changeset 114274 d0a5bc47e590dafaa9884755e4ccd5e801576d39
parent 114273 4ce2a3b3b08e1baf232fd77b30cb037433ec0647
child 114275 b5b4caaea44f44d45e9dd1de59f721a230e72012
push id23913
push useremorley@mozilla.com
push dateWed, 28 Nov 2012 17:11:31 +0000
treeherdermozilla-central@17c267a881cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs767933
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 767933 part 5. Remove no longer needed FloatValidate calls from canvas code. r=bas
content/canvas/src/CanvasRenderingContext2D.cpp
content/canvas/src/CanvasRenderingContext2D.h
--- a/content/canvas/src/CanvasRenderingContext2D.cpp
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp
@@ -1053,94 +1053,73 @@ CanvasRenderingContext2D::Restore()
 
 //
 // transformations
 //
 
 void
 CanvasRenderingContext2D::Scale(double x, double y, ErrorResult& error)
 {
-  if (!FloatValidate(x,y)) {
-    return;
-  }
-
   TransformWillUpdate();
   if (!IsTargetValid()) {
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix newMatrix = mTarget->GetTransform();
   mTarget->SetTransform(newMatrix.Scale(x, y));
 }
 
 void
 CanvasRenderingContext2D::Rotate(double angle, ErrorResult& error)
 {
-  if (!FloatValidate(angle)) {
-    return;
-  }
-
   TransformWillUpdate();
   if (!IsTargetValid()) {
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
-
   Matrix rotation = Matrix::Rotation(angle);
   mTarget->SetTransform(rotation * mTarget->GetTransform());
 }
 
 void
 CanvasRenderingContext2D::Translate(double x, double y, ErrorResult& error)
 {
-  if (!FloatValidate(x,y)) {
-    return;
-  }
-
   TransformWillUpdate();
   if (!IsTargetValid()) {
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix newMatrix = mTarget->GetTransform();
   mTarget->SetTransform(newMatrix.Translate(x, y));
 }
 
 void
 CanvasRenderingContext2D::Transform(double m11, double m12, double m21,
                                     double m22, double dx, double dy,
                                     ErrorResult& error)
 {
-  if (!FloatValidate(m11,m12,m21,m22,dx,dy)) {
-    return;
-  }
-
   TransformWillUpdate();
   if (!IsTargetValid()) {
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix matrix(m11, m12, m21, m22, dx, dy);
   mTarget->SetTransform(matrix * mTarget->GetTransform());
 }
 
 void
 CanvasRenderingContext2D::SetTransform(double m11, double m12,
                                        double m21, double m22,
                                        double dx, double dy,
                                        ErrorResult& error)
 {
-  if (!FloatValidate(m11,m12,m21,m22,dx,dy)) {
-    return;
-  }
-
   TransformWillUpdate();
   if (!IsTargetValid()) {
     error.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   Matrix matrix(m11, m12, m21, m22, dx, dy);
   mTarget->SetTransform(matrix);
@@ -1375,37 +1354,27 @@ CanvasRenderingContext2D::GetFillRule(ns
 }
 //
 // gradients and patterns
 //
 already_AddRefed<nsIDOMCanvasGradient>
 CanvasRenderingContext2D::CreateLinearGradient(double x0, double y0, double x1, double y1,
                                                ErrorResult& aError)
 {
-  if (!FloatValidate(x0,y0,x1,y1)) {
-    aError.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
-    return nullptr;
-  }
-
   nsRefPtr<nsIDOMCanvasGradient> grad =
     new CanvasLinearGradient(Point(x0, y0), Point(x1, y1));
 
   return grad.forget();
 }
 
 already_AddRefed<nsIDOMCanvasGradient>
 CanvasRenderingContext2D::CreateRadialGradient(double x0, double y0, double r0,
                                                double x1, double y1, double r1,
                                                ErrorResult& aError)
 {
-  if (!FloatValidate(x0,y0,r0,x1,y1,r1)) {
-    aError.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
-    return nullptr;
-  }
-
   if (r0 < 0.0 || r1 < 0.0) {
     aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return nullptr;
   }
 
   nsRefPtr<nsIDOMCanvasGradient> grad =
     new CanvasRadialGradient(Point(x0, y0), r0, Point(x1, y1), r1);
 
@@ -1505,33 +1474,29 @@ CanvasRenderingContext2D::SetShadowColor
 //
 // rects
 //
 
 void
 CanvasRenderingContext2D::ClearRect(double x, double y, double w,
                                     double h)
 {
-  if (!FloatValidate(x,y,w,h) || !mTarget) {
+  if (!mTarget) {
     return;
   }
 
   mTarget->ClearRect(mgfx::Rect(x, y, w, h));
 
   RedrawUser(gfxRect(x, y, w, h));
 }
 
 void
 CanvasRenderingContext2D::FillRect(double x, double y, double w,
                                    double h)
 {
-  if (!FloatValidate(x,y,w,h)) {
-    return;
-  }
-
   const ContextState &state = CurrentState();
 
   if (state.patternStyles[STYLE_FILL]) {
     CanvasPattern::RepeatMode repeat =
       state.patternStyles[STYLE_FILL]->mRepeat;
     // In the FillRect case repeat modes are easy to deal with.
     bool limitx = repeat == CanvasPattern::NOREPEAT || repeat == CanvasPattern::REPEATY;
     bool limity = repeat == CanvasPattern::NOREPEAT || repeat == CanvasPattern::REPEATX;
@@ -1590,20 +1555,16 @@ CanvasRenderingContext2D::FillRect(doubl
 
   RedrawUser(gfxRect(x, y, w, h));
 }
 
 void
 CanvasRenderingContext2D::StrokeRect(double x, double y, double w,
                                      double h)
 {
-  if (!FloatValidate(x,y,w,h)) {
-    return;
-  }
-
   const ContextState &state = CurrentState();
 
   mgfx::Rect bounds;
 
   if (!w && !h) {
     return;
   }
 
@@ -1742,20 +1703,16 @@ CanvasRenderingContext2D::Clip()
   CurrentState().clipsPushed.push_back(mPath);
 }
 
 void
 CanvasRenderingContext2D::ArcTo(double x1, double y1, double x2,
                                 double y2, double radius,
                                 ErrorResult& error)
 {
-  if (!FloatValidate(x1, y1, x2, y2, radius)) {
-    return;
-  }
-
   if (radius < 0) {
     error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return;
   }
 
   EnsureWritablePath();
 
   // Current point in user space!
@@ -1824,37 +1781,29 @@ CanvasRenderingContext2D::ArcTo(double x
   Arc(cx, cy, radius, angle0, angle1, anticlockwise, error);
 }
 
 void
 CanvasRenderingContext2D::Arc(double x, double y, double r,
                               double startAngle, double endAngle,
                               bool anticlockwise, ErrorResult& error)
 {
-  if (!FloatValidate(x, y, r, startAngle, endAngle)) {
-    return;
-  }
-
   if (r < 0.0) {
     error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return;
   }
 
   EnsureWritablePath();
 
   ArcToBezier(this, Point(x, y), r, startAngle, endAngle, anticlockwise);
 }
 
 void
 CanvasRenderingContext2D::Rect(double x, double y, double w, double h)
 {
-  if (!FloatValidate(x, y, w, h)) {
-    return;
-  }
-
   EnsureWritablePath();
 
   if (mPathBuilder) {
     mPathBuilder->MoveTo(Point(x, y));
     mPathBuilder->LineTo(Point(x + w, y));
     mPathBuilder->LineTo(Point(x + w, y + h));
     mPathBuilder->LineTo(Point(x, y + h));
     mPathBuilder->Close();
@@ -2545,20 +2494,16 @@ CanvasRenderingContext2D::DrawOrMeasureT
                                             float aX,
                                             float aY,
                                             const Optional<double>& aMaxWidth,
                                             TextDrawOperation aOp,
                                             float* aWidth)
 {
   nsresult rv;
 
-  if (!FloatValidate(aX, aY) ||
-      (aMaxWidth.WasPassed() && !FloatValidate(aMaxWidth.Value())))
-      return NS_ERROR_DOM_SYNTAX_ERR;
-
   // spec isn't clear on what should happen if aMaxWidth <= 0, so
   // treat it as an invalid argument
   // technically, 0 should be an invalid value as well, but 0 is the default
   // arg, and there is no way to tell if the default was used
   if (aMaxWidth.WasPassed() && aMaxWidth.Value() < 0)
     return NS_ERROR_INVALID_ARG;
 
   if (!mCanvasElement && !mDocShell) {
@@ -2884,20 +2829,16 @@ CanvasRenderingContext2D::GetMozDash(JSC
   JS::Value mozDash;
   error = DashArrayToJSVal(CurrentState().dash, cx, &mozDash);
   return mozDash;
 }
 
 void
 CanvasRenderingContext2D::SetMozDashOffset(double mozDashOffset)
 {
-  if (!FloatValidate(mozDashOffset)) {
-    return;
-  }
-
   ContextState& state = CurrentState();
   if (!state.dash.IsEmpty()) {
     state.dashOffset = mozDashOffset;
   }
 }
 
 bool
 CanvasRenderingContext2D::IsPointInPath(double x, double y)
@@ -3590,40 +3531,30 @@ CanvasRenderingContext2D::FillRuleChange
     mPath = nullptr;
   }
 }
 
 void
 CanvasRenderingContext2D::PutImageData(ImageData& imageData, double dx,
                                        double dy, ErrorResult& error)
 {
-  if (!FloatValidate(dx, dy)) {
-    error.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
-    return;
-  }
-
   dom::Uint8ClampedArray arr(imageData.GetDataObject());
 
   error = PutImageData_explicit(JS_DoubleToInt32(dx), JS_DoubleToInt32(dy),
                                 imageData.Width(), imageData.Height(),
                                 arr.Data(), arr.Length(), false, 0, 0, 0, 0);
 }
 
 void
 CanvasRenderingContext2D::PutImageData(ImageData& imageData, double dx,
                                        double dy, double dirtyX,
                                        double dirtyY, double dirtyWidth,
                                        double dirtyHeight,
                                        ErrorResult& error)
 {
-  if (!FloatValidate(dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight)) {
-    error.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
-    return;
-  }
-
   dom::Uint8ClampedArray arr(imageData.GetDataObject());
 
   error = PutImageData_explicit(JS_DoubleToInt32(dx), JS_DoubleToInt32(dy),
                                 imageData.Width(), imageData.Height(),
                                 arr.Data(), arr.Length(), true,
                                 JS_DoubleToInt32(dirtyX),
                                 JS_DoubleToInt32(dirtyY),
                                 JS_DoubleToInt32(dirtyWidth),
@@ -3796,21 +3727,16 @@ CreateImageData(JSContext* cx, CanvasRen
     new mozilla::dom::ImageData(w, h, *darray);
   return imageData.forget();
 }
 
 already_AddRefed<ImageData>
 CanvasRenderingContext2D::CreateImageData(JSContext* cx, double sw,
                                           double sh, ErrorResult& error)
 {
-  if (!FloatValidate(sw, sh)) {
-    error.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
-    return NULL;
-  }
-
   if (!sw || !sh) {
     error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
     return NULL;
   }
 
   int32_t wi = JS_DoubleToInt32(sw);
   int32_t hi = JS_DoubleToInt32(sh);
 
--- a/content/canvas/src/CanvasRenderingContext2D.h
+++ b/content/canvas/src/CanvasRenderingContext2D.h
@@ -159,18 +159,17 @@ public:
 
   double GlobalAlpha()
   {
     return CurrentState().globalAlpha;
   }
 
   void SetGlobalAlpha(double globalAlpha)
   {
-    if (mozilla::CanvasUtils::FloatValidate(globalAlpha) &&
-        globalAlpha >= 0.0 && globalAlpha <= 1.0) {
+    if (globalAlpha >= 0.0 && globalAlpha <= 1.0) {
       CurrentState().globalAlpha = globalAlpha;
     }
   }
 
   void GetGlobalCompositeOperation(nsAString& op, mozilla::ErrorResult& error);
   void SetGlobalCompositeOperation(const nsAString& op,
                                    mozilla::ErrorResult& error);
   JS::Value GetStrokeStyle(JSContext* cx, mozilla::ErrorResult& error);
@@ -199,41 +198,37 @@ public:
 
   double ShadowOffsetX()
   {
     return CurrentState().shadowOffset.x;
   }
 
   void SetShadowOffsetX(double shadowOffsetX)
   {
-    if (mozilla::CanvasUtils::FloatValidate(shadowOffsetX)) {
-      CurrentState().shadowOffset.x = shadowOffsetX;
-    }
+    CurrentState().shadowOffset.x = shadowOffsetX;
   }
 
   double ShadowOffsetY()
   {
     return CurrentState().shadowOffset.y;
   }
 
   void SetShadowOffsetY(double shadowOffsetY)
   {
-    if (mozilla::CanvasUtils::FloatValidate(shadowOffsetY)) {
-      CurrentState().shadowOffset.y = shadowOffsetY;
-    }
+    CurrentState().shadowOffset.y = shadowOffsetY;
   }
 
   double ShadowBlur()
   {
     return CurrentState().shadowBlur;
   }
 
   void SetShadowBlur(double shadowBlur)
   {
-    if (mozilla::CanvasUtils::FloatValidate(shadowBlur) && shadowBlur >= 0.0) {
+    if (shadowBlur >= 0.0) {
       CurrentState().shadowBlur = shadowBlur;
     }
   }
 
   void GetShadowColor(nsAString& shadowColor)
   {
     StyleColorToString(CurrentState().shadowColor, shadowColor);
   }
@@ -255,40 +250,30 @@ public:
                   const mozilla::dom::Optional<double>& maxWidth,
                   mozilla::ErrorResult& error);
   already_AddRefed<nsIDOMTextMetrics>
     MeasureText(const nsAString& rawText, mozilla::ErrorResult& error);
 
   void DrawImage(const HTMLImageOrCanvasOrVideoElement& image,
                  double dx, double dy, mozilla::ErrorResult& error)
   {
-    if (!mozilla::CanvasUtils::FloatValidate(dx, dy)) {
-      return;
-    }
     DrawImage(image, 0.0, 0.0, 0.0, 0.0, dx, dy, 0.0, 0.0, 0, error);
   }
 
   void DrawImage(const HTMLImageOrCanvasOrVideoElement& image,
                  double dx, double dy, double dw, double dh,
                  mozilla::ErrorResult& error)
   {
-    if (!mozilla::CanvasUtils::FloatValidate(dx, dy, dw, dh)) {
-      return;
-    }
     DrawImage(image, 0.0, 0.0, 0.0, 0.0, dx, dy, dw, dh, 2, error);
   }
 
   void DrawImage(const HTMLImageOrCanvasOrVideoElement& image,
                  double sx, double sy, double sw, double sh, double dx,
                  double dy, double dw, double dh, mozilla::ErrorResult& error)
   {
-    if (!mozilla::CanvasUtils::FloatValidate(sx, sy, sw, sh) ||
-        !mozilla::CanvasUtils::FloatValidate(dx, dy, dw, dh)) {
-      return;
-    }
     DrawImage(image, sx, sy, sw, sh, dx, dy, dw, dh, 6, error);
   }
 
   already_AddRefed<mozilla::dom::ImageData>
     CreateImageData(JSContext* cx, double sw, double sh,
                     mozilla::ErrorResult& error);
   already_AddRefed<mozilla::dom::ImageData>
     CreateImageData(JSContext* cx, mozilla::dom::ImageData& imagedata,
@@ -305,33 +290,33 @@ public:
 
   double LineWidth()
   {
     return CurrentState().lineWidth;
   }
 
   void SetLineWidth(double width)
   {
-    if (mozilla::CanvasUtils::FloatValidate(width) && width > 0.0) {
+    if (width > 0.0) {
       CurrentState().lineWidth = width;
     }
   }
   void GetLineCap(nsAString& linecap);
   void SetLineCap(const nsAString& linecap);
   void GetLineJoin(nsAString& linejoin, mozilla::ErrorResult& error);
   void SetLineJoin(const nsAString& linejoin);
 
   double MiterLimit()
   {
     return CurrentState().miterLimit;
   }
 
   void SetMiterLimit(double miter)
   {
-    if (mozilla::CanvasUtils::FloatValidate(miter) && miter > 0.0) {
+    if (miter > 0.0) {
       CurrentState().miterLimit = miter;
     }
   }
 
   void GetFont(nsAString& font)
   {
     font = GetFont();
   }
@@ -350,64 +335,56 @@ public:
       mPathBuilder->Close();
     } else {
       mDSPathBuilder->Close();
     }
   }
 
   void MoveTo(double x, double y)
   {
-    if (mozilla::CanvasUtils::FloatValidate(x, y)) {
-      EnsureWritablePath();
+    EnsureWritablePath();
 
-      if (mPathBuilder) {
-        mPathBuilder->MoveTo(mozilla::gfx::Point(x, y));
-      } else {
-        mDSPathBuilder->MoveTo(mTarget->GetTransform() *
-                                 mozilla::gfx::Point(x, y));
-      }
+    if (mPathBuilder) {
+      mPathBuilder->MoveTo(mozilla::gfx::Point(x, y));
+    } else {
+      mDSPathBuilder->MoveTo(mTarget->GetTransform() *
+                             mozilla::gfx::Point(x, y));
     }
   }
 
   void LineTo(double x, double y)
   {
-    if (mozilla::CanvasUtils::FloatValidate(x, y)) {
-      EnsureWritablePath();
+    EnsureWritablePath();
     
-      LineTo(mozilla::gfx::Point(x, y));
-    }
+    LineTo(mozilla::gfx::Point(x, y));
   }
 
   void QuadraticCurveTo(double cpx, double cpy, double x, double y)
   {
-    if (mozilla::CanvasUtils::FloatValidate(cpx, cpy, x, y)) {
-      EnsureWritablePath();
+    EnsureWritablePath();
 
-      if (mPathBuilder) {
-        mPathBuilder->QuadraticBezierTo(mozilla::gfx::Point(cpx, cpy),
+    if (mPathBuilder) {
+      mPathBuilder->QuadraticBezierTo(mozilla::gfx::Point(cpx, cpy),
+                                      mozilla::gfx::Point(x, y));
+    } else {
+      mozilla::gfx::Matrix transform = mTarget->GetTransform();
+      mDSPathBuilder->QuadraticBezierTo(transform *
+                                        mozilla::gfx::Point(cpx, cpy),
+                                        transform *
                                         mozilla::gfx::Point(x, y));
-      } else {
-        mozilla::gfx::Matrix transform = mTarget->GetTransform();
-        mDSPathBuilder->QuadraticBezierTo(transform *
-                                            mozilla::gfx::Point(cpx, cpy),
-                                          transform *
-                                            mozilla::gfx::Point(x, y));
-      }
     }
   }
 
   void BezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y)
   {
-    if (mozilla::CanvasUtils::FloatValidate(cp1x, cp1y, cp2x, cp2y, x, y)) {
-      EnsureWritablePath();
+    EnsureWritablePath();
 
-      BezierTo(mozilla::gfx::Point(cp1x, cp1y),
-               mozilla::gfx::Point(cp2x, cp2y),
-               mozilla::gfx::Point(x, y));
-    }
+    BezierTo(mozilla::gfx::Point(cp1x, cp1y),
+             mozilla::gfx::Point(cp2x, cp2y),
+             mozilla::gfx::Point(x, y));
   }
 
   void ArcTo(double x1, double y1, double x2, double y2, double radius,
              mozilla::ErrorResult& error);
   void Rect(double x, double y, double w, double h);
   void Arc(double x, double y, double radius, double startAngle,
            double endAngle, bool anticlockwise, mozilla::ErrorResult& error);