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

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

Powered by Google App Engine
This is Rietveld 408576698