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> |
11 | 11 |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
14 #include "cc/layers/render_surface_impl.h" | 14 #include "cc/layers/render_surface_impl.h" |
15 #include "ui/gfx/transform.h" | 15 #include "ui/gfx/transform.h" |
16 | 16 |
17 namespace cc { | 17 namespace cc { |
18 | 18 |
19 // This epsilon is used to determine if two layers are too close to each other | 19 // This epsilon is used to determine if two layers are too close to each other |
20 // to be able to tell which is in front of the other. It's a relative epsilon | 20 // to be able to tell which is in front of the other. It's a relative epsilon |
21 // so it is robust to changes in scene scale. This value was chosen by picking | 21 // so it is robust to changes in scene scale. This value was chosen by picking |
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(const gfx::Vector2dF& u, | |
27 const gfx::Vector2dF& v) { | |
28 return u.x() * v.y() - u.y() * v.x(); | |
29 } | |
30 | |
31 // Tests if two edges defined by their endpoints (a,b) and (c,d) intersect. | 26 // Tests if two edges defined by their endpoints (a,b) and (c,d) intersect. |
32 // Returns true and the point of intersection if they do and false otherwise. | 27 // Returns true and the point of intersection if they do and false otherwise. |
33 static bool EdgeEdgeTest(const gfx::PointF& a, | 28 static bool EdgeEdgeTest(const gfx::PointF& a, |
34 const gfx::PointF& b, | 29 const gfx::PointF& b, |
35 const gfx::PointF& c, | 30 const gfx::PointF& c, |
36 const gfx::PointF& d, | 31 const gfx::PointF& d, |
37 gfx::PointF* r) { | 32 gfx::PointF* r) { |
38 gfx::Vector2dF u = b - a; | 33 gfx::Vector2dF u = b - a; |
39 gfx::Vector2dF v = d - c; | 34 gfx::Vector2dF v = d - c; |
40 gfx::Vector2dF w = a - c; | 35 gfx::Vector2dF w = a - c; |
41 | 36 |
42 float denom = PerpProduct(u, v); | 37 float denom = gfx::CrossProduct(u, v); |
danakj
2014/08/06 13:45:55
this method returns a double, so you'll get narrow
hj.r.chung
2014/08/07 01:55:12
While looking into the code, I've found that there
| |
43 | 38 |
44 // If denom == 0 then the edges are parallel. While they could be overlapping | 39 // If denom == 0 then the edges are parallel. While they could be overlapping |
45 // we don't bother to check here as the we'll find their intersections from | 40 // we don't bother to check here as the we'll find their intersections from |
46 // the corner to quad tests. | 41 // the corner to quad tests. |
47 if (!denom) | 42 if (!denom) |
48 return false; | 43 return false; |
49 | 44 |
50 float s = PerpProduct(v, w) / denom; | 45 float s = gfx::CrossProduct(v, w) / denom; |
51 if (s < 0.f || s > 1.f) | 46 if (s < 0.f || s > 1.f) |
52 return false; | 47 return false; |
53 | 48 |
54 float t = PerpProduct(u, w) / denom; | 49 float t = gfx::CrossProduct(u, w) / denom; |
55 if (t < 0.f || t > 1.f) | 50 if (t < 0.f || t > 1.f) |
56 return false; | 51 return false; |
57 | 52 |
58 u.Scale(s); | 53 u.Scale(s); |
59 *r = a + u; | 54 *r = a + u; |
60 return true; | 55 return true; |
61 } | 56 } |
62 | 57 |
63 GraphNode::GraphNode(LayerImpl* layer_impl) | 58 GraphNode::GraphNode(LayerImpl* layer_impl) |
64 : layer(layer_impl), | 59 : layer(layer_impl), |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
461 *it = sorted_list[count++]->layer; | 456 *it = sorted_list[count++]->layer; |
462 | 457 |
463 DVLOG(2) << "Sorting end ----"; | 458 DVLOG(2) << "Sorting end ----"; |
464 | 459 |
465 nodes_.clear(); | 460 nodes_.clear(); |
466 edges_.clear(); | 461 edges_.clear(); |
467 active_edges_.clear(); | 462 active_edges_.clear(); |
468 } | 463 } |
469 | 464 |
470 } // namespace cc | 465 } // namespace cc |
OLD | NEW |