OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_sorter.h" | 5 #include "cc/trees/layer_sorter.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 #include <limits> | 9 #include <limits> |
10 #include <vector> | 10 #include <vector> |
(...skipping 11 matching lines...) Expand all Loading... |
22 // a value near machine epsilon and then increasing it until the flickering on | 22 // a value near machine epsilon and then increasing it until the flickering on |
23 // the test scene went away. | 23 // the test scene went away. |
24 const float k_layer_epsilon = 1e-4f; | 24 const float k_layer_epsilon = 1e-4f; |
25 | 25 |
26 inline static float PerpProduct(gfx::Vector2dF u, gfx::Vector2dF v) { | 26 inline static float PerpProduct(gfx::Vector2dF u, gfx::Vector2dF v) { |
27 return u.x() * v.y() - u.y() * v.x(); | 27 return u.x() * v.y() - u.y() * v.x(); |
28 } | 28 } |
29 | 29 |
30 // Tests if two edges defined by their endpoints (a,b) and (c,d) intersect. | 30 // Tests if two edges defined by their endpoints (a,b) and (c,d) intersect. |
31 // Returns true and the point of intersection if they do and false otherwise. | 31 // Returns true and the point of intersection if they do and false otherwise. |
32 static bool EdgeEdgeTest(gfx::PointF a, | 32 static bool EdgeEdgeTest(const gfx::PointF& a, |
33 gfx::PointF b, | 33 const gfx::PointF& b, |
34 gfx::PointF c, | 34 const gfx::PointF& c, |
35 gfx::PointF d, | 35 const gfx::PointF& d, |
36 gfx::PointF* r) { | 36 gfx::PointF* r) { |
37 gfx::Vector2dF u = b - a; | 37 gfx::Vector2dF u = b - a; |
38 gfx::Vector2dF v = d - c; | 38 gfx::Vector2dF v = d - c; |
39 gfx::Vector2dF w = a - c; | 39 gfx::Vector2dF w = a - c; |
40 | 40 |
41 float denom = PerpProduct(u, v); | 41 float denom = PerpProduct(u, v); |
42 | 42 |
43 // If denom == 0 then the edges are parallel. While they could be overlapping | 43 // If denom == 0 then the edges are parallel. While they could be overlapping |
44 // we don't bother to check here as the we'll find their intersections from | 44 // we don't bother to check here as the we'll find their intersections from |
45 // the corner to quad tests. | 45 // the corner to quad tests. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 235 |
236 transform_origin = c1; | 236 transform_origin = c1; |
237 } | 237 } |
238 | 238 |
239 LayerShape::~LayerShape() {} | 239 LayerShape::~LayerShape() {} |
240 | 240 |
241 // Returns the Z coordinate of a point on the layer that projects | 241 // Returns the Z coordinate of a point on the layer that projects |
242 // to point p which lies on the z = 0 plane. It does it by computing the | 242 // to point p which lies on the z = 0 plane. It does it by computing the |
243 // intersection of a line starting from p along the Z axis and the plane | 243 // intersection of a line starting from p along the Z axis and the plane |
244 // of the layer. | 244 // of the layer. |
245 float LayerShape::LayerZFromProjectedPoint(gfx::PointF p) const { | 245 float LayerShape::LayerZFromProjectedPoint(const gfx::PointF& p) const { |
246 gfx::Vector3dF z_axis(0.f, 0.f, 1.f); | 246 gfx::Vector3dF z_axis(0.f, 0.f, 1.f); |
247 gfx::Vector3dF w = gfx::Point3F(p) - transform_origin; | 247 gfx::Vector3dF w = gfx::Point3F(p) - transform_origin; |
248 | 248 |
249 float d = gfx::DotProduct(layer_normal, z_axis); | 249 float d = gfx::DotProduct(layer_normal, z_axis); |
250 float n = -gfx::DotProduct(layer_normal, w); | 250 float n = -gfx::DotProduct(layer_normal, w); |
251 | 251 |
252 // Check if layer is parallel to the z = 0 axis which will make it | 252 // Check if layer is parallel to the z = 0 axis which will make it |
253 // invisible and hence returning zero is fine. | 253 // invisible and hence returning zero is fine. |
254 if (!d) | 254 if (!d) |
255 return 0.f; | 255 return 0.f; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 *it = sorted_list[count++]->layer; | 460 *it = sorted_list[count++]->layer; |
461 | 461 |
462 DVLOG(2) << "Sorting end ----"; | 462 DVLOG(2) << "Sorting end ----"; |
463 | 463 |
464 nodes_.clear(); | 464 nodes_.clear(); |
465 edges_.clear(); | 465 edges_.clear(); |
466 active_edges_.clear(); | 466 active_edges_.clear(); |
467 } | 467 } |
468 | 468 |
469 } // namespace cc | 469 } // namespace cc |
OLD | NEW |