Bug 966996 - The computed gradient stops need not cover the origin, so don't start at zero. r=jrmuizel
authorMarkus Stange <mstange@themasta.com>
Thu, 13 Feb 2014 12:11:16 +0100
changeset 186791 7d6e5cd7fe20ba7c7b5e5a88903ef3900929aed7
parent 186790 28b77fb96e6299b8cd99c812795ba063af5fcea4
child 186792 5d85a904177426340df7432a2b23b0c3a56ee47a
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel
bugs966996
milestone30.0a1
Bug 966996 - The computed gradient stops need not cover the origin, so don't start at zero. r=jrmuizel
gfx/2d/DrawTargetCG.cpp
--- a/gfx/2d/DrawTargetCG.cpp
+++ b/gfx/2d/DrawTargetCG.cpp
@@ -7,16 +7,17 @@
 #include "SourceSurfaceCG.h"
 #include "Rect.h"
 #include "ScaledFontMac.h"
 #include "Tools.h"
 #include <vector>
 #include <algorithm>
 #include "MacIOSurface.h"
 #include "FilterNodeSoftware.h"
+#include "mozilla/Assertions.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);
 
@@ -447,18 +448,18 @@ UpdateLinearParametersToIncludePoint(dou
  * Repeat the gradient line such that lines extended perpendicular to the
  * gradient line at both start and end would completely enclose the drawing
  * extents.
  */
 static void
 CalculateRepeatingGradientParams(CGPoint *aStart, CGPoint *aEnd,
                                  CGRect aExtents, int *aRepeatCount)
 {
-  double t_min = 0.;
-  double t_max = 0.;
+  double t_min = INFINITY;
+  double t_max = -INFINITY;
   double dx = aEnd->x - aStart->x;
   double dy = aEnd->y - aStart->y;
 
   double bounds_x1 = aExtents.origin.x;
   double bounds_y1 = aExtents.origin.y;
   double bounds_x2 = aExtents.origin.x + aExtents.size.width;
   double bounds_y2 = aExtents.origin.y + aExtents.size.height;
 
@@ -466,16 +467,19 @@ CalculateRepeatingGradientParams(CGPoint
                                        bounds_x1, bounds_y1);
   UpdateLinearParametersToIncludePoint(&t_min, &t_max, aStart, dx, dy,
                                        bounds_x2, bounds_y1);
   UpdateLinearParametersToIncludePoint(&t_min, &t_max, aStart, dx, dy,
                                        bounds_x2, bounds_y2);
   UpdateLinearParametersToIncludePoint(&t_min, &t_max, aStart, dx, dy,
                                        bounds_x1, bounds_y2);
 
+  MOZ_ASSERT(!isinf(t_min) && !isinf(t_max),
+             "The first call to UpdateLinearParametersToIncludePoint should have made t_min and t_max non-infinite.");
+
   // Move t_min and t_max to the nearest usable integer to try to avoid
   // subtle variations due to numerical instability, especially accidentally
   // cutting off a pixel. Extending the gradient repetitions is always safe.
   t_min = floor (t_min);
   t_max = ceil (t_max);
   aEnd->x = aStart->x + dx * t_max;
   aEnd->y = aStart->y + dy * t_max;
   aStart->x = aStart->x + dx * t_min;