Chromium Code Reviews| Index: services/ui/demo/mus_demo.cc |
| diff --git a/services/ui/demo/mus_demo.cc b/services/ui/demo/mus_demo.cc |
| index 0fbcd356c25475ef3794f4687541853891d9582f..1cfb2619fbbb91c4846312cf6bb520db0af36002 100644 |
| --- a/services/ui/demo/mus_demo.cc |
| +++ b/services/ui/demo/mus_demo.cc |
| @@ -4,11 +4,13 @@ |
| #include "services/ui/demo/mus_demo.h" |
| +#include "base/command_line.h" |
| #include "base/memory/ptr_util.h" |
| #include "base/time/time.h" |
| #include "services/service_manager/public/cpp/connector.h" |
| #include "services/service_manager/public/cpp/service_context.h" |
| #include "services/ui/public/cpp/gpu/gpu.h" |
| +#include "services/ui/public/interfaces/constants.mojom.h" |
| #include "third_party/skia/include/core/SkBitmap.h" |
| #include "third_party/skia/include/core/SkCanvas.h" |
| #include "third_party/skia/include/core/SkColor.h" |
| @@ -67,6 +69,55 @@ void DrawSquare(const gfx::Rect& bounds, double angle, SkCanvas* canvas) { |
| } // namespace |
| +class MusDemo::WindowTreeData { |
| + public: |
| + explicit WindowTreeData( |
| + std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| + Init(std::move(window_tree_host)); |
| + } |
| + explicit WindowTreeData(mojom::WindowTreeHostFactory* factory, |
| + mojom::WindowTreeClientPtr tree_client) { |
| + factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client)); |
| + } |
| + ~WindowTreeData(); |
| + |
| + // Initializes the window tree host and start drawing frames. |
| + void Init(std::unique_ptr<aura::WindowTreeHostMus> window_tree_host); |
| + |
| + private: |
| + bool IsInitialized() { return !!window_tree_host_; } |
| + |
| + // Draws one frame, incrementing the rotation angle. |
| + void DrawFrame(); |
| + |
| + // The Window tree host corresponding to this data. |
| + // When the WindowTreeData is created with WindowTreeHostFactory, it remains |
| + // null until an explicit call to Init. |
| + std::unique_ptr<aura::WindowTreeHostMus> window_tree_host_; |
| + |
| + // When the WindowTreeData is created with WindowTreeHostFactory, this holds |
| + // the Mojo pointer to the window tree host. |
| + mojom::WindowTreeHostPtr host_; |
| + |
| + // Root window of the window tree host. |
| + aura::Window* root_window_ = nullptr; |
| + |
| + // Window to which we draw the bitmap. |
| + std::unique_ptr<aura::Window> bitmap_window_; |
| + |
| + // Destroys itself when the window gets destroyed. |
| + aura_extra::ImageWindowDelegate* window_delegate_ = nullptr; |
| + |
| + // Timer for calling DrawFrame(). |
| + base::RepeatingTimer timer_; |
| + |
| + // Current rotation angle for drawing. |
| + double angle_ = 0.0; |
| + |
| + // Last time a frame was drawn. |
| + base::TimeTicks last_draw_frame_time_; |
| +}; |
| + |
| MusDemo::MusDemo() {} |
| MusDemo::~MusDemo() { |
| @@ -74,6 +125,8 @@ MusDemo::~MusDemo() { |
| } |
| void MusDemo::OnStart() { |
| + external_window_mode_ = |
| + base::CommandLine::ForCurrentProcess()->HasSwitch("external-window-mode"); |
| screen_ = base::MakeUnique<display::ScreenBase>(); |
| display::Screen::SetScreenInstance(screen_.get()); |
| @@ -82,9 +135,21 @@ void MusDemo::OnStart() { |
| property_converter_ = base::MakeUnique<aura::PropertyConverter>(); |
| wm_state_ = base::MakeUnique<::wm::WMState>(); |
| - window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>( |
| - context()->connector(), this, this); |
| - window_tree_client_->ConnectAsWindowManager(); |
| + if (external_window_mode_) { |
| + context()->connector()->BindInterface(ui::mojom::kServiceName, |
| + &window_tree_host_factory_); |
| + mojom::WindowTreeClientPtr tree_client; |
| + window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>( |
|
rjkroege
2017/02/09 18:03:53
I would like mus demo to not depend on aura in eit
fwang
2017/02/09 18:50:38
I'm not sure I understand this comment. Mus demo h
|
| + context()->connector(), this, this, MakeRequest(&tree_client)); |
| + window_tree_data_ = base::MakeUnique<WindowTreeData>( |
| + window_tree_host_factory_.get(), std::move(tree_client)); |
| + // TODO: Management of display (CL 2645093003 and 2684623002)? |
|
rjkroege
2017/02/09 18:03:53
Need a ScreenManagerOzoneExternal I would think. P
|
| + // TODO: Demo of two external windows. |
| + } else { |
| + window_tree_client_ = base::MakeUnique<aura::WindowTreeClient>( |
| + context()->connector(), this, this); |
| + window_tree_client_->ConnectAsWindowManager(); |
| + } |
| env_->SetWindowTreeClient(window_tree_client_.get()); |
| } |
| @@ -96,8 +161,9 @@ bool MusDemo::OnConnect(const service_manager::ServiceInfo& remote_info, |
| void MusDemo::OnEmbed( |
| std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| - // Not called for the WindowManager. |
| - NOTREACHED(); |
| + DCHECK(external_window_mode_); |
| + DCHECK(window_tree_data_); |
| + window_tree_data_->Init(std::move(window_tree_host)); |
| } |
| void MusDemo::OnUnembed(aura::Window* root) { |
| @@ -105,14 +171,13 @@ void MusDemo::OnUnembed(aura::Window* root) { |
| } |
| void MusDemo::OnEmbedRootDestroyed(aura::WindowTreeHostMus* window_tree_host) { |
| - // Not called for the WindowManager. |
| - NOTREACHED(); |
| + DCHECK(external_window_mode_); |
| + window_tree_data_.reset(); |
| } |
| void MusDemo::OnLostConnection(aura::WindowTreeClient* client) { |
| - root_window_ = nullptr; |
| window_tree_client_.reset(); |
| - timer_.Stop(); |
| + window_tree_data_.reset(); |
| } |
| void MusDemo::OnPointerEventObserved(const PointerEvent& event, |
| @@ -157,8 +222,14 @@ void MusDemo::OnWmWillCreateDisplay(const display::Display& display) { |
| void MusDemo::OnWmNewDisplay( |
| std::unique_ptr<aura::WindowTreeHostMus> window_tree_host, |
| const display::Display& display) { |
| - DCHECK(!root_window_); // Only support one display. |
| + DCHECK(!external_window_mode_); |
| + DCHECK(!window_tree_data_); // Only support one display. |
| + window_tree_data_ = |
| + base::MakeUnique<WindowTreeData>(std::move(window_tree_host)); |
| +} |
| +void MusDemo::WindowTreeData::Init( |
| + std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| window_tree_host->InitHost(); |
| window_tree_host->Show(); |
| root_window_ = window_tree_host->window(); |
| @@ -178,13 +249,19 @@ void MusDemo::OnWmNewDisplay( |
| // Draw initial frame and start the timer to regularly draw frames. |
| DrawFrame(); |
| timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kFrameDelay), |
| - base::Bind(&MusDemo::DrawFrame, base::Unretained(this))); |
| + base::Bind(&WindowTreeData::DrawFrame, base::Unretained(this))); |
| } |
| void MusDemo::OnWmDisplayRemoved(aura::WindowTreeHostMus* window_tree_host) { |
| - timer_.Stop(); |
| - root_window_->RemoveChild(bitmap_window_.get()); |
| - bitmap_window_.reset(); |
| + window_tree_data_.reset(); |
| +} |
| + |
| +MusDemo::WindowTreeData::~WindowTreeData() { |
| + if (IsInitialized()) { |
| + timer_.Stop(); |
| + root_window_->RemoveChild(bitmap_window_.get()); |
| + bitmap_window_.reset(); |
| + } |
| } |
| void MusDemo::OnWmDisplayModified(const display::Display& display) {} |
| @@ -211,7 +288,7 @@ bool MusDemo::IsWindowActive(aura::Window* window) { return false; } |
| void MusDemo::OnWmDeactivateWindow(aura::Window* window) {} |
| -void MusDemo::DrawFrame() { |
| +void MusDemo::WindowTreeData::DrawFrame() { |
| base::TimeTicks now = base::TimeTicks::Now(); |
| VLOG(1) << (now - last_draw_frame_time_).InMilliseconds() |