ozone: fix pointer size when crossing monitors with different scale factors
[chromium-blink-merge.git] / ui / ozone / platform / dri / ozone_platform_dri.cc
blob4a2be7ef4d5769649d191c1d842e934caa94b069
1 // Copyright 2013 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.
5 #include "ui/ozone/platform/dri/ozone_platform_dri.h"
7 #include "base/at_exit.h"
8 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h"
9 #include "ui/events/ozone/device/device_manager.h"
10 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
11 #include "ui/events/ozone/evdev/event_factory_evdev.h"
12 #include "ui/ozone/platform/dri/display_manager.h"
13 #include "ui/ozone/platform/dri/dri_buffer.h"
14 #include "ui/ozone/platform/dri/dri_cursor.h"
15 #include "ui/ozone/platform/dri/dri_gpu_platform_support.h"
16 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h"
17 #include "ui/ozone/platform/dri/dri_surface_factory.h"
18 #include "ui/ozone/platform/dri/dri_window.h"
19 #include "ui/ozone/platform/dri/dri_window_delegate_impl.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/native_display_delegate_dri.h"
24 #include "ui/ozone/platform/dri/native_display_delegate_proxy.h"
25 #include "ui/ozone/platform/dri/screen_manager.h"
26 #include "ui/ozone/public/ozone_platform.h"
27 #include "ui/ozone/public/ui_thread_gpu.h"
29 namespace ui {
31 namespace {
33 const char kDefaultGraphicsCardPath[] = "/dev/dri/card0";
35 // OzonePlatform for Linux DRI (Direct Rendering Infrastructure)
37 // This platform is Linux without any display server (no X, wayland, or
38 // anything). This means chrome alone owns the display and input devices.
39 class OzonePlatformDri : public OzonePlatform {
40 public:
41 OzonePlatformDri()
42 : dri_(new DriWrapper(kDefaultGraphicsCardPath)),
43 buffer_generator_(new DriBufferGenerator(dri_.get())),
44 screen_manager_(new ScreenManager(dri_.get(), buffer_generator_.get())),
45 device_manager_(CreateDeviceManager()) {
46 base::AtExitManager::RegisterTask(
47 base::Bind(&base::DeletePointer<OzonePlatformDri>, this));
49 ~OzonePlatformDri() override {}
51 // OzonePlatform:
52 ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override {
53 return surface_factory_ozone_.get();
55 CursorFactoryOzone* GetCursorFactoryOzone() override {
56 return cursor_factory_ozone_.get();
58 GpuPlatformSupport* GetGpuPlatformSupport() override {
59 return gpu_platform_support_.get();
61 GpuPlatformSupportHost* GetGpuPlatformSupportHost() override {
62 return gpu_platform_support_host_.get();
64 scoped_ptr<SystemInputInjector> CreateSystemInputInjector() override {
65 return event_factory_ozone_->CreateSystemInputInjector();
67 scoped_ptr<PlatformWindow> CreatePlatformWindow(
68 PlatformWindowDelegate* delegate,
69 const gfx::Rect& bounds) override {
70 scoped_ptr<DriWindow> platform_window(
71 new DriWindow(delegate, bounds, gpu_platform_support_host_.get(),
72 event_factory_ozone_.get(), window_manager_.get(),
73 display_manager_.get()));
74 platform_window->Initialize();
75 return platform_window.Pass();
77 scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() override {
78 return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateProxy(
79 gpu_platform_support_host_.get(), device_manager_.get(),
80 display_manager_.get()));
82 void InitializeUI() override {
83 dri_->Initialize();
84 display_manager_.reset(new DisplayManager());
85 surface_factory_ozone_.reset(
86 new DriSurfaceFactory(dri_.get(), &window_delegate_manager_));
87 gpu_platform_support_.reset(new DriGpuPlatformSupport(
88 dri_.get(), &window_delegate_manager_, screen_manager_.get(),
89 scoped_ptr<NativeDisplayDelegateDri>(new NativeDisplayDelegateDri(
90 dri_.get(), screen_manager_.get(), NULL))));
91 gpu_platform_support_host_.reset(new DriGpuPlatformSupportHost());
92 cursor_factory_ozone_.reset(new BitmapCursorFactoryOzone);
93 window_manager_.reset(
94 new DriWindowManager(gpu_platform_support_host_.get()));
95 event_factory_ozone_.reset(new EventFactoryEvdev(window_manager_->cursor(),
96 device_manager_.get()));
97 if (surface_factory_ozone_->InitializeHardware() !=
98 DriSurfaceFactory::INITIALIZED)
99 LOG(FATAL) << "Failed to initialize display hardware.";
101 if (!ui_thread_gpu_.Initialize())
102 LOG(FATAL) << "Failed to initialize dummy channel.";
105 void InitializeGPU() override {}
107 private:
108 scoped_ptr<DriWrapper> dri_;
109 scoped_ptr<DriBufferGenerator> buffer_generator_;
110 scoped_ptr<ScreenManager> screen_manager_;
111 scoped_ptr<DeviceManager> device_manager_;
113 scoped_ptr<DriSurfaceFactory> surface_factory_ozone_;
114 scoped_ptr<BitmapCursorFactoryOzone> cursor_factory_ozone_;
115 scoped_ptr<EventFactoryEvdev> event_factory_ozone_;
117 scoped_ptr<DriWindowManager> window_manager_;
118 scoped_ptr<DisplayManager> display_manager_;
120 scoped_ptr<DriGpuPlatformSupport> gpu_platform_support_;
121 scoped_ptr<DriGpuPlatformSupportHost> gpu_platform_support_host_;
123 DriWindowDelegateManager window_delegate_manager_;
125 UiThreadGpu ui_thread_gpu_;
127 DISALLOW_COPY_AND_ASSIGN(OzonePlatformDri);
130 } // namespace
132 OzonePlatform* CreateOzonePlatformDri() { return new OzonePlatformDri; }
134 } // namespace ui