Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: ui/compositor/layer.cc

Issue 2254733003: Add ui::LayerObserver and use it to update Alt+Tab previews as needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: layer owner Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
31 #include "ui/compositor/paint_context.h" 32 #include "ui/compositor/paint_context.h"
32 #include "ui/gfx/animation/animation.h" 33 #include "ui/gfx/animation/animation.h"
33 #include "ui/gfx/canvas.h" 34 #include "ui/gfx/canvas.h"
34 #include "ui/gfx/geometry/point3_f.h" 35 #include "ui/gfx/geometry/point3_f.h"
35 #include "ui/gfx/geometry/point_conversions.h" 36 #include "ui/gfx/geometry/point_conversions.h"
36 #include "ui/gfx/geometry/size_conversions.h" 37 #include "ui/gfx/geometry/size_conversions.h"
37 #include "ui/gfx/interpolated_transform.h" 38 #include "ui/gfx/interpolated_transform.h"
38 39
39 namespace { 40 namespace {
40 41
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 delegate_(NULL), 93 delegate_(NULL),
93 owner_(NULL), 94 owner_(NULL),
94 cc_layer_(NULL), 95 cc_layer_(NULL),
95 device_scale_factor_(1.0f), 96 device_scale_factor_(1.0f),
96 texture_x_scale_(1.0f), 97 texture_x_scale_(1.0f),
97 texture_y_scale_(1.0f) { 98 texture_y_scale_(1.0f) {
98 CreateCcLayer(); 99 CreateCcLayer();
99 } 100 }
100 101
101 Layer::~Layer() { 102 Layer::~Layer() {
103 FOR_EACH_OBSERVER(LayerObserver, observer_list_, LayerDestroyed(this));
104
102 // Destroying the animator may cause observers to use the layer (and 105 // Destroying the animator may cause observers to use the layer (and
103 // indirectly the WebLayer). Destroy the animator first so that the WebLayer 106 // indirectly the WebLayer). Destroy the animator first so that the WebLayer
104 // is still around. 107 // is still around.
105 SetAnimator(nullptr); 108 SetAnimator(nullptr);
106 if (compositor_) 109 if (compositor_)
107 compositor_->SetRootLayer(NULL); 110 compositor_->SetRootLayer(NULL);
108 if (parent_) 111 if (parent_)
109 parent_->Remove(this); 112 parent_->Remove(this);
110 if (layer_mask_) 113 if (layer_mask_)
111 SetMaskLayer(NULL); 114 SetMaskLayer(NULL);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 147 }
145 148
146 void Layer::ResetCompositor() { 149 void Layer::ResetCompositor() {
147 DCHECK(!parent_); 150 DCHECK(!parent_);
148 if (compositor_) { 151 if (compositor_) {
149 ResetCompositorForAnimatorsInTree(compositor_); 152 ResetCompositorForAnimatorsInTree(compositor_);
150 compositor_ = nullptr; 153 compositor_ = nullptr;
151 } 154 }
152 } 155 }
153 156
157 void Layer::AddObserver(LayerObserver* observer) {
158 observer_list_.AddObserver(observer);
159 }
160
161 void Layer::RemoveObserver(LayerObserver* observer) {
162 observer_list_.RemoveObserver(observer);
163 }
164
154 void Layer::Add(Layer* child) { 165 void Layer::Add(Layer* child) {
155 DCHECK(!child->compositor_); 166 DCHECK(!child->compositor_);
156 if (child->parent_) 167 if (child->parent_)
157 child->parent_->Remove(child); 168 child->parent_->Remove(child);
158 child->parent_ = this; 169 child->parent_ = this;
159 children_.push_back(child); 170 children_.push_back(child);
160 cc_layer_->AddChild(child->cc_layer_); 171 cc_layer_->AddChild(child->cc_layer_);
161 child->OnDeviceScaleFactorChanged(device_scale_factor_); 172 child->OnDeviceScaleFactorChanged(device_scale_factor_);
162 Compositor* compositor = GetCompositor(); 173 Compositor* compositor = GetCompositor();
163 if (compositor) 174 if (compositor)
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR); 610 DCHECK(type_ == LAYER_TEXTURED || type_ == LAYER_SOLID_COLOR);
600 611
601 scoped_refptr<cc::SurfaceLayer> new_layer = 612 scoped_refptr<cc::SurfaceLayer> new_layer =
602 cc::SurfaceLayer::Create(satisfy_callback, require_callback); 613 cc::SurfaceLayer::Create(satisfy_callback, require_callback);
603 new_layer->SetSurfaceId(surface_id, scale, surface_size); 614 new_layer->SetSurfaceId(surface_id, scale, surface_size);
604 SwitchToLayer(new_layer); 615 SwitchToLayer(new_layer);
605 surface_layer_ = new_layer; 616 surface_layer_ = new_layer;
606 617
607 frame_size_in_dip_ = frame_size_in_dip; 618 frame_size_in_dip_ = frame_size_in_dip;
608 RecomputeDrawsContentAndUVRect(); 619 RecomputeDrawsContentAndUVRect();
620
621 FOR_EACH_OBSERVER(LayerObserver, observer_list_, SurfaceChanged(this));
609 } 622 }
610 623
611 void Layer::SetShowSolidColorContent() { 624 void Layer::SetShowSolidColorContent() {
612 DCHECK_EQ(type_, LAYER_SOLID_COLOR); 625 DCHECK_EQ(type_, LAYER_SOLID_COLOR);
613 626
614 if (solid_color_layer_.get()) 627 if (solid_color_layer_.get())
615 return; 628 return;
616 629
617 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create(); 630 scoped_refptr<cc::SolidColorLayer> new_layer = cc::SolidColorLayer::Create();
618 SwitchToLayer(new_layer); 631 SwitchToLayer(new_layer);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 if (delegate_) 757 if (delegate_)
745 delegate_->OnDeviceScaleFactorChanged(device_scale_factor); 758 delegate_->OnDeviceScaleFactorChanged(device_scale_factor);
746 for (size_t i = 0; i < children_.size(); ++i) 759 for (size_t i = 0; i < children_.size(); ++i)
747 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor); 760 children_[i]->OnDeviceScaleFactorChanged(device_scale_factor);
748 if (layer_mask_) 761 if (layer_mask_)
749 layer_mask_->OnDeviceScaleFactorChanged(device_scale_factor); 762 layer_mask_->OnDeviceScaleFactorChanged(device_scale_factor);
750 } 763 }
751 764
752 void Layer::OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) { 765 void Layer::OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) {
753 DCHECK(surface_layer_.get()); 766 DCHECK(surface_layer_.get());
754 if (!delegate_) 767 if (delegate_)
755 return; 768 delegate_->OnDelegatedFrameDamage(damage_rect_in_dip);
756 delegate_->OnDelegatedFrameDamage(damage_rect_in_dip);
757 } 769 }
758 770
759 void Layer::SetScrollable(Layer* parent_clip_layer, 771 void Layer::SetScrollable(Layer* parent_clip_layer,
760 const base::Closure& on_scroll) { 772 const base::Closure& on_scroll) {
761 cc_layer_->SetScrollClipLayerId(parent_clip_layer->cc_layer_->id()); 773 cc_layer_->SetScrollClipLayerId(parent_clip_layer->cc_layer_->id());
762 cc_layer_->set_did_scroll_callback(on_scroll); 774 cc_layer_->set_did_scroll_callback(on_scroll);
763 cc_layer_->SetUserScrollable(true, true); 775 cc_layer_->SetUserScrollable(true, true);
764 } 776 }
765 777
766 gfx::ScrollOffset Layer::CurrentScrollOffset() const { 778 gfx::ScrollOffset Layer::CurrentScrollOffset() const {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 paint_region_.Clear(); 814 paint_region_.Clear();
803 cc::DisplayItemListSettings settings; 815 cc::DisplayItemListSettings settings;
804 settings.use_cached_picture = false; 816 settings.use_cached_picture = false;
805 scoped_refptr<cc::DisplayItemList> display_list = 817 scoped_refptr<cc::DisplayItemList> display_list =
806 cc::DisplayItemList::Create(settings); 818 cc::DisplayItemList::Create(settings);
807 if (delegate_) { 819 if (delegate_) {
808 delegate_->OnPaintLayer( 820 delegate_->OnPaintLayer(
809 PaintContext(display_list.get(), device_scale_factor_, invalidation)); 821 PaintContext(display_list.get(), device_scale_factor_, invalidation));
810 } 822 }
811 display_list->Finalize(); 823 display_list->Finalize();
824 FOR_EACH_OBSERVER(LayerObserver, observer_list_,
825 DidPaintLayer(this, invalidation));
812 return display_list; 826 return display_list;
813 } 827 }
814 828
815 bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; } 829 bool Layer::FillsBoundsCompletely() const { return fills_bounds_completely_; }
816 830
817 size_t Layer::GetApproximateUnsharedMemoryUsage() const { 831 size_t Layer::GetApproximateUnsharedMemoryUsage() const {
818 // Most of the "picture memory" is shared with the cc::DisplayItemList, so 832 // Most of the "picture memory" is shared with the cc::DisplayItemList, so
819 // there's nothing significant to report here. 833 // there's nothing significant to report here.
820 return 0; 834 return 0;
821 } 835 }
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 if (animator_) { 1109 if (animator_) {
1096 animator_->ResetCompositor(compositor); 1110 animator_->ResetCompositor(compositor);
1097 animator_->RemoveFromCollection(collection); 1111 animator_->RemoveFromCollection(collection);
1098 } 1112 }
1099 1113
1100 for (auto* child : children_) 1114 for (auto* child : children_)
1101 child->ResetCompositorForAnimatorsInTree(compositor); 1115 child->ResetCompositorForAnimatorsInTree(compositor);
1102 } 1116 }
1103 1117
1104 } // namespace ui 1118 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698