1

对于我的 Wear OS 表盘项目,我正在使用Gles2WatchFaceService,因此表盘在需要时具有平滑的OpenGL动画。我刚刚在build.gradle中更新了以下依赖项:

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

旧版本是 2.8.1。现在,使用 2.9.0,当鼠标悬停在 Gles2WatchFaceService 上时,我在主项目文件中看到了这个:

在此处输入图像描述

似乎 Gles2WatchFaceService 和 WatchFaceService 已弃用。如果是这样,我可以用什么代替?我在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.

但是Gles2WatchFaceService呢?任何帮助表示赞赏。

4

1 回答 1

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.

于 2022-02-25T11:55:18.783 回答