| OLD | NEW |
| 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/Xatom.h> |
| 8 #include <X11/XKBlib.h> | 8 #include <X11/XKBlib.h> |
| 9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
| 10 | 10 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| 91 | 91 |
| 92 X11EventSource* X11EventSource::instance_ = nullptr; | 92 X11EventSource* X11EventSource::instance_ = nullptr; |
| 93 | 93 |
| 94 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, | 94 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, |
| 95 XDisplay* display) | 95 XDisplay* display) |
| 96 : delegate_(delegate), | 96 : delegate_(delegate), |
| 97 display_(display), | 97 display_(display), |
| 98 last_seen_server_time_(CurrentTime), | 98 last_seen_server_time_(CurrentTime), |
| 99 event_timestamp_(CurrentTime), |
| 99 dummy_initialized_(false), | 100 dummy_initialized_(false), |
| 100 continue_stream_(true) { | 101 continue_stream_(true) { |
| 101 DCHECK(!instance_); | 102 DCHECK(!instance_); |
| 102 instance_ = this; | 103 instance_ = this; |
| 103 | 104 |
| 104 DCHECK(delegate_); | 105 DCHECK(delegate_); |
| 105 DCHECK(display_); | 106 DCHECK(display_); |
| 106 DeviceDataManagerX11::CreateInstance(); | 107 DeviceDataManagerX11::CreateInstance(); |
| 107 InitializeXkb(display_); | 108 InitializeXkb(display_); |
| 108 } | 109 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 | 178 |
| 178 last_seen_server_time_ = event.xproperty.time; | 179 last_seen_server_time_ = event.xproperty.time; |
| 179 | 180 |
| 180 UMA_HISTOGRAM_CUSTOM_COUNTS( | 181 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 181 "Event.Latency.X11EventSource.UpdateServerTime", | 182 "Event.Latency.X11EventSource.UpdateServerTime", |
| 182 (base::TimeTicks::Now() - start).InMicroseconds(), 1, | 183 (base::TimeTicks::Now() - start).InMicroseconds(), 1, |
| 183 base::TimeDelta::FromMilliseconds(1).InMicroseconds(), 50); | 184 base::TimeDelta::FromMilliseconds(1).InMicroseconds(), 50); |
| 184 return last_seen_server_time_; | 185 return last_seen_server_time_; |
| 185 } | 186 } |
| 186 | 187 |
| 188 void X11EventSource::SetLastSeenServerTime(Time time) { |
| 189 if (time != CurrentTime) { |
| 190 int64_t event_time_64 = time; |
| 191 int64_t time_difference = last_seen_server_time_ - event_time_64; |
| 192 // Ignore timestamps that go backwards. However, X server time is a 32-bit |
| 193 // millisecond counter, so if the time goes backwards by more than half the |
| 194 // range of the 32-bit counter, treat it as a rollover. |
| 195 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1)) |
| 196 last_seen_server_time_ = time; |
| 197 } |
| 198 } |
| 199 |
| 200 Time X11EventSource::GetTimestamp() { |
| 201 if (event_timestamp_ != CurrentTime) { |
| 202 return event_timestamp_; |
| 203 } |
| 204 DVLOG(1) << "Making a round trip to get a recent server timestamp."; |
| 205 return UpdateLastSeenServerTime(); |
| 206 } |
| 207 |
| 187 //////////////////////////////////////////////////////////////////////////////// | 208 //////////////////////////////////////////////////////////////////////////////// |
| 188 // X11EventSource, protected | 209 // X11EventSource, protected |
| 189 | 210 |
| 190 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { | 211 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { |
| 191 bool have_cookie = false; | 212 bool have_cookie = false; |
| 192 if (xevent->type == GenericEvent && | 213 if (xevent->type == GenericEvent && |
| 193 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { | 214 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { |
| 194 have_cookie = true; | 215 have_cookie = true; |
| 195 } | 216 } |
| 196 Time event_time = ExtractTimeFromXEvent(*xevent); | 217 |
| 197 if (event_time != CurrentTime) { | 218 event_timestamp_ = ExtractTimeFromXEvent(*xevent); |
| 198 int64_t event_time_64 = event_time; | 219 SetLastSeenServerTime(event_timestamp_); |
| 199 int64_t time_difference = last_seen_server_time_ - event_time_64; | 220 |
| 200 // Ignore timestamps that go backwards. However, X server time is a 32-bit | |
| 201 // millisecond counter, so if the time goes backwards by more than half the | |
| 202 // range of the 32-bit counter, treat it as a rollover. | |
| 203 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1)) | |
| 204 last_seen_server_time_ = event_time; | |
| 205 } | |
| 206 delegate_->ProcessXEvent(xevent); | 221 delegate_->ProcessXEvent(xevent); |
| 207 PostDispatchEvent(xevent); | 222 PostDispatchEvent(xevent); |
| 223 |
| 224 event_timestamp_ = CurrentTime; |
| 225 |
| 208 if (have_cookie) | 226 if (have_cookie) |
| 209 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); | 227 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); |
| 210 } | 228 } |
| 211 | 229 |
| 212 void X11EventSource::PostDispatchEvent(XEvent* xevent) { | 230 void X11EventSource::PostDispatchEvent(XEvent* xevent) { |
| 213 bool should_update_device_list = false; | 231 bool should_update_device_list = false; |
| 214 | 232 |
| 215 if (xevent->type == GenericEvent) { | 233 if (xevent->type == GenericEvent) { |
| 216 if (xevent->xgeneric.evtype == XI_HierarchyChanged) { | 234 if (xevent->xgeneric.evtype == XI_HierarchyChanged) { |
| 217 should_update_device_list = true; | 235 should_update_device_list = true; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 | 275 |
| 258 void X11EventSource::OnDispatcherListChanged() { | 276 void X11EventSource::OnDispatcherListChanged() { |
| 259 if (!hotplug_event_handler_) { | 277 if (!hotplug_event_handler_) { |
| 260 hotplug_event_handler_.reset(new X11HotplugEventHandler()); | 278 hotplug_event_handler_.reset(new X11HotplugEventHandler()); |
| 261 // Force the initial device query to have an update list of active devices. | 279 // Force the initial device query to have an update list of active devices. |
| 262 hotplug_event_handler_->OnHotplugEvent(); | 280 hotplug_event_handler_->OnHotplugEvent(); |
| 263 } | 281 } |
| 264 } | 282 } |
| 265 | 283 |
| 266 } // namespace ui | 284 } // namespace ui |
| OLD | NEW |