OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/wayland/wayland_display.h" | 5 #include "ui/ozone/platform/wayland/wayland_display.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "ui/ozone/platform/wayland/wayland_object.h" | 9 #include "ui/ozone/platform/wayland/wayland_object.h" |
10 #include "ui/ozone/platform/wayland/wayland_window.h" | 10 #include "ui/ozone/platform/wayland/wayland_window.h" |
11 | 11 |
12 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); | 12 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); |
13 | 13 |
14 namespace ui { | 14 namespace ui { |
15 namespace { | |
16 const uint32_t kMaxCompositorVersion = 4; | |
17 const uint32_t kMaxShmVersion = 1; | |
18 const uint32_t kMaxXdgShellVersion = 1; | |
19 } // namespace | |
15 | 20 |
16 WaylandDisplay::WaylandDisplay() {} | 21 WaylandDisplay::WaylandDisplay() {} |
17 | 22 |
18 WaylandDisplay::~WaylandDisplay() {} | 23 WaylandDisplay::~WaylandDisplay() {} |
19 | 24 |
20 bool WaylandDisplay::Initialize() { | 25 bool WaylandDisplay::Initialize() { |
21 static const wl_registry_listener registry_listener = { | 26 static const wl_registry_listener registry_listener = { |
22 &WaylandDisplay::Global, &WaylandDisplay::GlobalRemove, | 27 &WaylandDisplay::Global, &WaylandDisplay::GlobalRemove, |
23 }; | 28 }; |
24 | 29 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 wl_registry* registry, | 101 wl_registry* registry, |
97 uint32_t name, | 102 uint32_t name, |
98 const char* interface, | 103 const char* interface, |
99 uint32_t version) { | 104 uint32_t version) { |
100 static const xdg_shell_listener shell_listener = { | 105 static const xdg_shell_listener shell_listener = { |
101 &WaylandDisplay::Ping, | 106 &WaylandDisplay::Ping, |
102 }; | 107 }; |
103 | 108 |
104 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); | 109 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); |
105 if (!display->compositor_ && strcmp(interface, "wl_compositor") == 0) { | 110 if (!display->compositor_ && strcmp(interface, "wl_compositor") == 0) { |
106 display->compositor_ = wl::Bind<wl_compositor>(registry, name, version); | 111 display->compositor_ = wl::Bind<wl_compositor>( |
112 registry, name, std::min(version, kMaxCompositorVersion)); | |
spang
2016/02/17 23:25:03
Should
version < 4
be an error? Or is the code a
| |
107 if (!display->compositor_) | 113 if (!display->compositor_) |
108 LOG(ERROR) << "Failed to bind to wl_compositor global"; | 114 LOG(ERROR) << "Failed to bind to wl_compositor global"; |
109 } else if (!display->shm_ && strcmp(interface, "wl_shm") == 0) { | 115 } else if (!display->shm_ && strcmp(interface, "wl_shm") == 0) { |
110 display->shm_ = wl::Bind<wl_shm>(registry, name, version); | 116 display->shm_ = |
117 wl::Bind<wl_shm>(registry, name, std::min(version, kMaxShmVersion)); | |
111 if (!display->shm_) | 118 if (!display->shm_) |
112 LOG(ERROR) << "Failed to bind to wl_shm global"; | 119 LOG(ERROR) << "Failed to bind to wl_shm global"; |
113 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { | 120 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { |
114 display->shell_ = wl::Bind<xdg_shell>(registry, name, version); | 121 display->shell_ = wl::Bind<xdg_shell>( |
122 registry, name, std::min(version, kMaxXdgShellVersion)); | |
115 if (!display->shell_) { | 123 if (!display->shell_) { |
116 LOG(ERROR) << "Failed to bind to xdg_shell global"; | 124 LOG(ERROR) << "Failed to bind to xdg_shell global"; |
117 return; | 125 return; |
118 } | 126 } |
119 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); | 127 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); |
120 xdg_shell_use_unstable_version(display->shell_.get(), | 128 xdg_shell_use_unstable_version(display->shell_.get(), |
121 XDG_SHELL_VERSION_CURRENT); | 129 XDG_SHELL_VERSION_CURRENT); |
122 } | 130 } |
123 } | 131 } |
124 | 132 |
125 // static | 133 // static |
126 void WaylandDisplay::GlobalRemove(void* data, | 134 void WaylandDisplay::GlobalRemove(void* data, |
127 wl_registry* registry, | 135 wl_registry* registry, |
128 uint32_t name) { | 136 uint32_t name) { |
129 NOTIMPLEMENTED(); | 137 NOTIMPLEMENTED(); |
130 } | 138 } |
131 | 139 |
132 // static | 140 // static |
133 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { | 141 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { |
134 xdg_shell_pong(shell, serial); | 142 xdg_shell_pong(shell, serial); |
135 } | 143 } |
136 | 144 |
137 } // namespace ui | 145 } // namespace ui |
OLD | NEW |