| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/mus/mus_app.h" | 5 #include "components/mus/mus_app.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "components/mus/common/args.h" | 9 #include "components/mus/common/args.h" |
| 10 #include "components/mus/gles2/gpu_impl.h" | 10 #include "components/mus/gles2/gpu_impl.h" |
| 11 #include "components/mus/ws/client_connection.h" | 11 #include "components/mus/ws/client_connection.h" |
| 12 #include "components/mus/ws/connection_manager.h" | 12 #include "components/mus/ws/connection_manager.h" |
| 13 #include "components/mus/ws/window_tree_factory.h" | 13 #include "components/mus/ws/window_tree_factory.h" |
| 14 #include "components/mus/ws/window_tree_host_connection.h" | 14 #include "components/mus/ws/window_tree_host_connection.h" |
| 15 #include "components/mus/ws/window_tree_host_impl.h" | 15 #include "components/mus/ws/window_tree_host_impl.h" |
| 16 #include "components/mus/ws/window_tree_impl.h" | 16 #include "components/mus/ws/window_tree_impl.h" |
| 17 #include "mojo/public/c/system/main.h" | 17 #include "mojo/public/c/system/main.h" |
| 18 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 18 #include "mojo/services/tracing/public/cpp/tracing_impl.h" |
| 19 #include "mojo/shell/public/cpp/application_connection.h" | 19 #include "mojo/shell/public/cpp/application_connection.h" |
| 20 #include "mojo/shell/public/cpp/application_impl.h" | 20 #include "mojo/shell/public/cpp/shell.h" |
| 21 #include "mojo/shell/public/cpp/application_runner.h" | |
| 22 #include "ui/events/event_switches.h" | 21 #include "ui/events/event_switches.h" |
| 23 #include "ui/events/platform/platform_event_source.h" | 22 #include "ui/events/platform/platform_event_source.h" |
| 24 #include "ui/gl/gl_surface.h" | 23 #include "ui/gl/gl_surface.h" |
| 25 | 24 |
| 26 #if defined(USE_X11) | 25 #if defined(USE_X11) |
| 27 #include <X11/Xlib.h> | 26 #include <X11/Xlib.h> |
| 28 #include "base/command_line.h" | 27 #include "base/command_line.h" |
| 29 #include "ui/platform_window/x11/x11_window.h" | 28 #include "ui/platform_window/x11/x11_window.h" |
| 30 #elif defined(USE_OZONE) | 29 #elif defined(USE_OZONE) |
| 31 #include "ui/ozone/public/ozone_platform.h" | 30 #include "ui/ozone/public/ozone_platform.h" |
| 32 #endif | 31 #endif |
| 33 | 32 |
| 34 using mojo::ApplicationConnection; | 33 using mojo::ApplicationConnection; |
| 35 using mojo::ApplicationImpl; | |
| 36 using mojo::InterfaceRequest; | 34 using mojo::InterfaceRequest; |
| 37 using mus::mojom::WindowTreeHostFactory; | 35 using mus::mojom::WindowTreeHostFactory; |
| 38 using mus::mojom::Gpu; | 36 using mus::mojom::Gpu; |
| 39 | 37 |
| 40 namespace mus { | 38 namespace mus { |
| 41 | 39 |
| 42 // TODO(sky): this is a pretty typical pattern, make it easier to do. | 40 // TODO(sky): this is a pretty typical pattern, make it easier to do. |
| 43 struct MandolineUIServicesApp::PendingRequest { | 41 struct MandolineUIServicesApp::PendingRequest { |
| 44 scoped_ptr<mojo::InterfaceRequest<mojom::DisplayManager>> dm_request; | 42 scoped_ptr<mojo::InterfaceRequest<mojom::DisplayManager>> dm_request; |
| 45 scoped_ptr<mojo::InterfaceRequest<mojom::WindowTreeFactory>> wtf_request; | 43 scoped_ptr<mojo::InterfaceRequest<mojom::WindowTreeFactory>> wtf_request; |
| 46 }; | 44 }; |
| 47 | 45 |
| 48 MandolineUIServicesApp::MandolineUIServicesApp() | 46 MandolineUIServicesApp::MandolineUIServicesApp() |
| 49 : app_impl_(nullptr) {} | 47 : shell_(nullptr) {} |
| 50 | 48 |
| 51 MandolineUIServicesApp::~MandolineUIServicesApp() { | 49 MandolineUIServicesApp::~MandolineUIServicesApp() { |
| 52 if (gpu_state_) | 50 if (gpu_state_) |
| 53 gpu_state_->StopThreads(); | 51 gpu_state_->StopThreads(); |
| 54 // Destroy |connection_manager_| first, since it depends on |event_source_|. | 52 // Destroy |connection_manager_| first, since it depends on |event_source_|. |
| 55 connection_manager_.reset(); | 53 connection_manager_.reset(); |
| 56 } | 54 } |
| 57 | 55 |
| 58 void MandolineUIServicesApp::Initialize(ApplicationImpl* app) { | 56 void MandolineUIServicesApp::Initialize(mojo::Shell* shell, |
| 59 app_impl_ = app; | 57 const std::string& url, |
| 58 uint32_t id) { |
| 59 shell_ = shell; |
| 60 surfaces_state_ = new SurfacesState; | 60 surfaces_state_ = new SurfacesState; |
| 61 | 61 |
| 62 #if defined(USE_X11) | 62 #if defined(USE_X11) |
| 63 XInitThreads(); | 63 XInitThreads(); |
| 64 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 64 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 65 if (command_line->HasSwitch(kUseX11TestConfig)) { | 65 if (command_line->HasSwitch(kUseX11TestConfig)) { |
| 66 ui::test::SetUseOverrideRedirectWindowByDefault(true); | 66 ui::test::SetUseOverrideRedirectWindowByDefault(true); |
| 67 } | 67 } |
| 68 #endif | 68 #endif |
| 69 | 69 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 80 hardware_rendering_available = gfx::GLSurface::InitializeOneOff(); | 80 hardware_rendering_available = gfx::GLSurface::InitializeOneOff(); |
| 81 event_source_ = ui::PlatformEventSource::CreateDefault(); | 81 event_source_ = ui::PlatformEventSource::CreateDefault(); |
| 82 #endif | 82 #endif |
| 83 | 83 |
| 84 // TODO(rjkroege): It is possible that we might want to generalize the | 84 // TODO(rjkroege): It is possible that we might want to generalize the |
| 85 // GpuState object. | 85 // GpuState object. |
| 86 if (!gpu_state_.get()) | 86 if (!gpu_state_.get()) |
| 87 gpu_state_ = new GpuState(hardware_rendering_available); | 87 gpu_state_ = new GpuState(hardware_rendering_available); |
| 88 connection_manager_.reset(new ws::ConnectionManager(this, surfaces_state_)); | 88 connection_manager_.reset(new ws::ConnectionManager(this, surfaces_state_)); |
| 89 | 89 |
| 90 tracing_.Initialize(app); | 90 tracing_.Initialize(shell, url); |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool MandolineUIServicesApp::AcceptConnection( | 93 bool MandolineUIServicesApp::AcceptConnection( |
| 94 ApplicationConnection* connection) { | 94 ApplicationConnection* connection) { |
| 95 connection->AddService<Gpu>(this); | 95 connection->AddService<Gpu>(this); |
| 96 connection->AddService<mojom::DisplayManager>(this); | 96 connection->AddService<mojom::DisplayManager>(this); |
| 97 connection->AddService<mojom::WindowManagerFactoryService>(this); | 97 connection->AddService<mojom::WindowManagerFactoryService>(this); |
| 98 connection->AddService<mojom::WindowTreeFactory>(this); | 98 connection->AddService<mojom::WindowTreeFactory>(this); |
| 99 connection->AddService<WindowTreeHostFactory>(this); | 99 connection->AddService<WindowTreeHostFactory>(this); |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 void MandolineUIServicesApp::OnFirstRootConnectionCreated() { | 103 void MandolineUIServicesApp::OnFirstRootConnectionCreated() { |
| 104 PendingRequests requests; | 104 PendingRequests requests; |
| 105 requests.swap(pending_requests_); | 105 requests.swap(pending_requests_); |
| 106 for (auto& request : requests) { | 106 for (auto& request : requests) { |
| 107 if (request->dm_request) | 107 if (request->dm_request) |
| 108 Create(nullptr, std::move(*request->dm_request)); | 108 Create(nullptr, std::move(*request->dm_request)); |
| 109 else | 109 else |
| 110 Create(nullptr, std::move(*request->wtf_request)); | 110 Create(nullptr, std::move(*request->wtf_request)); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| 114 void MandolineUIServicesApp::OnNoMoreRootConnections() { | 114 void MandolineUIServicesApp::OnNoMoreRootConnections() { |
| 115 app_impl_->Quit(); | 115 shell_->Quit(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 ws::ClientConnection* | 118 ws::ClientConnection* |
| 119 MandolineUIServicesApp::CreateClientConnectionForEmbedAtWindow( | 119 MandolineUIServicesApp::CreateClientConnectionForEmbedAtWindow( |
| 120 ws::ConnectionManager* connection_manager, | 120 ws::ConnectionManager* connection_manager, |
| 121 mojo::InterfaceRequest<mojom::WindowTree> tree_request, | 121 mojo::InterfaceRequest<mojom::WindowTree> tree_request, |
| 122 ws::ServerWindow* root, | 122 ws::ServerWindow* root, |
| 123 uint32_t policy_bitmask, | 123 uint32_t policy_bitmask, |
| 124 mojom::WindowTreeClientPtr client) { | 124 mojom::WindowTreeClientPtr client) { |
| 125 scoped_ptr<ws::WindowTreeImpl> service( | 125 scoped_ptr<ws::WindowTreeImpl> service( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 } | 179 } |
| 180 | 180 |
| 181 void MandolineUIServicesApp::CreateWindowTreeHost( | 181 void MandolineUIServicesApp::CreateWindowTreeHost( |
| 182 mojo::InterfaceRequest<mojom::WindowTreeHost> host, | 182 mojo::InterfaceRequest<mojom::WindowTreeHost> host, |
| 183 mojom::WindowTreeClientPtr tree_client) { | 183 mojom::WindowTreeClientPtr tree_client) { |
| 184 DCHECK(connection_manager_); | 184 DCHECK(connection_manager_); |
| 185 | 185 |
| 186 // TODO(fsamuel): We need to make sure that only the window manager can create | 186 // TODO(fsamuel): We need to make sure that only the window manager can create |
| 187 // new roots. | 187 // new roots. |
| 188 ws::WindowTreeHostImpl* host_impl = new ws::WindowTreeHostImpl( | 188 ws::WindowTreeHostImpl* host_impl = new ws::WindowTreeHostImpl( |
| 189 connection_manager_.get(), app_impl_, gpu_state_, surfaces_state_); | 189 connection_manager_.get(), shell_, gpu_state_, surfaces_state_); |
| 190 | 190 |
| 191 // WindowTreeHostConnection manages its own lifetime. | 191 // WindowTreeHostConnection manages its own lifetime. |
| 192 host_impl->Init(new ws::WindowTreeHostConnectionImpl( | 192 host_impl->Init(new ws::WindowTreeHostConnectionImpl( |
| 193 std::move(host), make_scoped_ptr(host_impl), std::move(tree_client), | 193 std::move(host), make_scoped_ptr(host_impl), std::move(tree_client), |
| 194 connection_manager_.get())); | 194 connection_manager_.get())); |
| 195 } | 195 } |
| 196 | 196 |
| 197 } // namespace mus | 197 } // namespace mus |
| OLD | NEW |