Skip to content

Commit

Permalink
aura: Allow deferred widget creation
Browse files Browse the repository at this point in the history
This further passes through OnAcceleratedWidgetAvailable(),
which will then defer LayerTreeHost::SetLayerTreeHostClientReady().
That again means there will be no attempts to create an OutputSurface
until OnAcceleratedWidgetAvailable() happens.

BUG=513540,255128

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

Cr-Commit-Position: refs/heads/master@{#345407}
  • Loading branch information
sievers authored and Commit bot committed Aug 25, 2015
1 parent 636937b commit b2a31d3
Show file tree
Hide file tree
Showing 26 changed files with 95 additions and 74 deletions.
3 changes: 2 additions & 1 deletion ash/host/ash_window_tree_host_unified.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class UnifiedEventTargeter : public aura::WindowTargeter {
AshWindowTreeHostUnified::AshWindowTreeHostUnified(
const gfx::Rect& initial_bounds)
: bounds_(gfx::Rect(initial_bounds.size())), transformer_helper_(this) {
CreateCompositor(GetAcceleratedWidget());
CreateCompositor();
OnAcceleratedWidgetAvailable();
transformer_helper_.Init();
}

Expand Down
3 changes: 2 additions & 1 deletion content/browser/compositor/browser_compositor_view_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ bool WidgetNeedsGLFinishWorkaround() {
: accelerated_widget_mac_(
new ui::AcceleratedWidgetMac(WidgetNeedsGLFinishWorkaround())),
compositor_(
accelerated_widget_mac_->accelerated_widget(),
content::GetContextFactory(),
RenderWidgetResizeHelper::Get()->task_runner()) {
compositor_.SetAcceleratedWidgetAndStartCompositor(
accelerated_widget_mac_->accelerated_widget());
compositor_.SetLocksWillTimeOut(false);
Suspend();
compositor_.AddObserver(this);
Expand Down
7 changes: 4 additions & 3 deletions content/browser/compositor/reflector_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ class ReflectorImplTest : public testing::Test {
message_loop_.reset(new base::MessageLoop());
task_runner_ = message_loop_->task_runner();
compositor_task_runner_ = new FakeTaskRunner();
compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
context_factory,
compositor_task_runner_.get()));
compositor_.reset(
new ui::Compositor(context_factory, compositor_task_runner_.get()));
compositor_->SetAcceleratedWidgetAndStartCompositor(
gfx::kNullAcceleratedWidget);
context_provider_ = cc::TestContextProvider::Create(
cc::TestWebGraphicsContext3D::Create().Pass());
output_surface_ =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ void SoftwareBrowserCompositorOutputSurfaceTest::SetUp() {
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);

compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
context_factory,
base::ThreadTaskRunnerHandle::Get()));
compositor_.reset(
new ui::Compositor(context_factory, base::ThreadTaskRunnerHandle::Get()));
compositor_->SetAcceleratedWidgetAndStartCompositor(
gfx::kNullAcceleratedWidget);
}

