When Is a TextureView's “Consumer Side” Closed?

前端 未结 2 1065
借酒劲吻你
借酒劲吻你 2021-02-08 10:14

One of the official Google samples for the Camera2 API suffers from the same BufferQueue has been abandoned problem as is seen in:

  • What can I do when the BufferQue
2条回答
  •  时光说笑
    2021-02-08 10:40

    As to the actual question - "when is a TextureView's 'Consumer side' closed", I don't know the exact timing, but it is certainly after onPause returns.

    Roughly, TextureView contains a GL surface, and once the UI for the activity is no longer visible, those resources are torn down. Once that happens, the SurfaceTexture given out by the TextureView is no longer valid, and any existing users of that SurfaceTexture (or Surfaces made from it) will start receiving those errors. The method TextureView.SurfaceTextureListener.onSurfaceTextureDestroyed should be invoked by TextureView right before this happens.

    So as an alternative, you may be able to return false from onSurfaceTextureDestroyed to avoid having it be released during UI teardown, and instead wait for onClosed to fire, and then in onClosed release the TextureView's SurfaceTexture yourself. However, I'm not quite familiar enough with the UI/View side of things to know for sure this'll work, and since some of the underlying native surfaces are released either way, you might still see the abandoned errors with this approach.

    If you're curious, the top levels of the relevant code are in TextureView , especially the destroySurface method, though there's a lot you'd need to understand about the whole Android UI system to sort out when exactly the destroySurface method is invoked, and what its effects are.

提交回复
热议问题