GLConsumer is already attached to a context for new SurfaceTexture

大城市里の小女人 提交于 2019-12-01 12:30:01

I'll post an answer to my own question just in case someone else is facing the same issue.

Presumably, a new SurfaceTexture is attached to GLContext by default due to:

  1. SurfaceTexture constructor calls to nativeInit

  2. nativeInit corresponds to SurfaceTexture_init: https://android.googlesource.com/platform/frameworks/base.git/+/android-4.4.4_r2.0.1/core/jni/android/graphics/SurfaceTexture.cpp#337

  3. SurfaceTexture_init creates a new GLConsumer here: https://android.googlesource.com/platform/frameworks/base.git/+/android-4.4.4_r2.0.1/core/jni/android/graphics/SurfaceTexture.cpp#239

Solution would be to manually detach this newly created SurfaceTexture from GLContext right after the call to a super constructor.

public class MySurfaceTexture extends SurfaceTexture {
    public MySurfaceTexture(int texName) {
        super(texName);
        init();
    }

    private void init() {
        super.detachFromGLContext();
    }
}

I looked up docs specifically for API-19, but you can follow the same path for other API levels.

In Android O there is a new constructor which doesn't attach immediately. Sounds like that's what you want. As your self-answer says, the previous constructors automatically attach to the current thread's GL context.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!