void SoftwareBrowserCompositorOutputSurfaceTest::TearDown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ void SoftwareOutputDeviceOzoneTest::SetUp() {
const gfx::Size size(500, 400);
window_ = ui::OzonePlatform::GetInstance()->CreatePlatformWindow(
&window_delegate_, gfx::Rect(size));
compositor_.reset(new ui::Compositor(window_delegate_.GetAcceleratedWidget(),
context_factory,
base::ThreadTaskRunnerHandle::Get()));
compositor_.reset(
new ui::Compositor(context_factory, base::ThreadTaskRunnerHandle::Get()));
compositor_->SetAcceleratedWidgetAndStartCompositor(
window_delegate_.GetAcceleratedWidget());
compositor_->SetScaleAndSize(1.0f, size);

output_device_.reset(new content::SoftwareOutputDeviceOzone(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class BeginFrameObserverProxyTest : public testing::Test {
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(enable_pixel_output);
compositor_task_runner_ = new base::TestSimpleTaskRunner();
compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
context_factory,
compositor_task_runner_));
compositor_.reset(
new ui::Compositor(context_factory, compositor_task_runner_));
compositor_->SetAcceleratedWidgetAndStartCompositor(
gfx::kNullAcceleratedWidget);
}

void TearDown() override {
Expand Down
3 changes: 2 additions & 1 deletion mandoline/ui/aura/window_tree_host_mojo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ WindowTreeHostMojo::WindowTreeHostMojo(mojo::Shell* shell, mojo::View* view)
ui::ContextFactory* default_context_factory =
aura::Env::GetInstance()->context_factory();
aura::Env::GetInstance()->set_context_factory(context_factory_.get());
CreateCompositor(GetAcceleratedWidget());
CreateCompositor();
OnAcceleratedWidgetAvailable();
aura::Env::GetInstance()->set_context_factory(default_context_factory);
DCHECK_EQ(context_factory_.get(), compositor()->context_factory());

Expand Down
6 changes: 4 additions & 2 deletions ui/aura/remote_window_tree_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ RemoteWindowTreeHostWin::RemoteWindowTreeHostWin()
CHECK(!g_instance);
g_instance = this;
prop_.reset(new ui::ViewProp(NULL, kWindowTreeHostWinKey, this));
CreateCompositor(GetAcceleratedWidget());
CreateCompositor();
OnAcceleratedWidgetAvailable();
}

RemoteWindowTreeHostWin::~RemoteWindowTreeHostWin() {
Expand All @@ -123,7 +124,8 @@ void RemoteWindowTreeHostWin::Connected(IPC::Sender* host) {
host_ = host;
// Recreate the compositor for the target surface represented by the
// remote_window HWND.
CreateCompositor(remote_window_);
CreateCompositor();
OnAcceleratedWidgetAvailable();
InitCompositor();
}

Expand Down
18 changes: 8 additions & 10 deletions ui/aura/window_tree_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -239,30 +239,28 @@ void WindowTreeHost::DestroyDispatcher() {
//window()->RemoveOrDestroyChildren();
}

void WindowTreeHost::CreateCompositor(
gfx::AcceleratedWidget accelerated_widget) {
void WindowTreeHost::CreateCompositor() {
DCHECK(Env::GetInstance());
ui::ContextFactory* context_factory = Env::GetInstance()->context_factory();
DCHECK(context_factory);
compositor_.reset(
new ui::Compositor(GetAcceleratedWidget(),
context_factory,
base::ThreadTaskRunnerHandle::Get()));
// TODO(beng): I think this setup should probably all move to a "accelerated
// widget available" function.
new ui::Compositor(context_factory, base::ThreadTaskRunnerHandle::Get()));
if (!dispatcher()) {
window()->Init(ui::LAYER_NOT_DRAWN);
window()->set_host(this);
window()->SetName("RootWindow");
window()->SetEventTargeter(
scoped_ptr<ui::EventTargeter>(new WindowTargeter()));
prop_.reset(new ui::ViewProp(GetAcceleratedWidget(),
kWindowTreeHostForAcceleratedWidget,
this));
dispatcher_.reset(new WindowEventDispatcher(this));
}
}

void WindowTreeHost::OnAcceleratedWidgetAvailable() {
compositor_->SetAcceleratedWidgetAndStartCompositor(GetAcceleratedWidget());
prop_.reset(new ui::ViewProp(GetAcceleratedWidget(),
kWindowTreeHostForAcceleratedWidget, this));
}

void WindowTreeHost::OnHostMoved(const gfx::Point& new_location) {
TRACE_EVENT1("ui", "WindowTreeHost::OnHostMoved",
"origin", new_location.ToString());
Expand Down
3 changes: 2 additions & 1 deletion ui/aura/window_tree_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ class AURA_EXPORT WindowTreeHost : public ui::internal::InputMethodDelegate,
void DestroyCompositor();
void DestroyDispatcher();

void CreateCompositor(gfx::AcceleratedWidget accelerated_widget);
void CreateCompositor();
void OnAcceleratedWidgetAvailable();

// Returns the location of the RootWindow on native screen.
virtual gfx::Point GetLocationOnNativeScreen() const = 0;
Expand Down
3 changes: 2 additions & 1 deletion ui/aura/window_tree_host_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO]);
CreateCompositor(GetAcceleratedWidget());
CreateCompositor();
OnAcceleratedWidgetAvailable();
}

WindowTreeHostMac::~WindowTreeHostMac() {
Expand Down
3 changes: 2 additions & 1 deletion ui/aura/window_tree_host_ozone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ void WindowTreeHostOzone::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget,
float device_pixel_ratio) {
widget_ = widget;
CreateCompositor(widget_);
CreateCompositor();
WindowTreeHost::OnAcceleratedWidgetAvailable();
}

