Index: ui/compositor/layer.cc |
diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc |
index ac20550710eff3c762a72a6000170a9b61ae6ae6..6da6f9109533a3136ada87ac64bb52b2754fa674 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" |
@@ -96,6 +95,9 @@ Layer::Layer(LayerType type) |
} |
Layer::~Layer() { |
+ for (auto* mirror : mirrors_) |
+ mirror->RemoveObserver(this); |
+ |
for (auto& observer : observer_list_) |
observer.LayerDestroyed(this); |
@@ -119,6 +121,37 @@ Layer::~Layer() { |
mailbox_release_callback_->Run(gpu::SyncToken(), false); |
} |
+std::unique_ptr<Layer> Layer::Clone() const { |
+ auto clone = base::MakeUnique<Layer>(type_); |
+ |
+ clone->SetVisible(GetTargetVisibility()); |
+ clone->SetOpacity(GetTargetOpacity()); |
sky
2016/10/14 22:36:37
What about
int background_blur_radius_, satuations
Dominik Laskowski
2016/10/17 19:53:21
This code was pulled from LayerOwner::RecreateLaye
|
+ clone->SetBounds(bounds_); |
+ clone->SetMasksToBounds(GetMasksToBounds()); |
+ clone->set_name(name_); |
+ clone->SetFillsBoundsOpaquely(fills_bounds_opaquely_); |
+ clone->SetFillsBoundsCompletely(fills_bounds_completely_); |
+ clone->SetSubpixelPositionOffset(subpixel_position_offset_); |
+ clone->SetLayerInverted(layer_inverted_); |
+ clone->SetTransform(GetTargetTransform()); |
+ |
+ if (type_ == LAYER_SOLID_COLOR) |
+ clone->SetColor(GetTargetColor()); |
+ if (alpha_shape_) |
+ clone->SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape_)); |
+ |
+ if (surface_layer_ && !surface_layer_->surface_id().is_null()) { |
+ clone->SetShowSurface( |
+ surface_layer_->surface_id(), |
+ surface_layer_->satisfy_callback(), |
+ surface_layer_->require_callback(), |
+ surface_layer_->surface_size(), |
+ surface_layer_->surface_scale(), |
+ frame_size_in_dip_); |
+ } |
+ return clone; |
+} |
+ |
const Compositor* Layer::GetCompositor() const { |
return GetRoot(this)->compositor_; |
} |
@@ -593,8 +626,17 @@ void Layer::SetShowSurface( |
frame_size_in_dip_ = frame_size_in_dip; |
RecomputeDrawsContentAndUVRect(); |
- for (auto& observer : observer_list_) |
- observer.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 = Clone(); |
+ mirror->AddObserver(this); |
+ mirrors_.push_back(mirror.get()); |
+ return mirror; |
} |
void Layer::SetShowSolidColorContent() { |
@@ -651,9 +693,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(); |
} |
@@ -916,6 +959,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); |
+ } |
} |
void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { |
@@ -1005,6 +1053,12 @@ LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() { |
return animator_.get(); |
} |
+void Layer::LayerDestroyed(Layer* mirror) { |
+ const auto it = std::find(mirrors_.begin(), mirrors_.end(), mirror); |
+ DCHECK(it != mirrors_.end()); |
+ mirrors_.erase(it); |
+} |
+ |
void Layer::CreateCcLayer() { |
if (type_ == LAYER_SOLID_COLOR) { |
solid_color_layer_ = cc::SolidColorLayer::Create(); |