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

Side by Side Diff: cc/base/math_util.cc

Issue 266913021: Hit test on the layer tree rather than the RSLL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
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 23 matching lines...) Expand all
34 34
35 SkMScalar z = -(transform.matrix().get(2, 0) * p.x() + 35 SkMScalar z = -(transform.matrix().get(2, 0) * p.x() +
36 transform.matrix().get(2, 1) * p.y() + 36 transform.matrix().get(2, 1) * p.y() +
37 transform.matrix().get(2, 3)) / 37 transform.matrix().get(2, 3)) /
38 transform.matrix().get(2, 2); 38 transform.matrix().get(2, 2);
39 HomogeneousCoordinate result(p.x(), p.y(), z, 1.0); 39 HomogeneousCoordinate result(p.x(), p.y(), z, 1.0);
40 transform.matrix().mapMScalars(result.vec, result.vec); 40 transform.matrix().mapMScalars(result.vec, result.vec);
41 return result; 41 return result;
42 } 42 }
43 43
44 static HomogeneousCoordinate ProjectHomogeneousPoint(
45 const gfx::Transform& transform,
46 const gfx::PointF& p,
47 bool* clipped) {
48 HomogeneousCoordinate h = ProjectHomogeneousPoint(transform, p);
49 *clipped = h.w() <= 0;
50 return h;
51 }
52
44 static HomogeneousCoordinate MapHomogeneousPoint( 53 static HomogeneousCoordinate MapHomogeneousPoint(
45 const gfx::Transform& transform, 54 const gfx::Transform& transform,
46 const gfx::Point3F& p) { 55 const gfx::Point3F& p) {
47 HomogeneousCoordinate result(p.x(), p.y(), p.z(), 1.0); 56 HomogeneousCoordinate result(p.x(), p.y(), p.z(), 1.0);
48 transform.matrix().mapMScalars(result.vec, result.vec); 57 transform.matrix().mapMScalars(result.vec, result.vec);
49 return result; 58 return result;
50 } 59 }
51 60
52 static HomogeneousCoordinate ComputeClippedPointForEdge( 61 static HomogeneousCoordinate ComputeClippedPointForEdge(
53 const HomogeneousCoordinate& h1, 62 const HomogeneousCoordinate& h1,
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 *clipped |= clipped_point; 446 *clipped |= clipped_point;
438 projected_quad.set_p4(ProjectPoint(transform, q.p4(), &clipped_point)); 447 projected_quad.set_p4(ProjectPoint(transform, q.p4(), &clipped_point));
439 *clipped |= clipped_point; 448 *clipped |= clipped_point;
440 449
441 return projected_quad; 450 return projected_quad;
442 } 451 }
443 452
444 gfx::PointF MathUtil::ProjectPoint(const gfx::Transform& transform, 453 gfx::PointF MathUtil::ProjectPoint(const gfx::Transform& transform,
445 const gfx::PointF& p, 454 const gfx::PointF& p,
446 bool* clipped) { 455 bool* clipped) {
447 HomogeneousCoordinate h = ProjectHomogeneousPoint(transform, p); 456 HomogeneousCoordinate h = ProjectHomogeneousPoint(transform, p, clipped);
448
449 if (h.w() > 0) {
450 // The cartesian coordinates will be valid in this case.
451 *clipped = false;
452 return h.CartesianPoint2d();
453 }
454
455 // The cartesian coordinates will be invalid after dividing by w.
456 *clipped = true;
457
458 // Avoid dividing by w if w == 0. 457 // Avoid dividing by w if w == 0.
459 if (!h.w()) 458 if (!h.w())
460 return gfx::PointF(); 459 return gfx::PointF();
461 460
462 // This return value will be invalid because clipped == true, but (1) users of 461 // This return value will be invalid if clipped == true, but (1) users of
463 // this code should be ignoring the return value when clipped == true anyway, 462 // this code should be ignoring the return value when clipped == true anyway,
464 // and (2) this behavior is more consistent with existing behavior of WebKit 463 // and (2) this behavior is more consistent with existing behavior of WebKit
465 // transforms if the user really does not ignore the return value. 464 // transforms if the user really does not ignore the return value.
466 return h.CartesianPoint2d(); 465 return h.CartesianPoint2d();
467 } 466 }
468 467
468 gfx::Point3F MathUtil::ProjectPoint3D(const gfx::Transform& transform,
469 const gfx::PointF& p,
470 bool* clipped) {
471 HomogeneousCoordinate h = ProjectHomogeneousPoint(transform, p, clipped);
472 if (!h.w())
473 return gfx::Point3F();
474 return h.CartesianPoint3d();
enne (OOO) 2014/05/06 20:30:58 What if h is clipped?
Ian Vollick 2014/05/06 21:06:20 In that case, the answer isn't valid, but won't di
475 }
476
469 gfx::RectF MathUtil::ScaleRectProportional(const gfx::RectF& input_outer_rect, 477 gfx::RectF MathUtil::ScaleRectProportional(const gfx::RectF& input_outer_rect,
470 const gfx::RectF& scale_outer_rect, 478 const gfx::RectF& scale_outer_rect,
471 const gfx::RectF& scale_inner_rect) { 479 const gfx::RectF& scale_inner_rect) {
472 gfx::RectF output_inner_rect = input_outer_rect; 480 gfx::RectF output_inner_rect = input_outer_rect;
473 float scale_rect_to_input_scale_x = 481 float scale_rect_to_input_scale_x =
474 scale_outer_rect.width() / input_outer_rect.width(); 482 scale_outer_rect.width() / input_outer_rect.width();
475 float scale_rect_to_input_scale_y = 483 float scale_rect_to_input_scale_y =
476 scale_outer_rect.height() / input_outer_rect.height(); 484 scale_outer_rect.height() / input_outer_rect.height();
477 485
478 gfx::Vector2dF top_left_diff = 486 gfx::Vector2dF top_left_diff =
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( 645 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue(
638 std::min(value, std::numeric_limits<double>::max()))); 646 std::min(value, std::numeric_limits<double>::max())));
639 } 647 }
640 648
641 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) { 649 scoped_ptr<base::Value> MathUtil::AsValueSafely(float value) {
642 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue( 650 return scoped_ptr<base::Value>(base::Value::CreateDoubleValue(
643 std::min(value, std::numeric_limits<float>::max()))); 651 std::min(value, std::numeric_limits<float>::max())));
644 } 652 }
645 653
646 } // namespace cc 654 } // namespace cc
OLDNEW
« no previous file with comments | « cc/base/math_util.h ('k') | cc/layers/draw_properties.h » ('j') | cc/layers/draw_properties.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698