问题
I am trying to apply real-time effects to camera preview and show in multiple views, how can I do?
(just like the camera2) (snapshot)
I know 2 approaches to show real-time effects on camera preivew if no ScrollView involved on the left side.
- Use GLSurfaceView and setRenderer. Bind SurfaceTexture as GLES external texture, and use GLSL(OpenGL Shading Language) to apply effects.
- Use TextureView. It is more complex because need to setup EGLContext/EGLSurface and do thread management.
However, I don't know how to make ScrollView with real-time effect items overlay GLES composition.
- Should I choose GLSurfaceView (for performance) or TextureView (for flexble) to implement the ScrollView? Which one is better solution and why?
- Is it possible to share one EGL context/surface among multiple views? If yes, any code snippets to refer to?
After googling and reading nice Graphics architecture article and Grafika project, I still have no idea ...
Maybe I miss something important, dose someone point me out? Thanks in advance.
回答1:
SurfaceView and scrolling don't go well together, because the SurfaceView has two parts -- the Surface and the View -- and movement of one tends to lag behind movement of the other. The View is rendered by the app, but the Surface is composited by SurfaceFlinger, so window movement has to get passed through the Window Manager. TextureView doesn't have this problem, but does introduce some additional overhead.
If you want it to look good when scrolling, you'll probably want a TextureView.
It is possible for multiple EGL contexts to share data, and it is possible to use a single EGL context to render to more than one surface. Grafika has examples of both ("show + capture camera" uses GLSurfaceView and a shared EGL context, "continuous capture" uses SurfaceView and a single EGL context; both activities render to an on-screen surface and an off-screen surface).
All hardware-accelerated Views do their own EGL context management, and there's no reason to mess with that if you're rendering onto SurfaceView or TextureView.
If you're planning to draw multiple versions of the live camera preview in real time, you'll get the best performance by rendering them all yourself in a single scene. Rendering multiple TextureViews will be less efficient. Depending on your UI choices, this might mean handling the item drawing and scrolling yourself instead of handing it off to ListView. (At the very least, you'd want to ensure that you're only live-updating the thumbnails that are actually on screen.)
来源:https://stackoverflow.com/questions/27376340/surfaceview-or-textureview-combination