Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ozone / wayland / shell / shell.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/wayland/shell/shell.h"
6
7 #include "base/logging.h"
8 #include "ozone/wayland/display.h"
9 #include "ozone/wayland/shell/ivi-application-client-protocol.h"
10 #include "ozone/wayland/shell/ivi_shell_surface.h"
11 #include "ozone/wayland/shell/wl_shell_surface.h"
12 #include "ozone/wayland/shell/xdg-shell-client-protocol.h"
13 #include "ozone/wayland/shell/xdg_shell_surface.h"
14
15 namespace ozonewayland {
16
17 WaylandShell::WaylandShell()
18     : shell_(NULL),
19       xdg_shell_(NULL),
20       ivi_application_(NULL) {
21 }
22
23 WaylandShell::~WaylandShell() {
24   if (shell_)
25     wl_shell_destroy(shell_);
26   if (xdg_shell_)
27     xdg_shell_destroy(xdg_shell_);
28   if (ivi_application_)
29     ivi_application_destroy(ivi_application_);
30 }
31
32 WaylandShellSurface*
33 WaylandShell::CreateShellSurface(WaylandWindow* window,
34                                  WaylandWindow::ShellType type) {
35   DCHECK(shell_ || xdg_shell_ || ivi_application_);
36   WaylandDisplay* display = WaylandDisplay::GetInstance();
37   DCHECK(display);
38   WaylandShellSurface* surface = NULL;
39   if (ivi_application_)
40     surface = new IVIShellSurface();
41   if (xdg_shell_)
42     surface = new XDGShellSurface();
43   if (!surface)
44     surface = new WLShellSurface();
45
46   DCHECK(surface);
47   surface->InitializeShellSurface(window, type);
48   wl_surface_set_user_data(surface->GetWLSurface(), window);
49   display->FlushDisplay();
50
51   return surface;
52 }
53
54 void WaylandShell::Initialize(struct wl_registry *registry,
55                               uint32_t name,
56                               const char *interface,
57                               uint32_t version) {
58   if (strcmp(interface, "wl_shell") == 0) {
59     DCHECK(!shell_);
60     shell_ = static_cast<wl_shell*>(
61         wl_registry_bind(registry, name, &wl_shell_interface, 1));
62   } else if ((strcmp(interface, "xdg_shell") == 0) &&
63                 getenv("OZONE_WAYLAND_USE_XDG_SHELL")) {
64       DCHECK(!xdg_shell_);
65       xdg_shell_ = static_cast<xdg_shell*>(
66           wl_registry_bind(registry, name, &xdg_shell_interface, 1));
67       xdg_shell_use_unstable_version(xdg_shell_, XDG_SHELL_VERSION_CURRENT);
68
69       static const xdg_shell_listener xdg_shell_listener = {
70         WaylandShell::XDGHandlePing
71       };
72       xdg_shell_add_listener(xdg_shell_, &xdg_shell_listener, NULL);
73   } else if (strcmp(interface, "ivi_application") == 0) {
74       DCHECK(!ivi_application_);
75       ivi_application_ = static_cast<ivi_application*>(
76           wl_registry_bind(registry, name, &ivi_application_interface, 1));
77   }
78 }
79
80 void WaylandShell::XDGHandlePing(void* data,
81                                  struct xdg_shell* xdg_shell,
82                                  uint32_t serial) {
83   xdg_shell_pong(xdg_shell, serial);
84 }
85
86 }  // namespace ozonewayland