Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/compositor/layer.h" | 5 #include "ui/compositor/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "cc/layers/texture_layer.h" | 21 #include "cc/layers/texture_layer.h" |
| 22 #include "cc/output/copy_output_request.h" | 22 #include "cc/output/copy_output_request.h" |
| 23 #include "cc/output/filter_operation.h" | 23 #include "cc/output/filter_operation.h" |
| 24 #include "cc/output/filter_operations.h" | 24 #include "cc/output/filter_operations.h" |
| 25 #include "cc/playback/display_item_list_settings.h" | 25 #include "cc/playback/display_item_list_settings.h" |
| 26 #include "cc/resources/transferable_resource.h" | 26 #include "cc/resources/transferable_resource.h" |
| 27 #include "cc/trees/layer_tree_settings.h" | 27 #include "cc/trees/layer_tree_settings.h" |
| 28 #include "ui/compositor/compositor_switches.h" | 28 #include "ui/compositor/compositor_switches.h" |
| 29 #include "ui/compositor/dip_util.h" | 29 #include "ui/compositor/dip_util.h" |
| 30 #include "ui/compositor/layer_animator.h" | 30 #include "ui/compositor/layer_animator.h" |
| 31 #include "ui/compositor/layer_observer.h" | |
| 32 #include "ui/compositor/paint_context.h" | 31 #include "ui/compositor/paint_context.h" |
| 33 #include "ui/gfx/animation/animation.h" | 32 #include "ui/gfx/animation/animation.h" |
| 34 #include "ui/gfx/canvas.h" | 33 #include "ui/gfx/canvas.h" |
| 35 #include "ui/gfx/geometry/point3_f.h" | 34 #include "ui/gfx/geometry/point3_f.h" |
| 36 #include "ui/gfx/geometry/point_conversions.h" | 35 #include "ui/gfx/geometry/point_conversions.h" |
| 37 #include "ui/gfx/geometry/size_conversions.h" | 36 #include "ui/gfx/geometry/size_conversions.h" |
| 38 #include "ui/gfx/interpolated_transform.h" | 37 #include "ui/gfx/interpolated_transform.h" |
| 39 | 38 |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 layer_mask_back_link_(NULL), | 87 layer_mask_back_link_(NULL), |
| 89 zoom_(1), | 88 zoom_(1), |
| 90 zoom_inset_(0), | 89 zoom_inset_(0), |
| 91 delegate_(NULL), | 90 delegate_(NULL), |
| 92 owner_(NULL), | 91 owner_(NULL), |
| 93 cc_layer_(NULL), | 92 cc_layer_(NULL), |
| 94 device_scale_factor_(1.0f) { | 93 device_scale_factor_(1.0f) { |
| 95 CreateCcLayer(); | 94 CreateCcLayer(); |
| 96 } | 95 } |
| 97 | 96 |
| 97 Layer::Layer(const Layer& layer) | |
| 98 : Layer(layer.type_) { | |
| 99 SetVisible(layer.GetTargetVisibility()); | |
| 100 SetOpacity(layer.GetTargetOpacity()); | |
| 101 SetBounds(layer.bounds_); | |
| 102 SetMasksToBounds(layer.GetMasksToBounds()); | |
| 103 set_name(layer.name_); | |
| 104 SetFillsBoundsOpaquely(layer.fills_bounds_opaquely_); | |
| 105 SetFillsBoundsCompletely(layer.fills_bounds_completely_); | |
| 106 SetSubpixelPositionOffset(layer.subpixel_position_offset_); | |
| 107 SetLayerInverted(layer.layer_inverted_); | |
| 108 SetTransform(layer.GetTargetTransform()); | |
| 109 if (layer.type_ == LAYER_SOLID_COLOR) | |
| 110 SetColor(layer.GetTargetColor()); | |
| 111 if (SkRegion* alpha_shape = layer.alpha_shape()) | |
| 112 SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape)); | |
| 113 | |
| 114 const cc::SurfaceLayer* const surface = layer.surface_layer_.get(); | |
| 115 if (surface && !surface->surface_id().is_null()) { | |
| 116 SetShowSurface( | |
| 117 surface->surface_id(), | |
| 118 surface->satisfy_callback(), surface->require_callback(), | |
| 119 surface->surface_size(), surface->surface_scale(), | |
| 120 layer.frame_size_in_dip_); | |
| 121 } | |
| 122 } | |
| 123 | |
| 98 Layer::~Layer() { | 124 Layer::~Layer() { |
| 125 for (auto* mirror : mirrors_) | |
| 126 mirror->RemoveObserver(this); | |
| 127 | |
| 99 FOR_EACH_OBSERVER(LayerObserver, observer_list_, LayerDestroyed(this)); | 128 FOR_EACH_OBSERVER(LayerObserver, observer_list_, LayerDestroyed(this)); |
| 100 | 129 |
| 101 // Destroying the animator may cause observers to use the layer (and | 130 // Destroying the animator may cause observers to use the layer (and |
| 102 // indirectly the WebLayer). Destroy the animator first so that the WebLayer | 131 // indirectly the WebLayer). Destroy the animator first so that the WebLayer |
| 103 // is still around. | 132 // is still around. |
| 104 SetAnimator(nullptr); | 133 SetAnimator(nullptr); |
| 105 if (compositor_) | 134 if (compositor_) |
| 106 compositor_->SetRootLayer(NULL); | 135 compositor_->SetRootLayer(NULL); |
| 107 if (parent_) | 136 if (parent_) |
| 108 parent_->Remove(this); | 137 parent_->Remove(this); |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 | 614 |
| 586 scoped_refptr<cc::SurfaceLayer> new_layer = | 615 scoped_refptr<cc::SurfaceLayer> new_layer = |
| 587 cc::SurfaceLayer::Create(satisfy_callback, require_callback); | 616 cc::SurfaceLayer::Create(satisfy_callback, require_callback); |
| 588 new_layer->SetSurfaceId(surface_id, scale, surface_size); | 617 new_layer->SetSurfaceId(surface_id, scale, surface_size); |
| 589 SwitchToLayer(new_layer); | 618 SwitchToLayer(new_layer); |
| 590 surface_layer_ = new_layer; | 619 surface_layer_ = new_layer; |
| 591 | 620 |
| 592 frame_size_in_dip_ = frame_size_in_dip; | 621 frame_size_in_dip_ = frame_size_in_dip; |
| 593 RecomputeDrawsContentAndUVRect(); | 622 RecomputeDrawsContentAndUVRect(); |
| 594 | 623 |
| 595 FOR_EACH_OBSERVER(LayerObserver, observer_list_, SurfaceChanged(this)); | 624 for (auto* mirror : mirrors_) { |
| 625 mirror->SetShowSurface(surface_id, satisfy_callback, require_callback, | |
| 626 surface_size, scale, frame_size_in_dip); | |
| 627 } | |
| 628 } | |
| 629 | |
| 630 std::unique_ptr<Layer> Layer::Mirror() { | |
| 631 std::unique_ptr<Layer> mirror(new Layer(*this)); | |
| 632 mirror->AddObserver(this); | |
| 633 mirrors_.push_back(mirror.get()); | |
| 634 return mirror; | |
| 596 } | 635 } |
| 597 | 636 |
| 598 void Layer::SetShowSolidColorContent() { | 637 void Layer::SetShowSolidColorContent() { |
| 599 DCHECK_EQ(type_, LAYER_SOLID_COLOR); | 638 DCHECK_EQ(type_, LAYER_SOLID_COLOR); |
| 600 | 639 |
| 601 if (solid_color_layer_.get()) | 640 if (solid_color_layer_.get()) |
| 602 return; | 641 return; |
| 603 | 642 |
| 604 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); | 643 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); |
| 605 SwitchToLayer(new_layer); | 644 SwitchToLayer(new_layer); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 nine_patch_layer_->SetBorder(border); | 681 nine_patch_layer_->SetBorder(border); |
| 643 } | 682 } |
| 644 | 683 |
| 645 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) { | 684 void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) { |
| 646 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); | 685 DCHECK(type_ == LAYER_NINE_PATCH && nine_patch_layer_.get()); |
| 647 nine_patch_layer_->SetLayerOcclusion(occlusion); | 686 nine_patch_layer_->SetLayerOcclusion(occlusion); |
| 648 } | 687 } |
| 649 | 688 |
| 650 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } | 689 void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); } |
| 651 | 690 |
| 652 SkColor Layer::GetTargetColor() { | 691 SkColor Layer::GetTargetColor() const { |
| 653 if (GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR)) | 692 if (animator_.get() && animator_->IsAnimatingProperty( |
| 654 return GetAnimator()->GetTargetColor(); | 693 LayerAnimationElement::COLOR)) |
| 694 return animator_->GetTargetColor(); | |
| 655 return cc_layer_->background_color(); | 695 return cc_layer_->background_color(); |
| 656 } | 696 } |
| 657 | 697 |
| 658 SkColor Layer::background_color() const { | 698 SkColor Layer::background_color() const { |
| 659 return cc_layer_->background_color(); | 699 return cc_layer_->background_color(); |
| 660 } | 700 } |
| 661 | 701 |
| 662 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { | 702 bool Layer::SchedulePaint(const gfx::Rect& invalid_rect) { |
| 663 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || | 703 if ((type_ == LAYER_SOLID_COLOR && !texture_layer_.get()) || |
| 664 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) | 704 type_ == LAYER_NINE_PATCH || (!delegate_ && !mailbox_.IsValid())) |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 907 | 947 |
| 908 if (bounds.size() == old_bounds.size()) { | 948 if (bounds.size() == old_bounds.size()) { |
| 909 // Don't schedule a draw if we're invisible. We'll schedule one | 949 // Don't schedule a draw if we're invisible. We'll schedule one |
| 910 // automatically when we get visible. | 950 // automatically when we get visible. |
| 911 if (IsDrawn()) | 951 if (IsDrawn()) |
| 912 ScheduleDraw(); | 952 ScheduleDraw(); |
| 913 } else { | 953 } else { |
| 914 // Always schedule a paint, even if we're invisible. | 954 // Always schedule a paint, even if we're invisible. |
| 915 SchedulePaint(gfx::Rect(bounds.size())); | 955 SchedulePaint(gfx::Rect(bounds.size())); |
| 916 } | 956 } |
| 957 | |
| 958 if (sync_bounds_) { | |
| 959 for (auto* mirror : mirrors_) | |
| 960 mirror->SetBounds(bounds); | |
|
sky
2016/10/13 19:21:33
I don't think it's always the case that the mirror
Dominik Laskowski
2016/10/13 22:19:39
Good point. I've added an option to disable bounds
| |
| 961 } | |
| 917 } | 962 } |
| 918 | 963 |
| 919 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { | 964 void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { |
| 920 cc_layer_->SetTransform(transform); | 965 cc_layer_->SetTransform(transform); |
| 921 } | 966 } |
| 922 | 967 |
| 923 void Layer::SetOpacityFromAnimation(float opacity) { | 968 void Layer::SetOpacityFromAnimation(float opacity) { |
| 924 cc_layer_->SetOpacity(opacity); | 969 cc_layer_->SetOpacity(opacity); |
| 925 ScheduleDraw(); | 970 ScheduleDraw(); |
| 926 } | 971 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 | 1041 |
| 997 cc::Layer* Layer::GetCcLayer() const { | 1042 cc::Layer* Layer::GetCcLayer() const { |
| 998 return cc_layer_; | 1043 return cc_layer_; |
| 999 } | 1044 } |
| 1000 | 1045 |
| 1001 LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() { | 1046 LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() { |
| 1002 DCHECK(animator_); | 1047 DCHECK(animator_); |
| 1003 return animator_.get(); | 1048 return animator_.get(); |
| 1004 } | 1049 } |
| 1005 | 1050 |
| 1051 void Layer::LayerDestroyed(Layer* mirror) { | |
| 1052 const auto it = std::find(mirrors_.begin(), mirrors_.end(), mirror); | |
|
sky
2016/10/13 19:21:33
mirror->RemoveObserver(this).
Dominik Laskowski
2016/10/13 22:19:39
The caller is the destructor of |mirror|, so that'
| |
| 1053 DCHECK(it != mirrors_.end()); | |
| 1054 mirrors_.erase(it); | |
| 1055 } | |
| 1056 | |
| 1006 void Layer::CreateCcLayer() { | 1057 void Layer::CreateCcLayer() { |
| 1007 if (type_ == LAYER_SOLID_COLOR) { | 1058 if (type_ == LAYER_SOLID_COLOR) { |
| 1008 solid_color_layer_ = cc::SolidColorLayer::Create(); | 1059 solid_color_layer_ = cc::SolidColorLayer::Create(); |
| 1009 cc_layer_ = solid_color_layer_.get(); | 1060 cc_layer_ = solid_color_layer_.get(); |
| 1010 } else if (type_ == LAYER_NINE_PATCH) { | 1061 } else if (type_ == LAYER_NINE_PATCH) { |
| 1011 nine_patch_layer_ = cc::NinePatchLayer::Create(); | 1062 nine_patch_layer_ = cc::NinePatchLayer::Create(); |
| 1012 cc_layer_ = nine_patch_layer_.get(); | 1063 cc_layer_ = nine_patch_layer_.get(); |
| 1013 } else { | 1064 } else { |
| 1014 content_layer_ = cc::PictureLayer::Create(this); | 1065 content_layer_ = cc::PictureLayer::Create(this); |
| 1015 cc_layer_ = content_layer_.get(); | 1066 cc_layer_ = content_layer_.get(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1068 if (animator_) { | 1119 if (animator_) { |
| 1069 animator_->DetachLayerAndTimeline(compositor); | 1120 animator_->DetachLayerAndTimeline(compositor); |
| 1070 animator_->RemoveFromCollection(collection); | 1121 animator_->RemoveFromCollection(collection); |
| 1071 } | 1122 } |
| 1072 | 1123 |
| 1073 for (auto* child : children_) | 1124 for (auto* child : children_) |
| 1074 child->ResetCompositorForAnimatorsInTree(compositor); | 1125 child->ResetCompositorForAnimatorsInTree(compositor); |
| 1075 } | 1126 } |
| 1076 | 1127 |
| 1077 } // namespace ui | 1128 } // namespace ui |
| OLD | NEW |