Commit 0d86ccd6 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[PE] Optimize FloatRect::EnclosingIntRect() and EnclosedRect()

Use ClampSub on integer values instead of clampTo<int> on float values.

This can improve record time by 3% on Android
(https://pinpoint-dot-chromeperf.appspot.com/job/14d64d9e440000
 click "Analyze benchmark results).

Change-Id: I8521a93caf821c551f342c551b5de84b6e35e092
Bug: 820467
Reviewed-on: https://chromium-review.googlesource.com/958292Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543264}
parent 5391302f
......@@ -220,14 +220,12 @@ FloatRect UnionRect(const Vector<FloatRect>& rects) {
}
IntRect EnclosedIntRect(const FloatRect& rect) {
// Compute the enclosed rect using float types directly rather than
// FlooredIntPoint(...) etc. to avoid triggering integer overflows.
FloatPoint location(ceilf(rect.X()), ceilf(rect.Y()));
FloatPoint max_point(floorf(rect.MaxX()), floorf(rect.MaxY()));
FloatSize size = max_point - location;
IntPoint location = CeiledIntPoint(rect.Location());
IntPoint max_point = FlooredIntPoint(rect.MaxXMaxYCorner());
IntSize size(ClampSub(max_point.X(), location.X()),
ClampSub(max_point.Y(), location.Y()));
size.ClampNegativeToZero();
return IntRect(clampTo<int>(location.X()), clampTo<int>(location.Y()),
clampTo<int>(size.Width()), clampTo<int>(size.Height()));
return IntRect(location, size);
}
IntRect RoundedIntRect(const FloatRect& rect) {
......
......@@ -35,6 +35,7 @@
#include "platform/geometry/IntRect.h"
#include "platform/wtf/Allocator.h"
#include "platform/wtf/Forward.h"
#include "platform/wtf/SaturatedArithmetic.h"
#if defined(OS_MACOSX)
typedef struct CGRect CGRect;
......@@ -239,13 +240,10 @@ inline bool operator!=(const FloatRect& a, const FloatRect& b) {
// Returns a IntRect containing the given FloatRect.
inline IntRect EnclosingIntRect(const FloatRect& rect) {
// Compute the enclosing rect using float types directly rather than
// FlooredIntPoint(...) etc. to avoid triggering integer overflows.
FloatPoint location(floorf(rect.X()), floorf(rect.Y()));
FloatPoint max_point(ceilf(rect.MaxX()), ceilf(rect.MaxY()));
FloatSize size = max_point - location;
return IntRect(clampTo<int>(location.X()), clampTo<int>(location.Y()),
clampTo<int>(size.Width()), clampTo<int>(size.Height()));
IntPoint location = FlooredIntPoint(rect.Location());
IntPoint max_point = CeiledIntPoint(rect.MaxXMaxYCorner());
return IntRect(location, IntSize(ClampSub(max_point.X(), location.X()),
ClampSub(max_point.Y(), location.Y())));
}
// Returns a valid IntRect contained within the given FloatRect.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment