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

Unified Diff: ui/android/java/src/org/chromium/ui/base/TouchDevice.java

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 side-by-side diff with in-line comments
Download patch
Index: ui/android/java/src/org/chromium/ui/base/TouchDevice.java
diff --git a/ui/android/java/src/org/chromium/ui/base/TouchDevice.java b/ui/android/java/src/org/chromium/ui/base/TouchDevice.java
index e34441d12489dabd92bd42e65b21e8bf85fc7b28..abd8b7d6ff6d3be5d749a073fdba101b53d59914 100644
--- a/ui/android/java/src/org/chromium/ui/base/TouchDevice.java
+++ b/ui/android/java/src/org/chromium/ui/base/TouchDevice.java
@@ -49,12 +49,13 @@ public class TouchDevice {
}
/**
- * @return the pointer-types supported by the device, as the union (bitwise OR) of PointerType
- * bits.
+ * @return the pointer-types supported by the device in result[0]
+ * the hover-types supported by the device in result[1]
*/
@CalledByNative
- private static int availablePointerTypes(Context context) {
- int pointerTypesVal = 0;
+ private static int[] availablePointerAndHoverTypes(Context context) {
+ int[] result = new int[2];
+ result[0] = result[1] = 0;
for (int deviceId : InputDevice.getDeviceIds()) {
InputDevice inputDevice = InputDevice.getDevice(deviceId);
@@ -62,21 +63,37 @@ public class TouchDevice {
int sources = inputDevice.getSources();
- if (hasSource(sources, InputDevice.SOURCE_MOUSE)
- || hasSource(sources, InputDevice.SOURCE_STYLUS)
- || hasSource(sources, InputDevice.SOURCE_TOUCHPAD)
- || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) {
- pointerTypesVal |= PointerType.FINE;
+ if (hasAnySource(sources, InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_STYLUS
+ | InputDevice.SOURCE_TOUCHPAD | InputDevice.SOURCE_TRACKBALL)) {
+ result[0] |= PointerType.FINE;
} else if (hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) {
- pointerTypesVal |= PointerType.COARSE;
+ result[0] |= PointerType.COARSE;
}
+
+ if (hasAnySource(sources, InputDevice.SOURCE_MOUSE | InputDevice.SOURCE_TOUCHPAD
+ | InputDevice.SOURCE_TRACKBALL)) {
+ result[1] |= HoverType.HOVER;
+ } else if (hasAnySource(sources,
+ InputDevice.SOURCE_STYLUS | InputDevice.SOURCE_TOUCHSCREEN)) {
+ result[1] |= HoverType.ON_DEMAND;
+ }
+
// Remaining InputDevice sources: SOURCE_DPAD, SOURCE_GAMEPAD, SOURCE_JOYSTICK,
// SOURCE_KEYBOARD, SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN
}
- if (pointerTypesVal == 0) pointerTypesVal = PointerType.NONE;
+ if (result[0] == 0) result[0] = PointerType.NONE;
+ if (result[1] == 0) result[1] = HoverType.NONE;
- return pointerTypesVal;
+ return result;
+ }
+ /**
+ * @return the pointer-types supported by the device, as the union (bitwise OR) of PointerType
+ * bits.
+ */
+ @CalledByNative
+ private static int availablePointerTypes(Context context) {
+ return availablePointerAndHoverTypes(context)[0];
}
/**
@@ -84,29 +101,11 @@ public class TouchDevice {
*/
@CalledByNative
private static int availableHoverTypes(Context context) {
- int hoverTypesVal = 0;
-
- for (int deviceId : InputDevice.getDeviceIds()) {
- InputDevice inputDevice = InputDevice.getDevice(deviceId);
- if (inputDevice == null) continue;
-
- int sources = inputDevice.getSources();
-
- if (hasSource(sources, InputDevice.SOURCE_MOUSE)
- || hasSource(sources, InputDevice.SOURCE_TOUCHPAD)
- || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) {
- hoverTypesVal |= HoverType.HOVER;
- } else if (hasSource(sources, InputDevice.SOURCE_STYLUS)
- || hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) {
- hoverTypesVal |= HoverType.ON_DEMAND;
- }
- // Remaining InputDevice sources: SOURCE_DPAD, SOURCE_GAMEPAD, SOURCE_JOYSTICK,
- // SOURCE_KEYBOARD, SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN
- }
-
- if (hoverTypesVal == 0) hoverTypesVal = HoverType.NONE;
+ return availablePointerAndHoverTypes(context)[1];
+ }
- return hoverTypesVal;
+ private static boolean hasAnySource(int sources, int inputDeviceSources) {
+ return (sources & inputDeviceSources) != 0;
}
private static boolean hasSource(int sources, int inputDeviceSource) {

Powered by Google App Engine
This is Rietveld 408576698