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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "cc/layer_quad.h" | 7 #include "cc/layer_quad.h" |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "ui/gfx/quad_f.h" |
10 | 11 |
11 namespace cc { | 12 namespace cc { |
12 | 13 |
13 LayerQuad::Edge::Edge(const gfx::PointF& p, const gfx::PointF& q) | 14 LayerQuad::Edge::Edge(const gfx::PointF& p, const gfx::PointF& q) |
14 { | 15 { |
15 DCHECK(p != q); | 16 DCHECK(p != q); |
16 | 17 |
17 gfx::Vector2dF tangent(p.y() - q.y(), q.x() - p.x()); | 18 gfx::Vector2dF tangent(p.y() - q.y(), q.x() - p.x()); |
18 float cross2 = p.x() * q.y() - q.x() * p.y(); | 19 float cross2 = p.x() * q.y() - q.x() * p.y(); |
19 | 20 |
20 set(tangent.x(), tangent.y(), cross2); | 21 set(tangent.x(), tangent.y(), cross2); |
21 scale(1.0f / tangent.Length()); | 22 scale(1.0f / tangent.Length()); |
22 } | 23 } |
23 | 24 |
24 LayerQuad::LayerQuad(const FloatQuad& quad) | 25 LayerQuad::LayerQuad(const gfx::QuadF& quad) |
25 { | 26 { |
26 // Create edges. | 27 // Create edges. |
27 m_left = Edge(quad.p4(), quad.p1()); | 28 m_left = Edge(quad.p4(), quad.p1()); |
28 m_right = Edge(quad.p2(), quad.p3()); | 29 m_right = Edge(quad.p2(), quad.p3()); |
29 m_top = Edge(quad.p1(), quad.p2()); | 30 m_top = Edge(quad.p1(), quad.p2()); |
30 m_bottom = Edge(quad.p3(), quad.p4()); | 31 m_bottom = Edge(quad.p3(), quad.p4()); |
31 | 32 |
32 float sign = quad.isCounterclockwise() ? -1 : 1; | 33 float sign = quad.IsCounterClockwise() ? -1 : 1; |
33 m_left.scale(sign); | 34 m_left.scale(sign); |
34 m_right.scale(sign); | 35 m_right.scale(sign); |
35 m_top.scale(sign); | 36 m_top.scale(sign); |
36 m_bottom.scale(sign); | 37 m_bottom.scale(sign); |
37 } | 38 } |
38 | 39 |
39 LayerQuad::LayerQuad(const Edge& left, const Edge& top, const Edge& right, const
Edge& bottom) | 40 LayerQuad::LayerQuad(const Edge& left, const Edge& top, const Edge& right, const
Edge& bottom) |
40 : m_left(left) | 41 : m_left(left) |
41 , m_top(top) | 42 , m_top(top) |
42 , m_right(right) | 43 , m_right(right) |
43 , m_bottom(bottom) | 44 , m_bottom(bottom) |
44 { | 45 { |
45 } | 46 } |
46 | 47 |
47 FloatQuad LayerQuad::floatQuad() const | 48 gfx::QuadF LayerQuad::ToQuadF() const |
48 { | 49 { |
49 return FloatQuad(m_left.intersect(m_top), | 50 return gfx::QuadF(m_left.intersect(m_top), |
50 m_top.intersect(m_right), | 51 m_top.intersect(m_right), |
51 m_right.intersect(m_bottom), | 52 m_right.intersect(m_bottom), |
52 m_bottom.intersect(m_left)); | 53 m_bottom.intersect(m_left)); |
53 } | 54 } |
54 | 55 |
55 void LayerQuad::toFloatArray(float flattened[12]) const | 56 void LayerQuad::toFloatArray(float flattened[12]) const |
56 { | 57 { |
57 flattened[0] = m_left.x(); | 58 flattened[0] = m_left.x(); |
58 flattened[1] = m_left.y(); | 59 flattened[1] = m_left.y(); |
59 flattened[2] = m_left.z(); | 60 flattened[2] = m_left.z(); |
60 flattened[3] = m_top.x(); | 61 flattened[3] = m_top.x(); |
61 flattened[4] = m_top.y(); | 62 flattened[4] = m_top.y(); |
62 flattened[5] = m_top.z(); | 63 flattened[5] = m_top.z(); |
63 flattened[6] = m_right.x(); | 64 flattened[6] = m_right.x(); |
64 flattened[7] = m_right.y(); | 65 flattened[7] = m_right.y(); |
65 flattened[8] = m_right.z(); | 66 flattened[8] = m_right.z(); |
66 flattened[9] = m_bottom.x(); | 67 flattened[9] = m_bottom.x(); |
67 flattened[10] = m_bottom.y(); | 68 flattened[10] = m_bottom.y(); |
68 flattened[11] = m_bottom.z(); | 69 flattened[11] = m_bottom.z(); |
69 } | 70 } |
70 | 71 |
71 } // namespace cc | 72 } // namespace cc |
OLD | NEW |