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

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: Created 6 years, 4 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 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 // If the subtree will scale layer contents by the transform hierarchy, then 1810 // 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 1811 // we should scale things into the render surface by the transform hierarchy
1810 // to take advantage of that. 1812 // to take advantage of that.
1811 gfx::Vector2dF render_surface_sublayer_scale = 1813 gfx::Vector2dF render_surface_sublayer_scale =
1812 globals.can_adjust_raster_scales 1814 globals.can_adjust_raster_scales
1813 ? combined_transform_scales 1815 ? combined_transform_scales
1814 : gfx::Vector2dF(layer_scale_factors, layer_scale_factors); 1816 : gfx::Vector2dF(layer_scale_factors, layer_scale_factors);
1815 1817
1816 bool render_to_separate_surface; 1818 bool render_to_separate_surface;
1817 if (globals.can_render_to_separate_surface) { 1819 if (globals.can_render_to_separate_surface) {
1818 render_to_separate_surface = SubtreeShouldRenderToSeparateSurface( 1820 render_to_separate_surface = layer->ShouldHaveRenderSurface();
1819 layer, combined_transform.Preserves2dAxisAlignment());
1820 } else { 1821 } else {
1821 render_to_separate_surface = IsRootLayer(layer); 1822 render_to_separate_surface =
1823 layer->ShouldHaveRenderSurface() && IsRootLayer(layer);
1822 } 1824 }
1825 layer->SetRenderSurfaceActive(render_to_separate_surface);
1826
1823 if (render_to_separate_surface) { 1827 if (render_to_separate_surface) {
1824 // Check back-face visibility before continuing with this surface and its 1828 // Check back-face visibility before continuing with this surface and its
1825 // subtree 1829 // subtree
1826 if (!layer->double_sided() && TransformToParentIsKnown(layer) && 1830 if (!layer->double_sided() && TransformToParentIsKnown(layer) &&
1827 IsSurfaceBackFaceVisible(layer, combined_transform)) { 1831 IsSurfaceBackFaceVisible(layer, combined_transform)) {
1828 layer->ClearRenderSurfaceLayerList(); 1832 layer->SetRenderSurfaceActive(false);
1829 return; 1833 return;
1830 } 1834 }
1831 1835
1832 typename LayerType::RenderSurfaceType* render_surface = 1836 typename LayerType::RenderSurfaceType* render_surface =
1833 CreateOrReuseRenderSurface(layer); 1837 layer->render_surface();
1834 1838 render_surface->ClearLayerLists();
1835 if (IsRootLayer(layer)) { 1839 if (IsRootLayer(layer)) {
1836 // The root layer's render surface size is predetermined and so the root 1840 // 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 1841 // layer can't directly support non-identity transforms. It should just
1838 // forward top-level transforms to the rest of the tree. 1842 // forward top-level transforms to the rest of the tree.
1839 data_for_children.parent_matrix = combined_transform; 1843 data_for_children.parent_matrix = combined_transform;
1840 1844
1841 // The root surface does not contribute to any other surface, it has no 1845 // The root surface does not contribute to any other surface, it has no
1842 // target. 1846 // target.
1843 layer->render_surface()->set_contributes_to_drawn_surface(false); 1847 layer->render_surface()->set_contributes_to_drawn_surface(false);
1844 } else { 1848 } else {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1999 layer_draw_properties.target_space_transform_is_animating = 2003 layer_draw_properties.target_space_transform_is_animating =
2000 animating_transform_to_target; 2004 animating_transform_to_target;
2001 layer_draw_properties.screen_space_transform_is_animating = 2005 layer_draw_properties.screen_space_transform_is_animating =
2002 animating_transform_to_screen; 2006 animating_transform_to_screen;
2003 layer_draw_properties.opacity = accumulated_draw_opacity; 2007 layer_draw_properties.opacity = accumulated_draw_opacity;
2004 layer_draw_properties.opacity_is_animating = animating_opacity_to_target; 2008 layer_draw_properties.opacity_is_animating = animating_opacity_to_target;
2005 layer_draw_properties.screen_space_opacity_is_animating = 2009 layer_draw_properties.screen_space_opacity_is_animating =
2006 animating_opacity_to_screen; 2010 animating_opacity_to_screen;
2007 data_for_children.parent_matrix = combined_transform; 2011 data_for_children.parent_matrix = combined_transform;
2008 2012
2009 layer->ClearRenderSurface();
2010
2011 // Layers without render_surfaces directly inherit the ancestor's clip 2013 // Layers without render_surfaces directly inherit the ancestor's clip
2012 // status. 2014 // status.
2013 layer_or_ancestor_clips_descendants = ancestor_clips_subtree; 2015 layer_or_ancestor_clips_descendants = ancestor_clips_subtree;
2014 if (ancestor_clips_subtree) { 2016 if (ancestor_clips_subtree) {
2015 clip_rect_in_target_space = 2017 clip_rect_in_target_space =
2016 ancestor_clip_rect_in_target_space; 2018 ancestor_clip_rect_in_target_space;
2017 } 2019 }
2018 2020
2019 // The surface's cached clip rect value propagates regardless of what 2021 // The surface's cached clip rect value propagates regardless of what
2020 // clipping goes on between layers here. 2022 // clipping goes on between layers here.
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
2376 device_viewport_rect; 2378 device_viewport_rect;
2377 data_for_recursion->maximum_animation_contents_scale = 0.f; 2379 data_for_recursion->maximum_animation_contents_scale = 0.f;
2378 data_for_recursion->ancestor_is_animating_scale = false; 2380 data_for_recursion->ancestor_is_animating_scale = false;
2379 data_for_recursion->ancestor_clips_subtree = true; 2381 data_for_recursion->ancestor_clips_subtree = true;
2380 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL; 2382 data_for_recursion->nearest_occlusion_immune_ancestor_surface = NULL;
2381 data_for_recursion->in_subtree_of_page_scale_application_layer = false; 2383 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; 2384 data_for_recursion->subtree_can_use_lcd_text = inputs.can_use_lcd_text;
2383 data_for_recursion->subtree_is_visible_from_ancestor = true; 2385 data_for_recursion->subtree_is_visible_from_ancestor = true;
2384 } 2386 }
2385 2387
2388 template <typename LayerType>
2389 void CreateOrDestroyRenderSurface(LayerType* type, gfx::Transform* t) {
2390 }
2391
2392 template <>
2393 void CreateOrDestroyRenderSurface<LayerImpl>(LayerImpl* layer,
2394 gfx::Transform* transform) {
2395 if (SubtreeShouldRenderToSeparateSurface<LayerImpl>(
2396 layer,
2397 transform->IsIdentity() || transform->Preserves2dAxisAlignment())) {
2398 transform->MakeIdentity();
2399 if (!layer->render_surface()) {
2400 layer->CreateRenderSurface();
2401 }
2402 return;
2403 }
2404 if (layer->render_surface())
2405 layer->ClearRenderSurface();
2406 }
2407
2408 template <>
2409 void CreateOrDestroyRenderSurface<Layer>(Layer* layer,
2410 gfx::Transform* transform) {
2411 if (SubtreeShouldRenderToSeparateSurface<Layer>(
2412 layer,
2413 transform->IsIdentity() || transform->Preserves2dAxisAlignment())) {
2414 transform->MakeIdentity();
2415 layer->SetShouldHaveRenderSurface(true);
2416 if (!layer->render_surface()) {
2417 layer->CreateRenderSurface();
2418 }
2419 return;
2420 }
2421 if (layer->render_surface())
2422 layer->ClearRenderSurface();
2423 layer->SetShouldHaveRenderSurface(false);
2424 }
2425
2426 template <typename LayerType>
2427 static void CreateRenderSurfaces(LayerType* layer,
2428 const gfx::Transform& parent_transform) {
2429 gfx::Transform transformForChildren = layer->transform();
2430 transformForChildren *= parent_transform;
2431 CreateOrDestroyRenderSurface(layer, &transformForChildren);
2432
2433 for (size_t i = 0; i < layer->children().size(); ++i) {
2434 CreateRenderSurfaces<LayerType>(layer->children()[i], transformForChildren);
2435 }
2436 }
2437
2438 void LayerTreeHostCommon::CalculateDrawProperties(
2439 CalcDrawPropsImplInputsForTesting* inputs) {
2440 CreateRenderSurfaces(inputs->root_layer, gfx::Transform());
2441 CalculateDrawProperties(static_cast<CalcDrawPropsImplInputs*>(inputs));
2442 }
2443
2386 void LayerTreeHostCommon::CalculateDrawProperties( 2444 void LayerTreeHostCommon::CalculateDrawProperties(
2387 CalcDrawPropsMainInputs* inputs) { 2445 CalcDrawPropsMainInputs* inputs) {
2446 CreateRenderSurfaces(inputs->root_layer, gfx::Transform());
2388 LayerList dummy_layer_list; 2447 LayerList dummy_layer_list;
2389 SubtreeGlobals<Layer> globals; 2448 SubtreeGlobals<Layer> globals;
2390 DataForRecursion<Layer> data_for_recursion; 2449 DataForRecursion<Layer> data_for_recursion;
2391 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); 2450 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion);
2392 2451
2393 PreCalculateMetaInformationRecursiveData recursive_data; 2452 PreCalculateMetaInformationRecursiveData recursive_data;
2394 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); 2453 PreCalculateMetaInformation(inputs->root_layer, &recursive_data);
2395 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state; 2454 std::vector<AccumulatedSurfaceState<Layer> > accumulated_surface_state;
2396 CalculateDrawPropertiesInternal<Layer>( 2455 CalculateDrawPropertiesInternal<Layer>(
2397 inputs->root_layer, 2456 inputs->root_layer,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2433 inputs->current_render_surface_layer_list_id); 2492 inputs->current_render_surface_layer_list_id);
2434 2493
2435 // The dummy layer list should not have been used. 2494 // The dummy layer list should not have been used.
2436 DCHECK_EQ(0u, dummy_layer_list.size()); 2495 DCHECK_EQ(0u, dummy_layer_list.size());
2437 // A root layer render_surface should always exist after 2496 // A root layer render_surface should always exist after
2438 // CalculateDrawProperties. 2497 // CalculateDrawProperties.
2439 DCHECK(inputs->root_layer->render_surface()); 2498 DCHECK(inputs->root_layer->render_surface());
2440 } 2499 }
2441 2500
2442 } // namespace cc 2501 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698