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/resources/layer_quad.h" | 5 #include "cc/resources/layer_quad.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/gfx/geometry/quad_f.h" | 8 #include "ui/gfx/geometry/quad_f.h" |
9 | 9 |
10 namespace cc { | 10 namespace cc { |
11 | 11 |
12 LayerQuad::Edge::Edge(const gfx::PointF& p, const gfx::PointF& q) { | 12 LayerQuad::Edge::Edge(const gfx::PointF& p, const gfx::PointF& q) { |
13 if (p == q) { | 13 if (p == q) { |
14 degenerate_ = true; | 14 degenerate_ = true; |
15 return; | 15 return; |
16 } | 16 } |
17 degenerate_ = false; | 17 degenerate_ = false; |
18 gfx::Vector2dF tangent(p.y() - q.y(), q.x() - p.x()); | 18 gfx::Vector2dF tangent(p.y() - q.y(), q.x() - p.x()); |
19 float cross2 = p.x() * q.y() - q.x() * p.y(); | 19 float cross2 = p.x() * q.y() - q.x() * p.y(); |
20 | 20 |
21 set(tangent.x(), tangent.y(), cross2); | 21 set(tangent.x(), tangent.y(), cross2); |
22 scale(1.0f / tangent.Length()); | 22 scale(1.0f / tangent.Length()); |
23 } | 23 } |
24 | 24 |
| 25 gfx::PointF LayerQuad::Edge::Intersect(const LayerQuad::Edge& e) const { |
| 26 DCHECK(!degenerate()); |
| 27 DCHECK(!e.degenerate()); |
| 28 |
| 29 return gfx::PointF((y() * e.z() - e.y() * z()) / (x() * e.y() - e.x() * y()), |
| 30 (x() * e.z() - e.x() * z()) / (e.x() * y() - x() * e.y())); |
| 31 } |
| 32 |
25 LayerQuad::LayerQuad(const gfx::QuadF& quad) { | 33 LayerQuad::LayerQuad(const gfx::QuadF& quad) { |
26 // Create edges. | 34 // Create edges. |
27 left_ = Edge(quad.p4(), quad.p1()); | 35 left_ = Edge(quad.p4(), quad.p1()); |
28 right_ = Edge(quad.p2(), quad.p3()); | 36 right_ = Edge(quad.p2(), quad.p3()); |
29 top_ = Edge(quad.p1(), quad.p2()); | 37 top_ = Edge(quad.p1(), quad.p2()); |
30 bottom_ = Edge(quad.p3(), quad.p4()); | 38 bottom_ = Edge(quad.p3(), quad.p4()); |
31 | 39 |
32 float sign = quad.IsCounterClockwise() ? -1 : 1; | 40 float sign = quad.IsCounterClockwise() ? -1 : 1; |
33 left_.scale(sign); | 41 left_.scale(sign); |
34 right_.scale(sign); | 42 right_.scale(sign); |
35 top_.scale(sign); | 43 top_.scale(sign); |
36 bottom_.scale(sign); | 44 bottom_.scale(sign); |
37 } | 45 } |
38 | 46 |
39 LayerQuad::LayerQuad(const Edge& left, | 47 LayerQuad::LayerQuad(const Edge& left, |
40 const Edge& top, | 48 const Edge& top, |
41 const Edge& right, | 49 const Edge& right, |
42 const Edge& bottom) | 50 const Edge& bottom) |
43 : left_(left), | 51 : left_(left), |
44 top_(top), | 52 top_(top), |
45 right_(right), | 53 right_(right), |
46 bottom_(bottom) {} | 54 bottom_(bottom) {} |
47 | 55 |
48 gfx::QuadF LayerQuad::ToQuadF() const { | 56 gfx::QuadF LayerQuad::ToQuadF() const { |
| 57 size_t num_degenerate_edges = left_.degenerate() + right_.degenerate() + |
| 58 top_.degenerate() + bottom_.degenerate(); |
| 59 if (num_degenerate_edges > 1) { |
| 60 return gfx::QuadF(); |
| 61 } |
| 62 |
49 if (left_.degenerate()) { | 63 if (left_.degenerate()) { |
50 return gfx::QuadF(top_.Intersect(bottom_), top_.Intersect(right_), | 64 return gfx::QuadF(top_.Intersect(bottom_), top_.Intersect(right_), |
51 right_.Intersect(bottom_), bottom_.Intersect(top_)); | 65 right_.Intersect(bottom_), bottom_.Intersect(top_)); |
52 } | 66 } |
53 if (right_.degenerate()) { | 67 if (right_.degenerate()) { |
54 return gfx::QuadF(left_.Intersect(top_), top_.Intersect(bottom_), | 68 return gfx::QuadF(left_.Intersect(top_), top_.Intersect(bottom_), |
55 bottom_.Intersect(top_), bottom_.Intersect(left_)); | 69 bottom_.Intersect(top_), bottom_.Intersect(left_)); |
56 } | 70 } |
57 if (top_.degenerate()) { | 71 if (top_.degenerate()) { |
58 return gfx::QuadF(left_.Intersect(right_), right_.Intersect(left_), | 72 return gfx::QuadF(left_.Intersect(right_), right_.Intersect(left_), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 flattened[10] = right_.y(); | 115 flattened[10] = right_.y(); |
102 flattened[11] = right_.z(); | 116 flattened[11] = right_.z(); |
103 } else { | 117 } else { |
104 flattened[9] = bottom_.x(); | 118 flattened[9] = bottom_.x(); |
105 flattened[10] = bottom_.y(); | 119 flattened[10] = bottom_.y(); |
106 flattened[11] = bottom_.z(); | 120 flattened[11] = bottom_.z(); |
107 } | 121 } |
108 } | 122 } |
109 | 123 |
110 } // namespace cc | 124 } // namespace cc |
OLD | NEW |