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

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: Removed unrelated changes. 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
« no previous file with comments | « cc/base/math_util.h ('k') | cc/base/math_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/math_util.cc
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc
index 6e5ac0bd45db73b47d318a7d4b3aef0f42af0078..388fcd694eb4daed1a17cd6eb5b41ab41035ef9f 100644
--- a/cc/base/math_util.cc
+++ b/cc/base/math_util.cc
@@ -120,6 +120,21 @@ static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex,
(*num_vertices_in_clipped_quad)++;
}
+float MathUtil::RoundToFixedPrecision(float value) {
+ const int kScalePrecision = 4;
vmpstr 2015/10/16 17:58:17 Can you just write const float kFactor = 1e4 inste
prashant.n 2015/10/17 01:28:13 I'll add precision as a parameter, I was thinking
+ // Limiting precision 1 <= kScalePrecision <= 8, as floating point precision
+ // of >= 12 gives different values, 8 on a safer side.
+ DCHECK(kScalePrecision >= 1 && kScalePrecision <= 8);
+
+ const float factor = pow(10, kScalePrecision);
+ float integral;
+ float fractional = std::modf(value, &integral);
+ fractional *= factor;
vmpstr 2015/10/16 17:58:17 nit: I'd just write these three things in one line
+ fractional = std::round(fractional);
+ fractional /= factor;
+ return integral + fractional;
+}
+
gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform,
const gfx::Rect& src_rect) {
if (transform.IsIdentityOrIntegerTranslation()) {
« no previous file with comments | « cc/base/math_util.h ('k') | cc/base/math_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698