| 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 <xdg-shell-unstable-v5-client-protocol.h> | 7 #include <xdg-shell-unstable-v5-client-protocol.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "ui/ozone/platform/wayland/wayland_object.h" | 12 #include "ui/ozone/platform/wayland/wayland_object.h" |
| 13 #include "ui/ozone/platform/wayland/wayland_window.h" | 13 #include "ui/ozone/platform/wayland/wayland_window.h" |
| 14 | 14 |
| 15 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); | 15 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); |
| 16 | 16 |
| 17 namespace ui { | 17 namespace ui { |
| 18 namespace { | 18 namespace { |
| 19 const uint32_t kMaxCompositorVersion = 4; | 19 const uint32_t kMaxCompositorVersion = 4; |
| 20 const uint32_t kMaxSeatVersion = 4; |
| 20 const uint32_t kMaxShmVersion = 1; | 21 const uint32_t kMaxShmVersion = 1; |
| 21 const uint32_t kMaxXdgShellVersion = 1; | 22 const uint32_t kMaxXdgShellVersion = 1; |
| 22 } // namespace | 23 } // namespace |
| 23 | 24 |
| 24 WaylandDisplay::WaylandDisplay() {} | 25 WaylandDisplay::WaylandDisplay() {} |
| 25 | 26 |
| 26 WaylandDisplay::~WaylandDisplay() {} | 27 WaylandDisplay::~WaylandDisplay() {} |
| 27 | 28 |
| 28 bool WaylandDisplay::Initialize() { | 29 bool WaylandDisplay::Initialize() { |
| 29 static const wl_registry_listener registry_listener = { | 30 static const wl_registry_listener registry_listener = { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 wl_display_roundtrip(display_.get()); | 47 wl_display_roundtrip(display_.get()); |
| 47 | 48 |
| 48 if (!compositor_) { | 49 if (!compositor_) { |
| 49 LOG(ERROR) << "No wl_compositor object"; | 50 LOG(ERROR) << "No wl_compositor object"; |
| 50 return false; | 51 return false; |
| 51 } | 52 } |
| 52 if (!shm_) { | 53 if (!shm_) { |
| 53 LOG(ERROR) << "No wl_shm object"; | 54 LOG(ERROR) << "No wl_shm object"; |
| 54 return false; | 55 return false; |
| 55 } | 56 } |
| 57 if (!seat_) { |
| 58 LOG(ERROR) << "No wl_seat object"; |
| 59 return false; |
| 60 } |
| 56 if (!shell_) { | 61 if (!shell_) { |
| 57 LOG(ERROR) << "No xdg_shell object"; | 62 LOG(ERROR) << "No xdg_shell object"; |
| 58 return false; | 63 return false; |
| 59 } | 64 } |
| 60 | 65 |
| 61 return true; | 66 return true; |
| 62 } | 67 } |
| 63 | 68 |
| 64 bool WaylandDisplay::StartProcessingEvents() { | 69 bool WaylandDisplay::StartProcessingEvents() { |
| 65 if (watching_) | 70 if (watching_) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 107 |
| 103 void WaylandDisplay::OnDispatcherListChanged() { | 108 void WaylandDisplay::OnDispatcherListChanged() { |
| 104 StartProcessingEvents(); | 109 StartProcessingEvents(); |
| 105 } | 110 } |
| 106 | 111 |
| 107 void WaylandDisplay::Flush() { | 112 void WaylandDisplay::Flush() { |
| 108 wl_display_flush(display_.get()); | 113 wl_display_flush(display_.get()); |
| 109 scheduled_flush_ = false; | 114 scheduled_flush_ = false; |
| 110 } | 115 } |
| 111 | 116 |
| 117 void WaylandDisplay::DispatchUiEvent(Event* event) { |
| 118 PlatformEventSource::DispatchEvent(event); |
| 119 } |
| 120 |
| 112 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) { | 121 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) { |
| 113 wl_display_dispatch(display_.get()); | 122 wl_display_dispatch(display_.get()); |
| 114 for (const auto& window : window_map_) | 123 for (const auto& window : window_map_) |
| 115 window.second->ApplyPendingBounds(); | 124 window.second->ApplyPendingBounds(); |
| 116 } | 125 } |
| 117 | 126 |
| 118 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {} | 127 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {} |
| 119 | 128 |
| 120 // static | 129 // static |
| 121 void WaylandDisplay::Global(void* data, | 130 void WaylandDisplay::Global(void* data, |
| 122 wl_registry* registry, | 131 wl_registry* registry, |
| 123 uint32_t name, | 132 uint32_t name, |
| 124 const char* interface, | 133 const char* interface, |
| 125 uint32_t version) { | 134 uint32_t version) { |
| 135 static const wl_seat_listener seat_listener = { |
| 136 &WaylandDisplay::Capabilities, &WaylandDisplay::Name, |
| 137 }; |
| 126 static const xdg_shell_listener shell_listener = { | 138 static const xdg_shell_listener shell_listener = { |
| 127 &WaylandDisplay::Ping, | 139 &WaylandDisplay::Ping, |
| 128 }; | 140 }; |
| 129 | 141 |
| 130 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); | 142 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); |
| 131 if (!display->compositor_ && strcmp(interface, "wl_compositor") == 0) { | 143 if (!display->compositor_ && strcmp(interface, "wl_compositor") == 0) { |
| 132 display->compositor_ = wl::Bind<wl_compositor>( | 144 display->compositor_ = wl::Bind<wl_compositor>( |
| 133 registry, name, std::min(version, kMaxCompositorVersion)); | 145 registry, name, std::min(version, kMaxCompositorVersion)); |
| 134 if (!display->compositor_) | 146 if (!display->compositor_) |
| 135 LOG(ERROR) << "Failed to bind to wl_compositor global"; | 147 LOG(ERROR) << "Failed to bind to wl_compositor global"; |
| 136 } else if (!display->shm_ && strcmp(interface, "wl_shm") == 0) { | 148 } else if (!display->shm_ && strcmp(interface, "wl_shm") == 0) { |
| 137 display->shm_ = | 149 display->shm_ = |
| 138 wl::Bind<wl_shm>(registry, name, std::min(version, kMaxShmVersion)); | 150 wl::Bind<wl_shm>(registry, name, std::min(version, kMaxShmVersion)); |
| 139 if (!display->shm_) | 151 if (!display->shm_) |
| 140 LOG(ERROR) << "Failed to bind to wl_shm global"; | 152 LOG(ERROR) << "Failed to bind to wl_shm global"; |
| 153 } else if (!display->seat_ && strcmp(interface, "wl_seat") == 0) { |
| 154 display->seat_ = |
| 155 wl::Bind<wl_seat>(registry, name, std::min(version, kMaxSeatVersion)); |
| 156 if (!display->seat_) { |
| 157 LOG(ERROR) << "Failed to bind to wl_seat global"; |
| 158 return; |
| 159 } |
| 160 wl_seat_add_listener(display->seat_.get(), &seat_listener, display); |
| 141 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { | 161 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { |
| 142 display->shell_ = wl::Bind<xdg_shell>( | 162 display->shell_ = wl::Bind<xdg_shell>( |
| 143 registry, name, std::min(version, kMaxXdgShellVersion)); | 163 registry, name, std::min(version, kMaxXdgShellVersion)); |
| 144 if (!display->shell_) { | 164 if (!display->shell_) { |
| 145 LOG(ERROR) << "Failed to bind to xdg_shell global"; | 165 LOG(ERROR) << "Failed to bind to xdg_shell global"; |
| 146 return; | 166 return; |
| 147 } | 167 } |
| 148 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); | 168 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); |
| 149 xdg_shell_use_unstable_version(display->shell_.get(), | 169 xdg_shell_use_unstable_version(display->shell_.get(), |
| 150 XDG_SHELL_VERSION_CURRENT); | 170 XDG_SHELL_VERSION_CURRENT); |
| 151 } | 171 } |
| 152 | 172 |
| 153 display->ScheduleFlush(); | 173 display->ScheduleFlush(); |
| 154 } | 174 } |
| 155 | 175 |
| 156 // static | 176 // static |
| 157 void WaylandDisplay::GlobalRemove(void* data, | 177 void WaylandDisplay::GlobalRemove(void* data, |
| 158 wl_registry* registry, | 178 wl_registry* registry, |
| 159 uint32_t name) { | 179 uint32_t name) { |
| 160 NOTIMPLEMENTED(); | 180 NOTIMPLEMENTED(); |
| 161 } | 181 } |
| 162 | 182 |
| 163 // static | 183 // static |
| 184 void WaylandDisplay::Capabilities(void* data, |
| 185 wl_seat* seat, |
| 186 uint32_t capabilities) { |
| 187 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); |
| 188 if (capabilities & WL_SEAT_CAPABILITY_POINTER) { |
| 189 if (!display->pointer_) { |
| 190 wl_pointer* pointer = wl_seat_get_pointer(display->seat_.get()); |
| 191 if (!pointer) { |
| 192 LOG(ERROR) << "Failed to get wl_pointer from seat"; |
| 193 return; |
| 194 } |
| 195 display->pointer_ = make_scoped_ptr(new WaylandPointer( |
| 196 pointer, base::Bind(&WaylandDisplay::DispatchUiEvent, |
| 197 base::Unretained(display)))); |
| 198 } |
| 199 } else if (display->pointer_) { |
| 200 display->pointer_.reset(); |
| 201 } |
| 202 display->ScheduleFlush(); |
| 203 } |
| 204 |
| 205 // static |
| 206 void WaylandDisplay::Name(void* data, wl_seat* seat, const char* name) {} |
| 207 |
| 208 // static |
| 164 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { | 209 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { |
| 165 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); | 210 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); |
| 166 xdg_shell_pong(shell, serial); | 211 xdg_shell_pong(shell, serial); |
| 167 display->ScheduleFlush(); | 212 display->ScheduleFlush(); |
| 168 } | 213 } |
| 169 | 214 |
| 170 } // namespace ui | 215 } // namespace ui |
| OLD | NEW |