OLD | NEW |
1 // Copyright 2011 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 | 4 |
5 #include "cc/trees/layer_sorter.h" | 5 #include "cc/trees/layer_sorter.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <deque> | 8 #include <deque> |
9 #include <limits> | 9 #include <limits> |
10 #include <vector> | 10 #include <vector> |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 181 |
182 LayerShape::LayerShape() {} | 182 LayerShape::LayerShape() {} |
183 | 183 |
184 LayerShape::LayerShape(float width, | 184 LayerShape::LayerShape(float width, |
185 float height, | 185 float height, |
186 const gfx::Transform& draw_transform) { | 186 const gfx::Transform& draw_transform) { |
187 gfx::QuadF layer_quad(gfx::RectF(0.f, 0.f, width, height)); | 187 gfx::QuadF layer_quad(gfx::RectF(0.f, 0.f, width, height)); |
188 | 188 |
189 // Compute the projection of the layer quad onto the z = 0 plane. | 189 // Compute the projection of the layer quad onto the z = 0 plane. |
190 | 190 |
191 gfx::PointF clippedQuad[8]; | 191 gfx::PointF clipped_quad[8]; |
192 int num_vertices_in_clipped_quad; | 192 int num_vertices_in_clipped_quad; |
193 MathUtil::MapClippedQuad(draw_transform, | 193 MathUtil::MapClippedQuad(draw_transform, |
194 layer_quad, | 194 layer_quad, |
195 clippedQuad, | 195 clipped_quad, |
196 num_vertices_in_clipped_quad); | 196 num_vertices_in_clipped_quad); |
197 | 197 |
198 if (num_vertices_in_clipped_quad < 3) { | 198 if (num_vertices_in_clipped_quad < 3) { |
199 projected_bounds = gfx::RectF(); | 199 projected_bounds = gfx::RectF(); |
200 return; | 200 return; |
201 } | 201 } |
202 | 202 |
203 projected_bounds = | 203 projected_bounds = |
204 MathUtil::ComputeEnclosingRectOfVertices(clippedQuad, | 204 MathUtil::ComputeEnclosingRectOfVertices(clipped_quad, |
205 num_vertices_in_clipped_quad); | 205 num_vertices_in_clipped_quad); |
206 | 206 |
207 // NOTE: it will require very significant refactoring and overhead to deal | 207 // NOTE: it will require very significant refactoring and overhead to deal |
208 // with generalized polygons or multiple quads per layer here. For the sake of | 208 // with generalized polygons or multiple quads per layer here. For the sake of |
209 // layer sorting it is equally correct to take a subsection of the polygon | 209 // layer sorting it is equally correct to take a subsection of the polygon |
210 // that can be made into a quad. This will only be incorrect in the case of | 210 // that can be made into a quad. This will only be incorrect in the case of |
211 // intersecting layers, which are not supported yet anyway. | 211 // intersecting layers, which are not supported yet anyway. |
212 projected_quad.set_p1(clippedQuad[0]); | 212 projected_quad.set_p1(clipped_quad[0]); |
213 projected_quad.set_p2(clippedQuad[1]); | 213 projected_quad.set_p2(clipped_quad[1]); |
214 projected_quad.set_p3(clippedQuad[2]); | 214 projected_quad.set_p3(clipped_quad[2]); |
215 if (num_vertices_in_clipped_quad >= 4) { | 215 if (num_vertices_in_clipped_quad >= 4) { |
216 projected_quad.set_p4(clippedQuad[3]); | 216 projected_quad.set_p4(clipped_quad[3]); |
217 } else { | 217 } else { |
218 // This will be a degenerate quad that is actually a triangle. | 218 // This will be a degenerate quad that is actually a triangle. |
219 projected_quad.set_p4(clippedQuad[2]); | 219 projected_quad.set_p4(clipped_quad[2]); |
220 } | 220 } |
221 | 221 |
222 // Compute the normal of the layer's plane. | 222 // Compute the normal of the layer's plane. |
223 bool clipped = false; | 223 bool clipped = false; |
224 gfx::Point3F c1 = | 224 gfx::Point3F c1 = |
225 MathUtil::MapPoint(draw_transform, gfx::Point3F(0.f, 0.f, 0.f), &clipped); | 225 MathUtil::MapPoint(draw_transform, gfx::Point3F(0.f, 0.f, 0.f), &clipped); |
226 gfx::Point3F c2 = | 226 gfx::Point3F c2 = |
227 MathUtil::MapPoint(draw_transform, gfx::Point3F(0.f, 1.f, 0.f), &clipped); | 227 MathUtil::MapPoint(draw_transform, gfx::Point3F(0.f, 1.f, 0.f), &clipped); |
228 gfx::Point3F c3 = | 228 gfx::Point3F c3 = |
229 MathUtil::MapPoint(draw_transform, gfx::Point3F(1.f, 0.f, 0.f), &clipped); | 229 MathUtil::MapPoint(draw_transform, gfx::Point3F(1.f, 0.f, 0.f), &clipped); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 291 |
292 max_z = std::max(max_z, node.shape.transform_origin.z()); | 292 max_z = std::max(max_z, node.shape.transform_origin.z()); |
293 min_z = std::min(min_z, node.shape.transform_origin.z()); | 293 min_z = std::min(min_z, node.shape.transform_origin.z()); |
294 } | 294 } |
295 | 295 |
296 z_range_ = fabsf(max_z - min_z); | 296 z_range_ = fabsf(max_z - min_z); |
297 } | 297 } |
298 | 298 |
299 void LayerSorter::CreateGraphEdges() { | 299 void LayerSorter::CreateGraphEdges() { |
300 DVLOG(2) << "Edges:"; | 300 DVLOG(2) << "Edges:"; |
301 // Fraction of the total zRange below which z differences | 301 // Fraction of the total z_range below which z differences |
302 // are not considered reliable. | 302 // are not considered reliable. |
303 const float z_threshold_factor = 0.01f; | 303 const float z_threshold_factor = 0.01f; |
304 float z_threshold = z_range_ * z_threshold_factor; | 304 float z_threshold = z_range_ * z_threshold_factor; |
305 | 305 |
306 for (size_t na = 0; na < nodes_.size(); na++) { | 306 for (size_t na = 0; na < nodes_.size(); na++) { |
307 GraphNode& node_a = nodes_[na]; | 307 GraphNode& node_a = nodes_[na]; |
308 if (!node_a.layer->DrawsContent() && !node_a.layer->render_surface()) | 308 if (!node_a.layer->DrawsContent() && !node_a.layer->render_surface()) |
309 continue; | 309 continue; |
310 for (size_t nb = na + 1; nb < nodes_.size(); nb++) { | 310 for (size_t nb = na + 1; nb < nodes_.size(); nb++) { |
311 GraphNode& node_b = nodes_[nb]; | 311 GraphNode& node_b = nodes_[nb]; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 *it = sorted_list[count++]->layer; | 459 *it = sorted_list[count++]->layer; |
460 | 460 |
461 DVLOG(2) << "Sorting end ----"; | 461 DVLOG(2) << "Sorting end ----"; |
462 | 462 |
463 nodes_.clear(); | 463 nodes_.clear(); |
464 edges_.clear(); | 464 edges_.clear(); |
465 active_edges_.clear(); | 465 active_edges_.clear(); |
466 } | 466 } |
467 | 467 |
468 } // namespace cc | 468 } // namespace cc |
OLD | NEW |