ListenableGlesRenderer2


abstract class ListenableGlesRenderer2<SharedAssetsT : Renderer.SharedAssets> : Renderer.GlesRenderer2


ListenableFuture-based compatibility wrapper around Renderer.GlesRenderer's suspending methods.

Summary

Public constructors

<SharedAssetsT : Renderer.SharedAssets> ListenableGlesRenderer2(
    surfaceHolder: SurfaceHolder,
    currentUserStyleRepository: CurrentUserStyleRepository,
    watchState: WatchState,
    interactiveDrawModeUpdateDelayMillis: @IntRange(from = 0, to = 60000) Long,
    eglConfigAttribList: IntArray,
    eglSurfaceAttribList: IntArray
)

Public functions

abstract ListenableFuture<SharedAssetsT>

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.

final suspend Unit

Called once a background thread when a new GL context is created on the background thread, before any subsequent calls to render.

final suspend Unit
onUiThreadGlSurfaceCreated(width: @Px Int, height: @Px Int)

Called when a new GL surface is created on the UiThread, before any subsequent calls to render or in response to SurfaceHolder.Callback.surfaceChanged.

Unit

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.

Unit

Inside of a Mutex this function sets the UiThread GL context as the current one, executes runnable and finally unsets the GL context.

Protected functions

final suspend SharedAssetsT

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.

open ListenableFuture<Unit>

Called once a background thread when a new GL context is created on the background thread, before any subsequent calls to render.

open ListenableFuture<Unit>

Called when a new GL surface is created on the UiThread, before any subsequent calls to render and in response to SurfaceHolder.Callback.surfaceChanged.

Inherited functions

From androidx.wear.watchface.Renderer
open Rect

This method is used for accessibility support to describe the portion of the screen containing the main clock element.

Unit

Schedules a call to either CanvasRenderer.render or GlesRenderer.render to draw the next frame.

open Unit

Called when the RenderParameters has been updated.

Unit

Posts a message to schedule a call to either CanvasRenderer.render or GlesRenderer.render to draw the next frame.

Unit

Sends a request to the system asking it to update the preview image.

open Boolean

The system periodically (at least once per minute) calls onTimeTick() to trigger a display update.

From androidx.wear.watchface.Renderer.GlesRenderer
open Unit

Called when the Renderer is destroyed.

open Unit

Called when adb shell dumpsys is invoked for the WatchFaceService, allowing the renderer to optionally record state for debugging purposes.

suspend Unit

Inside of a Mutex this function sets the GL context associated with the WatchFaceService.getBackgroundThreadHandler's looper thread as the current one, executes commands and finally unsets the GL context.

suspend Unit
runUiThreadGlCommands(commands: suspend () -> Unit)

Inside of a Mutex this function sets the UiThread GL context as the current one, executes commands and finally unsets the GL context.

From androidx.wear.watchface.Renderer.GlesRenderer2
final Unit
render(zonedDateTime: ZonedDateTime)

Sub-classes should override this to implement their watch face rendering logic which should respect the current renderParameters.

abstract Unit
@UiThread
render(zonedDateTime: ZonedDateTime, sharedAssets: SharedAssetsT)

Sub-classes should override this to implement their watch face rendering logic which should respect the current renderParameters.

final Unit

Sub-classes should override this to implement their watch face highlight layer rendering logic for the RenderParameters.highlightLayer aspect of renderParameters.

abstract Unit
@UiThread
renderHighlightLayer(
    zonedDateTime: ZonedDateTime,
    sharedAssets: SharedAssetsT
)

Sub-classes should override this to implement their watch face highlight layer rendering logic for the RenderParameters.highlightLayer aspect of renderParameters.

Inherited properties

From androidx.wear.watchface.Renderer
Collection<Pair<IntContentDescriptionLabel>>

Accessibility ContentDescriptionLabel for any rendered watch face elements other than the time and ComplicationSlots which are generated automatically.

@Px Float

The center x coordinate of the SurfaceHolder this Renderer renders into.

@Px Float

The center y coordinate of the SurfaceHolder this Renderer renders into.

Long

The interval in milliseconds between frames in interactive DrawModes.

RenderParameters

The current RenderParameters.

Rect

The bounds of the SurfaceHolder this Renderer renders into.

SurfaceHolder

The SurfaceHolder that renderInternal will draw into.

WatchFaceColors?

Representative WatchFaceColors which are made available to system clients via androidx.wear.watchface.client.InteractiveWatchFaceClient.OnWatchFaceColorsListener.

From androidx.wear.watchface.Renderer.GlesRenderer
EGLContext

The GlesRenderer's background Thread EGLContext.

EGLConfig

The GlesRenderer's EGLConfig.

EGLDisplay

The GlesRenderer's EGLDisplay.

EGLContext

The GlesRenderer's UiThread EGLContext.

From androidx.wear.watchface.Renderer.GlesRenderer2
Int

If an eglConfigAttribListList is specified then each list of attributes will be tried in turn by EGL14.eglChooseConfig.

Public constructors

ListenableGlesRenderer2

<SharedAssetsT : Renderer.SharedAssets> ListenableGlesRenderer2(
    surfaceHolder: SurfaceHolder,
    currentUserStyleRepository: CurrentUserStyleRepository,
    watchState: WatchState,
    interactiveDrawModeUpdateDelayMillis: @IntRange(from = 0, to = 60000) Long,
    eglConfigAttribList: IntArray = EGL_CONFIG_ATTRIB_LIST,
    eglSurfaceAttribList: IntArray = EGL_SURFACE_ATTRIB_LIST
)

Public functions

createSharedAssetsFuture

Added in 1.1.0
@WorkerThread
abstract fun createSharedAssetsFuture(): ListenableFuture<SharedAssetsT>

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
ListenableFuture<SharedAssetsT>

A ListenableFuture for the SharedAssetsT that will be passed into render and renderHighlightLayer

onBackgroundThreadGlContextCreated

Added in 1.1.0
final suspend fun onBackgroundThreadGlContextCreated(): Unit

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

Added in 1.1.0
final suspend fun onUiThreadGlSurfaceCreated(width: @Px Int, height: @Px Int): Unit

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.

Parameters
width: @Px Int

width of surface in pixels

height: @Px Int

height of surface in pixels

runBackgroundThreadGlCommands

Added in 1.1.0
@WorkerThread
fun runBackgroundThreadGlCommands(runnable: Runnable): Unit

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 EGL14.eglMakeCurrent fails

runUiThreadGlCommands

Added in 1.1.0
@UiThread
fun runUiThreadGlCommands(runnable: Runnable): Unit

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 EGL14.eglMakeCurrent fails

Protected functions

createSharedAssets

protected final suspend fun createSharedAssets(): SharedAssetsT

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
SharedAssetsT

The SharedAssetsT that will be passed into render and renderHighlightLayer.

onBackgroundThreadGlContextCreatedFuture

Added in 1.1.0
protected open fun onBackgroundThreadGlContextCreatedFuture(): ListenableFuture<Unit>

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
ListenableFuture<Unit>

A ListenableFuture which is resolved when background thread work has completed. Rendering will be blocked until this has resolved.

onUiThreadGlSurfaceCreatedFuture

Added in 1.1.0
@UiThread
protected open fun onUiThreadGlSurfaceCreatedFuture(width: @Px Int, height: @Px Int): ListenableFuture<Unit>

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.

Parameters
width: @Px Int

width of surface in pixels

height: @Px Int

height of surface in pixels

Returns
ListenableFuture<Unit>

A ListenableFuture which is resolved when UI thread work has completed. Rendering will be blocked until this has resolved.