Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3081)

Unified Diff: cc/base/math_util.cc

Issue 1321503002: cc: Do not create separate tilings for almost equal scale factors. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved roundto function to ideal scales. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/base/math_util.cc
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc
index 6e5ac0bd45db73b47d318a7d4b3aef0f42af0078..f3ad5ef7a967ad186d7fbbf6987c2ea8341d7560 100644
--- a/cc/base/math_util.cc
+++ b/cc/base/math_util.cc
@@ -120,6 +120,32 @@ static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex,
(*num_vertices_in_clipped_quad)++;
}
+float MathUtil::RoundToFixedPrecision(float value, int precision) {
+ DCHECK_GE(precision, 0);
+
+ // The value of std::numeric_limits<float>::digits10 is the number of base-10
+ // digits that can be represented by the type float without change.
+ int max_digits10 = std::numeric_limits<float>::digits10;
+
+ float integral_part;
+ float fractional_part = std::modf(value, &integral_part);
+
+ // Return if |value| can not be represented by float without change.
+ int digits10_in_integral_part =
+ integral_part > 0 ? static_cast<int>(std::log10(integral_part)) + 1 : 1;
+ if (digits10_in_integral_part > max_digits10)
+ return value;
+
+ // Get maximum possible precision.
+ int possible_precision =
+ std::min((max_digits10 - digits10_in_integral_part), precision);
+ DCHECK(possible_precision < max_digits10);
+
+ float factor = std::pow(10, possible_precision);
+ fractional_part = std::round(fractional_part * factor) / factor;
+ return integral_part + fractional_part;
+}
+
gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform,
const gfx::Rect& src_rect) {
if (transform.IsIdentityOrIntegerTranslation()) {

Powered by Google App Engine
This is Rietveld 408576698