Skip to content

Commit

Permalink
game_activity/input: support Pointer::tool_type()
Browse files Browse the repository at this point in the history
This maintains compatibility with the `ndk` crate's `Pointer` API

Ref: rust-mobile/ndk#323

This will also be required for enabling pen pressure support to
Winit, re: rust-windowing/winit#2396
  • Loading branch information
rib committed Oct 23, 2022
1 parent bd8cc86 commit c75f33a
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,7 @@ static struct {

jmethodID getPointerCount;
jmethodID getPointerId;
jmethodID getToolType;
jmethodID getRawX;
jmethodID getRawY;
jmethodID getXPrecision;
Expand Down Expand Up @@ -941,6 +942,8 @@ extern "C" int GameActivityMotionEvent_fromJava(
env->GetMethodID(motionEventClass, "getPointerCount", "()I");
gMotionEventClassInfo.getPointerId =
env->GetMethodID(motionEventClass, "getPointerId", "(I)I");
gMotionEventClassInfo.getToolType =
env->GetMethodID(motionEventClass, "getToolType", "(I)I");
if (sdkVersion >= 29) {
gMotionEventClassInfo.getRawX =
env->GetMethodID(motionEventClass, "getRawX", "(I)F");
Expand Down Expand Up @@ -1001,6 +1004,8 @@ extern "C" int GameActivityMotionEvent_fromJava(
out_event->pointers[i] = {
/*id=*/env->CallIntMethod(motionEvent,
gMotionEventClassInfo.getPointerId, i),
/*toolType=*/env->CallIntMethod(motionEvent,
gMotionEventClassInfo.getToolType, i),
/*axisValues=*/{0},
/*rawX=*/gMotionEventClassInfo.getRawX
? env->CallFloatMethod(motionEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ typedef struct GameActivity {
*/
typedef struct GameActivityPointerAxes {
int32_t id;
int32_t toolType;
float axisValues[GAME_ACTIVITY_POINTER_INFO_AXIS_COUNT];
float rawX;
float rawY;
Expand Down
81 changes: 47 additions & 34 deletions android-activity/src/game_activity/ffi_aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2713,6 +2713,7 @@ fn bindgen_test_layout_GameActivity() {
#[derive(Debug, Copy, Clone)]
pub struct GameActivityPointerAxes {
pub id: i32,
pub toolType: i32,
pub axisValues: [f32; 48usize],
pub rawX: f32,
pub rawY: f32,
Expand All @@ -2721,7 +2722,7 @@ pub struct GameActivityPointerAxes {
fn bindgen_test_layout_GameActivityPointerAxes() {
assert_eq!(
::std::mem::size_of::<GameActivityPointerAxes>(),
204usize,
208usize,
concat!("Size of: ", stringify!(GameActivityPointerAxes))
);
assert_eq!(
Expand All @@ -2741,9 +2742,21 @@ fn bindgen_test_layout_GameActivityPointerAxes() {
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<GameActivityPointerAxes>())).axisValues as *const _ as usize
&(*(::std::ptr::null::<GameActivityPointerAxes>())).toolType as *const _ as usize
},
4usize,
concat!(
"Offset of field: ",
stringify!(GameActivityPointerAxes),
"::",
stringify!(toolType)
)
);
assert_eq!(
unsafe {
&(*(::std::ptr::null::<GameActivityPointerAxes>())).axisValues as *const _ as usize
},
8usize,
concat!(
"Offset of field: ",
stringify!(GameActivityPointerAxes),
Expand All @@ -2753,7 +2766,7 @@ fn bindgen_test_layout_GameActivityPointerAxes() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<GameActivityPointerAxes>())).rawX as *const _ as usize },
196usize,
200usize,
concat!(
"Offset of field: ",
stringify!(GameActivityPointerAxes),
Expand All @@ -2763,7 +2776,7 @@ fn bindgen_test_layout_GameActivityPointerAxes() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<GameActivityPointerAxes>())).rawY as *const _ as usize },
200usize,
204usize,
concat!(
"Offset of field: ",
stringify!(GameActivityPointerAxes),
Expand Down Expand Up @@ -2888,7 +2901,7 @@ pub struct GameActivityMotionEvent {
fn bindgen_test_layout_GameActivityMotionEvent() {
assert_eq!(
::std::mem::size_of::<GameActivityMotionEvent>(),
1704usize,
1736usize,
concat!("Size of: ", stringify!(GameActivityMotionEvent))
);
assert_eq!(
Expand Down Expand Up @@ -3050,7 +3063,7 @@ fn bindgen_test_layout_GameActivityMotionEvent() {
unsafe {
&(*(::std::ptr::null::<GameActivityMotionEvent>())).precisionX as *const _ as usize
},
1692usize,
1724usize,
concat!(
"Offset of field: ",
stringify!(GameActivityMotionEvent),
Expand All @@ -3062,7 +3075,7 @@ fn bindgen_test_layout_GameActivityMotionEvent() {
unsafe {
&(*(::std::ptr::null::<GameActivityMotionEvent>())).precisionY as *const _ as usize
},
1696usize,
1728usize,
concat!(
"Offset of field: ",
stringify!(GameActivityMotionEvent),
Expand All @@ -3074,7 +3087,7 @@ fn bindgen_test_layout_GameActivityMotionEvent() {
unsafe {
&(*(::std::ptr::null::<GameActivityMotionEvent>())).historicalStart as *const _ as usize
},
1700usize,
1732usize,
concat!(
"Offset of field: ",
stringify!(GameActivityMotionEvent),
Expand All @@ -3086,7 +3099,7 @@ fn bindgen_test_layout_GameActivityMotionEvent() {
unsafe {
&(*(::std::ptr::null::<GameActivityMotionEvent>())).historicalCount as *const _ as usize
},
1702usize,
1734usize,
concat!(
"Offset of field: ",
stringify!(GameActivityMotionEvent),
Expand Down Expand Up @@ -7208,7 +7221,7 @@ pub struct android_input_buffer {
fn bindgen_test_layout_android_input_buffer() {
assert_eq!(
::std::mem::size_of::<android_input_buffer>(),
40312usize,
40824usize,
concat!("Size of: ", stringify!(android_input_buffer))
);
assert_eq!(
Expand All @@ -7232,7 +7245,7 @@ fn bindgen_test_layout_android_input_buffer() {
unsafe {
&(*(::std::ptr::null::<android_input_buffer>())).motionEventsCount as *const _ as usize
},
27264usize,
27776usize,
concat!(
"Offset of field: ",
stringify!(android_input_buffer),
Expand All @@ -7245,7 +7258,7 @@ fn bindgen_test_layout_android_input_buffer() {
&(*(::std::ptr::null::<android_input_buffer>())).historicalAxisSamples as *const _
as usize
},
27272usize,
27784usize,
concat!(
"Offset of field: ",
stringify!(android_input_buffer),
Expand All @@ -7258,7 +7271,7 @@ fn bindgen_test_layout_android_input_buffer() {
&(*(::std::ptr::null::<android_input_buffer>())).historicalSamplesCount as *const _
as usize
},
40072usize,
40584usize,
concat!(
"Offset of field: ",
stringify!(android_input_buffer),
Expand All @@ -7268,7 +7281,7 @@ fn bindgen_test_layout_android_input_buffer() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_input_buffer>())).keyEvents as *const _ as usize },
40080usize,
40592usize,
concat!(
"Offset of field: ",
stringify!(android_input_buffer),
Expand All @@ -7280,7 +7293,7 @@ fn bindgen_test_layout_android_input_buffer() {
unsafe {
&(*(::std::ptr::null::<android_input_buffer>())).keyEventsCount as *const _ as usize
},
40304usize,
40816usize,
concat!(
"Offset of field: ",
stringify!(android_input_buffer),
Expand Down Expand Up @@ -7411,7 +7424,7 @@ pub struct android_app {
fn bindgen_test_layout_android_app() {
assert_eq!(
::std::mem::size_of::<android_app>(),
80912usize,
81936usize,
concat!("Size of: ", stringify!(android_app))
);
assert_eq!(
Expand Down Expand Up @@ -7541,7 +7554,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).currentInputBuffer as *const _ as usize },
80712usize,
81736usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7551,7 +7564,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).textInputState as *const _ as usize },
80716usize,
81740usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7561,7 +7574,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).mutex as *const _ as usize },
80720usize,
81744usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7571,7 +7584,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).cond as *const _ as usize },
80760usize,
81784usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7581,7 +7594,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).msgread as *const _ as usize },
80808usize,
81832usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7591,7 +7604,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).msgwrite as *const _ as usize },
80812usize,
81836usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7601,7 +7614,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).thread as *const _ as usize },
80816usize,
81840usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7611,7 +7624,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).cmdPollSource as *const _ as usize },
80824usize,
81848usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7621,7 +7634,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).running as *const _ as usize },
80848usize,
81872usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7631,7 +7644,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).stateSaved as *const _ as usize },
80852usize,
81876usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7641,7 +7654,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).destroyed as *const _ as usize },
80856usize,
81880usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7651,7 +7664,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).redrawNeeded as *const _ as usize },
80860usize,
81884usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7661,7 +7674,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).pendingWindow as *const _ as usize },
80864usize,
81888usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7671,7 +7684,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).pendingContentRect as *const _ as usize },
80872usize,
81896usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7681,7 +7694,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).keyEventFilter as *const _ as usize },
80888usize,
81912usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7691,7 +7704,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).motionEventFilter as *const _ as usize },
80896usize,
81920usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7703,7 +7716,7 @@ fn bindgen_test_layout_android_app() {
unsafe {
&(*(::std::ptr::null::<android_app>())).inputAvailableWakeUp as *const _ as usize
},
80904usize,
81928usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand All @@ -7713,7 +7726,7 @@ fn bindgen_test_layout_android_app() {
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<android_app>())).inputSwapPending as *const _ as usize },
80905usize,
81929usize,
concat!(
"Offset of field: ",
stringify!(android_app),
Expand Down
Loading

0 comments on commit c75f33a

Please sign in to comment.