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

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

Issue 1739193004: ozone/platform/wayland: Use more realistic event processing and request flushing in tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@wayland-test2
Patch Set: Use watching_ instead of base::MessageLoopForUI::IsCurrent() Created 4 years, 9 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
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/logging.h" 10 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "ui/ozone/platform/wayland/wayland_object.h" 12 #include "ui/ozone/platform/wayland/wayland_object.h"
12 #include "ui/ozone/platform/wayland/wayland_window.h" 13 #include "ui/ozone/platform/wayland/wayland_window.h"
13 14
14 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version"); 15 static_assert(XDG_SHELL_VERSION_CURRENT == 5, "Unsupported xdg-shell version");
15 16
16 namespace ui { 17 namespace ui {
17 namespace { 18 namespace {
18 const uint32_t kMaxCompositorVersion = 4; 19 const uint32_t kMaxCompositorVersion = 4;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 return false; 54 return false;
54 } 55 }
55 if (!shell_) { 56 if (!shell_) {
56 LOG(ERROR) << "No xdg_shell object"; 57 LOG(ERROR) << "No xdg_shell object";
57 return false; 58 return false;
58 } 59 }
59 60
60 return true; 61 return true;
61 } 62 }
62 63
63 void WaylandDisplay::Flush() { 64 bool WaylandDisplay::StartProcessingEvents() {
65 if (watching_)
66 return true;
67
64 DCHECK(display_); 68 DCHECK(display_);
65 wl_display_flush(display_.get()); 69 wl_display_flush(display_.get());
70
71 DCHECK(base::MessageLoopForUI::IsCurrent());
72 if (!base::MessageLoopForUI::current()->WatchFileDescriptor(
73 wl_display_get_fd(display_.get()), true,
74 base::MessagePumpLibevent::WATCH_READ, &controller_, this))
75 return false;
76
77 watching_ = true;
78 return true;
79 }
80
81 void WaylandDisplay::ScheduleFlush() {
82 if (scheduled_flush_ || !watching_)
83 return;
84 base::MessageLoopForUI::current()->task_runner()->PostTask(
85 FROM_HERE, base::Bind(&WaylandDisplay::Flush, base::Unretained(this)));
86 scheduled_flush_ = true;
66 } 87 }
67 88
68 WaylandWindow* WaylandDisplay::GetWindow(gfx::AcceleratedWidget widget) { 89 WaylandWindow* WaylandDisplay::GetWindow(gfx::AcceleratedWidget widget) {
69 auto it = window_map_.find(widget); 90 auto it = window_map_.find(widget);
70 return it == window_map_.end() ? nullptr : it->second; 91 return it == window_map_.end() ? nullptr : it->second;
71 } 92 }
72 93
73 void WaylandDisplay::AddWindow(gfx::AcceleratedWidget widget, 94 void WaylandDisplay::AddWindow(gfx::AcceleratedWidget widget,
74 WaylandWindow* window) { 95 WaylandWindow* window) {
75 window_map_[widget] = window; 96 window_map_[widget] = window;
76 } 97 }
77 98
78 void WaylandDisplay::RemoveWindow(gfx::AcceleratedWidget widget) { 99 void WaylandDisplay::RemoveWindow(gfx::AcceleratedWidget widget) {
79 window_map_.erase(widget); 100 window_map_.erase(widget);
80 } 101 }
81 102
82 void WaylandDisplay::OnDispatcherListChanged() { 103 void WaylandDisplay::OnDispatcherListChanged() {
83 if (watching_) 104 StartProcessingEvents();
84 return; 105 }
85 106
86 DCHECK(display_); 107 void WaylandDisplay::Flush() {
87 DCHECK(base::MessageLoopForUI::IsCurrent()); 108 wl_display_flush(display_.get());
88 base::MessageLoopForUI::current()->WatchFileDescriptor( 109 scheduled_flush_ = false;
89 wl_display_get_fd(display_.get()), true,
90 base::MessagePumpLibevent::WATCH_READ, &controller_, this);
91 watching_ = true;
92 } 110 }
93 111
94 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) { 112 void WaylandDisplay::OnFileCanReadWithoutBlocking(int fd) {
95 wl_display_dispatch(display_.get()); 113 wl_display_dispatch(display_.get());
96 for (const auto& window : window_map_) 114 for (const auto& window : window_map_)
97 window.second->ApplyPendingBounds(); 115 window.second->ApplyPendingBounds();
98 } 116 }
99 117
100 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {} 118 void WaylandDisplay::OnFileCanWriteWithoutBlocking(int fd) {}
101 119
(...skipping 22 matching lines...) Expand all
124 display->shell_ = wl::Bind<xdg_shell>( 142 display->shell_ = wl::Bind<xdg_shell>(
125 registry, name, std::min(version, kMaxXdgShellVersion)); 143 registry, name, std::min(version, kMaxXdgShellVersion));
126 if (!display->shell_) { 144 if (!display->shell_) {
127 LOG(ERROR) << "Failed to bind to xdg_shell global"; 145 LOG(ERROR) << "Failed to bind to xdg_shell global";
128 return; 146 return;
129 } 147 }
130 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display); 148 xdg_shell_add_listener(display->shell_.get(), &shell_listener, display);
131 xdg_shell_use_unstable_version(display->shell_.get(), 149 xdg_shell_use_unstable_version(display->shell_.get(),
132 XDG_SHELL_VERSION_CURRENT); 150 XDG_SHELL_VERSION_CURRENT);
133 } 151 }
152
153 display->ScheduleFlush();
134 } 154 }
135 155
136 // static 156 // static
137 void WaylandDisplay::GlobalRemove(void* data, 157 void WaylandDisplay::GlobalRemove(void* data,
138 wl_registry* registry, 158 wl_registry* registry,
139 uint32_t name) { 159 uint32_t name) {
140 NOTIMPLEMENTED(); 160 NOTIMPLEMENTED();
141 } 161 }
142 162
143 // static 163 // static
144 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) { 164 void WaylandDisplay::Ping(void* data, xdg_shell* shell, uint32_t serial) {
165 WaylandDisplay* display = static_cast<WaylandDisplay*>(data);
145 xdg_shell_pong(shell, serial); 166 xdg_shell_pong(shell, serial);
167 display->ScheduleFlush();
146 } 168 }
147 169
148 } // namespace ui 170 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/wayland/wayland_display.h ('k') | ui/ozone/platform/wayland/wayland_display_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698