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

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: Use base::SharedMemory, expand ObjectTraits macros, etc 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 = {
rjkroege 2016/01/25 20:41:31 is Chrome allowed to use this style of constructio
Michael Forney 2016/01/26 02:25:26 Good question. It looks like designated initialize
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 WaylandWindow* WaylandDisplay::GetWindow(gfx::AcceleratedWidget widget) {
63 auto it = windows_.find(widget);
64 return it == windows_.end() ? nullptr : it->second;
65 }
66
67 void WaylandDisplay::AddWindow(WaylandWindow* window) {
68 windows_[window->GetWidget()] = window;
69 }
70
71 void WaylandDisplay::RemoveWindow(WaylandWindow* window) {
72 windows_.erase(window->GetWidget());
73 }
74
75 void WaylandDisplay::OnDispatcherListChanged() {
76 if (watching_)
77 return;
78
79 DCHECK(display_);
80 DCHECK(base::MessageLoopForUI::IsCurrent());
81 base::MessageLoopForUI::current()->WatchFileDescriptor(
82 wl_display_get_fd(display_.get()), true,
83 base::MessagePumpLibevent::WATCH_READ, &controller_, this);
84 watching_ = true;
85 }
86
87 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) {
88 wl_display_dispatch(display_.get());
89 for (const auto& window : windows_)
90 window.second->ApplyPendingBounds();
91 }
92
93 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {}
94
95 // static
96 void WaylandDisplay::Global(void* data,
97 wl_registry* registry,
98 uint32_t name,
99 const char* interface,
100 uint32_t version) {
101 static const xdg_shell_listener shell_listener = {
102 .ping = &WaylandDisplay::Ping,
103 };
104
105 WaylandDisplay* display = static_cast<WaylandDisplay*>(data);
106 if (!display->compositor_ && strcmp(interface, "wl_compositor") == 0) {
107 display->compositor_ = wl::Bind<wl_compositor>(registry, name, version);
108 if (!display->compositor_)
109 LOG(ERROR) << "Failed to bind to wl_compositor global";
110 } else if (!display->shm_ && strcmp(interface, "wl_shm") == 0) {
111 display->shm_ = wl::Bind<wl_shm>(registry, name, version);
112 if (!display->shm_)
113 LOG(ERROR) << "Failed to bind to wl_shm global";
114 } else if (!display->shell_ && strcmp(interface, "xdg_shell") == 0) {
115 display->shell_ = wl::Bind<xdg_shell>(registry, name, version);
116 if (!display->shell_) {
117 LOG(ERROR) << "Failed to bind to xdg_shell global";
118 return;
119 }
120 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display);
121 xdg_shell_use_unstable_version(display->shell_.get(),
122 XDG_SHELL_VERSION_CURRENT);
123 }
124 }
125
126 // static
127 void WaylandDisplay::GlobalRemove(void* data,
128 wl_registry* registry,
129 uint32_t name) {
130 NOTIMPLEMENTED();
131 }
132
133 // static
134 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) {
135 xdg_shell_pong(shell, serial);
136 }
137
138 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698