Commit 8765e8c4 authored by spang's avatar spang Committed by Commit bot

ozone: evdev: Allow setting slot values in EventDeviceInfo

Currently we stub out TouchEventConverterEvdev::Initialize() in the
tests, but we now need to fix that because that's where we'll detect if a
device is MT-capable.

Initialize() looks up slot values, so we'll need to populate them from
captured device descriptions in CapabilitiesToDeviceInfo(). The initial
state is all zeroes except for tracking id (this matches kernel initial
slot state).

While we're here, clean up a bunch of the slot values setup & access
code in EventDeviceInfo.

BUG=461518
TEST=events_unittests

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

Cr-Commit-Position: refs/heads/master@{#322580}
parent b7289d59
...@@ -52,9 +52,9 @@ bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) { ...@@ -52,9 +52,9 @@ bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) {
// //
// |size| is num_slots + 1 (for code). // |size| is num_slots + 1 (for code).
bool GetSlotValues(int fd, int32_t* request, unsigned int size) { bool GetSlotValues(int fd, int32_t* request, unsigned int size) {
if (ioctl(fd, size_t data_size = size * sizeof(*request);
EVIOCGMTSLOTS(sizeof(int32_t) * size),
request) < 0) { if (ioctl(fd, EVIOCGMTSLOTS(data_size), request) < 0) {
DLOG(ERROR) << "failed EVIOCGMTSLOTS(" << request[0] << ") on fd " << fd; DLOG(ERROR) << "failed EVIOCGMTSLOTS(" << request[0] << ") on fd " << fd;
return false; return false;
} }
...@@ -117,18 +117,23 @@ bool EventDeviceInfo::Initialize(int fd) { ...@@ -117,18 +117,23 @@ bool EventDeviceInfo::Initialize(int fd) {
if (!GetAbsInfo(fd, i, &abs_info_[i])) if (!GetAbsInfo(fd, i, &abs_info_[i]))
return false; return false;
int max_num_slots = abs_info_[ABS_MT_SLOT].maximum + 1; int max_num_slots = GetAbsMtSlotCount();
// |request| is MT code + slots. // |request| is MT code + slots.
int32_t request[max_num_slots + 1]; int32_t request[max_num_slots + 1];
for (unsigned int i = ABS_MT_SLOT + 1; i < ABS_MAX; ++i) { int32_t* request_code = &request[0];
int32_t* request_slots = &request[1];
for (unsigned int i = EVDEV_ABS_MT_FIRST; i <= EVDEV_ABS_MT_LAST; ++i) {
if (!HasAbsEvent(i))
continue;
memset(request, 0, sizeof(request)); memset(request, 0, sizeof(request));
request[0] = i; *request_code = i;
if (HasAbsEvent(i)) if (!GetSlotValues(fd, request, max_num_slots + 1))
if (!GetSlotValues(fd, request, max_num_slots + 1)) LOG(WARNING) << "Failed to get multitouch values for code " << i;
LOG(WARNING) << "Failed to get multitouch values for code " << i;
slot_values_[i - ABS_MT_SLOT - 1].assign( std::vector<int32_t>* slots = &slot_values_[i - EVDEV_ABS_MT_FIRST];
request + 1, request + max_num_slots + 1); slots->assign(request_slots, request_slots + max_num_slots);
} }
return true; return true;
...@@ -174,6 +179,15 @@ void EventDeviceInfo::SetAbsInfo(unsigned int code, ...@@ -174,6 +179,15 @@ void EventDeviceInfo::SetAbsInfo(unsigned int code,
memcpy(&abs_info_[code], &abs_info, sizeof(abs_info)); memcpy(&abs_info_[code], &abs_info, sizeof(abs_info));
} }
void EventDeviceInfo::SetAbsMtSlots(int code,
const std::vector<int32_t>& values) {
DCHECK_EQ(GetAbsMtSlotCount(), values.size());
int index = code - EVDEV_ABS_MT_FIRST;
if (index < 0 || index >= EVDEV_ABS_MT_COUNT)
return;
slot_values_[index] = values;
}
bool EventDeviceInfo::HasEventType(unsigned int type) const { bool EventDeviceInfo::HasEventType(unsigned int type) const {
if (type > EV_MAX) if (type > EV_MAX)
return false; return false;
...@@ -222,20 +236,34 @@ bool EventDeviceInfo::HasProp(unsigned int code) const { ...@@ -222,20 +236,34 @@ bool EventDeviceInfo::HasProp(unsigned int code) const {
return EvdevBitIsSet(prop_bits_, code); return EvdevBitIsSet(prop_bits_, code);
} }
int32 EventDeviceInfo::GetAbsMinimum(unsigned int code) const { int32_t EventDeviceInfo::GetAbsMinimum(unsigned int code) const {
return abs_info_[code].minimum; return abs_info_[code].minimum;
} }
int32 EventDeviceInfo::GetAbsMaximum(unsigned int code) const { int32_t EventDeviceInfo::GetAbsMaximum(unsigned int code) const {
return abs_info_[code].maximum; return abs_info_[code].maximum;
} }
int32 EventDeviceInfo::GetSlotValue(unsigned int code, uint32_t EventDeviceInfo::GetAbsMtSlotCount() const {
unsigned int slot) const { if (!HasAbsEvent(ABS_MT_SLOT))
const std::vector<int32_t>& slots = GetMtSlotsForCode(code); return 0;
DCHECK_LE(0u, slot) << slot << " is an invalid slot"; return GetAbsMaximum(ABS_MT_SLOT) + 1;
DCHECK_LT(slot, slots.size()) << slot << " is an invalid slot"; }
return slots[slot];
int32_t EventDeviceInfo::GetAbsMtSlotValue(unsigned int code,
unsigned int slot) const {
unsigned int index = code - EVDEV_ABS_MT_FIRST;
DCHECK(index < EVDEV_ABS_MT_COUNT);
return slot_values_[index][slot];
}
int32_t EventDeviceInfo::GetAbsMtSlotValueWithDefault(
unsigned int code,
unsigned int slot,
int32_t default_value) const {
if (!HasAbsEvent(code))
return default_value;
return GetAbsMtSlotValue(code, slot);
} }
bool EventDeviceInfo::HasAbsXY() const { bool EventDeviceInfo::HasAbsXY() const {
...@@ -324,14 +352,6 @@ bool EventDeviceInfo::HasTouchscreen() const { ...@@ -324,14 +352,6 @@ bool EventDeviceInfo::HasTouchscreen() const {
return HasAbsXY() && HasDirect(); return HasAbsXY() && HasDirect();
} }
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];
}
EventDeviceInfo::LegacyAbsoluteDeviceType EventDeviceInfo::LegacyAbsoluteDeviceType
EventDeviceInfo::ProbeLegacyAbsoluteDevice() const { EventDeviceInfo::ProbeLegacyAbsoluteDevice() const {
if (!HasAbsXY()) if (!HasAbsXY())
......
...@@ -14,8 +14,14 @@ ...@@ -14,8 +14,14 @@
#include "ui/events/ozone/evdev/event_device_util.h" #include "ui/events/ozone/evdev/event_device_util.h"
#include "ui/events/ozone/evdev/events_ozone_evdev_export.h" #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
#if !defined(ABS_MT_TOOL_Y)
#define ABS_MT_TOOL_Y 0x3d
#endif
// ABS_MT_SLOT isn't valid options for EVIOCGMTSLOTS ioctl. // ABS_MT_SLOT isn't valid options for EVIOCGMTSLOTS ioctl.
#define EVDEV_ABS_MT_COUNT (ABS_MAX - ABS_MT_SLOT - 1) #define EVDEV_ABS_MT_FIRST ABS_MT_TOUCH_MAJOR
#define EVDEV_ABS_MT_LAST ABS_MT_TOOL_Y
#define EVDEV_ABS_MT_COUNT (EVDEV_ABS_MT_LAST - EVDEV_ABS_MT_FIRST + 1)
namespace ui { namespace ui {
...@@ -52,6 +58,7 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo { ...@@ -52,6 +58,7 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
void SetLedEvents(const unsigned long* led_bits, size_t len); void SetLedEvents(const unsigned long* led_bits, size_t len);
void SetProps(const unsigned long* prop_bits, size_t len); void SetProps(const unsigned long* prop_bits, size_t len);
void SetAbsInfo(unsigned int code, const input_absinfo& absinfo); void SetAbsInfo(unsigned int code, const input_absinfo& absinfo);
void SetAbsMtSlots(int code, const std::vector<int32_t>& values);
// Check events this device can generate. // Check events this device can generate.
bool HasEventType(unsigned int type) const; bool HasEventType(unsigned int type) const;
...@@ -63,9 +70,13 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo { ...@@ -63,9 +70,13 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
bool HasLedEvent(unsigned int code) const; bool HasLedEvent(unsigned int code) const;
// Properties of absolute axes. // Properties of absolute axes.
int32 GetAbsMinimum(unsigned int code) const; int32_t GetAbsMinimum(unsigned int code) const;
int32 GetAbsMaximum(unsigned int code) const; int32_t GetAbsMaximum(unsigned int code) const;
int32 GetSlotValue(unsigned int code, unsigned int slot) const; uint32_t GetAbsMtSlotCount() const;
int32_t GetAbsMtSlotValue(unsigned int code, unsigned int slot) const;
int32_t GetAbsMtSlotValueWithDefault(unsigned int code,
unsigned int slot,
int32_t default_value) const;
// Check input device properties. // Check input device properties.
bool HasProp(unsigned int code) const; bool HasProp(unsigned int code) const;
...@@ -109,9 +120,6 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo { ...@@ -109,9 +120,6 @@ class EVENTS_OZONE_EVDEV_EXPORT EventDeviceInfo {
bool HasTouchscreen() const; bool HasTouchscreen() const;
private: private:
// Return the slot vector in |slot_values_| for |code|.
const std::vector<int32_t>& GetMtSlotsForCode(int code) const;
enum class LegacyAbsoluteDeviceType { enum class LegacyAbsoluteDeviceType {
LADT_TOUCHPAD, LADT_TOUCHPAD,
LADT_TOUCHSCREEN, LADT_TOUCHSCREEN,
......
...@@ -405,6 +405,18 @@ bool CapabilitiesToDeviceInfo(const DeviceCapabilities& capabilities, ...@@ -405,6 +405,18 @@ bool CapabilitiesToDeviceInfo(const DeviceCapabilities& capabilities,
devinfo->SetAbsInfo(axis.code, axis.absinfo); devinfo->SetAbsInfo(axis.code, axis.absinfo);
} }
size_t slots = devinfo->GetAbsMtSlotCount();
std::vector<int32_t> zero_slots(slots, 0);
std::vector<int32_t> minus_one_slots(slots, -1);
for (int code = EVDEV_ABS_MT_FIRST; code <= EVDEV_ABS_MT_LAST; ++code) {
if (!devinfo->HasAbsEvent(code))
continue;
if (code == ABS_MT_TRACKING_ID)
devinfo->SetAbsMtSlots(code, minus_one_slots);
else
devinfo->SetAbsMtSlots(code, zero_slots);
}
return true; return true;
} }
......
...@@ -110,14 +110,19 @@ void TouchEventConverterEvdev::Initialize(const EventDeviceInfo& info) { ...@@ -110,14 +110,19 @@ void TouchEventConverterEvdev::Initialize(const EventDeviceInfo& info) {
events_.resize(touch_points_); events_.resize(touch_points_);
for (size_t i = 0; i < events_.size(); ++i) { for (size_t i = 0; i < events_.size(); ++i) {
events_[i].x = info.GetSlotValue(ABS_MT_POSITION_X, i); events_[i].x = info.GetAbsMtSlotValue(ABS_MT_POSITION_X, i);
events_[i].y = info.GetSlotValue(ABS_MT_POSITION_Y, i); events_[i].y = info.GetAbsMtSlotValue(ABS_MT_POSITION_Y, i);
events_[i].tracking_id = info.GetSlotValue(ABS_MT_TRACKING_ID, i); events_[i].tracking_id = info.GetAbsMtSlotValue(ABS_MT_TRACKING_ID, i);
events_[i].touching = (events_[i].tracking_id >= 0); events_[i].touching = (events_[i].tracking_id >= 0);
events_[i].slot = i; events_[i].slot = i;
events_[i].radius_x = info.GetSlotValue(ABS_MT_TOUCH_MAJOR, i);
events_[i].radius_y = info.GetSlotValue(ABS_MT_TOUCH_MINOR, i); // Optional bits.
events_[i].pressure = info.GetSlotValue(ABS_MT_PRESSURE, i); events_[i].radius_x =
info.GetAbsMtSlotValueWithDefault(ABS_MT_TOUCH_MAJOR, i, 0);
events_[i].radius_y =
info.GetAbsMtSlotValueWithDefault(ABS_MT_TOUCH_MINOR, i, 0);
events_[i].pressure =
info.GetAbsMtSlotValueWithDefault(ABS_MT_PRESSURE, i, 0);
} }
} }
......
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