Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: ui/ozone/platform/drm/ozone_platform_gbm.cc

Issue 1285183008: Ozone integration. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: add missing license header Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "ui/ozone/platform/drm/ozone_platform_gbm.h"
6
7 #include <dlfcn.h>
8 #include <gbm.h>
9 #include <stdlib.h>
10
11 #include "base/at_exit.h"
12 #include "base/bind.h"
13 #include "base/command_line.h"
14 #include "base/thread_task_runner_handle.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_gpu_test_helper.h"
40 #include "ui/ozone/public/ozone_platform.h"
41 #include "ui/ozone/public/ozone_switches.h"
42
43 #if defined(USE_XKBCOMMON)
44 #include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h"
45 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h"
46 #else
47 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h"
48 #endif
49
50 namespace ui {
51
52 namespace {
53
54 class GlApiLoader {
55 public:
56 GlApiLoader()
57 : glapi_lib_(dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL)) {}
58
59 ~GlApiLoader() {
60 if (glapi_lib_)
61 dlclose(glapi_lib_);
62 }
63
64 private:
65 // HACK: gbm drivers have broken linkage. The Mesa DRI driver references
66 // symbols in the libglapi library however it does not explicitly link against
67 // it. That caused linkage errors when running an application that does not
68 // explicitly link against libglapi.
69 void* glapi_lib_;
70
71 DISALLOW_COPY_AND_ASSIGN(GlApiLoader);
72 };
73
74 class GbmBufferGenerator : public ScanoutBufferGenerator {
75 public:
76 GbmBufferGenerator() {}
77 ~GbmBufferGenerator() override {}
78
79 // ScanoutBufferGenerator:
80 scoped_refptr<ScanoutBuffer> Create(const scoped_refptr<DrmDevice>& drm,
81 const gfx::Size& size) override {
82 scoped_refptr<GbmDevice> gbm(static_cast<GbmDevice*>(drm.get()));
83 return GbmBuffer::CreateBuffer(gbm, SurfaceFactoryOzone::BGRA_8888, size,
84 true);
85 }
86
87 protected:
88 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator);
89 };
90
91 class GbmDeviceGenerator : public DrmDeviceGenerator {
92 public:
93 GbmDeviceGenerator(bool use_atomic) : use_atomic_(use_atomic) {}
94 ~GbmDeviceGenerator() override {}
95
96 // DrmDeviceGenerator:
97 scoped_refptr<DrmDevice> CreateDevice(const base::FilePath& path,
98 base::File file) override {
99 scoped_refptr<DrmDevice> drm = new GbmDevice(path, file.Pass());
100 if (drm->Initialize(use_atomic_))
101 return drm;
102
103 return nullptr;
104 }
105
106 private:
107 bool use_atomic_;
108
109 DISALLOW_COPY_AND_ASSIGN(GbmDeviceGenerator);
110 };
111
112 class OzonePlatformGbm : public OzonePlatform {
113 public:
114 OzonePlatformGbm(bool use_surfaceless) : use_surfaceless_(use_surfaceless) {}
115 ~OzonePlatformGbm() override {}
116
117 // OzonePlatform:
118 ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override {
119 return surface_factory_ozone_.get();
120 }
121 OverlayManagerOzone* GetOverlayManager() override {
122 return overlay_manager_.get();
123 }
124 CursorFactoryOzone* GetCursorFactoryOzone() override {
125 NOTIMPLEMENTED();
126 return nullptr;
127 }
128 InputController* GetInputController() override {
129 return event_factory_ozone_->input_controller();
130 }
131 GpuPlatformSupport* GetGpuPlatformSupport() override {
132 return gpu_platform_support_.get();
133 }
134 GpuPlatformSupportHost* GetGpuPlatformSupportHost() override {
135 return gpu_platform_support_host_.get();
136 }
137 scoped_ptr<SystemInputInjector> CreateSystemInputInjector() override {
138 return event_factory_ozone_->CreateSystemInputInjector();
139 }
140 scoped_ptr<PlatformWindow> CreatePlatformWindow(
141 PlatformWindowDelegate* delegate,
142 const gfx::Rect& bounds) override {
143 scoped_ptr<DrmWindowHost> platform_window(
144 new DrmWindowHost(delegate, bounds, gpu_platform_support_host_.get(),
145 event_factory_ozone_.get(), cursor_.get(),
146 window_manager_.get(), display_manager_.get()));
147 platform_window->Initialize();
148 return platform_window.Pass();
149 }
150 scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() override {
151 return make_scoped_ptr(
152 new DrmNativeDisplayDelegate(display_manager_.get()));
153 }
154 void InitializeUI() override {
155 device_manager_ = CreateDeviceManager();
156 window_manager_.reset(new DrmWindowHostManager());
157 cursor_.reset(new DrmCursor(window_manager_.get()));
158 #if defined(USE_XKBCOMMON)
159 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(make_scoped_ptr(
160 new XkbKeyboardLayoutEngine(xkb_evdev_code_converter_)));
161 #else
162 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine(
163 make_scoped_ptr(new StubKeyboardLayoutEngine()));
164 #endif
165 event_factory_ozone_.reset(new EventFactoryEvdev(
166 cursor_.get(), device_manager_.get(),
167 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine()));
168 gpu_platform_support_host_.reset(
169 new DrmGpuPlatformSupportHost(cursor_.get()));
170 display_manager_.reset(new DrmDisplayHostManager(
171 gpu_platform_support_host_.get(), device_manager_.get(),
172 event_factory_ozone_->input_controller()));
173 overlay_manager_.reset(new DrmOverlayManager(
174 use_surfaceless_, gpu_platform_support_host_.get()));
175
176 gpu_platform_support_host_->SetDisplayManager(display_manager_.get());
177 gpu_platform_support_host_->SetWindowManager(window_manager_.get());
178 }
179
180 void InitializeGPU() override {
181 bool use_atomic = false;
182 gl_api_loader_.reset(new GlApiLoader());
183 drm_device_manager_.reset(new DrmDeviceManager(
184 scoped_ptr<DrmDeviceGenerator>(new GbmDeviceGenerator(use_atomic))));
185 buffer_generator_.reset(new GbmBufferGenerator());
186 screen_manager_.reset(new ScreenManager(buffer_generator_.get()));
187 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_));
188 surface_factory_ozone_->InitializeGpu(drm_device_manager_.get(),
189 screen_manager_.get());
190 scoped_ptr<DrmGpuDisplayManager> display_manager(new DrmGpuDisplayManager(
191 screen_manager_.get(), drm_device_manager_.get()));
192 gpu_platform_support_.reset(new DrmGpuPlatformSupport(
193 drm_device_manager_.get(), screen_manager_.get(),
194 buffer_generator_.get(), display_manager.Pass()));
195 }
196
197 private:
198 // Objects in both processes.
199 bool use_surfaceless_;
200
201 // Objects in the GPU process.
202 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_;
203 scoped_ptr<GlApiLoader> gl_api_loader_;
204 scoped_ptr<DrmDeviceManager> drm_device_manager_;
205 scoped_ptr<GbmBufferGenerator> buffer_generator_;
206 scoped_ptr<ScreenManager> screen_manager_;
207 scoped_ptr<DrmGpuPlatformSupport> gpu_platform_support_;
208
209 // Objects in the Browser process.
210 scoped_ptr<DeviceManager> device_manager_;
211 scoped_ptr<DrmWindowHostManager> window_manager_;
212 scoped_ptr<DrmCursor> cursor_;
213 scoped_ptr<EventFactoryEvdev> event_factory_ozone_;
214 scoped_ptr<DrmGpuPlatformSupportHost> gpu_platform_support_host_;
215 scoped_ptr<DrmDisplayHostManager> display_manager_;
216 scoped_ptr<DrmOverlayManager> overlay_manager_;
217
218 #if defined(USE_XKBCOMMON)
219 XkbEvdevCodes xkb_evdev_code_converter_;
220 #endif
221
222 DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm);
223 };
224
225 } // namespace
226
227 OzonePlatform* CreateOzonePlatformGbm() {
228 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess();
229 #if defined(USE_MESA_PLATFORM_NULL)
230 // Only works with surfaceless.
231 cmd->AppendSwitch(switches::kOzoneUseSurfaceless);
232 #endif
233 return new OzonePlatformGbm(cmd->HasSwitch(switches::kOzoneUseSurfaceless));
234 }
235
236 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/drm/ozone_platform_gbm.h ('k') | ui/ozone/platform/drm/test/mock_drm_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698