OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/mus/view_manager_app.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/stl_util.h" |
| 9 #include "components/mus/client_connection.h" |
| 10 #include "components/mus/connection_manager.h" |
| 11 #include "components/mus/gles2/gpu_impl.h" |
| 12 #include "components/mus/public/cpp/args.h" |
| 13 #include "components/mus/surfaces/surfaces_scheduler.h" |
| 14 #include "components/mus/view_tree_host_connection.h" |
| 15 #include "components/mus/view_tree_host_impl.h" |
| 16 #include "components/mus/view_tree_impl.h" |
| 17 #include "mojo/application/public/cpp/application_connection.h" |
| 18 #include "mojo/application/public/cpp/application_impl.h" |
| 19 #include "mojo/application/public/cpp/application_runner.h" |
| 20 #include "mojo/common/tracing_impl.h" |
| 21 #include "third_party/mojo/src/mojo/public/c/system/main.h" |
| 22 #include "ui/events/event_switches.h" |
| 23 #include "ui/events/platform/platform_event_source.h" |
| 24 #include "ui/gl/gl_surface.h" |
| 25 #include "ui/gl/test/gl_surface_test_support.h" |
| 26 |
| 27 #if defined(USE_X11) |
| 28 #include <X11/Xlib.h> |
| 29 #include "ui/platform_window/x11/x11_window.h" |
| 30 #endif |
| 31 |
| 32 using mojo::ApplicationConnection; |
| 33 using mojo::ApplicationImpl; |
| 34 using mojo::Gpu; |
| 35 using mojo::InterfaceRequest; |
| 36 using mojo::ViewTreeHostFactory; |
| 37 |
| 38 namespace view_manager { |
| 39 |
| 40 ViewManagerApp::ViewManagerApp() : app_impl_(nullptr), is_headless_(false) {} |
| 41 |
| 42 ViewManagerApp::~ViewManagerApp() { |
| 43 if (gpu_state_) |
| 44 gpu_state_->StopControlThread(); |
| 45 // Destroy |connection_manager_| first, since it depends on |event_source_|. |
| 46 connection_manager_.reset(); |
| 47 } |
| 48 |
| 49 void ViewManagerApp::Initialize(ApplicationImpl* app) { |
| 50 app_impl_ = app; |
| 51 tracing_.Initialize(app); |
| 52 surfaces_state_ = new surfaces::SurfacesState; |
| 53 |
| 54 #if !defined(OS_ANDROID) |
| 55 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 56 is_headless_ = command_line->HasSwitch(mojo::kUseHeadlessConfig); |
| 57 if (!is_headless_) { |
| 58 #if defined(USE_X11) |
| 59 if (command_line->HasSwitch(mojo::kUseX11TestConfig)) { |
| 60 XInitThreads(); |
| 61 ui::test::SetUseOverrideRedirectWindowByDefault(true); |
| 62 } |
| 63 #endif |
| 64 gfx::GLSurface::InitializeOneOff(); |
| 65 event_source_ = ui::PlatformEventSource::CreateDefault(); |
| 66 } |
| 67 #endif |
| 68 |
| 69 if (!gpu_state_.get()) |
| 70 gpu_state_ = new gles2::GpuState; |
| 71 connection_manager_.reset(new ConnectionManager(this, surfaces_state_)); |
| 72 } |
| 73 |
| 74 bool ViewManagerApp::ConfigureIncomingConnection( |
| 75 ApplicationConnection* connection) { |
| 76 // ViewManager |
| 77 connection->AddService<ViewTreeHostFactory>(this); |
| 78 // GPU |
| 79 connection->AddService<Gpu>(this); |
| 80 return true; |
| 81 } |
| 82 |
| 83 void ViewManagerApp::OnNoMoreRootConnections() { |
| 84 app_impl_->Quit(); |
| 85 } |
| 86 |
| 87 ClientConnection* ViewManagerApp::CreateClientConnectionForEmbedAtView( |
| 88 ConnectionManager* connection_manager, |
| 89 mojo::InterfaceRequest<mojo::ViewTree> tree_request, |
| 90 mojo::ConnectionSpecificId creator_id, |
| 91 mojo::URLRequestPtr request, |
| 92 const ViewId& root_id, |
| 93 uint32_t policy_bitmask) { |
| 94 mojo::ViewTreeClientPtr client; |
| 95 app_impl_->ConnectToService(request.Pass(), &client); |
| 96 |
| 97 scoped_ptr<ViewTreeImpl> service(new ViewTreeImpl( |
| 98 connection_manager, creator_id, root_id, policy_bitmask)); |
| 99 return new DefaultClientConnection(service.Pass(), connection_manager, |
| 100 tree_request.Pass(), client.Pass()); |
| 101 } |
| 102 |
| 103 ClientConnection* ViewManagerApp::CreateClientConnectionForEmbedAtView( |
| 104 ConnectionManager* connection_manager, |
| 105 mojo::InterfaceRequest<mojo::ViewTree> tree_request, |
| 106 mojo::ConnectionSpecificId creator_id, |
| 107 const ViewId& root_id, |
| 108 uint32_t policy_bitmask, |
| 109 mojo::ViewTreeClientPtr client) { |
| 110 scoped_ptr<ViewTreeImpl> service(new ViewTreeImpl( |
| 111 connection_manager, creator_id, root_id, policy_bitmask)); |
| 112 return new DefaultClientConnection(service.Pass(), connection_manager, |
| 113 tree_request.Pass(), client.Pass()); |
| 114 } |
| 115 |
| 116 void ViewManagerApp::Create(ApplicationConnection* connection, |
| 117 InterfaceRequest<ViewTreeHostFactory> request) { |
| 118 factory_bindings_.AddBinding(this, request.Pass()); |
| 119 } |
| 120 |
| 121 void ViewManagerApp::Create(mojo::ApplicationConnection* connection, |
| 122 mojo::InterfaceRequest<Gpu> request) { |
| 123 if (!gpu_state_.get()) |
| 124 gpu_state_ = new gles2::GpuState; |
| 125 new gles2::GpuImpl(request.Pass(), gpu_state_); |
| 126 } |
| 127 |
| 128 void ViewManagerApp::CreateViewTreeHost( |
| 129 mojo::InterfaceRequest<mojo::ViewTreeHost> host, |
| 130 mojo::ViewTreeHostClientPtr host_client, |
| 131 mojo::ViewTreeClientPtr tree_client) { |
| 132 DCHECK(connection_manager_.get()); |
| 133 |
| 134 // TODO(fsamuel): We need to make sure that only the window manager can create |
| 135 // new roots. |
| 136 ViewTreeHostImpl* host_impl = new ViewTreeHostImpl( |
| 137 host_client.Pass(), connection_manager_.get(), is_headless_, app_impl_, |
| 138 gpu_state_, surfaces_state_); |
| 139 |
| 140 // ViewTreeHostConnection manages its own lifetime. |
| 141 host_impl->Init(new ViewTreeHostConnectionImpl( |
| 142 host.Pass(), make_scoped_ptr(host_impl), tree_client.Pass(), |
| 143 connection_manager_.get())); |
| 144 } |
| 145 |
| 146 } // namespace view_manager |
OLD | NEW |