Bug 973308 - Don't let empty clip rects put infinities into the gradient calculations. r=jrmuizel
authorMarkus Stange <mstange@themasta.com>
Tue, 18 Feb 2014 23:18:29 +0100
changeset 187622 74b07332a161fba40b1f8ce4f545a7860643c925
parent 187621 37de5a3f1a93e196bdb35609e40ed0ce84f8509f
child 187623 56fa355b196de79be1c3e6fba8c65aaa2518fe44
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel
bugs973308
milestone30.0a1
Bug 973308 - Don't let empty clip rects put infinities into the gradient calculations. r=jrmuizel
gfx/2d/DrawTargetCG.cpp
--- a/gfx/2d/DrawTargetCG.cpp
+++ b/gfx/2d/DrawTargetCG.cpp
@@ -8,16 +8,17 @@
 #include "Rect.h"
 #include "ScaledFontMac.h"
 #include "Tools.h"
 #include <vector>
 #include <algorithm>
 #include "MacIOSurface.h"
 #include "FilterNodeSoftware.h"
 #include "mozilla/Assertions.h"
+#include "mozilla/FloatingPoint.h"
 
 using namespace std;
 
 //CG_EXTERN void CGContextSetCompositeOperation (CGContextRef, PrivateCGCompositeMode);
 
 // A private API that Cairo has been using for a long time
 CG_EXTERN void CGContextSetCTM(CGContextRef, CGAffineTransform);
 
@@ -408,16 +409,18 @@ DrawTargetCG::CreateGradientStops(Gradie
 }
 
 static void
 UpdateLinearParametersToIncludePoint(double *min_t, double *max_t,
                                      CGPoint *start,
                                      double dx, double dy,
                                      double x, double y)
 {
+  MOZ_ASSERT(IsFinite(x) && IsFinite(y));
+
   /**
    * Compute a parameter t such that a line perpendicular to the (dx,dy)
    * vector, passing through (start->x + dx*t, start->y + dy*t), also
    * passes through (x,y).
    *
    * Let px = x - start->x, py = y - start->y.
    * t is given by
    *   (px - dx*t)*dx + (py - dy*t)*dy = 0
@@ -604,16 +607,20 @@ DrawRadialRepeatingGradient(CGContextRef
   CGContextDrawRadialGradient(cg, gradient, startCenter, startRadius, endCenter, endRadius,
                               kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation);
   CGGradientRelease(gradient);
 }
 
 static void
 DrawGradient(CGContextRef cg, const Pattern &aPattern, const CGRect &aExtents)
 {
+  if (CGRectIsEmpty(aExtents)) {
+    return;
+  }
+
   if (aPattern.GetType() == PatternType::LINEAR_GRADIENT) {
     const LinearGradientPattern& pat = static_cast<const LinearGradientPattern&>(aPattern);
     GradientStopsCG *stops = static_cast<GradientStopsCG*>(pat.mStops.get());
     CGContextConcatCTM(cg, GfxMatrixToCGAffineTransform(pat.mMatrix));
     if (stops->mExtend == ExtendMode::CLAMP) {
 
       // XXX: we should take the m out of the properties of LinearGradientPatterns
       CGPoint startPoint = { pat.mBegin.x, pat.mBegin.y };