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 1191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 layer->draw_properties().num_unclipped_descendants = | 1234 layer->draw_properties().num_unclipped_descendants = |
1250 recursive_data->num_unclipped_descendants; | 1235 recursive_data->num_unclipped_descendants; |
1251 layer->draw_properties().layer_or_descendant_has_copy_request = | 1236 layer->draw_properties().layer_or_descendant_has_copy_request = |
1252 recursive_data->layer_or_descendant_has_copy_request; | 1237 recursive_data->layer_or_descendant_has_copy_request; |
1253 layer->draw_properties().layer_or_descendant_has_input_handler = | 1238 layer->draw_properties().layer_or_descendant_has_input_handler = |
1254 recursive_data->layer_or_descendant_has_input_handler; | 1239 recursive_data->layer_or_descendant_has_input_handler; |
1255 } | 1240 } |
1256 | 1241 |
1257 template <typename LayerType> | 1242 template <typename LayerType> |
1258 struct SubtreeGlobals { | 1243 struct SubtreeGlobals { |
1259 LayerSorter* layer_sorter; | |
1260 int max_texture_size; | 1244 int max_texture_size; |
1261 float device_scale_factor; | 1245 float device_scale_factor; |
1262 float page_scale_factor; | 1246 float page_scale_factor; |
1263 const LayerType* page_scale_application_layer; | 1247 const LayerType* page_scale_application_layer; |
1264 gfx::Vector2dF elastic_overscroll; | 1248 gfx::Vector2dF elastic_overscroll; |
1265 const LayerType* elastic_overscroll_application_layer; | 1249 const LayerType* elastic_overscroll_application_layer; |
1266 bool can_adjust_raster_scales; | 1250 bool can_adjust_raster_scales; |
1267 bool can_render_to_separate_surface; | 1251 bool can_render_to_separate_surface; |
1268 bool layers_always_allowed_lcd_text; | 1252 bool layers_always_allowed_lcd_text; |
1269 }; | 1253 }; |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2332 } | 2316 } |
2333 | 2317 |
2334 SavePaintPropertiesLayer(layer); | 2318 SavePaintPropertiesLayer(layer); |
2335 | 2319 |
2336 // If neither this layer nor any of its children were added, early out. | 2320 // If neither this layer nor any of its children were added, early out. |
2337 if (sorting_start_index == descendants.size()) { | 2321 if (sorting_start_index == descendants.size()) { |
2338 DCHECK(!render_to_separate_surface || IsRootLayer(layer)); | 2322 DCHECK(!render_to_separate_surface || IsRootLayer(layer)); |
2339 return; | 2323 return; |
2340 } | 2324 } |
2341 | 2325 |
2342 // If preserves-3d then sort all the descendants in 3D so that they can be | |
2343 // drawn from back to front. If the preserves-3d property is also set on the | |
2344 // parent then skip the sorting as the parent will sort all the descendants | |
2345 // anyway. | |
2346 if (globals.layer_sorter && descendants.size() && layer->Is3dSorted() && | |
2347 !LayerIsInExisting3DRenderingContext(layer)) { | |
2348 SortLayers(descendants.begin() + sorting_start_index, | |
2349 descendants.end(), | |
2350 globals.layer_sorter); | |
2351 } | |
2352 | |
2353 UpdateAccumulatedSurfaceState<LayerType>( | 2326 UpdateAccumulatedSurfaceState<LayerType>( |
2354 layer, local_drawable_content_rect_of_subtree, accumulated_surface_state); | 2327 layer, local_drawable_content_rect_of_subtree, accumulated_surface_state); |
2355 | 2328 |
2356 if (layer->HasContributingDelegatedRenderPasses()) { | 2329 if (layer->HasContributingDelegatedRenderPasses()) { |
2357 layer->render_target()->render_surface()-> | 2330 layer->render_target()->render_surface()-> |
2358 AddContributingDelegatedRenderPassLayer(layer); | 2331 AddContributingDelegatedRenderPassLayer(layer); |
2359 } | 2332 } |
2360 } // NOLINT(readability/fn_size) | 2333 } // NOLINT(readability/fn_size) |
2361 | 2334 |
2362 template <typename LayerType, typename RenderSurfaceLayerListType> | 2335 template <typename LayerType, typename RenderSurfaceLayerListType> |
(...skipping 17 matching lines...) Expand all Loading... |
2380 MathUtil::ComputeTransform2dScaleComponents(inputs.device_transform, 1.f); | 2353 MathUtil::ComputeTransform2dScaleComponents(inputs.device_transform, 1.f); |
2381 // Not handling the rare case of different x and y device scale. | 2354 // Not handling the rare case of different x and y device scale. |
2382 float device_transform_scale = | 2355 float device_transform_scale = |
2383 std::max(device_transform_scale_components.x(), | 2356 std::max(device_transform_scale_components.x(), |
2384 device_transform_scale_components.y()); | 2357 device_transform_scale_components.y()); |
2385 | 2358 |
2386 gfx::Transform scaled_device_transform = inputs.device_transform; | 2359 gfx::Transform scaled_device_transform = inputs.device_transform; |
2387 scaled_device_transform.Scale(inputs.device_scale_factor, | 2360 scaled_device_transform.Scale(inputs.device_scale_factor, |
2388 inputs.device_scale_factor); | 2361 inputs.device_scale_factor); |
2389 | 2362 |
2390 globals->layer_sorter = NULL; | |
2391 globals->max_texture_size = inputs.max_texture_size; | 2363 globals->max_texture_size = inputs.max_texture_size; |
2392 globals->device_scale_factor = | 2364 globals->device_scale_factor = |
2393 inputs.device_scale_factor * device_transform_scale; | 2365 inputs.device_scale_factor * device_transform_scale; |
2394 globals->page_scale_factor = inputs.page_scale_factor; | 2366 globals->page_scale_factor = inputs.page_scale_factor; |
2395 globals->page_scale_application_layer = inputs.page_scale_application_layer; | 2367 globals->page_scale_application_layer = inputs.page_scale_application_layer; |
2396 globals->elastic_overscroll = inputs.elastic_overscroll; | 2368 globals->elastic_overscroll = inputs.elastic_overscroll; |
2397 globals->elastic_overscroll_application_layer = | 2369 globals->elastic_overscroll_application_layer = |
2398 inputs.elastic_overscroll_application_layer; | 2370 inputs.elastic_overscroll_application_layer; |
2399 globals->can_render_to_separate_surface = | 2371 globals->can_render_to_separate_surface = |
2400 inputs.can_render_to_separate_surface; | 2372 inputs.can_render_to_separate_surface; |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2535 } | 2507 } |
2536 } | 2508 } |
2537 | 2509 |
2538 void LayerTreeHostCommon::CalculateDrawProperties( | 2510 void LayerTreeHostCommon::CalculateDrawProperties( |
2539 CalcDrawPropsImplInputs* inputs) { | 2511 CalcDrawPropsImplInputs* inputs) { |
2540 LayerImplList dummy_layer_list; | 2512 LayerImplList dummy_layer_list; |
2541 SubtreeGlobals<LayerImpl> globals; | 2513 SubtreeGlobals<LayerImpl> globals; |
2542 DataForRecursion<LayerImpl> data_for_recursion; | 2514 DataForRecursion<LayerImpl> data_for_recursion; |
2543 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); | 2515 ProcessCalcDrawPropsInputs(*inputs, &globals, &data_for_recursion); |
2544 | 2516 |
2545 LayerSorter layer_sorter; | |
2546 globals.layer_sorter = &layer_sorter; | |
2547 | |
2548 PreCalculateMetaInformationRecursiveData recursive_data; | 2517 PreCalculateMetaInformationRecursiveData recursive_data; |
2549 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); | 2518 PreCalculateMetaInformation(inputs->root_layer, &recursive_data); |
2550 std::vector<AccumulatedSurfaceState<LayerImpl>> accumulated_surface_state; | 2519 std::vector<AccumulatedSurfaceState<LayerImpl>> accumulated_surface_state; |
2551 CalculateDrawPropertiesInternal<LayerImpl>( | 2520 CalculateDrawPropertiesInternal<LayerImpl>( |
2552 inputs->root_layer, | 2521 inputs->root_layer, |
2553 globals, | 2522 globals, |
2554 data_for_recursion, | 2523 data_for_recursion, |
2555 inputs->render_surface_layer_list, | 2524 inputs->render_surface_layer_list, |
2556 &dummy_layer_list, | 2525 &dummy_layer_list, |
2557 &accumulated_surface_state, | 2526 &accumulated_surface_state, |
2558 inputs->current_render_surface_layer_list_id); | 2527 inputs->current_render_surface_layer_list_id); |
2559 | 2528 |
2560 // The dummy layer list should not have been used. | 2529 // The dummy layer list should not have been used. |
2561 DCHECK_EQ(0u, dummy_layer_list.size()); | 2530 DCHECK_EQ(0u, dummy_layer_list.size()); |
2562 // A root layer render_surface should always exist after | 2531 // A root layer render_surface should always exist after |
2563 // CalculateDrawProperties. | 2532 // CalculateDrawProperties. |
2564 DCHECK(inputs->root_layer->render_surface()); | 2533 DCHECK(inputs->root_layer->render_surface()); |
2565 } | 2534 } |
2566 | 2535 |
2567 } // namespace cc | 2536 } // namespace cc |
OLD | NEW |