Chromium Code Reviews| 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 | |
|
alexst (slow to review)
2015/01/21 22:35:40
Period at the end of the sentence, and please expl
dnicoara
2015/01/21 22:51:13
Done.
| |
| 64 void* glapi_lib_; | |
| 65 | |
| 66 DISALLOW_COPY_AND_ASSIGN(GlApiLoader); | |
| 67 }; | |
| 68 | |
| 69 class GbmBufferGenerator : public ScanoutBufferGenerator { | |
| 70 public: | |
| 71 GbmBufferGenerator() {} | |
| 72 ~GbmBufferGenerator() override {} | |
| 67 | 73 |
| 68 scoped_refptr<ScanoutBuffer> Create(DriWrapper* drm, | 74 scoped_refptr<ScanoutBuffer> Create(DriWrapper* drm, |
| 69 const gfx::Size& size) override { | 75 const gfx::Size& size) override { |
| 70 return GbmBuffer::CreateBuffer(drm, device_, SurfaceFactoryOzone::RGBA_8888, | 76 return GbmBuffer::CreateBuffer(static_cast<GbmWrapper*>(drm), |
| 71 size, true); | 77 SurfaceFactoryOzone::RGBA_8888, size, true); |
| 72 } | 78 } |
| 73 | 79 |
| 74 protected: | 80 protected: |
| 75 // HACK: gbm drivers have broken linkage | |
| 76 void* glapi_lib_; | |
| 77 | |
| 78 gbm_device* device_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator); | 81 DISALLOW_COPY_AND_ASSIGN(GbmBufferGenerator); |
| 81 }; | 82 }; |
| 82 | 83 |
| 83 class OzonePlatformGbm : public OzonePlatform { | 84 class OzonePlatformGbm : public OzonePlatform { |
| 84 public: | 85 public: |
| 85 OzonePlatformGbm(bool use_surfaceless) : use_surfaceless_(use_surfaceless) { | 86 OzonePlatformGbm(bool use_surfaceless) : use_surfaceless_(use_surfaceless) { |
| 86 } | 87 } |
| 87 ~OzonePlatformGbm() override {} | 88 ~OzonePlatformGbm() override {} |
| 88 | 89 |
| 89 // OzonePlatform: | 90 // OzonePlatform: |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 #else | 140 #else |
| 140 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( | 141 KeyboardLayoutEngineManager::SetKeyboardLayoutEngine( |
| 141 make_scoped_ptr(new StubKeyboardLayoutEngine())); | 142 make_scoped_ptr(new StubKeyboardLayoutEngine())); |
| 142 #endif | 143 #endif |
| 143 event_factory_ozone_.reset(new EventFactoryEvdev( | 144 event_factory_ozone_.reset(new EventFactoryEvdev( |
| 144 cursor_.get(), device_manager_.get(), | 145 cursor_.get(), device_manager_.get(), |
| 145 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine())); | 146 KeyboardLayoutEngineManager::GetKeyboardLayoutEngine())); |
| 146 } | 147 } |
| 147 | 148 |
| 148 void InitializeGPU() override { | 149 void InitializeGPU() override { |
| 150 gl_api_loader_.reset(new GlApiLoader()); | |
| 149 // Async page flips are supported only on surfaceless mode. | 151 // Async page flips are supported only on surfaceless mode. |
| 150 dri_.reset(new DriWrapper(kDefaultGraphicsCardPath, !use_surfaceless_)); | 152 gbm_.reset(new GbmWrapper(kDefaultGraphicsCardPath, !use_surfaceless_)); |
| 151 dri_->Initialize(); | 153 gbm_->Initialize(); |
| 152 buffer_generator_.reset(new GbmBufferGenerator(dri_.get())); | 154 buffer_generator_.reset(new GbmBufferGenerator()); |
| 153 screen_manager_.reset( | 155 screen_manager_.reset( |
| 154 new ScreenManager(dri_.get(), buffer_generator_.get())); | 156 new ScreenManager(gbm_.get(), buffer_generator_.get())); |
| 155 window_delegate_manager_.reset(new DriWindowDelegateManager()); | 157 window_delegate_manager_.reset(new DriWindowDelegateManager()); |
| 156 if (!surface_factory_ozone_) | 158 if (!surface_factory_ozone_) |
| 157 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_)); | 159 surface_factory_ozone_.reset(new GbmSurfaceFactory(use_surfaceless_)); |
| 158 | 160 |
| 159 surface_factory_ozone_->InitializeGpu( | 161 surface_factory_ozone_->InitializeGpu(gbm_.get(), screen_manager_.get(), |
| 160 dri_.get(), buffer_generator_->device(), screen_manager_.get(), | 162 window_delegate_manager_.get()); |
| 161 window_delegate_manager_.get()); | |
| 162 scoped_ptr<NativeDisplayDelegateDri> ndd( | 163 scoped_ptr<NativeDisplayDelegateDri> ndd( |
| 163 new NativeDisplayDelegateDri(dri_.get(), screen_manager_.get())); | 164 new NativeDisplayDelegateDri(gbm_.get(), screen_manager_.get())); |
| 164 ndd->Initialize(); | 165 ndd->Initialize(); |
| 165 gpu_platform_support_.reset( | 166 gpu_platform_support_.reset( |
| 166 new DriGpuPlatformSupport(dri_.get(), window_delegate_manager_.get(), | 167 new DriGpuPlatformSupport(gbm_.get(), window_delegate_manager_.get(), |
| 167 screen_manager_.get(), ndd.Pass())); | 168 screen_manager_.get(), ndd.Pass())); |
| 168 } | 169 } |
| 169 | 170 |
| 170 private: | 171 private: |
| 171 bool use_surfaceless_; | 172 bool use_surfaceless_; |
| 172 scoped_ptr<DriWrapper> dri_; | 173 scoped_ptr<GlApiLoader> gl_api_loader_; |
| 174 scoped_ptr<GbmWrapper> gbm_; | |
| 173 scoped_ptr<GbmBufferGenerator> buffer_generator_; | 175 scoped_ptr<GbmBufferGenerator> buffer_generator_; |
| 174 scoped_ptr<ScreenManager> screen_manager_; | 176 scoped_ptr<ScreenManager> screen_manager_; |
| 175 scoped_ptr<DeviceManager> device_manager_; | 177 scoped_ptr<DeviceManager> device_manager_; |
| 176 | 178 |
| 177 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_; | 179 scoped_ptr<GbmSurfaceFactory> surface_factory_ozone_; |
| 178 scoped_ptr<BitmapCursorFactoryOzone> cursor_factory_ozone_; | 180 scoped_ptr<BitmapCursorFactoryOzone> cursor_factory_ozone_; |
| 179 scoped_ptr<EventFactoryEvdev> event_factory_ozone_; | 181 scoped_ptr<EventFactoryEvdev> event_factory_ozone_; |
| 180 | 182 |
| 181 scoped_ptr<DriGpuPlatformSupport> gpu_platform_support_; | 183 scoped_ptr<DriGpuPlatformSupport> gpu_platform_support_; |
| 182 scoped_ptr<DriGpuPlatformSupportHost> gpu_platform_support_host_; | 184 scoped_ptr<DriGpuPlatformSupportHost> gpu_platform_support_host_; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 195 }; | 197 }; |
| 196 | 198 |
| 197 } // namespace | 199 } // namespace |
| 198 | 200 |
| 199 OzonePlatform* CreateOzonePlatformGbm() { | 201 OzonePlatform* CreateOzonePlatformGbm() { |
| 200 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); | 202 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); |
| 201 return new OzonePlatformGbm(cmd->HasSwitch(switches::kOzoneUseSurfaceless)); | 203 return new OzonePlatformGbm(cmd->HasSwitch(switches::kOzoneUseSurfaceless)); |
| 202 } | 204 } |
| 203 | 205 |
| 204 } // namespace ui | 206 } // namespace ui |
| OLD | NEW |