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

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

Issue 131373007: ozone: Use gfx::Display size for touch scaling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test crash Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/gfx/ozone/surface_factory_ozone.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/logging.h" 19 #include "base/logging.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/events/ozone/event_factory_ozone.h" 23 #include "ui/events/ozone/event_factory_ozone.h"
24 #include "ui/gfx/ozone/surface_factory_ozone.h" 24 #include "ui/gfx/screen.h"
25 25
26 namespace { 26 namespace {
27 27
28 // Number is determined empirically. 28 // Number is determined empirically.
29 // TODO(rjkroege): Configure this per device. 29 // TODO(rjkroege): Configure this per device.
30 const float kFingerWidth = 25.f; 30 const float kFingerWidth = 25.f;
31 31
32 } // namespace 32 } // namespace
33 33
34 namespace ui { 34 namespace ui {
(...skipping 14 matching lines...) Expand all
49 path_(path) { 49 path_(path) {
50 Init(); 50 Init();
51 } 51 }
52 52
53 TouchEventConverterEvdev::~TouchEventConverterEvdev() { 53 TouchEventConverterEvdev::~TouchEventConverterEvdev() {
54 Stop(); 54 Stop();
55 close(fd_); 55 close(fd_);
56 } 56 }
57 57
58 void TouchEventConverterEvdev::Init() { 58 void TouchEventConverterEvdev::Init() {
59 if (x_max_ && y_max_ && gfx::SurfaceFactoryOzone::GetInstance()) { 59 gfx::Screen *screen = gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE);
60 const char* display = 60 if (!screen)
61 gfx::SurfaceFactoryOzone::GetInstance()->DefaultDisplaySpec(); 61 return; // No scaling.
62 int screen_width, screen_height; 62 gfx::Display display = screen->GetPrimaryDisplay();
63 int sc = sscanf(display, "%dx%d", &screen_width, &screen_height); 63 gfx::Size size = display.GetSizeInPixel();
64 if (sc == 2) { 64
65 x_scale_ = (double)screen_width / (x_max_ - x_min_); 65 x_scale_ = (double)size.width() / (x_max_ - x_min_);
66 y_scale_ = (double)screen_height / (y_max_ - y_min_); 66 y_scale_ = (double)size.height() / (y_max_ - y_min_);
67 x_max_ = screen_width - 1; 67 VLOG(1) << "touch scaling x_scale=" << x_scale_ << " y_scale=" << y_scale_;
68 y_max_ = screen_height - 1;
69 VLOG(1) << "touch input x_scale=" << x_scale_
70 << " y_scale=" << y_scale_;
71 } else {
72 LOG(WARNING) << "malformed display spec from "
73 << "SurfaceFactoryOzone::DefaultDisplaySpec";
74 }
75 }
76 } 68 }
77 69
78 void TouchEventConverterEvdev::Start() { 70 void TouchEventConverterEvdev::Start() {
79 base::MessagePumpOzone::Current()->WatchFileDescriptor( 71 base::MessagePumpOzone::Current()->WatchFileDescriptor(
80 fd_, true, base::MessagePumpLibevent::WATCH_READ, &controller_, this); 72 fd_, true, base::MessagePumpLibevent::WATCH_READ, &controller_, this);
81 } 73 }
82 74
83 void TouchEventConverterEvdev::Stop() { 75 void TouchEventConverterEvdev::Stop() {
84 controller_.StopWatchingFileDescriptor(); 76 controller_.StopWatchingFileDescriptor();
85 } 77 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 default: 173 default:
182 NOTREACHED() << "invalid code for EV_KEY: " << input.code; 174 NOTREACHED() << "invalid code for EV_KEY: " << input.code;
183 } 175 }
184 } else { 176 } else {
185 NOTREACHED() << "invalid type: " << input.type; 177 NOTREACHED() << "invalid type: " << input.type;
186 } 178 }
187 } 179 }
188 } 180 }
189 181
190 } // namespace ui 182 } // namespace ui
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/ozone/surface_factory_ozone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698