pub struct NativeWindow { /* private fields */ }
Expand description

It is the C counterpart of the android.view.Surface object in Java, and can be converted both ways. Depending on the consumer, images submitted to NativeWindow can be shown on the display or sent to other consumers, such as video encoders.

Implementations§

source§

impl NativeWindow

source

pub unsafe fn from_ptr(ptr: NonNull<ANativeWindow>) -> Self

Assumes ownership of ptr

Safety

ptr must be a valid pointer to an Android ffi::ANativeWindow.

source

pub unsafe fn clone_from_ptr(ptr: NonNull<ANativeWindow>) -> Self

Acquires ownership of ptr

Safety

ptr must be a valid pointer to an Android ffi::ANativeWindow.

source

pub fn ptr(&self) -> NonNull<ANativeWindow>

source

pub fn height(&self) -> i32

source

pub fn width(&self) -> i32

source

pub fn format(&self) -> HardwareBufferFormat

Return the current pixel format (HardwareBufferFormat) of the window surface.

source

pub fn set_buffers_geometry( &self, width: i32, height: i32, format: Option<HardwareBufferFormat> ) -> Result<()>

Change the format and size of the window buffers.

The width and height control the number of pixels in the buffers, not the dimensions of the window on screen. If these are different than the window’s physical size, then its buffer will be scaled to match that size when compositing it to the screen. The width and height must be either both zero or both non-zero.

For all of these parameters, if 0 or None is supplied then the window’s base value will come back in force.

source

pub fn set_buffers_transform( &self, transform: NativeWindowTransform ) -> Result<()>

Available on crate feature api-level-26 only.

Set a transform that will be applied to future buffers posted to the window.

source

pub fn set_buffers_data_space(&self, data_space: DataSpace) -> Result<()>

Available on crate feature api-level-28 only.

All buffers queued after this call will be associated with the dataSpace parameter specified.

data_space specifies additional information about the buffer. For example, it can be used to convey the color space of the image data in the buffer, or it can be used to indicate that the buffers contain depth measurement data instead of color images. The default dataSpace is 0, DataSpace::Unknown, unless it has been overridden by the producer.

source

pub fn buffers_data_space(&self) -> Result<DataSpace, GetDataSpaceError>

Available on crate feature api-level-28 only.

Get the dataspace of the buffers in this NativeWindow.

source

pub fn set_frame_rate( &self, frame_rate: f32, compatibility: FrameRateCompatibility ) -> Result<()>

Available on crate feature api-level-30 only.
source

pub fn set_frame_rate_with_change_strategy( &self, frame_rate: f32, compatibility: FrameRateCompatibility, change_frame_rate_strategy: ChangeFrameRateStrategy ) -> Result<()>

Available on crate feature api-level-31 only.

Sets the intended frame rate for this window.

On devices that are capable of running the display at different refresh rates, the system may choose a display refresh rate to better match this window’s frame rate. Usage of this API won’t introduce frame rate throttling, or affect other aspects of the application’s frame production pipeline. However, because the system may change the display refresh rate, calls to this function may result in changes to Choreographer callback timings, and changes to the time interval at which the system releases buffers back to the application.

Note that this only has an effect for windows presented on the display. If this NativeWindow is consumed by something other than the system compositor, e.g. a media codec, this call has no effect.

You can register for changes in the refresh rate using ffi::AChoreographer_registerRefreshRateCallback().

Parameters
  • frame_rate: The intended frame rate of this window, in frames per second. 0 is a special value that indicates the app will accept the system’s choice for the display frame rate, which is the default behavior if this function isn’t called. The frame_rate param does not need to be a valid refresh rate for this device’s display - e.g., it’s fine to pass 30fps to a device that can only run the display at 60fps.
  • compatibility: The frame rate compatibility of this window. The compatibility value may influence the system’s choice of display refresh rate. See the FrameRateCompatibility values for more info. This parameter is ignored when frame_rate is 0.
  • change_frame_rate_strategy: Whether display refresh rate transitions caused by this window should be seamless. A seamless transition is one that doesn’t have any visual interruptions, such as a black screen for a second or two. See the ChangeFrameRateStrategy values. This parameter is ignored when frame_rate is 0.
source

pub fn try_allocate_buffers(&self)

Available on crate feature api-level-30 only.

Provides a hint to the window that buffers should be preallocated ahead of time.

Note that the window implementation is not guaranteed to preallocate any buffers, for instance if an implementation disallows allocation of new buffers, or if there is insufficient memory in the system to preallocate additional buffers

source

pub unsafe fn from_surface(env: *mut JNIEnv, surface: jobject) -> Option<Self>

Return the NativeWindow associated with a JNI android.view.Surface pointer.

Safety

By calling this function, you assert that env is a valid pointer to a JNIEnv and surface is a valid pointer to an android.view.Surface.

source

pub unsafe fn to_surface(&self, env: *mut JNIEnv) -> jobject

Available on crate feature api-level-26 only.

Return a JNI android.view.Surface pointer derived from this NativeWindow.

Safety

By calling this function, you assert that env is a valid pointer to a JNIEnv.

source

pub fn lock( &self, dirty_bounds: Option<&mut Rect> ) -> Result<NativeWindowBufferLockGuard<'_>>

Lock the window’s next drawing surface for writing.

Optionally pass the region you intend to draw into dirty_bounds. When this function returns it is updated (commonly enlarged) with the actual area the caller needs to redraw.

Trait Implementations§

source§

impl Clone for NativeWindow

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for NativeWindow

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for NativeWindow

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl HasRawWindowHandle for NativeWindow

Available on crate feature rwh_05 only.
source§

impl HasRawWindowHandle for NativeWindow

Available on crate feature rwh_04 only.
source§

impl HasWindowHandle for NativeWindow

Available on crate feature rwh_06 only.
source§

fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>

Get a handle to the window.
source§

impl Hash for NativeWindow

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for NativeWindow

source§

fn cmp(&self, other: &NativeWindow) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for NativeWindow

source§

fn eq(&self, other: &NativeWindow) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for NativeWindow

source§

fn partial_cmp(&self, other: &NativeWindow) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for NativeWindow

source§

impl Send for NativeWindow

source§

impl StructuralEq for NativeWindow

source§

impl StructuralPartialEq for NativeWindow

source§

impl Sync for NativeWindow

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> HasRawWindowHandle for Twhere T: HasWindowHandle + ?Sized,

source§

fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>

👎Deprecated: Use HasWindowHandle instead
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.