ListenableGlesRenderer2
public abstract class ListenableGlesRenderer2<SharedAssetsT extends Renderer.SharedAssets> extends Renderer.GlesRenderer2
| java.lang.Object | ||||
| ↳ | androidx.wear.watchface.Renderer | |||
| ↳ | androidx.wear.watchface.Renderer.GlesRenderer | |||
| ↳ | androidx.wear.watchface.Renderer.GlesRenderer2 | |||
| ↳ | androidx.wear.watchface.ListenableGlesRenderer2 |
ListenableFuture-based compatibility wrapper around Renderer.GlesRenderer's suspending methods.
use Watch Face Format instead
Summary
Public constructors |
|---|
<SharedAssetsT extends Renderer.SharedAssets> This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Public methods |
|
|---|---|
abstract @NonNull ListenableFuture<@NonNull SharedAssetsT> |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final void |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final void |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final void |
@WorkerThreadThis method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
final void |
@UiThreadThis method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Protected methods |
|
|---|---|
final @NonNull SharedAssetsT |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
@NonNull ListenableFuture<Unit> |
This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
@NonNull ListenableFuture<Unit> |
@UiThreadThis method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead. |
Inherited methods |
||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
Public constructors
ListenableGlesRenderer2
public <SharedAssetsT extends Renderer.SharedAssets>ListenableGlesRenderer2(
@NonNull SurfaceHolder surfaceHolder,
@NonNull CurrentUserStyleRepository currentUserStyleRepository,
@NonNull WatchState watchState,
@IntRange(from = 0, to = 60000) long interactiveDrawModeUpdateDelayMillis,
@NonNull int[] eglConfigAttribList,
@NonNull int[] eglSurfaceAttribList
)
Public methods
createSharedAssetsFuture
@WorkerThread
public abstract @NonNull ListenableFuture<@NonNull SharedAssetsT>createSharedAssetsFuture()
When editing multiple WatchFaceService instances and hence Renderers can exist concurrently (e.g. a headless instance and an interactive instance) and using SharedAssets allows memory to be saved by sharing immutable data (e.g. Bitmaps, shaders, etc...) between them.
To take advantage of SharedAssets, override this method. The constructed SharedAssets are passed into the render as an argument (NB you'll have to cast this to your type). It is safe to make GLES calls within this method.
When all instances using SharedAssets have been closed, SharedAssets.onDestroy will be called.
Note that while SharedAssets are constructed on a background thread, they'll typically be used on the main thread and subsequently destroyed there. The watch face library constructs shared GLES contexts to allow resource sharing between threads.
| Returns | |
|---|---|
@NonNull ListenableFuture<@NonNull SharedAssetsT> |
A |
onBackgroundThreadGlContextCreated
public final void onBackgroundThreadGlContextCreated()Called once a background thread when a new GL context is created on the background thread, before any subsequent calls to render. Note this function is called inside a lambda passed to runBackgroundThreadGlCommands which has synchronized access to the GL context.
If you need to override this method in java, consider using androidx.wear.watchface.ListenableGlesRenderer instead.
onUiThreadGlSurfaceCreated
public final voidonUiThreadGlSurfaceCreated(@Px int width, @Px int height)
Called when a new GL surface is created on the UiThread, before any subsequent calls to render or in response to SurfaceHolder.Callback.surfaceChanged. Note this function is called inside a lambda passed to runUiThreadGlCommands which has synchronized access to the GL context.
If you need to override this method in java, consider using androidx.wear.watchface.ListenableGlesRenderer instead.
runBackgroundThreadGlCommands
@WorkerThread
public final voidrunBackgroundThreadGlCommands(@NonNull Runnable runnable)
Inside of a Mutex this function sets the GL context associated with the WatchFaceService.getBackgroundThreadHandler's looper thread as the current one, executes runnable and finally unsets the GL context.
Access to the GL context this way is necessary because GL contexts are not shared between renderers and there can be multiple watch face instances existing concurrently (e.g. headless and interactive, potentially from different watch faces if an APK contains more than one WatchFaceService).
NB this function is called by the library before running runBackgroundThreadGlCommands so there's no need to use this directly in client code unless you need to make GL calls outside of those methods.
| Throws | |
|---|---|
kotlin.IllegalStateException |
if the calls to |
runUiThreadGlCommands
@UiThread
public final voidrunUiThreadGlCommands(@NonNull Runnable runnable)
Inside of a Mutex this function sets the UiThread GL context as the current one, executes runnable and finally unsets the GL context.
Access to the GL context this way is necessary because GL contexts are not shared between renderers and there can be multiple watch face instances existing concurrently (e.g. headless and interactive, potentially from different watch faces if an APK contains more than one WatchFaceService).
| Throws | |
|---|---|
kotlin.IllegalStateException |
if the calls to |
Protected methods
createSharedAssets
protected final @NonNull SharedAssetsTcreateSharedAssets()
When editing multiple WatchFaceService instances and hence Renderers can exist concurrently (e.g. a headless instance and an interactive instance) and using SharedAssets allows memory to be saved by sharing immutable data (e.g. Bitmaps, shaders, etc...) between them.
To take advantage of SharedAssets, override this method. The constructed SharedAssets are passed into the render as an argument (NB you'll have to cast this to your type). It is safe to make GLES calls within this method.
When all instances using SharedAssets have been closed, SharedAssets.onDestroy will be called.
Note that while SharedAssets are constructed on a background thread, they'll typically be used on the main thread and subsequently destroyed there. The watch face library constructs shared GLES contexts to allow resource sharing between threads.
| Returns | |
|---|---|
@NonNull SharedAssetsT |
The |
onBackgroundThreadGlContextCreatedFuture
protected @NonNull ListenableFuture<Unit>onBackgroundThreadGlContextCreatedFuture()
Called once a background thread when a new GL context is created on the background thread, before any subsequent calls to render. Note this function is called inside a lambda passed to runBackgroundThreadGlCommands which has synchronized access to the GL context. Note cancellation of the returned future is not supported.
| Returns | |
|---|---|
@NonNull ListenableFuture<Unit> |
A ListenableFuture |
onUiThreadGlSurfaceCreatedFuture
@UiThread
protected @NonNull ListenableFuture<Unit>onUiThreadGlSurfaceCreatedFuture(@Px int width, @Px int height)
Called when a new GL surface is created on the UiThread, before any subsequent calls to render and in response to SurfaceHolder.Callback.surfaceChanged. Note this function is called inside a lambda passed to Renderer.GlesRenderer.runUiThreadGlCommands which has synchronized access to the GL context. Note cancellation of the returned future is not supported.
| Returns | |
|---|---|
@NonNull ListenableFuture<Unit> |
A ListenableFuture |