OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/ozone/platform/dri/ozone_platform_gbm.h" | 5 #include "ui/ozone/platform/dri/ozone_platform_gbm.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <gbm.h> | 8 #include <gbm.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 | 10 |
11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
12 #include "ui/events/ozone/device/device_manager.h" | 12 #include "ui/events/ozone/device/device_manager.h" |
13 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 13 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
14 #include "ui/ozone/common/window/platform_window_compat.h" | 14 #include "ui/ozone/common/window/platform_window_compat.h" |
15 #include "ui/ozone/platform/dri/cursor_factory_evdev_dri.h" | 15 #include "ui/ozone/platform/dri/cursor_factory_evdev_dri.h" |
16 #include "ui/ozone/platform/dri/dri_wrapper.h" | 16 #include "ui/ozone/platform/dri/dri_wrapper.h" |
17 #include "ui/ozone/platform/dri/gbm_buffer.h" | 17 #include "ui/ozone/platform/dri/gbm_buffer.h" |
18 #include "ui/ozone/platform/dri/gbm_surface.h" | 18 #include "ui/ozone/platform/dri/gbm_surface.h" |
19 #include "ui/ozone/platform/dri/gbm_surface_factory.h" | 19 #include "ui/ozone/platform/dri/gbm_surface_factory.h" |
20 #include "ui/ozone/platform/dri/gpu_platform_support_gbm.h" | 20 #include "ui/ozone/platform/dri/gpu_platform_support_gbm.h" |
21 #include "ui/ozone/platform/dri/gpu_platform_support_host_gbm.h" | 21 #include "ui/ozone/platform/dri/gpu_platform_support_host_gbm.h" |
22 #include "ui/ozone/platform/dri/scanout_surface.h" | 22 #include "ui/ozone/platform/dri/scanout_buffer.h" |
23 #include "ui/ozone/platform/dri/screen_manager.h" | 23 #include "ui/ozone/platform/dri/screen_manager.h" |
24 #include "ui/ozone/platform/dri/virtual_terminal_manager.h" | 24 #include "ui/ozone/platform/dri/virtual_terminal_manager.h" |
25 #include "ui/ozone/public/cursor_factory_ozone.h" | 25 #include "ui/ozone/public/cursor_factory_ozone.h" |
26 #include "ui/ozone/public/gpu_platform_support.h" | 26 #include "ui/ozone/public/gpu_platform_support.h" |
27 #include "ui/ozone/public/gpu_platform_support_host.h" | 27 #include "ui/ozone/public/gpu_platform_support_host.h" |
28 #include "ui/ozone/public/ozone_platform.h" | 28 #include "ui/ozone/public/ozone_platform.h" |
29 | 29 |
30 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
31 #include "ui/ozone/common/chromeos/touchscreen_device_manager_ozone.h" | 31 #include "ui/ozone/common/chromeos/touchscreen_device_manager_ozone.h" |
32 #include "ui/ozone/platform/dri/chromeos/display_message_handler.h" | 32 #include "ui/ozone/platform/dri/chromeos/display_message_handler.h" |
33 #include "ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h" | 33 #include "ui/ozone/platform/dri/chromeos/native_display_delegate_dri.h" |
34 #include "ui/ozone/platform/dri/chromeos/native_display_delegate_proxy.h" | 34 #include "ui/ozone/platform/dri/chromeos/native_display_delegate_proxy.h" |
35 #endif | 35 #endif |
36 | 36 |
37 namespace ui { | 37 namespace ui { |
38 | 38 |
39 namespace { | 39 namespace { |
40 | 40 |
41 const char kDefaultGraphicsCardPath[] = "/dev/dri/card0"; | 41 const char kDefaultGraphicsCardPath[] = "/dev/dri/card0"; |
42 | 42 |
43 class GbmSurfaceGenerator : public ScanoutSurfaceGenerator { | 43 class GbmBufferGenerator : public ScanoutBufferGenerator { |
44 public: | 44 public: |
45 GbmSurfaceGenerator(DriWrapper* dri) | 45 GbmBufferGenerator(DriWrapper* dri) |
46 : dri_(dri), | 46 : dri_(dri), |
47 glapi_lib_(dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL)), | 47 glapi_lib_(dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL)), |
48 device_(gbm_create_device(dri_->get_fd())) {} | 48 device_(gbm_create_device(dri_->get_fd())) {} |
49 virtual ~GbmSurfaceGenerator() { | 49 virtual ~GbmBufferGenerator() { |
50 gbm_device_destroy(device_); | 50 gbm_device_destroy(device_); |
51 if (glapi_lib_) | 51 if (glapi_lib_) |
52 dlclose(glapi_lib_); | 52 dlclose(glapi_lib_); |
53 } | 53 } |
54 | 54 |
55 gbm_device* device() const { return device_; } | 55 gbm_device* device() const { return device_; } |
56 | 56 |
57 virtual ScanoutSurface* Create(const gfx::Size& size) OVERRIDE { | 57 virtual scoped_refptr<ScanoutBuffer> Create(const gfx::Size& size) OVERRIDE { |
58 return new GbmSurface(device_, dri_, size); | 58 return GbmBuffer::CreateBuffer( |
| 59 dri_, device_, SurfaceFactoryOzone::RGBA_8888, size, true); |
59 } | 60 } |
60 | 61 |
61 protected: | 62 protected: |
62 DriWrapper* dri_; // Not owned. | 63 DriWrapper* dri_; // Not owned. |
63 | 64 |
64 // HACK: gbm drivers have broken linkage | 65 // HACK: gbm drivers have broken linkage |
65 void *glapi_lib_; | 66 void *glapi_lib_; |
66 | 67 |
67 gbm_device* device_; | 68 gbm_device* device_; |
68 | 69 |
69 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceGenerator); | 70 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator); |
70 }; | |
71 | |
72 class GbmEglImageSurfaceGenerator : public GbmSurfaceGenerator { | |
73 public: | |
74 GbmEglImageSurfaceGenerator(DriWrapper* dri) : GbmSurfaceGenerator(dri) {} | |
75 virtual ~GbmEglImageSurfaceGenerator() {} | |
76 | |
77 virtual ScanoutSurface* Create(const gfx::Size& size) OVERRIDE { | |
78 scoped_ptr<GbmBuffer> buffer = | |
79 scoped_ptr<GbmBuffer>(new GbmBuffer(device_, dri_, size)); | |
80 if (!buffer->InitializeBuffer(SurfaceFactoryOzone::RGBA_8888, true)) { | |
81 return NULL; | |
82 } | |
83 return buffer.release(); | |
84 } | |
85 }; | 71 }; |
86 | 72 |
87 class OzonePlatformGbm : public OzonePlatform { | 73 class OzonePlatformGbm : public OzonePlatform { |
88 public: | 74 public: |
89 OzonePlatformGbm(bool use_surfaceless) : use_surfaceless_(use_surfaceless) { | 75 OzonePlatformGbm(bool use_surfaceless) : use_surfaceless_(use_surfaceless) { |
90 base::AtExitManager::RegisterTask( | 76 base::AtExitManager::RegisterTask( |
91 base::Bind(&base::DeletePointer<OzonePlatformGbm>, this)); | 77 base::Bind(&base::DeletePointer<OzonePlatformGbm>, this)); |
92 } | 78 } |
93 virtual ~OzonePlatformGbm() {} | 79 virtual ~OzonePlatformGbm() {} |
94 | 80 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 device_manager_ = CreateDeviceManager(); | 121 device_manager_ = CreateDeviceManager(); |
136 gpu_platform_support_host_.reset(new GpuPlatformSupportHostGbm()); | 122 gpu_platform_support_host_.reset(new GpuPlatformSupportHostGbm()); |
137 cursor_factory_ozone_.reset( | 123 cursor_factory_ozone_.reset( |
138 new CursorFactoryEvdevDri(gpu_platform_support_host_.get())); | 124 new CursorFactoryEvdevDri(gpu_platform_support_host_.get())); |
139 event_factory_ozone_.reset(new EventFactoryEvdev( | 125 event_factory_ozone_.reset(new EventFactoryEvdev( |
140 cursor_factory_ozone_.get(), device_manager_.get())); | 126 cursor_factory_ozone_.get(), device_manager_.get())); |
141 } | 127 } |
142 | 128 |
143 virtual void InitializeGPU() OVERRIDE { | 129 virtual void InitializeGPU() OVERRIDE { |
144 dri_.reset(new DriWrapper(kDefaultGraphicsCardPath)); | 130 dri_.reset(new DriWrapper(kDefaultGraphicsCardPath)); |
145 if (use_surfaceless_) | 131 buffer_generator_.reset(new GbmBufferGenerator(dri_.get())); |
146 surface_generator_.reset(new GbmEglImageSurfaceGenerator(dri_.get())); | |
147 else | |
148 surface_generator_.reset(new GbmSurfaceGenerator(dri_.get())); | |
149 screen_manager_.reset(new ScreenManager(dri_.get(), | 132 screen_manager_.reset(new ScreenManager(dri_.get(), |
150 surface_generator_.get())); | 133 buffer_generator_.get())); |
151 if (!surface_factory_ozone_) | 134 if (!surface_factory_ozone_) |
152 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_)); | 135 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_)); |
153 | 136 |
154 surface_factory_ozone_->InitializeGpu(dri_.get(), | 137 surface_factory_ozone_->InitializeGpu(dri_.get(), |
155 surface_generator_->device(), | 138 buffer_generator_->device(), |
156 screen_manager_.get()); | 139 screen_manager_.get()); |
157 | 140 |
158 gpu_platform_support_.reset( | 141 gpu_platform_support_.reset( |
159 new GpuPlatformSupportGbm(surface_factory_ozone_.get())); | 142 new GpuPlatformSupportGbm(surface_factory_ozone_.get())); |
160 #if defined(OS_CHROMEOS) | 143 #if defined(OS_CHROMEOS) |
161 gpu_platform_support_->AddHandler(scoped_ptr<GpuPlatformSupport>( | 144 gpu_platform_support_->AddHandler(scoped_ptr<GpuPlatformSupport>( |
162 new DisplayMessageHandler( | 145 new DisplayMessageHandler( |
163 scoped_ptr<NativeDisplayDelegateDri>(new NativeDisplayDelegateDri( | 146 scoped_ptr<NativeDisplayDelegateDri>(new NativeDisplayDelegateDri( |
164 dri_.get(), | 147 dri_.get(), |
165 screen_manager_.get(), | 148 screen_manager_.get(), |
166 NULL))))); | 149 NULL))))); |
167 #endif | 150 #endif |
168 } | 151 } |
169 | 152 |
170 private: | 153 private: |
171 bool use_surfaceless_; | 154 bool use_surfaceless_; |
172 scoped_ptr<VirtualTerminalManager> vt_manager_; | 155 scoped_ptr<VirtualTerminalManager> vt_manager_; |
173 scoped_ptr<DriWrapper> dri_; | 156 scoped_ptr<DriWrapper> dri_; |
174 scoped_ptr<GbmSurfaceGenerator> surface_generator_; | 157 scoped_ptr<GbmBufferGenerator> buffer_generator_; |
175 scoped_ptr<ScreenManager> screen_manager_; | 158 scoped_ptr<ScreenManager> screen_manager_; |
176 scoped_ptr<DeviceManager> device_manager_; | 159 scoped_ptr<DeviceManager> device_manager_; |
177 | 160 |
178 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_; | 161 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_; |
179 scoped_ptr<CursorFactoryEvdevDri> cursor_factory_ozone_; | 162 scoped_ptr<CursorFactoryEvdevDri> cursor_factory_ozone_; |
180 scoped_ptr<EventFactoryEvdev> event_factory_ozone_; | 163 scoped_ptr<EventFactoryEvdev> event_factory_ozone_; |
181 | 164 |
182 scoped_ptr<GpuPlatformSupportGbm> gpu_platform_support_; | 165 scoped_ptr<GpuPlatformSupportGbm> gpu_platform_support_; |
183 scoped_ptr<GpuPlatformSupportHostGbm> gpu_platform_support_host_; | 166 scoped_ptr<GpuPlatformSupportHostGbm> gpu_platform_support_host_; |
184 | 167 |
185 DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm); | 168 DISALLOW_COPY_AND_ASSIGN(OzonePlatformGbm); |
186 }; | 169 }; |
187 | 170 |
188 } // namespace | 171 } // namespace |
189 | 172 |
190 OzonePlatform* CreateOzonePlatformGbm() { | 173 OzonePlatform* CreateOzonePlatformGbm() { |
191 return new OzonePlatformGbm(false); | 174 return new OzonePlatformGbm(false); |
192 } | 175 } |
193 OzonePlatform* CreateOzonePlatformGbmEglImage() { | 176 OzonePlatform* CreateOzonePlatformGbmEglImage() { |
194 return new OzonePlatformGbm(true); | 177 return new OzonePlatformGbm(true); |
195 } | 178 } |
196 | 179 |
197 } // namespace ui | 180 } // namespace ui |
OLD | NEW |