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

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

Issue 616633002: [Ozone-Evdev] Propagate touchscreen device information to DeviceDataManager (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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_evdev.h" 5 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <fcntl.h> 8 #include <fcntl.h>
9 #include <linux/input.h> 9 #include <linux/input.h>
10 #include <poll.h> 10 #include <poll.h>
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <unistd.h> 12 #include <unistd.h>
13 13
14 #include <cmath> 14 #include <cmath>
15 #include <limits> 15 #include <limits>
16 16
17 #include "base/bind.h" 17 #include "base/bind.h"
18 #include "base/callback.h" 18 #include "base/callback.h"
19 #include "base/command_line.h" 19 #include "base/command_line.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/memory/scoped_vector.h" 21 #include "base/memory/scoped_vector.h"
22 #include "base/message_loop/message_loop.h" 22 #include "base/message_loop/message_loop.h"
23 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
25 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 #include "ui/events/event.h" 26 #include "ui/events/event.h"
27 #include "ui/events/event_constants.h" 27 #include "ui/events/event_constants.h"
28 #include "ui/events/event_switches.h" 28 #include "ui/events/event_switches.h"
29 #include "ui/gfx/screen.h"
30 29
31 namespace { 30 namespace {
32 31
33 struct TouchCalibration { 32 struct TouchCalibration {
34 int bezel_left; 33 int bezel_left;
35 int bezel_right; 34 int bezel_right;
36 int bezel_top; 35 int bezel_top;
37 int bezel_bottom; 36 int bezel_bottom;
38 }; 37 };
39 38
(...skipping 28 matching lines...) Expand all
68 return val * num_pixels / num_tuxels; 67 return val * num_pixels / num_tuxels;
69 } 68 }
70 69
71 } // namespace 70 } // namespace
72 71
73 namespace ui { 72 namespace ui {
74 73
75 TouchEventConverterEvdev::TouchEventConverterEvdev( 74 TouchEventConverterEvdev::TouchEventConverterEvdev(
76 int fd, 75 int fd,
77 base::FilePath path, 76 base::FilePath path,
78 const EventDeviceInfo& info, 77 scoped_ptr<EventDeviceInfo> device_info,
79 const EventDispatchCallback& callback) 78 const EventDispatchCallback& callback)
80 : EventConverterEvdev(fd, path), 79 : EventConverterEvdev(fd, path, device_info.Pass()),
81 callback_(callback), 80 callback_(callback),
82 syn_dropped_(false), 81 syn_dropped_(false),
83 is_type_a_(false), 82 is_type_a_(false),
84 current_slot_(0) { 83 current_slot_(0) {
85 Init(info); 84 Init();
86 } 85 }
87 86
88 TouchEventConverterEvdev::~TouchEventConverterEvdev() { 87 TouchEventConverterEvdev::~TouchEventConverterEvdev() {
89 Stop(); 88 Stop();
90 close(fd_); 89 close(fd_);
91 } 90 }
92 91
93 void TouchEventConverterEvdev::Init(const EventDeviceInfo& info) { 92 void TouchEventConverterEvdev::Init() {
94 gfx::Screen *screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); 93 pressure_min_ = device_info_->GetAbsMinimum(ABS_MT_PRESSURE);
95 if (!screen) 94 pressure_max_ = device_info_->GetAbsMaximum(ABS_MT_PRESSURE);
96 return; // No scaling. 95 x_min_tuxels_ = device_info_->GetAbsMinimum(ABS_MT_POSITION_X);
97 gfx::Display display = screen->GetPrimaryDisplay(); 96 x_num_tuxels_ =
98 gfx::Size size = display.GetSizeInPixel(); 97 device_info_->GetAbsMaximum(ABS_MT_POSITION_X) - x_min_tuxels_ + 1;
99 98 y_min_tuxels_ = device_info_->GetAbsMinimum(ABS_MT_POSITION_Y);
100 pressure_min_ = info.GetAbsMinimum(ABS_MT_PRESSURE), 99 y_num_tuxels_ =
101 pressure_max_ = info.GetAbsMaximum(ABS_MT_PRESSURE), 100 device_info_->GetAbsMaximum(ABS_MT_POSITION_Y) - y_min_tuxels_ + 1;
102 x_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_X), 101 x_min_pixels_ = x_min_tuxels_;
103 x_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_X) - x_min_tuxels_ + 1, 102 x_num_pixels_ = x_num_tuxels_;
104 y_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_Y), 103 y_min_pixels_ = y_min_tuxels_;
105 y_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_Y) - y_min_tuxels_ + 1, 104 y_num_pixels_ = y_num_tuxels_;
106 x_min_pixels_ = x_min_tuxels_,
107 x_num_pixels_ = x_num_tuxels_,
108 y_min_pixels_ = y_min_tuxels_,
109 y_num_pixels_ = y_num_tuxels_,
110 105
111 // Map coordinates onto screen. 106 // Map coordinates onto screen.
112 x_min_pixels_ = 0; 107 x_min_pixels_ = 0;
113 y_min_pixels_ = 0; 108 y_min_pixels_ = 0;
114 x_num_pixels_ = size.width(); 109 x_num_pixels_ = x_num_tuxels_;
115 y_num_pixels_ = size.height(); 110 y_num_pixels_ = y_num_tuxels_;
116 111
117 VLOG(1) << "mapping touch coordinates to screen coordinates: " 112 VLOG(1) << "mapping touch coordinates to screen coordinates: "
118 << base::StringPrintf("%dx%d", size.width(), size.height()); 113 << base::StringPrintf("%fx%f", x_num_pixels_, y_num_pixels_);
119 114
120 // Apply --touch-calibration. 115 // Apply --touch-calibration.
121 TouchCalibration cal = {}; 116 TouchCalibration cal = {};
122 GetTouchCalibration(&cal); 117 GetTouchCalibration(&cal);
123 x_min_tuxels_ += cal.bezel_left; 118 x_min_tuxels_ += cal.bezel_left;
124 x_num_tuxels_ -= cal.bezel_left + cal.bezel_right; 119 x_num_tuxels_ -= cal.bezel_left + cal.bezel_right;
125 y_min_tuxels_ += cal.bezel_top; 120 y_min_tuxels_ += cal.bezel_top;
126 y_num_tuxels_ -= cal.bezel_top + cal.bezel_bottom; 121 y_num_tuxels_ -= cal.bezel_top + cal.bezel_bottom;
127 122
128 VLOG(1) << "applying touch calibration: " 123 VLOG(1) << "applying touch calibration: "
129 << base::StringPrintf("[%d, %d, %d, %d]", 124 << base::StringPrintf("[%d, %d, %d, %d]",
130 cal.bezel_left, 125 cal.bezel_left,
131 cal.bezel_right, 126 cal.bezel_right,
132 cal.bezel_top, 127 cal.bezel_top,
133 cal.bezel_bottom); 128 cal.bezel_bottom);
134 } 129 }
135 130
136 bool TouchEventConverterEvdev::Reinitialize() { 131 bool TouchEventConverterEvdev::Reinitialize() {
137 EventDeviceInfo info; 132 device_info_.reset(new EventDeviceInfo(device_info_->id()));
138 if (info.Initialize(fd_)) { 133 if (device_info_->Initialize(fd_)) {
139 Init(info); 134 Init();
140 return true; 135 return true;
141 } 136 }
142 return false; 137 return false;
143 } 138 }
144 139
145 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { 140 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) {
146 input_event inputs[MAX_FINGERS * 6 + 1]; 141 input_event inputs[MAX_FINGERS * 6 + 1];
147 ssize_t read_size = read(fd, inputs, sizeof(inputs)); 142 ssize_t read_size = read(fd, inputs, sizeof(inputs));
148 if (read_size < 0) { 143 if (read_size < 0) {
149 if (errno == EINTR || errno == EAGAIN) 144 if (errno == EINTR || errno == EAGAIN)
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 282
288 // Subsequent events for this finger will be touch-move until it 283 // Subsequent events for this finger will be touch-move until it
289 // is released. 284 // is released.
290 events_[i].type_ = ET_TOUCH_MOVED; 285 events_[i].type_ = ET_TOUCH_MOVED;
291 } 286 }
292 } 287 }
293 altered_slots_.reset(); 288 altered_slots_.reset();
294 } 289 }
295 290
296 } // namespace ui 291 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698