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 "ui/ozone/platform/drm/ozone_platform_gbm.h" | 5 #include "ui/ozone/platform/drm/ozone_platform_gbm.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <gbm.h> | 9 #include <gbm.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
11 #include <xf86drm.h> | 11 #include <xf86drm.h> |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 #include <utility> | 14 #include <utility> |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 20 #include "services/shell/public/cpp/connection.h" |
| 21 #include "services/shell/public/cpp/interface_factory.h" |
20 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" | 22 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" |
21 #include "ui/events/ozone/device/device_manager.h" | 23 #include "ui/events/ozone/device/device_manager.h" |
22 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 24 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
23 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | 25 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
24 #include "ui/ozone/platform/drm/common/drm_util.h" | 26 #include "ui/ozone/platform/drm/common/drm_util.h" |
| 27 #include "ui/ozone/platform/drm/cursor_proxy_mojo.h" |
25 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h" | 28 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h" |
26 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h" | 29 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h" |
27 #include "ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h" | 30 #include "ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h" |
28 #include "ui/ozone/platform/drm/gpu/drm_gpu_platform_support.h" | 31 #include "ui/ozone/platform/drm/gpu/drm_gpu_platform_support.h" |
29 #include "ui/ozone/platform/drm/gpu/drm_thread_message_proxy.h" | 32 #include "ui/ozone/platform/drm/gpu/drm_thread_message_proxy.h" |
30 #include "ui/ozone/platform/drm/gpu/drm_thread_proxy.h" | 33 #include "ui/ozone/platform/drm/gpu/drm_thread_proxy.h" |
31 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" | 34 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h" |
32 #include "ui/ozone/platform/drm/gpu/proxy_helpers.h" | 35 #include "ui/ozone/platform/drm/gpu/proxy_helpers.h" |
33 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h" | 36 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h" |
34 #include "ui/ozone/platform/drm/gpu/screen_manager.h" | 37 #include "ui/ozone/platform/drm/gpu/screen_manager.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 private: | 73 private: |
71 // HACK: gbm drivers have broken linkage. The Mesa DRI driver references | 74 // HACK: gbm drivers have broken linkage. The Mesa DRI driver references |
72 // symbols in the libglapi library however it does not explicitly link against | 75 // symbols in the libglapi library however it does not explicitly link against |
73 // it. That caused linkage errors when running an application that does not | 76 // it. That caused linkage errors when running an application that does not |
74 // explicitly link against libglapi. | 77 // explicitly link against libglapi. |
75 void* glapi_lib_; | 78 void* glapi_lib_; |
76 | 79 |
77 DISALLOW_COPY_AND_ASSIGN(GlApiLoader); | 80 DISALLOW_COPY_AND_ASSIGN(GlApiLoader); |
78 }; | 81 }; |
79 | 82 |
80 // Returns true if we should operate in Mus mode. | 83 class OzonePlatformGbm |
81 // TODO(rjkroege): Create an explicit "single process ozone mode" that can be | 84 : public OzonePlatform, |
82 // used for tests after mus+ash team finishes splitting mus. | 85 public shell::InterfaceFactory<ozone::mojom::DeviceCursor> { |
83 bool RunningInsideMus() { | |
84 bool has_channel_handle = base::CommandLine::ForCurrentProcess()->HasSwitch( | |
85 "mojo-platform-channel-handle"); | |
86 return has_channel_handle; | |
87 } | |
88 | |
89 class OzonePlatformGbm : public OzonePlatform { | |
90 public: | 86 public: |
91 OzonePlatformGbm() {} | 87 OzonePlatformGbm() : using_mojo_(false), single_process_(false) {} |
92 ~OzonePlatformGbm() override {} | 88 ~OzonePlatformGbm() override {} |
93 | 89 |
94 // OzonePlatform: | 90 // OzonePlatform: |
95 ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override { | 91 ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override { |
96 return surface_factory_.get(); | 92 return surface_factory_.get(); |
97 } | 93 } |
98 OverlayManagerOzone* GetOverlayManager() override { | 94 OverlayManagerOzone* GetOverlayManager() override { |
99 return overlay_manager_.get(); | 95 return overlay_manager_.get(); |
100 } | 96 } |
101 CursorFactoryOzone* GetCursorFactoryOzone() override { | 97 CursorFactoryOzone* GetCursorFactoryOzone() override { |
102 return cursor_factory_ozone_.get(); | 98 return cursor_factory_ozone_.get(); |
103 } | 99 } |
104 InputController* GetInputController() override { | 100 InputController* GetInputController() override { |
105 return event_factory_ozone_->input_controller(); | 101 return event_factory_ozone_->input_controller(); |
106 } | 102 } |
107 GpuPlatformSupport* GetGpuPlatformSupport() override { | 103 GpuPlatformSupport* GetGpuPlatformSupport() override { |
108 return gpu_platform_support_.get(); | 104 return gpu_platform_support_.get(); |
109 } | 105 } |
110 GpuPlatformSupportHost* GetGpuPlatformSupportHost() override { | 106 GpuPlatformSupportHost* GetGpuPlatformSupportHost() override { |
111 return gpu_platform_support_host_.get(); | 107 return gpu_platform_support_host_.get(); |
112 } | 108 } |
113 std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() override { | 109 std::unique_ptr<SystemInputInjector> CreateSystemInputInjector() override { |
114 return event_factory_ozone_->CreateSystemInputInjector(); | 110 return event_factory_ozone_->CreateSystemInputInjector(); |
115 } | 111 } |
| 112 void AddInterfaces(shell::Connection* connection) override { |
| 113 connection->AddInterface<ozone::mojom::DeviceCursor>(this); |
| 114 } |
| 115 // shell::InterfaceFactory<mojom::ozone::Cursor> implementation. |
| 116 void Create(const shell::Identity& remote_identity, |
| 117 ozone::mojom::DeviceCursorRequest request) override { |
| 118 DCHECK(drm_thread_); |
| 119 drm_thread_->AddBinding(std::move(request)); |
| 120 } |
116 std::unique_ptr<PlatformWindow> CreatePlatformWindow( | 121 std::unique_ptr<PlatformWindow> CreatePlatformWindow( |
117 PlatformWindowDelegate* delegate, | 122 PlatformWindowDelegate* delegate, |
118 const gfx::Rect& bounds) override { | 123 const gfx::Rect& bounds) override { |
119 GpuThreadAdapter* adapter = gpu_platform_support_host_.get(); | 124 GpuThreadAdapter* adapter = gpu_platform_support_host_.get(); |
120 if (RunningInsideMus()) { | 125 if (using_mojo_ || single_process_) { |
121 DCHECK(drm_thread_) << "drm_thread_ should exist (and be running) here."; | 126 DCHECK(drm_thread_) << "drm_thread_ should exist (and be running) here."; |
122 adapter = mus_thread_proxy_.get(); | 127 adapter = mus_thread_proxy_.get(); |
123 } | 128 } |
124 | 129 |
125 std::unique_ptr<DrmWindowHost> platform_window(new DrmWindowHost( | 130 std::unique_ptr<DrmWindowHost> platform_window(new DrmWindowHost( |
126 delegate, bounds, adapter, event_factory_ozone_.get(), cursor_.get(), | 131 delegate, bounds, adapter, event_factory_ozone_.get(), cursor_.get(), |
127 window_manager_.get(), display_manager_.get(), overlay_manager_.get())); | 132 window_manager_.get(), display_manager_.get(), overlay_manager_.get())); |
128 platform_window->Initialize(); | 133 platform_window->Initialize(); |
129 return std::move(platform_window); | 134 return std::move(platform_window); |
130 } | 135 } |
131 std::unique_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() | 136 std::unique_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() |
132 override { | 137 override { |
133 return base::WrapUnique( | 138 return base::WrapUnique( |
134 new DrmNativeDisplayDelegate(display_manager_.get())); | 139 new DrmNativeDisplayDelegate(display_manager_.get())); |
135 } | 140 } |
136 void InitializeUI() override { | 141 void InitializeUI() override { |
| 142 InitParams default_params; |
| 143 InitializeUI(default_params); |
| 144 } |
| 145 void InitializeUI(const InitParams& args) override { |
| 146 // Ozone drm can operate in three modes configured at runtime: |
| 147 // 1. legacy mode where browser and gpu components communicate |
| 148 // via param traits IPC. |
| 149 // 2. single-process mode where browser and gpu components |
| 150 // communicate via PostTask. |
| 151 // 3. mojo mode where browser and gpu components communicate |
| 152 // via mojo IPC. |
| 153 // Currently, mojo mode uses mojo in a single process but this is |
| 154 // an interim implementation detail that will be eliminated in a |
| 155 // future CL. |
| 156 single_process_ = args.single_process; |
| 157 using_mojo_ = args.connector != nullptr; |
| 158 DCHECK(!(using_mojo_ && single_process_)); |
| 159 |
137 device_manager_ = CreateDeviceManager(); | 160 device_manager_ = CreateDeviceManager(); |
138 window_manager_.reset(new DrmWindowHostManager()); | 161 window_manager_.reset(new DrmWindowHostManager()); |
139 cursor_.reset(new DrmCursor(window_manager_.get())); | 162 cursor_.reset(new DrmCursor(window_manager_.get())); |
140 #if defined(USE_XKBCOMMON) | 163 #if defined(USE_XKBCOMMON) |
141 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(base::WrapUnique( | 164 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(base::WrapUnique( |
142 new XkbKeyboardLayoutEngine(xkb_evdev_code_converter_))); | 165 new XkbKeyboardLayoutEngine(xkb_evdev_code_converter_))); |
143 #else | 166 #else |
144 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( | 167 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( |
145 base::WrapUnique(new StubKeyboardLayoutEngine())); | 168 base::WrapUnique(new StubKeyboardLayoutEngine())); |
146 #endif | 169 #endif |
| 170 |
147 event_factory_ozone_.reset(new EventFactoryEvdev( | 171 event_factory_ozone_.reset(new EventFactoryEvdev( |
148 cursor_.get(), device_manager_.get(), | 172 cursor_.get(), device_manager_.get(), |
149 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine())); | 173 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine())); |
150 | 174 |
151 GpuThreadAdapter* adapter; | 175 GpuThreadAdapter* adapter; |
152 if (RunningInsideMus()) { | 176 |
| 177 // TODO(rjkroege): Once mus is split, only do this for single_process. |
| 178 if (single_process_ || using_mojo_) |
153 gl_api_loader_.reset(new GlApiLoader()); | 179 gl_api_loader_.reset(new GlApiLoader()); |
| 180 |
| 181 if (using_mojo_) { |
| 182 DCHECK(args.connector); |
154 mus_thread_proxy_.reset(new MusThreadProxy()); | 183 mus_thread_proxy_.reset(new MusThreadProxy()); |
155 adapter = mus_thread_proxy_.get(); | 184 adapter = mus_thread_proxy_.get(); |
156 cursor_->SetDrmCursorProxy(mus_thread_proxy_.get()); | 185 cursor_->SetDrmCursorProxy(new CursorProxyMojo(args.connector)); |
| 186 } else if (single_process_) { |
| 187 mus_thread_proxy_.reset(new MusThreadProxy()); |
| 188 adapter = mus_thread_proxy_.get(); |
| 189 cursor_->SetDrmCursorProxy( |
| 190 new CursorProxyThread(mus_thread_proxy_.get())); |
157 } else { | 191 } else { |
158 gpu_platform_support_host_.reset( | 192 gpu_platform_support_host_.reset( |
159 new DrmGpuPlatformSupportHost(cursor_.get())); | 193 new DrmGpuPlatformSupportHost(cursor_.get())); |
160 adapter = gpu_platform_support_host_.get(); | 194 adapter = gpu_platform_support_host_.get(); |
161 } | 195 } |
162 | 196 |
163 display_manager_.reset( | 197 display_manager_.reset( |
164 new DrmDisplayHostManager(adapter, device_manager_.get(), | 198 new DrmDisplayHostManager(adapter, device_manager_.get(), |
165 event_factory_ozone_->input_controller())); | 199 event_factory_ozone_->input_controller())); |
166 cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone); | 200 cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone); |
167 overlay_manager_.reset( | 201 overlay_manager_.reset( |
168 new DrmOverlayManager(adapter, window_manager_.get())); | 202 new DrmOverlayManager(adapter, window_manager_.get())); |
169 | 203 |
170 if (RunningInsideMus()) { | 204 if (using_mojo_ || single_process_) { |
171 mus_thread_proxy_->ProvideManagers(display_manager_.get(), | 205 mus_thread_proxy_->ProvideManagers(display_manager_.get(), |
172 overlay_manager_.get()); | 206 overlay_manager_.get()); |
173 } | 207 } |
174 } | 208 } |
| 209 void InitializeGPU() override { |
| 210 InitParams default_params; |
| 211 InitializeGPU(default_params); |
| 212 } |
| 213 void InitializeGPU(const InitParams& args) override { |
| 214 // TODO(rjkroege): services/ui should initalize this with a connector. |
| 215 // However, in-progress refactorings in services/ui make it difficult to |
| 216 // require this at present. Set using_mojo_ like below once this is |
| 217 // complete. |
| 218 // using_mojo_ = args.connector != nullptr; |
175 | 219 |
176 void InitializeGPU() override { | |
177 InterThreadMessagingProxy* itmp; | 220 InterThreadMessagingProxy* itmp; |
178 if (RunningInsideMus()) { | 221 if (using_mojo_ || single_process_) { |
179 DCHECK(mus_thread_proxy_); | |
180 itmp = mus_thread_proxy_.get(); | 222 itmp = mus_thread_proxy_.get(); |
181 } else { | 223 } else { |
182 gl_api_loader_.reset(new GlApiLoader()); | 224 gl_api_loader_.reset(new GlApiLoader()); |
183 scoped_refptr<DrmThreadMessageProxy> message_proxy( | 225 scoped_refptr<DrmThreadMessageProxy> message_proxy( |
184 new DrmThreadMessageProxy()); | 226 new DrmThreadMessageProxy()); |
185 itmp = message_proxy.get(); | 227 itmp = message_proxy.get(); |
186 gpu_platform_support_.reset(new DrmGpuPlatformSupport(message_proxy)); | 228 gpu_platform_support_.reset(new DrmGpuPlatformSupport(message_proxy)); |
187 } | 229 } |
188 | 230 |
189 // NOTE: Can't start the thread here since this is called before sandbox | 231 // NOTE: Can't start the thread here since this is called before sandbox |
190 // initialization in multi-process Chrome. In mus, we start the DRM thread. | 232 // initialization in multi-process Chrome. In mus, we start the DRM thread. |
191 drm_thread_.reset(new DrmThreadProxy()); | 233 drm_thread_.reset(new DrmThreadProxy()); |
192 drm_thread_->BindThreadIntoMessagingProxy(itmp); | 234 drm_thread_->BindThreadIntoMessagingProxy(itmp); |
193 | 235 |
194 surface_factory_.reset(new GbmSurfaceFactory(drm_thread_.get())); | 236 surface_factory_.reset(new GbmSurfaceFactory(drm_thread_.get())); |
195 if (RunningInsideMus()) { | 237 if (using_mojo_ || single_process_) { |
196 mus_thread_proxy_->StartDrmThread(); | 238 mus_thread_proxy_->StartDrmThread(); |
197 } | 239 } |
198 } | 240 } |
199 | 241 |
200 private: | 242 private: |
| 243 bool using_mojo_; |
| 244 bool single_process_; |
| 245 |
201 // Objects in the GPU process. | 246 // Objects in the GPU process. |
| 247 // TODO(rjk): rename drm_thread_ to drm_thread_proxy_; |
202 std::unique_ptr<DrmThreadProxy> drm_thread_; | 248 std::unique_ptr<DrmThreadProxy> drm_thread_; |
203 std::unique_ptr<GlApiLoader> gl_api_loader_; | 249 std::unique_ptr<GlApiLoader> gl_api_loader_; |
204 std::unique_ptr<GbmSurfaceFactory> surface_factory_; | 250 std::unique_ptr<GbmSurfaceFactory> surface_factory_; |
205 std::unique_ptr<DrmGpuPlatformSupport> gpu_platform_support_; | 251 std::unique_ptr<DrmGpuPlatformSupport> gpu_platform_support_; |
206 | 252 |
207 // Objects in the Browser process. | 253 // Objects in the Browser process. |
208 std::unique_ptr<DeviceManager> device_manager_; | 254 std::unique_ptr<DeviceManager> device_manager_; |
209 std::unique_ptr<BitmapCursorFactoryOzone> cursor_factory_ozone_; | 255 std::unique_ptr<BitmapCursorFactoryOzone> cursor_factory_ozone_; |
210 std::unique_ptr<DrmWindowHostManager> window_manager_; | 256 std::unique_ptr<DrmWindowHostManager> window_manager_; |
211 std::unique_ptr<DrmCursor> cursor_; | 257 std::unique_ptr<DrmCursor> cursor_; |
(...skipping 12 matching lines...) Expand all Loading... |
224 DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm); | 270 DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm); |
225 }; | 271 }; |
226 | 272 |
227 } // namespace | 273 } // namespace |
228 | 274 |
229 OzonePlatform* CreateOzonePlatformGbm() { | 275 OzonePlatform* CreateOzonePlatformGbm() { |
230 return new OzonePlatformGbm; | 276 return new OzonePlatformGbm; |
231 } | 277 } |
232 | 278 |
233 } // namespace ui | 279 } // namespace ui |
OLD | NEW |