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

Side by Side Diff: ui/base/touch/touch_device_linux.cc

Issue 2301073002: Optimization: avoid making 4 JNI calls to get touch device attributes. (Closed)
Patch Set: Created 4 years, 3 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/base/touch/touch_device.h" 5 #include "ui/base/touch/touch_device.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "ui/events/devices/input_device_manager.h" 8 #include "ui/events/devices/input_device_manager.h"
9 9
10 namespace ui { 10 namespace ui {
(...skipping 19 matching lines...) Expand all
30 int max_touch = 0; 30 int max_touch = 0;
31 const std::vector<ui::TouchscreenDevice>& touchscreen_devices = 31 const std::vector<ui::TouchscreenDevice>& touchscreen_devices =
32 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices(); 32 ui::InputDeviceManager::GetInstance()->GetTouchscreenDevices();
33 for (const ui::TouchscreenDevice& device : touchscreen_devices) { 33 for (const ui::TouchscreenDevice& device : touchscreen_devices) {
34 if (device.touch_points > max_touch) 34 if (device.touch_points > max_touch)
35 max_touch = device.touch_points; 35 max_touch = device.touch_points;
36 } 36 }
37 return max_touch; 37 return max_touch;
38 } 38 }
39 39
40 std::pair<int, int> GetAvailablePointerAndHoverTypes() {
41 return std::make_pair(GetAvailablePointerTypes(), GetAvailableHoverTypes());
42 }
43
40 // TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634 44 // TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634
41 int GetAvailablePointerTypes() { 45 int GetAvailablePointerTypes() {
42 // Assume a mouse is there 46 // Assume a mouse is there
43 int available_pointer_types = POINTER_TYPE_FINE; 47 int available_pointer_types = POINTER_TYPE_FINE;
44 if (IsTouchDevicePresent()) 48 if (IsTouchDevicePresent())
45 available_pointer_types |= POINTER_TYPE_COARSE; 49 available_pointer_types |= POINTER_TYPE_COARSE;
46 50
47 DCHECK(available_pointer_types); 51 DCHECK(available_pointer_types);
48 return available_pointer_types; 52 return available_pointer_types;
49 } 53 }
50 54
51 PointerType GetPrimaryPointerType() { 55 PointerType GetPrimaryPointerType(int available_pointer_types) {
52 int available_pointer_types = GetAvailablePointerTypes();
53 if (available_pointer_types & POINTER_TYPE_FINE) 56 if (available_pointer_types & POINTER_TYPE_FINE)
54 return POINTER_TYPE_FINE; 57 return POINTER_TYPE_FINE;
55 if (available_pointer_types & POINTER_TYPE_COARSE) 58 if (available_pointer_types & POINTER_TYPE_COARSE)
56 return POINTER_TYPE_COARSE; 59 return POINTER_TYPE_COARSE;
57 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE); 60 DCHECK_EQ(available_pointer_types, POINTER_TYPE_NONE);
58 return POINTER_TYPE_NONE; 61 return POINTER_TYPE_NONE;
59 } 62 }
60 63
64 PointerType GetPrimaryPointerType() {
65 return GetPrimaryPointerType(GetAvailablePointerTypes());
66 }
67
61 // TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634 68 // TODO(mustaq@chromium.org): Use mouse detection logic. crbug.com/495634
62 int GetAvailableHoverTypes() { 69 int GetAvailableHoverTypes() {
63 // Assume a mouse is there 70 // Assume a mouse is there
64 int available_hover_types = HOVER_TYPE_HOVER; 71 int available_hover_types = HOVER_TYPE_HOVER;
65 if (IsTouchDevicePresent()) 72 if (IsTouchDevicePresent())
66 available_hover_types |= HOVER_TYPE_ON_DEMAND; 73 available_hover_types |= HOVER_TYPE_ON_DEMAND;
67 74
68 DCHECK(available_hover_types); 75 DCHECK(available_hover_types);
69 return available_hover_types; 76 return available_hover_types;
70 } 77 }
71 78
72 HoverType GetPrimaryHoverType() { 79 HoverType GetPrimaryHoverType(int available_hover_types) {
73 int available_hover_types = GetAvailableHoverTypes();
74 if (available_hover_types & HOVER_TYPE_HOVER) 80 if (available_hover_types & HOVER_TYPE_HOVER)
75 return HOVER_TYPE_HOVER; 81 return HOVER_TYPE_HOVER;
76 if (available_hover_types & HOVER_TYPE_ON_DEMAND) 82 if (available_hover_types & HOVER_TYPE_ON_DEMAND)
77 return HOVER_TYPE_ON_DEMAND; 83 return HOVER_TYPE_ON_DEMAND;
78 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE); 84 DCHECK_EQ(available_hover_types, HOVER_TYPE_NONE);
79 return HOVER_TYPE_NONE; 85 return HOVER_TYPE_NONE;
80 } 86 }
81 87
88 HoverType GetPrimaryHoverType() {
89 return GetPrimaryHoverType(GetAvailableHoverTypes());
90 }
91
82 } // namespace ui 92 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698