Struct ndk::surface_texture::SurfaceTexture

source ·
pub struct SurfaceTexture { /* private fields */ }
Available on crate feature api-level-28 only.
Expand description

An opaque type to manage android.graphics.SurfaceTexture from native code

Implementations§

source§

impl SurfaceTexture

source

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

Assumes ownership of ptr

§Safety

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

source

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

Get a reference to the native SurfaceTexture from the corresponding Java object.

§Safety

This function should be called with a healthy JVM pointer and with a non-null android.graphics.SurfaceTexture, which must be kept alive on the Java/Kotlin side.

The caller must keep a reference to the Java android.graphics.SurfaceTexture during the lifetime of the returned SurfaceTexture. Failing to do so could result in the SurfaceTexture to stop functioning properly once the Java object gets finalized. However, this will not result in program termination.

source

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

Returns a pointer to the native ffi::ASurfaceTexture.

source

pub fn acquire_native_window(&self) -> Option<NativeWindow>

Returns a reference to a NativeWindow (i.e. the Producer) for this SurfaceTexture.

This is equivalent to Java’s:

Surface sur = new Surface(surfaceTexture);
source

pub fn attach_to_gl_context(&self, tex_name: u32) -> Result<()>

Attach the SurfaceTexture to the OpenGL ES context that is current on the calling thread.

A new OpenGL ES texture object is created and populated with the SurfaceTexture image frame that was current at the time of the last call to detach_from_gl_context(). This new texture is bound to the GL_TEXTURE_EXTERNAL_OES texture target.

This can be used to access the SurfaceTexture image contents from multiple OpenGL ES contexts. Note, however, that the image contents are only accessible from one OpenGL ES context at a time.

source

pub fn detach_from_gl_context(&self) -> Result<()>

Detach the SurfaceTexture from the OpenGL ES context that owns the OpenGL ES texture object.

This call must be made with the OpenGL ES context current on the calling thread. The OpenGL ES texture object will be deleted as a result of this call. After calling this method all calls to update_tex_image() will fail until a successful call to attach_to_gl_context() is made.

This can be used to access the SurfaceTexture image contents from multiple OpenGL ES contexts. Note, however, that the image contents are only accessible from one OpenGL ES context at a time.

source

pub fn transform_matrix(&self) -> [f32; 16]

Retrieve the 4x4 texture coordinate transform matrix associated with the texture image set by the most recent call to update_tex_image().

This transform matrix maps 2D homogeneous texture coordinates of the form (s, t, 0, 1) with s and t in the inclusive range [0, 1] to the texture coordinate that should be used to sample that location from the texture. Sampling the texture outside of the range of this transform is undefined.

The matrix is stored in column-major order so that it may be passed directly to OpenGL ES via the glLoadMatrixf() or glUniformMatrix4fv() functions.

source

pub fn timestamp(&self) -> Duration

Retrieve the timestamp associated with the texture image set by the most recent call to update_tex_image().

This timestamp is in nanoseconds, and is normally monotonically increasing. The timestamp should be unaffected by time-of-day adjustments, and for a camera should be strictly monotonic but for a MediaPlayer may be reset when the position is set. The specific meaning and zero point of the timestamp depends on the source providing images to the SurfaceTexture. Unless otherwise specified by the image source, timestamps cannot generally be compared across SurfaceTexture instances, or across multiple program invocations. It is mostly useful for determining time offsets between subsequent frames.

For EGL/Vulkan producers, this timestamp is the desired present time set with the EGL_ANDROID_presentation_time or VK_GOOGLE_display_timing extensions.

source

pub fn update_tex_image(&self) -> Result<()>

Update the texture image to the most recent frame from the image stream.

This may only be called while the OpenGL ES context that owns the texture is current on the calling thread. It will implicitly bind its texture to the GL_TEXTURE_EXTERNAL_OES texture target.

Trait Implementations§

source§

impl Debug for SurfaceTexture

source§

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

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

impl Drop for SurfaceTexture

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Hash for SurfaceTexture

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 SurfaceTexture

source§

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

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

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

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

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

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

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

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

impl PartialEq for SurfaceTexture

source§

fn eq(&self, other: &SurfaceTexture) -> 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 SurfaceTexture

source§

fn partial_cmp(&self, other: &SurfaceTexture) -> 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 SurfaceTexture

source§

impl Send for SurfaceTexture

source§

impl StructuralPartialEq for SurfaceTexture

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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, U> Into<U> for T
where 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, U> TryFrom<U> for T
where 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 T
where 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.