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" |
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/trees/draw_property_utils.h" | 17 #include "cc/trees/draw_property_utils.h" |
18 #include "cc/trees/layer_sorter.h" | |
19 #include "cc/trees/layer_tree_host.h" | 18 #include "cc/trees/layer_tree_host.h" |
20 #include "cc/trees/layer_tree_impl.h" | 19 #include "cc/trees/layer_tree_impl.h" |
21 #include "ui/gfx/geometry/rect_conversions.h" | 20 #include "ui/gfx/geometry/rect_conversions.h" |
22 #include "ui/gfx/geometry/vector2d_conversions.h" | 21 #include "ui/gfx/geometry/vector2d_conversions.h" |
23 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
24 #include "ui/gfx/transform_util.h" | 23 #include "ui/gfx/transform_util.h" |
25 | 24 |
26 namespace cc { | 25 namespace cc { |
27 | 26 |
28 ScrollAndScaleSet::ScrollAndScaleSet() | 27 ScrollAndScaleSet::ScrollAndScaleSet() |
29 : page_scale_delta(1.f), top_controls_delta(0.f) { | 28 : page_scale_delta(1.f), top_controls_delta(0.f) { |
30 } | 29 } |
31 | 30 |
32 ScrollAndScaleSet::~ScrollAndScaleSet() {} | 31 ScrollAndScaleSet::~ScrollAndScaleSet() {} |
33 | 32 |
34 static void SortLayers(LayerList::iterator forst, | |
35 LayerList::iterator end, | |
36 void* layer_sorter) { | |
37 NOTREACHED(); | |
38 } | |
39 | |
40 static void SortLayers(LayerImplList::iterator first, | |
41 LayerImplList::iterator end, | |
42 LayerSorter* layer_sorter) { | |
43 DCHECK(layer_sorter); | |
44 TRACE_EVENT0("cc", "LayerTreeHostCommon::SortLayers"); | |
45 layer_sorter->Sort(first, end); | |
46 } | |
47 | |
48 template <typename LayerType> | 33 template <typename LayerType> |
49 static gfx::Vector2dF GetEffectiveScrollDelta(LayerType* layer) { | 34 static gfx::Vector2dF GetEffectiveScrollDelta(LayerType* layer) { |
50 // Layer's scroll offset can have an integer part and fractional part. | 35 // Layer's scroll offset can have an integer part and fractional part. |
51 // Due to Blink's limitation, it only counter-scrolls the position-fixed | 36 // Due to Blink's limitation, it only counter-scrolls the position-fixed |
52 // layer using the integer part of Layer's scroll offset. | 37 // layer using the integer part of Layer's scroll offset. |
53 // CC scrolls the layer using the full scroll offset, so we have to | 38 // CC scrolls the layer using the full scroll offset, so we have to |
54 // add the ScrollCompensationAdjustment (fractional part of the scroll | 39 // add the ScrollCompensationAdjustment (fractional part of the scroll |
55 // offset) to the effective scroll delta which is used to counter-scroll | 40 // offset) to the effective scroll delta which is used to counter-scroll |
56 // the position-fixed layer. | 41 // the position-fixed layer. |
57 gfx::Vector2dF scroll_delta = | 42 gfx::Vector2dF scroll_delta = |
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1267 layer->draw_properties().num_unclipped_descendants = | 1252 layer->draw_properties().num_unclipped_descendants = |
1268 recursive_data->num_unclipped_descendants; | 1253 recursive_data->num_unclipped_descendants; |
1269 layer->draw_properties().layer_or_descendant_has_copy_request = | 1254 layer->draw_properties().layer_or_descendant_has_copy_request = |
1270 recursive_data->layer_or_descendant_has_copy_request; | 1255 recursive_data->layer_or_descendant_has_copy_request; |
1271 layer->draw_properties().layer_or_descendant_has_input_handler = | 1256 layer->draw_properties().layer_or_descendant_has_input_handler = |
1272 recursive_data->layer_or_descendant_has_input_handler; | 1257 recursive_data->layer_or_descendant_has_input_handler; |
1273 } | 1258 } |
1274 | 1259 |
1275 template <typename LayerType> | 1260 template <typename LayerType> |
1276 struct SubtreeGlobals { | 1261 struct SubtreeGlobals { |
1277 LayerSorter* layer_sorter; | |
1278 int max_texture_size; | 1262 int max_texture_size; |
1279 float device_scale_factor; | 1263 float device_scale_factor; |
1280 float page_scale_factor; | 1264 float page_scale_factor; |
1281 const LayerType* page_scale_application_layer; | 1265 const LayerType* page_scale_application_layer; |
1282 gfx::Vector2dF elastic_overscroll; | 1266 gfx::Vector2dF elastic_overscroll; |
1283 const LayerType* elastic_overscroll_application_layer; | 1267 const LayerType* elastic_overscroll_application_layer; |
1284 bool can_adjust_raster_scales; | 1268 bool can_adjust_raster_scales; |
1285 bool can_render_to_separate_surface; | 1269 bool can_render_to_separate_surface; |
1286 bool layers_always_allowed_lcd_text; | 1270 bool layers_always_allowed_lcd_text; |
1287 }; | 1271 }; |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2350 } | 2334 } |
2351 | 2335 |
2352 SavePaintPropertiesLayer(layer); | 2336 SavePaintPropertiesLayer(layer); |
2353 | 2337 |
2354 // If neither this layer nor any of its children were added, early out. | 2338 // If neither this layer nor any of its children were added, early out. |
2355 if (sorting_start_index == descendants.size()) { | 2339 if (sorting_start_index == descendants.size()) { |
2356 DCHECK(!render_to_separate_surface || IsRootLayer(layer)); | 2340 DCHECK(!render_to_separate_surface || IsRootLayer(layer)); |
2357 return; | 2341 return; |
2358 } | 2342 } |
2359 | 2343 |
2360 // If preserves-3d then sort all the descendants in 3D so that they can be | |
2361 // drawn from back to front. If the preserves-3d property is also set on the | |
2362 // parent then skip the sorting as the parent will sort all the descendants | |
2363 // anyway. | |
2364 if (globals.layer_sorter && descendants.size() && layer->Is3dSorted() && | |
2365 !LayerIsInExisting3DRenderingContext(layer)) { | |
2366 SortLayers(descendants.begin() + sorting_start_index, | |
2367 descendants.end(), | |
2368 globals.layer_sorter); | |
2369 } | |
2370 | |
2371 UpdateAccumulatedSurfaceState<LayerType>( | 2344 UpdateAccumulatedSurfaceState<LayerType>( |
2372 layer, local_drawable_content_rect_of_subtree, accumulated_surface_state); | 2345 layer, local_drawable_content_rect_of_subtree, accumulated_surface_state); |
2373 | 2346 |
2374 if (layer->HasContributingDelegatedRenderPasses()) { | 2347 if (layer->HasContributingDelegatedRenderPasses()) { |
2375 layer->render_target()->render_surface()-> | 2348 layer->render_target()->render_surface()-> |
2376 AddContributingDelegatedRenderPassLayer(layer); | 2349 AddContributingDelegatedRenderPassLayer(layer); |
2377 } | 2350 } |
2378 } // NOLINT(readability/fn_size) | 2351 } // NOLINT(readability/fn_size) |
2379 | 2352 |
2380 template <typename LayerType, typename RenderSurfaceLayerListType> | 2353 template <typename LayerType, typename RenderSurfaceLayerListType> |
(...skipping 17 matching lines...) Expand all Loading... |
2398 MathUtil::ComputeTransform2dScaleComponents(inputs.device_transform, 1.f); | 2371 MathUtil::ComputeTransform2dScaleComponents(inputs.device_transform, 1.f); |
2399 // Not handling the rare case of different x and y device scale. | 2372 // Not handling the rare case of different x and y device scale. |
2400 float device_transform_scale = | 2373 float device_transform_scale = |
2401 std::max(device_transform_scale_components.x(), | 2374 std::max(device_transform_scale_components.x(), |
2402 device_transform_scale_components.y()); | 2375 device_transform_scale_components.y()); |
2403 | 2376 |
2404 gfx::Transform scaled_device_transform = inputs.device_transform; | 2377 gfx::Transform scaled_device_transform = inputs.device_transform; |
2405 scaled_device_transform.Scale(inputs.device_scale_factor, | 2378 scaled_device_transform.Scale(inputs.device_scale_factor, |
2406 inputs.device_scale_factor); | 2379 inputs.device_scale_factor); |
2407 | 2380 |
2408 globals->layer_sorter = NULL; | |
2409 globals->max_texture_size = inputs.max_texture_size; | 2381 globals->max_texture_size = inputs.max_texture_size; |
2410 globals->device_scale_factor = | 2382 globals->device_scale_factor = |
2411 inputs.device_scale_factor * device_transform_scale; | 2383 inputs.device_scale_factor * device_transform_scale; |
2412 globals->page_scale_factor = inputs.page_scale_factor; | 2384 globals->page_scale_factor = inputs.page_scale_factor; |
2413 globals->page_scale_application_layer = inputs.page_scale_application_layer; | 2385 globals->page_scale_application_layer = inputs.page_scale_application_layer; |
2414 globals->elastic_overscroll = inputs.elastic_overscroll; | 2386 globals->elastic_overscroll = inputs.elastic_overscroll; |
2415 globals->elastic_overscroll_application_layer = | 2387 globals->elastic_overscroll_application_layer = |
2416 inputs.elastic_overscroll_application_layer; | 2388 inputs.elastic_overscroll_application_layer; |
2417 globals->can_render_to_separate_surface = | 2389 globals->can_render_to_separate_surface = |
2418 inputs.can_render_to_separate_surface; | 2390 inputs.can_render_to_separate_surface; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2553 } | 2525 } |
2554 } | 2526 } |
2555 | 2527 |
2556 void LayerTreeHostCommon::CalculateDrawProperties( | 2528 void LayerTreeHostCommon::CalculateDrawProperties( |
2557 CalcDrawPropsImplInputs* inputs) { | 2529 CalcDrawPropsImplInputs* inputs) { |
2558 LayerImplList dummy_layer_list; | 2530 LayerImplList dummy_layer_list; |
2559 SubtreeGlobals<LayerImpl> globals; | 2531 SubtreeGlobals<LayerImpl> globals; |
2560 DataForRecursion<LayerImpl> data_for_recursion; | 2532 DataForRecursion<LayerImpl> data_for_recursion; |
2561 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2533 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2562 | 2534 |
2563 LayerSorter layer_sorter; | |
2564 globals.layer_sorter = &layer_sorter; | |
2565 | |
2566 PreCalculateMetaInformationRecursiveData recursive_data; | 2535 PreCalculateMetaInformationRecursiveData recursive_data; |
2567 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2536 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2568 std::vector<AccumulatedSurfaceState<LayerImpl>> accumulated_surface_state; | 2537 std::vector<AccumulatedSurfaceState<LayerImpl>> accumulated_surface_state; |
2569 CalculateDrawPropertiesInternal<LayerImpl>( | 2538 CalculateDrawPropertiesInternal<LayerImpl>( |
2570 inputs->root_layer, | 2539 inputs->root_layer, |
2571 globals, | 2540 globals, |
2572 data_for_recursion, | 2541 data_for_recursion, |
2573 inputs->render_surface_layer_list, | 2542 inputs->render_surface_layer_list, |
2574 &dummy_layer_list, | 2543 &dummy_layer_list, |
2575 &accumulated_surface_state, | 2544 &accumulated_surface_state, |
2576 inputs->current_render_surface_layer_list_id); | 2545 inputs->current_render_surface_layer_list_id); |
2577 | 2546 |
2578 // The dummy layer list should not have been used. | 2547 // The dummy layer list should not have been used. |
2579 DCHECK_EQ(0u, dummy_layer_list.size()); | 2548 DCHECK_EQ(0u, dummy_layer_list.size()); |
2580 // A root layer render_surface should always exist after | 2549 // A root layer render_surface should always exist after |
2581 // CalculateDrawProperties. | 2550 // CalculateDrawProperties. |
2582 DCHECK(inputs->root_layer->render_surface()); | 2551 DCHECK(inputs->root_layer->render_surface()); |
2583 } | 2552 } |
2584 | 2553 |
2585 } // namespace cc | 2554 } // namespace cc |
OLD | NEW |