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

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

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Rebase 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 "ui/compositor/layer.h" 7 #include "ui/compositor/layer.h"
9 #include "ui/compositor/layer_owner.h" 8 #include "ui/compositor/layer_owner.h"
10 9
11 namespace ash { 10 namespace ash {
12 namespace wm { 11 namespace wm {
13 12
14 ForwardingLayerDelegate::ForwardingLayerDelegate(ui::Layer* new_layer, 13 ForwardingLayerDelegate::ForwardingLayerDelegate(ui::Layer* new_layer,
15 ui::Layer* original_layer) 14 ui::Layer* original_layer)
16 : client_layer_(new_layer), 15 : layer_(new_layer),
17 original_layer_(original_layer), 16 original_layer_(original_layer),
18 scoped_observer_(this) { 17 scoped_observer_(this) {
19 scoped_observer_.Add(original_layer); 18 scoped_observer_.Add(original_layer);
20 } 19 }
21 20
22 ForwardingLayerDelegate::~ForwardingLayerDelegate() {} 21 ForwardingLayerDelegate::~ForwardingLayerDelegate() {}
23 22
24 void ForwardingLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { 23 void ForwardingLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
25 if (original_layer_ && original_layer_->delegate()) 24 if (original_layer_ && original_layer_->delegate())
26 original_layer_->delegate()->OnPaintLayer(context); 25 original_layer_->delegate()->OnPaintLayer(context);
27 } 26 }
28 27
29 void ForwardingLayerDelegate::OnDelegatedFrameDamage( 28 void ForwardingLayerDelegate::OnDelegatedFrameDamage(
30 const gfx::Rect& damage_rect_in_dip) {} 29 const gfx::Rect& damage_rect_in_dip) {}
31 30
32 void ForwardingLayerDelegate::OnDeviceScaleFactorChanged( 31 void ForwardingLayerDelegate::OnDeviceScaleFactorChanged(
33 float device_scale_factor) { 32 float device_scale_factor) {
34 // Don't tell the original delegate about device scale factor change 33 // Don't tell the original delegate about device scale factor change
35 // on cloned layer because the original layer is still on the same display. 34 // on cloned layer because the original layer is still on the same display.
36 } 35 }
37 36
38 void ForwardingLayerDelegate::DidPaintLayer(ui::Layer* layer, 37 void ForwardingLayerDelegate::DidPaintLayer(ui::Layer* layer,
39 const gfx::Rect& rect) { 38 const gfx::Rect& rect) {
40 client_layer_->SchedulePaint(rect); 39 layer_->SchedulePaint(rect);
41 }
42
43 void ForwardingLayerDelegate::SurfaceChanged(ui::Layer* layer) {
44 // This will delete the old layer and any descendants.
45 ui::LayerOwner old_client;
46 old_client.SetLayer(client_layer_);
47
48 ui::LayerOwner* owner = layer->owner();
49 // The layer recreation step isn't recursive, but layers with surfaces don't
50 // tend to have children anyway. We may end up missing some children, but we
51 // can also reach that state if layers are ever added or removed.
52 // TODO(estade): address this if it ever becomes a practical issue.
53 std::unique_ptr<ui::Layer> recreated = owner->RecreateLayer();
54 client_layer_ = recreated.get();
55 old_client.layer()->parent()->Add(recreated.release());
56 old_client.layer()->parent()->Remove(old_client.layer());
57
58 scoped_observer_.Remove(original_layer_);
59 original_layer_ = owner->layer();
60 scoped_observer_.Add(original_layer_);
61 } 40 }
62 41
63 void ForwardingLayerDelegate::LayerDestroyed(ui::Layer* layer) { 42 void ForwardingLayerDelegate::LayerDestroyed(ui::Layer* layer) {
43 DCHECK_EQ(layer, original_layer_);
64 original_layer_ = nullptr; 44 original_layer_ = nullptr;
65 scoped_observer_.Remove(layer); 45 scoped_observer_.Remove(layer);
66 } 46 }
67 47
68 } // namespace wm 48 } // namespace wm
69 } // namespace ash 49 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698