go3d
go3d

Reputation: 463

Gles2WatchFaceService deprecated? What now?

For my Wear OS watch face project, I am using Gles2WatchFaceService so the watch face has smooth OpenGL animation when needed. I just updated in build.gradle the following dependency:

implementation 'com.google.android.support:wearable:2.9.0'

The old version was 2.8.1. Now, with 2.9.0, I see this in my main project file when hovering with the mouse over Gles2WatchFaceService:

enter image description here

Seems like Gles2WatchFaceService and WatchFaceService are deprecated. If so, what can I use instead? I found this warning in https://developer.android.com/reference/android/support/wearable/watchface/WatchFaceService:

This class is deprecated.
Use androidx.wear.watchface.WatchFaceService from the Jetpack Wear Watch Face libraries instead.

But what about Gles2WatchFaceService? Any help appreciated.

Upvotes: 2

Views: 1201

Answers (2)

Lim Thye Chean
Lim Thye Chean

Reputation: 9434

According to release note: https://developer.android.com/wear/releases

Version 2.9.0 of the Wearable Support Library deprecates all remaining classes. The Wear OS Jetpack libraries should now be used instead.

Upvotes: 0

Yuri Schimke
Yuri Schimke

Reputation: 13448

See https://developer.android.com/reference/androidx/wear/watchface/Renderer.GlesRenderer

Watch faces that require GLES20 rendering should extend their Renderer from this class.

A GlesRenderer is expected to be constructed on the background thread associated with WatchFaceService.getBackgroundThreadHandler inside a call to WatchFaceService.createWatchFace. All rendering is be done on the UiThread. There is a memory barrier between construction and rendering so no special threading primitives are required.

Two linked EGLContexts are created eglBackgroundThreadContext and eglUiThreadContext which are associated with background and UiThread respectively and are shared by all instances of the renderer. OpenGL objects created on (e.g. shaders and textures) can be used on the other.

Because there can be more than once instance when editing, to save memory its recommended to override createSharedAssets and load all static data (e.g. models, textures, shaders, etc...). OpenGL objects created inside createSharedAssets will be available to all instances of the watch face on both threads.

If you need to make any OpenGl calls outside of render, onBackgroundThreadGlContextCreated or onUiThreadGlSurfaceCreated then you must use either runUiThreadGlCommands or runBackgroundThreadGlCommands to execute a Runnable inside of the corresponding context. Access to the GL contexts 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). In addition most drivers do not support concurrent access.

In Java it may be easier to extend androidx.wear.watchface.ListenableGlesRenderer instead.

Upvotes: 1

Related Questions