OLD | NEW |
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" | |
8 #include "base/callback.h" | 7 #include "base/callback.h" |
9 #include "ui/compositor/layer.h" | 8 #include "ui/compositor/layer.h" |
10 #include "ui/compositor/layer_owner.h" | 9 #include "ui/compositor/layer_owner.h" |
11 | 10 |
12 namespace ash { | 11 namespace ash { |
13 namespace wm { | 12 namespace wm { |
14 | 13 |
15 ForwardingLayerDelegate::ForwardingLayerDelegate(ui::Layer* new_layer, | 14 ForwardingLayerDelegate::ForwardingLayerDelegate(ui::Layer* client_layer, |
16 ui::Layer* original_layer) | 15 ui::Layer* original_layer) |
17 : client_layer_(new_layer), | 16 : client_layer_(client_layer), |
18 original_layer_(original_layer), | 17 original_layer_(original_layer), |
19 scoped_observer_(this) { | 18 scoped_observer_(this) { |
20 scoped_observer_.Add(original_layer); | 19 scoped_observer_.Add(original_layer); |
21 } | 20 } |
22 | 21 |
23 ForwardingLayerDelegate::~ForwardingLayerDelegate() {} | 22 ForwardingLayerDelegate::~ForwardingLayerDelegate() {} |
24 | 23 |
25 void ForwardingLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | 24 void ForwardingLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { |
26 if (original_layer_ && original_layer_->delegate()) | 25 if (original_layer_ && original_layer_->delegate()) |
27 original_layer_->delegate()->OnPaintLayer(context); | 26 original_layer_->delegate()->OnPaintLayer(context); |
(...skipping 10 matching lines...) Expand all Loading... |
38 | 37 |
39 base::Closure ForwardingLayerDelegate::PrepareForLayerBoundsChange() { | 38 base::Closure ForwardingLayerDelegate::PrepareForLayerBoundsChange() { |
40 return base::Closure(); | 39 return base::Closure(); |
41 } | 40 } |
42 | 41 |
43 void ForwardingLayerDelegate::DidPaintLayer(ui::Layer* layer, | 42 void ForwardingLayerDelegate::DidPaintLayer(ui::Layer* layer, |
44 const gfx::Rect& rect) { | 43 const gfx::Rect& rect) { |
45 client_layer_->SchedulePaint(rect); | 44 client_layer_->SchedulePaint(rect); |
46 } | 45 } |
47 | 46 |
48 void ForwardingLayerDelegate::SurfaceChanged(ui::Layer* layer) { | |
49 // This will delete the old layer and any descendants. | |
50 ui::LayerOwner old_client; | |
51 old_client.SetLayer(client_layer_); | |
52 | |
53 ui::LayerOwner* owner = layer->owner(); | |
54 // The layer recreation step isn't recursive, but layers with surfaces don't | |
55 // tend to have children anyway. We may end up missing some children, but we | |
56 // can also reach that state if layers are ever added or removed. | |
57 // TODO(estade): address this if it ever becomes a practical issue. | |
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) { | 47 void ForwardingLayerDelegate::LayerDestroyed(ui::Layer* layer) { |
| 48 DCHECK_EQ(layer, original_layer_); |
69 original_layer_ = nullptr; | 49 original_layer_ = nullptr; |
70 scoped_observer_.Remove(layer); | 50 scoped_observer_.Remove(layer); |
71 } | 51 } |
72 | 52 |
73 } // namespace wm | 53 } // namespace wm |
74 } // namespace ash | 54 } // namespace ash |
OLD | NEW |