OLD | NEW |
1 // Copyright 2012 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 |
| 5 |
| 6 #ifndef CCLayerQuad_h |
| 7 #define CCLayerQuad_h |
| 8 |
| 9 #if USE(ACCELERATED_COMPOSITING) |
| 10 |
| 11 #include "FloatPoint3D.h" |
| 12 #include "FloatQuad.h" |
| 13 |
| 14 static const float kAntiAliasingInflateDistance = 0.5f; |
| 15 |
| 16 namespace cc { |
| 17 |
| 18 class CCLayerQuad { |
| 19 public: |
| 20 class Edge { |
| 21 public: |
| 22 Edge() |
| 23 : m_x(0) |
| 24 , m_y(0) |
| 25 , m_z(0) |
| 26 { |
| 27 } |
| 28 Edge(const FloatPoint&, const FloatPoint&); |
| 29 |
| 30 float x() const { return m_x; } |
| 31 float y() const { return m_y; } |
| 32 float z() const { return m_z; } |
| 33 |
| 34 void setX(float x) { m_x = x; } |
| 35 void setY(float y) { m_y = y; } |
| 36 void setZ(float z) { m_z = z; } |
| 37 void set(float x, float y, float z) |
| 38 { |
| 39 m_x = x; |
| 40 m_y = y; |
| 41 m_z = z; |
| 42 } |
| 43 |
| 44 void moveX(float dx) { m_x += dx; } |
| 45 void moveY(float dy) { m_y += dy; } |
| 46 void moveZ(float dz) { m_z += dz; } |
| 47 void move(float dx, float dy, float dz) |
| 48 { |
| 49 m_x += dx; |
| 50 m_y += dy; |
| 51 m_z += dz; |
| 52 } |
| 53 |
| 54 void scaleX(float sx) { m_x *= sx; } |
| 55 void scaleY(float sy) { m_y *= sy; } |
| 56 void scaleZ(float sz) { m_z *= sz; } |
| 57 void scale(float sx, float sy, float sz) |
| 58 { |
| 59 m_x *= sx; |
| 60 m_y *= sy; |
| 61 m_z *= sz; |
| 62 } |
| 63 void scale(float s) { scale(s, s, s); } |
| 64 |
| 65 FloatPoint intersect(const Edge& e) const |
| 66 { |
| 67 return FloatPoint( |
| 68 (y() * e.z() - e.y() * z()) / (x() * e.y() - e.x() * y()), |
| 69 (x() * e.z() - e.x() * z()) / (e.x() * y() - x() * e.y())); |
| 70 } |
| 71 |
| 72 private: |
| 73 float m_x; |
| 74 float m_y; |
| 75 float m_z; |
| 76 }; |
| 77 |
| 78 CCLayerQuad(const Edge& left, const Edge& top, const Edge& right, const Edge
& bottom); |
| 79 CCLayerQuad(const FloatQuad&); |
| 80 |
| 81 Edge left() const { return m_left; } |
| 82 Edge top() const { return m_top; } |
| 83 Edge right() const { return m_right; } |
| 84 Edge bottom() const { return m_bottom; } |
| 85 |
| 86 void inflateX(float dx) { m_left.moveZ(dx); m_right.moveZ(dx); } |
| 87 void inflateY(float dy) { m_top.moveZ(dy); m_bottom.moveZ(dy); } |
| 88 void inflate(float d) { inflateX(d); inflateY(d); } |
| 89 void inflateAntiAliasingDistance() { inflate(kAntiAliasingInflateDistance);
} |
| 90 |
| 91 FloatQuad floatQuad() const; |
| 92 |
| 93 void toFloatArray(float[12]) const; |
| 94 |
| 95 private: |
| 96 Edge m_left; |
| 97 Edge m_top; |
| 98 Edge m_right; |
| 99 Edge m_bottom; |
| 100 }; |
| 101 |
| 102 } |
| 103 |
| 104 #endif // USE(ACCELERATED_COMPOSITING) |
| 105 |
| 106 #endif |
OLD | NEW |