Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ndk/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use std::{
ffi::{CStr, CString},
io,
os::fd::{FromRawFd, OwnedFd},
os::fd::{FromRawFd as _, OwnedFd},
ptr::NonNull,
};

Expand Down
8 changes: 4 additions & 4 deletions ndk/src/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ impl AudioStreamBuilder {
#[doc(alias = "AAudioStreamBuilder_setAllowedCapturePolicy")]
pub fn allowed_capture_policy(self, capture_policy: AudioAllowedCapturePolicy) -> Self {
unsafe {
ffi::AAudioStreamBuilder_setAllowedCapturePolicy(self.as_ptr(), capture_policy.into())
ffi::AAudioStreamBuilder_setAllowedCapturePolicy(self.as_ptr(), capture_policy.into());
};
self
}
Expand Down Expand Up @@ -692,7 +692,7 @@ impl AudioStreamBuilder {
self.as_ptr(),
Some(ffi_callback),
ptr as *mut c_void,
)
);
};

self.data_callback = Some(boxed);
Expand Down Expand Up @@ -763,15 +763,15 @@ impl AudioStreamBuilder {
let err = AudioError::from_result(error).unwrap_err();
(*callback)(&stream, err);
std::mem::forget(stream);
})
});
}

unsafe {
ffi::AAudioStreamBuilder_setErrorCallback(
self.as_ptr(),
Some(ffi_callback),
ptr as *mut c_void,
)
);
};

self.error_callback = Some(boxed);
Expand Down
1 change: 1 addition & 0 deletions ndk/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl Configuration {
}

