Android:是否可以在没有SurfaceView的情况下创建SurfaceTexture? [英] Android: Is it possible to create a SurfaceTexture without a SurfaceView?

查看:556
本文介绍了Android:是否可以在没有SurfaceView的情况下创建SurfaceTexture?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用类似于的设置创建具有我可以管理的OpenGL纹理的 SurfaceTexture 这个答案. (在这里引用:)

I want to create a SurfaceTexture with an OpenGL texture that I can manage, in a setup similar to this answer. (Quoted here:)

  1. 通过OpenGL创建纹理
  2. 将此纹理传递给新的SurfaceTexture的构造函数.
  3. 将此新的SurfaceTexture提供给相机.
  4. 确保您使用的是OES_External(请参阅文档以获取 详细信息.)
  1. Create a texture through OpenGL
  2. Pass this texture to the constructor of new SurfaceTexture.
  3. Give this new SurfaceTexture to the camera.
  4. Make sure you are using OES_External (see documentation for details).

但是,创建OpenGL纹理(如答案的第1步所示)需要 EGL上下文,这需要将EGLSurface设置为最新,并需要SurfaceTexture.似乎创建EGL上下文的唯一方法是创建一个SurfaceView(或另一个具有SurfaceTexture的视图),然后使用它初始化EGLSurface,然后使EGLContext为当前版本.

However, creating an OpenGL texture (as in step 1 of the answer), requires an EGL context, which requires a EGLSurface to be made current, which requires a SurfaceTexture. It seems the only way of creating the EGL context is by creating a SurfaceView (or another view that has a SurfaceTexture), and use it to initialise the EGLSurface and then make the EGLContext current.

我的目标是创建一个EGLContext并使其在后台线程中成为当前状态,以对摄像机预览图像进行一些屏幕外计算(主要是使用NDK).我想创建一个库,并使其尽可能独立于UI.两个相关的问题:

My objective is to create an EGLContext and make it current in a background thread, to do some offscreen computation on the camera preview image (mostly using the NDK). I want to create a library, and make it as independent of the UI as possible. Two related questions:

在Java方面,是否可以在没有预先创建SurfaceTexture的情况下创建EGLContext?

On the Java side, is it possible to create an EGLContext without having a SurfaceTexture created beforehand?

在NDK端,曾经有一个私有API调用来创建本机窗口android_createDisplaySurface(),但是它不再起作用了,而且,它是一个私有API.是否可以使用NDK创建曲面?

On the NDK side, there used to be a private API call to create native windows android_createDisplaySurface(), but it doesn't work anymore, and well, it's a private API. Is there any way of creating a surface with the NDK?

我对使用EGL还是很陌生,但我不明白为什么您需要一个EGLSurface才能使EGLContext成为最新的.在iOS中,可以先创建EAGLContext,然后根据需要创建帧缓冲区.使用EGL似乎总是需要一个本机窗口.

I'm quite new to using EGL, and I fail to understand why you need an EGLSurface for an EGLContext to be made current. In iOS, EAGLContexts can be created first, and then framebuffers can be created as needed. Using EGL it seems you always need a native window.

推荐答案

您可以在

You can see a number of examples that manipulate Camera output, SurfaceTexture, and EGL in Grafika. The "Continuous capture" activity is one, but it uses the technique you mentioned: to avoid having to create an EGLSurface, it just borrows the one from the nearby SurfaceView.

您确实需要具有EGLSurface,但是它不必是 window 曲面.您可以创建一个1x1的pbuffer曲面并使用它.这是通过eglCreatePbufferSurface()调用完成的;有关示例,请参见Grafika中的EglCore类.

You do need to have an EGLSurface, but it doesn't need to be a window surface. You can create a 1x1 pbuffer surface and just use that. This is done with the eglCreatePbufferSurface() call; see the EglCore class in Grafika for an example.

这些示例是用Java编写的,但是Java实现只是包装了本地EGL/GLES调用.

These examples are in Java, but the Java implementation just wraps the native EGL/GLES calls.

android_createDisplaySurface()是一个内部调用,如您所见,它在较新的设备上不起作用.在NDK中搜索ANativeWindow.

android_createDisplaySurface() is an internal call that, as you discovered, doesn't work on newer devices. Search the NDK for ANativeWindow instead.

更新:对于通过搜索到达此处的任何人,android_createDisplaySurface()依赖于名为FramebufferNativeWindow的内部类,该内部类在Android 5.0中在此基于SurfaceFlinger的替换进行了更新.更改.测试代码的原始版本需要关闭Android应用程序框架,以便它可以获取帧缓冲区.较新的版本只是要求SurfaceFlinger提供一个覆盖屏幕并在其他所有内容之上合成的窗口.

Update: for anyone who gets here by searching, android_createDisplaySurface() relied on an internal class called FramebufferNativeWindow, which was marked obsolete in Android 5.0 in this change. The internal OpenGL ES test code that used it was updated with a SurfaceFlinger-based replacement in this change. The original version of the test code required shutting down the Android app framework so it could grab the frame buffer; the newer version just asks SurfaceFlinger for a window that covers the screen and is composited on top of everything else.

这篇关于Android:是否可以在没有SurfaceView的情况下创建SurfaceTexture?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