Bug 1059033 - Part 2: Approximate path stroke extents for culling since its faster. r=Bas
☠☠ backed out by 6cddb4cf40e3 ☠ ☠
authorMatt Woodrow <mwoodrow@mozilla.com>
Mon, 01 Sep 2014 15:22:40 +1200
changeset 224472 1ef5a3a9bb0641803493ec57d7ebbb2b3c91a108
parent 224471 a7eaac164c36c9a23df61c91bf3359ee0c296071
child 224473 301fdfea8fbfe14e1179b96a47b2c9a69f3a2bae
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs1059033
milestone34.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 1059033 - Part 2: Approximate path stroke extents for culling since its faster. r=Bas
gfx/2d/DrawTargetTiled.cpp
--- a/gfx/2d/DrawTargetTiled.cpp
+++ b/gfx/2d/DrawTargetTiled.cpp
@@ -215,20 +215,50 @@ DrawTargetTiled::FillRect(const Rect& aR
                                    mTiles[i].mTileOrigin.y,
                                    mTiles[i].mDrawTarget->GetSize().width,
                                    mTiles[i].mDrawTarget->GetSize().height))) {
       mTiles[i].mDrawTarget->FillRect(aRect, aPattern, aDrawOptions);
     }
   }
 }
 
+// The logic for this comes from _cairo_stroke_style_max_distance_from_path
+static Rect
+PathExtentsToMaxStrokeExtents(const StrokeOptions &aStrokeOptions,
+                              const Rect &aRect,
+                              const Matrix &aTransform)
+{
+  float styleExpansionFactor = 0.5f;
+
+  if (aStrokeOptions.mLineCap == CapStyle::SQUARE) {
+    styleExpansionFactor = M_SQRT1_2;
+  }
+
+  if (aStrokeOptions.mLineJoin == JoinStyle::MITER &&
+      styleExpansionFactor < M_SQRT2 * aStrokeOptions.mMiterLimit) {
+    styleExpansionFactor = M_SQRT2 * aStrokeOptions.mMiterLimit;
+  }
+
+  styleExpansionFactor *= aStrokeOptions.mLineWidth;
+
+  double dx = styleExpansionFactor * hypot(aTransform._11, aTransform._21);
+  double dy = styleExpansionFactor * hypot(aTransform._22, aTransform._12);
+
+  Rect result = aRect;
+  result.Inflate(dx, dy);
+  return result;
+}
+
 void
 DrawTargetTiled::Stroke(const Path* aPath, const Pattern& aPattern, const StrokeOptions& aStrokeOptions, const DrawOptions& aDrawOptions)
 {
-  Rect deviceRect = aPath->GetStrokedBounds(aStrokeOptions, mTransform);
+  // Approximate the stroke extents, since Path::GetStrokeExtents can be slow
+  Rect deviceRect = PathExtentsToMaxStrokeExtents(aStrokeOptions,
+                                                 aPath->GetBounds(mTransform),
+                                                 mTransform);
   for (size_t i = 0; i < mTiles.size(); i++) {
     if (deviceRect.Intersects(Rect(mTiles[i].mTileOrigin.x,
                                    mTiles[i].mTileOrigin.y,
                                    mTiles[i].mDrawTarget->GetSize().width,
                                    mTiles[i].mDrawTarget->GetSize().height))) {
       mTiles[i].mDrawTarget->Stroke(aPath, aPattern, aStrokeOptions, aDrawOptions);
     }
   }