Commit 9eb82e8f authored by Malay Keshav's avatar Malay Keshav Committed by Commit Bot

Input: Remove device limit for touch input devices

This patch removes the 128 device limit that was imposed on input
devices. Instead of using a fixed size array, a flat_map is used.

The DeviceDataManager also removes entries from the flat_map if a
device has been disconnected.

Test: Manually tested on the faulty device.
Bug: b/137907174
Change-Id: I5e5803aa4fb853bf4129515767c60a2dec81686d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913717Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Commit-Queue: Malay Keshav <malaykeshav@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715624}
parent fc923406
......@@ -4,12 +4,15 @@
#include "ui/events/devices/device_data_manager.h"
#include <algorithm>
#include "base/at_exit.h"
#include "base/bind.h"
#include "base/logging.h"
#include "ui/display/types/display_constants.h"
#include "ui/events/devices/input_device_event_observer.h"
#include "ui/events/devices/touch_device_transform.h"
#include "ui/events/devices/touchscreen_device.h"
#include "ui/gfx/geometry/point3_f.h"
// This macro provides the implementation for the observer notification methods.
......@@ -79,19 +82,16 @@ void DeviceDataManager::ConfigureTouchDevices(
}
void DeviceDataManager::ClearTouchDeviceAssociations() {
for (size_t i = 0; i < touch_map_.size(); ++i)
touch_map_[i] = TouchDeviceTransform();
touch_map_.clear();
for (TouchscreenDevice& touchscreen_device : touchscreen_devices_)
touchscreen_device.target_display_id = display::kInvalidDisplayId;
}
void DeviceDataManager::UpdateTouchInfoFromTransform(
const ui::TouchDeviceTransform& touch_device_transform) {
if (!IsTouchDeviceIdValid(touch_device_transform.device_id))
return;
DCHECK_GE(touch_device_transform.device_id, 0);
touch_map_[touch_device_transform.device_id] = touch_device_transform;
for (TouchscreenDevice& touchscreen_device : touchscreen_devices_) {
if (touchscreen_device.id == touch_device_transform.device_id) {
touchscreen_device.target_display_id = touch_device_transform.display_id;
......@@ -100,22 +100,41 @@ void DeviceDataManager::UpdateTouchInfoFromTransform(
}
}
bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const {
return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum);
void DeviceDataManager::UpdateTouchMap() {
// Remove all entries for devices from the |touch_map_| that are not currently
// connected.
auto last_iter = std::remove_if(
touch_map_.begin(), touch_map_.end(),
[this](const std::pair<int, TouchDeviceTransform>& map_entry) {
// Check if the given |map_entry| is present in the current list of
// connected devices.
auto iter = std::find_if(
touchscreen_devices_.begin(), touchscreen_devices_.end(),
[&map_entry](const TouchscreenDevice& touch_device) {
return touch_device.id == map_entry.second.device_id;
});
// Remove the device identified by |map_entry| from |touch_map_| if it
// is not present in the list of currently connected devices.
return iter != touchscreen_devices_.end();
});
touch_map_.erase(last_iter, touch_map_.end());
}
void DeviceDataManager::ApplyTouchRadiusScale(int touch_device_id,
double* radius) {
if (IsTouchDeviceIdValid(touch_device_id))
*radius = (*radius) * touch_map_[touch_device_id].radius_scale;
auto iter = touch_map_.find(touch_device_id);
if (iter != touch_map_.end())
*radius = (*radius) * iter->second.radius_scale;
}
void DeviceDataManager::ApplyTouchTransformer(int touch_device_id,
float* x,
float* y) {
if (IsTouchDeviceIdValid(touch_device_id)) {
auto iter = touch_map_.find(touch_device_id);
if (iter != touch_map_.end()) {
gfx::Point3F point(*x, *y, 0.0);
const gfx::Transform& trans = touch_map_[touch_device_id].transform;
const gfx::Transform& trans = iter->second.transform;
trans.TransformPoint(&point);
*x = point.x();
*y = point.y();
......@@ -150,8 +169,9 @@ bool DeviceDataManager::AreDeviceListsComplete() const {
int64_t DeviceDataManager::GetTargetDisplayForTouchDevice(
int touch_device_id) const {
if (IsTouchDeviceIdValid(touch_device_id))
return touch_map_[touch_device_id].display_id;
auto iter = touch_map_.find(touch_device_id);
if (iter != touch_map_.end())
return iter->second.display_id;
return display::kInvalidDisplayId;
}
......@@ -170,6 +190,7 @@ void DeviceDataManager::OnTouchscreenDevicesUpdated(
touchscreen_device.target_display_id =
GetTargetDisplayForTouchDevice(touchscreen_device.id);
}
UpdateTouchMap();
NotifyObserversTouchscreenDeviceConfigurationChanged();
}
......
......@@ -11,6 +11,7 @@
#include <memory>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "ui/events/devices/device_hotplug_event_observer.h"
......@@ -91,7 +92,7 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager
void ClearTouchDeviceAssociations();
void UpdateTouchInfoFromTransform(
const ui::TouchDeviceTransform& touch_device_transform);
bool IsTouchDeviceIdValid(int touch_device_id) const;
void UpdateTouchMap();
void NotifyObserversTouchscreenDeviceConfigurationChanged();
void NotifyObserversKeyboardDeviceConfigurationChanged();
......@@ -117,10 +118,8 @@ class EVENTS_DEVICES_EXPORT DeviceDataManager
// Set to true when ConfigureTouchDevices() is called.
bool are_touchscreen_target_displays_valid_ = false;
// Contains touchscreen device info for each device mapped by device ID. Will
// have default values if the device with corresponding ID isn't a touchscreen
// or doesn't exist.
std::array<TouchDeviceTransform, kMaxDeviceNum> touch_map_;
// Contains touchscreen device info for each device mapped by device ID.
base::flat_map<int, TouchDeviceTransform> touch_map_;
DISALLOW_COPY_AND_ASSIGN(DeviceDataManager);
};
......
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