SurfaceTexture Class

Definition

Captures frames from an image stream as an OpenGL ES texture.

[Android.Runtime.Register("android/graphics/SurfaceTexture", DoNotGenerateAcw=true)]
public class SurfaceTexture : Java.Lang.Object
[<Android.Runtime.Register("android/graphics/SurfaceTexture", DoNotGenerateAcw=true)>]
type SurfaceTexture = class
    inherit Object
Inheritance
SurfaceTexture
Attributes

Remarks

Captures frames from an image stream as an OpenGL ES texture.

The image stream may come from either camera preview or video decode. A android.view.Surface created from a SurfaceTexture can be used as an output destination for the android.hardware.camera2, android.media.MediaCodec, android.media.MediaPlayer, and android.renderscript.Allocation APIs. When #updateTexImage is called, the contents of the texture object specified when the SurfaceTexture was created are updated to contain the most recent image from the image stream. This may cause some frames of the stream to be skipped.

A SurfaceTexture may also be used in place of a SurfaceHolder when specifying the output destination of the older android.hardware.Camera API. Doing so will cause all the frames from the image stream to be sent to the SurfaceTexture object rather than to the device's display.

When sampling from the texture one should first transform the texture coordinates using the matrix queried via #getTransformMatrix(float[]). The transform matrix may change each time #updateTexImage is called, so it should be re-queried each time the texture image is updated. This matrix transforms traditional 2D OpenGL ES texture coordinate column vectors of the form (s, t, 0, 1) where s and t are on the inclusive interval [0, 1] to the proper sampling location in the streamed texture. This transform compensates for any properties of the image stream source that cause it to appear different from a traditional OpenGL ES texture. For example, sampling from the bottom left corner of the image can be accomplished by transforming the column vector (0, 0, 0, 1) using the queried matrix, while sampling from the top right corner of the image can be done by transforming (1, 1, 0, 1).

The texture object uses the GL_TEXTURE_EXTERNAL_OES texture target, which is defined by the GL_OES_EGL_image_external OpenGL ES extension. This limits how the texture may be used. Each time the texture is bound it must be bound to the GL_TEXTURE_EXTERNAL_OES target rather than the GL_TEXTURE_2D target. Additionally, any OpenGL ES 2.0 shader that samples from the texture must declare its use of this extension using, for example, an "#extension GL_OES_EGL_image_external : require" directive. Such shaders must also access the texture using the samplerExternalOES GLSL sampler type.

SurfaceTexture objects may be created on any thread. #updateTexImage may only be called on the thread with the OpenGL ES context that contains the texture object. The frame-available callback is called on an arbitrary thread, so unless special care is taken #updateTexImage should not be called directly from the callback.

Java documentation for android.graphics.SurfaceTexture.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

SurfaceTexture(Boolean)

Construct a new SurfaceTexture to stream images to a given OpenGL texture.

SurfaceTexture(Int32)

Construct a new SurfaceTexture to stream images to a given OpenGL texture.

SurfaceTexture(Int32, Boolean)

Construct a new SurfaceTexture to stream images to a given OpenGL texture.

SurfaceTexture(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
DataSpace

Retrieve the dataspace associated with the texture image.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsReleased

Returns true if the SurfaceTexture was released.

JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Timestamp

Retrieve the timestamp associated with the texture image set by the most recent call to #updateTexImage.

Methods

AttachToGLContext(Int32)

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

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
DetachFromGLContext()

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

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetTransformMatrix(Single[])

Retrieve the 4x4 texture coordinate transform matrix associated with the texture image set by the most recent call to #updateTexImage.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Release()

release() frees all the buffers and puts the SurfaceTexture into the 'abandoned' state.

ReleaseTexImage()

Releases the the texture content.

SetDefaultBufferSize(Int32, Int32)

Set the default size of the image buffers.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetOnFrameAvailableListener(SurfaceTexture+IOnFrameAvailableListener)

Register a callback to be invoked when a new image frame becomes available to the SurfaceTexture.

SetOnFrameAvailableListener(SurfaceTexture+IOnFrameAvailableListener, Handler)

Register a callback to be invoked when a new image frame becomes available to the SurfaceTexture.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
UpdateTexImage()

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

Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Events

FrameAvailable

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to