Skip to content

Commit 7927af9

Browse files
committed
ndk: Extend new flags
1 parent a140ca0 commit 7927af9

File tree

3 files changed

+97
-13
lines changed

3 files changed

+97
-13
lines changed

ndk/src/event.rs

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,63 @@ pub enum Axis {
326326
Generic15 = ffi::AMOTION_EVENT_AXIS_GENERIC_15 as i32,
327327
Generic16 = ffi::AMOTION_EVENT_AXIS_GENERIC_16 as i32,
328328

329+
/// Axis constant: X gesture offset axis of a motion event.
330+
///
331+
/// - For a touch pad, reports the distance that a swipe gesture has moved in the X axis, as a
332+
/// proportion of the touch pad's size. For example, if a touch pad is `1000` units wide, and
333+
/// a swipe gesture starts at `X = 500` then moves to `X = 400`, this axis would have a value
334+
/// of `-0.1`.
335+
///
336+
/// These values are relative to the state from the last event, not accumulated, so developers
337+
/// should make sure to process this axis value for all batched historical events.
338+
///
339+
/// This axis is only set on the first pointer in a motion event.
340+
#[doc(alias = "AMOTION_EVENT_AXIS_GESTURE_X_OFFSET")]
341+
GestureXOffset = ffi::AMOTION_EVENT_AXIS_GESTURE_X_OFFSET as i32,
342+
/// Axis constant: Y gesture offset axis of a motion event.
343+
///
344+
/// The same as [`Axis::GestureXOffset`], but for the Y axis.
345+
#[doc(alias = "AMOTION_EVENT_AXIS_GESTURE_Y_OFFSET")]
346+
GestureYOffset = ffi::AMOTION_EVENT_AXIS_GESTURE_Y_OFFSET as i32,
347+
/// Axis constant: X scroll distance axis of a motion event.
348+
///
349+
/// - For a touch pad, reports the distance that should be scrolled in the X axis as a result of
350+
/// the user's two-finger scroll gesture, in display pixels.
351+
///
352+
/// These values are relative to the state from the last event, not accumulated, so developers
353+
/// should make sure to process this axis value for all batched historical events.
354+
///
355+
/// This axis is only set on the first pointer in a motion event.
356+
#[doc(alias = "AMOTION_EVENT_AXIS_GESTURE_SCROLL_X_DISTANCE")]
357+
GestureScrollXDistance = ffi::AMOTION_EVENT_AXIS_GESTURE_SCROLL_X_DISTANCE as i32,
358+
/// Axis constant: Y scroll distance axis of a motion event.
359+
///
360+
/// The same as [`Axis::GestureScrollXDistance`], but for the Y axis.
361+
#[doc(alias = "AMOTION_EVENT_AXIS_GESTURE_SCROLL_Y_DISTANCE")]
362+
GestureScrollYDistance = ffi::AMOTION_EVENT_AXIS_GESTURE_SCROLL_Y_DISTANCE as i32,
363+
/// Axis constant: pinch scale factor of a motion event.
364+
///
365+
/// - For a touch pad, reports the change in distance between the fingers when the user is
366+
/// making a pinch gesture, as a proportion of that distance when the gesture was last
367+
/// reported. For example, if the fingers were `50` units apart and are now `52` units apart,
368+
/// the scale factor would be `1.04`.
369+
///
370+
/// These values are relative to the state from the last event, not accumulated, so developers
371+
/// should make sure to process this axis value for all batched historical events.
372+
///
373+
/// This axis is only set on the first pointer in a motion event.
374+
#[doc(alias = "AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR")]
375+
GesturePinchScaleFactor = ffi::AMOTION_EVENT_AXIS_GESTURE_PINCH_SCALE_FACTOR as i32,
376+
/// Axis constant: the number of fingers being used in a multi-finger swipe gesture.
377+
///
378+
/// - For a touch pad, reports the number of fingers being used in a multi-finger swipe gesture
379+
/// (with [`MotionClassification::MultiFingerSwipe`]).
380+
///
381+
/// Since [`MotionClassification::MultiFingerSwipe`] is a hidden API, so is this axis. It is
382+
/// only set on the first pointer in a motion event.
383+
#[doc(alias = "AMOTION_EVENT_AXIS_GESTURE_SWIPE_FINGER_COUNT")]
384+
GestureSwipeFingerCount = ffi::AMOTION_EVENT_AXIS_GESTURE_SWIPE_FINGER_COUNT as i32,
385+
329386
#[doc(hidden)]
330387
#[num_enum(catch_all)]
331388
__Unknown(i32),
@@ -573,7 +630,7 @@ impl MotionEvent {
573630
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getmetastate)
574631
#[inline]
575632
pub fn meta_state(&self) -> MetaState {
576-
unsafe { MetaState(ffi::AMotionEvent_getMetaState(self.ptr.as_ptr()) as u32) }
633+
MetaState(unsafe { ffi::AMotionEvent_getMetaState(self.ptr.as_ptr()) } as u32)
577634
}
578635

579636
/// Returns the button state during this event, as a bitfield.
@@ -582,7 +639,7 @@ impl MotionEvent {
582639
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getbuttonstate)
583640
#[inline]
584641
pub fn button_state(&self) -> ButtonState {
585-
unsafe { ButtonState(ffi::AMotionEvent_getButtonState(self.ptr.as_ptr()) as u32) }
642+
ButtonState(unsafe { ffi::AMotionEvent_getButtonState(self.ptr.as_ptr()) } as u32)
586643
}
587644

588645
/// Returns the time of the start of this gesture, in the `java.lang.System.nanoTime()` time
@@ -601,7 +658,7 @@ impl MotionEvent {
601658
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getedgeflags)
602659
#[inline]
603660
pub fn edge_flags(&self) -> EdgeFlags {
604-
unsafe { EdgeFlags(ffi::AMotionEvent_getEdgeFlags(self.ptr.as_ptr()) as u32) }
661+
EdgeFlags(unsafe { ffi::AMotionEvent_getEdgeFlags(self.ptr.as_ptr()) } as u32)
605662
}
606663

607664
/// Returns the time of this event, in the `java.lang.System.nanoTime()` time base
@@ -619,7 +676,7 @@ impl MotionEvent {
619676
/// docs](https://developer.android.com/ndk/reference/group/input#amotionevent_getflags)
620677
#[inline]
621678
pub fn flags(&self) -> MotionEventFlags {
622-
unsafe { MotionEventFlags(ffi::AMotionEvent_getFlags(self.ptr.as_ptr()) as u32) }
679+
MotionEventFlags(unsafe { ffi::AMotionEvent_getFlags(self.ptr.as_ptr()) } as u32)
623680
}
624681

625682
/// Returns the offset in the x direction between the coordinates and the raw coordinates
@@ -657,6 +714,26 @@ impl MotionEvent {
657714
pub fn y_precision(&self) -> f32 {
658715
unsafe { ffi::AMotionEvent_getYPrecision(self.ptr.as_ptr()) }
659716
}
717+
718+
/// Get the action button for the motion event. Returns a valid action button when the event is
719+
/// associated with a button press or button release action. For other actions the return value
720+
/// is undefined.
721+
#[cfg(feature = "api-level-33")]
722+
#[doc(alias = "AMotionEvent_getActionButton")]
723+
// TODO: Button enum to signify only one valid value?
724+
pub fn action_button(&self) -> ButtonState {
725+
ButtonState(unsafe { ffi::AMotionEvent_getActionButton(self.ptr.as_ptr()) } as u32)
726+
}
727+
728+
/// Returns the classification for the current gesture. The classification may change as more
729+
/// events become available for the same gesture.
730+
#[cfg(feature = "api-level-33")]
731+
#[doc(alias = "AMotionEvent_getClassification")]
732+
pub fn classification(&self) -> MotionClassification {
733+
u32::try_from(unsafe { ffi::AMotionEvent_getClassification(self.ptr.as_ptr()) })
734+
.unwrap()
735+
.into()
736+
}
660737
}
661738

662739
/// A view into the data of a specific pointer in a motion event.

ndk/src/hardware_buffer.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,14 @@ bitflags::bitflags! {
128128
#[doc(alias = "AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE")]
129129
const GPU_MIPMAP_COMPLETE = ffi::AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE.0;
130130

131-
// TODO: Only available in a newer NDK
132-
// /// Usage: The buffer is used for front-buffer rendering. When front-buffering rendering
133-
// /// is specified, different usages may adjust their behavior as a result. For example, when
134-
// /// used as [`HardwareBufferFormat::GPU_COLOR_OUTPUT`] the buffer will behave similar to a
135-
// /// single-buffered window. When used with [`HardwareBufferFormat::COMPOSER_OVERLAY`], the
136-
// /// system will try to prioritize the buffer receiving an overlay plane & avoid caching it
137-
// /// in intermediate composition buffers.
138-
// #[doc(alias = "AHARDWAREBUFFER_USAGE_FRONT_BUFFER")]
139-
// const USAGE_FRONT_BUFFER = ffi::AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_FRONT_BUFFER.0;
131+
/// Usage: The buffer is used for front-buffer rendering. When front-buffering rendering
132+
/// is specified, different usages may adjust their behavior as a result. For example, when
133+
/// used as [`HardwareBufferFormat::GPU_COLOR_OUTPUT`] the buffer will behave similar to a
134+
/// single-buffered window. When used with [`HardwareBufferFormat::COMPOSER_OVERLAY`], the
135+
/// system will try to prioritize the buffer receiving an overlay plane & avoid caching it
136+
/// in intermediate composition buffers.
137+
#[doc(alias = "AHARDWAREBUFFER_USAGE_FRONT_BUFFER")]
138+
const USAGE_FRONT_BUFFER = ffi::AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_FRONT_BUFFER.0;
140139

141140
#[doc(alias = "AHARDWAREBUFFER_USAGE_VENDOR_0")]
142141
const VENDOR_0 = ffi::AHardwareBuffer_UsageFlags::AHARDWAREBUFFER_USAGE_VENDOR_0.0;

ndk/src/media/image_reader.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ impl ImageReader {
184184
Ok(Self::from_ptr(inner))
185185
}
186186

187+
/// [`ImageReader`] constructor similar to [`ImageReader::new_with_usage()`] that takes two
188+
/// additional parameters to build the format of the [`Image`]. All other parameters and the
189+
/// return values are identical to those passed to [`ImageReader::new_with_usage()`].
190+
///
191+
/// Instead of passing an [`ImageFormat`] parameter, this constructor accepts the combination
192+
/// of [`HardwareBufferFormat`] and [`DataSpace`] for the format of the Image that the reader
193+
/// will produce.
187194
#[cfg(feature = "api-level-34")]
188195
#[doc(alias = "AImageReader_newWithDataSpace")]
189196
pub fn new_with_data_space(
@@ -482,6 +489,7 @@ impl Image {
482489
std::mem::forget(self);
483490
}
484491

492+
/// Query the [`DataSpace`] of the input [`Image`].
485493
#[cfg(feature = "api-level-34")]
486494
#[doc(alias = "AImage_getDataSpace")]
487495
pub fn data_space(&self) -> Result<DataSpace> {

0 commit comments

Comments
 (0)