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

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: Fix windows compile issues 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
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.cc ('k') | ui/base/touch/touch_device.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..21b28c66d491461082c6fe0c69ef1aa51d2479d8 100644
--- a/ui/android/java/src/org/chromium/ui/base/TouchDevice.java
+++ b/ui/android/java/src/org/chromium/ui/base/TouchDevice.java
@@ -50,11 +50,14 @@ public class TouchDevice {
/**
* @return the pointer-types supported by the device, as the union (bitwise OR) of PointerType
- * bits.
+ * bits in result[0]
+ * the hover-types supported by the device, as the union (bitwise OR) of HoverType bits
+ * 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,51 +65,33 @@ 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;
}
- // Remaining InputDevice sources: SOURCE_DPAD, SOURCE_GAMEPAD, SOURCE_JOYSTICK,
- // SOURCE_KEYBOARD, SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN
- }
-
- if (pointerTypesVal == 0) pointerTypesVal = PointerType.NONE;
-
- return pointerTypesVal;
- }
-
- /**
- * @return the hover-types supported by the device, as the union (bitwise OR) of HoverType bits.
- */
- @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;
+ 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 (hoverTypesVal == 0) hoverTypesVal = HoverType.NONE;
+ if (result[0] == 0) result[0] = PointerType.NONE;
+ if (result[1] == 0) result[1] = HoverType.NONE;
+
+ return result;
+ }
- return hoverTypesVal;
+ private static boolean hasAnySource(int sources, int inputDeviceSources) {
+ return (sources & inputDeviceSources) != 0;
}
private static boolean hasSource(int sources, int inputDeviceSource) {
« no previous file with comments | « content/browser/renderer_host/render_view_host_impl.cc ('k') | ui/base/touch/touch_device.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698