| 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 <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 12 #include "components/mus/common/args.h" | 12 #include "components/mus/common/args.h" |
| 13 #include "components/mus/gles2/gpu_impl.h" | 13 #include "components/mus/gles2/gpu_impl.h" |
| 14 #include "components/mus/ws/client_connection.h" | 14 #include "components/mus/ws/client_connection.h" |
| 15 #include "components/mus/ws/connection_manager.h" | 15 #include "components/mus/ws/connection_manager.h" |
| 16 #include "components/mus/ws/window_tree_factory.h" | 16 #include "components/mus/ws/window_tree_factory.h" |
| 17 #include "components/mus/ws/window_tree_host_connection.h" | 17 #include "components/mus/ws/window_tree_host_connection.h" |
| 18 #include "components/mus/ws/window_tree_host_impl.h" | 18 #include "components/mus/ws/window_tree_host_impl.h" |
| 19 #include "components/mus/ws/window_tree_impl.h" | 19 #include "components/mus/ws/window_tree_impl.h" |
| 20 #include "components/resource_provider/public/cpp/resource_loader.h" | 20 #include "components/resource_provider/public/cpp/resource_loader.h" |
| 21 #include "mojo/public/c/system/main.h" | 21 #include "mojo/public/c/system/main.h" |
| 22 #include "mojo/services/tracing/public/cpp/tracing_impl.h" | 22 #include "mojo/services/tracing/public/cpp/tracing_impl.h" |
| 23 #include "mojo/shell/public/cpp/connection.h" | 23 #include "mojo/shell/public/cpp/connection.h" |
| 24 #include "mojo/shell/public/cpp/shell.h" | 24 #include "mojo/shell/public/cpp/connector.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/base/ui_base_paths.h" | 26 #include "ui/base/ui_base_paths.h" |
| 27 #include "ui/events/event_switches.h" | 27 #include "ui/events/event_switches.h" |
| 28 #include "ui/events/platform/platform_event_source.h" | 28 #include "ui/events/platform/platform_event_source.h" |
| 29 #include "ui/gl/gl_surface.h" | 29 #include "ui/gl/gl_surface.h" |
| 30 | 30 |
| 31 #if defined(USE_X11) | 31 #if defined(USE_X11) |
| 32 #include <X11/Xlib.h> | 32 #include <X11/Xlib.h> |
| 33 #include "base/command_line.h" | 33 #include "base/command_line.h" |
| 34 #include "ui/platform_window/x11/x11_window.h" | 34 #include "ui/platform_window/x11/x11_window.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 51 | 51 |
| 52 } // namespace | 52 } // namespace |
| 53 | 53 |
| 54 // TODO(sky): this is a pretty typical pattern, make it easier to do. | 54 // TODO(sky): this is a pretty typical pattern, make it easier to do. |
| 55 struct MandolineUIServicesApp::PendingRequest { | 55 struct MandolineUIServicesApp::PendingRequest { |
| 56 scoped_ptr<mojo::InterfaceRequest<mojom::DisplayManager>> dm_request; | 56 scoped_ptr<mojo::InterfaceRequest<mojom::DisplayManager>> dm_request; |
| 57 scoped_ptr<mojo::InterfaceRequest<mojom::WindowTreeFactory>> wtf_request; | 57 scoped_ptr<mojo::InterfaceRequest<mojom::WindowTreeFactory>> wtf_request; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 MandolineUIServicesApp::MandolineUIServicesApp() | 60 MandolineUIServicesApp::MandolineUIServicesApp() |
| 61 : shell_(nullptr) {} | 61 : connector_(nullptr) {} |
| 62 | 62 |
| 63 MandolineUIServicesApp::~MandolineUIServicesApp() { | 63 MandolineUIServicesApp::~MandolineUIServicesApp() { |
| 64 if (gpu_state_) | 64 if (gpu_state_) |
| 65 gpu_state_->StopThreads(); | 65 gpu_state_->StopThreads(); |
| 66 // Destroy |connection_manager_| first, since it depends on |event_source_|. | 66 // Destroy |connection_manager_| first, since it depends on |event_source_|. |
| 67 connection_manager_.reset(); | 67 connection_manager_.reset(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void MandolineUIServicesApp::InitializeResources(mojo::Shell* shell) { | 70 void MandolineUIServicesApp::InitializeResources(mojo::Connector* connector) { |
| 71 if (ui::ResourceBundle::HasSharedInstance()) | 71 if (ui::ResourceBundle::HasSharedInstance()) |
| 72 return; | 72 return; |
| 73 | 73 |
| 74 std::set<std::string> resource_paths; | 74 std::set<std::string> resource_paths; |
| 75 resource_paths.insert(kResourceFileStrings); | 75 resource_paths.insert(kResourceFileStrings); |
| 76 resource_paths.insert(kResourceFile100); | 76 resource_paths.insert(kResourceFile100); |
| 77 resource_paths.insert(kResourceFile200); | 77 resource_paths.insert(kResourceFile200); |
| 78 | 78 |
| 79 resource_provider::ResourceLoader resource_loader(shell, resource_paths); | 79 resource_provider::ResourceLoader resource_loader(connector, resource_paths); |
| 80 if (!resource_loader.BlockUntilLoaded()) | 80 if (!resource_loader.BlockUntilLoaded()) |
| 81 return; | 81 return; |
| 82 CHECK(resource_loader.loaded()); | 82 CHECK(resource_loader.loaded()); |
| 83 ui::RegisterPathProvider(); | 83 ui::RegisterPathProvider(); |
| 84 | 84 |
| 85 // Initialize resource bundle with 1x and 2x cursor bitmaps. | 85 // Initialize resource bundle with 1x and 2x cursor bitmaps. |
| 86 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 86 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
| 87 resource_loader.ReleaseFile(kResourceFileStrings), | 87 resource_loader.ReleaseFile(kResourceFileStrings), |
| 88 base::MemoryMappedFile::Region::kWholeFile); | 88 base::MemoryMappedFile::Region::kWholeFile); |
| 89 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 89 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
| 90 resource_loader.ReleaseFile(kResourceFile100), ui::SCALE_FACTOR_100P); | 90 resource_loader.ReleaseFile(kResourceFile100), ui::SCALE_FACTOR_100P); |
| 91 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( | 91 ui::ResourceBundle::GetSharedInstance().AddDataPackFromFile( |
| 92 resource_loader.ReleaseFile(kResourceFile200), ui::SCALE_FACTOR_200P); | 92 resource_loader.ReleaseFile(kResourceFile200), ui::SCALE_FACTOR_200P); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void MandolineUIServicesApp::Initialize(mojo::Shell* shell, | 95 void MandolineUIServicesApp::Initialize(mojo::Connector* connector, |
| 96 const std::string& url, | 96 const std::string& url, |
| 97 uint32_t id, | 97 uint32_t id, |
| 98 uint32_t user_id) { | 98 uint32_t user_id) { |
| 99 shell_ = shell; | 99 connector_ = connector; |
| 100 surfaces_state_ = new SurfacesState; | 100 surfaces_state_ = new SurfacesState; |
| 101 | 101 |
| 102 base::PlatformThread::SetName("mus"); | 102 base::PlatformThread::SetName("mus"); |
| 103 | 103 |
| 104 #if defined(USE_X11) | 104 #if defined(USE_X11) |
| 105 XInitThreads(); | 105 XInitThreads(); |
| 106 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 106 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 107 if (command_line->HasSwitch(kUseX11TestConfig)) { | 107 if (command_line->HasSwitch(kUseX11TestConfig)) { |
| 108 ui::test::SetUseOverrideRedirectWindowByDefault(true); | 108 ui::test::SetUseOverrideRedirectWindowByDefault(true); |
| 109 } | 109 } |
| 110 #endif | 110 #endif |
| 111 | 111 |
| 112 InitializeResources(shell); | 112 InitializeResources(connector); |
| 113 | 113 |
| 114 #if defined(USE_OZONE) | 114 #if defined(USE_OZONE) |
| 115 // The ozone platform can provide its own event source. So initialize the | 115 // The ozone platform can provide its own event source. So initialize the |
| 116 // platform before creating the default event source. | 116 // platform before creating the default event source. |
| 117 // TODO(rjkroege): Add tracing here. | 117 // TODO(rjkroege): Add tracing here. |
| 118 // Because GL libraries need to be initialized before entering the sandbox, | 118 // Because GL libraries need to be initialized before entering the sandbox, |
| 119 // in MUS, |InitializeForUI| will load the GL libraries. | 119 // in MUS, |InitializeForUI| will load the GL libraries. |
| 120 ui::OzonePlatform::InitializeForUI(); | 120 ui::OzonePlatform::InitializeForUI(); |
| 121 #endif | 121 #endif |
| 122 | 122 |
| 123 // TODO(rjkroege): Enter sandbox here before we start threads in GpuState | 123 // TODO(rjkroege): Enter sandbox here before we start threads in GpuState |
| 124 // http://crbug.com/584532 | 124 // http://crbug.com/584532 |
| 125 | 125 |
| 126 #if !defined(OS_ANDROID) | 126 #if !defined(OS_ANDROID) |
| 127 event_source_ = ui::PlatformEventSource::CreateDefault(); | 127 event_source_ = ui::PlatformEventSource::CreateDefault(); |
| 128 #endif | 128 #endif |
| 129 | 129 |
| 130 // TODO(rjkroege): It is possible that we might want to generalize the | 130 // TODO(rjkroege): It is possible that we might want to generalize the |
| 131 // GpuState object. | 131 // GpuState object. |
| 132 gpu_state_ = new GpuState(); | 132 gpu_state_ = new GpuState(); |
| 133 connection_manager_.reset(new ws::ConnectionManager(this, surfaces_state_)); | 133 connection_manager_.reset(new ws::ConnectionManager(this, surfaces_state_)); |
| 134 | 134 |
| 135 tracing_.Initialize(shell, url); | 135 tracing_.Initialize(connector, url); |
| 136 } | 136 } |
| 137 | 137 |
| 138 bool MandolineUIServicesApp::AcceptConnection(Connection* connection) { | 138 bool MandolineUIServicesApp::AcceptConnection(Connection* connection) { |
| 139 connection->AddInterface<Gpu>(this); | 139 connection->AddInterface<Gpu>(this); |
| 140 connection->AddInterface<mojom::DisplayManager>(this); | 140 connection->AddInterface<mojom::DisplayManager>(this); |
| 141 connection->AddInterface<mojom::WindowManagerFactoryService>(this); | 141 connection->AddInterface<mojom::WindowManagerFactoryService>(this); |
| 142 connection->AddInterface<mojom::WindowTreeFactory>(this); | 142 connection->AddInterface<mojom::WindowTreeFactory>(this); |
| 143 connection->AddInterface<WindowTreeHostFactory>(this); | 143 connection->AddInterface<WindowTreeHostFactory>(this); |
| 144 return true; | 144 return true; |
| 145 } | 145 } |
| 146 | 146 |
| 147 void MandolineUIServicesApp::OnFirstRootConnectionCreated() { | 147 void MandolineUIServicesApp::OnFirstRootConnectionCreated() { |
| 148 PendingRequests requests; | 148 PendingRequests requests; |
| 149 requests.swap(pending_requests_); | 149 requests.swap(pending_requests_); |
| 150 for (auto& request : requests) { | 150 for (auto& request : requests) { |
| 151 if (request->dm_request) | 151 if (request->dm_request) |
| 152 Create(nullptr, std::move(*request->dm_request)); | 152 Create(nullptr, std::move(*request->dm_request)); |
| 153 else | 153 else |
| 154 Create(nullptr, std::move(*request->wtf_request)); | 154 Create(nullptr, std::move(*request->wtf_request)); |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 void MandolineUIServicesApp::OnNoMoreRootConnections() { | 158 void MandolineUIServicesApp::OnNoMoreRootConnections() { |
| 159 shell_->Quit(); | 159 base::MessageLoop::current()->QuitWhenIdle(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 ws::ClientConnection* | 162 ws::ClientConnection* |
| 163 MandolineUIServicesApp::CreateClientConnectionForEmbedAtWindow( | 163 MandolineUIServicesApp::CreateClientConnectionForEmbedAtWindow( |
| 164 ws::ConnectionManager* connection_manager, | 164 ws::ConnectionManager* connection_manager, |
| 165 mojo::InterfaceRequest<mojom::WindowTree> tree_request, | 165 mojo::InterfaceRequest<mojom::WindowTree> tree_request, |
| 166 ws::ServerWindow* root, | 166 ws::ServerWindow* root, |
| 167 uint32_t policy_bitmask, | 167 uint32_t policy_bitmask, |
| 168 mojom::WindowTreeClientPtr client) { | 168 mojom::WindowTreeClientPtr client) { |
| 169 scoped_ptr<ws::WindowTreeImpl> service( | 169 scoped_ptr<ws::WindowTreeImpl> service( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 223 } |
| 224 | 224 |
| 225 void MandolineUIServicesApp::CreateWindowTreeHost( | 225 void MandolineUIServicesApp::CreateWindowTreeHost( |
| 226 mojo::InterfaceRequest<mojom::WindowTreeHost> host, | 226 mojo::InterfaceRequest<mojom::WindowTreeHost> host, |
| 227 mojom::WindowTreeClientPtr tree_client) { | 227 mojom::WindowTreeClientPtr tree_client) { |
| 228 DCHECK(connection_manager_); | 228 DCHECK(connection_manager_); |
| 229 | 229 |
| 230 // TODO(fsamuel): We need to make sure that only the window manager can create | 230 // TODO(fsamuel): We need to make sure that only the window manager can create |
| 231 // new roots. | 231 // new roots. |
| 232 ws::WindowTreeHostImpl* host_impl = new ws::WindowTreeHostImpl( | 232 ws::WindowTreeHostImpl* host_impl = new ws::WindowTreeHostImpl( |
| 233 connection_manager_.get(), shell_, gpu_state_, surfaces_state_); | 233 connection_manager_.get(), connector_, gpu_state_, surfaces_state_); |
| 234 | 234 |
| 235 // WindowTreeHostConnection manages its own lifetime. | 235 // WindowTreeHostConnection manages its own lifetime. |
| 236 host_impl->Init(new ws::WindowTreeHostConnectionImpl( | 236 host_impl->Init(new ws::WindowTreeHostConnectionImpl( |
| 237 std::move(host), make_scoped_ptr(host_impl), std::move(tree_client), | 237 std::move(host), make_scoped_ptr(host_impl), std::move(tree_client), |
| 238 connection_manager_.get())); | 238 connection_manager_.get())); |
| 239 } | 239 } |
| 240 | 240 |
| 241 } // namespace mus | 241 } // namespace mus |
| OLD | NEW |