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 #include "cc/quads/draw_polygon.h" | 5 #include "cc/quads/draw_polygon.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 transform, send_quad, points, &num_vertices_in_clipped_quad); | 71 transform, send_quad, points, &num_vertices_in_clipped_quad); |
72 for (int i = 0; i < num_vertices_in_clipped_quad; i++) { | 72 for (int i = 0; i < num_vertices_in_clipped_quad; i++) { |
73 points_.push_back(points[i]); | 73 points_.push_back(points[i]); |
74 } | 74 } |
75 ConstructNormal(); | 75 ConstructNormal(); |
76 } | 76 } |
77 | 77 |
78 DrawPolygon::~DrawPolygon() { | 78 DrawPolygon::~DrawPolygon() { |
79 } | 79 } |
80 | 80 |
81 scoped_ptr<DrawPolygon> DrawPolygon::CreateCopy() { | 81 std::unique_ptr<DrawPolygon> DrawPolygon::CreateCopy() { |
82 scoped_ptr<DrawPolygon> new_polygon(new DrawPolygon()); | 82 std::unique_ptr<DrawPolygon> new_polygon(new DrawPolygon()); |
83 new_polygon->order_index_ = order_index_; | 83 new_polygon->order_index_ = order_index_; |
84 new_polygon->original_ref_ = original_ref_; | 84 new_polygon->original_ref_ = original_ref_; |
85 new_polygon->points_.reserve(points_.size()); | 85 new_polygon->points_.reserve(points_.size()); |
86 new_polygon->points_ = points_; | 86 new_polygon->points_ = points_; |
87 new_polygon->normal_.set_x(normal_.x()); | 87 new_polygon->normal_.set_x(normal_.x()); |
88 new_polygon->normal_.set_y(normal_.y()); | 88 new_polygon->normal_.set_y(normal_.y()); |
89 new_polygon->normal_.set_z(normal_.z()); | 89 new_polygon->normal_.set_z(normal_.z()); |
90 return new_polygon; | 90 return new_polygon; |
91 } | 91 } |
92 | 92 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 // inverse transformation back to the polygon to move it back into layer space | 250 // inverse transformation back to the polygon to move it back into layer space |
251 // but we can ignore the costly process of applying the inverse to the normal | 251 // but we can ignore the costly process of applying the inverse to the normal |
252 // since we know the normal will just reset to its original state. | 252 // since we know the normal will just reset to its original state. |
253 void DrawPolygon::TransformToLayerSpace( | 253 void DrawPolygon::TransformToLayerSpace( |
254 const gfx::Transform& inverse_transform) { | 254 const gfx::Transform& inverse_transform) { |
255 ApplyTransform(inverse_transform); | 255 ApplyTransform(inverse_transform); |
256 normal_ = gfx::Vector3dF(0.0f, 0.0f, -1.0f); | 256 normal_ = gfx::Vector3dF(0.0f, 0.0f, -1.0f); |
257 } | 257 } |
258 | 258 |
259 bool DrawPolygon::Split(const DrawPolygon& splitter, | 259 bool DrawPolygon::Split(const DrawPolygon& splitter, |
260 scoped_ptr<DrawPolygon>* front, | 260 std::unique_ptr<DrawPolygon>* front, |
261 scoped_ptr<DrawPolygon>* back) { | 261 std::unique_ptr<DrawPolygon>* back) { |
262 gfx::Point3F intersections[2]; | 262 gfx::Point3F intersections[2]; |
263 std::vector<gfx::Point3F> out_points[2]; | 263 std::vector<gfx::Point3F> out_points[2]; |
264 // vertex_before stores the index of the vertex before its matching | 264 // vertex_before stores the index of the vertex before its matching |
265 // intersection. | 265 // intersection. |
266 // i.e. vertex_before[0] stores the vertex we saw before we crossed the plane | 266 // i.e. vertex_before[0] stores the vertex we saw before we crossed the plane |
267 // which resulted in the line/plane intersection giving us intersections[0]. | 267 // which resulted in the line/plane intersection giving us intersections[0]. |
268 size_t vertex_before[2]; | 268 size_t vertex_before[2]; |
269 size_t points_size = points_.size(); | 269 size_t points_size = points_.size(); |
270 size_t current_intersection = 0; | 270 size_t current_intersection = 0; |
271 | 271 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 out_points[1].push_back(intersections[1]); | 311 out_points[1].push_back(intersections[1]); |
312 size_t index = start2; | 312 size_t index = start2; |
313 for (size_t i = 0; i < points_remaining; i++) { | 313 for (size_t i = 0; i < points_remaining; i++) { |
314 out_points[1].push_back(points_[index % points_size]); | 314 out_points[1].push_back(points_[index % points_size]); |
315 ++index; | 315 ++index; |
316 } | 316 } |
317 out_points[1].push_back(intersections[0]); | 317 out_points[1].push_back(intersections[0]); |
318 | 318 |
319 // Give both polygons the original splitting polygon's ID, so that they'll | 319 // Give both polygons the original splitting polygon's ID, so that they'll |
320 // still be sorted properly in co-planar instances. | 320 // still be sorted properly in co-planar instances. |
321 scoped_ptr<DrawPolygon> poly1( | 321 std::unique_ptr<DrawPolygon> poly1( |
322 new DrawPolygon(original_ref_, out_points[0], normal_, order_index_)); | 322 new DrawPolygon(original_ref_, out_points[0], normal_, order_index_)); |
323 scoped_ptr<DrawPolygon> poly2( | 323 std::unique_ptr<DrawPolygon> poly2( |
324 new DrawPolygon(original_ref_, out_points[1], normal_, order_index_)); | 324 new DrawPolygon(original_ref_, out_points[1], normal_, order_index_)); |
325 | 325 |
326 DCHECK_GE(poly1->points().size(), 3u); | 326 DCHECK_GE(poly1->points().size(), 3u); |
327 DCHECK_GE(poly2->points().size(), 3u); | 327 DCHECK_GE(poly2->points().size(), 3u); |
328 | 328 |
329 if (SideCompare(*poly1, splitter) == BSP_FRONT) { | 329 if (SideCompare(*poly1, splitter) == BSP_FRONT) { |
330 *front = std::move(poly1); | 330 *front = std::move(poly1); |
331 *back = std::move(poly2); | 331 *back = std::move(poly2); |
332 } else { | 332 } else { |
333 *front = std::move(poly2); | 333 *front = std::move(poly2); |
(...skipping 29 matching lines...) Expand all Loading... |
363 quads->push_back( | 363 quads->push_back( |
364 gfx::QuadF(first, | 364 gfx::QuadF(first, |
365 gfx::PointF(points_[offset].x(), points_[offset].y()), | 365 gfx::PointF(points_[offset].x(), points_[offset].y()), |
366 gfx::PointF(points_[op1].x(), points_[op1].y()), | 366 gfx::PointF(points_[op1].x(), points_[op1].y()), |
367 gfx::PointF(points_[op2].x(), points_[op2].y()))); | 367 gfx::PointF(points_[op2].x(), points_[op2].y()))); |
368 offset = op2; | 368 offset = op2; |
369 } | 369 } |
370 } | 370 } |
371 | 371 |
372 } // namespace cc | 372 } // namespace cc |
OLD | NEW |