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

Unified Diff: ui/compositor/layer.cc

Issue 2383263002: Generalize layer mirroring for phantom windows (Closed)
Patch Set: Revert layer renaming 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 ac20550710eff3c762a72a6000170a9b61ae6ae6..5c749946df84288fb892af49e24b694f21de375b 100644
--- a/ui/compositor/layer.cc
+++ b/ui/compositor/layer.cc
@@ -28,7 +28,7 @@
#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/layer_owner.h"
#include "ui/compositor/paint_context.h"
#include "ui/gfx/animation/animation.h"
#include "ui/gfx/canvas.h"
@@ -49,6 +49,34 @@ const ui::Layer* GetRoot(const ui::Layer* layer) {
namespace ui {
+class Layer::LayerMirror : public ui::LayerOwner,
sky 2016/10/19 19:27:14 I find this code confusing. In particular it's a L
Dominik Laskowski 2016/10/19 22:46:38 The LayerOwner inheritance was just to reduce boil
sky 2016/10/19 23:44:26 I was suggesting you make this class the LayerObse
Dominik Laskowski 2016/10/20 02:12:30 Done.
+ public ui::LayerDelegate {
+ public:
+ explicit LayerMirror(ui::Layer* mirrored) : mirrored_(mirrored) {
+ SetLayer(mirrored->Clone());
+ layer()->AddObserver(mirrored);
+ layer()->set_delegate(this);
+ }
+
+ ~LayerMirror() override {
+ layer()->RemoveObserver(mirrored_);
+ layer()->set_delegate(nullptr);
+ }
+
+ // ui::LayerDelegate:
+ void OnPaintLayer(const ui::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 {}
+
+ private:
+ ui::Layer* const mirrored_;
+
+ DISALLOW_COPY_AND_ASSIGN(LayerMirror);
+};
+
Layer::Layer()
: type_(LAYER_TEXTURED),
compositor_(NULL),
@@ -119,6 +147,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 +661,16 @@ 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() {
+ mirrors_.emplace_back(base::MakeUnique<LayerMirror>(this));
+ return mirrors_.back()->AcquireLayer();
}
void Layer::SetShowSolidColorContent() {
@@ -651,9 +727,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 +993,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) {
@@ -1005,6 +1087,16 @@ LayerThreadedAnimationDelegate* Layer::GetThreadedAnimationDelegate() {
return animator_.get();
}
+void Layer::LayerDestroyed(Layer* layer) {
+ const auto it = std::find_if(mirrors_.begin(), mirrors_.end(),
+ [layer](const std::unique_ptr<LayerMirror>& mirror) {
+ return mirror->layer() == layer;
+ });
+
+ 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