| 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/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 "ui/ozone/platform/wayland/wayland_object.h" | 13 #include "ui/ozone/platform/wayland/wayland_object.h" |
| 14 #include "ui/ozone/platform/wayland/wayland_window.h" | 14 #include "ui/ozone/platform/wayland/wayland_window.h" |
| 15 | 15 |
| 16 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); | 16 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); |
| 17 | 17 |
| 18 namespace ui { | 18 namespace ui { |
| 19 namespace { | 19 namespace { |
| 20 const uint32_t kMaxCompositorVersion = 4; | 20 const uint32_t kMaxCompositorVersion = 4; |
| 21 const uint32_t kMaxSeatVersion = 4; | 21 const uint32_t kMaxSeatVersion = 4; |
| 22 const uint32_t kMaxShmVersion = 1; | 22 const uint32_t kMaxShmVersion = 1; |
| 23 const uint32_t kMaxXdgShellVersion = 1; | 23 const uint32_t kMaxXdgShellVersion = 1; |
| 24 } // namespace | 24 } // namespace |
| 25 | 25 |
| 26 WaylandDisplay::WaylandDisplay() {} | 26 WaylandDisplay* WaylandDisplay::instance_ = nullptr; |
| 27 | 27 |
| 28 WaylandDisplay::~WaylandDisplay() {} | 28 WaylandDisplay::WaylandDisplay() : desktop_platform_screen_delegate_(nullptr) {} |
| 29 |
| 30 WaylandDisplay::~WaylandDisplay() { |
| 31 for (WaylandScreen* screen : screen_list_) |
| 32 delete screen; |
| 33 screen_list_.clear(); |
| 34 } |
| 29 | 35 |
| 30 bool WaylandDisplay::Initialize() { | 36 bool WaylandDisplay::Initialize() { |
| 31 static const wl_registry_listener registry_listener = { | 37 static const wl_registry_listener registry_listener = { |
| 32 &WaylandDisplay::Global, &WaylandDisplay::GlobalRemove, | 38 &WaylandDisplay::Global, &WaylandDisplay::GlobalRemove, |
| 33 }; | 39 }; |
| 34 | 40 |
| 35 display_.reset(wl_display_connect(nullptr)); | 41 display_.reset(wl_display_connect(nullptr)); |
| 36 if (!display_) { | 42 if (!display_) { |
| 37 LOG(ERROR) << "Failed to connect to Wayland display"; | 43 LOG(ERROR) << "Failed to connect to Wayland display"; |
| 38 return false; | 44 return false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 57 } | 63 } |
| 58 if (!seat_) { | 64 if (!seat_) { |
| 59 LOG(ERROR) << "No wl_seat object"; | 65 LOG(ERROR) << "No wl_seat object"; |
| 60 return false; | 66 return false; |
| 61 } | 67 } |
| 62 if (!shell_) { | 68 if (!shell_) { |
| 63 LOG(ERROR) << "No xdg_shell object"; | 69 LOG(ERROR) << "No xdg_shell object"; |
| 64 return false; | 70 return false; |
| 65 } | 71 } |
| 66 | 72 |
| 73 instance_ = this; |
| 67 return true; | 74 return true; |
| 68 } | 75 } |
| 69 | 76 |
| 70 bool WaylandDisplay::StartProcessingEvents() { | 77 bool WaylandDisplay::StartProcessingEvents() { |
| 71 if (watching_) | 78 if (watching_) |
| 72 return true; | 79 return true; |
| 73 | 80 |
| 74 DCHECK(display_); | 81 DCHECK(display_); |
| 75 wl_display_flush(display_.get()); | 82 wl_display_flush(display_.get()); |
| 76 | 83 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 127 } |
| 121 | 128 |
| 122 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) { | 129 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) { |
| 123 wl_display_dispatch(display_.get()); | 130 wl_display_dispatch(display_.get()); |
| 124 for (const auto& window : window_map_) | 131 for (const auto& window : window_map_) |
| 125 window.second->ApplyPendingBounds(); | 132 window.second->ApplyPendingBounds(); |
| 126 } | 133 } |
| 127 | 134 |
| 128 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {} | 135 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {} |
| 129 | 136 |
| 137 void WaylandDisplay::OutputSizeChanged(int32_t name, |
| 138 unsigned width, |
| 139 unsigned height) { |
| 140 if (desktop_platform_screen_delegate_) |
| 141 desktop_platform_screen_delegate_->OnOutputSizeChanged(name, width, height); |
| 142 } |
| 143 |
| 144 const std::vector<WaylandScreen*>& WaylandDisplay::GetScreenList() const { |
| 145 return screen_list_; |
| 146 } |
| 147 |
| 148 void WaylandDisplay::SetDesktopScreenDelegate( |
| 149 DesktopPlatformScreenDelegate* delegate) { |
| 150 desktop_platform_screen_delegate_ = delegate; |
| 151 } |
| 152 |
| 130 // static | 153 // static |
| 131 void WaylandDisplay::Global(void* data, | 154 void WaylandDisplay::Global(void* data, |
| 132 wl_registry* registry, | 155 wl_registry* registry, |
| 133 uint32_t name, | 156 uint32_t name, |
| 134 const char* interface, | 157 const char* interface, |
| 135 uint32_t version) { | 158 uint32_t version) { |
| 136 static const wl_seat_listener seat_listener = { | 159 static const wl_seat_listener seat_listener = { |
| 137 &WaylandDisplay::Capabilities, &WaylandDisplay::Name, | 160 &WaylandDisplay::Capabilities, &WaylandDisplay::Name, |
| 138 }; | 161 }; |
| 139 static const xdg_shell_listener shell_listener = { | 162 static const xdg_shell_listener shell_listener = { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 162 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { | 185 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { |
| 163 display->shell_ = wl::Bind<xdg_shell>( | 186 display->shell_ = wl::Bind<xdg_shell>( |
| 164 registry, name, std::min(version, kMaxXdgShellVersion)); | 187 registry, name, std::min(version, kMaxXdgShellVersion)); |
| 165 if (!display->shell_) { | 188 if (!display->shell_) { |
| 166 LOG(ERROR) << "Failed to bind to xdg_shell global"; | 189 LOG(ERROR) << "Failed to bind to xdg_shell global"; |
| 167 return; | 190 return; |
| 168 } | 191 } |
| 169 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); | 192 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); |
| 170 xdg_shell_use_unstable_version(display->shell_.get(), | 193 xdg_shell_use_unstable_version(display->shell_.get(), |
| 171 XDG_SHELL_VERSION_CURRENT); | 194 XDG_SHELL_VERSION_CURRENT); |
| 195 } else if (strcmp(interface, "wl_output") == 0) { |
| 196 WaylandScreen* screen = new WaylandScreen(registry, name); |
| 197 if (!display->screen_list_.empty()) |
| 198 NOTIMPLEMENTED() << "Multiple screens support is not implemented"; |
| 199 |
| 200 display->screen_list_.push_back(screen); |
| 201 display->primary_screen_ = display->screen_list_.front(); |
| 172 } | 202 } |
| 173 | 203 |
| 174 display->ScheduleFlush(); | 204 display->ScheduleFlush(); |
| 175 } | 205 } |
| 176 | 206 |
| 177 // static | 207 // static |
| 178 void WaylandDisplay::GlobalRemove(void* data, | 208 void WaylandDisplay::GlobalRemove(void* data, |
| 179 wl_registry* registry, | 209 wl_registry* registry, |
| 180 uint32_t name) { | 210 uint32_t name) { |
| 181 NOTIMPLEMENTED(); | 211 NOTIMPLEMENTED(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 207 void WaylandDisplay::Name(void* data, wl_seat* seat, const char* name) {} | 237 void WaylandDisplay::Name(void* data, wl_seat* seat, const char* name) {} |
| 208 | 238 |
| 209 // static | 239 // static |
| 210 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { | 240 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { |
| 211 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); | 241 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); |
| 212 xdg_shell_pong(shell, serial); | 242 xdg_shell_pong(shell, serial); |
| 213 display->ScheduleFlush(); | 243 display->ScheduleFlush(); |
| 214 } | 244 } |
| 215 | 245 |
| 216 } // namespace ui | 246 } // namespace ui |
| OLD | NEW |