| 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_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 // visibility for themselves. | 363 // visibility for themselves. |
| 364 return false; | 364 return false; |
| 365 } | 365 } |
| 366 | 366 |
| 367 template <typename LayerType> | 367 template <typename LayerType> |
| 368 static inline bool LayerClipsSubtree(LayerType* layer) { | 368 static inline bool LayerClipsSubtree(LayerType* layer) { |
| 369 return layer->masks_to_bounds() || layer->mask_layer(); | 369 return layer->masks_to_bounds() || layer->mask_layer(); |
| 370 } | 370 } |
| 371 | 371 |
| 372 template <typename LayerType> | 372 template <typename LayerType> |
| 373 static gfx::Rect CalculateVisibleContentRect( | 373 static gfx::Rect CalculateVisibleLayerRect( |
| 374 LayerType* layer, | 374 LayerType* layer, |
| 375 const gfx::Rect& clip_rect_of_target_surface_in_target_space, | 375 const gfx::Rect& clip_rect_of_target_surface_in_target_space, |
| 376 const gfx::Rect& layer_rect_in_target_space) { | 376 const gfx::Rect& layer_rect_in_target_space) { |
| 377 DCHECK(layer->render_target()); | 377 DCHECK(layer->render_target()); |
| 378 | 378 |
| 379 // Nothing is visible if the layer bounds are empty. | 379 // Nothing is visible if the layer bounds are empty. |
| 380 if (!layer->DrawsContent() || layer->bounds().IsEmpty() || | 380 if (!layer->DrawsContent() || layer->bounds().IsEmpty() || |
| 381 layer->drawable_content_rect().IsEmpty()) | 381 layer->drawable_content_rect().IsEmpty()) |
| 382 return gfx::Rect(); | 382 return gfx::Rect(); |
| 383 | 383 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 // - is not drawn due to it or one of its ancestors being hidden (or having | 425 // - is not drawn due to it or one of its ancestors being hidden (or having |
| 426 // no copy requests). | 426 // no copy requests). |
| 427 // - does not draw content. | 427 // - does not draw content. |
| 428 // - is transparent. | 428 // - is transparent. |
| 429 // - has empty bounds | 429 // - has empty bounds |
| 430 // - the layer is not double-sided, but its back face is visible. | 430 // - the layer is not double-sided, but its back face is visible. |
| 431 // | 431 // |
| 432 // Some additional conditions need to be computed at a later point after the | 432 // Some additional conditions need to be computed at a later point after the |
| 433 // recursion is finished. | 433 // recursion is finished. |
| 434 // - the intersection of render_surface content and layer clip_rect is empty | 434 // - the intersection of render_surface content and layer clip_rect is empty |
| 435 // - the visible_content_rect is empty | 435 // - the visible_layer_rect is empty |
| 436 // | 436 // |
| 437 // Note, if the layer should not have been drawn due to being fully | 437 // Note, if the layer should not have been drawn due to being fully |
| 438 // transparent, we would have skipped the entire subtree and never made it | 438 // transparent, we would have skipped the entire subtree and never made it |
| 439 // into this function, so it is safe to omit this check here. | 439 // into this function, so it is safe to omit this check here. |
| 440 | 440 |
| 441 if (!layer_is_drawn) | 441 if (!layer_is_drawn) |
| 442 return true; | 442 return true; |
| 443 | 443 |
| 444 if (!layer->DrawsContent() || layer->bounds().IsEmpty()) | 444 if (!layer->DrawsContent() || layer->bounds().IsEmpty()) |
| 445 return true; | 445 return true; |
| (...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1910 render_surface->draw_transform()); | 1910 render_surface->draw_transform()); |
| 1911 | 1911 |
| 1912 // A render surface inherently acts as a flattening point for the content of | 1912 // A render surface inherently acts as a flattening point for the content of |
| 1913 // its descendants. | 1913 // its descendants. |
| 1914 data_for_children.full_hierarchy_matrix.FlattenTo2d(); | 1914 data_for_children.full_hierarchy_matrix.FlattenTo2d(); |
| 1915 | 1915 |
| 1916 if (layer->mask_layer()) { | 1916 if (layer->mask_layer()) { |
| 1917 DrawProperties<LayerType>& mask_layer_draw_properties = | 1917 DrawProperties<LayerType>& mask_layer_draw_properties = |
| 1918 layer->mask_layer()->draw_properties(); | 1918 layer->mask_layer()->draw_properties(); |
| 1919 mask_layer_draw_properties.render_target = layer; | 1919 mask_layer_draw_properties.render_target = layer; |
| 1920 mask_layer_draw_properties.visible_content_rect = | 1920 mask_layer_draw_properties.visible_layer_rect = |
| 1921 gfx::Rect(layer->bounds()); | 1921 gfx::Rect(layer->bounds()); |
| 1922 } | 1922 } |
| 1923 | 1923 |
| 1924 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { | 1924 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { |
| 1925 DrawProperties<LayerType>& replica_mask_draw_properties = | 1925 DrawProperties<LayerType>& replica_mask_draw_properties = |
| 1926 layer->replica_layer()->mask_layer()->draw_properties(); | 1926 layer->replica_layer()->mask_layer()->draw_properties(); |
| 1927 replica_mask_draw_properties.render_target = layer; | 1927 replica_mask_draw_properties.render_target = layer; |
| 1928 replica_mask_draw_properties.visible_content_rect = | 1928 replica_mask_draw_properties.visible_layer_rect = |
| 1929 gfx::Rect(layer->bounds()); | 1929 gfx::Rect(layer->bounds()); |
| 1930 } | 1930 } |
| 1931 | 1931 |
| 1932 // Ignore occlusion from outside the surface when surface contents need to | 1932 // Ignore occlusion from outside the surface when surface contents need to |
| 1933 // be fully drawn. Layers with copy-request need to be complete. | 1933 // be fully drawn. Layers with copy-request need to be complete. |
| 1934 // We could be smarter about layers with replica and exclude regions | 1934 // We could be smarter about layers with replica and exclude regions |
| 1935 // where both layer and the replica are occluded, but this seems like an | 1935 // where both layer and the replica are occluded, but this seems like an |
| 1936 // overkill. The same is true for layers with filters that move pixels. | 1936 // overkill. The same is true for layers with filters that move pixels. |
| 1937 // TODO(senorblanco): make this smarter for the SkImageFilter case (check | 1937 // TODO(senorblanco): make this smarter for the SkImageFilter case (check |
| 1938 // for pixel-moving filters) | 1938 // for pixel-moving filters) |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2215 if (layer_or_ancestor_clips_descendants) { | 2215 if (layer_or_ancestor_clips_descendants) { |
| 2216 layer_draw_properties.drawable_content_rect.Intersect( | 2216 layer_draw_properties.drawable_content_rect.Intersect( |
| 2217 clip_rect_in_target_space); | 2217 clip_rect_in_target_space); |
| 2218 } | 2218 } |
| 2219 if (layer->DrawsContent()) { | 2219 if (layer->DrawsContent()) { |
| 2220 local_drawable_content_rect_of_subtree.Union( | 2220 local_drawable_content_rect_of_subtree.Union( |
| 2221 layer_draw_properties.drawable_content_rect); | 2221 layer_draw_properties.drawable_content_rect); |
| 2222 } | 2222 } |
| 2223 | 2223 |
| 2224 // Compute the layer's visible content rect (the rect is in content space). | 2224 // Compute the layer's visible content rect (the rect is in content space). |
| 2225 layer_draw_properties.visible_content_rect = CalculateVisibleContentRect( | 2225 layer_draw_properties.visible_layer_rect = CalculateVisibleLayerRect( |
| 2226 layer, clip_rect_of_target_surface_in_target_space, rect_in_target_space); | 2226 layer, clip_rect_of_target_surface_in_target_space, rect_in_target_space); |
| 2227 | 2227 |
| 2228 // Compute the remaining properties for the render surface, if the layer has | 2228 // Compute the remaining properties for the render surface, if the layer has |
| 2229 // one. | 2229 // one. |
| 2230 if (IsRootLayer(layer)) { | 2230 if (IsRootLayer(layer)) { |
| 2231 // The root layer's surface's content_rect is always the entire viewport. | 2231 // The root layer's surface's content_rect is always the entire viewport. |
| 2232 DCHECK(render_to_separate_surface); | 2232 DCHECK(render_to_separate_surface); |
| 2233 layer->render_surface()->SetContentRect( | 2233 layer->render_surface()->SetContentRect( |
| 2234 ancestor_clip_rect_in_target_space); | 2234 ancestor_clip_rect_in_target_space); |
| 2235 } else if (render_to_separate_surface) { | 2235 } else if (render_to_separate_surface) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2474 } | 2474 } |
| 2475 } | 2475 } |
| 2476 | 2476 |
| 2477 return true; | 2477 return true; |
| 2478 } | 2478 } |
| 2479 | 2479 |
| 2480 template <typename LayerType> | 2480 template <typename LayerType> |
| 2481 void VerifyPropertyTreeValuesForLayer(LayerType* current_layer, | 2481 void VerifyPropertyTreeValuesForLayer(LayerType* current_layer, |
| 2482 PropertyTrees* property_trees) { | 2482 PropertyTrees* property_trees) { |
| 2483 const bool visible_rects_match = | 2483 const bool visible_rects_match = |
| 2484 ApproximatelyEqual(current_layer->visible_content_rect(), | 2484 ApproximatelyEqual(current_layer->visible_layer_rect(), |
| 2485 current_layer->visible_rect_from_property_trees()); | 2485 current_layer->visible_rect_from_property_trees()); |
| 2486 CHECK(visible_rects_match) | 2486 CHECK(visible_rects_match) |
| 2487 << "expected: " << current_layer->visible_content_rect().ToString() | 2487 << "expected: " << current_layer->visible_layer_rect().ToString() |
| 2488 << " actual: " | 2488 << " actual: " |
| 2489 << current_layer->visible_rect_from_property_trees().ToString(); | 2489 << current_layer->visible_rect_from_property_trees().ToString(); |
| 2490 | 2490 |
| 2491 const bool draw_transforms_match = | 2491 const bool draw_transforms_match = |
| 2492 ApproximatelyEqual(current_layer->draw_transform(), | 2492 ApproximatelyEqual(current_layer->draw_transform(), |
| 2493 DrawTransformFromPropertyTrees( | 2493 DrawTransformFromPropertyTrees( |
| 2494 current_layer, property_trees->transform_tree)); | 2494 current_layer, property_trees->transform_tree)); |
| 2495 CHECK(draw_transforms_match) | 2495 CHECK(draw_transforms_match) |
| 2496 << "expected: " << current_layer->draw_transform().ToString() | 2496 << "expected: " << current_layer->draw_transform().ToString() |
| 2497 << " actual: " | 2497 << " actual: " |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2643 | 2643 |
| 2644 PropertyTrees* GetPropertyTrees(Layer* layer) { | 2644 PropertyTrees* GetPropertyTrees(Layer* layer) { |
| 2645 return layer->layer_tree_host()->property_trees(); | 2645 return layer->layer_tree_host()->property_trees(); |
| 2646 } | 2646 } |
| 2647 | 2647 |
| 2648 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { | 2648 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { |
| 2649 return layer->layer_tree_impl()->property_trees(); | 2649 return layer->layer_tree_impl()->property_trees(); |
| 2650 } | 2650 } |
| 2651 | 2651 |
| 2652 } // namespace cc | 2652 } // namespace cc |
| OLD | NEW |