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

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

Issue 2585263003: Avoid overflow when checking if a transform is integer translation. (Closed)
Patch Set: integer-transform Created 4 years 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 | « ui/gfx/transform.h ('k') | ui/gfx/transform_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 (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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 ApproximatelyZero(matrix_.get(1, 2), tolerance) && 239 ApproximatelyZero(matrix_.get(1, 2), tolerance) &&
240 ApproximatelyOne(matrix_.get(2, 2), tolerance) && 240 ApproximatelyOne(matrix_.get(2, 2), tolerance) &&
241 matrix_.get(3, 2) == 0 && 241 matrix_.get(3, 2) == 0 &&
242 matrix_.get(3, 3) == 1; 242 matrix_.get(3, 3) == 1;
243 } 243 }
244 244
245 bool Transform::IsIdentityOrIntegerTranslation() const { 245 bool Transform::IsIdentityOrIntegerTranslation() const {
246 if (!IsIdentityOrTranslation()) 246 if (!IsIdentityOrTranslation())
247 return false; 247 return false;
248 248
249 float t[] = {matrix_.get(0, 3), matrix_.get(1, 3), matrix_.get(2, 3)};
249 bool no_fractional_translation = 250 bool no_fractional_translation =
250 static_cast<int>(matrix_.get(0, 3)) == matrix_.get(0, 3) && 251 base::IsValueInRangeForNumericType<int>(t[0]) &&
251 static_cast<int>(matrix_.get(1, 3)) == matrix_.get(1, 3) && 252 base::IsValueInRangeForNumericType<int>(t[1]) &&
252 static_cast<int>(matrix_.get(2, 3)) == matrix_.get(2, 3); 253 base::IsValueInRangeForNumericType<int>(t[2]) &&
254 static_cast<int>(t[0]) == t[0] && static_cast<int>(t[1]) == t[1] &&
255 static_cast<int>(t[2]) == t[2];
253 256
254 return no_fractional_translation; 257 return no_fractional_translation;
255 } 258 }
256 259
257 bool Transform::IsBackFaceVisible() const { 260 bool Transform::IsBackFaceVisible() const {
258 // Compute whether a layer with a forward-facing normal of (0, 0, 1, 0) 261 // Compute whether a layer with a forward-facing normal of (0, 0, 1, 0)
259 // would have its back face visible after applying the transform. 262 // would have its back face visible after applying the transform.
260 if (matrix_.isIdentity()) 263 if (matrix_.isIdentity())
261 return false; 264 return false;
262 265
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 matrix_.get(2, 1), 604 matrix_.get(2, 1),
602 matrix_.get(2, 2), 605 matrix_.get(2, 2),
603 matrix_.get(2, 3), 606 matrix_.get(2, 3),
604 matrix_.get(3, 0), 607 matrix_.get(3, 0),
605 matrix_.get(3, 1), 608 matrix_.get(3, 1),
606 matrix_.get(3, 2), 609 matrix_.get(3, 2),
607 matrix_.get(3, 3)); 610 matrix_.get(3, 3));
608 } 611 }
609 612
610 } // namespace gfx 613 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/transform.h ('k') | ui/gfx/transform_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698