| OLD | NEW | 
|---|
| 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/touch_event_converter.h" | 5 #include "ui/events/ozone/evdev/touch_event_converter.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" |  | 
| 20 #include "base/message_loop/message_pump_ozone.h" | 19 #include "base/message_loop/message_pump_ozone.h" | 
| 21 #include "ui/events/event.h" | 20 #include "ui/events/event.h" | 
| 22 #include "ui/events/event_constants.h" | 21 #include "ui/events/event_constants.h" | 
| 23 #include "ui/gfx/ozone/surface_factory_ozone.h" | 22 #include "ui/gfx/ozone/surface_factory_ozone.h" | 
| 24 | 23 | 
| 25 namespace { | 24 namespace { | 
| 26 | 25 | 
| 27 // Number is determined empirically. | 26 // Number is determined empirically. | 
| 28 // TODO(rjkroege): Configure this per device. | 27 // TODO(rjkroege): Configure this per device. | 
| 29 const float kFingerWidth = 25.f; | 28 const float kFingerWidth = 25.f; | 
| 30 | 29 | 
| 31 }  // namespace | 30 }  // namespace | 
| 32 | 31 | 
| 33 namespace ui { | 32 namespace ui { | 
| 34 | 33 | 
| 35 TouchEventConverterEvdev::TouchEventConverterEvdev(int fd, base::FilePath path) | 34 TouchEventConverterEvdev::TouchEventConverterEvdev(int fd, base::FilePath path) | 
| 36     : pressure_min_(0), | 35     : pressure_min_(0), | 
| 37       pressure_max_(0), | 36       pressure_max_(0), | 
| 38       x_scale_(1.), | 37       x_scale_(1.), | 
| 39       y_scale_(1.), | 38       y_scale_(1.), | 
| 40       x_max_(std::numeric_limits<int>::max()), | 39       x_max_(std::numeric_limits<int>::max()), | 
| 41       y_max_(std::numeric_limits<int>::max()), | 40       y_max_(std::numeric_limits<int>::max()), | 
| 42       current_slot_(0), | 41       current_slot_(0), | 
| 43       fd_(fd), | 42       fd_(fd), | 
| 44       path_(path) { | 43       path_(path) { | 
| 45   Init(); | 44   Init(); | 
|  | 45   Start(); | 
| 46 } | 46 } | 
| 47 | 47 | 
| 48 TouchEventConverterEvdev::~TouchEventConverterEvdev() { | 48 TouchEventConverterEvdev::~TouchEventConverterEvdev() { | 
| 49   if (fd_ >= 0 && close(fd_) < 0) | 49   Stop(); | 
| 50     DLOG(WARNING) << "failed close on " << path_.value(); | 50   close(fd_); | 
| 51 } | 51 } | 
| 52 | 52 | 
| 53 void TouchEventConverterEvdev::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 on " | 59     DLOG(WARNING) << "failed ioctl EVIOCGABS ABS_MT_SLOT event on " | 
| 60                   << path_.value(); | 60                   << path_.value(); | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 92       y_max_ = screen_height - 1; | 92       y_max_ = screen_height - 1; | 
| 93       VLOG(1) << "touch input x_scale=" << x_scale_ | 93       VLOG(1) << "touch input x_scale=" << x_scale_ | 
| 94               << " y_scale=" << y_scale_; | 94               << " y_scale=" << y_scale_; | 
| 95     } else { | 95     } else { | 
| 96       LOG(WARNING) << "malformed display spec from " | 96       LOG(WARNING) << "malformed display spec from " | 
| 97                    << "SurfaceFactoryOzone::DefaultDisplaySpec"; | 97                    << "SurfaceFactoryOzone::DefaultDisplaySpec"; | 
| 98     } | 98     } | 
| 99   } | 99   } | 
| 100 } | 100 } | 
| 101 | 101 | 
|  | 102 void TouchEventConverterEvdev::Start() { | 
|  | 103   base::MessagePumpOzone::Current()->WatchFileDescriptor( | 
|  | 104       fd_, true, base::MessagePumpLibevent::WATCH_READ, &controller_, this); | 
|  | 105 } | 
|  | 106 | 
|  | 107 void TouchEventConverterEvdev::Stop() { | 
|  | 108   controller_.StopWatchingFileDescriptor(); | 
|  | 109 } | 
|  | 110 | 
| 102 void TouchEventConverterEvdev::OnFileCanWriteWithoutBlocking(int /* fd */) { | 111 void TouchEventConverterEvdev::OnFileCanWriteWithoutBlocking(int /* fd */) { | 
| 103   // Read-only file-descriptors. | 112   // Read-only file-descriptors. | 
| 104   NOTREACHED(); | 113   NOTREACHED(); | 
| 105 } | 114 } | 
| 106 | 115 | 
| 107 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { | 116 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { | 
| 108   input_event inputs[MAX_FINGERS * 6 + 1]; | 117   input_event inputs[MAX_FINGERS * 6 + 1]; | 
| 109   ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 118   ssize_t read_size = read(fd, inputs, sizeof(inputs)); | 
| 110   if (read_size <= 0) | 119   if (read_size <= 0) | 
| 111     return; | 120     return; | 
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 190         default: | 199         default: | 
| 191           NOTREACHED() << "invalid code for EV_KEY: " << input.code; | 200           NOTREACHED() << "invalid code for EV_KEY: " << input.code; | 
| 192       } | 201       } | 
| 193     } else { | 202     } else { | 
| 194       NOTREACHED() << "invalid type: " << input.type; | 203       NOTREACHED() << "invalid type: " << input.type; | 
| 195     } | 204     } | 
| 196   } | 205   } | 
| 197 } | 206 } | 
| 198 | 207 | 
| 199 }  // namespace ui | 208 }  // namespace ui | 
| OLD | NEW | 
|---|