1 // Copyright 2013 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/dri/ozone_platform_dri.h"
7 #include "base/at_exit.h"
8 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
9 #include "ui/events/ozone/device/device_manager.h"
10 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
11 #include "ui/events/ozone/evdev/event_factory_evdev.h"
12 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h"
13 #include "ui/ozone/platform/dri/display_manager.h"
14 #include "ui/ozone/platform/dri/dri_buffer.h"
15 #include "ui/ozone/platform/dri/dri_cursor.h"
16 #include "ui/ozone/platform/dri/dri_gpu_platform_support.h"
17 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h"
18 #include "ui/ozone/platform/dri/dri_surface_factory.h"
19 #include "ui/ozone/platform/dri/dri_window.h"
20 #include "ui/ozone/platform/dri/dri_window_delegate_impl.h"
21 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h"
22 #include "ui/ozone/platform/dri/dri_window_manager.h"
23 #include "ui/ozone/platform/dri/dri_wrapper.h"
24 #include "ui/ozone/platform/dri/native_display_delegate_dri.h"
25 #include "ui/ozone/platform/dri/native_display_delegate_proxy.h"
26 #include "ui/ozone/platform/dri/screen_manager.h"
27 #include "ui/ozone/public/ozone_platform.h"
28 #include "ui/ozone/public/ui_thread_gpu.h"
30 #if defined(USE_XKBCOMMON)
31 #include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h"
32 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
34 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
41 const char kDefaultGraphicsCardPath
[] = "/dev/dri/card0";
43 // OzonePlatform for Linux DRI (Direct Rendering Infrastructure)
45 // This platform is Linux without any display server (no X, wayland, or
46 // anything). This means chrome alone owns the display and input devices.
47 class OzonePlatformDri
: public OzonePlatform
{
50 : dri_(new DriWrapper(kDefaultGraphicsCardPath
)),
51 buffer_generator_(new DriBufferGenerator()),
52 screen_manager_(new ScreenManager(dri_
.get(), buffer_generator_
.get())),
53 device_manager_(CreateDeviceManager()) {}
54 ~OzonePlatformDri() override
{}
57 ui::SurfaceFactoryOzone
* GetSurfaceFactoryOzone() override
{
58 return surface_factory_ozone_
.get();
60 CursorFactoryOzone
* GetCursorFactoryOzone() override
{
61 return cursor_factory_ozone_
.get();
63 InputController
* GetInputController() override
{
64 return event_factory_ozone_
->input_controller();
66 GpuPlatformSupport
* GetGpuPlatformSupport() override
{
67 return gpu_platform_support_
.get();
69 GpuPlatformSupportHost
* GetGpuPlatformSupportHost() override
{
70 return gpu_platform_support_host_
.get();
72 scoped_ptr
<SystemInputInjector
> CreateSystemInputInjector() override
{
73 return event_factory_ozone_
->CreateSystemInputInjector();
75 scoped_ptr
<PlatformWindow
> CreatePlatformWindow(
76 PlatformWindowDelegate
* delegate
,
77 const gfx::Rect
& bounds
) override
{
78 scoped_ptr
<DriWindow
> platform_window(
79 new DriWindow(delegate
, bounds
, gpu_platform_support_host_
.get(),
80 event_factory_ozone_
.get(), cursor_
.get(),
81 window_manager_
.get(), display_manager_
.get()));
82 platform_window
->Initialize();
83 return platform_window
.Pass();
85 scoped_ptr
<NativeDisplayDelegate
> CreateNativeDisplayDelegate() override
{
86 return scoped_ptr
<NativeDisplayDelegate
>(new NativeDisplayDelegateProxy(
87 gpu_platform_support_host_
.get(), device_manager_
.get(),
88 display_manager_
.get()));
90 void InitializeUI() override
{
92 display_manager_
.reset(new DisplayManager());
93 surface_factory_ozone_
.reset(
94 new DriSurfaceFactory(dri_
.get(), &window_delegate_manager_
));
95 scoped_ptr
<NativeDisplayDelegateDri
> ndd(
96 new NativeDisplayDelegateDri(dri_
.get(), screen_manager_
.get()));
98 gpu_platform_support_
.reset(
99 new DriGpuPlatformSupport(dri_
.get(), &window_delegate_manager_
,
100 screen_manager_
.get(), ndd
.Pass()));
101 gpu_platform_support_host_
.reset(new DriGpuPlatformSupportHost());
102 window_manager_
.reset(new DriWindowManager());
103 cursor_factory_ozone_
.reset(new BitmapCursorFactoryOzone
);
105 new DriCursor(window_manager_
.get(), gpu_platform_support_host_
.get()));
107 #if defined(USE_XKBCOMMON)
108 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(make_scoped_ptr(
109 new XkbKeyboardLayoutEngine(xkb_evdev_code_converter_
)));
111 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
112 make_scoped_ptr(new StubKeyboardLayoutEngine()));
114 event_factory_ozone_
.reset(new EventFactoryEvdev(
115 cursor_
.get(), device_manager_
.get(),
116 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()));
118 if (!ui_thread_gpu_
.Initialize())
119 LOG(FATAL
) << "Failed to initialize dummy channel.";
122 void InitializeGPU() override
{}
125 scoped_ptr
<DriWrapper
> dri_
;
126 scoped_ptr
<DriBufferGenerator
> buffer_generator_
;
127 scoped_ptr
<ScreenManager
> screen_manager_
;
128 scoped_ptr
<DeviceManager
> device_manager_
;
130 scoped_ptr
<DriSurfaceFactory
> surface_factory_ozone_
;
131 scoped_ptr
<BitmapCursorFactoryOzone
> cursor_factory_ozone_
;
132 scoped_ptr
<EventFactoryEvdev
> event_factory_ozone_
;
134 scoped_ptr
<DriCursor
> cursor_
;
135 scoped_ptr
<DriWindowManager
> window_manager_
;
136 scoped_ptr
<DisplayManager
> display_manager_
;
138 scoped_ptr
<DriGpuPlatformSupport
> gpu_platform_support_
;
139 scoped_ptr
<DriGpuPlatformSupportHost
> gpu_platform_support_host_
;
141 DriWindowDelegateManager window_delegate_manager_
;
143 UiThreadGpu ui_thread_gpu_
;
145 #if defined(USE_XKBCOMMON)
146 XkbEvdevCodes xkb_evdev_code_converter_
;
149 DISALLOW_COPY_AND_ASSIGN(OzonePlatformDri
);
154 OzonePlatform
* CreateOzonePlatformDri() {
155 return new OzonePlatformDri
;