Chromium Code Reviews| 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/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 Loading... | |
| 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 == DefaultRootWindow(display) && | |
| 88 event->xproperty.atom == *(Atom*)arg; | |
| 89 } | |
| 90 | |
| 81 } // namespace | 91 } // namespace |
| 82 | 92 |
| 83 X11EventSource* X11EventSource::instance_ = nullptr; | 93 X11EventSource* X11EventSource::instance_ = nullptr; |
| 84 | 94 |
| 85 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, | 95 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, |
| 86 XDisplay* display) | 96 XDisplay* display) |
| 87 : delegate_(delegate), | 97 : delegate_(delegate), |
| 88 display_(display), | 98 display_(display), |
| 89 last_seen_server_time_(CurrentTime), | 99 last_seen_server_time_(CurrentTime), |
| 90 continue_stream_(true) { | 100 continue_stream_(true) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 void X11EventSource::BlockUntilWindowMapped(XID window) { | 137 void X11EventSource::BlockUntilWindowMapped(XID window) { |
| 128 XEvent event; | 138 XEvent event; |
| 129 do { | 139 do { |
| 130 // Block until there's a message of |event_mask| type on |w|. Then remove | 140 // Block until there's a message of |event_mask| type on |w|. Then remove |
| 131 // it from the queue and stuff it in |event|. | 141 // it from the queue and stuff it in |event|. |
| 132 XWindowEvent(display_, window, StructureNotifyMask, &event); | 142 XWindowEvent(display_, window, StructureNotifyMask, &event); |
| 133 ExtractCookieDataDispatchEvent(&event); | 143 ExtractCookieDataDispatchEvent(&event); |
| 134 } while (event.type != MapNotify); | 144 } while (event.type != MapNotify); |
| 135 } | 145 } |
| 136 | 146 |
| 147 Time X11EventSource::UpdateLastSeenServerTime() { | |
| 148 base::TimeTicks start = base::TimeTicks::Now(); | |
| 149 | |
| 150 const char kAtomStr[] = "X11_EVENT_SOURCE_UPDATE_SERVER_TIME_DUMMY_ATOM"; | |
| 151 | |
| 152 DCHECK(display_); | |
| 153 Window window = DefaultRootWindow(display_); | |
| 154 const unsigned char dummy_data = 0; | |
| 155 Atom dummy_atom = XInternAtom(display_, kAtomStr, False); | |
| 156 | |
| 157 XWindowAttributes attributes; | |
| 158 XGetWindowAttributes(display_, window, &attributes); | |
|
danakj
2016/05/12 21:32:50
Round trips :(
Can you just use some arbitrary ne
| |
| 159 long old_event_mask = attributes.your_event_mask; | |
| 160 | |
| 161 // Make a no-op property change on the root window. | |
| 162 XSelectInput(display_, window, old_event_mask | PropertyChangeMask); | |
| 163 XChangeProperty(display_, window, dummy_atom, XA_INTEGER, 8, PropModeReplace, | |
| 164 &dummy_data, 1); | |
| 165 | |
| 166 | |
| 167 // Observe the resulting PropertyChange to obtain the timestamp. | |
| 168 XEvent event; | |
| 169 XIfEvent(display_, &event, IsPropertyNotifyForTimestamp, | |
| 170 (XPointer)&dummy_atom); | |
| 171 | |
| 172 // Clean up: don't leave a dummy property in the root window. | |
| 173 XSelectInput(display_, window, old_event_mask); | |
| 174 XDeleteProperty(display_, window, dummy_atom); | |
| 175 XFlush(display_); | |
| 176 | |
| 177 last_seen_server_time_ = event.xproperty.time; | |
| 178 | |
| 179 UMA_HISTOGRAM_TIMES("Event.Latency.X11EventSource.UpdateServerTime", | |
| 180 base::TimeTicks::Now() - start); | |
| 181 return last_seen_server_time_; | |
| 182 } | |
| 183 | |
| 137 //////////////////////////////////////////////////////////////////////////////// | 184 //////////////////////////////////////////////////////////////////////////////// |
| 138 // X11EventSource, protected | 185 // X11EventSource, protected |
| 139 | 186 |
| 140 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { | 187 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { |
| 141 bool have_cookie = false; | 188 bool have_cookie = false; |
| 142 if (xevent->type == GenericEvent && | 189 if (xevent->type == GenericEvent && |
| 143 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { | 190 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { |
| 144 have_cookie = true; | 191 have_cookie = true; |
| 145 } | 192 } |
| 146 Time event_time = ExtractTimeFromXEvent(*xevent); | 193 Time event_time = ExtractTimeFromXEvent(*xevent); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 | 230 |
| 184 void X11EventSource::OnDispatcherListChanged() { | 231 void X11EventSource::OnDispatcherListChanged() { |
| 185 if (!hotplug_event_handler_) { | 232 if (!hotplug_event_handler_) { |
| 186 hotplug_event_handler_.reset(new X11HotplugEventHandler()); | 233 hotplug_event_handler_.reset(new X11HotplugEventHandler()); |
| 187 // Force the initial device query to have an update list of active devices. | 234 // Force the initial device query to have an update list of active devices. |
| 188 hotplug_event_handler_->OnHotplugEvent(); | 235 hotplug_event_handler_->OnHotplugEvent(); |
| 189 } | 236 } |
| 190 } | 237 } |
| 191 | 238 |
| 192 } // namespace ui | 239 } // namespace ui |
| OLD | NEW |