Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: ui/events/ozone/evdev/event_device_info.cc

Issue 671723002: [Ozone] Properly initialize multitouch slot values (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "ui/events/ozone/evdev/event_device_info.h" 5 #include "ui/events/ozone/evdev/event_device_info.h"
6 6
7 #include <linux/input.h> 7 #include <linux/input.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/threading/thread_restrictions.h" 10 #include "base/threading/thread_restrictions.h"
11 11
12 namespace ui { 12 namespace ui {
13 13
14 namespace { 14 namespace {
15 15
16 struct MTSlotRequest {
spang 2014/10/21 19:38:36 For consistency: MtSlotRequest (and everywhere el
dnicoara 2014/10/21 20:32:12 Removed the struct for simplicity.
17 uint32_t code;
18 int32_t* values;
spang 2014/10/21 19:38:36 Should be an array.
19 };
20
16 bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) { 21 bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) {
17 if (ioctl(fd, EVIOCGBIT(type, size), buf) < 0) { 22 if (ioctl(fd, EVIOCGBIT(type, size), buf) < 0) {
18 DLOG(ERROR) << "failed EVIOCGBIT(" << type << ", " << size << ") on fd " 23 DLOG(ERROR) << "failed EVIOCGBIT(" << type << ", " << size << ") on fd "
19 << fd; 24 << fd;
20 return false; 25 return false;
21 } 26 }
22 27
23 return true; 28 return true;
24 } 29 }
25 30
26 bool GetPropBits(int fd, void* buf, unsigned int size) { 31 bool GetPropBits(int fd, void* buf, unsigned int size) {
27 if (ioctl(fd, EVIOCGPROP(size), buf) < 0) { 32 if (ioctl(fd, EVIOCGPROP(size), buf) < 0) {
28 DLOG(ERROR) << "failed EVIOCGPROP(" << size << ") on fd " << fd; 33 DLOG(ERROR) << "failed EVIOCGPROP(" << size << ") on fd " << fd;
29 return false; 34 return false;
30 } 35 }
31 36
32 return true; 37 return true;
33 } 38 }
34 39
35 bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) { 40 bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) {
36 if (ioctl(fd, EVIOCGABS(code), absinfo)) { 41 if (ioctl(fd, EVIOCGABS(code), absinfo)) {
37 DLOG(ERROR) << "failed EVIOCGABS(" << code << ") on fd " << fd; 42 DLOG(ERROR) << "failed EVIOCGABS(" << code << ") on fd " << fd;
38 return false; 43 return false;
39 } 44 }
40 return true; 45 return true;
41 } 46 }
42 47
48 bool GetSlotValues(int fd, int code, int32_t* slot_values, unsigned int size) {
49 MTSlotRequest request;
50 request.code = code;
51 request.values = slot_values;
52
53 if (ioctl(fd,
54 EVIOCGMTSLOTS(sizeof(uint32_t) + sizeof(int32_t) * size),
55 &request) < 0) {
56 LOG(ERROR) << "failed EVIOCGMTSLOTS(" << code << ") on fd " << fd;
57 return false;
58 }
59
60 return true;
61 }
62
63 int IndexToMTCode(int index) {
64 return index + ABS_MT_SLOT + 1;
65 }
66
67 int MTCodeToIndex(int code) {
68 return code - ABS_MT_SLOT - 1;
spang 2014/10/21 19:38:36 Can you make this a member function: int32_t* slo
dnicoara 2014/10/21 20:32:12 Done.
69 }
70
43 } // namespace 71 } // namespace
44 72
45 EventDeviceInfo::EventDeviceInfo() { 73 EventDeviceInfo::EventDeviceInfo() {
46 memset(ev_bits_, 0, sizeof(ev_bits_)); 74 memset(ev_bits_, 0, sizeof(ev_bits_));
47 memset(key_bits_, 0, sizeof(key_bits_)); 75 memset(key_bits_, 0, sizeof(key_bits_));
48 memset(rel_bits_, 0, sizeof(rel_bits_)); 76 memset(rel_bits_, 0, sizeof(rel_bits_));
49 memset(abs_bits_, 0, sizeof(abs_bits_)); 77 memset(abs_bits_, 0, sizeof(abs_bits_));
50 memset(msc_bits_, 0, sizeof(msc_bits_)); 78 memset(msc_bits_, 0, sizeof(msc_bits_));
51 memset(sw_bits_, 0, sizeof(sw_bits_)); 79 memset(sw_bits_, 0, sizeof(sw_bits_));
52 memset(led_bits_, 0, sizeof(led_bits_)); 80 memset(led_bits_, 0, sizeof(led_bits_));
53 memset(prop_bits_, 0, sizeof(prop_bits_)); 81 memset(prop_bits_, 0, sizeof(prop_bits_));
54 memset(abs_info_, 0, sizeof(abs_info_)); 82 memset(abs_info_, 0, sizeof(abs_info_));
83 memset(slot_values_, 0, sizeof(slot_values_));
55 } 84 }
56 85
57 EventDeviceInfo::~EventDeviceInfo() {} 86 EventDeviceInfo::~EventDeviceInfo() {
87 for (size_t i = 0; i < arraysize(slot_values_); ++i)
88 if (slot_values_[i])
89 delete[] slot_values_[i];
90 }
58 91
59 bool EventDeviceInfo::Initialize(int fd) { 92 bool EventDeviceInfo::Initialize(int fd) {
60 if (!GetEventBits(fd, 0, ev_bits_, sizeof(ev_bits_))) 93 if (!GetEventBits(fd, 0, ev_bits_, sizeof(ev_bits_)))
61 return false; 94 return false;
62 95
63 if (!GetEventBits(fd, EV_KEY, key_bits_, sizeof(key_bits_))) 96 if (!GetEventBits(fd, EV_KEY, key_bits_, sizeof(key_bits_)))
64 return false; 97 return false;
65 98
66 if (!GetEventBits(fd, EV_REL, rel_bits_, sizeof(rel_bits_))) 99 if (!GetEventBits(fd, EV_REL, rel_bits_, sizeof(rel_bits_)))
67 return false; 100 return false;
(...skipping 11 matching lines...) Expand all
79 return false; 112 return false;
80 113
81 if (!GetPropBits(fd, prop_bits_, sizeof(prop_bits_))) 114 if (!GetPropBits(fd, prop_bits_, sizeof(prop_bits_)))
82 return false; 115 return false;
83 116
84 for (unsigned int i = 0; i < ABS_CNT; ++i) 117 for (unsigned int i = 0; i < ABS_CNT; ++i)
85 if (HasAbsEvent(i)) 118 if (HasAbsEvent(i))
86 if (!GetAbsInfo(fd, i, &abs_info_[i])) 119 if (!GetAbsInfo(fd, i, &abs_info_[i]))
87 return false; 120 return false;
88 121
122 int max_num_slots = abs_info_[ABS_MT_SLOT].maximum + 1;
123 for (unsigned int i = 0; i < ABS_MT_COUNT; ++i) {
spang 2014/10/21 19:38:36 I think this should iterate over codes rather than
dnicoara 2014/10/21 20:32:12 Done.
124 slot_values_[i] = new int32[max_num_slots];
125 memset(slot_values_[i], 0, sizeof(int32) * max_num_slots);
126 if (!GetSlotValues(fd, IndexToMTCode(i), slot_values_[i], max_num_slots))
127 return false;
128 }
129
89 return true; 130 return true;
90 } 131 }
91 132
92 bool EventDeviceInfo::HasEventType(unsigned int type) const { 133 bool EventDeviceInfo::HasEventType(unsigned int type) const {
93 if (type > EV_MAX) 134 if (type > EV_MAX)
94 return false; 135 return false;
95 return EvdevBitIsSet(ev_bits_, type); 136 return EvdevBitIsSet(ev_bits_, type);
96 } 137 }
97 138
98 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const { 139 bool EventDeviceInfo::HasKeyEvent(unsigned int code) const {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 179 }
139 180
140 int32 EventDeviceInfo::GetAbsMinimum(unsigned int code) const { 181 int32 EventDeviceInfo::GetAbsMinimum(unsigned int code) const {
141 return abs_info_[code].minimum; 182 return abs_info_[code].minimum;
142 } 183 }
143 184
144 int32 EventDeviceInfo::GetAbsMaximum(unsigned int code) const { 185 int32 EventDeviceInfo::GetAbsMaximum(unsigned int code) const {
145 return abs_info_[code].maximum; 186 return abs_info_[code].maximum;
146 } 187 }
147 188
189 int32 EventDeviceInfo::GetSlotValue(unsigned int code,
190 unsigned int slot) const {
191 return slot_values_[MTCodeToIndex(code)][slot];
192 }
193
148 bool EventDeviceInfo::HasAbsXY() const { 194 bool EventDeviceInfo::HasAbsXY() const {
149 if (HasAbsEvent(ABS_X) && HasAbsEvent(ABS_Y)) 195 if (HasAbsEvent(ABS_X) && HasAbsEvent(ABS_Y))
150 return true; 196 return true;
151 197
152 if (HasAbsEvent(ABS_MT_POSITION_X) && HasAbsEvent(ABS_MT_POSITION_Y)) 198 if (HasAbsEvent(ABS_MT_POSITION_X) && HasAbsEvent(ABS_MT_POSITION_Y))
153 return true; 199 return true;
154 200
155 return false; 201 return false;
156 } 202 }
157 203
(...skipping 18 matching lines...) Expand all
176 // Touchpads are not mapped to the screen. 222 // Touchpads are not mapped to the screen.
177 if (HasKeyEvent(BTN_LEFT) || HasKeyEvent(BTN_MIDDLE) || 223 if (HasKeyEvent(BTN_LEFT) || HasKeyEvent(BTN_MIDDLE) ||
178 HasKeyEvent(BTN_RIGHT) || HasKeyEvent(BTN_TOOL_FINGER)) 224 HasKeyEvent(BTN_RIGHT) || HasKeyEvent(BTN_TOOL_FINGER))
179 return false; 225 return false;
180 226
181 // Touchscreens are mapped to the screen. 227 // Touchscreens are mapped to the screen.
182 return true; 228 return true;
183 } 229 }
184 230
185 } // namespace ui 231 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698