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() {} |
27 | 27 |
28 WaylandDisplay::~WaylandDisplay() {} | 28 WaylandDisplay::~WaylandDisplay() { |
29 for (WaylandScreen* screen : screen_list_) | |
30 delete screen; | |
31 screen_list_.clear(); | |
32 } | |
29 | 33 |
30 bool WaylandDisplay::Initialize() { | 34 bool WaylandDisplay::Initialize() { |
31 static const wl_registry_listener registry_listener = { | 35 static const wl_registry_listener registry_listener = { |
32 &WaylandDisplay::Global, &WaylandDisplay::GlobalRemove, | 36 &WaylandDisplay::Global, &WaylandDisplay::GlobalRemove, |
33 }; | 37 }; |
34 | 38 |
35 display_.reset(wl_display_connect(nullptr)); | 39 display_.reset(wl_display_connect(nullptr)); |
36 if (!display_) { | 40 if (!display_) { |
37 LOG(ERROR) << "Failed to connect to Wayland display"; | 41 LOG(ERROR) << "Failed to connect to Wayland display"; |
38 return false; | 42 return false; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 | 103 |
100 void WaylandDisplay::AddWindow(gfx::AcceleratedWidget widget, | 104 void WaylandDisplay::AddWindow(gfx::AcceleratedWidget widget, |
101 WaylandWindow* window) { | 105 WaylandWindow* window) { |
102 window_map_[widget] = window; | 106 window_map_[widget] = window; |
103 } | 107 } |
104 | 108 |
105 void WaylandDisplay::RemoveWindow(gfx::AcceleratedWidget widget) { | 109 void WaylandDisplay::RemoveWindow(gfx::AcceleratedWidget widget) { |
106 window_map_.erase(widget); | 110 window_map_.erase(widget); |
107 } | 111 } |
108 | 112 |
113 WaylandScreen* WaylandDisplay::PrimaryScreen() const { | |
114 if (!screen_list_.size()) | |
115 return nullptr; | |
116 return screen_list_.front(); | |
117 } | |
118 | |
109 void WaylandDisplay::OnDispatcherListChanged() { | 119 void WaylandDisplay::OnDispatcherListChanged() { |
110 StartProcessingEvents(); | 120 StartProcessingEvents(); |
111 } | 121 } |
112 | 122 |
113 void WaylandDisplay::Flush() { | 123 void WaylandDisplay::Flush() { |
114 wl_display_flush(display_.get()); | 124 wl_display_flush(display_.get()); |
115 scheduled_flush_ = false; | 125 scheduled_flush_ = false; |
116 } | 126 } |
117 | 127 |
118 void WaylandDisplay::DispatchUiEvent(Event* event) { | 128 void WaylandDisplay::DispatchUiEvent(Event* event) { |
119 PlatformEventSource::DispatchEvent(event); | 129 PlatformEventSource::DispatchEvent(event); |
120 } | 130 } |
121 | 131 |
122 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) { | 132 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) { |
123 wl_display_dispatch(display_.get()); | 133 wl_display_dispatch(display_.get()); |
124 for (const auto& window : window_map_) | 134 for (const auto& window : window_map_) |
125 window.second->ApplyPendingBounds(); | 135 window.second->ApplyPendingBounds(); |
126 } | 136 } |
127 | 137 |
128 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {} | 138 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {} |
129 | 139 |
140 const std::vector<WaylandScreen*>& WaylandDisplay::GetScreenList() const { | |
141 return screen_list_; | |
142 } | |
143 | |
130 // static | 144 // static |
131 void WaylandDisplay::Global(void* data, | 145 void WaylandDisplay::Global(void* data, |
132 wl_registry* registry, | 146 wl_registry* registry, |
133 uint32_t name, | 147 uint32_t name, |
134 const char* interface, | 148 const char* interface, |
135 uint32_t version) { | 149 uint32_t version) { |
136 static const wl_seat_listener seat_listener = { | 150 static const wl_seat_listener seat_listener = { |
137 &WaylandDisplay::Capabilities, &WaylandDisplay::Name, | 151 &WaylandDisplay::Capabilities, &WaylandDisplay::Name, |
138 }; | 152 }; |
139 static const xdg_shell_listener shell_listener = { | 153 static const xdg_shell_listener shell_listener = { |
(...skipping 22 matching lines...) Expand all Loading... | |
162 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { | 176 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { |
163 display->shell_ = wl::Bind<xdg_shell>( | 177 display->shell_ = wl::Bind<xdg_shell>( |
164 registry, name, std::min(version, kMaxXdgShellVersion)); | 178 registry, name, std::min(version, kMaxXdgShellVersion)); |
165 if (!display->shell_) { | 179 if (!display->shell_) { |
166 LOG(ERROR) << "Failed to bind to xdg_shell global"; | 180 LOG(ERROR) << "Failed to bind to xdg_shell global"; |
167 return; | 181 return; |
168 } | 182 } |
169 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); | 183 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); |
170 xdg_shell_use_unstable_version(display->shell_.get(), | 184 xdg_shell_use_unstable_version(display->shell_.get(), |
171 XDG_SHELL_VERSION_CURRENT); | 185 XDG_SHELL_VERSION_CURRENT); |
186 } else if (strcmp(interface, "wl_output") == 0) { | |
187 wl::Object<wl_output> output = wl::Bind<wl_output>(registry, name, 1); | |
188 if (!output) { | |
189 LOG(ERROR) << "Failed to bind to wl_output global"; | |
Michael Forney
2016/06/14 00:55:18
Looks like I have a typo double-space, which has p
joone
2016/06/14 22:10:28
Done.
| |
190 return; | |
191 } | |
192 | |
193 WaylandScreen* screen = new WaylandScreen(registry, name, output.release()); | |
194 if (!display->screen_list_.empty()) | |
195 NOTIMPLEMENTED() << "Multiple screens support is not implemented"; | |
196 | |
197 display->screen_list_.push_back(screen); | |
172 } | 198 } |
173 | 199 |
174 display->ScheduleFlush(); | 200 display->ScheduleFlush(); |
175 } | 201 } |
176 | 202 |
177 // static | 203 // static |
178 void WaylandDisplay::GlobalRemove(void* data, | 204 void WaylandDisplay::GlobalRemove(void* data, |
179 wl_registry* registry, | 205 wl_registry* registry, |
180 uint32_t name) { | 206 uint32_t name) { |
181 NOTIMPLEMENTED(); | 207 NOTIMPLEMENTED(); |
(...skipping 25 matching lines...) Expand all Loading... | |
207 void WaylandDisplay::Name(void* data, wl_seat* seat, const char* name) {} | 233 void WaylandDisplay::Name(void* data, wl_seat* seat, const char* name) {} |
208 | 234 |
209 // static | 235 // static |
210 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { | 236 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { |
211 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); | 237 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); |
212 xdg_shell_pong(shell, serial); | 238 xdg_shell_pong(shell, serial); |
213 display->ScheduleFlush(); | 239 display->ScheduleFlush(); |
214 } | 240 } |
215 | 241 |
216 } // namespace ui | 242 } // namespace ui |
OLD | NEW |