1 // Copyright 2014 Intel Corporation. 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 "ozone/platform/ozone_platform_wayland.h"
7 #include "base/at_exit.h"
9 #include "ozone/ui/cursor/cursor_factory_ozone_wayland.h"
10 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS)
11 #include "ozone/ui/desktop_aura/desktop_factory_wayland.h"
13 #include "ozone/platform/ozone_wayland_window.h"
14 #include "ozone/ui/events/event_factory_ozone_wayland.h"
15 #include "ozone/ui/ime/input_method_context_factory_wayland.h"
16 #include "ozone/ui/public/ozone_channel.h"
17 #include "ozone/ui/public/ozone_channel_host.h"
18 #include "ozone/wayland/display.h"
19 #include "ui/ozone/common/native_display_delegate_ozone.h"
20 #include "ui/ozone/public/ozone_platform.h"
21 #include "ui/platform_window/platform_window_delegate.h"
28 // OzonePlatform for Wayland
30 // This platform is Linux with the Wayland display server.
31 class OzonePlatformWayland : public OzonePlatform {
33 OzonePlatformWayland() {
34 base::AtExitManager::RegisterTask(
35 base::Bind(&base::DeletePointer<OzonePlatformWayland>, this));
38 virtual ~OzonePlatformWayland() {
42 ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override {
43 return wayland_display_.get();
46 CursorFactoryOzone* GetCursorFactoryOzone() override {
47 return cursor_factory_ozone_.get();
50 GpuPlatformSupportHost* GetGpuPlatformSupportHost() override {
51 return gpu_platform_host_.get();
54 GpuPlatformSupport* GetGpuPlatformSupport() override {
55 return gpu_platform_.get();
58 scoped_ptr<PlatformWindow> CreatePlatformWindow(
59 PlatformWindowDelegate* delegate,
60 const gfx::Rect& bounds) override {
62 return scoped_ptr<PlatformWindow>(new OzoneWaylandWindow(delegate,
65 // This is a hack to ensure we have the correct screen bounds at startup.
66 // DesktopFactroyWayland makes this call.
67 wayland_display_->LookAheadOutputGeometry();
68 return scoped_ptr<PlatformWindow>();
72 scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() override {
73 return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateOzone());
76 void InitializeUI() override {
77 event_factory_ozone_.reset(
78 new ui::EventFactoryOzoneWayland());
80 gpu_platform_host_.reset(new ui::OzoneChannelHost());
81 // Needed as Browser creates accelerated widgets through SFO.
82 wayland_display_.reset(new ozonewayland::WaylandDisplay());
83 input_method_factory_.reset(
84 new ui::InputMethodContextFactoryWayland());
85 cursor_factory_ozone_.reset(new ui::CursorFactoryOzoneWayland());
88 void InitializeGPU() override {
89 gpu_platform_.reset(new ui::OzoneChannel());
90 if (!event_factory_ozone_) {
91 event_factory_ozone_.reset(new ui::EventFactoryOzoneWayland());
92 gpu_platform_.get()->InitializeRemoteDispatcher();
94 // TODO(kalyan): Find a better way to handle this.
95 gpu_platform_host_.get()->DeleteRemoteStateChangeHandler();
98 if (!wayland_display_)
99 wayland_display_.reset(new ozonewayland::WaylandDisplay());
101 if (!wayland_display_->InitializeHardware())
102 LOG(FATAL) << "failed to initialize display hardware";
106 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS)
107 views::DesktopFactoryWayland desktop_factory_ozone_;
109 scoped_ptr<ui::InputMethodContextFactoryWayland> input_method_factory_;
110 scoped_ptr<ui::EventFactoryOzoneWayland> event_factory_ozone_;
111 scoped_ptr<ui::CursorFactoryOzoneWayland> cursor_factory_ozone_;
112 scoped_ptr<ui::OzoneChannelHost> gpu_platform_host_;
113 scoped_ptr<ui::OzoneChannel> gpu_platform_;
114 scoped_ptr<ozonewayland::WaylandDisplay> wayland_display_;
115 DISALLOW_COPY_AND_ASSIGN(OzonePlatformWayland);
120 OzonePlatform* CreateOzonePlatformWayland() { return new OzonePlatformWayland; }