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

Side by Side Diff: ui/events/platform/x11/x11_event_source.cc

Issue 1949393007: X11: Better timestamp handling for _NET_ACTIVE_WINDOW (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: C++ style casts and remove dummy_data_ Created 4 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/events/platform/x11/x11_event_source.h" 5 #include "ui/events/platform/x11/x11_event_source.h"
6 6
7 #include <X11/Xatom.h>
7 #include <X11/XKBlib.h> 8 #include <X11/XKBlib.h>
8 #include <X11/Xlib.h> 9 #include <X11/Xlib.h>
9 10
10 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram_macros.h"
11 #include "ui/events/devices/x11/device_data_manager_x11.h" 13 #include "ui/events/devices/x11/device_data_manager_x11.h"
12 #include "ui/events/devices/x11/touch_factory_x11.h" 14 #include "ui/events/devices/x11/touch_factory_x11.h"
13 #include "ui/events/event_utils.h" 15 #include "ui/events/event_utils.h"
14 #include "ui/events/platform/platform_event_dispatcher.h" 16 #include "ui/events/platform/platform_event_dispatcher.h"
15 #include "ui/events/platform/x11/x11_hotplug_event_handler.h" 17 #include "ui/events/platform/x11/x11_hotplug_event_handler.h"
16 18
17 namespace ui { 19 namespace ui {
18 20
19 namespace { 21 namespace {
20 22
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return CurrentTime; 73 return CurrentTime;
72 } 74 }
73 75
74 void UpdateDeviceList() { 76 void UpdateDeviceList() {
75 XDisplay* display = gfx::GetXDisplay(); 77 XDisplay* display = gfx::GetXDisplay();
76 DeviceListCacheX11::GetInstance()->UpdateDeviceList(display); 78 DeviceListCacheX11::GetInstance()->UpdateDeviceList(display);
77 TouchFactory::GetInstance()->UpdateDeviceList(display); 79 TouchFactory::GetInstance()->UpdateDeviceList(display);
78 DeviceDataManagerX11::GetInstance()->UpdateDeviceList(display); 80 DeviceDataManagerX11::GetInstance()->UpdateDeviceList(display);
79 } 81 }
80 82
83 Bool IsPropertyNotifyForTimestamp(Display* display,
84 XEvent* event,
85 XPointer arg) {
86 return event->type == PropertyNotify &&
87 event->xproperty.window == *reinterpret_cast<Window*>(arg);
88 }
89
81 } // namespace 90 } // namespace
82 91
83 X11EventSource* X11EventSource::instance_ = nullptr; 92 X11EventSource* X11EventSource::instance_ = nullptr;
84 93
85 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, 94 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate,
86 XDisplay* display) 95 XDisplay* display)
87 : delegate_(delegate), 96 : delegate_(delegate),
88 display_(display), 97 display_(display),
89 last_seen_server_time_(CurrentTime), 98 last_seen_server_time_(CurrentTime),
99 dummy_initialized_(false),
90 continue_stream_(true) { 100 continue_stream_(true) {
91 DCHECK(!instance_); 101 DCHECK(!instance_);
92 instance_ = this; 102 instance_ = this;
93 103
94 DCHECK(delegate_); 104 DCHECK(delegate_);
95 DCHECK(display_); 105 DCHECK(display_);
96 DeviceDataManagerX11::CreateInstance(); 106 DeviceDataManagerX11::CreateInstance();
97 InitializeXkb(display_); 107 InitializeXkb(display_);
98 } 108 }
99 109
100 X11EventSource::~X11EventSource() { 110 X11EventSource::~X11EventSource() {
101 DCHECK_EQ(this, instance_); 111 DCHECK_EQ(this, instance_);
102 instance_ = nullptr; 112 instance_ = nullptr;
113 if (dummy_initialized_)
114 XDestroyWindow(display_, dummy_window_);
103 } 115 }
104 116
105 // static 117 // static
106 X11EventSource* X11EventSource::GetInstance() { 118 X11EventSource* X11EventSource::GetInstance() {
107 DCHECK(instance_); 119 DCHECK(instance_);
108 return instance_; 120 return instance_;
109 } 121 }
110 122
111 //////////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////////
112 // X11EventSource, public 124 // X11EventSource, public
(...skipping 14 matching lines...) Expand all
127 void X11EventSource::BlockUntilWindowMapped(XID window) { 139 void X11EventSource::BlockUntilWindowMapped(XID window) {
128 XEvent event; 140 XEvent event;
129 do { 141 do {
130 // Block until there's a message of |event_mask| type on |w|. Then remove 142 // Block until there's a message of |event_mask| type on |w|. Then remove
131 // it from the queue and stuff it in |event|. 143 // it from the queue and stuff it in |event|.
132 XWindowEvent(display_, window, StructureNotifyMask, &event); 144 XWindowEvent(display_, window, StructureNotifyMask, &event);
133 ExtractCookieDataDispatchEvent(&event); 145 ExtractCookieDataDispatchEvent(&event);
134 } while (event.type != MapNotify); 146 } while (event.type != MapNotify);
135 } 147 }
136 148
149 Time X11EventSource::UpdateLastSeenServerTime() {
150 base::TimeTicks start = base::TimeTicks::Now();
151
152 DCHECK(display_);
153
154 if (!dummy_initialized_) {
155 // Create a new Window and Atom that will be used for the property change.
156 dummy_window_ = XCreateSimpleWindow(display_, DefaultRootWindow(display_),
157 0, 0, 1, 1, 0, 0, 0);
158 dummy_atom_ = XInternAtom(display_, "CHROMIUM_TIMESTAMP", False);
159 XSelectInput(display_, dummy_window_, PropertyChangeMask);
160 dummy_initialized_ = true;
161 }
162
163 // Make a no-op property change on |dummy_window_|.
164 XChangeProperty(display_, dummy_window_, dummy_atom_, XA_STRING, 8,
165 PropModeAppend, nullptr, 0);
166
167 // Observe the resulting PropertyNotify event to obtain the timestamp.
168 XEvent event;
169 XIfEvent(display_, &event, IsPropertyNotifyForTimestamp,
170 reinterpret_cast<XPointer>(&dummy_window_));
171
172 last_seen_server_time_ = event.xproperty.time;
173
174 UMA_HISTOGRAM_TIMES("Event.Latency.X11EventSource.UpdateServerTime",
rkaplow 2016/05/13 21:30:44 you can used SCOPED_UMA_HISTOGRAM_TIMER if you'd l
Tom (Use chromium acct) 2016/05/14 04:18:39 Done.
175 base::TimeTicks::Now() - start);
176 return last_seen_server_time_;
177 }
178
137 //////////////////////////////////////////////////////////////////////////////// 179 ////////////////////////////////////////////////////////////////////////////////
138 // X11EventSource, protected 180 // X11EventSource, protected
139 181
140 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { 182 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) {
141 bool have_cookie = false; 183 bool have_cookie = false;
142 if (xevent->type == GenericEvent && 184 if (xevent->type == GenericEvent &&
143 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { 185 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) {
144 have_cookie = true; 186 have_cookie = true;
145 } 187 }
146 Time event_time = ExtractTimeFromXEvent(*xevent); 188 Time event_time = ExtractTimeFromXEvent(*xevent);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 225
184 void X11EventSource::OnDispatcherListChanged() { 226 void X11EventSource::OnDispatcherListChanged() {
185 if (!hotplug_event_handler_) { 227 if (!hotplug_event_handler_) {
186 hotplug_event_handler_.reset(new X11HotplugEventHandler()); 228 hotplug_event_handler_.reset(new X11HotplugEventHandler());
187 // Force the initial device query to have an update list of active devices. 229 // Force the initial device query to have an update list of active devices.
188 hotplug_event_handler_->OnHotplugEvent(); 230 hotplug_event_handler_->OnHotplugEvent();
189 } 231 }
190 } 232 }
191 233
192 } // namespace ui 234 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698