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" |
18 #include "cc/trees/layer_tree_host.h" | 19 #include "cc/trees/layer_tree_host.h" |
19 #include "cc/trees/layer_tree_impl.h" | 20 #include "cc/trees/layer_tree_impl.h" |
20 #include "ui/gfx/geometry/rect_conversions.h" | 21 #include "ui/gfx/geometry/rect_conversions.h" |
21 #include "ui/gfx/geometry/vector2d_conversions.h" | 22 #include "ui/gfx/geometry/vector2d_conversions.h" |
22 #include "ui/gfx/transform.h" | 23 #include "ui/gfx/transform.h" |
23 #include "ui/gfx/transform_util.h" | 24 #include "ui/gfx/transform_util.h" |
24 | 25 |
25 namespace cc { | 26 namespace cc { |
26 | 27 |
27 ScrollAndScaleSet::ScrollAndScaleSet() | 28 ScrollAndScaleSet::ScrollAndScaleSet() |
28 : page_scale_delta(1.f), top_controls_delta(0.f) { | 29 : page_scale_delta(1.f), top_controls_delta(0.f) { |
29 } | 30 } |
30 | 31 |
31 ScrollAndScaleSet::~ScrollAndScaleSet() {} | 32 ScrollAndScaleSet::~ScrollAndScaleSet() {} |
32 | 33 |
| 34 static void SortLayers(LayerList::iterator first, |
| 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 |
33 template <typename LayerType> | 48 template <typename LayerType> |
34 static gfx::Vector2dF GetEffectiveScrollDelta(LayerType* layer) { | 49 static gfx::Vector2dF GetEffectiveScrollDelta(LayerType* layer) { |
35 // Layer's scroll offset can have an integer part and fractional part. | 50 // Layer's scroll offset can have an integer part and fractional part. |
36 // Due to Blink's limitation, it only counter-scrolls the position-fixed | 51 // Due to Blink's limitation, it only counter-scrolls the position-fixed |
37 // layer using the integer part of Layer's scroll offset. | 52 // layer using the integer part of Layer's scroll offset. |
38 // CC scrolls the layer using the full scroll offset, so we have to | 53 // CC scrolls the layer using the full scroll offset, so we have to |
39 // add the ScrollCompensationAdjustment (fractional part of the scroll | 54 // add the ScrollCompensationAdjustment (fractional part of the scroll |
40 // offset) to the effective scroll delta which is used to counter-scroll | 55 // offset) to the effective scroll delta which is used to counter-scroll |
41 // the position-fixed layer. | 56 // the position-fixed layer. |
42 gfx::Vector2dF scroll_delta = | 57 gfx::Vector2dF scroll_delta = |
(...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 layer->draw_properties().num_unclipped_descendants = | 1272 layer->draw_properties().num_unclipped_descendants = |
1258 recursive_data->num_unclipped_descendants; | 1273 recursive_data->num_unclipped_descendants; |
1259 layer->draw_properties().layer_or_descendant_has_copy_request = | 1274 layer->draw_properties().layer_or_descendant_has_copy_request = |
1260 recursive_data->layer_or_descendant_has_copy_request; | 1275 recursive_data->layer_or_descendant_has_copy_request; |
1261 layer->draw_properties().layer_or_descendant_has_input_handler = | 1276 layer->draw_properties().layer_or_descendant_has_input_handler = |
1262 recursive_data->layer_or_descendant_has_input_handler; | 1277 recursive_data->layer_or_descendant_has_input_handler; |
1263 } | 1278 } |
1264 | 1279 |
1265 template <typename LayerType> | 1280 template <typename LayerType> |
1266 struct SubtreeGlobals { | 1281 struct SubtreeGlobals { |
| 1282 LayerSorter* layer_sorter; |
1267 int max_texture_size; | 1283 int max_texture_size; |
1268 float device_scale_factor; | 1284 float device_scale_factor; |
1269 float page_scale_factor; | 1285 float page_scale_factor; |
1270 const LayerType* page_scale_application_layer; | 1286 const LayerType* page_scale_application_layer; |
1271 gfx::Vector2dF elastic_overscroll; | 1287 gfx::Vector2dF elastic_overscroll; |
1272 const LayerType* elastic_overscroll_application_layer; | 1288 const LayerType* elastic_overscroll_application_layer; |
1273 bool can_adjust_raster_scales; | 1289 bool can_adjust_raster_scales; |
1274 bool can_render_to_separate_surface; | 1290 bool can_render_to_separate_surface; |
1275 bool layers_always_allowed_lcd_text; | 1291 bool layers_always_allowed_lcd_text; |
1276 }; | 1292 }; |
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2342 } | 2358 } |
2343 | 2359 |
2344 SavePaintPropertiesLayer(layer); | 2360 SavePaintPropertiesLayer(layer); |
2345 | 2361 |
2346 // If neither this layer nor any of its children were added, early out. | 2362 // If neither this layer nor any of its children were added, early out. |
2347 if (sorting_start_index == descendants.size()) { | 2363 if (sorting_start_index == descendants.size()) { |
2348 DCHECK(!render_to_separate_surface || IsRootLayer(layer)); | 2364 DCHECK(!render_to_separate_surface || IsRootLayer(layer)); |
2349 return; | 2365 return; |
2350 } | 2366 } |
2351 | 2367 |
| 2368 // If preserves-3d then sort all the descendants in 3D so that they can be |
| 2369 // drawn from back to front. If the preserves-3d property is also set on the |
| 2370 // parent then skip the sorting as the parent will sort all the descendants |
| 2371 // anyway. |
| 2372 if (globals.layer_sorter && descendants.size() && layer->Is3dSorted() && |
| 2373 !LayerIsInExisting3DRenderingContext(layer)) { |
| 2374 SortLayers(descendants.begin() + sorting_start_index, |
| 2375 descendants.end(), |
| 2376 globals.layer_sorter); |
| 2377 } |
| 2378 |
2352 UpdateAccumulatedSurfaceState<LayerType>( | 2379 UpdateAccumulatedSurfaceState<LayerType>( |
2353 layer, local_drawable_content_rect_of_subtree, accumulated_surface_state); | 2380 layer, local_drawable_content_rect_of_subtree, accumulated_surface_state); |
2354 | 2381 |
2355 if (layer->HasContributingDelegatedRenderPasses()) { | 2382 if (layer->HasContributingDelegatedRenderPasses()) { |
2356 layer->render_target()->render_surface()-> | 2383 layer->render_target()->render_surface()-> |
2357 AddContributingDelegatedRenderPassLayer(layer); | 2384 AddContributingDelegatedRenderPassLayer(layer); |
2358 } | 2385 } |
2359 } // NOLINT(readability/fn_size) | 2386 } // NOLINT(readability/fn_size) |
2360 | 2387 |
2361 template <typename LayerType, typename RenderSurfaceLayerListType> | 2388 template <typename LayerType, typename RenderSurfaceLayerListType> |
(...skipping 17 matching lines...) Expand all Loading... |
2379 MathUtil::ComputeTransform2dScaleComponents(inputs.device_transform, 1.f); | 2406 MathUtil::ComputeTransform2dScaleComponents(inputs.device_transform, 1.f); |
2380 // Not handling the rare case of different x and y device scale. | 2407 // Not handling the rare case of different x and y device scale. |
2381 float device_transform_scale = | 2408 float device_transform_scale = |
2382 std::max(device_transform_scale_components.x(), | 2409 std::max(device_transform_scale_components.x(), |
2383 device_transform_scale_components.y()); | 2410 device_transform_scale_components.y()); |
2384 | 2411 |
2385 gfx::Transform scaled_device_transform = inputs.device_transform; | 2412 gfx::Transform scaled_device_transform = inputs.device_transform; |
2386 scaled_device_transform.Scale(inputs.device_scale_factor, | 2413 scaled_device_transform.Scale(inputs.device_scale_factor, |
2387 inputs.device_scale_factor); | 2414 inputs.device_scale_factor); |
2388 | 2415 |
| 2416 globals->layer_sorter = NULL; |
2389 globals->max_texture_size = inputs.max_texture_size; | 2417 globals->max_texture_size = inputs.max_texture_size; |
2390 globals->device_scale_factor = | 2418 globals->device_scale_factor = |
2391 inputs.device_scale_factor * device_transform_scale; | 2419 inputs.device_scale_factor * device_transform_scale; |
2392 globals->page_scale_factor = inputs.page_scale_factor; | 2420 globals->page_scale_factor = inputs.page_scale_factor; |
2393 globals->page_scale_application_layer = inputs.page_scale_application_layer; | 2421 globals->page_scale_application_layer = inputs.page_scale_application_layer; |
2394 globals->elastic_overscroll = inputs.elastic_overscroll; | 2422 globals->elastic_overscroll = inputs.elastic_overscroll; |
2395 globals->elastic_overscroll_application_layer = | 2423 globals->elastic_overscroll_application_layer = |
2396 inputs.elastic_overscroll_application_layer; | 2424 inputs.elastic_overscroll_application_layer; |
2397 globals->can_render_to_separate_surface = | 2425 globals->can_render_to_separate_surface = |
2398 inputs.can_render_to_separate_surface; | 2426 inputs.can_render_to_separate_surface; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2553 DCHECK(inputs->root_layer->render_surface()); | 2581 DCHECK(inputs->root_layer->render_surface()); |
2554 } | 2582 } |
2555 | 2583 |
2556 void LayerTreeHostCommon::CalculateDrawProperties( | 2584 void LayerTreeHostCommon::CalculateDrawProperties( |
2557 CalcDrawPropsImplInputs* inputs) { | 2585 CalcDrawPropsImplInputs* inputs) { |
2558 LayerImplList dummy_layer_list; | 2586 LayerImplList dummy_layer_list; |
2559 SubtreeGlobals<LayerImpl> globals; | 2587 SubtreeGlobals<LayerImpl> globals; |
2560 DataForRecursion<LayerImpl> data_for_recursion; | 2588 DataForRecursion<LayerImpl> data_for_recursion; |
2561 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2589 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2562 | 2590 |
| 2591 LayerSorter layer_sorter; |
| 2592 globals.layer_sorter = &layer_sorter; |
| 2593 |
2563 PreCalculateMetaInformationRecursiveData recursive_data; | 2594 PreCalculateMetaInformationRecursiveData recursive_data; |
2564 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2595 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2565 std::vector<AccumulatedSurfaceState<LayerImpl>> accumulated_surface_state; | 2596 std::vector<AccumulatedSurfaceState<LayerImpl>> accumulated_surface_state; |
2566 CalculateDrawPropertiesInternal<LayerImpl>( | 2597 CalculateDrawPropertiesInternal<LayerImpl>( |
2567 inputs->root_layer, | 2598 inputs->root_layer, |
2568 globals, | 2599 globals, |
2569 data_for_recursion, | 2600 data_for_recursion, |
2570 inputs->render_surface_layer_list, | 2601 inputs->render_surface_layer_list, |
2571 &dummy_layer_list, | 2602 &dummy_layer_list, |
2572 &accumulated_surface_state, | 2603 &accumulated_surface_state, |
2573 inputs->current_render_surface_layer_list_id); | 2604 inputs->current_render_surface_layer_list_id); |
2574 | 2605 |
2575 // The dummy layer list should not have been used. | 2606 // The dummy layer list should not have been used. |
2576 DCHECK_EQ(0u, dummy_layer_list.size()); | 2607 DCHECK_EQ(0u, dummy_layer_list.size()); |
2577 // A root layer render_surface should always exist after | 2608 // A root layer render_surface should always exist after |
2578 // CalculateDrawProperties. | 2609 // CalculateDrawProperties. |
2579 DCHECK(inputs->root_layer->render_surface()); | 2610 DCHECK(inputs->root_layer->render_surface()); |
2580 } | 2611 } |
2581 | 2612 |
2582 } // namespace cc | 2613 } // namespace cc |
OLD | NEW |