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/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/debug/trace_event_argument.h" | 8 #include "base/debug/trace_event_argument.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 transform_is_invertible_(true), | 62 transform_is_invertible_(true), |
63 is_container_for_fixed_position_layers_(false), | 63 is_container_for_fixed_position_layers_(false), |
64 background_color_(0), | 64 background_color_(0), |
65 opacity_(1.0), | 65 opacity_(1.0), |
66 blend_mode_(SkXfermode::kSrcOver_Mode), | 66 blend_mode_(SkXfermode::kSrcOver_Mode), |
67 num_descendants_that_draw_content_(0), | 67 num_descendants_that_draw_content_(0), |
68 draw_depth_(0.f), | 68 draw_depth_(0.f), |
69 needs_push_properties_(false), | 69 needs_push_properties_(false), |
70 num_dependents_need_push_properties_(0), | 70 num_dependents_need_push_properties_(0), |
71 sorting_context_id_(0), | 71 sorting_context_id_(0), |
72 current_draw_mode_(DRAW_MODE_NONE) { | 72 current_draw_mode_(DRAW_MODE_NONE), |
| 73 active_render_surface_(NULL) { |
73 DCHECK_GT(layer_id_, 0); | 74 DCHECK_GT(layer_id_, 0); |
74 DCHECK(layer_tree_impl_); | 75 DCHECK(layer_tree_impl_); |
75 layer_tree_impl_->RegisterLayer(this); | 76 layer_tree_impl_->RegisterLayer(this); |
76 AnimationRegistrar* registrar = layer_tree_impl_->animationRegistrar(); | 77 AnimationRegistrar* registrar = layer_tree_impl_->animationRegistrar(); |
77 layer_animation_controller_ = | 78 layer_animation_controller_ = |
78 registrar->GetAnimationControllerForId(layer_id_); | 79 registrar->GetAnimationControllerForId(layer_id_); |
79 layer_animation_controller_->AddValueObserver(this); | 80 layer_animation_controller_->AddValueObserver(this); |
80 if (IsActive()) { | 81 if (IsActive()) { |
81 layer_animation_controller_->set_value_provider(this); | 82 layer_animation_controller_->set_value_provider(this); |
82 layer_animation_controller_->set_layer_animation_delegate(this); | 83 layer_animation_controller_->set_layer_animation_delegate(this); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 gfx::Rect request_in_content_space = | 231 gfx::Rect request_in_content_space = |
231 LayerRectToContentRect(request_in_layer_space); | 232 LayerRectToContentRect(request_in_layer_space); |
232 request->set_area(MathUtil::MapEnclosingClippedRect( | 233 request->set_area(MathUtil::MapEnclosingClippedRect( |
233 draw_properties_.target_space_transform, request_in_content_space)); | 234 draw_properties_.target_space_transform, request_in_content_space)); |
234 } | 235 } |
235 | 236 |
236 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); | 237 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); |
237 } | 238 } |
238 | 239 |
239 void LayerImpl::CreateRenderSurface() { | 240 void LayerImpl::CreateRenderSurface() { |
240 DCHECK(!draw_properties_.render_surface); | 241 DCHECK(!render_surface_); |
241 draw_properties_.render_surface = | 242 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this)); |
242 make_scoped_ptr(new RenderSurfaceImpl(this)); | |
243 draw_properties_.render_target = this; | 243 draw_properties_.render_target = this; |
| 244 SetRenderSurfaceActive(true); |
244 } | 245 } |
245 | 246 |
246 void LayerImpl::ClearRenderSurface() { | 247 void LayerImpl::ClearRenderSurface() { |
247 draw_properties_.render_surface.reset(); | 248 SetRenderSurfaceActive(false); |
| 249 render_surface_.reset(); |
248 } | 250 } |
249 | 251 |
250 void LayerImpl::ClearRenderSurfaceLayerList() { | 252 void LayerImpl::ClearRenderSurfaceLayerList() { |
251 if (draw_properties_.render_surface) | 253 if (render_surface_) |
252 draw_properties_.render_surface->layer_list().clear(); | 254 render_surface_->layer_list().clear(); |
253 } | 255 } |
254 | 256 |
255 void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const { | 257 void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const { |
256 state->SetAll(draw_properties_.target_space_transform, | 258 state->SetAll(draw_properties_.target_space_transform, |
257 draw_properties_.content_bounds, | 259 draw_properties_.content_bounds, |
258 draw_properties_.visible_content_rect, | 260 draw_properties_.visible_content_rect, |
259 draw_properties_.clip_rect, | 261 draw_properties_.clip_rect, |
260 draw_properties_.is_clipped, | 262 draw_properties_.is_clipped, |
261 draw_properties_.opacity, | 263 draw_properties_.opacity, |
262 blend_mode_, | 264 blend_mode_, |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 536 |
535 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() | 537 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() |
536 : Layer::INVALID_ID); | 538 : Layer::INVALID_ID); |
537 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 539 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
538 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 540 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
539 layer->SetScrollOffsetAndDelta( | 541 layer->SetScrollOffsetAndDelta( |
540 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); | 542 scroll_offset_, layer->ScrollDelta() - layer->sent_scroll_delta()); |
541 layer->SetSentScrollDelta(gfx::Vector2d()); | 543 layer->SetSentScrollDelta(gfx::Vector2d()); |
542 layer->Set3dSortingContextId(sorting_context_id_); | 544 layer->Set3dSortingContextId(sorting_context_id_); |
543 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | 545 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); |
| 546 layer->SetShouldHaveRenderSurface(ShouldHaveRenderSurface()); |
544 | 547 |
545 LayerImpl* scroll_parent = NULL; | 548 LayerImpl* scroll_parent = NULL; |
546 if (scroll_parent_) { | 549 if (scroll_parent_) { |
547 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 550 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
548 DCHECK(scroll_parent); | 551 DCHECK(scroll_parent); |
549 } | 552 } |
550 | 553 |
551 layer->SetScrollParent(scroll_parent); | 554 layer->SetScrollParent(scroll_parent); |
552 if (scroll_children_) { | 555 if (scroll_children_) { |
553 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 556 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 const char* LayerImpl::LayerTypeAsString() const { | 713 const char* LayerImpl::LayerTypeAsString() const { |
711 return "cc::LayerImpl"; | 714 return "cc::LayerImpl"; |
712 } | 715 } |
713 | 716 |
714 void LayerImpl::ResetAllChangeTrackingForSubtree() { | 717 void LayerImpl::ResetAllChangeTrackingForSubtree() { |
715 layer_property_changed_ = false; | 718 layer_property_changed_ = false; |
716 | 719 |
717 update_rect_ = gfx::RectF(); | 720 update_rect_ = gfx::RectF(); |
718 damage_rect_ = gfx::RectF(); | 721 damage_rect_ = gfx::RectF(); |
719 | 722 |
720 if (draw_properties_.render_surface) | 723 if (render_surface_) |
721 draw_properties_.render_surface->ResetPropertyChangedFlag(); | 724 render_surface_->ResetPropertyChangedFlag(); |
722 | 725 |
723 if (mask_layer_) | 726 if (mask_layer_) |
724 mask_layer_->ResetAllChangeTrackingForSubtree(); | 727 mask_layer_->ResetAllChangeTrackingForSubtree(); |
725 | 728 |
726 if (replica_layer_) { | 729 if (replica_layer_) { |
727 // This also resets the replica mask, if it exists. | 730 // This also resets the replica mask, if it exists. |
728 replica_layer_->ResetAllChangeTrackingForSubtree(); | 731 replica_layer_->ResetAllChangeTrackingForSubtree(); |
729 } | 732 } |
730 | 733 |
731 for (size_t i = 0; i < children_.size(); ++i) | 734 for (size_t i = 0; i < children_.size(); ++i) |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 return num_descendants_that_draw_content_; | 1537 return num_descendants_that_draw_content_; |
1535 } | 1538 } |
1536 | 1539 |
1537 void LayerImpl::NotifyAnimationFinished( | 1540 void LayerImpl::NotifyAnimationFinished( |
1538 base::TimeTicks monotonic_time, | 1541 base::TimeTicks monotonic_time, |
1539 Animation::TargetProperty target_property) { | 1542 Animation::TargetProperty target_property) { |
1540 if (target_property == Animation::ScrollOffset) | 1543 if (target_property == Animation::ScrollOffset) |
1541 layer_tree_impl_->InputScrollAnimationFinished(); | 1544 layer_tree_impl_->InputScrollAnimationFinished(); |
1542 } | 1545 } |
1543 | 1546 |
| 1547 void LayerImpl::SetRenderSurfaceActive(bool active) { |
| 1548 if (active == !!active_render_surface_) { |
| 1549 return; |
| 1550 } |
| 1551 |
| 1552 if (active) { |
| 1553 active_render_surface_ = render_surface_.get(); |
| 1554 return; |
| 1555 } |
| 1556 if (active_render_surface_) { |
| 1557 active_render_surface_->ClearLayerLists(); |
| 1558 } |
| 1559 active_render_surface_ = NULL; |
| 1560 } |
| 1561 |
| 1562 void LayerImpl::SetShouldHaveRenderSurface(bool should_have_render_surface) { |
| 1563 if (ShouldHaveRenderSurface() == should_have_render_surface) |
| 1564 return; |
| 1565 if (should_have_render_surface) { |
| 1566 CreateRenderSurface(); |
| 1567 return; |
| 1568 } |
| 1569 ClearRenderSurface(); |
| 1570 } |
| 1571 |
1544 } // namespace cc | 1572 } // namespace cc |
OLD | NEW |