Commit 0df296f4 authored by bruthig's avatar bruthig Committed by Commit bot

Relanding "Reset the root layer on the compositor when recreating a root layer."

Initial attempt found here: https://codereview.chromium.org/983933002/

This is going to be used by https://codereview.chromium.org/975943002/

TEST=LayerOwnerTest.RecreateRootLayerWithNullCompositor
TEST=LayerOwnerTestWithCompositor.RecreateRootLayerWithCompositor

BUG=337596

Review URL: https://codereview.chromium.org/987043004

Cr-Commit-Position: refs/heads/master@{#319665}
parent f0a8ffb2
...@@ -66,6 +66,12 @@ scoped_ptr<Layer> LayerOwner::RecreateLayer() { ...@@ -66,6 +66,12 @@ scoped_ptr<Layer> LayerOwner::RecreateLayer() {
new_layer->Add(child); new_layer->Add(child);
} }
// If old_layer was the layer tree root then we need to move the Compositor
// over to the new root.
const bool is_root = !old_layer->parent();
if (is_root && old_layer->GetCompositor())
old_layer->GetCompositor()->SetRootLayer(new_layer);
// Install the delegate last so that the delegate isn't notified as we copy // Install the delegate last so that the delegate isn't notified as we copy
// state to the new layer. // state to the new layer.
new_layer->set_delegate(old_delegate); new_layer->set_delegate(old_delegate);
......
...@@ -4,12 +4,59 @@ ...@@ -4,12 +4,59 @@
#include "ui/compositor/layer_owner.h" #include "ui/compositor/layer_owner.h"
#include "base/test/null_task_runner.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h" #include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/compositor/test/context_factories_for_test.h"
#include "ui/gfx/native_widget_types.h"
namespace ui { namespace ui {
namespace {
// Test fixture for LayerOwner tests that require a ui::Compositor.
class LayerOwnerTestWithCompositor : public testing::Test {
public:
LayerOwnerTestWithCompositor();
~LayerOwnerTestWithCompositor() override;
void SetUp() override;
void TearDown() override;
protected:
ui::Compositor* compositor() { return compositor_.get(); }
private:
scoped_ptr<ui::Compositor> compositor_;
DISALLOW_COPY_AND_ASSIGN(LayerOwnerTestWithCompositor);
};
LayerOwnerTestWithCompositor::LayerOwnerTestWithCompositor() {
}
LayerOwnerTestWithCompositor::~LayerOwnerTestWithCompositor() {
}
void LayerOwnerTestWithCompositor::SetUp() {
scoped_refptr<base::SingleThreadTaskRunner> task_runner =
new base::NullTaskRunner();
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(false);
compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
context_factory, task_runner));
}
void LayerOwnerTestWithCompositor::TearDown() {
compositor_.reset();
ui::TerminateContextFactoryForTests();
}
} // namespace
TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) { TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) {
LayerOwner owner; LayerOwner owner;
...@@ -30,4 +77,29 @@ TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) { ...@@ -30,4 +77,29 @@ TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) {
EXPECT_EQ(0.0f, owner.layer()->opacity()); EXPECT_EQ(0.0f, owner.layer()->opacity());
} }
TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) {
LayerOwner owner;
Layer* layer = new Layer;
owner.SetLayer(layer);
scoped_ptr<Layer> layer_copy = owner.RecreateLayer();
EXPECT_EQ(nullptr, owner.layer()->GetCompositor());
EXPECT_EQ(nullptr, layer_copy->GetCompositor());
}
TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) {
LayerOwner owner;
Layer* layer = new Layer;
owner.SetLayer(layer);
compositor()->SetRootLayer(layer);
scoped_ptr<Layer> layer_copy = owner.RecreateLayer();
EXPECT_EQ(compositor(), owner.layer()->GetCompositor());
EXPECT_EQ(owner.layer(), compositor()->root_layer());
EXPECT_EQ(nullptr, layer_copy->GetCompositor());
}
} // namespace ui } // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment