| 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 "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" | 14 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" |
| 15 #include "ui/events/ozone/device/device_manager.h" | 15 #include "ui/events/ozone/device/device_manager.h" |
| 16 #include "ui/events/ozone/evdev/event_factory_evdev.h" | 16 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
| 17 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | 17 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
| 18 #include "ui/ozone/platform/dri/display_manager.h" | 18 #include "ui/ozone/platform/dri/display_manager.h" |
| 19 #include "ui/ozone/platform/dri/dri_cursor.h" | 19 #include "ui/ozone/platform/dri/dri_cursor.h" |
| 20 #include "ui/ozone/platform/dri/dri_gpu_platform_support.h" | 20 #include "ui/ozone/platform/dri/dri_gpu_platform_support.h" |
| 21 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h" | 21 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h" |
| 22 #include "ui/ozone/platform/dri/dri_window.h" | 22 #include "ui/ozone/platform/dri/dri_window.h" |
| 23 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" | 23 #include "ui/ozone/platform/dri/dri_window_delegate_manager.h" |
| 24 #include "ui/ozone/platform/dri/dri_window_manager.h" | 24 #include "ui/ozone/platform/dri/dri_window_manager.h" |
| 25 #include "ui/ozone/platform/dri/dri_wrapper.h" | |
| 26 #include "ui/ozone/platform/dri/gbm_buffer.h" | 25 #include "ui/ozone/platform/dri/gbm_buffer.h" |
| 27 #include "ui/ozone/platform/dri/gbm_surface.h" | 26 #include "ui/ozone/platform/dri/gbm_surface.h" |
| 28 #include "ui/ozone/platform/dri/gbm_surface_factory.h" | 27 #include "ui/ozone/platform/dri/gbm_surface_factory.h" |
| 28 #include "ui/ozone/platform/dri/gbm_wrapper.h" |
| 29 #include "ui/ozone/platform/dri/native_display_delegate_dri.h" | 29 #include "ui/ozone/platform/dri/native_display_delegate_dri.h" |
| 30 #include "ui/ozone/platform/dri/native_display_delegate_proxy.h" | 30 #include "ui/ozone/platform/dri/native_display_delegate_proxy.h" |
| 31 #include "ui/ozone/platform/dri/scanout_buffer.h" | 31 #include "ui/ozone/platform/dri/scanout_buffer.h" |
| 32 #include "ui/ozone/platform/dri/screen_manager.h" | 32 #include "ui/ozone/platform/dri/screen_manager.h" |
| 33 #include "ui/ozone/public/cursor_factory_ozone.h" | 33 #include "ui/ozone/public/cursor_factory_ozone.h" |
| 34 #include "ui/ozone/public/gpu_platform_support.h" | 34 #include "ui/ozone/public/gpu_platform_support.h" |
| 35 #include "ui/ozone/public/gpu_platform_support_host.h" | 35 #include "ui/ozone/public/gpu_platform_support_host.h" |
| 36 #include "ui/ozone/public/ozone_platform.h" | 36 #include "ui/ozone/public/ozone_platform.h" |
| 37 #include "ui/ozone/public/ozone_switches.h" | 37 #include "ui/ozone/public/ozone_switches.h" |
| 38 | 38 |
| 39 #if defined(USE_XKBCOMMON) | 39 #if defined(USE_XKBCOMMON) |
| 40 #include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h" | 40 #include "ui/events/ozone/layout/xkb/xkb_evdev_codes.h" |
| 41 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" | 41 #include "ui/events/ozone/layout/xkb/xkb_keyboard_layout_engine.h" |
| 42 #else | 42 #else |
| 43 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" | 43 #include "ui/events/ozone/layout/stub/stub_keyboard_layout_engine.h" |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 namespace ui { | 46 namespace ui { |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 const char kDefaultGraphicsCardPath[] = "/dev/dri/card0"; | 50 const char kDefaultGraphicsCardPath[] = "/dev/dri/card0"; |
| 51 | 51 |
| 52 class GbmBufferGenerator : public ScanoutBufferGenerator { | 52 class GlApiLoader { |
| 53 public: | 53 public: |
| 54 GbmBufferGenerator(DriWrapper* dri) | 54 GlApiLoader() |
| 55 : glapi_lib_(dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL)), | 55 : glapi_lib_(dlopen("libglapi.so.0", RTLD_LAZY | RTLD_GLOBAL)) {} |
| 56 device_(gbm_create_device(dri->get_fd())) { | 56 |
| 57 if (!device_) | 57 ~GlApiLoader() { |
| 58 LOG(FATAL) << "Unable to initialize gbm for " << kDefaultGraphicsCardPath; | |
| 59 } | |
| 60 virtual ~GbmBufferGenerator() { | |
| 61 gbm_device_destroy(device_); | |
| 62 if (glapi_lib_) | 58 if (glapi_lib_) |
| 63 dlclose(glapi_lib_); | 59 dlclose(glapi_lib_); |
| 64 } | 60 } |
| 65 | 61 |
| 66 gbm_device* device() const { return device_; } | 62 private: |
| 63 // HACK: gbm drivers have broken linkage. The Mesa DRI driver references |
| 64 // symbols in the libglapi library however it does not explicitly link against |
| 65 // it. That caused linkage errors when running an application that does not |
| 66 // explicitly link against libglapi. |
| 67 void* glapi_lib_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(GlApiLoader); |
| 70 }; |
| 71 |
| 72 class GbmBufferGenerator : public ScanoutBufferGenerator { |
| 73 public: |
| 74 GbmBufferGenerator() {} |
| 75 ~GbmBufferGenerator() override {} |
| 67 | 76 |
| 68 scoped_refptr<ScanoutBuffer> Create(DriWrapper* drm, | 77 scoped_refptr<ScanoutBuffer> Create(DriWrapper* drm, |
| 69 const gfx::Size& size) override { | 78 const gfx::Size& size) override { |
| 70 return GbmBuffer::CreateBuffer(drm, device_, SurfaceFactoryOzone::RGBA_8888, | 79 return GbmBuffer::CreateBuffer(static_cast<GbmWrapper*>(drm), |
| 71 size, true); | 80 SurfaceFactoryOzone::RGBA_8888, size, true); |
| 72 } | 81 } |
| 73 | 82 |
| 74 protected: | 83 protected: |
| 75 // HACK: gbm drivers have broken linkage | |
| 76 void* glapi_lib_; | |
| 77 | |
| 78 gbm_device* device_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator); | 84 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator); |
| 81 }; | 85 }; |
| 82 | 86 |
| 83 class OzonePlatformGbm : public OzonePlatform { | 87 class OzonePlatformGbm : public OzonePlatform { |
| 84 public: | 88 public: |
| 85 OzonePlatformGbm(bool use_surfaceless) : use_surfaceless_(use_surfaceless) { | 89 OzonePlatformGbm(bool use_surfaceless) : use_surfaceless_(use_surfaceless) { |
| 86 } | 90 } |
| 87 ~OzonePlatformGbm() override {} | 91 ~OzonePlatformGbm() override {} |
| 88 | 92 |
| 89 // OzonePlatform: | 93 // OzonePlatform: |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 #else | 143 #else |
| 140 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( | 144 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( |
| 141 make_scoped_ptr(new StubKeyboardLayoutEngine())); | 145 make_scoped_ptr(new StubKeyboardLayoutEngine())); |
| 142 #endif | 146 #endif |
| 143 event_factory_ozone_.reset(new EventFactoryEvdev( | 147 event_factory_ozone_.reset(new EventFactoryEvdev( |
| 144 cursor_.get(), device_manager_.get(), | 148 cursor_.get(), device_manager_.get(), |
| 145 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine())); | 149 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine())); |
| 146 } | 150 } |
| 147 | 151 |
| 148 void InitializeGPU() override { | 152 void InitializeGPU() override { |
| 153 gl_api_loader_.reset(new GlApiLoader()); |
| 149 // Async page flips are supported only on surfaceless mode. | 154 // Async page flips are supported only on surfaceless mode. |
| 150 dri_.reset(new DriWrapper(kDefaultGraphicsCardPath, !use_surfaceless_)); | 155 gbm_.reset(new GbmWrapper(kDefaultGraphicsCardPath, !use_surfaceless_)); |
| 151 dri_->Initialize(); | 156 gbm_->Initialize(); |
| 152 buffer_generator_.reset(new GbmBufferGenerator(dri_.get())); | 157 buffer_generator_.reset(new GbmBufferGenerator()); |
| 153 screen_manager_.reset( | 158 screen_manager_.reset( |
| 154 new ScreenManager(dri_.get(), buffer_generator_.get())); | 159 new ScreenManager(gbm_.get(), buffer_generator_.get())); |
| 155 window_delegate_manager_.reset(new DriWindowDelegateManager()); | 160 window_delegate_manager_.reset(new DriWindowDelegateManager()); |
| 156 if (!surface_factory_ozone_) | 161 if (!surface_factory_ozone_) |
| 157 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_)); | 162 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_)); |
| 158 | 163 |
| 159 surface_factory_ozone_->InitializeGpu( | 164 surface_factory_ozone_->InitializeGpu(gbm_.get(), screen_manager_.get(), |
| 160 dri_.get(), buffer_generator_->device(), screen_manager_.get(), | 165 window_delegate_manager_.get()); |
| 161 window_delegate_manager_.get()); | |
| 162 scoped_ptr<NativeDisplayDelegateDri> ndd( | 166 scoped_ptr<NativeDisplayDelegateDri> ndd( |
| 163 new NativeDisplayDelegateDri(dri_.get(), screen_manager_.get())); | 167 new NativeDisplayDelegateDri(gbm_.get(), screen_manager_.get())); |
| 164 ndd->Initialize(); | 168 ndd->Initialize(); |
| 165 gpu_platform_support_.reset( | 169 gpu_platform_support_.reset( |
| 166 new DriGpuPlatformSupport(dri_.get(), window_delegate_manager_.get(), | 170 new DriGpuPlatformSupport(gbm_.get(), window_delegate_manager_.get(), |
| 167 screen_manager_.get(), ndd.Pass())); | 171 screen_manager_.get(), ndd.Pass())); |
| 168 } | 172 } |
| 169 | 173 |
| 170 private: | 174 private: |
| 171 bool use_surfaceless_; | 175 bool use_surfaceless_; |
| 172 scoped_ptr<DriWrapper> dri_; | 176 scoped_ptr<GlApiLoader> gl_api_loader_; |
| 177 scoped_ptr<GbmWrapper> gbm_; |
| 173 scoped_ptr<GbmBufferGenerator> buffer_generator_; | 178 scoped_ptr<GbmBufferGenerator> buffer_generator_; |
| 174 scoped_ptr<ScreenManager> screen_manager_; | 179 scoped_ptr<ScreenManager> screen_manager_; |
| 175 scoped_ptr<DeviceManager> device_manager_; | 180 scoped_ptr<DeviceManager> device_manager_; |
| 176 | 181 |
| 177 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_; | 182 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_; |
| 178 scoped_ptr<BitmapCursorFactoryOzone> cursor_factory_ozone_; | 183 scoped_ptr<BitmapCursorFactoryOzone> cursor_factory_ozone_; |
| 179 scoped_ptr<EventFactoryEvdev> event_factory_ozone_; | 184 scoped_ptr<EventFactoryEvdev> event_factory_ozone_; |
| 180 | 185 |
| 181 scoped_ptr<DriGpuPlatformSupport> gpu_platform_support_; | 186 scoped_ptr<DriGpuPlatformSupport> gpu_platform_support_; |
| 182 scoped_ptr<DriGpuPlatformSupportHost> gpu_platform_support_host_; | 187 scoped_ptr<DriGpuPlatformSupportHost> gpu_platform_support_host_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 195 }; | 200 }; |
| 196 | 201 |
| 197 } // namespace | 202 } // namespace |
| 198 | 203 |
| 199 OzonePlatform* CreateOzonePlatformGbm() { | 204 OzonePlatform* CreateOzonePlatformGbm() { |
| 200 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | 205 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 201 return new OzonePlatformGbm(cmd->HasSwitch(switches::kOzoneUseSurfaceless)); | 206 return new OzonePlatformGbm(cmd->HasSwitch(switches::kOzoneUseSurfaceless)); |
| 202 } | 207 } |
| 203 | 208 |
| 204 } // namespace ui | 209 } // namespace ui |
| OLD | NEW |