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

Unified Diff: ui/compositor/layer.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 side-by-side diff with in-line comments
Download patch
Index: ui/compositor/layer.cc
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc
index 31c5da6a17361ba1bbf196762a28e83b1428a66f..5a1e0b9cb79136a480eb413907dcea982d994fdd 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -28,7 +28,6 @@
#include "ui/compositor/compositor_switches.h"
#include "ui/compositor/dip_util.h"
#include "ui/compositor/layer_animator.h"
-#include "ui/compositor/layer_observer.h"
#include "ui/compositor/paint_context.h"
#include "ui/gfx/animation/animation.h"
#include "ui/gfx/canvas.h"
@@ -95,7 +94,37 @@ Layer::Layer(LayerType type)
CreateCcLayer();
}
+Layer::Layer(const Layer& layer)
+ : Layer(layer.type_) {
+ SetVisible(layer.GetTargetVisibility());
+ SetOpacity(layer.GetTargetOpacity());
+ SetBounds(layer.bounds_);
+ SetMasksToBounds(layer.GetMasksToBounds());
+ set_name(layer.name_);
+ SetFillsBoundsOpaquely(layer.fills_bounds_opaquely_);
+ SetFillsBoundsCompletely(layer.fills_bounds_completely_);
+ SetSubpixelPositionOffset(layer.subpixel_position_offset_);
+ SetLayerInverted(layer.layer_inverted_);
+ SetTransform(layer.GetTargetTransform());
+ if (layer.type_ == LAYER_SOLID_COLOR)
+ SetColor(layer.GetTargetColor());
+ if (SkRegion* alpha_shape = layer.alpha_shape())
+ SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape));
+
+ const cc::SurfaceLayer* const surface = layer.surface_layer_.get();
+ if (surface && !surface->surface_id().is_null()) {
+ SetShowSurface(
+ surface->surface_id(),
+ surface->satisfy_callback(), surface->require_callback(),
+ surface->surface_size(), surface->surface_scale(),
+ layer.frame_size_in_dip_);
+ }
+}
+
Layer::~Layer() {
+ for (auto* mirror : mirrors_)
+ mirror->RemoveObserver(this);
+
FOR_EACH_OBSERVER(LayerObserver, observer_list_, LayerDestroyed(this));
// Destroying the animator may cause observers to use the layer (and
@@ -592,7 +621,17 @@ void Layer::SetShowSurface(
frame_size_in_dip_ = frame_size_in_dip;
RecomputeDrawsContentAndUVRect();
- FOR_EACH_OBSERVER(LayerObserver, observer_list_, SurfaceChanged(this));
+ for (auto* mirror : mirrors_) {
+ mirror->SetShowSurface(surface_id, satisfy_callback, require_callback,
+ surface_size, scale, frame_size_in_dip);
+ }
+}
+
+std::unique_ptr<Layer> Layer::Mirror() {
+ std::unique_ptr<Layer> mirror(new Layer(*this));
+ mirror->AddObserver(this);
+ mirrors_.push_back(mirror.get());
+ return mirror;
}
void Layer::SetShowSolidColorContent() {
@@ -649,9 +688,10 @@ void Layer::UpdateNinePatchOcclusion(const gfx::Rect& occlusion) {
void Layer::SetColor(SkColor color) { GetAnimator()->SetColor(color); }
-SkColor Layer::GetTargetColor() {
- if (GetAnimator()->IsAnimatingProperty(LayerAnimationElement::COLOR))
- return GetAnimator()->GetTargetColor();
+SkColor Layer::GetTargetColor() const {
+ if (animator_.get() && animator_->IsAnimatingProperty(
+ LayerAnimationElement::COLOR))
+ return animator_->GetTargetColor();
return cc_layer_->background_color();
}
@@ -914,6 +954,11 @@ void Layer::SetBoundsFromAnimation(const gfx::Rect& bounds) {
// Always schedule a paint, even if we're invisible.
SchedulePaint(gfx::Rect(bounds.size()));
}
+
+ if (sync_bounds_) {
+ for (auto* mirror : mirrors_)
+ mirror->SetBounds(bounds);
sky 2016/10/13 19:21:33 I don't think it's always the case that the mirror
Dominik Laskowski 2016/10/13 22:19:39 Good point. I've added an option to disable bounds
+ }
}
void Layer::SetTransformFromAnimation(const gfx::Transform& transform) {
@@ -1003,6 +1048,12 @@ LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() {
return animator_.get();
}
+void Layer::LayerDestroyed(Layer* mirror) {
+ const auto it = std::find(mirrors_.begin(), mirrors_.end(), mirror);
sky 2016/10/13 19:21:33 mirror->RemoveObserver(this).
Dominik Laskowski 2016/10/13 22:19:39 The caller is the destructor of |mirror|, so that'
+ DCHECK(it != mirrors_.end());
+ mirrors_.erase(it);
+}
+
void Layer::CreateCcLayer() {
if (type_ == LAYER_SOLID_COLOR) {
solid_color_layer_ = cc::SolidColorLayer::Create();

Powered by Google App Engine
This is Rietveld 408576698