# EGLSurfaceTexture

# EGLSurfaceTexture

Artifact:[androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3)  
[View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/EGLSurfaceTexture.java+class:androidx.media3.common.util.EGLSurfaceTexture)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/common/util/EGLSurfaceTexture "View this page in Java")

<br />

```
@UnstableApi
class EGLSurfaceTexture : SurfaceTexture.OnFrameAvailableListener, Runnable
```

<br />

*** ** * ** ***

Generates a[SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html)using EGL/GLES functions.

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                      ### Nested types                                                                                                                                                                                                                                                                                                                                                                                                                      |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[Documented](https://developer.android.com/reference/java/lang/annotation/Documented.html) `@`[Retention](https://developer.android.com/reference/java/lang/annotation/Retention.html)`(value = `[RetentionPolicy.SOURCE](https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE)`)` `@`[Target](https://developer.android.com/reference/java/lang/annotation/Target.html)`(value = `[ElementType.TYPE_USE](https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE)`)` `@`[IntDef](https://developer.android.com/reference/kotlin/androidx/annotation/IntDef)`(value = )` `annotation `[EGLSurfaceTexture.SecureMode](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture.SecureMode) Secure mode to be used by the EGL surface and context. |
| `interface `[EGLSurfaceTexture.TextureImageListener](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture.TextureImageListener) Listener to be called when the texture image on[SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html)has been updated.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SECURE_MODE_NONE](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#SECURE_MODE_NONE())` = 0` No secure EGL surface and context required.                                   |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SECURE_MODE_PROTECTED_PBUFFER](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#SECURE_MODE_PROTECTED_PBUFFER())` = 2` Creating a secure surface backed by a pixel buffer. |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [SECURE_MODE_SURFACELESS_CONTEXT](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#SECURE_MODE_SURFACELESS_CONTEXT())` = 1` Creating a surfaceless, secured EGL context.    |

|                                                                                                                                                                                                                                         ### Public constructors                                                                                                                                                                                                                                          |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [EGLSurfaceTexture](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#EGLSurfaceTexture(android.os.Handler))`(handler: `[Handler](https://developer.android.com/reference/android/os/Handler.html)`!)`                                                                                                                                                                                                                                                        |
| [EGLSurfaceTexture](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#EGLSurfaceTexture(android.os.Handler,androidx.media3.common.util.EGLSurfaceTexture.TextureImageListener))`(` ` handler: `[Handler](https://developer.android.com/reference/android/os/Handler.html)`!,` ` callback: `[EGLSurfaceTexture.TextureImageListener](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture.TextureImageListener)`?` `)` |

|                                       ### Public functions                                        |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html)`!` | [getSurfaceTexture](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#getSurfaceTexture())`()` Returns the wrapped[SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html).                                                                                                                                                                                                                                              |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [init](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#init(int))`(@`[EGLSurfaceTexture.SecureMode](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture.SecureMode)` secureMode: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Initializes required EGL parameters and creates the[SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html). |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [onFrameAvailable](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#onFrameAvailable(android.graphics.SurfaceTexture))`(surfaceTexture: `[SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html)`!)`                                                                                                                                                                                                                   |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [release](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#release())`()` Releases all allocated resources.                                                                                                                                                                                                                                                                                                                                                   |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [run](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#run())`()`                                                                                                                                                                                                                                                                                                                                                                                             |

## Constants

### SECURE_MODE_NONE

```
const val SECURE_MODE_NONE = 0: Int
```

No secure EGL surface and context required.  

### SECURE_MODE_PROTECTED_PBUFFER

```
const val SECURE_MODE_PROTECTED_PBUFFER = 2: Int
```

Creating a secure surface backed by a pixel buffer.  

### SECURE_MODE_SURFACELESS_CONTEXT

```
const val SECURE_MODE_SURFACELESS_CONTEXT = 1: Int
```

Creating a surfaceless, secured EGL context.  

## Public constructors

### EGLSurfaceTexture

```
EGLSurfaceTexture(handler: Handler!)
```  

|                                        Parameters                                        |
|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `handler: `[Handler](https://developer.android.com/reference/android/os/Handler.html)`!` | The[Handler](https://developer.android.com/reference/android/os/Handler.html)that will be used to call[updateTexImage](https://developer.android.com/reference/android/graphics/SurfaceTexture.html#updateTexImage())to update images on the[SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html). Note that[init](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#init(int))has to be called on the same looper thread as the[Handler](https://developer.android.com/reference/android/os/Handler.html)'s looper. |

### EGLSurfaceTexture

```
EGLSurfaceTexture(
    handler: Handler!,
    callback: EGLSurfaceTexture.TextureImageListener?
)
```  

|                                                                                 Parameters                                                                                 |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `handler: `[Handler](https://developer.android.com/reference/android/os/Handler.html)`!`                                                                                   | The[Handler](https://developer.android.com/reference/android/os/Handler.html)that will be used to call[updateTexImage](https://developer.android.com/reference/android/graphics/SurfaceTexture.html#updateTexImage())to update images on the[SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html). Note that[init](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#init(int))has to be called on the same looper thread as the looper of the[Handler](https://developer.android.com/reference/android/os/Handler.html). |
| `callback: `[EGLSurfaceTexture.TextureImageListener](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture.TextureImageListener)`?` | The[TextureImageListener](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture.TextureImageListener)to be called when the texture image on[SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html)has been updated. This callback will be called on the same handler thread as the`handler`.                                                                                                                                                                                                                                    |

## Public functions

### getSurfaceTexture

```
fun getSurfaceTexture(): SurfaceTexture!
```

Returns the wrapped[SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html). This can only be called after[init](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture#init(int)).  

### init

```
fun init(@EGLSurfaceTexture.SecureMode secureMode: Int): Unit
```

Initializes required EGL parameters and creates the[SurfaceTexture](https://developer.android.com/reference/android/graphics/SurfaceTexture.html).  

|                                                                                                              Parameters                                                                                                              |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
| `@`[EGLSurfaceTexture.SecureMode](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture.SecureMode)` secureMode: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The[SecureMode](https://developer.android.com/reference/kotlin/androidx/media3/common/util/EGLSurfaceTexture.SecureMode)to be used for EGL surface. |

|                                                                     Throws                                                                      |
|-------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [androidx.media3.common.util.GlUtil.GlException](https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException) |   |

### onFrameAvailable

```
fun onFrameAvailable(surfaceTexture: SurfaceTexture!): Unit
```  

### release

```
fun release(): Unit
```

Releases all allocated resources.  

### run

```
fun run(): Unit
```