1

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.

go3d
  • 443
  • 3
  • 11

2 Answers2

1

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.

Yuri Schimke
  • 12,435
  • 3
  • 35
  • 69
  • Thanks Yuri. If I change "extends Gles2WatchFaceService" to "extends Renderer.GlesRenderer" I get many parts in my code that don't work anymore. This seems like a bigger change in the code, almost like starting from scratch. Am I missing something? – go3d Feb 25 '22 at 15:21
  • 1
    Sorry, I haven't gone through that migration, so can't help you. But the legacy APIs are already having some issues on Wear 3, and won't get continuing improvements, bug fixes. So I don't know if you have an option. I can't see examples in the wild either. – Yuri Schimke Feb 25 '22 at 19:46
  • Thanks! That's sad. Since the update on the Galaxy Watch4, my watch face keeps crashing in ambient mode. Because my watch face has a lot of functionality, a complete re-development could even kill the project in worst case. Wondering if I am the only developer who relies on Gles2WatchFaceService for a bigger project. And wondering if OpenGl is still the way to go, or whether I should consider using only CanvasWatchFaceService. Not sure if that would make the animation sluggish and/or increase the CPU load. – go3d Feb 27 '22 at 01:02
  • 1
    I would (naively) expect that if you are using OpenGL, then the core rendering logic of your watchface won't change. There is a hardware canvas mode for non opengl watchfaces, so if you are just drawing a few shapes and an image, then it's probably simpler. But I expect you must have something more interesting that meant opengl was worthwhile in the first place. – Yuri Schimke Feb 27 '22 at 11:24
  • Thank for the insight! I have several shapes, but all 2D. Not sure if OpenGL is really needed. But the same project in web (html5) did not perform well without it. Perhaps you can have a look and comment whether you would go for OpenGL or not: youtu.be/RHfpxL8DRFg . Thanks – go3d Feb 28 '22 at 05:07
  • 1
    Not an educated opinion, but I suspect that the Canvas with hardware rendering would be enough for that watchface. It's gorgeous, BTW. I believe more typical opengl watchface might be some animated character, rendered as 2D from a 3d model (the bear on the Samsung watchface). – Yuri Schimke Mar 02 '22 at 17:08
  • There is an example watchface here https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:wear/watchface/watchface/samples/src/main/java/androidx/wear/watchface/samples/ExampleOpenGLWatchFaceService.kt – Yuri Schimke Mar 02 '22 at 17:08
0

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.
Lim Thye Chean
  • 8,704
  • 9
  • 49
  • 88