static float ComputeDistanceFromRegion(const nsPoint& aPoint, const nsRegion& aRegion) { MOZ_ASSERT(!aRegion.IsEmpty(), "can't compute distance between point and empty region"); float minDist = -1; for (auto iter = aRegion.RectIter(); !iter.Done(); iter.Next()) { float dist = ComputeDistanceFromRect(aPoint, iter.Get()); if (dist < minDist || minDist < 0) { minDist = dist; } } return minDist; }
// Subtract aRegion from aExposedRegion as long as that doesn't make the // exposed region get too complex or removes a big chunk of the exposed region. static void SubtractFromExposedRegion(nsRegion* aExposedRegion, const nsRegion& aRegion) { if (aRegion.IsEmpty()) return; nsRegion tmp; tmp.Sub(*aExposedRegion, aRegion); // Don't let *aExposedRegion get too complex, but don't let it fluff out to // its bounds either. Do let aExposedRegion get more complex if by doing so // we reduce its area by at least half. if (tmp.GetNumRects() <= 15 || tmp.Area() <= aExposedRegion->Area()/2) { *aExposedRegion = tmp; } }
static float ComputeDistanceFromRegion(const nsPoint& aPoint, const nsRegion& aRegion) { MOZ_ASSERT(!aRegion.IsEmpty(), "can't compute distance between point and empty region"); nsRegionRectIterator iter(aRegion); const nsRect* r; float minDist = -1; while ((r = iter.Next()) != nullptr) { float dist = ComputeDistanceFromRect(aPoint, *r); if (dist < minDist || minDist < 0) { minDist = dist; } } return minDist; }
nsRegion nsFilterInstance::GetPostFilterDirtyArea(nsIFrame *aFilteredFrame, const nsRegion& aPreFilterDirtyRegion) { if (aPreFilterDirtyRegion.IsEmpty()) { return nsRegion(); } gfxMatrix unused; // aPaintTransform arg not used since we're not painting auto& filterChain = aFilteredFrame->StyleSVGReset()->mFilters; UniquePtr<UserSpaceMetrics> metrics = UserSpaceMetricsForFrame(aFilteredFrame); nsFilterInstance instance(aFilteredFrame, aFilteredFrame->GetContent(), *metrics, filterChain, nullptr, unused, nullptr, &aPreFilterDirtyRegion); if (!instance.IsInitialized()) { return nsRegion(); } // We've passed in the source's dirty area so the instance knows about it. // Now we can ask the instance to compute the area of the filter output // that's dirty. return instance.ComputePostFilterDirtyRegion(); }
nsRegion nsFilterInstance::GetPostFilterDirtyArea(nsIFrame *aFilteredFrame, const nsRegion& aPreFilterDirtyRegion) { if (aPreFilterDirtyRegion.IsEmpty()) { return nsRegion(); } nsFilterInstance instance(aFilteredFrame, nullptr, nullptr, &aPreFilterDirtyRegion); if (!instance.IsInitialized()) { return nsRegion(); } // We've passed in the source's dirty area so the instance knows about it. // Now we can ask the instance to compute the area of the filter output // that's dirty. nsRegion dirtyRegion; nsresult rv = instance.ComputePostFilterDirtyRegion(&dirtyRegion); if (NS_SUCCEEDED(rv)) { return dirtyRegion; } return nsRegion(); }