| 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_connection.h" | 5 #include "ui/ozone/platform/wayland/wayland_connection.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/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_util.h" |
| 14 #include "ui/ozone/platform/wayland/wayland_object.h" |
| 13 #include "ui/ozone/platform/wayland/wayland_window.h" | 15 #include "ui/ozone/platform/wayland/wayland_window.h" |
| 14 | 16 |
| 15 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); | 17 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); |
| 16 | 18 |
| 17 namespace ui { | 19 namespace ui { |
| 18 namespace { | 20 namespace { |
| 19 const uint32_t kMaxCompositorVersion = 4; | 21 const uint32_t kMaxCompositorVersion = 4; |
| 20 const uint32_t kMaxSeatVersion = 4; | 22 const uint32_t kMaxSeatVersion = 4; |
| 21 const uint32_t kMaxShmVersion = 1; | 23 const uint32_t kMaxShmVersion = 1; |
| 22 const uint32_t kMaxXdgShellVersion = 1; | 24 const uint32_t kMaxXdgShellVersion = 1; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 100 |
| 99 void WaylandConnection::AddWindow(gfx::AcceleratedWidget widget, | 101 void WaylandConnection::AddWindow(gfx::AcceleratedWidget widget, |
| 100 WaylandWindow* window) { | 102 WaylandWindow* window) { |
| 101 window_map_[widget] = window; | 103 window_map_[widget] = window; |
| 102 } | 104 } |
| 103 | 105 |
| 104 void WaylandConnection::RemoveWindow(gfx::AcceleratedWidget widget) { | 106 void WaylandConnection::RemoveWindow(gfx::AcceleratedWidget widget) { |
| 105 window_map_.erase(widget); | 107 window_map_.erase(widget); |
| 106 } | 108 } |
| 107 | 109 |
| 110 WaylandOutput* WaylandConnection::PrimaryOutput() const { |
| 111 if (!output_list_.size()) |
| 112 return nullptr; |
| 113 return output_list_.front().get(); |
| 114 } |
| 115 |
| 108 void WaylandConnection::OnDispatcherListChanged() { | 116 void WaylandConnection::OnDispatcherListChanged() { |
| 109 StartProcessingEvents(); | 117 StartProcessingEvents(); |
| 110 } | 118 } |
| 111 | 119 |
| 112 void WaylandConnection::Flush() { | 120 void WaylandConnection::Flush() { |
| 113 wl_display_flush(display_.get()); | 121 wl_display_flush(display_.get()); |
| 114 scheduled_flush_ = false; | 122 scheduled_flush_ = false; |
| 115 } | 123 } |
| 116 | 124 |
| 117 void WaylandConnection::DispatchUiEvent(Event* event) { | 125 void WaylandConnection::DispatchUiEvent(Event* event) { |
| 118 PlatformEventSource::DispatchEvent(event); | 126 PlatformEventSource::DispatchEvent(event); |
| 119 } | 127 } |
| 120 | 128 |
| 121 void WaylandConnection::OnFileCanReadWithoutBlocking(int fd) { | 129 void WaylandConnection::OnFileCanReadWithoutBlocking(int fd) { |
| 122 wl_display_dispatch(display_.get()); | 130 wl_display_dispatch(display_.get()); |
| 123 for (const auto& window : window_map_) | 131 for (const auto& window : window_map_) |
| 124 window.second->ApplyPendingBounds(); | 132 window.second->ApplyPendingBounds(); |
| 125 } | 133 } |
| 126 | 134 |
| 127 void WaylandConnection::OnFileCanWriteWithoutBlocking(int fd) {} | 135 void WaylandConnection::OnFileCanWriteWithoutBlocking(int fd) {} |
| 128 | 136 |
| 137 const std::vector<std::unique_ptr<WaylandOutput>>& |
| 138 WaylandConnection::GetOutputList() const { |
| 139 return output_list_; |
| 140 } |
| 141 |
| 129 // static | 142 // static |
| 130 void WaylandConnection::Global(void* data, | 143 void WaylandConnection::Global(void* data, |
| 131 wl_registry* registry, | 144 wl_registry* registry, |
| 132 uint32_t name, | 145 uint32_t name, |
| 133 const char* interface, | 146 const char* interface, |
| 134 uint32_t version) { | 147 uint32_t version) { |
| 135 static const wl_seat_listener seat_listener = { | 148 static const wl_seat_listener seat_listener = { |
| 136 &WaylandConnection::Capabilities, &WaylandConnection::Name, | 149 &WaylandConnection::Capabilities, &WaylandConnection::Name, |
| 137 }; | 150 }; |
| 138 static const xdg_shell_listener shell_listener = { | 151 static const xdg_shell_listener shell_listener = { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 162 connection->shell_ = wl::Bind<xdg_shell>( | 175 connection->shell_ = wl::Bind<xdg_shell>( |
| 163 registry, name, std::min(version, kMaxXdgShellVersion)); | 176 registry, name, std::min(version, kMaxXdgShellVersion)); |
| 164 if (!connection->shell_) { | 177 if (!connection->shell_) { |
| 165 LOG(ERROR) << "Failed to bind to xdg_shell global"; | 178 LOG(ERROR) << "Failed to bind to xdg_shell global"; |
| 166 return; | 179 return; |
| 167 } | 180 } |
| 168 xdg_shell_add_listener(connection->shell_.get(), &shell_listener, | 181 xdg_shell_add_listener(connection->shell_.get(), &shell_listener, |
| 169 connection); | 182 connection); |
| 170 xdg_shell_use_unstable_version(connection->shell_.get(), | 183 xdg_shell_use_unstable_version(connection->shell_.get(), |
| 171 XDG_SHELL_VERSION_CURRENT); | 184 XDG_SHELL_VERSION_CURRENT); |
| 185 } else if (base::EqualsCaseInsensitiveASCII(interface, "wl_output")) { |
| 186 wl::Object<wl_output> output = wl::Bind<wl_output>(registry, name, 1); |
| 187 if (!output) { |
| 188 LOG(ERROR) << "Failed to bind to wl_output global"; |
| 189 return; |
| 190 } |
| 191 |
| 192 if (!connection->output_list_.empty()) |
| 193 NOTIMPLEMENTED() << "Multiple screens support is not implemented"; |
| 194 |
| 195 connection->output_list_.push_back( |
| 196 base::WrapUnique(new WaylandOutput(output.release()))); |
| 172 } | 197 } |
| 173 | 198 |
| 174 connection->ScheduleFlush(); | 199 connection->ScheduleFlush(); |
| 175 } | 200 } |
| 176 | 201 |
| 177 // static | 202 // static |
| 178 void WaylandConnection::GlobalRemove(void* data, | 203 void WaylandConnection::GlobalRemove(void* data, |
| 179 wl_registry* registry, | 204 wl_registry* registry, |
| 180 uint32_t name) { | 205 uint32_t name) { |
| 181 NOTIMPLEMENTED(); | 206 NOTIMPLEMENTED(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 207 void WaylandConnection::Name(void* data, wl_seat* seat, const char* name) {} | 232 void WaylandConnection::Name(void* data, wl_seat* seat, const char* name) {} |
| 208 | 233 |
| 209 // static | 234 // static |
| 210 void WaylandConnection::Ping(void* data, xdg_shell* shell, uint32_t serial) { | 235 void WaylandConnection::Ping(void* data, xdg_shell* shell, uint32_t serial) { |
| 211 WaylandConnection* connection = static_cast<WaylandConnection*>(data); | 236 WaylandConnection* connection = static_cast<WaylandConnection*>(data); |
| 212 xdg_shell_pong(shell, serial); | 237 xdg_shell_pong(shell, serial); |
| 213 connection->ScheduleFlush(); | 238 connection->ScheduleFlush(); |
| 214 } | 239 } |
| 215 | 240 |
| 216 } // namespace ui | 241 } // namespace ui |
| OLD | NEW |