OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/touch_event_converter_ozone.h" | 5 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <linux/input.h> | 8 #include <linux/input.h> |
9 #include <poll.h> | 9 #include <poll.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
13 #include <cmath> | 13 #include <cmath> |
14 #include <limits> | 14 #include <limits> |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "base/logging.h" | 18 #include "base/logging.h" |
19 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
20 #include "base/message_loop/message_pump_ozone.h" | 20 #include "base/message_loop/message_pump_ozone.h" |
21 #include "ui/events/event.h" | 21 #include "ui/events/event.h" |
22 #include "ui/events/event_constants.h" | 22 #include "ui/events/event_constants.h" |
23 #include "ui/gfx/ozone/surface_factory_ozone.h" | 23 #include "ui/gfx/ozone/surface_factory_ozone.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Number is determined empirically. | 27 // Number is determined empirically. |
28 // TODO(rjkroege): Configure this per device. | 28 // TODO(rjkroege): Configure this per device. |
29 const float kFingerWidth = 25.f; | 29 const float kFingerWidth = 25.f; |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 namespace ui { | 33 namespace ui { |
34 | 34 |
35 TouchEventConverterOzone::TouchEventConverterOzone(int fd, int id) | 35 TouchEventConverterEvdev::TouchEventConverterEvdev(int fd, int id) |
36 : pressure_min_(0), | 36 : pressure_min_(0), |
37 pressure_max_(0), | 37 pressure_max_(0), |
38 x_scale_(1.), | 38 x_scale_(1.), |
39 y_scale_(1.), | 39 y_scale_(1.), |
40 x_max_(std::numeric_limits<int>::max()), | 40 x_max_(std::numeric_limits<int>::max()), |
41 y_max_(std::numeric_limits<int>::max()), | 41 y_max_(std::numeric_limits<int>::max()), |
42 current_slot_(0), | 42 current_slot_(0), |
43 fd_(fd), | 43 fd_(fd), |
44 id_(id) { | 44 id_(id) { |
45 Init(); | 45 Init(); |
46 } | 46 } |
47 | 47 |
48 TouchEventConverterOzone::~TouchEventConverterOzone() { | 48 TouchEventConverterEvdev::~TouchEventConverterEvdev() { |
49 if (close(fd_) < 0) | 49 if (close(fd_) < 0) |
50 DLOG(WARNING) << "failed close on /dev/input/event" << id_; | 50 DLOG(WARNING) << "failed close on /dev/input/event" << id_; |
51 } | 51 } |
52 | 52 |
53 void TouchEventConverterOzone::Init() { | 53 void TouchEventConverterEvdev::Init() { |
54 input_absinfo abs = {}; | 54 input_absinfo abs = {}; |
55 if (ioctl(fd_, EVIOCGABS(ABS_MT_SLOT), &abs) != -1) { | 55 if (ioctl(fd_, EVIOCGABS(ABS_MT_SLOT), &abs) != -1) { |
56 CHECK_GE(abs.maximum, abs.minimum); | 56 CHECK_GE(abs.maximum, abs.minimum); |
57 CHECK_GE(abs.minimum, 0); | 57 CHECK_GE(abs.minimum, 0); |
58 } else { | 58 } else { |
59 DLOG(WARNING) << "failed ioctl EVIOCGABS ABS_MT_SLOT event" << id_; | 59 DLOG(WARNING) << "failed ioctl EVIOCGABS ABS_MT_SLOT event" << id_; |
60 } | 60 } |
61 if (ioctl(fd_, EVIOCGABS(ABS_MT_PRESSURE), &abs) != -1) { | 61 if (ioctl(fd_, EVIOCGABS(ABS_MT_PRESSURE), &abs) != -1) { |
62 pressure_min_ = abs.minimum; | 62 pressure_min_ = abs.minimum; |
63 pressure_max_ = abs.maximum; | 63 pressure_max_ = abs.maximum; |
(...skipping 26 matching lines...) Expand all Loading... |
90 y_max_ = screen_height - 1; | 90 y_max_ = screen_height - 1; |
91 LOG(INFO) << "touch input x_scale=" << x_scale_ | 91 LOG(INFO) << "touch input x_scale=" << x_scale_ |
92 << " y_scale=" << y_scale_; | 92 << " y_scale=" << y_scale_; |
93 } else { | 93 } else { |
94 LOG(WARNING) << "malformed display spec from " | 94 LOG(WARNING) << "malformed display spec from " |
95 << "SurfaceFactoryOzone::DefaultDisplaySpec"; | 95 << "SurfaceFactoryOzone::DefaultDisplaySpec"; |
96 } | 96 } |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 void TouchEventConverterOzone::OnFileCanWriteWithoutBlocking(int /* fd */) { | 100 void TouchEventConverterEvdev::OnFileCanWriteWithoutBlocking(int /* fd */) { |
101 // Read-only file-descriptors. | 101 // Read-only file-descriptors. |
102 NOTREACHED(); | 102 NOTREACHED(); |
103 } | 103 } |
104 | 104 |
105 void TouchEventConverterOzone::OnFileCanReadWithoutBlocking(int fd) { | 105 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { |
106 input_event inputs[MAX_FINGERS * 6 + 1]; | 106 input_event inputs[MAX_FINGERS * 6 + 1]; |
107 ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 107 ssize_t read_size = read(fd, inputs, sizeof(inputs)); |
108 if (read_size <= 0) | 108 if (read_size <= 0) |
109 return; | 109 return; |
110 | 110 |
111 for (unsigned i = 0; i < read_size / sizeof(*inputs); i++) { | 111 for (unsigned i = 0; i < read_size / sizeof(*inputs); i++) { |
112 const input_event& input = inputs[i]; | 112 const input_event& input = inputs[i]; |
113 if (input.type == EV_ABS) { | 113 if (input.type == EV_ABS) { |
114 switch (input.code) { | 114 switch (input.code) { |
115 case ABS_MT_TOUCH_MAJOR: | 115 case ABS_MT_TOUCH_MAJOR: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 NOTREACHED() << "SYN_MT events not supported."; | 181 NOTREACHED() << "SYN_MT events not supported."; |
182 break; | 182 break; |
183 } | 183 } |
184 } else { | 184 } else { |
185 NOTREACHED(); | 185 NOTREACHED(); |
186 } | 186 } |
187 } | 187 } |
188 } | 188 } |
189 | 189 |
190 } // namespace ui | 190 } // namespace ui |
OLD | NEW |