Commit 718a6f6f authored by Nick Diego Yamane's avatar Nick Diego Yamane Committed by Commit Bot

x11: Bring back MontionNotify events coalescing

MontionNotify XEvents coalescing logic has been accidentally lost after
the PlatformEvent migration CLs have landed (crbug.com/965991), what
leads to some performance hit/regressions. This patch adds it back as an
attempt to address regressions reported at crbug.com/1051325. Even
though the numbers the report seem quite noisy and unstable, [1] shows
that this was the major cause for such perf regression.

R=thomasanderson@chromium.org

[1] https://pinpoint-dot-chromeperf.appspot.com/job/172c2f5a620000

Bug: 1051325, 965991
Change-Id: Ib5d06867d97633c3593584222571b8d910deb304
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062098Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarThomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Nick Yamane <nickdiego@igalia.com>
Cr-Commit-Position: refs/heads/master@{#742892}
parent 06775374
......@@ -358,15 +358,34 @@ XcursorImage* SkBitmapToXcursorImage(const SkBitmap* cursor_image,
}
int CoalescePendingMotionEvents(const XEvent* xev, XEvent* last_event) {
XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
int num_coalesced = 0;
DCHECK(xev->type == MotionNotify || xev->type == GenericEvent);
XDisplay* display = xev->xany.display;
int event_type = xev->xgeneric.evtype;
XEvent next_event;
bool is_motion = false;
int num_coalesced = 0;
if (xev->type == MotionNotify) {
is_motion = true;
while (XPending(display)) {
XPeekEvent(xev->xany.display, &next_event);
// Discard all but the most recent motion event that targets the same
// window with unchanged state.
if (next_event.type == MotionNotify &&
next_event.xmotion.window == xev->xmotion.window &&
next_event.xmotion.subwindow == xev->xmotion.subwindow &&
next_event.xmotion.state == xev->xmotion.state) {
XNextEvent(xev->xany.display, last_event);
} else {
break;
}
}
} else {
int event_type = xev->xgeneric.evtype;
XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data);
DCHECK(event_type == XI_Motion || event_type == XI_TouchUpdate);
is_motion = event_type == XI_Motion;
while (XPending(display)) {
XEvent next_event;
XPeekEvent(display, &next_event);
// If we can't get the cookie, abort the check.
......@@ -377,7 +396,8 @@ int CoalescePendingMotionEvents(const XEvent* xev, XEvent* last_event) {
// that's what the message pump would do. Device events come in pairs
// with one from the master and one from the slave so there will
// always be at least one pending.
if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) {
if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(
&next_event)) {
XFreeEventData(display, &next_event.xcookie);
XNextEvent(display, &next_event);
continue;
......@@ -418,8 +438,9 @@ int CoalescePendingMotionEvents(const XEvent* xev, XEvent* last_event) {
XFreeEventData(display, &next_event.xcookie);
break;
}
}
if (event_type == XI_Motion && num_coalesced > 0)
if (is_motion && num_coalesced > 0)
UMA_HISTOGRAM_COUNTS_10000("Event.CoalescedCount.Mouse", num_coalesced);
return num_coalesced;
}
......
......@@ -12,6 +12,7 @@
#include "ui/events/event_utils.h"
#include "ui/events/keycodes/keyboard_code_conversion_x.h"
#include "ui/events/pointer_details.h"
#include "ui/events/types/event_type.h"
#include "ui/events/x/events_x_utils.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/x/x11.h"
......
......@@ -91,12 +91,13 @@ ui::XWindow::Configuration ConvertInitPropertiesToXWindowConfig(
// Coalesce touch/mouse events if needed
bool CoalesceEventsIfNeeded(XEvent* const xev, EventType type, XEvent* out) {
if (xev->type != GenericEvent ||
(type != ui::ET_TOUCH_MOVED && type != ui::ET_MOUSE_MOVED &&
type != ui::ET_MOUSE_DRAGGED)) {
return false;
}
if (xev->type == MotionNotify ||
(xev->type == GenericEvent &&
(type == ui::ET_TOUCH_MOVED || type == ui::ET_MOUSE_MOVED ||
type == ui::ET_MOUSE_DRAGGED))) {
return ui::CoalescePendingMotionEvents(xev, out) > 0;
}
return false;
}
} // namespace
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment