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

Side by Side Diff: ui/gfx/transform.cc

Issue 12541006: Use LCD text if the transform IsAlmostIdentityAndIntegerTranslation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Transform::IsAlmostXXX methods Created 7 years, 9 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 | Annotate | Revision Log
« cc/layer_tree_host_common.cc ('K') | « ui/gfx/transform.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "ui/gfx/transform.h" 8 #include "ui/gfx/transform.h"
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 12 matching lines...) Expand all
23 namespace { 23 namespace {
24 24
25 // Taken from SkMatrix44. 25 // Taken from SkMatrix44.
26 const double kTooSmallForDeterminant = 1e-8; 26 const double kTooSmallForDeterminant = 1e-8;
27 27
28 double TanDegrees(double degrees) { 28 double TanDegrees(double degrees) {
29 double radians = degrees * M_PI / 180; 29 double radians = degrees * M_PI / 180;
30 return std::tan(radians); 30 return std::tan(radians);
31 } 31 }
32 32
33 bool AlmostEqual(double d, double i) {
34 const double kErrorThreshold = 1e-6;
alokp 2013/03/08 19:40:06 The error threshold should really depend on the tr
Xianzhu 2013/03/08 23:36:56 My another thought is not to add these methods but
35 return std::abs(d - i) < kErrorThreshold;
36 }
37
38 double Round(double d) {
39 return (d > 0.0) ? std::floor(d + 0.5) : std::ceil(d - 0.5);
40 }
41
33 } // namespace 42 } // namespace
34 43
35 Transform::Transform( 44 Transform::Transform(
36 double col1row1, double col2row1, double col3row1, double col4row1, 45 double col1row1, double col2row1, double col3row1, double col4row1,
37 double col1row2, double col2row2, double col3row2, double col4row2, 46 double col1row2, double col2row2, double col3row2, double col4row2,
38 double col1row3, double col2row3, double col3row3, double col4row3, 47 double col1row3, double col2row3, double col3row3, double col4row3,
39 double col1row4, double col2row4, double col3row4, double col4row4) 48 double col1row4, double col2row4, double col3row4, double col4row4)
40 : matrix_(SkMatrix44::kUninitialized_Constructor) 49 : matrix_(SkMatrix44::kUninitialized_Constructor)
41 { 50 {
42 matrix_.setDouble(0, 0, col1row1); 51 matrix_.setDouble(0, 0, col1row1);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 return false; 217 return false;
209 218
210 bool no_fractional_translation = 219 bool no_fractional_translation =
211 static_cast<int>(matrix_.getDouble(0, 3)) == matrix_.getDouble(0, 3) && 220 static_cast<int>(matrix_.getDouble(0, 3)) == matrix_.getDouble(0, 3) &&
212 static_cast<int>(matrix_.getDouble(1, 3)) == matrix_.getDouble(1, 3) && 221 static_cast<int>(matrix_.getDouble(1, 3)) == matrix_.getDouble(1, 3) &&
213 static_cast<int>(matrix_.getDouble(2, 3)) == matrix_.getDouble(2, 3); 222 static_cast<int>(matrix_.getDouble(2, 3)) == matrix_.getDouble(2, 3);
214 223
215 return no_fractional_translation; 224 return no_fractional_translation;
216 } 225 }
217 226
227
228 bool Transform::IsAlmostIdentity() const {
229 return IsAlmostIdentityOrTranslation() &&
230 AlmostEqual(matrix_.getDouble(0, 3), 0) &&
231 AlmostEqual(matrix_.getDouble(1, 3), 0) &&
232 AlmostEqual(matrix_.getDouble(2, 3), 0);
233 }
234
235 bool Transform::IsAlmostIdentityOrTranslation() const {
236 return IsScaleOrTranslation() &&
237 AlmostEqual(matrix_.getDouble(0, 0), 1) &&
238 AlmostEqual(matrix_.getDouble(1, 1), 1) &&
239 AlmostEqual(matrix_.getDouble(2, 2), 1);
240 }
241
242 bool Transform::IsAlmostIdentityOrIntegerTranslation() const {
243 return IsAlmostIdentityOrTranslation() &&
244 AlmostEqual(matrix_.getDouble(0, 3), Round(matrix_.getDouble(0, 3))) &&
245 AlmostEqual(matrix_.getDouble(1, 3), Round(matrix_.getDouble(1, 3))) &&
246 AlmostEqual(matrix_.getDouble(2, 3), Round(matrix_.getDouble(2, 3)));
247 }
248
218 bool Transform::IsBackFaceVisible() const { 249 bool Transform::IsBackFaceVisible() const {
219 // Compute whether a layer with a forward-facing normal of (0, 0, 1, 0) 250 // Compute whether a layer with a forward-facing normal of (0, 0, 1, 0)
220 // would have its back face visible after applying the transform. 251 // would have its back face visible after applying the transform.
221 if (matrix_.isIdentity()) 252 if (matrix_.isIdentity())
222 return false; 253 return false;
223 254
224 // This is done by transforming the normal and seeing if the resulting z 255 // This is done by transforming the normal and seeing if the resulting z
225 // value is positive or negative. However, note that transforming a normal 256 // value is positive or negative. However, note that transforming a normal
226 // actually requires using the inverse-transpose of the original transform. 257 // actually requires using the inverse-transpose of the original transform.
227 // 258 //
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 matrix_.getDouble(2, 1), 473 matrix_.getDouble(2, 1),
443 matrix_.getDouble(2, 2), 474 matrix_.getDouble(2, 2),
444 matrix_.getDouble(2, 3), 475 matrix_.getDouble(2, 3),
445 matrix_.getDouble(3, 0), 476 matrix_.getDouble(3, 0),
446 matrix_.getDouble(3, 1), 477 matrix_.getDouble(3, 1),
447 matrix_.getDouble(3, 2), 478 matrix_.getDouble(3, 2),
448 matrix_.getDouble(3, 3)); 479 matrix_.getDouble(3, 3));
449 } 480 }
450 481
451 } // namespace gfx 482 } // namespace gfx
OLDNEW
« cc/layer_tree_host_common.cc ('K') | « ui/gfx/transform.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698