/// Create a new `Configuration`, with none of the values set.
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
unsafe {
Self {
Expand Down
2 changes: 1 addition & 1 deletion ndk/src/data_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ pub enum DataSpaceStandard {
/// Transfer aspect.
///
/// Transfer characteristics are the opto-electronic transfer characteristic at the source as a
///function of linear optical intensity (luminance).
/// function of linear optical intensity (luminance).
///
/// For digital signals, `E` corresponds to the recorded value. Normally, the transfer function is
/// applied in `RGB` space to each of the `R`, `G` and `B` components independently. This may result
Expand Down
12 changes: 7 additions & 5 deletions ndk/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
//! [`android.view.MotionEvent`]: https://developer.android.com/reference/android/view/MotionEvent
//! [`android.view.KeyEvent`]: https://developer.android.com/reference/android/view/KeyEvent

use std::{ops::Deref, ptr::NonNull};
use std::ptr::NonNull;

#[cfg(feature = "api-level-31")]
use jni_sys::{jobject, JNIEnv};
use num_enum::{FromPrimitive, IntoPrimitive};
#[cfg(feature = "api-level-31")]
use std::ops::Deref;

/// A native [`AInputEvent *`]
///
Expand Down Expand Up @@ -161,8 +163,8 @@ impl InputEvent {
#[doc(alias = "AInputEvent_getType")]
pub unsafe fn from_ptr(ptr: NonNull<ffi::AInputEvent>) -> Self {
match ffi::AInputEvent_getType(ptr.as_ptr()) as u32 {
ffi::AINPUT_EVENT_TYPE_KEY => InputEvent::KeyEvent(KeyEvent::from_ptr(ptr)),
ffi::AINPUT_EVENT_TYPE_MOTION => InputEvent::MotionEvent(MotionEvent::from_ptr(ptr)),
ffi::AINPUT_EVENT_TYPE_KEY => Self::KeyEvent(KeyEvent::from_ptr(ptr)),
ffi::AINPUT_EVENT_TYPE_MOTION => Self::MotionEvent(MotionEvent::from_ptr(ptr)),
x => panic!("Bad event type received: {}", x),
}
}
Expand All @@ -171,8 +173,8 @@ impl InputEvent {
#[inline]
pub fn ptr(&self) -> NonNull<ffi::AInputEvent> {
match self {
InputEvent::MotionEvent(MotionEvent { ptr }) => *ptr,
InputEvent::KeyEvent(KeyEvent { ptr }) => *ptr,
Self::MotionEvent(MotionEvent { ptr }) => *ptr,
Self::KeyEvent(KeyEvent { ptr }) => *ptr,
}
}

Expand Down
53 changes: 27 additions & 26 deletions ndk/src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use std::convert::TryFrom;
use std::ffi::{CStr, OsStr};
use std::fmt::{self, Write as _};
use std::os::unix::prelude::OsStrExt;
use std::os::unix::prelude::OsStrExt as _;
use std::path::Path;
use std::ptr::NonNull;

Expand Down Expand Up @@ -37,51 +37,51 @@ impl FontWeight {
/// The minimum value for the font weight value. Unlike [`ffi::AFONT_WEIGHT_MIN`] being `0`,
/// [`FontWeight::MIN`] is `1` to make the `MIN..MAX` range be inclusive, keeping consistency
/// between [`FontWeight`] and other types like `std::num::NonZeroU*`.
pub const MIN: FontWeight = FontWeight(ffi::AFONT_WEIGHT_MIN as u16 + 1);
pub const MIN: Self = Self(ffi::AFONT_WEIGHT_MIN as u16 + 1);

/// A font weight value for the thin weight.
pub const THIN: FontWeight = FontWeight(ffi::AFONT_WEIGHT_THIN as u16);
pub const THIN: Self = Self(ffi::AFONT_WEIGHT_THIN as u16);

/// A font weight value for the extra-light weight.
pub const EXTRA_LIGHT: FontWeight = FontWeight(ffi::AFONT_WEIGHT_EXTRA_LIGHT as u16);
pub const EXTRA_LIGHT: Self = Self(ffi::AFONT_WEIGHT_EXTRA_LIGHT as u16);

/// A font weight value for the light weight.
pub const LIGHT: FontWeight = FontWeight(ffi::AFONT_WEIGHT_LIGHT as u16);
pub const LIGHT: Self = Self(ffi::AFONT_WEIGHT_LIGHT as u16);

/// A font weight value for the normal weight.
pub const NORMAL: FontWeight = FontWeight(ffi::AFONT_WEIGHT_NORMAL as u16);
pub const NORMAL: Self = Self(ffi::AFONT_WEIGHT_NORMAL as u16);

/// A font weight value for the medium weight.
pub const MEDIUM: FontWeight = FontWeight(ffi::AFONT_WEIGHT_MEDIUM as u16);
pub const MEDIUM: Self = Self(ffi::AFONT_WEIGHT_MEDIUM as u16);

/// A font weight value for the semi-bold weight.
pub const SEMI_BOLD: FontWeight = FontWeight(ffi::AFONT_WEIGHT_SEMI_BOLD as u16);
pub const SEMI_BOLD: Self = Self(ffi::AFONT_WEIGHT_SEMI_BOLD as u16);

/// A font weight value for the bold weight.
pub const BOLD: FontWeight = FontWeight(ffi::AFONT_WEIGHT_BOLD as u16);
pub const BOLD: Self = Self(ffi::AFONT_WEIGHT_BOLD as u16);

/// A font weight value for the extra-bold weight.
pub const EXTRA_BOLD: FontWeight = FontWeight(ffi::AFONT_WEIGHT_EXTRA_BOLD as u16);
pub const EXTRA_BOLD: Self = Self(ffi::AFONT_WEIGHT_EXTRA_BOLD as u16);

/// A font weight value for the black weight.
pub const BLACK: FontWeight = FontWeight(ffi::AFONT_WEIGHT_BLACK as u16);
pub const BLACK: Self = Self(ffi::AFONT_WEIGHT_BLACK as u16);

/// The maximum value for the font weight value.
pub const MAX: FontWeight = FontWeight(ffi::AFONT_WEIGHT_MAX as u16);
pub const MAX: Self = Self(ffi::AFONT_WEIGHT_MAX as u16);
}

impl fmt::Display for FontWeight {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match *self {
FontWeight::THIN => "Thin",
FontWeight::EXTRA_LIGHT => "Extra Light (Ultra Light)",
FontWeight::LIGHT => "Light",
FontWeight::NORMAL => "Normal (Regular)",
FontWeight::MEDIUM => "Medium",
FontWeight::SEMI_BOLD => "Semi Bold (Demi Bold)",
FontWeight::BOLD => "Bold",
FontWeight::EXTRA_BOLD => "Extra Bold (Ultra Bold)",
FontWeight::BLACK => "Black (Heavy)",
Self::THIN => "Thin",
Self::EXTRA_LIGHT => "Extra Light (Ultra Light)",
Self::LIGHT => "Light",
Self::NORMAL => "Normal (Regular)",
Self::MEDIUM => "Medium",
Self::SEMI_BOLD => "Semi Bold (Demi Bold)",
Self::BOLD => "Bold",
Self::EXTRA_BOLD => "Extra Bold (Ultra Bold)",
Self::BLACK => "Black (Heavy)",
_ => return writeln!(f, "{}", self.0),
})
}
Expand All @@ -103,7 +103,7 @@ impl TryFrom<u16> for FontWeight {
type Error = FontWeightValueError;

fn try_from(value: u16) -> Result<Self, Self::Error> {
FontWeight::new(value)
Self::new(value)
}
}

Expand All @@ -113,7 +113,7 @@ pub struct AxisTag(u32);

impl AxisTag {
/// Checks whether the given 4-byte array can construct a valid axis tag and returns
/// [`Ok(AxisTag)`] if the array is valid.
/// `Ok(AxisTag)` if the array is valid.
///
/// Each byte in a tag must be in the range 0x20 to 0x7E. A space character cannot be followed
/// by a non-space character. A tag must have one to four non-space characters. See the
Expand Down Expand Up @@ -166,7 +166,7 @@ impl AxisTag {
}

/// Checks whether the given 4-byte array can construct a valid axis tag and returns
/// [`Ok(AxisTag)`] if the array is valid.
/// `Ok(AxisTag)` if the array is valid.
///
/// See [`AxisTag::from_be()`] for more details.
pub const fn from_be_checked(value: u32) -> Result<Self, AxisTagValueError> {
Expand Down Expand Up @@ -431,10 +431,11 @@ impl FontMatcher {

/// Creates a new [`FontMatcher`] object. [`FontMatcher`] selects the best font from the
/// parameters set by the user.
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
let ptr = NonNull::new(unsafe { ffi::AFontMatcher_create() })
.expect("AFontMatcher_create returned NULL");
unsafe { FontMatcher::from_ptr(ptr) }
unsafe { Self::from_ptr(ptr) }
}

/// Performs the matching from the generic font family for the text and select one font.
Expand Down Expand Up @@ -532,7 +533,7 @@ impl SystemFontIterator {
/// Creates a system font iterator.
pub fn new() -> Option<Self> {
NonNull::new(unsafe { ffi::ASystemFontIterator_open() })
.map(|p| unsafe { SystemFontIterator::from_ptr(p) })
.map(|p| unsafe { Self::from_ptr(p) })
}
}

Expand Down
6 changes: 3 additions & 3 deletions ndk/src/hardware_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
mem::MaybeUninit,
ops::Deref,
os::{
fd::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd},
fd::{AsRawFd as _, BorrowedFd, FromRawFd as _, IntoRawFd, OwnedFd},
raw::c_void,
},
ptr::NonNull,
Expand Down Expand Up @@ -184,13 +184,13 @@ bitflags::bitflags! {
impl HardwareBufferUsage {
/// Helper to read [`HardwareBufferUsage::CPU_READ_MASK`] values.
#[doc(alias = "AHARDWAREBUFFER_USAGE_CPU_READ_MASK")]
pub fn cpu_read(self) -> HardwareBufferUsage {
pub fn cpu_read(self) -> Self {
self.intersection(Self::CPU_READ_MASK)
}

/// Helper to read [`HardwareBufferUsage::CPU_WRITE_MASK`] values.
#[doc(alias = "AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK")]
pub fn cpu_write(self) -> HardwareBufferUsage {
pub fn cpu_write(self) -> Self {
self.intersection(Self::CPU_WRITE_MASK)
}
}
Expand Down
4 changes: 2 additions & 2 deletions ndk/src/input_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl InputQueue {
#[doc(alias = "AInputQueue_finishEvent")]
pub fn finish_event(&self, event: InputEvent, handled: bool) {
unsafe {
ffi::AInputQueue_finishEvent(self.ptr.as_ptr(), event.ptr().as_ptr(), handled as c_int)
ffi::AInputQueue_finishEvent(self.ptr.as_ptr(), event.ptr().as_ptr(), handled as c_int);
}
}

Expand All @@ -131,7 +131,7 @@ impl InputQueue {
id,
None,
ptr::null_mut(),
)
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ndk/src/looper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use std::mem::ManuallyDrop;
use std::os::{
fd::{AsRawFd, BorrowedFd, RawFd},
fd::{AsRawFd as _, BorrowedFd, RawFd},
raw::c_void,
};
use std::ptr;
Expand Down
12 changes: 6 additions & 6 deletions ndk/src/media/image_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#![cfg(feature = "api-level-24")]

#[cfg(feature = "api-level-26")]
use std::os::fd::{FromRawFd, IntoRawFd, OwnedFd};
use std::os::fd::{FromRawFd as _, IntoRawFd as _, OwnedFd};
use std::{ffi::c_void, fmt, mem::MaybeUninit, ptr::NonNull};

use num_enum::{FromPrimitive, IntoPrimitive};
Expand Down Expand Up @@ -77,9 +77,9 @@ pub enum AcquireResult<T> {
impl<T> AcquireResult<T> {
fn map<U>(self, f: impl FnOnce(T) -> U) -> AcquireResult<U> {
match self {
AcquireResult::Image(img) => AcquireResult::Image(f(img)),
AcquireResult::NoBufferAvailable => AcquireResult::NoBufferAvailable,
AcquireResult::MaxImagesAcquired => AcquireResult::MaxImagesAcquired,
Self::Image(img) => AcquireResult::Image(f(img)),
Self::NoBufferAvailable => AcquireResult::NoBufferAvailable,
Self::MaxImagesAcquired => AcquireResult::MaxImagesAcquired,
}
}
}
Expand Down Expand Up @@ -225,7 +225,7 @@ impl ImageReader {
let listener: *mut ImageListener = context.cast();
(*listener)(&reader);
std::mem::forget(reader);
})
});
}

let mut listener = ffi::AImageReader_ImageListener {
Expand Down Expand Up @@ -257,7 +257,7 @@ impl ImageReader {
let listener: *mut BufferRemovedListener = context.cast();
(*listener)(&reader, &buffer);
std::mem::forget(reader);
})
});
}

let mut listener = ffi::AImageReader_BufferRemovedListener {
Expand Down
17 changes: 10 additions & 7 deletions ndk/src/media/media_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl MediaCodec {
if let Some(f) = callback.on_input_available.as_mut() {
f(index as usize);
}
})
});
}

