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.
5 #include "ui/ozone/platform/drm/ozone_platform_gbm.h"
11 #include "base/at_exit.h"
12 #include "base/bind.h"
13 #include "base/command_line.h"
14 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
15 #include "ui/events/ozone/device/device_manager.h"
16 #include "ui/events/ozone/evdev/event_factory_evdev.h"
17 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
18 #include "ui/ozone/platform/drm/common/drm_util.h"
19 #include "ui/ozone/platform/drm/gpu/drm_device_generator.h"
20 #include "ui/ozone/platform/drm/gpu/drm_device_manager.h"
21 #include "ui/ozone/platform/drm/gpu/drm_gpu_display_manager.h"
22 #include "ui/ozone/platform/drm/gpu/drm_gpu_platform_support.h"
23 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h"
24 #include "ui/ozone/platform/drm/gpu/gbm_device.h"
25 #include "ui/ozone/platform/drm/gpu/gbm_surface.h"
26 #include "ui/ozone/platform/drm/gpu/gbm_surface_factory.h"
27 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h"
28 #include "ui/ozone/platform/drm/gpu/screen_manager.h"
29 #include "ui/ozone/platform/drm/host/drm_cursor.h"
30 #include "ui/ozone/platform/drm/host/drm_display_host_manager.h"
31 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
32 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.h"
33 #include "ui/ozone/platform/drm/host/drm_overlay_manager.h"
34 #include "ui/ozone/platform/drm/host/drm_window_host.h"
35 #include "ui/ozone/platform/drm/host/drm_window_host_manager.h"
36 #include "ui/ozone/public/cursor_factory_ozone.h"
37 #include "ui/ozone/public/gpu_platform_support.h"
38 #include "ui/ozone/public/gpu_platform_support_host.h"
39 #include "ui/ozone/public/ozone_platform.h"
40 #include "ui/ozone/public/ozone_switches.h"
42 #if defined(USE_XKBCOMMON)
43 #include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h"
44 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
46 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
56 : glapi_lib_(dlopen("libglapi.so.0", RTLD_LAZY
| RTLD_GLOBAL
)) {}
64 // HACK: gbm drivers have broken linkage. The Mesa DRI driver references
65 // symbols in the libglapi library however it does not explicitly link against
66 // it. That caused linkage errors when running an application that does not
67 // explicitly link against libglapi.
70 DISALLOW_COPY_AND_ASSIGN(GlApiLoader
);
73 class GbmBufferGenerator
: public ScanoutBufferGenerator
{
75 GbmBufferGenerator() {}
76 ~GbmBufferGenerator() override
{}
78 // ScanoutBufferGenerator:
79 scoped_refptr
<ScanoutBuffer
> Create(const scoped_refptr
<DrmDevice
>& drm
,
80 const gfx::Size
& size
) override
{
81 scoped_refptr
<GbmDevice
> gbm(static_cast<GbmDevice
*>(drm
.get()));
82 return GbmBuffer::CreateBuffer(gbm
, SurfaceFactoryOzone::BGRA_8888
, size
,
87 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator
);
90 class GbmDeviceGenerator
: public DrmDeviceGenerator
{
92 GbmDeviceGenerator(bool use_atomic
) : use_atomic_(use_atomic
) {}
93 ~GbmDeviceGenerator() override
{}
95 // DrmDeviceGenerator:
96 scoped_refptr
<DrmDevice
> CreateDevice(const base::FilePath
& path
,
97 base::File file
) override
{
98 scoped_refptr
<DrmDevice
> drm
= new GbmDevice(path
, file
.Pass());
99 if (drm
->Initialize(use_atomic_
))
108 DISALLOW_COPY_AND_ASSIGN(GbmDeviceGenerator
);
111 class OzonePlatformGbm
: public OzonePlatform
{
113 OzonePlatformGbm(bool use_surfaceless
) : use_surfaceless_(use_surfaceless
) {}
114 ~OzonePlatformGbm() override
{}
117 ui::SurfaceFactoryOzone
* GetSurfaceFactoryOzone() override
{
118 return surface_factory_ozone_
.get();
120 OverlayManagerOzone
* GetOverlayManager() override
{
121 return overlay_manager_
.get();
123 CursorFactoryOzone
* GetCursorFactoryOzone() override
{
124 return cursor_factory_ozone_
.get();
126 InputController
* GetInputController() override
{
127 return event_factory_ozone_
->input_controller();
129 GpuPlatformSupport
* GetGpuPlatformSupport() override
{
130 return gpu_platform_support_
.get();
132 GpuPlatformSupportHost
* GetGpuPlatformSupportHost() override
{
133 return gpu_platform_support_host_
.get();
135 scoped_ptr
<SystemInputInjector
> CreateSystemInputInjector() override
{
136 return event_factory_ozone_
->CreateSystemInputInjector();
138 scoped_ptr
<PlatformWindow
> CreatePlatformWindow(
139 PlatformWindowDelegate
* delegate
,
140 const gfx::Rect
& bounds
) override
{
141 scoped_ptr
<DrmWindowHost
> platform_window(
142 new DrmWindowHost(delegate
, bounds
, gpu_platform_support_host_
.get(),
143 event_factory_ozone_
.get(), cursor_
.get(),
144 window_manager_
.get(), display_manager_
.get()));
145 platform_window
->Initialize();
146 return platform_window
.Pass();
148 scoped_ptr
<NativeDisplayDelegate
> CreateNativeDisplayDelegate() override
{
149 return make_scoped_ptr(
150 new DrmNativeDisplayDelegate(display_manager_
.get()));
152 void InitializeUI() override
{
153 device_manager_
= CreateDeviceManager();
154 window_manager_
.reset(new DrmWindowHostManager());
155 cursor_
.reset(new DrmCursor(window_manager_
.get()));
156 #if defined(USE_XKBCOMMON)
157 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(make_scoped_ptr(
158 new XkbKeyboardLayoutEngine(xkb_evdev_code_converter_
)));
160 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
161 make_scoped_ptr(new StubKeyboardLayoutEngine()));
163 event_factory_ozone_
.reset(new EventFactoryEvdev(
164 cursor_
.get(), device_manager_
.get(),
165 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()));
166 gpu_platform_support_host_
.reset(
167 new DrmGpuPlatformSupportHost(cursor_
.get()));
168 display_manager_
.reset(new DrmDisplayHostManager(
169 gpu_platform_support_host_
.get(), device_manager_
.get(),
170 event_factory_ozone_
->input_controller()));
171 cursor_factory_ozone_
.reset(new BitmapCursorFactoryOzone
);
172 overlay_manager_
.reset(new DrmOverlayManager(
173 use_surfaceless_
, gpu_platform_support_host_
.get()));
176 void InitializeGPU() override
{
177 bool use_atomic
= false;
178 gl_api_loader_
.reset(new GlApiLoader());
179 drm_device_manager_
.reset(new DrmDeviceManager(
180 scoped_ptr
<DrmDeviceGenerator
>(new GbmDeviceGenerator(use_atomic
))));
181 buffer_generator_
.reset(new GbmBufferGenerator());
182 screen_manager_
.reset(new ScreenManager(buffer_generator_
.get()));
183 surface_factory_ozone_
.reset(new GbmSurfaceFactory(use_surfaceless_
));
184 surface_factory_ozone_
->InitializeGpu(drm_device_manager_
.get(),
185 screen_manager_
.get());
186 scoped_ptr
<DrmGpuDisplayManager
> display_manager(new DrmGpuDisplayManager(
187 screen_manager_
.get(), drm_device_manager_
.get()));
188 gpu_platform_support_
.reset(new DrmGpuPlatformSupport(
189 drm_device_manager_
.get(), screen_manager_
.get(),
190 buffer_generator_
.get(), display_manager
.Pass()));
194 // Objects in both processes.
195 bool use_surfaceless_
;
197 // Objects in the GPU process.
198 scoped_ptr
<GbmSurfaceFactory
> surface_factory_ozone_
;
199 scoped_ptr
<GlApiLoader
> gl_api_loader_
;
200 scoped_ptr
<DrmDeviceManager
> drm_device_manager_
;
201 scoped_ptr
<GbmBufferGenerator
> buffer_generator_
;
202 scoped_ptr
<ScreenManager
> screen_manager_
;
203 scoped_ptr
<DrmGpuPlatformSupport
> gpu_platform_support_
;
205 // Objects in the Browser process.
206 scoped_ptr
<DeviceManager
> device_manager_
;
207 scoped_ptr
<BitmapCursorFactoryOzone
> cursor_factory_ozone_
;
208 scoped_ptr
<DrmWindowHostManager
> window_manager_
;
209 scoped_ptr
<DrmCursor
> cursor_
;
210 scoped_ptr
<EventFactoryEvdev
> event_factory_ozone_
;
211 scoped_ptr
<DrmGpuPlatformSupportHost
> gpu_platform_support_host_
;
212 scoped_ptr
<DrmDisplayHostManager
> display_manager_
;
213 scoped_ptr
<DrmOverlayManager
> overlay_manager_
;
215 #if defined(USE_XKBCOMMON)
216 XkbEvdevCodes xkb_evdev_code_converter_
;
219 DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm
);
224 OzonePlatform
* CreateOzonePlatformGbm() {
225 base::CommandLine
* cmd
= base::CommandLine::ForCurrentProcess();
226 #if defined(USE_MESA_PLATFORM_NULL)
227 // Only works with surfaceless.
228 cmd
->AppendSwitch(switches::kOzoneUseSurfaceless
);
230 return new OzonePlatformGbm(cmd
->HasSwitch(switches::kOzoneUseSurfaceless
));