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

Side by Side Diff: ash/common/wm/forwarding_layer_delegate.cc

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Created 4 years, 2 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"
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 bool sync_bounds)
17 : client_layer_(client_layer),
18 original_layer_(original_layer), 18 original_layer_(original_layer),
19 scoped_observer_(this) { 19 scoped_observer_(this),
20 sync_bounds_(sync_bounds) {
21 DCHECK(original_layer->owner());
20 scoped_observer_.Add(original_layer); 22 scoped_observer_.Add(original_layer);
21 } 23 }
22 24
23 ForwardingLayerDelegate::~ForwardingLayerDelegate() {} 25 ForwardingLayerDelegate::~ForwardingLayerDelegate() {}
24 26
25 void ForwardingLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { 27 void ForwardingLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
26 if (original_layer_ && original_layer_->delegate()) 28 if (original_layer_ && original_layer_->delegate())
27 original_layer_->delegate()->OnPaintLayer(context); 29 original_layer_->delegate()->OnPaintLayer(context);
28 } 30 }
29 31
30 void ForwardingLayerDelegate::OnDelegatedFrameDamage( 32 void ForwardingLayerDelegate::OnDelegatedFrameDamage(
31 const gfx::Rect& damage_rect_in_dip) {} 33 const gfx::Rect& damage_rect_in_dip) {}
32 34
33 void ForwardingLayerDelegate::OnDeviceScaleFactorChanged( 35 void ForwardingLayerDelegate::OnDeviceScaleFactorChanged(
34 float device_scale_factor) { 36 float device_scale_factor) {
35 // Don't tell the original delegate about device scale factor change 37 // Don't tell the original delegate about device scale factor change
36 // on cloned layer because the original layer is still on the same display. 38 // on cloned layer because the original layer is still on the same display.
37 } 39 }
38 40
39 base::Closure ForwardingLayerDelegate::PrepareForLayerBoundsChange() { 41 base::Closure ForwardingLayerDelegate::PrepareForLayerBoundsChange() {
40 return base::Closure(); 42 return base::Closure();
41 } 43 }
42 44
43 void ForwardingLayerDelegate::DidPaintLayer(ui::Layer* layer, 45 void ForwardingLayerDelegate::DidPaintLayer(ui::Layer* layer,
44 const gfx::Rect& rect) { 46 const gfx::Rect& rect) {
45 client_layer_->SchedulePaint(rect); 47 client_layer_->SchedulePaint(rect);
46 } 48 }
47 49
50 void ForwardingLayerDelegate::BoundsChanged(ui::Layer* layer) {
51 DCHECK_EQ(layer, original_layer_);
52 if (sync_bounds_)
53 client_layer_->SetBounds(layer->bounds());
54 }
55
48 void ForwardingLayerDelegate::SurfaceChanged(ui::Layer* layer) { 56 void ForwardingLayerDelegate::SurfaceChanged(ui::Layer* layer) {
49 // This will delete the old layer and any descendants. 57 DCHECK_EQ(layer, original_layer_);
50 ui::LayerOwner old_client; 58 layer->owner()->MirrorLayer(client_layer_);
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 } 59 }
67 60
68 void ForwardingLayerDelegate::LayerDestroyed(ui::Layer* layer) { 61 void ForwardingLayerDelegate::LayerDestroyed(ui::Layer* layer) {
62 DCHECK_EQ(layer, original_layer_);
69 original_layer_ = nullptr; 63 original_layer_ = nullptr;
70 scoped_observer_.Remove(layer); 64 scoped_observer_.Remove(layer);
71 } 65 }
72 66
73 } // namespace wm 67 } // namespace wm
74 } // namespace ash 68 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698