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

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

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 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
« no previous file with comments | « ui/ozone/platform/dri/ozone_platform_gbm.h ('k') | ui/ozone/platform/dri/scanout_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/dri/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/command_line.h"
13 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
14 #include "ui/events/ozone/device/device_manager.h"
15 #include "ui/events/ozone/evdev/event_factory_evdev.h"
16 #include "ui/ozone/platform/dri/dri_cursor.h"
17 #include "ui/ozone/platform/dri/dri_gpu_platform_support.h"
18 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h"
19 #include "ui/ozone/platform/dri/dri_window.h"
20 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h"
21 #include "ui/ozone/platform/dri/dri_window_manager.h"
22 #include "ui/ozone/platform/dri/dri_wrapper.h"
23 #include "ui/ozone/platform/dri/gbm_buffer.h"
24 #include "ui/ozone/platform/dri/gbm_surface.h"
25 #include "ui/ozone/platform/dri/gbm_surface_factory.h"
26 #include "ui/ozone/platform/dri/native_display_delegate_dri.h"
27 #include "ui/ozone/platform/dri/native_display_delegate_proxy.h"
28 #include "ui/ozone/platform/dri/scanout_buffer.h"
29 #include "ui/ozone/platform/dri/screen_manager.h"
30 #include "ui/ozone/platform/dri/virtual_terminal_manager.h"
31 #include "ui/ozone/public/cursor_factory_ozone.h"
32 #include "ui/ozone/public/gpu_platform_support.h"
33 #include "ui/ozone/public/gpu_platform_support_host.h"
34 #include "ui/ozone/public/ozone_platform.h"
35 #include "ui/ozone/public/ozone_switches.h"
36
37 namespace ui {
38
39 namespace {
40
41 const char kDefaultGraphicsCardPath[] = "/dev/dri/card0";
42
43 class GbmBufferGenerator : public ScanoutBufferGenerator {
44 public:
45 GbmBufferGenerator(DriWrapper* dri)
46 : dri_(dri),
47 glapi_lib_(dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL)),
48 device_(gbm_create_device(dri_->get_fd())) {
49 if (!device_)
50 LOG(FATAL) << "Unable to initialize gbm for " << kDefaultGraphicsCardPath;
51 }
52 virtual ~GbmBufferGenerator() {
53 gbm_device_destroy(device_);
54 if (glapi_lib_)
55 dlclose(glapi_lib_);
56 }
57
58 gbm_device* device() const { return device_; }
59
60 virtual scoped_refptr<ScanoutBuffer> Create(const gfx::Size& size) override {
61 return GbmBuffer::CreateBuffer(
62 dri_, device_, SurfaceFactoryOzone::RGBA_8888, size, true);
63 }
64
65 protected:
66 DriWrapper* dri_; // Not owned.
67
68 // HACK: gbm drivers have broken linkage
69 void *glapi_lib_;
70
71 gbm_device* device_;
72
73 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator);
74 };
75
76 class OzonePlatformGbm : public OzonePlatform {
77 public:
78 OzonePlatformGbm(bool use_surfaceless) : use_surfaceless_(use_surfaceless) {
79 base::AtExitManager::RegisterTask(
80 base::Bind(&base::DeletePointer<OzonePlatformGbm>, this));
81 }
82 virtual ~OzonePlatformGbm() {}
83
84 // OzonePlatform:
85 virtual ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override {
86 return surface_factory_ozone_.get();
87 }
88 virtual CursorFactoryOzone* GetCursorFactoryOzone() override {
89 return cursor_factory_ozone_.get();
90 }
91 virtual GpuPlatformSupport* GetGpuPlatformSupport() override {
92 return gpu_platform_support_.get();
93 }
94 virtual GpuPlatformSupportHost* GetGpuPlatformSupportHost() override {
95 return gpu_platform_support_host_.get();
96 }
97 virtual scoped_ptr<PlatformWindow> CreatePlatformWindow(
98 PlatformWindowDelegate* delegate,
99 const gfx::Rect& bounds) override {
100 scoped_ptr<DriWindow> platform_window(
101 new DriWindow(delegate,
102 bounds,
103 gpu_platform_support_host_.get(),
104 event_factory_ozone_.get(),
105 window_manager_.get()));
106 platform_window->Initialize();
107 return platform_window.Pass();
108 }
109 virtual scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate()
110 override {
111 return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateProxy(
112 gpu_platform_support_host_.get(), device_manager_.get()));
113 }
114 virtual void InitializeUI() override {
115 vt_manager_.reset(new VirtualTerminalManager());
116 // Needed since the browser process creates the accelerated widgets and that
117 // happens through SFO.
118 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_));
119 device_manager_ = CreateDeviceManager();
120 gpu_platform_support_host_.reset(new DriGpuPlatformSupportHost());
121 cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
122 window_manager_.reset(
123 new DriWindowManager(gpu_platform_support_host_.get()));
124 event_factory_ozone_.reset(new EventFactoryEvdev(window_manager_->cursor(),
125 device_manager_.get()));
126 }
127
128 virtual void InitializeGPU() override {
129 dri_.reset(new DriWrapper(kDefaultGraphicsCardPath));
130 dri_->Initialize();
131 buffer_generator_.reset(new GbmBufferGenerator(dri_.get()));
132 screen_manager_.reset(new ScreenManager(dri_.get(),
133 buffer_generator_.get()));
134 window_delegate_manager_.reset(new DriWindowDelegateManager());
135 if (!surface_factory_ozone_)
136 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_));
137
138 surface_factory_ozone_->InitializeGpu(dri_.get(),
139 buffer_generator_->device(),
140 screen_manager_.get(),
141 window_delegate_manager_.get());
142 gpu_platform_support_.reset(new DriGpuPlatformSupport(
143 surface_factory_ozone_.get(),
144 window_delegate_manager_.get(),
145 screen_manager_.get(),
146 scoped_ptr<NativeDisplayDelegateDri>(new NativeDisplayDelegateDri(
147 dri_.get(), screen_manager_.get(), NULL))));
148 if (surface_factory_ozone_->InitializeHardware() !=
149 DriSurfaceFactory::INITIALIZED)
150 LOG(FATAL) << "failed to initialize display hardware";
151 }
152
153 private:
154 bool use_surfaceless_;
155 scoped_ptr<VirtualTerminalManager> vt_manager_;
156 scoped_ptr<DriWrapper> dri_;
157 scoped_ptr<GbmBufferGenerator> buffer_generator_;
158 scoped_ptr<ScreenManager> screen_manager_;
159 scoped_ptr<DeviceManager> device_manager_;
160
161 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_;
162 scoped_ptr<BitmapCursorFactoryOzone> cursor_factory_ozone_;
163 scoped_ptr<EventFactoryEvdev> event_factory_ozone_;
164
165 scoped_ptr<DriGpuPlatformSupport> gpu_platform_support_;
166 scoped_ptr<DriGpuPlatformSupportHost> gpu_platform_support_host_;
167
168 scoped_ptr<DriWindowDelegateManager> window_delegate_manager_;
169 // Browser side object only.
170 scoped_ptr<DriWindowManager> window_manager_;
171
172 DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm);
173 };
174
175 } // namespace
176
177 OzonePlatform* CreateOzonePlatformGbm() {
178 CommandLine* cmd = CommandLine::ForCurrentProcess();
179 return new OzonePlatformGbm(cmd->HasSwitch(switches::kOzoneUseSurfaceless));
180 }
181
182 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/ozone_platform_gbm.h ('k') | ui/ozone/platform/dri/scanout_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698