unsafe extern "C" fn ffi_on_output_available(
Expand All @@ -187,7 +187,7 @@ impl MediaCodec {
};
f(index as usize, &buffer_info);
}
})
});
}

unsafe extern "C" fn ffi_on_format_changed(
Expand All @@ -205,7 +205,7 @@ impl MediaCodec {
if let Some(f) = callback.on_format_changed.as_mut() {
f(&format);
}
})
});
}

unsafe extern "C" fn ffi_on_error(
Expand All @@ -224,7 +224,7 @@ impl MediaCodec {
CStr::from_ptr(detail),
);
}
})
});
}

let (callback, ffi_callback, user_data) = if let Some(callback) = callback {
Expand Down Expand Up @@ -315,7 +315,10 @@ impl MediaCodec {
}
}

pub fn dequeue_input_buffer(&self, timeout: Duration) -> Result<DequeuedInputBufferResult<'_>> {
pub fn dequeue_input_buffer(
&mut self,
timeout: Duration,
) -> Result<DequeuedInputBufferResult<'_>> {
let result = unsafe {
ffi::AMediaCodec_dequeueInputBuffer(
self.as_ptr(),
Expand Down Expand Up @@ -377,7 +380,7 @@ impl MediaCodec {
MediaError::from_status(status)
}

pub fn input_buffer(&self, index: usize) -> Option<&mut [MaybeUninit<u8>]> {
pub fn input_buffer(&mut self, index: usize) -> Option<&mut [MaybeUninit<u8>]> {
unsafe {
let mut out_size = 0;
let buffer_ptr = ffi::AMediaCodec_getInputBuffer(self.as_ptr(), index, &mut out_size);
Expand Down Expand Up @@ -533,7 +536,7 @@ impl Drop for MediaCodec {

#[derive(Debug)]
pub struct InputBuffer<'a> {
codec: &'a MediaCodec,
codec: &'a mut MediaCodec,
index: usize,
}

Expand Down
Loading
Loading