Bug 1268854 - Break out of loop if no intersecting points on positive side of clipping plane. r=kip, a=sylvestre
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Thu, 23 Jun 2016 12:41:04 +0200
changeset 312123 910b8f21e777344217c019c8487fb79a52362799
parent 312122 aa538aa9619d2034e89b1890dfe4ea195d671f1b
child 312124 2246e1791e363a3a39d601d5b4d47000f4ca82d2
child 312130 188615976db5378e62521997d974601654b1624c
push id167
push usercbook@mozilla.com
push dateFri, 24 Jun 2016 09:48:23 +0000
treeherdermozilla-esr45@910b8f21e777 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskip, sylvestre
bugs1268854
milestone45.2.1esr
Bug 1268854 - Break out of loop if no intersecting points on positive side of clipping plane. r=kip, a=sylvestre
gfx/2d/Matrix.h
--- a/gfx/2d/Matrix.h
+++ b/gfx/2d/Matrix.h
@@ -688,16 +688,17 @@ public:
   size_t TransformAndClipRect(const RectTyped<SourceUnits, F>& aRect,
                               const RectTyped<TargetUnits, F>& aClip,
                               PointTyped<TargetUnits, F>* aVerts) const
   {
     // Initialize a double-buffered array of points in homogenous space with
     // the input rectangle, aRect.
     Point4DTyped<UnknownUnits, F> points[2][kTransformAndClipRectMaxVerts];
     Point4DTyped<UnknownUnits, F>* dstPoint = points[0];
+
     *dstPoint++ = *this * Point4DTyped<UnknownUnits, F>(aRect.x, aRect.y, 0, 1);
     *dstPoint++ = *this * Point4DTyped<UnknownUnits, F>(aRect.XMost(), aRect.y, 0, 1);
     *dstPoint++ = *this * Point4DTyped<UnknownUnits, F>(aRect.XMost(), aRect.YMost(), 0, 1);
     *dstPoint++ = *this * Point4DTyped<UnknownUnits, F>(aRect.x, aRect.YMost(), 0, 1);
 
     // View frustum clipping planes are described as normals originating from
     // the 0,0,0,0 origin.
     Point4DTyped<UnknownUnits, F> planeNormals[4];
@@ -706,24 +707,25 @@ public:
     planeNormals[2] = Point4DTyped<UnknownUnits, F>(0.0, 1.0, 0.0, -aClip.y);
     planeNormals[3] = Point4DTyped<UnknownUnits, F>(0.0, -1.0, 0.0, aClip.YMost());
 
     // Iterate through each clipping plane and clip the polygon.
     // In each pass, we double buffer, alternating between points[0] and
     // points[1].
     for (int plane=0; plane < 4; plane++) {
       planeNormals[plane].Normalize();
-
       Point4DTyped<UnknownUnits, F>* srcPoint = points[plane & 1];
       Point4DTyped<UnknownUnits, F>* srcPointEnd = dstPoint;
+
       dstPoint = points[~plane & 1];
+      Point4DTyped<UnknownUnits, F>* dstPointStart = dstPoint;
 
       Point4DTyped<UnknownUnits, F>* prevPoint = srcPointEnd - 1;
       F prevDot = planeNormals[plane].DotProduct(*prevPoint);
-      while (srcPoint < srcPointEnd) {
+      while (srcPoint < srcPointEnd && ((dstPoint - dstPointStart) < kTransformAndClipRectMaxVerts)) {
         F nextDot = planeNormals[plane].DotProduct(*srcPoint);
 
         if ((nextDot >= 0.0) != (prevDot >= 0.0)) {
           // An intersection with the clipping plane has been detected.
           // Interpolate to find the intersecting point and emit it.
           F t = -prevDot / (nextDot - prevDot);
           *dstPoint++ = *srcPoint * t + *prevPoint * (1.0 - t);
         }
@@ -732,16 +734,20 @@ public:
           // Emit any source points that are on the positive side of the
           // clipping plane.
           *dstPoint++ = *srcPoint;
         }
 
         prevPoint = srcPoint++;
         prevDot = nextDot;
       }
+
+      if (dstPoint == dstPointStart) {
+        break;
+      }
     }
 
     size_t dstPointCount = 0;
     size_t srcPointCount = dstPoint - points[0];
     for (Point4DTyped<UnknownUnits, F>* srcPoint = points[0]; srcPoint < points[0] + srcPointCount; srcPoint++) {
 
       PointTyped<TargetUnits, F> p;
       if (srcPoint->w == 0.0) {
@@ -755,17 +761,17 @@ public:
       if (dstPointCount == 0 || p != aVerts[dstPointCount - 1]) {
         aVerts[dstPointCount++] = p;
       }
     }
 
     return dstPointCount;
   }
 
-  static const size_t kTransformAndClipRectMaxVerts = 32;
+  static const int kTransformAndClipRectMaxVerts = 32;
 
   static Matrix4x4Typed From2D(const Matrix &aMatrix) {
     Matrix4x4Typed matrix;
     matrix._11 = aMatrix._11;
     matrix._12 = aMatrix._12;
     matrix._21 = aMatrix._21;
     matrix._22 = aMatrix._22;
     matrix._41 = aMatrix._31;