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 DCHECK(p != q); | 13 if (p == q) { |
14 | 14 degenerate_ = true; |
| 15 return; |
| 16 } |
| 17 degenerate_ = false; |
15 gfx::Vector2dF tangent(p.y() - q.y(), q.x() - p.x()); | 18 gfx::Vector2dF tangent(p.y() - q.y(), q.x() - p.x()); |
16 float cross2 = p.x() * q.y() - q.x() * p.y(); | 19 float cross2 = p.x() * q.y() - q.x() * p.y(); |
17 | 20 |
18 set(tangent.x(), tangent.y(), cross2); | 21 set(tangent.x(), tangent.y(), cross2); |
19 scale(1.0f / tangent.Length()); | 22 scale(1.0f / tangent.Length()); |
20 } | 23 } |
21 | 24 |
22 LayerQuad::LayerQuad(const gfx::QuadF& quad) { | 25 LayerQuad::LayerQuad(const gfx::QuadF& quad) { |
23 // Create edges. | 26 // Create edges. |
24 left_ = Edge(quad.p4(), quad.p1()); | 27 left_ = Edge(quad.p4(), quad.p1()); |
(...skipping 11 matching lines...) Expand all Loading... |
36 LayerQuad::LayerQuad(const Edge& left, | 39 LayerQuad::LayerQuad(const Edge& left, |
37 const Edge& top, | 40 const Edge& top, |
38 const Edge& right, | 41 const Edge& right, |
39 const Edge& bottom) | 42 const Edge& bottom) |
40 : left_(left), | 43 : left_(left), |
41 top_(top), | 44 top_(top), |
42 right_(right), | 45 right_(right), |
43 bottom_(bottom) {} | 46 bottom_(bottom) {} |
44 | 47 |
45 gfx::QuadF LayerQuad::ToQuadF() const { | 48 gfx::QuadF LayerQuad::ToQuadF() const { |
| 49 if (left_.degenerate()) { |
| 50 return gfx::QuadF(top_.Intersect(bottom_), top_.Intersect(right_), |
| 51 right_.Intersect(bottom_), bottom_.Intersect(top_)); |
| 52 } |
| 53 if (right_.degenerate()) { |
| 54 return gfx::QuadF(left_.Intersect(top_), top_.Intersect(bottom_), |
| 55 bottom_.Intersect(top_), bottom_.Intersect(left_)); |
| 56 } |
| 57 if (top_.degenerate()) { |
| 58 return gfx::QuadF(left_.Intersect(right_), right_.Intersect(left_), |
| 59 right_.Intersect(bottom_), bottom_.Intersect(left_)); |
| 60 } |
| 61 if (bottom_.degenerate()) { |
| 62 return gfx::QuadF(left_.Intersect(top_), top_.Intersect(right_), |
| 63 right_.Intersect(left_), left_.Intersect(right_)); |
| 64 } |
46 return gfx::QuadF(left_.Intersect(top_), | 65 return gfx::QuadF(left_.Intersect(top_), |
47 top_.Intersect(right_), | 66 top_.Intersect(right_), |
48 right_.Intersect(bottom_), | 67 right_.Intersect(bottom_), |
49 bottom_.Intersect(left_)); | 68 bottom_.Intersect(left_)); |
50 } | 69 } |
51 | 70 |
52 void LayerQuad::ToFloatArray(float flattened[12]) const { | 71 void LayerQuad::ToFloatArray(float flattened[12]) const { |
53 flattened[0] = left_.x(); | 72 if (left_.degenerate()) { |
54 flattened[1] = left_.y(); | 73 flattened[0] = bottom_.x(); |
55 flattened[2] = left_.z(); | 74 flattened[1] = bottom_.y(); |
56 flattened[3] = top_.x(); | 75 flattened[2] = bottom_.z(); |
57 flattened[4] = top_.y(); | 76 } else { |
58 flattened[5] = top_.z(); | 77 flattened[0] = left_.x(); |
59 flattened[6] = right_.x(); | 78 flattened[1] = left_.y(); |
60 flattened[7] = right_.y(); | 79 flattened[2] = left_.z(); |
61 flattened[8] = right_.z(); | 80 } |
62 flattened[9] = bottom_.x(); | 81 if (top_.degenerate()) { |
63 flattened[10] = bottom_.y(); | 82 flattened[3] = left_.x(); |
64 flattened[11] = bottom_.z(); | 83 flattened[4] = left_.y(); |
| 84 flattened[5] = left_.z(); |
| 85 } else { |
| 86 flattened[3] = top_.x(); |
| 87 flattened[4] = top_.y(); |
| 88 flattened[5] = top_.z(); |
| 89 } |
| 90 if (right_.degenerate()) { |
| 91 flattened[6] = top_.x(); |
| 92 flattened[7] = top_.y(); |
| 93 flattened[8] = top_.z(); |
| 94 } else { |
| 95 flattened[6] = right_.x(); |
| 96 flattened[7] = right_.y(); |
| 97 flattened[8] = right_.z(); |
| 98 } |
| 99 if (bottom_.degenerate()) { |
| 100 flattened[9] = right_.x(); |
| 101 flattened[10] = right_.y(); |
| 102 flattened[11] = right_.z(); |
| 103 } else { |
| 104 flattened[9] = bottom_.x(); |
| 105 flattened[10] = bottom_.y(); |
| 106 flattened[11] = bottom_.z(); |
| 107 } |
65 } | 108 } |
66 | 109 |
67 } // namespace cc | 110 } // namespace cc |
OLD | NEW |