OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
9 #include "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 bitmap->unlockPixels(); | 544 bitmap->unlockPixels(); |
545 } | 545 } |
546 | 546 |
547 return image; | 547 return image; |
548 } | 548 } |
549 | 549 |
550 | 550 |
551 int CoalescePendingMotionEvents(const XEvent* xev, | 551 int CoalescePendingMotionEvents(const XEvent* xev, |
552 XEvent* last_event) { | 552 XEvent* last_event) { |
553 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 553 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
554 int num_coalesed = 0; | 554 int num_coalesced = 0; |
555 Display* display = xev->xany.display; | 555 Display* display = xev->xany.display; |
556 int event_type = xev->xgeneric.evtype; | 556 int event_type = xev->xgeneric.evtype; |
557 | 557 |
558 #if defined(USE_XI2_MT) | 558 DCHECK_EQ(event_type, XI_Motion); |
559 float tracking_id = -1; | |
560 if (event_type == XI_TouchUpdate) { | |
561 if (!ui::ValuatorTracker::GetInstance()->ExtractValuator(*xev, | |
562 ui::ValuatorTracker::VAL_TRACKING_ID, &tracking_id)) | |
563 tracking_id = -1; | |
564 } | |
565 #endif | |
566 | 559 |
567 while (XPending(display)) { | 560 while (XPending(display)) { |
568 XEvent next_event; | 561 XEvent next_event; |
569 XPeekEvent(display, &next_event); | 562 XPeekEvent(display, &next_event); |
570 | 563 |
571 // If we can't get the cookie, abort the check. | 564 // If we can't get the cookie, abort the check. |
572 if (!XGetEventData(next_event.xgeneric.display, &next_event.xcookie)) | 565 if (!XGetEventData(next_event.xgeneric.display, &next_event.xcookie)) |
573 return num_coalesed; | 566 return num_coalesced; |
574 | 567 |
575 // If this isn't from a valid device, throw the event away, as | 568 // If this isn't from a valid device, throw the event away, as |
576 // that's what the message pump would do. Device events come in pairs | 569 // that's what the message pump would do. Device events come in pairs |
577 // with one from the master and one from the slave so there will | 570 // with one from the master and one from the slave so there will |
578 // always be at least one pending. | 571 // always be at least one pending. |
579 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) { | 572 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) { |
580 XFreeEventData(display, &next_event.xcookie); | 573 XFreeEventData(display, &next_event.xcookie); |
581 XNextEvent(display, &next_event); | 574 XNextEvent(display, &next_event); |
582 continue; | 575 continue; |
583 } | 576 } |
584 | 577 |
585 if (next_event.type == GenericEvent && | 578 if (next_event.type == GenericEvent && |
586 next_event.xgeneric.evtype == event_type && | 579 next_event.xgeneric.evtype == event_type && |
587 !ui::GetScrollOffsets(&next_event, NULL, NULL, NULL, NULL, NULL) && | 580 !ui::GetScrollOffsets(&next_event, NULL, NULL, NULL, NULL, NULL) && |
588 !ui::GetFlingData(&next_event, NULL, NULL, NULL, NULL, NULL)) { | 581 !ui::GetFlingData(&next_event, NULL, NULL, NULL, NULL, NULL)) { |
589 XIDeviceEvent* next_xievent = | 582 XIDeviceEvent* next_xievent = |
590 static_cast<XIDeviceEvent*>(next_event.xcookie.data); | 583 static_cast<XIDeviceEvent*>(next_event.xcookie.data); |
591 #if defined(USE_XI2_MT) | |
592 float next_tracking_id = -1; | |
593 if (event_type == XI_TouchUpdate) { | |
594 // If this is a touch motion event (as opposed to mouse motion event), | |
595 // then make sure the events are from the same touch-point. | |
596 if (!ui::ValuatorTracker::GetInstance()->ExtractValuator(next_event, | |
597 ui::ValuatorTracker::VAL_TRACKING_ID, &next_tracking_id)) | |
598 next_tracking_id = -1; | |
599 } | |
600 #endif | |
601 // Confirm that the motion event is targeted at the same window | 584 // Confirm that the motion event is targeted at the same window |
602 // and that no buttons or modifiers have changed. | 585 // and that no buttons or modifiers have changed. |
603 if (xievent->event == next_xievent->event && | 586 if (xievent->event == next_xievent->event && |
604 xievent->child == next_xievent->child && | 587 xievent->child == next_xievent->child && |
605 #if defined(USE_XI2_MT) | |
606 (event_type == XI_Motion || tracking_id == next_tracking_id) && | |
607 #endif | |
608 xievent->buttons.mask_len == next_xievent->buttons.mask_len && | 588 xievent->buttons.mask_len == next_xievent->buttons.mask_len && |
609 (memcmp(xievent->buttons.mask, | 589 (memcmp(xievent->buttons.mask, |
610 next_xievent->buttons.mask, | 590 next_xievent->buttons.mask, |
611 xievent->buttons.mask_len) == 0) && | 591 xievent->buttons.mask_len) == 0) && |
612 xievent->mods.base == next_xievent->mods.base && | 592 xievent->mods.base == next_xievent->mods.base && |
613 xievent->mods.latched == next_xievent->mods.latched && | 593 xievent->mods.latched == next_xievent->mods.latched && |
614 xievent->mods.locked == next_xievent->mods.locked && | 594 xievent->mods.locked == next_xievent->mods.locked && |
615 xievent->mods.effective == next_xievent->mods.effective) { | 595 xievent->mods.effective == next_xievent->mods.effective) { |
616 XFreeEventData(display, &next_event.xcookie); | 596 XFreeEventData(display, &next_event.xcookie); |
617 // Free the previous cookie. | 597 // Free the previous cookie. |
618 if (num_coalesed > 0) | 598 if (num_coalesced > 0) |
619 XFreeEventData(display, &last_event->xcookie); | 599 XFreeEventData(display, &last_event->xcookie); |
620 // Get the event and its cookie data. | 600 // Get the event and its cookie data. |
621 XNextEvent(display, last_event); | 601 XNextEvent(display, last_event); |
622 XGetEventData(display, &last_event->xcookie); | 602 XGetEventData(display, &last_event->xcookie); |
623 ++num_coalesed; | 603 ++num_coalesced; |
624 continue; | 604 continue; |
625 } else { | 605 } else { |
626 // This isn't an event we want so free its cookie data. | 606 // This isn't an event we want so free its cookie data. |
627 XFreeEventData(display, &next_event.xcookie); | 607 XFreeEventData(display, &next_event.xcookie); |
628 } | 608 } |
629 } | 609 } |
630 break; | 610 break; |
631 } | 611 } |
632 | 612 |
633 if (num_coalesed > 0) { | 613 if (num_coalesced > 0) { |
634 base::TimeDelta delta = ui::EventTimeFromNative(last_event) - | 614 base::TimeDelta delta = ui::EventTimeFromNative(last_event) - |
635 ui::EventTimeFromNative(const_cast<XEvent*>(xev)); | 615 ui::EventTimeFromNative(const_cast<XEvent*>(xev)); |
636 if (event_type == XI_Motion) { | 616 UMA_HISTOGRAM_COUNTS_10000("Event.CoalescedCount.Mouse", num_coalesced); |
637 UMA_HISTOGRAM_COUNTS_10000("Event.CoalescedCount.Mouse", num_coalesed); | 617 UMA_HISTOGRAM_TIMES("Event.CoalescedLatency.Mouse", delta); |
638 UMA_HISTOGRAM_TIMES("Event.CoalescedLatency.Mouse", delta); | |
639 } else { | |
640 #if defined(USE_XI2_MT) | |
641 DCHECK_EQ(event_type, XI_TouchUpdate); | |
642 #endif | |
643 UMA_HISTOGRAM_COUNTS_10000("Event.CoalescedCount.Touch", num_coalesed); | |
644 UMA_HISTOGRAM_TIMES("Event.CoalescedLatency.Touch", delta); | |
645 } | |
646 } | 618 } |
647 return num_coalesed; | 619 return num_coalesced; |
648 } | 620 } |
649 #endif | 621 #endif |
650 | 622 |
651 void HideHostCursor() { | 623 void HideHostCursor() { |
652 CR_DEFINE_STATIC_LOCAL(XScopedCursor, invisible_cursor, | 624 CR_DEFINE_STATIC_LOCAL(XScopedCursor, invisible_cursor, |
653 (CreateInvisibleCursor(), ui::GetXDisplay())); | 625 (CreateInvisibleCursor(), ui::GetXDisplay())); |
654 XDefineCursor(ui::GetXDisplay(), DefaultRootWindow(ui::GetXDisplay()), | 626 XDefineCursor(ui::GetXDisplay(), DefaultRootWindow(ui::GetXDisplay()), |
655 invisible_cursor.get()); | 627 invisible_cursor.get()); |
656 } | 628 } |
657 | 629 |
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1809 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1781 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1810 << "minor_code " << static_cast<int>(error_event.minor_code) | 1782 << "minor_code " << static_cast<int>(error_event.minor_code) |
1811 << " (" << request_str << ")"; | 1783 << " (" << request_str << ")"; |
1812 } | 1784 } |
1813 | 1785 |
1814 // ---------------------------------------------------------------------------- | 1786 // ---------------------------------------------------------------------------- |
1815 // End of x11_util_internal.h | 1787 // End of x11_util_internal.h |
1816 | 1788 |
1817 | 1789 |
1818 } // namespace ui | 1790 } // namespace ui |
OLD | NEW |