From 935ba27050014122fe90f049a4f1deb46ed706bd Mon Sep 17 00:00:00 2001 From: "danakj@chromium.org" Date: Mon, 20 May 2013 03:50:21 +0000 Subject: 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 --- ui/gfx/rect.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'ui/gfx/rect.h') 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 #include #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; #endif -- cgit v1.1