Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: ui/ozone/platform/wayland/wayland_display.cc

Issue 1610683003: Add initial SHM-only Wayland Ozone implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/ozone/platform/wayland/wayland_display.h"
6
7 #include "base/logging.h"
8 #include "base/message_loop/message_loop.h"
9 #include "ui/ozone/platform/wayland/wayland_object.h"
10 #include "ui/ozone/platform/wayland/wayland_window.h"
11
12 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version");
13
14 namespace ui {
15
16 WaylandDisplay::WaylandDisplay() {}
17
18 WaylandDisplay::~WaylandDisplay() {}
19
20 bool WaylandDisplay::Initialize() {
21 static const wl_registry_listener registry_listener = {
22 .global = &WaylandDisplay::Global,
23 .global_remove = &WaylandDisplay::GlobalRemove,
24 };
25
26 display_.reset(wl_display_connect(nullptr));
27 if (!display_) {
28 LOG(ERROR) << "Failed to connect to Wayland display";
29 return false;
30 }
31
32 registry_.reset(wl_display_get_registry(display_.get()));
33 if (!registry_) {
34 LOG(ERROR) << "Failed to get Wayland registry";
35 return false;
36 }
37
38 wl_registry_add_listener(registry_.get(), &registry_listener, this);
39 wl_display_roundtrip(display_.get());
40
41 if (!compositor_) {
42 LOG(ERROR) << "No wl_compositor object";
43 return false;
44 }
45 if (!shm_) {
46 LOG(ERROR) << "No wl_shm object";
47 return false;
48 }
49 if (!shell_) {
50 LOG(ERROR) << "No xdg_shell object";
51 return false;
52 }
53
54 return true;
55 }
56
57 void WaylandDisplay::Flush() {
58 DCHECK(display_);
59 wl_display_flush(display_.get());
60 }
61
62 wl_compositor* WaylandDisplay::GetCompositor() {
63 DCHECK(compositor_);
64 return compositor_.get();
65 }
66
67 wl_shm* WaylandDisplay::GetShm() {
68 DCHECK(shm_);
69 return shm_.get();
70 }
71
72 xdg_shell* WaylandDisplay::GetShell() {
73 DCHECK(shell_);
74 return shell_.get();
75 }
76
77 WaylandWindow* WaylandDisplay::GetWindow(gfx::AcceleratedWidget widget) {
78 auto it = windows_.find(widget);
79 return it == windows_.end() ? nullptr : it->second;
80 }
81
82 void WaylandDisplay::AddWindow(WaylandWindow* window) {
83 windows_[window->GetWidget()] = window;
84 }
85
86 void WaylandDisplay::RemoveWindow(WaylandWindow* window) {
87 windows_.erase(window->GetWidget());
88 }
89
90 void WaylandDisplay::StartProcessingEvents() {
91 if (watching_)
92 return;
93
94 DCHECK(display_);
95 DCHECK(base::MessageLoopForUI::IsCurrent());
96 base::MessageLoopForUI::current()->WatchFileDescriptor(
97 wl_display_get_fd(display_.get()), true,
98 base::MessagePumpLibevent::WATCH_READ, &controller_, this);
99 watching_ = true;
100 }
101
102 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) {
103 wl_display_dispatch(display_.get());
104 for (const auto& window : windows_)
105 window.second->ApplyPendingBounds();
106 }
107
108 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {}
109
110 // static
111 void WaylandDisplay::Global(void* data,
112 wl_registry* registry,
113 uint32_t name,
114 const char* interface,
115 uint32_t version) {
116 static const xdg_shell_listener shell_listener = {
117 .ping = &WaylandDisplay::Ping,
118 };
119
120 WaylandDisplay* display = static_cast<WaylandDisplay*>(data);
121 if (!display->compositor_ && strcmp(interface, "wl_compositor") == 0) {
122 display->compositor_ = wl::Bind<wl_compositor>(registry, name, version);
123 if (!display->compositor_)
124 LOG(ERROR) << "Failed to bind to wl_compositor global";
125 } else if (!display->shm_ && strcmp(interface, "wl_shm") == 0) {
126 display->shm_ = wl::Bind<wl_shm>(registry, name, version);
127 if (!display->shm_)
128 LOG(ERROR) << "Failed to bind to wl_shm global";
129 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) {
130 display->shell_ = wl::Bind<xdg_shell>(registry, name, version);
131 if (!display->shell_) {
132 LOG(ERROR) << "Failed to bind to xdg_shell global";
133 return;
134 }
135 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display);
136 xdg_shell_use_unstable_version(display->shell_.get(),
137 XDG_SHELL_VERSION_CURRENT);
138 }
139 }
140
141 // static
142 void WaylandDisplay::GlobalRemove(void* data,
143 wl_registry* registry,
144 uint32_t name) {
145 NOTIMPLEMENTED();
146 }
147
148 // static
149 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) {
150 xdg_shell_pong(shell, serial);
151 }
152
153 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698