void WindowTreeHostOzone::OnActivationChanged(bool active) {
Expand Down
3 changes: 2 additions & 1 deletion ui/aura/window_tree_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ void WindowTreeHostWin::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget,
float device_pixel_ratio) {
widget_ = widget;
CreateCompositor(widget);
CreateCompositor();
WindowTreeHost::OnAcceleratedWidgetAvailable();
}

void WindowTreeHostWin::OnActivationChanged(bool active) {
Expand Down
3 changes: 2 additions & 1 deletion ui/aura/window_tree_host_x11.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ WindowTreeHostX11::WindowTreeHostX11(const gfx::Rect& bounds)

XRRSelectInput(xdisplay_, x_root_window_,
RRScreenChangeNotifyMask | RROutputChangeNotifyMask);
CreateCompositor(GetAcceleratedWidget());
CreateCompositor();
OnAcceleratedWidgetAvailable();
}

WindowTreeHostX11::~WindowTreeHostX11() {
Expand Down
14 changes: 10 additions & 4 deletions ui/compositor/compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ void CompositorLock::CancelLock() {
compositor_ = NULL;
}

Compositor::Compositor(gfx::AcceleratedWidget widget,
ui::ContextFactory* context_factory,
Compositor::Compositor(ui::ContextFactory* context_factory,
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
: context_factory_(context_factory),
root_layer_(NULL),
widget_(widget),
widget_(gfx::kNullAcceleratedWidget),
surface_id_allocator_(context_factory->CreateSurfaceIdAllocator()),
task_runner_(task_runner),
vsync_manager_(new CompositorVSyncManager()),
Expand Down Expand Up @@ -177,7 +176,6 @@ Compositor::Compositor(gfx::AcceleratedWidget widget,
base::TimeTicks::Now() - before_create);
host_->SetRootLayer(root_web_layer_);
host_->set_surface_id_namespace(surface_id_allocator_->id_namespace());
host_->SetLayerTreeHostClientReady();
}

Compositor::~Compositor() {
Expand Down Expand Up @@ -299,6 +297,14 @@ void Compositor::SetAuthoritativeVSyncInterval(
vsync_manager_->SetAuthoritativeVSyncInterval(interval);
}

void Compositor::SetAcceleratedWidgetAndStartCompositor(
gfx::AcceleratedWidget widget) {
// This function should only get called once.
DCHECK_EQ(gfx::kNullAcceleratedWidget, widget_);
widget_ = widget;
host_->SetLayerTreeHostClientReady();
}

scoped_refptr<CompositorVSyncManager> Compositor::vsync_manager() const {
return vsync_manager_;
}
Expand Down
6 changes: 3 additions & 3 deletions ui/compositor/compositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ class COMPOSITOR_EXPORT Compositor
: NON_EXPORTED_BASE(public cc::LayerTreeHostClient),
NON_EXPORTED_BASE(public cc::LayerTreeHostSingleThreadClient) {
public:
Compositor(gfx::AcceleratedWidget widget,
ui::ContextFactory* context_factory,
Compositor(ui::ContextFactory* context_factory,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~Compositor() override;

Expand Down Expand Up @@ -230,7 +229,8 @@ class COMPOSITOR_EXPORT Compositor
// context.
void SetAuthoritativeVSyncInterval(const base::TimeDelta& interval);

// Returns the widget for this compositor.
// Sets the widget for the compositor to render into.
void SetAcceleratedWidgetAndStartCompositor(gfx::AcceleratedWidget widget);
gfx::AcceleratedWidget widget() const { return widget_; }

// Returns the vsync manager for this compositor.
Expand Down
5 changes: 3 additions & 2 deletions ui/compositor/compositor_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class CompositorTest : public testing::Test {
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(false);

compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
context_factory, task_runner_));
compositor_.reset(new ui::Compositor(context_factory, task_runner_));
compositor_->SetAcceleratedWidgetAndStartCompositor(
gfx::kNullAcceleratedWidget);
}
void TearDown() override {
compositor_.reset();
Expand Down
5 changes: 3 additions & 2 deletions ui/compositor/layer_owner_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ void LayerOwnerTestWithCompositor::SetUp() {
ui::ContextFactory* context_factory =
ui::InitializeContextFactoryForTests(false);

compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
context_factory, task_runner));
compositor_.reset(new ui::Compositor(context_factory, task_runner));
compositor_->SetAcceleratedWidgetAndStartCompositor(
gfx::kNullAcceleratedWidget);
}

void LayerOwnerTestWithCompositor::TearDown() {
Expand Down
2 changes: 1 addition & 1 deletion ui/compositor/test/test_compositor_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TestCompositorHost {
static TestCompositorHost* Create(const gfx::Rect& bounds,
ui::ContextFactory* context_factory);

// Shows the TestCompositorHost.
// Shows the TestCompositorHost. Must only be called once.
virtual void Show() = 0;

virtual Compositor* GetCompositor() = 0;
Expand Down
17 changes: 9 additions & 8 deletions ui/compositor/test/test_compositor_host_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ - (void)drawRect:(NSRect)rect {

ui::ContextFactory* context_factory_;

scoped_ptr<ui::Compositor> compositor_;
ui::Compositor compositor_;

// Owned. Released when window is closed.
NSWindow* window_;
Expand All @@ -105,7 +105,10 @@ - (void)drawRect:(NSRect)rect {
TestCompositorHostMac::TestCompositorHostMac(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory)
: bounds_(bounds), context_factory_(context_factory), window_(nil) {
: bounds_(bounds),
context_factory_(context_factory),
compositor_(context_factory, base::ThreadTaskRunnerHandle::Get()),
window_(nil) {
}

TestCompositorHostMac::~TestCompositorHostMac() {
Expand All @@ -130,17 +133,15 @@ - (void)drawRect:(NSRect)rect {
defer:NO];
base::scoped_nsobject<AcceleratedTestView> view(
[[AcceleratedTestView alloc] init]);
compositor_.reset(new ui::Compositor(view,
context_factory_,
base::ThreadTaskRunnerHandle::Get()));
compositor_->SetScaleAndSize(1.0f, bounds_.size());
[view setCompositor:compositor_.get()];
compositor_.SetAcceleratedWidgetAndStartCompositor(view);
compositor_.SetScaleAndSize(1.0f, bounds_.size());
[view setCompositor:&compositor_];
[window_ setContentView:view];
[window_ orderFront:nil];
}

ui::Compositor* TestCompositorHostMac::GetCompositor() {
return compositor_.get();
return &compositor_;
}

// static
Expand Down
13 changes: 6 additions & 7 deletions ui/compositor/test/test_compositor_host_ozone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TestCompositorHostOzone : public TestCompositorHost {

ui::ContextFactory* context_factory_;

scoped_ptr<ui::Compositor> compositor_;
ui::Compositor compositor_;

DISALLOW_COPY_AND_ASSIGN(TestCompositorHostOzone);
};
Expand All @@ -40,7 +40,8 @@ TestCompositorHostOzone::TestCompositorHostOzone(
const gfx::Rect& bounds,
ui::ContextFactory* context_factory)
: bounds_(bounds),
context_factory_(context_factory) {}
context_factory_(context_factory),
compositor_(context_factory, base::ThreadTaskRunnerHandle::Get()) {}

TestCompositorHostOzone::~TestCompositorHostOzone() {}

Expand All @@ -52,14 +53,12 @@ void TestCompositorHostOzone::Show() {
// with a non-0 widget.
// TODO(rjkroege): Use a "real" ozone widget when it is
// available: http://crbug.com/255128
compositor_.reset(new ui::Compositor(1,
context_factory_,
base::ThreadTaskRunnerHandle::Get()));
compositor_->SetScaleAndSize(1.0f, bounds_.size());
compositor_.SetAcceleratedWidgetAndStartCompositor(1);
compositor_.SetScaleAndSize(1.0f, bounds_.size());
}

ui::Compositor* TestCompositorHostOzone::GetCompositor() {
return compositor_.get();
return &compositor_;
}

// static
Expand Down
4 changes: 2 additions & 2 deletions ui/compositor/test/test_compositor_host_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class TestCompositorHostWin : public TestCompositorHost,
TestCompositorHostWin(const gfx::Rect& bounds,
ui::ContextFactory* context_factory) {
Init(NULL, bounds);
compositor_.reset(new ui::Compositor(hwnd(),
context_factory,
compositor_.reset(new ui::Compositor(context_factory,
base::ThreadTaskRunnerHandle::Get()));
compositor_->SetAcceleratedWidgetAndStartCompositor(hwnd());
compositor_->SetScaleAndSize(1.0f, GetSize());
}

Expand Down
Loading

0 comments on commit b2a31d3

Please sign in to comment.