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