OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CC_QUADS_DRAW_POLYGON_H_ | 5 #ifndef CC_QUADS_DRAW_POLYGON_H_ |
6 #define CC_QUADS_DRAW_POLYGON_H_ | 6 #define CC_QUADS_DRAW_POLYGON_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
11 #include "cc/output/bsp_compare_result.h" | 11 #include "cc/output/bsp_compare_result.h" |
12 #include "ui/gfx/geometry/point3_f.h" | 12 #include "ui/gfx/geometry/point3_f.h" |
13 #include "ui/gfx/geometry/quad_f.h" | 13 #include "ui/gfx/geometry/quad_f.h" |
14 #include "ui/gfx/geometry/rect_f.h" | 14 #include "ui/gfx/geometry/rect_f.h" |
15 #include "ui/gfx/geometry/vector3d_f.h" | 15 #include "ui/gfx/geometry/vector3d_f.h" |
16 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 | 19 |
20 class DrawQuad; | 20 class DrawQuad; |
21 | 21 |
22 class CC_EXPORT DrawPolygon { | 22 class CC_EXPORT DrawPolygon { |
23 public: | 23 public: |
24 DrawPolygon(); | 24 DrawPolygon(); |
25 ~DrawPolygon(); | 25 ~DrawPolygon(); |
26 | 26 |
27 DrawPolygon(DrawQuad* original_ref, | 27 DrawPolygon(const DrawQuad* original_ref, |
28 const std::vector<gfx::Point3F>& in_points, | 28 const std::vector<gfx::Point3F>& in_points, |
29 const gfx::Vector3dF& normal, | 29 const gfx::Vector3dF& normal, |
30 int draw_order_index = 0); | 30 int draw_order_index = 0); |
31 DrawPolygon(DrawQuad* original_ref, | 31 DrawPolygon(const DrawQuad* original_ref, |
32 const gfx::RectF& visible_content_rect, | 32 const gfx::RectF& visible_content_rect, |
33 const gfx::Transform& transform, | 33 const gfx::Transform& transform, |
34 int draw_order_index = 0); | 34 int draw_order_index = 0); |
35 | 35 |
36 // Split takes this DrawPolygon and splits it into two pieces that are on | 36 // Split takes this DrawPolygon and splits it into two pieces that are on |
37 // either side of |splitter|. Any edges of this polygon that cross the plane | 37 // either side of |splitter|. Any edges of this polygon that cross the plane |
38 // of |splitter| will have an intersection point that is shared by both | 38 // of |splitter| will have an intersection point that is shared by both |
39 // polygons on either side. | 39 // polygons on either side. |
40 // Split will only return true if it determines that we got back 2 | 40 // Split will only return true if it determines that we got back 2 |
41 // intersection points. Only when it returns true will front and back both be | 41 // intersection points. Only when it returns true will front and back both be |
42 // valid new polygons that are on opposite sides of the splitting plane. | 42 // valid new polygons that are on opposite sides of the splitting plane. |
43 bool Split(const DrawPolygon& splitter, | 43 bool Split(const DrawPolygon& splitter, |
44 scoped_ptr<DrawPolygon>* front, | 44 scoped_ptr<DrawPolygon>* front, |
45 scoped_ptr<DrawPolygon>* back); | 45 scoped_ptr<DrawPolygon>* back); |
46 float SignedPointDistance(const gfx::Point3F& point) const; | 46 float SignedPointDistance(const gfx::Point3F& point) const; |
47 // Checks polygon a against polygon b and returns which side it lies on, or | 47 // Checks polygon a against polygon b and returns which side it lies on, or |
48 // whether it crosses (necessitating a split in the BSP tree). | 48 // whether it crosses (necessitating a split in the BSP tree). |
49 static BspCompareResult SideCompare(const DrawPolygon& a, | 49 static BspCompareResult SideCompare(const DrawPolygon& a, |
50 const DrawPolygon& b); | 50 const DrawPolygon& b); |
51 void ToQuads2D(std::vector<gfx::QuadF>* quads) const; | 51 void ToQuads2D(std::vector<gfx::QuadF>* quads) const; |
52 void TransformToScreenSpace(const gfx::Transform& transform); | 52 void TransformToScreenSpace(const gfx::Transform& transform); |
53 void TransformToLayerSpace(const gfx::Transform& inverse_transform); | 53 void TransformToLayerSpace(const gfx::Transform& inverse_transform); |
54 | 54 |
55 const std::vector<gfx::Point3F>& points() const { return points_; } | 55 const std::vector<gfx::Point3F>& points() const { return points_; } |
56 const gfx::Vector3dF& normal() const { return normal_; } | 56 const gfx::Vector3dF& normal() const { return normal_; } |
57 const DrawQuad* original_ref() const { return original_ref_; } | 57 const DrawQuad* original_ref() const { return original_ref_; } |
58 int order_index() const { return order_index_; } | 58 int order_index() const { return order_index_; } |
59 | 59 bool is_split() const { return is_split_; } |
60 scoped_ptr<DrawPolygon> CreateCopy(); | 60 scoped_ptr<DrawPolygon> CreateCopy(); |
61 | 61 |
62 static gfx::Vector3dF default_normal; | |
63 | |
64 private: | 62 private: |
65 void ApplyTransform(const gfx::Transform& transform); | 63 void ApplyTransform(const gfx::Transform& transform); |
66 void ApplyTransformToNormal(const gfx::Transform& transform); | 64 void ApplyTransformToNormal(const gfx::Transform& transform); |
67 | 65 |
68 std::vector<gfx::Point3F> points_; | 66 std::vector<gfx::Point3F> points_; |
69 // Normalized, necessitated by distance calculations and tests of coplanarity. | 67 // Normalized, necessitated by distance calculations and tests of coplanarity. |
70 gfx::Vector3dF normal_; | 68 gfx::Vector3dF normal_; |
71 // This is an index that can be used to test whether a quad comes before or | 69 // This is an index that can be used to test whether a quad comes before or |
72 // after another in document order, useful for tie-breaking when it comes | 70 // after another in document order, useful for tie-breaking when it comes |
73 // to coplanar surfaces. | 71 // to coplanar surfaces. |
74 int order_index_; | 72 int order_index_; |
75 // The pointer to the original quad, which gives us all the drawing info | 73 // The pointer to the original quad, which gives us all the drawing info |
76 // we need. | 74 // we need. |
77 // This DrawQuad is owned by the caller and its lifetime must be preserved | 75 // This DrawQuad is owned by the caller and its lifetime must be preserved |
78 // as long as this DrawPolygon is alive. | 76 // as long as this DrawPolygon is alive. |
79 DrawQuad* original_ref_; | 77 const DrawQuad* original_ref_; |
| 78 bool is_split_; |
80 }; | 79 }; |
81 | 80 |
82 } // namespace cc | 81 } // namespace cc |
83 | 82 |
84 #endif // CC_QUADS_DRAW_POLYGON_H_ | 83 #endif // CC_QUADS_DRAW_POLYGON_H_ |
OLD | NEW |