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

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, 10 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
« no previous file with comments | « ui/ozone/platform/wayland/wayland_display.h ('k') | ui/ozone/platform/wayland/wayland_object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 &WaylandDisplay::Global, &WaylandDisplay::GlobalRemove,
23 };
24
25 display_.reset(wl_display_connect(nullptr));
26 if (!display_) {
27 LOG(ERROR) << "Failed to connect to Wayland display";
28 return false;
29 }
30
31 registry_.reset(wl_display_get_registry(display_.get()));
32 if (!registry_) {
33 LOG(ERROR) << "Failed to get Wayland registry";
34 return false;
35 }
36
37 wl_registry_add_listener(registry_.get(), &registry_listener, this);
38 wl_display_roundtrip(display_.get());
39
40 if (!compositor_) {
41 LOG(ERROR) << "No wl_compositor object";
42 return false;
43 }
44 if (!shm_) {
45 LOG(ERROR) << "No wl_shm object";
46 return false;
47 }
48 if (!shell_) {
49 LOG(ERROR) << "No xdg_shell object";
50 return false;
51 }
52
53 return true;
54 }
55
56 void WaylandDisplay::Flush() {
57 DCHECK(display_);
58 wl_display_flush(display_.get());
59 }
60
61 WaylandWindow* WaylandDisplay::GetWindow(gfx::AcceleratedWidget widget) {
62 auto it = window_map_.find(widget);
63 return it == window_map_.end() ? nullptr : it->second;
64 }
65
66 void WaylandDisplay::AddWindow(WaylandWindow* window) {
67 window_map_[window->GetWidget()] = window;
68 }
69
70 void WaylandDisplay::RemoveWindow(WaylandWindow* window) {
71 window_map_.erase(window->GetWidget());
72 }
73
74 void WaylandDisplay::OnDispatcherListChanged() {
75 if (watching_)
76 return;
77
78 DCHECK(display_);
79 DCHECK(base::MessageLoopForUI::IsCurrent());
80 base::MessageLoopForUI::current()->WatchFileDescriptor(
81 wl_display_get_fd(display_.get()), true,
82 base::MessagePumpLibevent::WATCH_READ, &controller_, this);
83 watching_ = true;
84 }
85
86 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) {
87 wl_display_dispatch(display_.get());
88 for (const auto& window : window_map_)
89 window.second->ApplyPendingBounds();
90 }
91
92 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {}
93
94 // static
95 void WaylandDisplay::Global(void* data,
96 wl_registry* registry,
97 uint32_t name,
98 const char* interface,
99 uint32_t version) {
100 static const xdg_shell_listener shell_listener = {
101 &WaylandDisplay::Ping,
102 };
103
104 WaylandDisplay* display = static_cast<WaylandDisplay*>(data);
105 if (!display->compositor_ && strcmp(interface, "wl_compositor") == 0) {
106 display->compositor_ = wl::Bind<wl_compositor>(registry, name, version);
107 if (!display->compositor_)
108 LOG(ERROR) << "Failed to bind to wl_compositor global";
109 } else if (!display->shm_ && strcmp(interface, "wl_shm") == 0) {
110 display->shm_ = wl::Bind<wl_shm>(registry, name, version);
111 if (!display->shm_)
112 LOG(ERROR) << "Failed to bind to wl_shm global";
113 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) {
114 display->shell_ = wl::Bind<xdg_shell>(registry, name, version);
115 if (!display->shell_) {
116 LOG(ERROR) << "Failed to bind to xdg_shell global";
117 return;
118 }
119 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display);
120 xdg_shell_use_unstable_version(display->shell_.get(),
121 XDG_SHELL_VERSION_CURRENT);
122 }
123 }
124
125 // static
126 void WaylandDisplay::GlobalRemove(void* data,
127 wl_registry* registry,
128 uint32_t name) {
129 NOTIMPLEMENTED();
130 }
131
132 // static
133 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) {
134 xdg_shell_pong(shell, serial);
135 }
136
137 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/wayland/wayland_display.h ('k') | ui/ozone/platform/wayland/wayland_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698