| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/common/wm/forwarding_layer_delegate.h" | |
| 6 | |
| 7 #include "ash/common/wm_window.h" | |
| 8 #include "ui/compositor/layer.h" | |
| 9 #include "ui/compositor/layer_owner.h" | |
| 10 | |
| 11 namespace ash { | |
| 12 namespace wm { | |
| 13 | |
| 14 ForwardingLayerDelegate::ForwardingLayerDelegate(ui::Layer* new_layer, | |
| 15 ui::Layer* original_layer) | |
| 16 : client_layer_(new_layer), | |
| 17 original_layer_(original_layer), | |
| 18 scoped_observer_(this) { | |
| 19 scoped_observer_.Add(original_layer); | |
| 20 } | |
| 21 | |
| 22 ForwardingLayerDelegate::~ForwardingLayerDelegate() {} | |
| 23 | |
| 24 void ForwardingLayerDelegate::OnPaintLayer(const ui::PaintContext& context) { | |
| 25 if (original_layer_ && original_layer_->delegate()) | |
| 26 original_layer_->delegate()->OnPaintLayer(context); | |
| 27 } | |
| 28 | |
| 29 void ForwardingLayerDelegate::OnDelegatedFrameDamage( | |
| 30 const gfx::Rect& damage_rect_in_dip) {} | |
| 31 | |
| 32 void ForwardingLayerDelegate::OnDeviceScaleFactorChanged( | |
| 33 float device_scale_factor) { | |
| 34 // 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. | |
| 36 } | |
| 37 | |
| 38 void ForwardingLayerDelegate::DidPaintLayer(ui::Layer* layer, | |
| 39 const gfx::Rect& rect) { | |
| 40 client_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 } | |
| 62 | |
| 63 void ForwardingLayerDelegate::LayerDestroyed(ui::Layer* layer) { | |
| 64 original_layer_ = nullptr; | |
| 65 scoped_observer_.Remove(layer); | |
| 66 } | |
| 67 | |
| 68 } // namespace wm | |
| 69 } // namespace ash | |
| OLD | NEW |