Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/renderer_host/input/motion_event_android.h" | 5 #include "content/browser/renderer_host/input/motion_event_android.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "jni/MotionEvent_jni.h" | 8 #include "jni/MotionEvent_jni.h" |
| 9 | 9 |
| 10 using base::android::AttachCurrentThread; | 10 using base::android::AttachCurrentThread; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 cached_touch_majors_[1] = ToDips(touch_major_1_pixels); | 139 cached_touch_majors_[1] = ToDips(touch_major_1_pixels); |
| 140 cached_raw_position_offset_ = | 140 cached_raw_position_offset_ = |
| 141 ToDips(gfx::PointF(raw_pos_x_pixels, raw_pos_y_pixels)) - | 141 ToDips(gfx::PointF(raw_pos_x_pixels, raw_pos_y_pixels)) - |
| 142 cached_positions_[0]; | 142 cached_positions_[0]; |
| 143 cached_tool_types_[0] = FromAndroidToolType(android_tool_type_0); | 143 cached_tool_types_[0] = FromAndroidToolType(android_tool_type_0); |
| 144 cached_tool_types_[1] = FromAndroidToolType(android_tool_type_1); | 144 cached_tool_types_[1] = FromAndroidToolType(android_tool_type_1); |
| 145 } | 145 } |
| 146 | 146 |
| 147 MotionEventAndroid::MotionEventAndroid(float pix_to_dip, | 147 MotionEventAndroid::MotionEventAndroid(float pix_to_dip, |
| 148 JNIEnv* env, | 148 JNIEnv* env, |
| 149 jobject event) | 149 jobject event, |
| 150 bool should_recycle) | |
|
cjhopman
2014/07/09 22:29:12
So this constructor makes like ~16 jni calls (and
jdduke (slow)
2014/07/10 02:08:39
Agreed, I'll take a closer look at this. I think
| |
| 150 : cached_time_(FromAndroidTime(Java_MotionEvent_getEventTime(env, event))), | 151 : cached_time_(FromAndroidTime(Java_MotionEvent_getEventTime(env, event))), |
| 151 cached_action_( | 152 cached_action_( |
| 152 FromAndroidAction(Java_MotionEvent_getActionMasked(env, event))), | 153 FromAndroidAction(Java_MotionEvent_getActionMasked(env, event))), |
| 153 cached_pointer_count_(Java_MotionEvent_getPointerCount(env, event)), | 154 cached_pointer_count_(Java_MotionEvent_getPointerCount(env, event)), |
| 154 cached_history_size_(Java_MotionEvent_getHistorySize(env, event)), | 155 cached_history_size_(Java_MotionEvent_getHistorySize(env, event)), |
| 155 cached_action_index_(Java_MotionEvent_getActionIndex(env, event)), | 156 cached_action_index_(Java_MotionEvent_getActionIndex(env, event)), |
| 156 cached_button_state_( | 157 cached_button_state_( |
| 157 FromAndroidButtonState(Java_MotionEvent_getButtonState(env, event))), | 158 FromAndroidButtonState(Java_MotionEvent_getButtonState(env, event))), |
| 158 pix_to_dip_(pix_to_dip), | 159 pix_to_dip_(pix_to_dip), |
| 159 should_recycle_(true) { | 160 should_recycle_(should_recycle) { |
| 160 event_.Reset(env, event); | 161 event_.Reset(env, event); |
| 161 DCHECK(event_.obj()); | 162 DCHECK(event_.obj()); |
| 162 | 163 |
| 163 for (size_t i = 0; i < MAX_POINTERS_TO_CACHE; ++i) { | 164 for (size_t i = 0; i < MAX_POINTERS_TO_CACHE; ++i) { |
| 164 if (i < cached_pointer_count_) { | 165 if (i < cached_pointer_count_) { |
| 165 cached_positions_[i] = | 166 cached_positions_[i] = |
| 166 ToDips(gfx::PointF(Java_MotionEvent_getXF_I(env, event, i), | 167 ToDips(gfx::PointF(Java_MotionEvent_getXF_I(env, event, i), |
| 167 Java_MotionEvent_getYF_I(env, event, i))); | 168 Java_MotionEvent_getYF_I(env, event, i))); |
| 168 cached_pointer_ids_[i] = Java_MotionEvent_getPointerId(env, event, i); | 169 cached_pointer_ids_[i] = Java_MotionEvent_getPointerId(env, event, i); |
| 169 cached_touch_majors_[i] = | 170 cached_touch_majors_[i] = |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 | 319 |
| 319 scoped_ptr<ui::MotionEvent> MotionEventAndroid::Clone() const { | 320 scoped_ptr<ui::MotionEvent> MotionEventAndroid::Clone() const { |
| 320 return scoped_ptr<MotionEvent>(new MotionEventAndroid(*this)); | 321 return scoped_ptr<MotionEvent>(new MotionEventAndroid(*this)); |
| 321 } | 322 } |
| 322 | 323 |
| 323 scoped_ptr<ui::MotionEvent> MotionEventAndroid::Cancel() const { | 324 scoped_ptr<ui::MotionEvent> MotionEventAndroid::Cancel() const { |
| 324 // The input coordinates to |MotionEventAndroid| are always in device pixels, | 325 // The input coordinates to |MotionEventAndroid| are always in device pixels, |
| 325 // but the cached coordinates are in DIPs. | 326 // but the cached coordinates are in DIPs. |
| 326 const gfx::PointF position_pixels = | 327 const gfx::PointF position_pixels = |
| 327 gfx::ScalePoint(cached_positions_[0], 1.f / pix_to_dip_); | 328 gfx::ScalePoint(cached_positions_[0], 1.f / pix_to_dip_); |
| 329 const bool recycle = true; | |
| 328 return scoped_ptr<MotionEvent>( | 330 return scoped_ptr<MotionEvent>( |
| 329 new MotionEventAndroid(pix_to_dip_, | 331 new MotionEventAndroid(pix_to_dip_, |
| 330 AttachCurrentThread(), | 332 AttachCurrentThread(), |
| 331 Obtain(GetDownTime(), | 333 Obtain(GetDownTime(), |
| 332 GetEventTime(), | 334 GetEventTime(), |
| 333 MotionEventAndroid::ACTION_CANCEL, | 335 MotionEventAndroid::ACTION_CANCEL, |
| 334 position_pixels.x(), | 336 position_pixels.x(), |
| 335 position_pixels.y()).obj())); | 337 position_pixels.y()).obj(), |
| 338 recycle)); | |
| 336 } | 339 } |
| 337 | 340 |
| 338 float MotionEventAndroid::GetTouchMinor(size_t pointer_index) const { | 341 float MotionEventAndroid::GetTouchMinor(size_t pointer_index) const { |
| 339 return ToDips(Java_MotionEvent_getTouchMinorF_I( | 342 return ToDips(Java_MotionEvent_getTouchMinorF_I( |
| 340 AttachCurrentThread(), event_.obj(), pointer_index)); | 343 AttachCurrentThread(), event_.obj(), pointer_index)); |
| 341 } | 344 } |
| 342 | 345 |
| 343 float MotionEventAndroid::GetOrientation() const { | 346 float MotionEventAndroid::GetOrientation() const { |
| 344 return Java_MotionEvent_getOrientationF(AttachCurrentThread(), event_.obj()); | 347 return Java_MotionEvent_getOrientationF(AttachCurrentThread(), event_.obj()); |
| 345 } | 348 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 return Java_MotionEvent_obtainAVME_J_J_I_F_F_I(AttachCurrentThread(), | 382 return Java_MotionEvent_obtainAVME_J_J_I_F_F_I(AttachCurrentThread(), |
| 380 ToAndroidTime(down_time), | 383 ToAndroidTime(down_time), |
| 381 ToAndroidTime(event_time), | 384 ToAndroidTime(event_time), |
| 382 ToAndroidAction(action), | 385 ToAndroidAction(action), |
| 383 x_pixels, | 386 x_pixels, |
| 384 y_pixels, | 387 y_pixels, |
| 385 0); | 388 0); |
| 386 } | 389 } |
| 387 | 390 |
| 388 } // namespace content | 391 } // namespace content |
| OLD | NEW |