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" | 13 #include "base/strings/string_util.h" |
14 #include "ui/ozone/platform/wayland/wayland_object.h" | 14 #include "ui/ozone/platform/wayland/wayland_object.h" |
15 #include "ui/ozone/platform/wayland/wayland_window.h" | 15 #include "ui/ozone/platform/wayland/wayland_window.h" |
16 | 16 |
17 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); | 17 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 namespace { | 20 namespace { |
21 const uint32_t kMaxCompositorVersion = 4; | 21 const uint32_t kMaxCompositorVersion = 4; |
22 const uint32_t kMaxSeatVersion = 4; | 22 const uint32_t kMaxSeatVersion = 4; |
23 const uint32_t kMaxShmVersion = 1; | 23 const uint32_t kMaxShmVersion = 1; |
24 const uint32_t kMaxXdgShellVersion = 1; | 24 const uint32_t kMaxXdgShellVersion = 1; |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 WaylandConnection::WaylandConnection() {} | 27 WaylandConnection* WaylandConnection::instance_ = nullptr; |
| 28 |
| 29 WaylandConnection::WaylandConnection() : output_observer_(nullptr) {} |
28 | 30 |
29 WaylandConnection::~WaylandConnection() {} | 31 WaylandConnection::~WaylandConnection() {} |
30 | 32 |
31 bool WaylandConnection::Initialize() { | 33 bool WaylandConnection::Initialize() { |
32 static const wl_registry_listener registry_listener = { | 34 static const wl_registry_listener registry_listener = { |
33 &WaylandConnection::Global, &WaylandConnection::GlobalRemove, | 35 &WaylandConnection::Global, &WaylandConnection::GlobalRemove, |
34 }; | 36 }; |
35 | 37 |
36 display_.reset(wl_display_connect(nullptr)); | 38 display_.reset(wl_display_connect(nullptr)); |
37 if (!display_) { | 39 if (!display_) { |
(...skipping 20 matching lines...) Expand all Loading... |
58 } | 60 } |
59 if (!seat_) { | 61 if (!seat_) { |
60 LOG(ERROR) << "No wl_seat object"; | 62 LOG(ERROR) << "No wl_seat object"; |
61 return false; | 63 return false; |
62 } | 64 } |
63 if (!shell_) { | 65 if (!shell_) { |
64 LOG(ERROR) << "No xdg_shell object"; | 66 LOG(ERROR) << "No xdg_shell object"; |
65 return false; | 67 return false; |
66 } | 68 } |
67 | 69 |
| 70 instance_ = this; |
68 return true; | 71 return true; |
69 } | 72 } |
70 | 73 |
71 bool WaylandConnection::StartProcessingEvents() { | 74 bool WaylandConnection::StartProcessingEvents() { |
72 if (watching_) | 75 if (watching_) |
73 return true; | 76 return true; |
74 | 77 |
75 DCHECK(display_); | 78 DCHECK(display_); |
76 wl_display_flush(display_.get()); | 79 wl_display_flush(display_.get()); |
77 | 80 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 window.second->ApplyPendingBounds(); | 135 window.second->ApplyPendingBounds(); |
133 } | 136 } |
134 | 137 |
135 void WaylandConnection::OnFileCanWriteWithoutBlocking(int fd) {} | 138 void WaylandConnection::OnFileCanWriteWithoutBlocking(int fd) {} |
136 | 139 |
137 const std::vector<std::unique_ptr<WaylandOutput>>& | 140 const std::vector<std::unique_ptr<WaylandOutput>>& |
138 WaylandConnection::GetOutputList() const { | 141 WaylandConnection::GetOutputList() const { |
139 return output_list_; | 142 return output_list_; |
140 } | 143 } |
141 | 144 |
| 145 void WaylandConnection::SetOutputObserver( |
| 146 OzonePlatformScreenDelegate* observer) { |
| 147 output_observer_ = observer; |
| 148 } |
| 149 |
| 150 void WaylandConnection::OnOutputGeometryChanged(int32_t name, |
| 151 const gfx::Rect& rect) { |
| 152 if (output_observer_) |
| 153 output_observer_->OnOutputGeometryChanged(name, rect); |
| 154 } |
| 155 |
142 // static | 156 // static |
143 void WaylandConnection::Global(void* data, | 157 void WaylandConnection::Global(void* data, |
144 wl_registry* registry, | 158 wl_registry* registry, |
145 uint32_t name, | 159 uint32_t name, |
146 const char* interface, | 160 const char* interface, |
147 uint32_t version) { | 161 uint32_t version) { |
148 static const wl_seat_listener seat_listener = { | 162 static const wl_seat_listener seat_listener = { |
149 &WaylandConnection::Capabilities, &WaylandConnection::Name, | 163 &WaylandConnection::Capabilities, &WaylandConnection::Name, |
150 }; | 164 }; |
151 static const xdg_shell_listener shell_listener = { | 165 static const xdg_shell_listener shell_listener = { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 wl::Object<wl_output> output = wl::Bind<wl_output>(registry, name, 1); | 200 wl::Object<wl_output> output = wl::Bind<wl_output>(registry, name, 1); |
187 if (!output) { | 201 if (!output) { |
188 LOG(ERROR) << "Failed to bind to wl_output global"; | 202 LOG(ERROR) << "Failed to bind to wl_output global"; |
189 return; | 203 return; |
190 } | 204 } |
191 | 205 |
192 if (!connection->output_list_.empty()) | 206 if (!connection->output_list_.empty()) |
193 NOTIMPLEMENTED() << "Multiple screens support is not implemented"; | 207 NOTIMPLEMENTED() << "Multiple screens support is not implemented"; |
194 | 208 |
195 connection->output_list_.push_back( | 209 connection->output_list_.push_back( |
196 base::WrapUnique(new WaylandOutput(output.release()))); | 210 base::WrapUnique(new WaylandOutput(output.release(), name))); |
197 } | 211 } |
198 | 212 |
199 connection->ScheduleFlush(); | 213 connection->ScheduleFlush(); |
200 } | 214 } |
201 | 215 |
202 // static | 216 // static |
203 void WaylandConnection::GlobalRemove(void* data, | 217 void WaylandConnection::GlobalRemove(void* data, |
204 wl_registry* registry, | 218 wl_registry* registry, |
205 uint32_t name) { | 219 uint32_t name) { |
206 NOTIMPLEMENTED(); | 220 NOTIMPLEMENTED(); |
(...skipping 25 matching lines...) Expand all Loading... |
232 void WaylandConnection::Name(void* data, wl_seat* seat, const char* name) {} | 246 void WaylandConnection::Name(void* data, wl_seat* seat, const char* name) {} |
233 | 247 |
234 // static | 248 // static |
235 void WaylandConnection::Ping(void* data, xdg_shell* shell, uint32_t serial) { | 249 void WaylandConnection::Ping(void* data, xdg_shell* shell, uint32_t serial) { |
236 WaylandConnection* connection = static_cast<WaylandConnection*>(data); | 250 WaylandConnection* connection = static_cast<WaylandConnection*>(data); |
237 xdg_shell_pong(shell, serial); | 251 xdg_shell_pong(shell, serial); |
238 connection->ScheduleFlush(); | 252 connection->ScheduleFlush(); |
239 } | 253 } |
240 | 254 |
241 } // namespace ui | 255 } // namespace ui |
OLD | NEW |