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

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,
77 int id,
78 const EventDeviceInfo& info, 78 const EventDeviceInfo& info,
79 const EventDispatchCallback& callback) 79 const EventDispatchCallback& callback)
80 : EventConverterEvdev(fd, path), 80 : EventConverterEvdev(fd, path, id),
81 callback_(callback), 81 callback_(callback),
82 syn_dropped_(false), 82 syn_dropped_(false),
83 is_type_a_(false), 83 is_type_a_(false),
84 current_slot_(0) { 84 current_slot_(0) {
85 Init(info); 85 Init(info);
86 } 86 }
87 87
88 TouchEventConverterEvdev::~TouchEventConverterEvdev() { 88 TouchEventConverterEvdev::~TouchEventConverterEvdev() {
89 Stop(); 89 Stop();
90 close(fd_); 90 close(fd_);
91 } 91 }
92 92
93 void TouchEventConverterEvdev::Init(const EventDeviceInfo& info) { 93 void TouchEventConverterEvdev::Init(const EventDeviceInfo& info) {
94 gfx::Screen *screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE); 94 pressure_min_ = info.GetAbsMinimum(ABS_MT_PRESSURE);
95 if (!screen) 95 pressure_max_ = info.GetAbsMaximum(ABS_MT_PRESSURE);
96 return; // No scaling. 96 x_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_X);
97 gfx::Display display = screen->GetPrimaryDisplay(); 97 x_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_X) - x_min_tuxels_ + 1;
98 gfx::Size size = display.GetSizeInPixel(); 98 y_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_Y);
99 99 y_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_Y) - y_min_tuxels_ + 1;
spang 2014/09/30 21:42:42 Haha
100 pressure_min_ = info.GetAbsMinimum(ABS_MT_PRESSURE), 100 native_size_ = gfx::Size(x_num_tuxels_, y_num_tuxels_);
101 pressure_max_ = info.GetAbsMaximum(ABS_MT_PRESSURE),
102 x_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_X),
103 x_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_X) - x_min_tuxels_ + 1,
104 y_min_tuxels_ = info.GetAbsMinimum(ABS_MT_POSITION_Y),
105 y_num_tuxels_ = info.GetAbsMaximum(ABS_MT_POSITION_Y) - y_min_tuxels_ + 1,
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 101
111 // Map coordinates onto screen. 102 // Map coordinates onto screen.
112 x_min_pixels_ = 0; 103 x_min_pixels_ = 0;
113 y_min_pixels_ = 0; 104 y_min_pixels_ = 0;
114 x_num_pixels_ = size.width(); 105 x_num_pixels_ = x_num_tuxels_;
115 y_num_pixels_ = size.height(); 106 y_num_pixels_ = y_num_tuxels_;
spang 2014/09/30 21:42:41 This part disturbs me. Can you move it to the foll
dnicoara 2014/10/01 19:49:13 Done.
116 107
117 VLOG(1) << "mapping touch coordinates to screen coordinates: " 108 VLOG(1) << "mapping touch coordinates to screen coordinates: "
118 << base::StringPrintf("%dx%d", size.width(), size.height()); 109 << base::StringPrintf("%fx%f", x_num_pixels_, y_num_pixels_);
119 110
120 // Apply --touch-calibration. 111 // Apply --touch-calibration.
121 TouchCalibration cal = {}; 112 TouchCalibration cal = {};
122 GetTouchCalibration(&cal); 113 GetTouchCalibration(&cal);
123 x_min_tuxels_ += cal.bezel_left; 114 x_min_tuxels_ += cal.bezel_left;
124 x_num_tuxels_ -= cal.bezel_left + cal.bezel_right; 115 x_num_tuxels_ -= cal.bezel_left + cal.bezel_right;
125 y_min_tuxels_ += cal.bezel_top; 116 y_min_tuxels_ += cal.bezel_top;
126 y_num_tuxels_ -= cal.bezel_top + cal.bezel_bottom; 117 y_num_tuxels_ -= cal.bezel_top + cal.bezel_bottom;
127 118
128 VLOG(1) << "applying touch calibration: " 119 VLOG(1) << "applying touch calibration: "
129 << base::StringPrintf("[%d, %d, %d, %d]", 120 << base::StringPrintf("[%d, %d, %d, %d]",
130 cal.bezel_left, 121 cal.bezel_left,
131 cal.bezel_right, 122 cal.bezel_right,
132 cal.bezel_top, 123 cal.bezel_top,
133 cal.bezel_bottom); 124 cal.bezel_bottom);
134 } 125 }
135 126
136 bool TouchEventConverterEvdev::Reinitialize() { 127 bool TouchEventConverterEvdev::Reinitialize() {
137 EventDeviceInfo info; 128 EventDeviceInfo info;
138 if (info.Initialize(fd_)) { 129 if (info.Initialize(fd_)) {
139 Init(info); 130 Init(info);
140 return true; 131 return true;
141 } 132 }
142 return false; 133 return false;
143 } 134 }
144 135
136 bool TouchEventConverterEvdev::HasTouchscreen() const {
137 return true;
138 }
139
140 gfx::Size TouchEventConverterEvdev::GetTouchscreenSize() const {
141 return native_size_;
142 }
143
145 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { 144 void TouchEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) {
146 input_event inputs[MAX_FINGERS * 6 + 1]; 145 input_event inputs[MAX_FINGERS * 6 + 1];
147 ssize_t read_size = read(fd, inputs, sizeof(inputs)); 146 ssize_t read_size = read(fd, inputs, sizeof(inputs));
148 if (read_size < 0) { 147 if (read_size < 0) {
149 if (errno == EINTR || errno == EAGAIN) 148 if (errno == EINTR || errno == EAGAIN)
150 return; 149 return;
151 if (errno != ENODEV) 150 if (errno != ENODEV)
152 PLOG(ERROR) << "error reading device " << path_.value(); 151 PLOG(ERROR) << "error reading device " << path_.value();
153 Stop(); 152 Stop();
154 return; 153 return;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 286
288 // Subsequent events for this finger will be touch-move until it 287 // Subsequent events for this finger will be touch-move until it
289 // is released. 288 // is released.
290 events_[i].type_ = ET_TOUCH_MOVED; 289 events_[i].type_ = ET_TOUCH_MOVED;
291 } 290 }
292 } 291 }
293 altered_slots_.reset(); 292 altered_slots_.reset();
294 } 293 }
295 294
296 } // namespace ui 295 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698