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

Side by Side Diff: ash/common/wm/forwarding_layer_delegate.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, 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ash/common/wm/forwarding_layer_delegate.h" 5 #include "ash/common/wm/forwarding_layer_delegate.h"
6 6
7 #include "ash/common/wm_window.h" 7 #include "ash/common/wm_window.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
10 #include "ui/compositor/layer_owner.h"
10 11
11 namespace ash { 12 namespace ash {
12 namespace wm { 13 namespace wm {
13 14
14 ForwardingLayerDelegate::ForwardingLayerDelegate(WmWindow* original_window, 15 ForwardingLayerDelegate::ForwardingLayerDelegate(ui::Layer* new_layer,
15 ui::LayerDelegate* delegate) 16 ui::Layer* original_layer)
16 : original_window_(original_window), original_delegate_(delegate) {} 17 : client_layer_(new_layer),
18 original_layer_(original_layer),
19 scoped_observer_(this) {
20 scoped_observer_.Add(original_layer);
21 }
17 22
18 ForwardingLayerDelegate::~ForwardingLayerDelegate() {} 23 ForwardingLayerDelegate::~ForwardingLayerDelegate() {}
19 24
20 void ForwardingLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { 25 void ForwardingLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
21 if (!original_delegate_) 26 if (original_layer_)
22 return; 27 original_layer_->delegate()->OnPaintLayer(context);
23 // |original_delegate_| may have already been deleted or
24 // disconnected by this time. Check if |original_delegate_| is still
25 // used by the original_window tree, or skip otherwise.
26 if (IsDelegateValid(original_window_->GetLayer()))
27 original_delegate_->OnPaintLayer(context);
28 else
29 original_delegate_ = nullptr;
30 } 28 }
31 29
32 void ForwardingLayerDelegate::OnDelegatedFrameDamage( 30 void ForwardingLayerDelegate::OnDelegatedFrameDamage(
33 const gfx::Rect& damage_rect_in_dip) {} 31 const gfx::Rect& damage_rect_in_dip) {}
34 32
35 void ForwardingLayerDelegate::OnDeviceScaleFactorChanged( 33 void ForwardingLayerDelegate::OnDeviceScaleFactorChanged(
36 float device_scale_factor) { 34 float device_scale_factor) {
37 // Don't tell the original delegate about device scale factor change 35 // Don't tell the original delegate about device scale factor change
38 // on cloned layer because the original layer is still on the same display. 36 // on cloned layer because the original layer is still on the same display.
39 } 37 }
40 38
41 base::Closure ForwardingLayerDelegate::PrepareForLayerBoundsChange() { 39 base::Closure ForwardingLayerDelegate::PrepareForLayerBoundsChange() {
42 return base::Closure(); 40 return base::Closure();
43 } 41 }
44 42
45 bool ForwardingLayerDelegate::IsDelegateValid(ui::Layer* layer) const { 43 void ForwardingLayerDelegate::DidPaintLayer(ui::Layer* layer,
46 if (layer->delegate() == original_delegate_) 44 const gfx::Rect& rect) {
47 return true; 45 client_layer_->SchedulePaint(rect);
48 for (auto* child : layer->children()) { 46 }
49 if (IsDelegateValid(child)) 47
50 return true; 48 void ForwardingLayerDelegate::SurfaceChanged(ui::Layer* layer) {
51 } 49 ui::LayerOwner* owner = layer->owner();
52 return false; 50 std::unique_ptr<ui::Layer> recreated = owner->RecreateLayer();
sky 2016/08/23 17:15:07 Don't you need to reset client_layer_ to recreated
Evan Stade 2016/08/29 23:51:54 yes indeed.
51 client_layer_->parent()->Add(recreated.release());
52 client_layer_->parent()->Remove(client_layer_);
53
54 // This will delete the old layer and all of its descendants.
55 ui::LayerOwner client_owner;
56 client_owner.SetLayer(client_layer_);
57
58 scoped_observer_.Remove(original_layer_);
59 original_layer_ = owner->layer();
60 scoped_observer_.Add(original_layer_);
61 }
62
63 void ForwardingLayerDelegate::LayerDestroyed(ui::Layer* layer) {
64 original_layer_ = nullptr;
65 scoped_observer_.Remove(layer);
53 } 66 }
54 67
55 } // namespace wm 68 } // namespace wm
56 } // namespace ash 69 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698