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

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: Updated 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
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 base::AtExitManager::RegisterTask(
20 base::Bind(&base::DeletePointer<DeviceDataManager>, this));
21
22 for (int i = 0; i < kMaxDeviceNum; ++i)
23 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID;
24 }
25
26 DeviceDataManager::~DeviceDataManager() {
27 CHECK_EQ(this, instance_);
28 instance_ = NULL;
29 }
30
31 // static
32 void DeviceDataManager::CreateInstance() {
33 if (instance_)
34 return;
35
36 instance_ = new DeviceDataManager();
37 }
38
39 // static
40 DeviceDataManager* DeviceDataManager::GetInstance() {
41 CHECK(instance_) << "DeviceDataManager was not created.";
42 return instance_;
43 }
44
45 void DeviceDataManager::ClearTouchTransformerRecord() {
46 for (int i = 0; i < kMaxDeviceNum; i++) {
47 touch_device_transformer_map_[i] = gfx::Transform();
48 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID;
49 }
50 }
51
52 bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const {
53 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum);
54 }
55
56 void DeviceDataManager::UpdateTouchInfoForDisplay(
57 int64_t display_id,
58 int touch_device_id,
59 const gfx::Transform& touch_transformer) {
60 if (IsTouchDeviceIdValid(touch_device_id)) {
61 touch_device_to_display_map_[touch_device_id] = display_id;
62 touch_device_transformer_map_[touch_device_id] = touch_transformer;
63 }
64 }
65
66 void DeviceDataManager::ApplyTouchTransformer(int touch_device_id,
67 float* x,
68 float* y) {
69 if (IsTouchDeviceIdValid(touch_device_id)) {
70 gfx::Point3F point(*x, *y, 0.0);
71 const gfx::Transform& trans =
72 touch_device_transformer_map_[touch_device_id];
73 trans.TransformPoint(&point);
74 *x = point.x();
75 *y = point.y();
76 }
77 }
78
79 int64_t DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const {
80 if (IsTouchDeviceIdValid(touch_device_id))
81 return touch_device_to_display_map_[touch_device_id];
82 return gfx::Display::kInvalidDisplayID;
83 }
84
85 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698