Struct ndk::native_window::NativeWindow
source · 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
impl NativeWindow
sourcepub unsafe fn from_ptr(ptr: NonNull<ANativeWindow>) -> Self
pub unsafe fn from_ptr(ptr: NonNull<ANativeWindow>) -> Self
sourcepub unsafe fn clone_from_ptr(ptr: NonNull<ANativeWindow>) -> Self
pub unsafe fn clone_from_ptr(ptr: NonNull<ANativeWindow>) -> Self
pub fn ptr(&self) -> NonNull<ANativeWindow>
pub fn height(&self) -> i32
pub fn width(&self) -> i32
sourcepub fn format(&self) -> HardwareBufferFormat
pub fn format(&self) -> HardwareBufferFormat
Return the current pixel format (HardwareBufferFormat) of the window surface.
sourcepub fn set_buffers_geometry(
&self,
width: i32,
height: i32,
format: Option<HardwareBufferFormat>
) -> Result<()>
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.
sourcepub fn set_buffers_transform(
&self,
transform: NativeWindowTransform
) -> Result<()>
Available on crate feature api-level-26 only.
pub fn set_buffers_transform( &self, transform: NativeWindowTransform ) -> Result<()>
api-level-26 only.Set a transform that will be applied to future buffers posted to the window.
sourcepub fn set_buffers_data_space(&self, data_space: DataSpace) -> Result<()>
Available on crate feature api-level-28 only.
pub fn set_buffers_data_space(&self, data_space: DataSpace) -> Result<()>
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.
sourcepub fn buffers_data_space(&self) -> Result<DataSpace, GetDataSpaceError>
Available on crate feature api-level-28 only.
pub fn buffers_data_space(&self) -> Result<DataSpace, GetDataSpaceError>
api-level-28 only.Get the dataspace of the buffers in this NativeWindow.
sourcepub fn set_frame_rate(
&self,
frame_rate: f32,
compatibility: FrameRateCompatibility
) -> Result<()>
Available on crate feature api-level-30 only.
pub fn set_frame_rate( &self, frame_rate: f32, compatibility: FrameRateCompatibility ) -> Result<()>
api-level-30 only.Sets the intended frame rate for this window.
sourcepub 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.
pub fn set_frame_rate_with_change_strategy( &self, frame_rate: f32, compatibility: FrameRateCompatibility, change_frame_rate_strategy: ChangeFrameRateStrategy ) -> Result<()>
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.0is 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. Theframe_rateparam does not need to be a valid refresh rate for this device’s display - e.g., it’s fine to pass30fps to a device that can only run the display at60fps.compatibility: The frame rate compatibility of this window. The compatibility value may influence the system’s choice of display refresh rate. See theFrameRateCompatibilityvalues for more info. This parameter is ignored whenframe_rateis0.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 theChangeFrameRateStrategyvalues. This parameter is ignored whenframe_rateis0.
sourcepub fn try_allocate_buffers(&self)
Available on crate feature api-level-30 only.
pub fn try_allocate_buffers(&self)
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
sourcepub unsafe fn from_surface(env: *mut JNIEnv, surface: jobject) -> Option<Self>
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.
sourcepub unsafe fn to_surface(&self, env: *mut JNIEnv) -> jobject
Available on crate feature api-level-26 only.
pub unsafe fn to_surface(&self, env: *mut JNIEnv) -> jobject
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.
sourcepub fn lock(
&self,
dirty_bounds: Option<&mut Rect>
) -> Result<NativeWindowBufferLockGuard<'_>>
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
impl Clone for NativeWindow
source§impl Debug for NativeWindow
impl Debug for NativeWindow
source§impl Drop for NativeWindow
impl Drop for NativeWindow
source§impl HasRawWindowHandle for NativeWindow
Available on crate feature rwh_05 only.
impl HasRawWindowHandle for NativeWindow
rwh_05 only.fn raw_window_handle(&self) -> RawWindowHandle
source§impl HasRawWindowHandle for NativeWindow
Available on crate feature rwh_04 only.
impl HasRawWindowHandle for NativeWindow
rwh_04 only.fn raw_window_handle(&self) -> RawWindowHandle
source§impl HasWindowHandle for NativeWindow
Available on crate feature rwh_06 only.
impl HasWindowHandle for NativeWindow
rwh_06 only.source§fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError>
source§impl Hash for NativeWindow
impl Hash for NativeWindow
source§impl Ord for NativeWindow
impl Ord for NativeWindow
source§fn cmp(&self, other: &NativeWindow) -> Ordering
fn cmp(&self, other: &NativeWindow) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq for NativeWindow
impl PartialEq for NativeWindow
source§fn eq(&self, other: &NativeWindow) -> bool
fn eq(&self, other: &NativeWindow) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd for NativeWindow
impl PartialOrd for NativeWindow
source§fn partial_cmp(&self, other: &NativeWindow) -> Option<Ordering>
fn partial_cmp(&self, other: &NativeWindow) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Eq for NativeWindow
impl Send for NativeWindow
impl StructuralEq for NativeWindow
impl StructuralPartialEq for NativeWindow
impl Sync for NativeWindow
Auto Trait Implementations§
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> HasRawWindowHandle for Twhere
T: HasWindowHandle + ?Sized,
impl<T> HasRawWindowHandle for Twhere T: HasWindowHandle + ?Sized,
source§fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>
fn raw_window_handle(&self) -> Result<RawWindowHandle, HandleError>
HasWindowHandle instead