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

Side by Side Diff: ui/events/device_data_manager.cc

Issue 289283015: Extract touchscreen device management into a generic manager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 6 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 | « ui/events/device_data_manager.h ('k') | ui/events/events.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ui/events/device_data_manager.h"
6
7 #include "base/at_exit.h"
8 #include "base/bind.h"
9 #include "base/logging.h"
10 #include "ui/gfx/display.h"
11 #include "ui/gfx/geometry/point3_f.h"
12
13 namespace ui {
14
15 // static
16 DeviceDataManager* DeviceDataManager::instance_ = NULL;
17
18 DeviceDataManager::DeviceDataManager() {
19 CHECK(!instance_) << "Can not create multiple instances of DeviceDataManager";
20 instance_ = this;
21
22 base::AtExitManager::RegisterTask(
23 base::Bind(&base::DeletePointer<DeviceDataManager>, this));
24
25 for (int i = 0; i < kMaxDeviceNum; ++i)
26 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID;
27 }
28
29 DeviceDataManager::~DeviceDataManager() {
30 CHECK_EQ(this, instance_);
31 instance_ = NULL;
32 }
33
34 // static
35 DeviceDataManager* DeviceDataManager::instance() { return instance_; }
36
37 // static
38 void DeviceDataManager::CreateInstance() {
39 if (instance())
40 return;
41
42 new DeviceDataManager();
43 }
44
45 // static
46 DeviceDataManager* DeviceDataManager::GetInstance() {
47 CHECK(instance_) << "DeviceDataManager was not created.";
48 return instance_;
49 }
50
51 void DeviceDataManager::ClearTouchTransformerRecord() {
52 for (int i = 0; i < kMaxDeviceNum; i++) {
53 touch_device_transformer_map_[i] = gfx::Transform();
54 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID;
55 }
56 }
57
58 bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const {
59 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum);
60 }
61
62 void DeviceDataManager::UpdateTouchInfoForDisplay(
63 int64_t display_id,
64 int touch_device_id,
65 const gfx::Transform& touch_transformer) {
66 if (IsTouchDeviceIdValid(touch_device_id)) {
67 touch_device_to_display_map_[touch_device_id] = display_id;
68 touch_device_transformer_map_[touch_device_id] = touch_transformer;
69 }
70 }
71
72 void DeviceDataManager::ApplyTouchTransformer(int touch_device_id,
73 float* x,
74 float* y) {
75 if (IsTouchDeviceIdValid(touch_device_id)) {
76 gfx::Point3F point(*x, *y, 0.0);
77 const gfx::Transform& trans =
78 touch_device_transformer_map_[touch_device_id];
79 trans.TransformPoint(&point);
80 *x = point.x();
81 *y = point.y();
82 }
83 }
84
85 int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const {
86 if (IsTouchDeviceIdValid(touch_device_id))
87 return touch_device_to_display_map_[touch_device_id];
88 return gfx::Display::kInvalidDisplayID;
89 }
90
91 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/device_data_manager.h ('k') | ui/events/events.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698