Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: cc/trees/layer_tree_host_common.cc

Issue 465853004: Moving RenderSurface creation outside of CalcDrawProps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated unit tests Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "cc/base/math_util.h" 10 #include "cc/base/math_util.h"
11 #include "cc/layers/heads_up_display_layer_impl.h" 11 #include "cc/layers/heads_up_display_layer_impl.h"
12 #include "cc/layers/layer.h" 12 #include "cc/layers/layer.h"
13 #include "cc/layers/layer_impl.h" 13 #include "cc/layers/layer_impl.h"
14 #include "cc/layers/layer_iterator.h" 14 #include "cc/layers/layer_iterator.h"
15 #include "cc/layers/render_surface.h" 15 #include "cc/layers/render_surface.h"
16 #include "cc/layers/render_surface_impl.h" 16 #include "cc/layers/render_surface_impl.h"
17 #include "cc/test/fake_layer_tree_host_impl.h"
17 #include "cc/trees/layer_sorter.h" 18 #include "cc/trees/layer_sorter.h"
19 #include "cc/trees/layer_tree_host.h"
18 #include "cc/trees/layer_tree_impl.h" 20 #include "cc/trees/layer_tree_impl.h"
19 #include "ui/gfx/rect_conversions.h" 21 #include "ui/gfx/rect_conversions.h"
20 #include "ui/gfx/transform.h" 22 #include "ui/gfx/transform.h"
21 23
22 namespace cc { 24 namespace cc {
23 25
24 ScrollAndScaleSet::ScrollAndScaleSet() {} 26 ScrollAndScaleSet::ScrollAndScaleSet() {}
25 27
26 ScrollAndScaleSet::~ScrollAndScaleSet() {} 28 ScrollAndScaleSet::~ScrollAndScaleSet() {}
27 29
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 543
542 static inline void SavePaintPropertiesLayer(Layer* layer) { 544 static inline void SavePaintPropertiesLayer(Layer* layer) {
543 layer->SavePaintProperties(); 545 layer->SavePaintProperties();
544 546
545 if (layer->mask_layer()) 547 if (layer->mask_layer())
546 layer->mask_layer()->SavePaintProperties(); 548 layer->mask_layer()->SavePaintProperties();
547 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) 549 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
548 layer->replica_layer()->mask_layer()->SavePaintProperties(); 550 layer->replica_layer()->mask_layer()->SavePaintProperties();
549 } 551 }
550 552
551 template <typename LayerType>
552 static bool SubtreeShouldRenderToSeparateSurface( 553 static bool SubtreeShouldRenderToSeparateSurface(
553 LayerType* layer, 554 Layer* layer,
554 bool axis_aligned_with_respect_to_parent) { 555 bool axis_aligned_with_respect_to_parent) {
555 // 556 //
556 // A layer and its descendants should render onto a new RenderSurfaceImpl if 557 // A layer and its descendants should render onto a new RenderSurfaceImpl if
557 // any of these rules hold: 558 // any of these rules hold:
558 // 559 //
559 560
560 // The root layer owns a render surface, but it never acts as a contributing 561 // The root layer owns a render surface, but it never acts as a contributing
561 // surface to another render target. Compositor features that are applied via 562 // surface to another render target. Compositor features that are applied via
562 // a contributing surface can not be applied to the root layer. In order to 563 // a contributing surface can not be applied to the root layer. In order to
563 // use these effects, another child of the root would need to be introduced 564 // use these effects, another child of the root would need to be introduced
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
1100 return; 1101 return;
1101 } 1102 }
1102 gfx::Vector2dF ancestor_transform_scales = 1103 gfx::Vector2dF ancestor_transform_scales =
1103 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f); 1104 MathUtil::ComputeTransform2dScaleComponents(ancestor_transform, 0.f);
1104 *combined_maximum_animation_contents_scale = 1105 *combined_maximum_animation_contents_scale =
1105 layer_maximum_animated_scale * 1106 layer_maximum_animated_scale *
1106 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y()); 1107 std::max(ancestor_transform_scales.x(), ancestor_transform_scales.y());
1107 } 1108 }
1108 1109
1109 template <typename LayerType> 1110 template <typename LayerType>
1110 static inline typename LayerType::RenderSurfaceType* CreateOrReuseRenderSurface( 1111 static inline typename LayerType::RenderSurfaceType* CreateOrReuseRenderSurface(
danakj 2014/08/26 18:06:13 unused?
awoloszyn 2014/08/28 19:31:43 Done.
1111 LayerType* layer) { 1112 LayerType* layer) {
1112 if (!layer->render_surface()) { 1113 if (!layer->render_surface()) {
1113 layer->CreateRenderSurface(); 1114 layer->CreateRenderSurface();
1114 return layer->render_surface(); 1115 return layer->render_surface();
1115 } 1116 }
1116 1117
1117 layer->render_surface()->ClearLayerLists(); 1118 layer->render_surface()->ClearLayerLists();
1118 return layer->render_surface(); 1119 return layer->render_surface();
1119 } 1120 }
1120 1121
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 // If the subtree will scale layer contents by the transform hierarchy, then 1809 // If the subtree will scale layer contents by the transform hierarchy, then
1809 // we should scale things into the render surface by the transform hierarchy 1810 // we should scale things into the render surface by the transform hierarchy
1810 // to take advantage of that. 1811 // to take advantage of that.
1811 gfx::Vector2dF render_surface_sublayer_scale = 1812 gfx::Vector2dF render_surface_sublayer_scale =
1812 globals.can_adjust_raster_scales 1813 globals.can_adjust_raster_scales
1813 ? combined_transform_scales 1814 ? combined_transform_scales
1814 : gfx::Vector2dF(layer_scale_factors, layer_scale_factors); 1815 : gfx::Vector2dF(layer_scale_factors, layer_scale_factors);
1815 1816
1816 bool render_to_separate_surface; 1817 bool render_to_separate_surface;
1817 if (globals.can_render_to_separate_surface) { 1818 if (globals.can_render_to_separate_surface) {
1818 render_to_separate_surface = SubtreeShouldRenderToSeparateSurface( 1819 render_to_separate_surface = layer->ShouldHaveRenderSurface();
1819 layer, combined_transform.Preserves2dAxisAlignment());
1820 } else { 1820 } else {
1821 render_to_separate_surface = IsRootLayer(layer); 1821 render_to_separate_surface =
1822 layer->ShouldHaveRenderSurface() && IsRootLayer(layer);
danakj 2014/08/26 18:06:13 the root has to have a surface, and nothing else i
awoloszyn 2014/08/28 19:31:43 We may still have a render-surface if !globals.can
1822 } 1823 }
1824 layer->SetRenderSurfaceActive(render_to_separate_surface);
danakj 2014/08/26 18:06:13 The RS computation decides if the render surface s
awoloszyn 2014/08/28 19:31:43 Done.
1825
1823 if (render_to_separate_surface) { 1826 if (render_to_separate_surface) {
1824 // Check back-face visibility before continuing with this surface and its 1827 // Check back-face visibility before continuing with this surface and its
1825 // subtree 1828 // subtree
1826 if (!layer->double_sided() && TransformToParentIsKnown(layer) && 1829 if (!layer->double_sided() && TransformToParentIsKnown(layer) &&
1827 IsSurfaceBackFaceVisible(layer, combined_transform)) { 1830 IsSurfaceBackFaceVisible(layer, combined_transform)) {
1828 layer->ClearRenderSurfaceLayerList(); 1831 layer->SetRenderSurfaceActive(false);
danakj 2014/08/26 18:06:13 And since the RS exists or not correctly, we shoul
awoloszyn 2014/08/28 19:31:43 Done.
1829 return; 1832 return;
1830 } 1833 }
1831 1834
1832 typename LayerType::RenderSurfaceType* render_surface = 1835 typename LayerType::RenderSurfaceType* render_surface =
1833 CreateOrReuseRenderSurface(layer); 1836 layer->render_surface();
1834 1837 render_surface->ClearLayerLists();
1835 if (IsRootLayer(layer)) { 1838 if (IsRootLayer(layer)) {
1836 // The root layer's render surface size is predetermined and so the root 1839 // The root layer's render surface size is predetermined and so the root
1837 // layer can't directly support non-identity transforms. It should just 1840 // layer can't directly support non-identity transforms. It should just
1838 // forward top-level transforms to the rest of the tree. 1841 // forward top-level transforms to the rest of the tree.
1839 data_for_children.parent_matrix = combined_transform; 1842 data_for_children.parent_matrix = combined_transform;
1840 1843
1841 // The root surface does not contribute to any other surface, it has no 1844 // The root surface does not contribute to any other surface, it has no
1842 // target. 1845 // target.
1843 layer->render_surface()->set_contributes_to_drawn_surface(false); 1846 layer->render_surface()->set_contributes_to_drawn_surface(false);
1844 } else { 1847 } else {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 layer_draw_properties.target_space_transform_is_animating = 2002 layer_draw_properties.target_space_transform_is_animating =
2000 animating_transform_to_target; 2003 animating_transform_to_target;
2001 layer_draw_properties.screen_space_transform_is_animating = 2004 layer_draw_properties.screen_space_transform_is_animating =
2002 animating_transform_to_screen; 2005 animating_transform_to_screen;
2003 layer_draw_properties.opacity = accumulated_draw_opacity; 2006 layer_draw_properties.opacity = accumulated_draw_opacity;
2004 layer_draw_properties.opacity_is_animating = animating_opacity_to_target; 2007 layer_draw_properties.opacity_is_animating = animating_opacity_to_target;
2005 layer_draw_properties.screen_space_opacity_is_animating = 2008 layer_draw_properties.screen_space_opacity_is_animating =
2006 animating_opacity_to_screen; 2009 animating_opacity_to_screen;
2007 data_for_children.parent_matrix = combined_transform; 2010 data_for_children.parent_matrix = combined_transform;
2008 2011
2009 layer->ClearRenderSurface();
2010
2011 // Layers without render_surfaces directly inherit the ancestor's clip 2012 // Layers without render_surfaces directly inherit the ancestor's clip
2012 // status. 2013 // status.
2013 layer_or_ancestor_clips_descendants = ancestor_clips_subtree; 2014 layer_or_ancestor_clips_descendants = ancestor_clips_subtree;
2014 if (ancestor_clips_subtree) { 2015 if (ancestor_clips_subtree) {
2015 clip_rect_in_target_space = 2016 clip_rect_in_target_space =
2016 ancestor_clip_rect_in_target_space; 2017 ancestor_clip_rect_in_target_space;
2017 } 2018 }
2018 2019
2019 // The surface's cached clip rect value propagates regardless of what 2020 // The surface's cached clip rect value propagates regardless of what
2020 // clipping goes on between layers here. 2021 // clipping goes on between layers here.
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2376 device_viewport_rect; 2377 device_viewport_rect;
2377 data_for_recursion->maximum_animation_contents_scale = 0.f; 2378 data_for_recursion->maximum_animation_contents_scale = 0.f;
2378 data_for_recursion->ancestor_is_animating_scale = false; 2379 data_for_recursion->ancestor_is_animating_scale = false;
2379 data_for_recursion->ancestor_clips_subtree = true; 2380 data_for_recursion->ancestor_clips_subtree = true;
2380 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL; 2381 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL;
2381 data_for_recursion->in_subtree_of_page_scale_application_layer = false; 2382 data_for_recursion->in_subtree_of_page_scale_application_layer = false;
2382 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text; 2383 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text;
2383 data_for_recursion->subtree_is_visible_from_ancestor = true; 2384 data_for_recursion->subtree_is_visible_from_ancestor = true;
2384 } 2385 }
2385 2386
2387 void CreateOrDestroyRenderSurface(Layer* layer, gfx::Transform* transform) {
2388 if (SubtreeShouldRenderToSeparateSurface(
2389 layer,
2390 transform->IsIdentity() || transform->Preserves2dAxisAlignment())) {
2391 transform->MakeIdentity();
2392 layer->SetShouldHaveRenderSurface(true);
2393 if (!layer->render_surface()) {
2394 layer->CreateRenderSurface();
2395 }
2396 return;
2397 }
2398 if (layer->render_surface())
2399 layer->ClearRenderSurface();
2400 layer->SetShouldHaveRenderSurface(false);
2401 }
2402
2403 static void CreateRenderSurfaces(Layer* layer,
2404 const gfx::Transform& parent_transform) {
2405 if (!layer)
2406 return;
2407 gfx::Transform transformForChildren = layer->transform();
2408 transformForChildren *= parent_transform;
2409 CreateOrDestroyRenderSurface(layer, &transformForChildren);
2410
2411 for (size_t i = 0; i < layer->children().size(); ++i) {
2412 CreateRenderSurfaces(layer->children()[i], transformForChildren);
2413 }
2414 }
2415
2386 void LayerTreeHostCommon::CalculateDrawProperties( 2416 void LayerTreeHostCommon::CalculateDrawProperties(
2387 CalcDrawPropsMainInputs* inputs) { 2417 CalcDrawPropsMainInputs* inputs) {
2418 CreateRenderSurfaces(inputs->root_layer, gfx::Transform());
2388 LayerList dummy_layer_list; 2419 LayerList dummy_layer_list;
2389 SubtreeGlobals<Layer> globals; 2420 SubtreeGlobals<Layer> globals;
2390 DataForRecursion<Layer> data_for_recursion; 2421 DataForRecursion<Layer> data_for_recursion;
2391 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); 2422 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion);
2392 2423
2393 PreCalculateMetaInformationRecursiveData recursive_data; 2424 PreCalculateMetaInformationRecursiveData recursive_data;
2394 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); 2425 PreCalculateMetaInformation(inputs->root_layer, &recursive_data);
2395 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; 2426 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state;
2396 CalculateDrawPropertiesInternal<Layer>( 2427 CalculateDrawPropertiesInternal<Layer>(
2397 inputs->root_layer, 2428 inputs->root_layer,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2433 inputs->current_render_surface_layer_list_id); 2464 inputs->current_render_surface_layer_list_id);
2434 2465
2435 // The dummy layer list should not have been used. 2466 // The dummy layer list should not have been used.
2436 DCHECK_EQ(0u, dummy_layer_list.size()); 2467 DCHECK_EQ(0u, dummy_layer_list.size());
2437 // A root layer render_surface should always exist after 2468 // A root layer render_surface should always exist after
2438 // CalculateDrawProperties. 2469 // CalculateDrawProperties.
2439 DCHECK(inputs->root_layer->render_surface()); 2470 DCHECK(inputs->root_layer->render_surface());
2440 } 2471 }
2441 2472
2442 } // namespace cc 2473 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698