Commit 826d0a0c authored by dnicoara's avatar dnicoara Committed by Commit bot

[Ozone] Properly initialize multitouch slot values

BUG=424363
NOTRY=true

Review URL: https://codereview.chromium.org/671723002

Cr-Commit-Position: refs/heads/master@{#300680}
parent cbaf51be
......@@ -40,6 +40,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) {
LOG(ERROR) << "failed EVIOCGMTSLOTS(" << request[0] << ") on fd " << fd;
return false;
}
return true;
}
} // namespace
EventDeviceInfo::EventDeviceInfo() {
......@@ -86,6 +104,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))
return false;
slot_values_[i - ABS_MT_SLOT - 1].assign(
request + 1, request + max_num_slots + 1);
}
return true;
}
......@@ -145,6 +177,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 +222,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
......@@ -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);
};
......
......@@ -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() {
......
......@@ -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
......
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