summaryrefslogtreecommitdiffstats
path: root/ui/events
diff options
context:
space:
mode:
authordnicoara <dnicoara@chromium.org>2014-10-22 09:48:40 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-22 16:49:06 +0000
commite1c0f12dd004b3626e643d0699a74ca00adf000e (patch)
tree5af91dcce8ad13796a10e3938b401b9239f545e4 /ui/events
parent20e0c25693e5c1896b24eb902af058eb0691c9cd (diff)
downloadchromium_src-e1c0f12dd004b3626e643d0699a74ca00adf000e.zip
chromium_src-e1c0f12dd004b3626e643d0699a74ca00adf000e.tar.gz
chromium_src-e1c0f12dd004b3626e643d0699a74ca00adf000e.tar.bz2
Reland of [Ozone] Properly initialize multitouch slot values
Original CL https://codereview.chromium.org/671723002/ BUG=424363 NOTRY=true Review URL: https://codereview.chromium.org/674523003 Cr-Commit-Position: refs/heads/master@{#300690}
Diffstat (limited to 'ui/events')
-rw-r--r--ui/events/ozone/evdev/event_device_info.cc52
-rw-r--r--ui/events/ozone/evdev/event_device_info.h12
-rw-r--r--ui/events/ozone/evdev/touch_event_converter_evdev.cc24
-rw-r--r--ui/events/ozone/evdev/touch_event_converter_evdev.h2
4 files changed, 90 insertions, 0 deletions
diff --git a/ui/events/ozone/evdev/event_device_info.cc b/ui/events/ozone/evdev/event_device_info.cc
index 6d75ea9..a59d472 100644
--- a/ui/events/ozone/evdev/event_device_info.cc
+++ b/ui/events/ozone/evdev/event_device_info.cc
@@ -9,6 +9,10 @@
#include "base/logging.h"
#include "base/threading/thread_restrictions.h"
+#if !defined(EVIOCGMTSLOTS)
+#define EVIOCGMTSLOTS(len) _IOC(_IOC_READ, 'E', 0x0a, len)
+#endif
+
namespace ui {
namespace {
@@ -40,6 +44,24 @@ bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) {
return true;
}
+// |request| needs to be the equivalent to:
+// struct input_mt_request_layout {
+// uint32_t code;
+// int32_t values[num_slots];
+// };
+//
+// |size| is num_slots + 1 (for code).
+bool GetSlotValues(int fd, int32_t* request, unsigned int size) {
+ if (ioctl(fd,
+ EVIOCGMTSLOTS(sizeof(int32_t) * size),
+ request) < 0) {
+ DLOG(ERROR) << "failed EVIOCGMTSLOTS(" << request[0] << ") on fd " << fd;
+ return false;
+ }
+
+ return true;
+}
+
} // namespace
EventDeviceInfo::EventDeviceInfo() {
@@ -86,6 +108,20 @@ bool EventDeviceInfo::Initialize(int fd) {
if (!GetAbsInfo(fd, i, &abs_info_[i]))
return false;
+ int max_num_slots = abs_info_[ABS_MT_SLOT].maximum + 1;
+ // |request| is MT code + slots.
+ int32_t request[max_num_slots + 1];
+ for (unsigned int i = ABS_MT_SLOT + 1; i < ABS_MAX; ++i) {
+ memset(request, 0, sizeof(request));
+ request[0] = i;
+ if (HasAbsEvent(i))
+ if (!GetSlotValues(fd, request, max_num_slots + 1))
+ LOG(WARNING) << "Failed to get multitouch values for code " << i;
+
+ slot_values_[i - ABS_MT_SLOT - 1].assign(
+ request + 1, request + max_num_slots + 1);
+ }
+
return true;
}
@@ -145,6 +181,14 @@ int32 EventDeviceInfo::GetAbsMaximum(unsigned int code) const {
return abs_info_[code].maximum;
}
+int32 EventDeviceInfo::GetSlotValue(unsigned int code,
+ unsigned int slot) const {
+ const std::vector<int32_t>& slots = GetMtSlotsForCode(code);
+ DCHECK_LE(0u, slot) << slot << " is an invalid slot";
+ DCHECK_LT(slot, slots.size()) << slot << " is an invalid slot";
+ return slots[slot];
+}
+
bool EventDeviceInfo::HasAbsXY() const {
if (HasAbsEvent(ABS_X) && HasAbsEvent(ABS_Y))
return true;
@@ -182,4 +226,12 @@ bool EventDeviceInfo::IsMappedToScreen() const {
return true;
}
+const std::vector<int32_t>& EventDeviceInfo::GetMtSlotsForCode(int code) const {
+ int index = code - ABS_MT_SLOT - 1;
+ DCHECK_LE(0, index) << code << " is not a valid multi-touch code";
+ DCHECK_LT(index, EVDEV_ABS_MT_COUNT)
+ << code << " is not a valid multi-touch code";
+ return slot_values_[index];
+}
+
} // namespace ui
diff --git a/ui/events/ozone/evdev/event_device_info.h b/ui/events/ozone/evdev/event_device_info.h
index 3217114..adca89e 100644
--- a/ui/events/ozone/evdev/event_device_info.h
+++ b/ui/events/ozone/evdev/event_device_info.h
@@ -8,10 +8,15 @@
#include <limits.h>
#include <linux/input.h>
+#include <vector>
+
#include "base/basictypes.h"
#include "ui/events/ozone/evdev/event_device_util.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
+// ABS_MT_SLOT isn't valid options for EVIOCGMTSLOTS ioctl.
+#define EVDEV_ABS_MT_COUNT (ABS_MAX - ABS_MT_SLOT - 1)
+
namespace ui {
// Device information for Linux input devices
@@ -38,6 +43,7 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
// Properties of absolute axes.
int32 GetAbsMinimum(unsigned int code) const;
int32 GetAbsMaximum(unsigned int code) const;
+ int32 GetSlotValue(unsigned int code, unsigned int slot) const;
// Check input device properties.
bool HasProp(unsigned int code) const;
@@ -53,6 +59,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
bool IsMappedToScreen() const;
private:
+ // Return the slot vector in |slot_values_| for |code|.
+ const std::vector<int32_t>& GetMtSlotsForCode(int code) const;
+
unsigned long ev_bits_[EVDEV_BITS_TO_LONGS(EV_CNT)];
unsigned long key_bits_[EVDEV_BITS_TO_LONGS(KEY_CNT)];
unsigned long rel_bits_[EVDEV_BITS_TO_LONGS(REL_CNT)];
@@ -64,6 +73,9 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
struct input_absinfo abs_info_[ABS_CNT];
+ // Store the values for the multi-touch properties for each slot.
+ std::vector<int32_t> slot_values_[EVDEV_ABS_MT_COUNT];
+
DISALLOW_COPY_AND_ASSIGN(EventDeviceInfo);
};
diff --git a/ui/events/ozone/evdev/touch_event_converter_evdev.cc b/ui/events/ozone/evdev/touch_event_converter_evdev.cc
index c3fc7e2..ef087a1 100644
--- a/ui/events/ozone/evdev/touch_event_converter_evdev.cc
+++ b/ui/events/ozone/evdev/touch_event_converter_evdev.cc
@@ -72,6 +72,17 @@ float TuxelToPixelSize(float val, float num_tuxels, float num_pixels) {
namespace ui {
+TouchEventConverterEvdev::InProgressEvents::InProgressEvents()
+ : x_(0),
+ y_(0),
+ id_(-1),
+ finger_(-1),
+ type_(ET_UNKNOWN),
+ radius_x_(0),
+ radius_y_(0),
+ pressure_(0) {
+}
+
TouchEventConverterEvdev::TouchEventConverterEvdev(
int fd,
base::FilePath path,
@@ -129,6 +140,19 @@ void TouchEventConverterEvdev::Init(const EventDeviceInfo& info) {
cal.bezel_right,
cal.bezel_top,
cal.bezel_bottom);
+
+ for (int i = 0;
+ i < std::min<int>(info.GetAbsMaximum(ABS_MT_SLOT) + 1, MAX_FINGERS);
+ ++i) {
+ events_[i].finger_ = info.GetSlotValue(ABS_MT_TRACKING_ID, i);
+ events_[i].type_ =
+ events_[i].finger_ < 0 ? ET_TOUCH_RELEASED : ET_TOUCH_PRESSED;
+ events_[i].x_ = info.GetSlotValue(ABS_MT_POSITION_X, i);
+ events_[i].y_ = info.GetSlotValue(ABS_MT_POSITION_Y, i);
+ events_[i].radius_x_ = info.GetSlotValue(ABS_MT_TOUCH_MAJOR, i);
+ events_[i].radius_y_ = info.GetSlotValue(ABS_MT_TOUCH_MINOR, i);
+ events_[i].pressure_ = info.GetSlotValue(ABS_MT_PRESSURE, i);
+ }
}
bool TouchEventConverterEvdev::Reinitialize() {
diff --git a/ui/events/ozone/evdev/touch_event_converter_evdev.h b/ui/events/ozone/evdev/touch_event_converter_evdev.h
index 83aa13ac..d36f901 100644
--- a/ui/events/ozone/evdev/touch_event_converter_evdev.h
+++ b/ui/events/ozone/evdev/touch_event_converter_evdev.h
@@ -93,6 +93,8 @@ class EVENTS_OZONE_EVDEV_EXPORT TouchEventConverterEvdev
std::bitset<MAX_FINGERS> altered_slots_;
struct InProgressEvents {
+ InProgressEvents();
+
float x_;
float y_;
int id_; // Device reported "unique" touch point id; -1 means not active