OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/layers/layer_impl.h" | 5 #include "cc/layers/layer_impl.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/numerics/safe_conversions.h" | 8 #include "base/numerics/safe_conversions.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 transform_tree_index_(-1), | 81 transform_tree_index_(-1), |
82 effect_tree_index_(-1), | 82 effect_tree_index_(-1), |
83 clip_tree_index_(-1), | 83 clip_tree_index_(-1), |
84 draw_depth_(0.f), | 84 draw_depth_(0.f), |
85 needs_push_properties_(false), | 85 needs_push_properties_(false), |
86 num_dependents_need_push_properties_(0), | 86 num_dependents_need_push_properties_(0), |
87 sorting_context_id_(0), | 87 sorting_context_id_(0), |
88 current_draw_mode_(DRAW_MODE_NONE), | 88 current_draw_mode_(DRAW_MODE_NONE), |
89 element_id_(0), | 89 element_id_(0), |
90 mutable_properties_(kMutablePropertyNone), | 90 mutable_properties_(kMutablePropertyNone), |
| 91 force_render_surface_(false), |
91 num_layer_or_descendants_with_copy_request_(0), | 92 num_layer_or_descendants_with_copy_request_(0), |
92 frame_timing_requests_dirty_(false), | 93 frame_timing_requests_dirty_(false), |
93 visited_(false), | 94 visited_(false), |
94 layer_or_descendant_is_drawn_(false), | 95 layer_or_descendant_is_drawn_(false), |
95 layer_or_descendant_has_input_handler_(false), | 96 layer_or_descendant_has_input_handler_(false), |
96 sorted_for_recursion_(false) { | 97 sorted_for_recursion_(false) { |
97 DCHECK_GT(layer_id_, 0); | 98 DCHECK_GT(layer_id_, 0); |
98 DCHECK(layer_tree_impl_); | 99 DCHECK(layer_tree_impl_); |
99 layer_tree_impl_->RegisterLayer(this); | 100 layer_tree_impl_->RegisterLayer(this); |
100 | 101 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 // handle preserving these output requests (and their surface). | 274 // handle preserving these output requests (and their surface). |
274 if (!copy_requests_.empty()) { | 275 if (!copy_requests_.empty()) { |
275 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); | 276 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); |
276 // Destroying these will abort them. | 277 // Destroying these will abort them. |
277 copy_requests_.clear(); | 278 copy_requests_.clear(); |
278 } | 279 } |
279 | 280 |
280 if (requests->empty()) | 281 if (requests->empty()) |
281 return; | 282 return; |
282 | 283 |
283 DCHECK(render_surface()); | |
284 bool was_empty = copy_requests_.empty(); | 284 bool was_empty = copy_requests_.empty(); |
285 for (auto& request : *requests) | 285 for (auto& request : *requests) |
286 copy_requests_.push_back(std::move(request)); | 286 copy_requests_.push_back(std::move(request)); |
287 requests->clear(); | 287 requests->clear(); |
288 | 288 |
289 if (was_empty && layer_tree_impl()->IsActiveTree()) | 289 if (was_empty && layer_tree_impl()->IsActiveTree()) |
290 layer_tree_impl()->AddLayerWithCopyOutputRequest(this); | 290 layer_tree_impl()->AddLayerWithCopyOutputRequest(this); |
291 NoteLayerPropertyChangedForSubtree(); | 291 NoteLayerPropertyChangedForSubtree(); |
292 } | 292 } |
293 | 293 |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_); | 566 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_); |
567 } | 567 } |
568 | 568 |
569 void LayerImpl::PushPropertiesTo(LayerImpl* layer) { | 569 void LayerImpl::PushPropertiesTo(LayerImpl* layer) { |
570 layer->SetTransformOrigin(transform_origin_); | 570 layer->SetTransformOrigin(transform_origin_); |
571 layer->SetBackgroundColor(background_color_); | 571 layer->SetBackgroundColor(background_color_); |
572 layer->SetBounds(bounds_); | 572 layer->SetBounds(bounds_); |
573 layer->SetDoubleSided(double_sided_); | 573 layer->SetDoubleSided(double_sided_); |
574 layer->SetDrawsContent(DrawsContent()); | 574 layer->SetDrawsContent(DrawsContent()); |
575 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_); | 575 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_); |
| 576 // If whether layer has render surface changes, we need to update draw |
| 577 // properties. |
| 578 // TODO(weiliangc): Should be safely removed after impl side is able to |
| 579 // update render surfaces without rebuilding property trees. |
| 580 if (layer->has_render_surface() != has_render_surface()) |
| 581 layer->layer_tree_impl()->set_needs_update_draw_properties(); |
576 layer->SetHasRenderSurface(!!render_surface()); | 582 layer->SetHasRenderSurface(!!render_surface()); |
| 583 layer->SetForceRenderSurface(force_render_surface_); |
577 layer->SetFilters(filters()); | 584 layer->SetFilters(filters()); |
578 layer->SetBackgroundFilters(background_filters()); | 585 layer->SetBackgroundFilters(background_filters()); |
579 layer->SetMasksToBounds(masks_to_bounds_); | 586 layer->SetMasksToBounds(masks_to_bounds_); |
580 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_); | 587 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_); |
581 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_); | 588 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_); |
582 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_); | 589 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_); |
583 layer->SetScrollBlocksOn(scroll_blocks_on_); | 590 layer->SetScrollBlocksOn(scroll_blocks_on_); |
584 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); | 591 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); |
585 layer->SetTouchEventHandlerRegion(touch_event_handler_region_); | 592 layer->SetTouchEventHandlerRegion(touch_event_handler_region_); |
586 layer->SetContentsOpaque(contents_opaque_); | 593 layer->SetContentsOpaque(contents_opaque_); |
(...skipping 761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1348 if (!layer_animation_controller_) | 1355 if (!layer_animation_controller_) |
1349 return layer_tree_impl_->HasOnlyTranslationTransforms(this); | 1356 return layer_tree_impl_->HasOnlyTranslationTransforms(this); |
1350 | 1357 |
1351 LayerAnimationController::ObserverType observer_type = | 1358 LayerAnimationController::ObserverType observer_type = |
1352 IsActive() ? LayerAnimationController::ObserverType::ACTIVE | 1359 IsActive() ? LayerAnimationController::ObserverType::ACTIVE |
1353 : LayerAnimationController::ObserverType::PENDING; | 1360 : LayerAnimationController::ObserverType::PENDING; |
1354 return layer_animation_controller_->HasOnlyTranslationTransforms( | 1361 return layer_animation_controller_->HasOnlyTranslationTransforms( |
1355 observer_type); | 1362 observer_type); |
1356 } | 1363 } |
1357 | 1364 |
| 1365 bool LayerImpl::AnimationsPreserveAxisAlignment() const { |
| 1366 return layer_animation_controller_ |
| 1367 ? layer_animation_controller_->AnimationsPreserveAxisAlignment() |
| 1368 : layer_tree_impl_->AnimationsPreserveAxisAlignment(this); |
| 1369 } |
| 1370 |
1358 bool LayerImpl::MaximumTargetScale(float* max_scale) const { | 1371 bool LayerImpl::MaximumTargetScale(float* max_scale) const { |
1359 if (!layer_animation_controller_) | 1372 if (!layer_animation_controller_) |
1360 return layer_tree_impl_->MaximumTargetScale(this, max_scale); | 1373 return layer_tree_impl_->MaximumTargetScale(this, max_scale); |
1361 | 1374 |
1362 LayerAnimationController::ObserverType observer_type = | 1375 LayerAnimationController::ObserverType observer_type = |
1363 IsActive() ? LayerAnimationController::ObserverType::ACTIVE | 1376 IsActive() ? LayerAnimationController::ObserverType::ACTIVE |
1364 : LayerAnimationController::ObserverType::PENDING; | 1377 : LayerAnimationController::ObserverType::PENDING; |
1365 return layer_animation_controller_->MaximumTargetScale(observer_type, | 1378 return layer_animation_controller_->MaximumTargetScale(observer_type, |
1366 max_scale); | 1379 max_scale); |
1367 } | 1380 } |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1792 int group) { | 1805 int group) { |
1793 if (target_property == Animation::SCROLL_OFFSET) | 1806 if (target_property == Animation::SCROLL_OFFSET) |
1794 layer_tree_impl_->InputScrollAnimationFinished(); | 1807 layer_tree_impl_->InputScrollAnimationFinished(); |
1795 } | 1808 } |
1796 | 1809 |
1797 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { | 1810 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { |
1798 if (!!render_surface() == should_have_render_surface) | 1811 if (!!render_surface() == should_have_render_surface) |
1799 return; | 1812 return; |
1800 | 1813 |
1801 SetNeedsPushProperties(); | 1814 SetNeedsPushProperties(); |
1802 layer_tree_impl()->set_needs_update_draw_properties(); | |
1803 if (should_have_render_surface) { | 1815 if (should_have_render_surface) { |
1804 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this)); | 1816 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this)); |
1805 return; | 1817 return; |
1806 } | 1818 } |
1807 render_surface_.reset(); | 1819 render_surface_.reset(); |
1808 } | 1820 } |
1809 | 1821 |
1810 gfx::Transform LayerImpl::DrawTransform() const { | 1822 gfx::Transform LayerImpl::DrawTransform() const { |
1811 // Only drawn layers have up-to-date draw properties when property trees are | 1823 // Only drawn layers have up-to-date draw properties when property trees are |
1812 // enabled. | 1824 // enabled. |
(...skipping 16 matching lines...) Expand all Loading... |
1829 // enabled. | 1841 // enabled. |
1830 if (layer_tree_impl()->settings().use_property_trees && | 1842 if (layer_tree_impl()->settings().use_property_trees && |
1831 !IsDrawnRenderSurfaceLayerListMember()) { | 1843 !IsDrawnRenderSurfaceLayerListMember()) { |
1832 return ScreenSpaceTransformFromPropertyTrees( | 1844 return ScreenSpaceTransformFromPropertyTrees( |
1833 this, layer_tree_impl()->property_trees()->transform_tree); | 1845 this, layer_tree_impl()->property_trees()->transform_tree); |
1834 } | 1846 } |
1835 | 1847 |
1836 return draw_properties().screen_space_transform; | 1848 return draw_properties().screen_space_transform; |
1837 } | 1849 } |
1838 | 1850 |
| 1851 void LayerImpl::SetForceRenderSurface(bool force_render_surface) { |
| 1852 if (force_render_surface == force_render_surface_) |
| 1853 return; |
| 1854 |
| 1855 force_render_surface_ = force_render_surface; |
| 1856 NoteLayerPropertyChanged(); |
| 1857 } |
| 1858 |
1839 Region LayerImpl::GetInvalidationRegion() { | 1859 Region LayerImpl::GetInvalidationRegion() { |
1840 return Region(update_rect_); | 1860 return Region(update_rect_); |
1841 } | 1861 } |
1842 | 1862 |
1843 gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const { | 1863 gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const { |
1844 return MathUtil::MapEnclosingClippedRect(DrawTransform(), | 1864 return MathUtil::MapEnclosingClippedRect(DrawTransform(), |
1845 gfx::Rect(bounds())); | 1865 gfx::Rect(bounds())); |
1846 } | 1866 } |
1847 | 1867 |
1848 gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { | 1868 gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { |
(...skipping 16 matching lines...) Expand all Loading... |
1865 .layer_transforms_should_scale_layer_contents) { | 1885 .layer_transforms_should_scale_layer_contents) { |
1866 return default_scale; | 1886 return default_scale; |
1867 } | 1887 } |
1868 | 1888 |
1869 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1889 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
1870 DrawTransform(), default_scale); | 1890 DrawTransform(), default_scale); |
1871 return std::max(transform_scales.x(), transform_scales.y()); | 1891 return std::max(transform_scales.x(), transform_scales.y()); |
1872 } | 1892 } |
1873 | 1893 |
1874 } // namespace cc | 1894 } // namespace cc |
OLD | NEW |