WebKit merge 128969:128981
[chromium-blink-merge.git] / cc / CCLayerQuad.cpp
blobb51e425feb5bc8ea5878c9919f4840d3c2df63ce
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
3 // found in the LICENSE file.
6 #include "config.h"
8 #if USE(ACCELERATED_COMPOSITING)
10 #include "CCLayerQuad.h"
12 namespace cc {
14 CCLayerQuad::Edge::Edge(const FloatPoint& p, const FloatPoint& q)
16 ASSERT(p != q);
18 FloatPoint tangent(p.y() - q.y(), q.x() - p.x());
19 float cross2 = p.x() * q.y() - q.x() * p.y();
21 set(tangent.x(), tangent.y(), cross2);
22 scale(1.0f / tangent.length());
25 CCLayerQuad::CCLayerQuad(const FloatQuad& quad)
27 // Create edges.
28 m_left = Edge(quad.p4(), quad.p1());
29 m_right = Edge(quad.p2(), quad.p3());
30 m_top = Edge(quad.p1(), quad.p2());
31 m_bottom = Edge(quad.p3(), quad.p4());
33 float sign = quad.isCounterclockwise() ? -1 : 1;
34 m_left.scale(sign);
35 m_right.scale(sign);
36 m_top.scale(sign);
37 m_bottom.scale(sign);
40 FloatQuad CCLayerQuad::floatQuad() const
42 return FloatQuad(m_left.intersect(m_top),
43 m_top.intersect(m_right),
44 m_right.intersect(m_bottom),
45 m_bottom.intersect(m_left));
48 void CCLayerQuad::toFloatArray(float flattened[12]) const
50 flattened[0] = m_left.x();
51 flattened[1] = m_left.y();
52 flattened[2] = m_left.z();
53 flattened[3] = m_top.x();
54 flattened[4] = m_top.y();
55 flattened[5] = m_top.z();
56 flattened[6] = m_right.x();
57 flattened[7] = m_right.y();
58 flattened[8] = m_right.z();
59 flattened[9] = m_bottom.x();
60 flattened[10] = m_bottom.y();
61 flattened[11] = m_bottom.z();
64 } // namespace cc
66 #endif // USE(ACCELERATED_COMPOSITING)