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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/base/math_util.h" 5 #include "cc/base/math_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 (*num_vertices_in_clipped_quad)++; 113 (*num_vertices_in_clipped_quad)++;
114 } 114 }
115 115
116 static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex, 116 static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex,
117 gfx::Point3F clipped_quad[8], 117 gfx::Point3F clipped_quad[8],
118 int* num_vertices_in_clipped_quad) { 118 int* num_vertices_in_clipped_quad) {
119 clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; 119 clipped_quad[*num_vertices_in_clipped_quad] = new_vertex;
120 (*num_vertices_in_clipped_quad)++; 120 (*num_vertices_in_clipped_quad)++;
121 } 121 }
122 122
123 float MathUtil::RoundToFixedPrecision(float value) {
124 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
125 // Limiting precision 1 <= kScalePrecision <= 8, as floating point precision
126 // of >= 12 gives different values, 8 on a safer side.
127 DCHECK(kScalePrecision >= 1 && kScalePrecision <= 8);
128
129 const float factor = pow(10, kScalePrecision);
130 float integral;
131 float fractional = std::modf(value, &integral);
132 fractional *= factor;
vmpstr 2015/10/16 17:58:17 nit: I'd just write these three things in one line
133 fractional = std::round(fractional);
134 fractional /= factor;
135 return integral + fractional;
136 }
137
123 gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform, 138 gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform,
124 const gfx::Rect& src_rect) { 139 const gfx::Rect& src_rect) {
125 if (transform.IsIdentityOrIntegerTranslation()) { 140 if (transform.IsIdentityOrIntegerTranslation()) {
126 gfx::Vector2d offset(static_cast<int>(transform.matrix().getFloat(0, 3)), 141 gfx::Vector2d offset(static_cast<int>(transform.matrix().getFloat(0, 3)),
127 static_cast<int>(transform.matrix().getFloat(1, 3))); 142 static_cast<int>(transform.matrix().getFloat(1, 3)));
128 return src_rect + offset; 143 return src_rect + offset;
129 } 144 }
130 gfx::RectF mapped_rect = MapClippedRect(transform, gfx::RectF(src_rect)); 145 gfx::RectF mapped_rect = MapClippedRect(transform, gfx::RectF(src_rect));
131 146
132 // gfx::ToEnclosingRect crashes if called on a RectF with any NaN coordinate. 147 // gfx::ToEnclosingRect crashes if called on a RectF with any NaN coordinate.
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 transform.matrix().getFloat(2, 0)); 904 transform.matrix().getFloat(2, 0));
890 } 905 }
891 906
892 gfx::Vector3dF MathUtil::GetYAxis(const gfx::Transform& transform) { 907 gfx::Vector3dF MathUtil::GetYAxis(const gfx::Transform& transform) {
893 return gfx::Vector3dF(transform.matrix().getFloat(0, 1), 908 return gfx::Vector3dF(transform.matrix().getFloat(0, 1),
894 transform.matrix().getFloat(1, 1), 909 transform.matrix().getFloat(1, 1),
895 transform.matrix().getFloat(2, 1)); 910 transform.matrix().getFloat(2, 1));
896 } 911 }
897 912
898 } // namespace cc 913 } // namespace cc
OLDNEW
« 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