Skip to content

Commit

Permalink
Mus Demo: Demonstrate external window mode
Browse files Browse the repository at this point in the history
Previously the only user of mus was ChromeOS, and so Chrome currently
creates all toplevel windows as children of an ash-managed root window.
In this sense, all created windows are 'internal' to this virtual root.
However, as desktop Linux also transitions to using Mus, it is necessary
to support 'external' window mode where toplevel windows are created as
native (x11, wayland, ...) windows.

This CL adjusts the Mus Demo so that non-ChromeOS Ozone platforms work
in external mode. For now, only a single external window is created by
Mus Demo. Supporting multiple external windows will require some code
refactoring in WindowTreeHostFactory that will be handled in a
follow-up CL [1].

The CL also disables an assertion for these non-ChromeOS Ozone platforms
until display & screen managers are refactored to remove assumptions
specific to internal mode [2].

[1] https://codereview.chromium.org/2700493005
[2] https://bugs.chromium.org/p/chromium/issues/detail?id=693081

BUG=666958
TEST=./out/LinuxOzoneX11/mash --service=mus_demo --ozone-platform=x11 or ./out/LinuxOzoneX11/mus_demo_unittests --ozone-platform=x11

Review-Url: https://codereview.chromium.org/2622103004
Cr-Commit-Position: refs/heads/master@{#451922}
  • Loading branch information
fred-wang authored and Commit bot committed Feb 22, 2017
1 parent 453d588 commit 12d9a31
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 16 deletions.
27 changes: 22 additions & 5 deletions services/ui/demo/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/ui.gni")
import("//services/catalog/public/tools/catalog.gni")
import("//services/service_manager/public/cpp/service.gni")
import("//services/service_manager/public/service_manifest.gni")
Expand All @@ -12,12 +13,22 @@ source_set("lib") {
sources = [
"mus_demo.cc",
"mus_demo.h",
"mus_demo_internal.cc",
"mus_demo_internal.h",
"window_tree_data.cc",
"window_tree_data.h",
]

if (use_ozone && !is_chromeos) {
sources += [
"mus_demo_external.cc",
"mus_demo_external.h",
]
} else {
sources += [
"mus_demo_internal.cc",
"mus_demo_internal.h",
]
}

public_deps = [
"//services/service_manager/public/cpp:sources",
"//skia",
Expand All @@ -38,9 +49,15 @@ source_set("lib") {
}

service("mus_demo") {
sources = [
"main.cc",
]
if (use_ozone && !is_chromeos) {
sources = [
"main_external.cc",
]
} else {
sources = [
"main_internal.cc",
]
}

deps = [
":lib",
Expand Down
12 changes: 12 additions & 0 deletions services/ui/demo/main_external.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/service_manager/public/c/main.h"
#include "services/service_manager/public/cpp/service_runner.h"
#include "services/ui/demo/mus_demo_external.h"

MojoResult ServiceMain(MojoHandle service_request_handle) {
service_manager::ServiceRunner runner(new ui::demo::MusDemoExternal);
return runner.Run(service_request_handle);
}
File renamed without changes.
2 changes: 1 addition & 1 deletion services/ui/demo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"interface_provider_specs": {
"service_manager:connector": {
"requires": {
"ui": [ "window_manager" ]
"ui": [ "window_manager", "window_tree_host_factory" ]
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion services/ui/demo/mus_demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void MusDemo::OnStart() {
property_converter_ = base::MakeUnique<aura::PropertyConverter>();
wm_state_ = base::MakeUnique<::wm::WMState>();

OnStartImpl(window_tree_client_, window_tree_data_);
OnStartImpl(&window_tree_client_, &window_tree_data_);

env_->SetWindowTreeClient(window_tree_client_.get());
}
Expand Down
4 changes: 2 additions & 2 deletions services/ui/demo/mus_demo.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class MusDemo : public service_manager::Service,

private:
virtual void OnStartImpl(
std::unique_ptr<aura::WindowTreeClient>& window_tree_client,
std::unique_ptr<WindowTreeData>& window_tree_data) = 0;
std::unique_ptr<aura::WindowTreeClient>* window_tree_client,
std::unique_ptr<WindowTreeData>* window_tree_data) = 0;

// service_manager::Service:
void OnStart() override;
Expand Down
73 changes: 73 additions & 0 deletions services/ui/demo/mus_demo_external.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "services/ui/demo/mus_demo_external.h"

#include "services/service_manager/public/cpp/service_context.h"
#include "services/ui/demo/window_tree_data.h"
#include "services/ui/public/interfaces/constants.mojom.h"
#include "services/ui/public/interfaces/window_tree_host.mojom.h"
#include "ui/aura/mus/window_tree_client.h"
#include "ui/aura/mus/window_tree_host_mus.h"
#include "ui/display/display.h"

namespace ui {
namespace demo {

namespace {

class WindowTreeDataExternal : public WindowTreeData {
public:
// Creates a new window tree host associated to the WindowTreeData.
WindowTreeDataExternal(mojom::WindowTreeHostFactory* factory,
mojom::WindowTreeClientPtr tree_client,
int square_size)
: WindowTreeData(square_size) {
factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client));
}

private:
// Holds the Mojo pointer to the window tree host.
mojom::WindowTreeHostPtr host_;
};

// Size of square in pixels to draw.
const int kSquareSize = 500;
} // namespace

MusDemoExternal::MusDemoExternal() {}

MusDemoExternal::~MusDemoExternal() {}

void MusDemoExternal::OnStartImpl(
std::unique_ptr<aura::WindowTreeClient>* window_tree_client,
std::unique_ptr<WindowTreeData>* window_tree_data) {
context()->connector()->BindInterface(ui::mojom::kServiceName,
&window_tree_host_factory_);
mojom::WindowTreeClientPtr tree_client;
*window_tree_client = base::MakeUnique<aura::WindowTreeClient>(
context()->connector(), this, nullptr, MakeRequest(&tree_client));
// TODO(tonikitoo,fwang): Open two external windows with different square
// sizes.
*window_tree_data = base::MakeUnique<WindowTreeDataExternal>(
window_tree_host_factory_.get(), std::move(tree_client), kSquareSize);

// TODO(tonikitoo,fwang): Implement management of displays in external mode.
// For now, a fake display is created in order to work around an assertion in
// aura::GetDeviceScaleFactorFromDisplay().
AddPrimaryDisplay(display::Display(0));
}

void MusDemoExternal::OnEmbed(
std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
InitWindowTreeData(std::move(window_tree_host));
}

void MusDemoExternal::OnEmbedRootDestroyed(
aura::WindowTreeHostMus* window_tree_host) {
CleanupWindowTreeData();
}

} // namespace demo
} // namespace ui
41 changes: 41 additions & 0 deletions services/ui/demo/mus_demo_external.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_UI_DEMO_MUS_DEMO_EXTERNAL_H_
#define SERVICES_UI_DEMO_MUS_DEMO_EXTERNAL_H_

#include <memory>
#include <vector>

#include "services/ui/demo/mus_demo.h"
#include "services/ui/public/interfaces/window_tree_host.mojom.h"

namespace ui {
namespace demo {

// MusDemoExternal demonstrates Mus operating in "external" mode: A new platform
// window (and hence acceleratedWidget) is created for each aura window.
class MusDemoExternal : public MusDemo {
public:
MusDemoExternal();
~MusDemoExternal() final;

private:
// ui::demo::MusDemo:
void OnStartImpl(std::unique_ptr<aura::WindowTreeClient>* window_tree_client,
std::unique_ptr<WindowTreeData>* window_tree_data) final;

// aura::WindowTreeClientDelegate:
void OnEmbed(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) final;
void OnEmbedRootDestroyed(aura::WindowTreeHostMus* window_tree_host) final;

mojom::WindowTreeHostFactoryPtr window_tree_host_factory_;

DISALLOW_COPY_AND_ASSIGN(MusDemoExternal);
};

} // namespace demo
} // namespace ui

#endif // SERVICES_UI_DEMO_MUS_DEMO_EXTERNAL_H_
10 changes: 5 additions & 5 deletions services/ui/demo/mus_demo_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ MusDemoInternal::MusDemoInternal() {}
MusDemoInternal::~MusDemoInternal() {}

void MusDemoInternal::OnStartImpl(
std::unique_ptr<aura::WindowTreeClient>& window_tree_client,
std::unique_ptr<WindowTreeData>& window_tree_data) {
window_tree_client = base::MakeUnique<aura::WindowTreeClient>(
std::unique_ptr<aura::WindowTreeClient>* window_tree_client,
std::unique_ptr<WindowTreeData>* window_tree_data) {
*window_tree_client = base::MakeUnique<aura::WindowTreeClient>(
context()->connector(), this, this);
window_tree_client->ConnectAsWindowManager();
window_tree_data = base::MakeUnique<WindowTreeData>(kSquareSize);
window_tree_client->get()->ConnectAsWindowManager();
*window_tree_data = base::MakeUnique<WindowTreeData>(kSquareSize);
}

void MusDemoInternal::SetWindowManagerClient(
Expand Down
8 changes: 6 additions & 2 deletions services/ui/demo/mus_demo_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@
namespace ui {
namespace demo {

// MusDemoInternal demonstrates Mus operating in "internal" mode: There is a
// single acceleratedWidget for a single display and all aura windows are
// contained in that display.
class MusDemoInternal : public MusDemo, public aura::WindowManagerDelegate {
public:
MusDemoInternal();
~MusDemoInternal() final;

private:
void OnStartImpl(std::unique_ptr<aura::WindowTreeClient>& window_tree_client,
std::unique_ptr<WindowTreeData>& window_tree_data) final;
// ui::demo::MusDemo:
void OnStartImpl(std::unique_ptr<aura::WindowTreeClient>* window_tree_client,
std::unique_ptr<WindowTreeData>* window_tree_data) final;

// aura::WindowManagerDelegate:
void SetWindowManagerClient(aura::WindowManagerClient* client) final;
Expand Down

0 comments on commit 12d9a31

Please sign in to comment.