Chromium Code Reviews| 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::instance_ = nullptr; | |
| 27 | |
| 26 WaylandDisplay::WaylandDisplay() {} | 28 WaylandDisplay::WaylandDisplay() {} |
| 27 | 29 |
| 28 WaylandDisplay::~WaylandDisplay() {} | 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; | |
|
tonikitoo
2016/06/06 21:35:15
analogously, should not you set "instance_" to nul
joone
2016/06/07 22:26:59
Done.
| |
| 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 (!output_complete_closure_.is_null()) | |
| 141 output_complete_closure_.Run(); | |
| 142 } | |
| 143 | |
| 144 void WaylandDisplay::SetOutputCompleteClosure(const base::Closure& closure) { | |
| 145 output_complete_closure_ = closure; | |
| 146 } | |
| 147 | |
| 148 const std::vector<WaylandScreen*>& WaylandDisplay::GetScreenList() const { | |
| 149 return screen_list_; | |
| 150 } | |
| 151 | |
| 130 // static | 152 // static |
| 131 void WaylandDisplay::Global(void* data, | 153 void WaylandDisplay::Global(void* data, |
| 132 wl_registry* registry, | 154 wl_registry* registry, |
| 133 uint32_t name, | 155 uint32_t name, |
| 134 const char* interface, | 156 const char* interface, |
| 135 uint32_t version) { | 157 uint32_t version) { |
| 136 static const wl_seat_listener seat_listener = { | 158 static const wl_seat_listener seat_listener = { |
| 137 &WaylandDisplay::Capabilities, &WaylandDisplay::Name, | 159 &WaylandDisplay::Capabilities, &WaylandDisplay::Name, |
| 138 }; | 160 }; |
| 139 static const xdg_shell_listener shell_listener = { | 161 static const xdg_shell_listener shell_listener = { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 162 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { | 184 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { |
| 163 display->shell_ = wl::Bind<xdg_shell>( | 185 display->shell_ = wl::Bind<xdg_shell>( |
| 164 registry, name, std::min(version, kMaxXdgShellVersion)); | 186 registry, name, std::min(version, kMaxXdgShellVersion)); |
| 165 if (!display->shell_) { | 187 if (!display->shell_) { |
| 166 LOG(ERROR) << "Failed to bind to xdg_shell global"; | 188 LOG(ERROR) << "Failed to bind to xdg_shell global"; |
| 167 return; | 189 return; |
| 168 } | 190 } |
| 169 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); | 191 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); |
| 170 xdg_shell_use_unstable_version(display->shell_.get(), | 192 xdg_shell_use_unstable_version(display->shell_.get(), |
| 171 XDG_SHELL_VERSION_CURRENT); | 193 XDG_SHELL_VERSION_CURRENT); |
| 194 } else if (strcmp(interface, "wl_output") == 0) { | |
| 195 WaylandScreen* screen = new WaylandScreen(registry, name); | |
| 196 if (!display->screen_list_.empty()) | |
| 197 NOTIMPLEMENTED() << "Multiple screens support is not implemented"; | |
| 198 | |
| 199 display->screen_list_.push_back(screen); | |
| 200 display->primary_screen_ = display->screen_list_.front(); | |
| 172 } | 201 } |
| 173 | 202 |
| 174 display->ScheduleFlush(); | 203 display->ScheduleFlush(); |
| 175 } | 204 } |
| 176 | 205 |
| 177 // static | 206 // static |
| 178 void WaylandDisplay::GlobalRemove(void* data, | 207 void WaylandDisplay::GlobalRemove(void* data, |
| 179 wl_registry* registry, | 208 wl_registry* registry, |
| 180 uint32_t name) { | 209 uint32_t name) { |
| 181 NOTIMPLEMENTED(); | 210 NOTIMPLEMENTED(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 207 void WaylandDisplay::Name(void* data, wl_seat* seat, const char* name) {} | 236 void WaylandDisplay::Name(void* data, wl_seat* seat, const char* name) {} |
| 208 | 237 |
| 209 // static | 238 // static |
| 210 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { | 239 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { |
| 211 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); | 240 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); |
| 212 xdg_shell_pong(shell, serial); | 241 xdg_shell_pong(shell, serial); |
| 213 display->ScheduleFlush(); | 242 display->ScheduleFlush(); |
| 214 } | 243 } |
| 215 | 244 |
| 216 } // namespace ui | 245 } // namespace ui |
| OLD | NEW |