Chromium Code Reviews| Index: ui/compositor/layer.cc |
| diff --git a/ui/compositor/layer.cc b/ui/compositor/layer.cc |
| index ac20550710eff3c762a72a6000170a9b61ae6ae6..006c046609dbbd51e0d51334dff057fb4947efd9 100644 |
| --- a/ui/compositor/layer.cc |
| +++ b/ui/compositor/layer.cc |
| @@ -49,6 +49,41 @@ const ui::Layer* GetRoot(const ui::Layer* layer) { |
| namespace ui { |
| +class Layer::LayerMirror : public LayerDelegate, LayerObserver { |
| + public: |
| + LayerMirror(Layer* mirrored, Layer* mirror) |
| + : mirrored_(mirrored), mirror_(mirror) { |
| + mirror->AddObserver(this); |
| + mirror->set_delegate(this); |
| + } |
| + |
| + ~LayerMirror() override { |
| + mirror_->RemoveObserver(this); |
| + mirror_->set_delegate(nullptr); |
| + } |
| + |
| + Layer* layer() const { return mirror_; } |
|
oshima
2016/10/21 13:35:09
remote const since you're returning (exposing) int
Dominik Laskowski
2016/10/21 18:22:54
Done. No need to update the loops, because the "co
|
| + |
| + // LayerDelegate: |
| + void OnPaintLayer(const PaintContext& context) override { |
| + if (const auto delegate = mirrored_->delegate()) |
| + delegate->OnPaintLayer(context); |
| + } |
| + void OnDelegatedFrameDamage(const gfx::Rect& damage_rect_in_dip) override {} |
| + void OnDeviceScaleFactorChanged(float device_scale_factor) override {} |
| + |
| + // LayerObserver: |
| + void LayerDestroyed(Layer*) override { |
| + mirrored_->OnMirrorDestroyed(this); |
| + } |
| + |
| + private: |
| + Layer* const mirrored_; |
| + Layer* const mirror_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(LayerMirror); |
| +}; |
| + |
| Layer::Layer() |
| : type_(LAYER_TEXTURED), |
| compositor_(NULL), |
| @@ -119,6 +154,46 @@ Layer::~Layer() { |
| mailbox_release_callback_->Run(gpu::SyncToken(), false); |
| } |
| +std::unique_ptr<Layer> Layer::Clone() const { |
| + auto clone = base::MakeUnique<Layer>(type_); |
| + |
| + clone->SetTransform(GetTargetTransform()); |
| + clone->SetBounds(bounds_); |
| + clone->SetSubpixelPositionOffset(subpixel_position_offset_); |
| + clone->SetMasksToBounds(GetMasksToBounds()); |
| + clone->SetOpacity(GetTargetOpacity()); |
| + clone->SetVisible(GetTargetVisibility()); |
| + clone->SetFillsBoundsOpaquely(fills_bounds_opaquely_); |
| + clone->SetFillsBoundsCompletely(fills_bounds_completely_); |
| + clone->set_name(name_); |
| + |
| + // Background filters. |
| + clone->SetBackgroundBlur(background_blur_radius_); |
| + clone->SetBackgroundZoom(zoom_, zoom_inset_); |
| + |
| + // Filters. |
| + clone->SetLayerSaturation(layer_saturation_); |
| + clone->SetLayerBrightness(GetTargetBrightness()); |
| + clone->SetLayerGrayscale(GetTargetGrayscale()); |
| + clone->SetLayerInverted(layer_inverted_); |
| + if (alpha_shape_) |
| + clone->SetAlphaShape(base::MakeUnique<SkRegion>(*alpha_shape_)); |
| + |
| + // cc::Layer state. |
| + 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_); |
| + } else if (type_ == LAYER_SOLID_COLOR) { |
| + clone->SetColor(GetTargetColor()); |
| + } |
| + return clone; |
| +} |
| + |
| const Compositor* Layer::GetCompositor() const { |
| return GetRoot(this)->compositor_; |
| } |
| @@ -593,8 +668,17 @@ void Layer::SetShowSurface( |
| frame_size_in_dip_ = frame_size_in_dip; |
| RecomputeDrawsContentAndUVRect(); |
| - for (auto& observer : observer_list_) |
| - observer.SurfaceChanged(this); |
| + for (const auto& mirror : mirrors_) { |
| + mirror->layer()->SetShowSurface( |
| + surface_id, satisfy_callback, require_callback, |
| + surface_size, scale, frame_size_in_dip); |
| + } |
| +} |
| + |
| +std::unique_ptr<Layer> Layer::Mirror() { |
| + auto mirror = Clone(); |
| + mirrors_.emplace_back(base::MakeUnique<LayerMirror>(this, mirror.get())); |
| + return mirror; |
| } |
| void Layer::SetShowSolidColorContent() { |
| @@ -651,9 +735,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 +1001,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 (const auto& mirror : mirrors_) |
| + mirror->layer()->SetBounds(bounds); |
| + } |
| } |
| void Layer::SetTransformFromAnimation(const gfx::Transform& transform) { |
| @@ -1076,4 +1166,14 @@ void Layer::ResetCompositorForAnimatorsInTree(Compositor* compositor) { |
| child->ResetCompositorForAnimatorsInTree(compositor); |
| } |
| +void Layer::OnMirrorDestroyed(LayerMirror* mirror) { |
| + const auto it = std::find_if(mirrors_.begin(), mirrors_.end(), |
| + [mirror](const std::unique_ptr<LayerMirror>& mirror_ptr) { |
| + return mirror_ptr.get() == mirror; |
| + }); |
| + |
| + DCHECK(it != mirrors_.end()); |
| + mirrors_.erase(it); |
| +} |
| + |
| } // namespace ui |