Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ozone / platform / ozone_platform_wayland.cc
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.
4
5 #include "ozone/platform/ozone_platform_wayland.h"
6
7 #include "base/at_exit.h"
8 #include "base/bind.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"
12 #endif
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"
22
23
24 namespace ui {
25
26 namespace {
27
28 // OzonePlatform for Wayland
29 //
30 // This platform is Linux with the Wayland display server.
31 class OzonePlatformWayland : public OzonePlatform {
32  public:
33   OzonePlatformWayland() {
34     base::AtExitManager::RegisterTask(
35         base::Bind(&base::DeletePointer<OzonePlatformWayland>, this));
36   }
37
38   virtual ~OzonePlatformWayland() {
39   }
40
41   // OzonePlatform:
42   ui::SurfaceFactoryOzone* GetSurfaceFactoryOzone() override {
43     return wayland_display_.get();
44   }
45
46   CursorFactoryOzone* GetCursorFactoryOzone() override {
47     return cursor_factory_ozone_.get();
48   }
49
50   GpuPlatformSupportHost* GetGpuPlatformSupportHost() override {
51     return gpu_platform_host_.get();
52   }
53
54   GpuPlatformSupport* GetGpuPlatformSupport() override {
55     return gpu_platform_.get();
56   }
57
58   scoped_ptr<PlatformWindow> CreatePlatformWindow(
59       PlatformWindowDelegate* delegate,
60       const gfx::Rect& bounds) override {
61     if (delegate) {
62       return scoped_ptr<PlatformWindow>(new OzoneWaylandWindow(delegate,
63                                                                bounds));
64     } else {
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>();
69     }
70   }
71
72   scoped_ptr<NativeDisplayDelegate> CreateNativeDisplayDelegate() override {
73     return scoped_ptr<NativeDisplayDelegate>(new NativeDisplayDelegateOzone());
74   }
75
76   void InitializeUI() override {
77     event_factory_ozone_.reset(
78         new ui::EventFactoryOzoneWayland());
79
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());
86   }
87
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();
93     } else {
94     // TODO(kalyan): Find a better way to handle this.
95       gpu_platform_host_.get()->DeleteRemoteStateChangeHandler();
96     }
97
98     if (!wayland_display_)
99       wayland_display_.reset(new ozonewayland::WaylandDisplay());
100
101     if (!wayland_display_->InitializeHardware())
102       LOG(FATAL) << "failed to initialize display hardware";
103   }
104
105  private:
106 #if defined(TOOLKIT_VIEWS) && !defined(OS_CHROMEOS)
107   views::DesktopFactoryWayland desktop_factory_ozone_;
108 #endif
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);
116 };
117
118 }  // namespace
119
120 OzonePlatform* CreateOzonePlatformWayland() { return new OzonePlatformWayland; }
121
122 }  // namespace ui