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; | |
|
Michael Forney
2016/06/10 18:12:21
Why do we need to make this a singleton?
joone
2016/06/14 00:04:43
We don't need WaylandDisplay::instance any more si
| |
| 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 instance_ = nullptr; | |
| 35 } | |
| 29 | 36 |
| 30 bool WaylandDisplay::Initialize() { | 37 bool WaylandDisplay::Initialize() { |
| 31 static const wl_registry_listener registry_listener = { | 38 static const wl_registry_listener registry_listener = { |
| 32 &WaylandDisplay::Global, &WaylandDisplay::GlobalRemove, | 39 &WaylandDisplay::Global, &WaylandDisplay::GlobalRemove, |
| 33 }; | 40 }; |
| 34 | 41 |
| 35 display_.reset(wl_display_connect(nullptr)); | 42 display_.reset(wl_display_connect(nullptr)); |
| 36 if (!display_) { | 43 if (!display_) { |
| 37 LOG(ERROR) << "Failed to connect to Wayland display"; | 44 LOG(ERROR) << "Failed to connect to Wayland display"; |
| 38 return false; | 45 return false; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 57 } | 64 } |
| 58 if (!seat_) { | 65 if (!seat_) { |
| 59 LOG(ERROR) << "No wl_seat object"; | 66 LOG(ERROR) << "No wl_seat object"; |
| 60 return false; | 67 return false; |
| 61 } | 68 } |
| 62 if (!shell_) { | 69 if (!shell_) { |
| 63 LOG(ERROR) << "No xdg_shell object"; | 70 LOG(ERROR) << "No xdg_shell object"; |
| 64 return false; | 71 return false; |
| 65 } | 72 } |
| 66 | 73 |
| 74 instance_ = this; | |
| 67 return true; | 75 return true; |
| 68 } | 76 } |
| 69 | 77 |
| 70 bool WaylandDisplay::StartProcessingEvents() { | 78 bool WaylandDisplay::StartProcessingEvents() { |
| 71 if (watching_) | 79 if (watching_) |
| 72 return true; | 80 return true; |
| 73 | 81 |
| 74 DCHECK(display_); | 82 DCHECK(display_); |
| 75 wl_display_flush(display_.get()); | 83 wl_display_flush(display_.get()); |
| 76 | 84 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 99 | 107 |
| 100 void WaylandDisplay::AddWindow(gfx::AcceleratedWidget widget, | 108 void WaylandDisplay::AddWindow(gfx::AcceleratedWidget widget, |
| 101 WaylandWindow* window) { | 109 WaylandWindow* window) { |
| 102 window_map_[widget] = window; | 110 window_map_[widget] = window; |
| 103 } | 111 } |
| 104 | 112 |
| 105 void WaylandDisplay::RemoveWindow(gfx::AcceleratedWidget widget) { | 113 void WaylandDisplay::RemoveWindow(gfx::AcceleratedWidget widget) { |
| 106 window_map_.erase(widget); | 114 window_map_.erase(widget); |
| 107 } | 115 } |
| 108 | 116 |
| 117 WaylandScreen* WaylandDisplay::PrimaryScreen() const { | |
| 118 if (!screen_list_.size()) | |
| 119 return nullptr; | |
| 120 return screen_list_.front(); | |
| 121 } | |
| 122 | |
| 109 void WaylandDisplay::OnDispatcherListChanged() { | 123 void WaylandDisplay::OnDispatcherListChanged() { |
| 110 StartProcessingEvents(); | 124 StartProcessingEvents(); |
| 111 } | 125 } |
| 112 | 126 |
| 113 void WaylandDisplay::Flush() { | 127 void WaylandDisplay::Flush() { |
| 114 wl_display_flush(display_.get()); | 128 wl_display_flush(display_.get()); |
| 115 scheduled_flush_ = false; | 129 scheduled_flush_ = false; |
| 116 } | 130 } |
| 117 | 131 |
| 118 void WaylandDisplay::DispatchUiEvent(Event* event) { | 132 void WaylandDisplay::DispatchUiEvent(Event* event) { |
| 119 PlatformEventSource::DispatchEvent(event); | 133 PlatformEventSource::DispatchEvent(event); |
| 120 } | 134 } |
| 121 | 135 |
| 122 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) { | 136 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) { |
| 123 wl_display_dispatch(display_.get()); | 137 wl_display_dispatch(display_.get()); |
| 124 for (const auto& window : window_map_) | 138 for (const auto& window : window_map_) |
| 125 window.second->ApplyPendingBounds(); | 139 window.second->ApplyPendingBounds(); |
| 126 } | 140 } |
| 127 | 141 |
| 128 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {} | 142 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {} |
| 129 | 143 |
| 144 void WaylandDisplay::OnOutputGeometryChanged(int32_t name, | |
| 145 const gfx::Rect& rect) { | |
| 146 display::Screen::GetScreen()->OnOutputGeometryChanged(name, rect); | |
|
Michael Forney
2016/06/10 18:12:21
Can't WaylandScreen call this?
Also, maybe I'm mi
joone
2016/06/14 00:04:43
I missed to include the header file.
| |
| 147 if (!output_complete_closure_.is_null()) | |
| 148 output_complete_closure_.Run(); | |
| 149 } | |
| 150 | |
| 151 void WaylandDisplay::SetOutputCompleteClosure(const base::Closure& closure) { | |
| 152 output_complete_closure_ = closure; | |
|
Michael Forney
2016/06/10 18:12:21
I think this should be a method on WaylandScreen.
joone
2016/06/14 00:04:43
Done.
| |
| 153 } | |
| 154 | |
| 155 const std::vector<WaylandScreen*>& WaylandDisplay::GetScreenList() const { | |
| 156 return screen_list_; | |
| 157 } | |
| 158 | |
| 130 // static | 159 // static |
| 131 void WaylandDisplay::Global(void* data, | 160 void WaylandDisplay::Global(void* data, |
| 132 wl_registry* registry, | 161 wl_registry* registry, |
| 133 uint32_t name, | 162 uint32_t name, |
| 134 const char* interface, | 163 const char* interface, |
| 135 uint32_t version) { | 164 uint32_t version) { |
| 136 static const wl_seat_listener seat_listener = { | 165 static const wl_seat_listener seat_listener = { |
| 137 &WaylandDisplay::Capabilities, &WaylandDisplay::Name, | 166 &WaylandDisplay::Capabilities, &WaylandDisplay::Name, |
| 138 }; | 167 }; |
| 139 static const xdg_shell_listener shell_listener = { | 168 static const xdg_shell_listener shell_listener = { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 162 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { | 191 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) { |
| 163 display->shell_ = wl::Bind<xdg_shell>( | 192 display->shell_ = wl::Bind<xdg_shell>( |
| 164 registry, name, std::min(version, kMaxXdgShellVersion)); | 193 registry, name, std::min(version, kMaxXdgShellVersion)); |
| 165 if (!display->shell_) { | 194 if (!display->shell_) { |
| 166 LOG(ERROR) << "Failed to bind to xdg_shell global"; | 195 LOG(ERROR) << "Failed to bind to xdg_shell global"; |
| 167 return; | 196 return; |
| 168 } | 197 } |
| 169 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); | 198 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); |
| 170 xdg_shell_use_unstable_version(display->shell_.get(), | 199 xdg_shell_use_unstable_version(display->shell_.get(), |
| 171 XDG_SHELL_VERSION_CURRENT); | 200 XDG_SHELL_VERSION_CURRENT); |
| 201 } else if (strcmp(interface, "wl_output") == 0) { | |
| 202 WaylandScreen* screen = new WaylandScreen(registry, name); | |
| 203 if (!display->screen_list_.empty()) | |
| 204 NOTIMPLEMENTED() << "Multiple screens support is not implemented"; | |
| 205 | |
| 206 display->screen_list_.push_back(screen); | |
| 172 } | 207 } |
| 173 | 208 |
| 174 display->ScheduleFlush(); | 209 display->ScheduleFlush(); |
| 175 } | 210 } |
| 176 | 211 |
| 177 // static | 212 // static |
| 178 void WaylandDisplay::GlobalRemove(void* data, | 213 void WaylandDisplay::GlobalRemove(void* data, |
| 179 wl_registry* registry, | 214 wl_registry* registry, |
| 180 uint32_t name) { | 215 uint32_t name) { |
| 181 NOTIMPLEMENTED(); | 216 NOTIMPLEMENTED(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 207 void WaylandDisplay::Name(void* data, wl_seat* seat, const char* name) {} | 242 void WaylandDisplay::Name(void* data, wl_seat* seat, const char* name) {} |
| 208 | 243 |
| 209 // static | 244 // static |
| 210 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { | 245 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { |
| 211 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); | 246 WaylandDisplay* display = static_cast<WaylandDisplay*>(data); |
| 212 xdg_shell_pong(shell, serial); | 247 xdg_shell_pong(shell, serial); |
| 213 display->ScheduleFlush(); | 248 display->ScheduleFlush(); |
| 214 } | 249 } |
| 215 | 250 |
| 216 } // namespace ui | 251 } // namespace ui |
| OLD | NEW |