Fix search results being clipped in app list.
[chromium-blink-merge.git] / ui / ozone / platform / drm / ozone_platform_gbm.cc
blobb63cd914df0870282e1a1f35e2617ce4a4161ee1
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"
7 #include <dlfcn.h>
8 #include <gbm.h>
9 #include <stdlib.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/gbm_surface_factory.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/drm_util.h"
24 #include "ui/ozone/platform/drm/gpu/gbm_buffer.h"
25 #include "ui/ozone/platform/drm/gpu/gbm_device.h"
26 #include "ui/ozone/platform/drm/gpu/gbm_surface.h"
27 #include "ui/ozone/platform/drm/gpu/gpu_lock.h"
28 #include "ui/ozone/platform/drm/gpu/scanout_buffer.h"
29 #include "ui/ozone/platform/drm/gpu/screen_manager.h"
30 #include "ui/ozone/platform/drm/host/display_manager.h"
31 #include "ui/ozone/platform/drm/host/drm_cursor.h"
32 #include "ui/ozone/platform/drm/host/drm_gpu_platform_support_host.h"
33 #include "ui/ozone/platform/drm/host/drm_native_display_delegate.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"
45 #else
46 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
47 #endif
49 namespace ui {
51 namespace {
53 class GlApiLoader {
54 public:
55 GlApiLoader()
56 : glapi_lib_(dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL)) {}
58 ~GlApiLoader() {
59 if (glapi_lib_)
60 dlclose(glapi_lib_);
63 private:
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.
68 void* glapi_lib_;
70 DISALLOW_COPY_AND_ASSIGN(GlApiLoader);
73 class GbmBufferGenerator : public ScanoutBufferGenerator {
74 public:
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::RGBA_8888, size,
83 true);
86 protected:
87 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator);
90 class GbmDeviceGenerator : public DrmDeviceGenerator {
91 public:
92 GbmDeviceGenerator() {}
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())
100 return drm;
102 return nullptr;
105 private:
106 DISALLOW_COPY_AND_ASSIGN(GbmDeviceGenerator);
109 class OzonePlatformGbm : public OzonePlatform {
110 public:
111 OzonePlatformGbm(bool use_surfaceless) : use_surfaceless_(use_surfaceless) {}
112 ~OzonePlatformGbm() override {}
114 // OzonePlatform:
115 ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override {
116 return surface_factory_ozone_.get();
118 CursorFactoryOzone* GetCursorFactoryOzone() override {
119 return cursor_factory_ozone_.get();
121 InputController* GetInputController() override {
122 return event_factory_ozone_->input_controller();
124 GpuPlatformSupport* GetGpuPlatformSupport() override {
125 return gpu_platform_support_.get();
127 GpuPlatformSupportHost* GetGpuPlatformSupportHost() override {
128 return gpu_platform_support_host_.get();
130 scoped_ptr<SystemInputInjector> CreateSystemInputInjector() override {
131 return event_factory_ozone_->CreateSystemInputInjector();
133 scoped_ptr<PlatformWindow> CreatePlatformWindow(
134 PlatformWindowDelegate* delegate,
135 const gfx::Rect& bounds) override {
136 scoped_ptr<DrmWindowHost> platform_window(
137 new DrmWindowHost(delegate, bounds, gpu_platform_support_host_.get(),
138 event_factory_ozone_.get(), cursor_.get(),
139 window_manager_.get(), display_manager_.get()));
140 platform_window->Initialize();
141 return platform_window.Pass();
143 scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() override {
144 return make_scoped_ptr(new DrmNativeDisplayDelegate(
145 gpu_platform_support_host_.get(), device_manager_.get(),
146 display_manager_.get(), primary_graphics_card_path_));
148 void InitializeUI() override {
149 primary_graphics_card_path_ = GetPrimaryDisplayCardPath();
150 display_manager_.reset(new DisplayManager());
151 // Needed since the browser process creates the accelerated widgets and that
152 // happens through SFO.
153 if (!surface_factory_ozone_)
154 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_));
155 device_manager_ = CreateDeviceManager();
156 window_manager_.reset(new DrmWindowHostManager());
157 cursor_.reset(new DrmCursor(window_manager_.get()));
158 gpu_platform_support_host_.reset(
159 new DrmGpuPlatformSupportHost(cursor_.get()));
160 cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
161 #if defined(USE_XKBCOMMON)
162 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(make_scoped_ptr(
163 new XkbKeyboardLayoutEngine(xkb_evdev_code_converter_)));
164 #else
165 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
166 make_scoped_ptr(new StubKeyboardLayoutEngine()));
167 #endif
168 event_factory_ozone_.reset(new EventFactoryEvdev(
169 cursor_.get(), device_manager_.get(),
170 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()));
173 void InitializeGPU() override {
174 #if defined(OS_CHROMEOS)
175 gpu_lock_.reset(new GpuLock());
176 #endif
177 gl_api_loader_.reset(new GlApiLoader());
178 // Async page flips are supported only on surfaceless mode.
179 gbm_ = new GbmDevice(GetPrimaryDisplayCardPath());
180 if (!gbm_->Initialize())
181 LOG(FATAL) << "Failed to initialize primary DRM device";
183 drm_device_manager_.reset(new DrmDeviceManager(gbm_));
184 buffer_generator_.reset(new GbmBufferGenerator());
185 screen_manager_.reset(new ScreenManager(buffer_generator_.get()));
186 // This makes sure that simple targets that do not handle display
187 // configuration can still use the primary display.
188 ForceInitializationOfPrimaryDisplay(gbm_, screen_manager_.get());
190 if (!surface_factory_ozone_)
191 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_));
193 surface_factory_ozone_->InitializeGpu(drm_device_manager_.get(),
194 screen_manager_.get());
195 scoped_ptr<DrmGpuDisplayManager> ndd(new DrmGpuDisplayManager(
196 screen_manager_.get(), gbm_,
197 scoped_ptr<DrmDeviceGenerator>(new GbmDeviceGenerator())));
198 gpu_platform_support_.reset(new DrmGpuPlatformSupport(
199 drm_device_manager_.get(), screen_manager_.get(), ndd.Pass()));
202 private:
203 // Objects in both processes.
204 bool use_surfaceless_;
205 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_;
207 // Objects in the GPU process.
208 scoped_ptr<GpuLock> gpu_lock_;
209 scoped_ptr<GlApiLoader> gl_api_loader_;
210 scoped_refptr<GbmDevice> gbm_;
211 scoped_ptr<DrmDeviceManager> drm_device_manager_;
212 scoped_ptr<GbmBufferGenerator> buffer_generator_;
213 scoped_ptr<ScreenManager> screen_manager_;
214 scoped_ptr<DrmGpuPlatformSupport> gpu_platform_support_;
216 // Objects in the Browser process.
217 base::FilePath primary_graphics_card_path_;
218 scoped_ptr<DeviceManager> device_manager_;
219 scoped_ptr<BitmapCursorFactoryOzone> cursor_factory_ozone_;
220 scoped_ptr<DrmWindowHostManager> window_manager_;
221 scoped_ptr<DrmCursor> cursor_;
222 scoped_ptr<EventFactoryEvdev> event_factory_ozone_;
223 scoped_ptr<DrmGpuPlatformSupportHost> gpu_platform_support_host_;
224 scoped_ptr<DisplayManager> display_manager_;
226 #if defined(USE_XKBCOMMON)
227 XkbEvdevCodes xkb_evdev_code_converter_;
228 #endif
230 DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm);
233 } // namespace
235 OzonePlatform* CreateOzonePlatformGbm() {
236 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
237 #if defined(USE_MESA_PLATFORM_NULL)
238 // Only works with surfaceless.
239 cmd->AppendSwitch(switches::kOzoneUseSurfaceless);
240 #endif
241 return new OzonePlatformGbm(cmd->HasSwitch(switches::kOzoneUseSurfaceless));
244 } // namespace ui