diff options
author | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-20 03:50:21 +0000 |
---|---|---|
committer | danakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-20 03:50:21 +0000 |
commit | 935ba27050014122fe90f049a4f1deb46ed706bd (patch) | |
tree | 5041e9cd7ccf2da87df61c5adb08e030a19ca5cf /ui/gfx/rect.h | |
parent | e9561a0db15f4d1384c150c589caf86cdb33dc93 (diff) | |
download | chromium_src-935ba27050014122fe90f049a4f1deb46ed706bd.zip chromium_src-935ba27050014122fe90f049a4f1deb46ed706bd.tar.gz chromium_src-935ba27050014122fe90f049a4f1deb46ed706bd.tar.bz2 |
Add shortcut path for scaling integer rects.
This adds a method to scale and take the enclosing/enclosed rect
for an integer rect, and uses it in cc/.
This method avoids mode complex methods in safe_integer_conversions
since the input is an integer rect not an arbitrary float rect.
This moves the ImplSidePaintingPerfTest.HeavyPage test from about
0.96 ms/commit to about 0.92 ms/commit.
R=enne, sky
BUG=239684
Review URL: https://chromiumcodereview.appspot.com/15313003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@201006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/rect.h')
-rw-r--r-- | ui/gfx/rect.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/ui/gfx/rect.h b/ui/gfx/rect.h index 52856d7..d983770 100644 --- a/ui/gfx/rect.h +++ b/ui/gfx/rect.h @@ -12,6 +12,7 @@ #ifndef UI_GFX_RECT_H_ #define UI_GFX_RECT_H_ +#include <cmath> #include <string> #include "ui/gfx/point.h" @@ -107,6 +108,34 @@ UI_EXPORT Rect SubtractRects(const Rect& a, const Rect& b); // contained within the rect, because they will appear on one of these edges. UI_EXPORT Rect BoundingRect(const Point& p1, const Point& p2); +inline Rect ScaleToEnclosingRect(const Rect& rect, + float x_scale, + float y_scale) { + int x = std::floor(rect.x() * x_scale); + int y = std::floor(rect.y() * y_scale); + int r = rect.width() == 0 ? x : std::ceil(rect.right() * x_scale); + int b = rect.height() == 0 ? y : std::ceil(rect.bottom() * y_scale); + return Rect(x, y, r - x, b - y); +} + +inline Rect ScaleToEnclosingRect(const Rect& rect, float scale) { + return ScaleToEnclosingRect(rect, scale, scale); +} + +inline Rect ScaleToEnclosedRect(const Rect& rect, + float x_scale, + float y_scale) { + int x = std::ceil(rect.x() * x_scale); + int y = std::ceil(rect.y() * y_scale); + int r = rect.width() == 0 ? x : std::floor(rect.right() * x_scale); + int b = rect.height() == 0 ? y : std::floor(rect.bottom() * y_scale); + return Rect(x, y, r - x, b - y); +} + +inline Rect ScaleToEnclosedRect(const Rect& rect, float scale) { + return ScaleToEnclosedRect(rect, scale, scale); +} + #if !defined(COMPILER_MSVC) extern template class RectBase<Rect, Point, Size, Insets, Vector2d, int>; #endif |