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

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: curlies 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
« no previous file with comments | « ash/common/wm/forwarding_layer_delegate.h ('k') | ash/wm/drag_window_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // The layer recreation step isn't recursive, but layers with surfaces don't
52 return false; 50 // tend to have children anyway.
sky 2016/08/30 00:03:13 I'm nervous about this DCHECK. It's seems entirely
51 DCHECK(layer->children().empty());
52
53 // This will delete the old layer.
54 ui::LayerOwner old_client;
55 old_client.SetLayer(client_layer_);
56
57 ui::LayerOwner* owner = layer->owner();
58 std::unique_ptr<ui::Layer> recreated = owner->RecreateLayer();
59 client_layer_ = recreated.get();
60 old_client.layer()->parent()->Add(recreated.release());
61 old_client.layer()->parent()->Remove(old_client.layer());
62
63 scoped_observer_.Remove(original_layer_);
64 original_layer_ = owner->layer();
65 scoped_observer_.Add(original_layer_);
66 }
67
68 void ForwardingLayerDelegate::LayerDestroyed(ui::Layer* layer) {
69 original_layer_ = nullptr;
70 scoped_observer_.Remove(layer);
53 } 71 }
54 72
55 } // namespace wm 73 } // namespace wm
56 } // namespace ash 74 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/forwarding_layer_delegate.h ('k') | ash/wm/drag_window_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698