| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 void LayerImpl::SetClipTreeIndex(int index) { | 146 void LayerImpl::SetClipTreeIndex(int index) { |
| 147 clip_tree_index_ = index; | 147 clip_tree_index_ = index; |
| 148 } | 148 } |
| 149 | 149 |
| 150 void LayerImpl::SetEffectTreeIndex(int index) { | 150 void LayerImpl::SetEffectTreeIndex(int index) { |
| 151 effect_tree_index_ = index; | 151 effect_tree_index_ = index; |
| 152 } | 152 } |
| 153 | 153 |
| 154 int LayerImpl::render_target_effect_tree_index() const { | 154 int LayerImpl::render_target_effect_tree_index() const { |
| 155 EffectNode* effect_node = GetEffectTree().Node(effect_tree_index_); | 155 EffectNode* effect_node = GetEffectTree().Node(effect_tree_index_); |
| 156 return effect_node->render_surface ? effect_node->id : effect_node->target_id; | 156 |
| 157 return GetEffectTree().GetRenderSurface(effect_tree_index_) |
| 158 ? effect_node->id |
| 159 : effect_node->target_id; |
| 157 } | 160 } |
| 158 | 161 |
| 159 void LayerImpl::SetScrollTreeIndex(int index) { | 162 void LayerImpl::SetScrollTreeIndex(int index) { |
| 160 scroll_tree_index_ = index; | 163 scroll_tree_index_ = index; |
| 161 } | 164 } |
| 162 | 165 |
| 163 void LayerImpl::ClearRenderSurfaceLayerList() { | |
| 164 if (render_surface_) | |
| 165 render_surface_->ClearLayerLists(); | |
| 166 } | |
| 167 | |
| 168 void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const { | 166 void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const { |
| 169 state->SetAll(draw_properties_.target_space_transform, bounds(), | 167 state->SetAll(draw_properties_.target_space_transform, bounds(), |
| 170 draw_properties_.visible_layer_rect, draw_properties_.clip_rect, | 168 draw_properties_.visible_layer_rect, draw_properties_.clip_rect, |
| 171 draw_properties_.is_clipped, draw_properties_.opacity, | 169 draw_properties_.is_clipped, draw_properties_.opacity, |
| 172 draw_blend_mode_, GetSortingContextId()); | 170 draw_blend_mode_, GetSortingContextId()); |
| 173 } | 171 } |
| 174 | 172 |
| 175 void LayerImpl::PopulateScaledSharedQuadState( | 173 void LayerImpl::PopulateScaledSharedQuadState( |
| 176 SharedQuadState* state, | 174 SharedQuadState* state, |
| 177 float layer_to_content_scale_x, | 175 float layer_to_content_scale_x, |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 layer->clip_tree_index_ = clip_tree_index_; | 351 layer->clip_tree_index_ = clip_tree_index_; |
| 354 layer->scroll_tree_index_ = scroll_tree_index_; | 352 layer->scroll_tree_index_ = scroll_tree_index_; |
| 355 layer->has_will_change_transform_hint_ = has_will_change_transform_hint_; | 353 layer->has_will_change_transform_hint_ = has_will_change_transform_hint_; |
| 356 layer->scrollbars_hidden_ = scrollbars_hidden_; | 354 layer->scrollbars_hidden_ = scrollbars_hidden_; |
| 357 | 355 |
| 358 if (layer_property_changed_) { | 356 if (layer_property_changed_) { |
| 359 layer->layer_tree_impl()->set_needs_update_draw_properties(); | 357 layer->layer_tree_impl()->set_needs_update_draw_properties(); |
| 360 layer->layer_property_changed_ = true; | 358 layer->layer_property_changed_ = true; |
| 361 } | 359 } |
| 362 | 360 |
| 363 // If whether layer has render surface changes, we need to update draw | |
| 364 // properties. | |
| 365 // TODO(weiliangc): Should be safely removed after impl side is able to | |
| 366 // update render surfaces without rebuilding property trees. | |
| 367 if (layer->has_render_surface() != has_render_surface()) | |
| 368 layer->layer_tree_impl()->set_needs_update_draw_properties(); | |
| 369 layer->SetBounds(bounds_); | 361 layer->SetBounds(bounds_); |
| 370 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 362 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
| 371 layer->SetElementId(element_id_); | 363 layer->SetElementId(element_id_); |
| 372 layer->SetMutableProperties(mutable_properties_); | 364 layer->SetMutableProperties(mutable_properties_); |
| 373 | 365 |
| 374 // If the main thread commits multiple times before the impl thread actually | 366 // If the main thread commits multiple times before the impl thread actually |
| 375 // draws, then damage tracking will become incorrect if we simply clobber the | 367 // draws, then damage tracking will become incorrect if we simply clobber the |
| 376 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. | 368 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. |
| 377 // union) any update changes that have occurred on the main thread. | 369 // union) any update changes that have occurred on the main thread. |
| 378 update_rect_.Union(layer->update_rect()); | 370 update_rect_.Union(layer->update_rect()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 const char* LayerImpl::LayerTypeAsString() const { | 474 const char* LayerImpl::LayerTypeAsString() const { |
| 483 return "cc::LayerImpl"; | 475 return "cc::LayerImpl"; |
| 484 } | 476 } |
| 485 | 477 |
| 486 void LayerImpl::ResetChangeTracking() { | 478 void LayerImpl::ResetChangeTracking() { |
| 487 layer_property_changed_ = false; | 479 layer_property_changed_ = false; |
| 488 needs_push_properties_ = false; | 480 needs_push_properties_ = false; |
| 489 | 481 |
| 490 update_rect_.SetRect(0, 0, 0, 0); | 482 update_rect_.SetRect(0, 0, 0, 0); |
| 491 damage_rect_.SetRect(0, 0, 0, 0); | 483 damage_rect_.SetRect(0, 0, 0, 0); |
| 492 | |
| 493 if (render_surface_) | |
| 494 render_surface_->ResetPropertyChangedFlags(); | |
| 495 } | 484 } |
| 496 | 485 |
| 497 int LayerImpl::num_copy_requests_in_target_subtree() { | 486 int LayerImpl::num_copy_requests_in_target_subtree() { |
| 498 return GetEffectTree() | 487 return GetEffectTree() |
| 499 .Node(effect_tree_index()) | 488 .Node(effect_tree_index()) |
| 500 ->num_copy_requests_in_subtree; | 489 ->num_copy_requests_in_subtree; |
| 501 } | 490 } |
| 502 | 491 |
| 503 void LayerImpl::UpdatePropertyTreeTransformIsAnimated(bool is_animated) { | 492 void LayerImpl::UpdatePropertyTreeTransformIsAnimated(bool is_animated) { |
| 504 PropertyTrees* property_trees = GetPropertyTrees(); | 493 PropertyTrees* property_trees = GetPropertyTrees(); |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 } | 955 } |
| 967 } | 956 } |
| 968 } | 957 } |
| 969 | 958 |
| 970 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } | 959 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } |
| 971 | 960 |
| 972 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { | 961 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
| 973 benchmark->RunOnLayer(this); | 962 benchmark->RunOnLayer(this); |
| 974 } | 963 } |
| 975 | 964 |
| 976 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { | |
| 977 if (!!render_surface() == should_have_render_surface) | |
| 978 return; | |
| 979 | |
| 980 if (should_have_render_surface) { | |
| 981 render_surface_ = base::MakeUnique<RenderSurfaceImpl>(this); | |
| 982 return; | |
| 983 } | |
| 984 render_surface_.reset(); | |
| 985 } | |
| 986 | |
| 987 gfx::Transform LayerImpl::DrawTransform() const { | 965 gfx::Transform LayerImpl::DrawTransform() const { |
| 988 // Only drawn layers have up-to-date draw properties. | 966 // Only drawn layers have up-to-date draw properties. |
| 989 if (!is_drawn_render_surface_layer_list_member()) { | 967 if (!is_drawn_render_surface_layer_list_member()) { |
| 990 if (GetPropertyTrees()->non_root_surfaces_enabled) { | 968 if (GetPropertyTrees()->non_root_surfaces_enabled) { |
| 991 return draw_property_utils::DrawTransform(this, GetTransformTree(), | 969 return draw_property_utils::DrawTransform(this, GetTransformTree(), |
| 992 GetEffectTree()); | 970 GetEffectTree()); |
| 993 } else { | 971 } else { |
| 994 return draw_property_utils::ScreenSpaceTransform(this, | 972 return draw_property_utils::ScreenSpaceTransform(this, |
| 995 GetTransformTree()); | 973 GetTransformTree()); |
| 996 } | 974 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 } | 1023 } |
| 1046 | 1024 |
| 1047 gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { | 1025 gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { |
| 1048 gfx::Transform scaled_draw_transform = DrawTransform(); | 1026 gfx::Transform scaled_draw_transform = DrawTransform(); |
| 1049 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); | 1027 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); |
| 1050 gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(bounds(), scale); | 1028 gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(bounds(), scale); |
| 1051 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, | 1029 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, |
| 1052 gfx::Rect(scaled_bounds)); | 1030 gfx::Rect(scaled_bounds)); |
| 1053 } | 1031 } |
| 1054 | 1032 |
| 1033 RenderSurfaceImpl* LayerImpl::render_surface() const { |
| 1034 EffectNode* effect_node = GetEffectTree().Node(effect_tree_index_); |
| 1035 if (effect_node->owning_layer_id == id()) |
| 1036 return GetEffectTree().GetRenderSurface(effect_tree_index_); |
| 1037 return nullptr; |
| 1038 } |
| 1039 |
| 1055 RenderSurfaceImpl* LayerImpl::render_target() { | 1040 RenderSurfaceImpl* LayerImpl::render_target() { |
| 1056 return GetEffectTree() | 1041 return GetEffectTree().GetRenderSurface(render_target_effect_tree_index()); |
| 1057 .Node(render_target_effect_tree_index()) | |
| 1058 ->render_surface; | |
| 1059 } | 1042 } |
| 1060 | 1043 |
| 1061 const RenderSurfaceImpl* LayerImpl::render_target() const { | 1044 const RenderSurfaceImpl* LayerImpl::render_target() const { |
| 1062 return GetEffectTree() | 1045 return GetEffectTree().GetRenderSurface(render_target_effect_tree_index()); |
| 1063 .Node(render_target_effect_tree_index()) | |
| 1064 ->render_surface; | |
| 1065 } | 1046 } |
| 1066 | 1047 |
| 1067 bool LayerImpl::IsHidden() const { | 1048 bool LayerImpl::IsHidden() const { |
| 1068 EffectNode* node = GetEffectTree().Node(effect_tree_index_); | 1049 EffectNode* node = GetEffectTree().Node(effect_tree_index_); |
| 1069 return node->screen_space_opacity == 0.f; | 1050 return node->screen_space_opacity == 0.f; |
| 1070 } | 1051 } |
| 1071 | 1052 |
| 1072 float LayerImpl::GetIdealContentsScale() const { | 1053 float LayerImpl::GetIdealContentsScale() const { |
| 1073 float page_scale = IsAffectedByPageScale() | 1054 float page_scale = IsAffectedByPageScale() |
| 1074 ? layer_tree_impl()->current_page_scale_factor() | 1055 ? layer_tree_impl()->current_page_scale_factor() |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1097 | 1078 |
| 1098 ScrollTree& LayerImpl::GetScrollTree() const { | 1079 ScrollTree& LayerImpl::GetScrollTree() const { |
| 1099 return GetPropertyTrees()->scroll_tree; | 1080 return GetPropertyTrees()->scroll_tree; |
| 1100 } | 1081 } |
| 1101 | 1082 |
| 1102 TransformTree& LayerImpl::GetTransformTree() const { | 1083 TransformTree& LayerImpl::GetTransformTree() const { |
| 1103 return GetPropertyTrees()->transform_tree; | 1084 return GetPropertyTrees()->transform_tree; |
| 1104 } | 1085 } |
| 1105 | 1086 |
| 1106 } // namespace cc | 1087 } // namespace cc |
| OLD | NEW |